echarts.js 874 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202
  1. /**
  2. * ESL (Enterprise Standard Loader)
  3. * Copyright 2013 Baidu Inc. All rights reserved.
  4. *
  5. * @file Browser端标准加载器,符合AMD规范
  6. * @author errorrik(errorrik@gmail.com)
  7. * Firede(firede@firede.us)
  8. */
  9. /* jshint ignore:start */
  10. var define;
  11. var require;
  12. var esl;
  13. /* jshint ignore:end */
  14. /* eslint-disable guard-for-in */
  15. /* eslint-env amd:false */
  16. (function (global) {
  17. // "mod"开头的变量或函数为内部模块管理函数
  18. // 为提高压缩率,不使用function或object包装
  19. /**
  20. * 模块容器
  21. *
  22. * @inner
  23. * @type {Object}
  24. */
  25. var modModules = {};
  26. // 模块状态枚举量
  27. var MODULE_PRE_DEFINED = 1;
  28. var MODULE_ANALYZED = 2;
  29. var MODULE_PREPARED = 3;
  30. var MODULE_DEFINED = 4;
  31. /**
  32. * 自动定义的模块表
  33. *
  34. * 模块define factory是用到时才执行,但是以下几种情况需要自动马上执行:
  35. * 1. require([moduleId], callback)
  36. * 2. plugin module and plugin resource: require('plugin!resource')
  37. * 3. shim module
  38. *
  39. * @inner
  40. * @type {Object}
  41. */
  42. var modAutoDefineModules = {};
  43. /**
  44. * 标记模块自动进行定义
  45. *
  46. * @inner
  47. * @param {string} id 模块id
  48. */
  49. function modFlagAutoDefine(id) {
  50. if (!modIs(id, MODULE_DEFINED)) {
  51. modAutoDefineModules[id] = 1;
  52. }
  53. }
  54. /**
  55. * 内建module名称集合
  56. *
  57. * @inner
  58. * @type {Object}
  59. */
  60. var BUILDIN_MODULE = {
  61. require: globalRequire,
  62. exports: 1,
  63. module: 1
  64. };
  65. /**
  66. * 全局require函数
  67. *
  68. * @inner
  69. * @type {Function}
  70. */
  71. var actualGlobalRequire = createLocalRequire();
  72. // #begin-ignore
  73. /**
  74. * 超时提醒定时器
  75. *
  76. * @inner
  77. * @type {number}
  78. */
  79. var waitTimeout;
  80. // #end-ignore
  81. /* eslint-disable fecs-key-spacing */
  82. /* eslint-disable key-spacing */
  83. /**
  84. * require配置
  85. *
  86. * @inner
  87. * @type {Object}
  88. */
  89. var requireConf = {
  90. baseUrl : './',
  91. paths : {},
  92. config : {},
  93. map : {},
  94. packages : [],
  95. shim : {},
  96. // #begin-ignore
  97. waitSeconds: 0,
  98. // #end-ignore
  99. bundles : {},
  100. urlArgs : {}
  101. };
  102. /* eslint-enable key-spacing */
  103. /**
  104. * 加载模块
  105. *
  106. * @param {string|Array} requireId 模块id或模块id数组,
  107. * @param {Function=} callback 加载完成的回调函数
  108. * @return {*} requireId为string时返回模块暴露对象
  109. */
  110. function globalRequire(requireId, callback) {
  111. // #begin-ignore
  112. // #begin assertNotContainRelativeId
  113. // 确定require的模块id不包含相对id。用于global require,提前预防难以跟踪的错误出现
  114. var invalidIds = [];
  115. /**
  116. * 监测模块id是否relative id
  117. *
  118. * @inner
  119. * @param {string} id 模块id
  120. */
  121. function monitor(id) {
  122. if (id.indexOf('.') === 0) {
  123. invalidIds.push(id);
  124. }
  125. }
  126. if (typeof requireId === 'string') {
  127. monitor(requireId);
  128. }
  129. else {
  130. each(
  131. requireId,
  132. function (id) {
  133. monitor(id);
  134. }
  135. );
  136. }
  137. // 包含相对id时,直接抛出错误
  138. if (invalidIds.length > 0) {
  139. throw new Error(
  140. '[REQUIRE_FATAL]Relative ID is not allowed in global require: '
  141. + invalidIds.join(', ')
  142. );
  143. }
  144. // #end assertNotContainRelativeId
  145. // 超时提醒
  146. var timeout = requireConf.waitSeconds;
  147. if (timeout && (requireId instanceof Array)) {
  148. if (waitTimeout) {
  149. clearTimeout(waitTimeout);
  150. }
  151. waitTimeout = setTimeout(waitTimeoutNotice, timeout * 1000);
  152. }
  153. // #end-ignore
  154. return actualGlobalRequire(requireId, callback);
  155. }
  156. /**
  157. * 版本号
  158. *
  159. * @type {string}
  160. */
  161. globalRequire.version = '2.0.2';
  162. /**
  163. * loader名称
  164. *
  165. * @type {string}
  166. */
  167. globalRequire.loader = 'esl';
  168. /**
  169. * 将模块标识转换成相对的url
  170. *
  171. * @param {string} id 模块标识
  172. * @return {string}
  173. */
  174. globalRequire.toUrl = actualGlobalRequire.toUrl;
  175. // #begin-ignore
  176. /**
  177. * 超时提醒函数
  178. *
  179. * @inner
  180. */
  181. function waitTimeoutNotice() {
  182. var hangModules = [];
  183. var missModules = [];
  184. var hangModulesMap = {};
  185. var missModulesMap = {};
  186. var visited = {};
  187. /**
  188. * 检查模块的加载错误
  189. *
  190. * @inner
  191. * @param {string} id 模块id
  192. * @param {boolean} hard 是否装载时依赖
  193. */
  194. function checkError(id, hard) {
  195. if (visited[id] || modIs(id, MODULE_DEFINED)) {
  196. return;
  197. }
  198. visited[id] = 1;
  199. if (!modIs(id, MODULE_PREPARED)) {
  200. // HACK: 为gzip后体积优化,不做抽取
  201. if (!hangModulesMap[id]) {
  202. hangModulesMap[id] = 1;
  203. hangModules.push(id);
  204. }
  205. }
  206. var mod = modModules[id];
  207. if (!mod) {
  208. if (!missModulesMap[id]) {
  209. missModulesMap[id] = 1;
  210. missModules.push(id);
  211. }
  212. }
  213. else if (hard) {
  214. if (!hangModulesMap[id]) {
  215. hangModulesMap[id] = 1;
  216. hangModules.push(id);
  217. }
  218. each(
  219. mod.depMs,
  220. function (dep) {
  221. checkError(dep.absId, dep.hard);
  222. }
  223. );
  224. }
  225. }
  226. for (var id in modAutoDefineModules) {
  227. checkError(id, 1);
  228. }
  229. if (hangModules.length || missModules.length) {
  230. throw new Error(
  231. '[MODULE_TIMEOUT]Hang( '
  232. + (hangModules.join(', ') || 'none')
  233. + ' ) Miss( '
  234. + (missModules.join(', ') || 'none')
  235. + ' )'
  236. );
  237. }
  238. }
  239. // #end-ignore
  240. /**
  241. * 未预定义的模块集合
  242. * 主要存储匿名方式define的模块
  243. *
  244. * @inner
  245. * @type {Array}
  246. */
  247. var wait4PreDefine = [];
  248. /**
  249. * 完成模块预定义,此时处理的模块是匿名define的模块
  250. *
  251. * @inner
  252. * @param {string} currentId 匿名define的模块的id
  253. */
  254. function modCompletePreDefine(currentId) {
  255. // HACK: 这里在IE下有个性能陷阱,不能使用任何变量。
  256. // 否则貌似会形成变量引用和修改的读写锁,导致wait4PreDefine释放困难
  257. each(wait4PreDefine, function (mod) {
  258. modPreDefine(
  259. currentId,
  260. mod.deps,
  261. mod.factory
  262. );
  263. });
  264. wait4PreDefine.length = 0;
  265. }
  266. /**
  267. * 定义模块
  268. *
  269. * @param {string=} id 模块标识
  270. * @param {Array=} dependencies 依赖模块列表
  271. * @param {Function=} factory 创建模块的工厂方法
  272. */
  273. function globalDefine(id, dependencies, factory) {
  274. // define(factory)
  275. // define(dependencies, factory)
  276. // define(id, factory)
  277. // define(id, dependencies, factory)
  278. if (factory == null) {
  279. if (dependencies == null) {
  280. factory = id;
  281. id = null;
  282. }
  283. else {
  284. factory = dependencies;
  285. dependencies = null;
  286. if (id instanceof Array) {
  287. dependencies = id;
  288. id = null;
  289. }
  290. }
  291. }
  292. if (factory == null) {
  293. return;
  294. }
  295. var opera = window.opera;
  296. // IE下通过current script的data-require-id获取当前id
  297. if (
  298. !id
  299. && document.attachEvent
  300. && (!(opera && opera.toString() === '[object Opera]'))
  301. ) {
  302. var currentScript = getCurrentScript();
  303. id = currentScript && currentScript.getAttribute('data-require-id');
  304. }
  305. if (id) {
  306. modPreDefine(id, dependencies, factory);
  307. }
  308. else {
  309. // 纪录到共享变量中,在load或readystatechange中处理
  310. // 标准浏览器下,使用匿名define时,将进入这个分支
  311. wait4PreDefine[0] = {
  312. deps: dependencies,
  313. factory: factory
  314. };
  315. }
  316. }
  317. globalDefine.amd = {};
  318. /**
  319. * 模块配置获取函数
  320. *
  321. * @inner
  322. * @return {Object} 模块配置对象
  323. */
  324. function moduleConfigGetter() {
  325. var conf = requireConf.config[this.id];
  326. if (conf && typeof conf === 'object') {
  327. return conf;
  328. }
  329. return {};
  330. }
  331. /**
  332. * 预定义模块
  333. *
  334. * @inner
  335. * @param {string} id 模块标识
  336. * @param {Array.<string>} dependencies 显式声明的依赖模块列表
  337. * @param {*} factory 模块定义函数或模块对象
  338. */
  339. function modPreDefine(id, dependencies, factory) {
  340. // 将模块存入容器
  341. //
  342. // 模块内部信息包括
  343. // -----------------------------------
  344. // id: module id
  345. // depsDec: 模块定义时声明的依赖
  346. // deps: 模块依赖,默认为['require', 'exports', 'module']
  347. // factory: 初始化函数或对象
  348. // factoryDeps: 初始化函数的参数依赖
  349. // exports: 模块的实际暴露对象(AMD定义)
  350. // config: 用于获取模块配置信息的函数(AMD定义)
  351. // state: 模块当前状态
  352. // require: local require函数
  353. // depMs: 实际依赖的模块集合,数组形式
  354. // depMkv: 实际依赖的模块集合,表形式,便于查找
  355. // depRs: 实际依赖的资源集合
  356. // ------------------------------------
  357. if (!modModules[id]) {
  358. /* eslint-disable key-spacing */
  359. modModules[id] = {
  360. id : id,
  361. depsDec : dependencies,
  362. deps : dependencies || ['require', 'exports', 'module'],
  363. factoryDeps : [],
  364. factory : factory,
  365. exports : {},
  366. config : moduleConfigGetter,
  367. state : MODULE_PRE_DEFINED,
  368. require : createLocalRequire(id),
  369. depMs : [],
  370. depMkv : {},
  371. depRs : []
  372. };
  373. /* eslint-enable key-spacing */
  374. }
  375. }
  376. /**
  377. * 开始执行模块定义前的准备工作
  378. *
  379. * 首先,完成对factory中声明依赖的分析提取
  380. * 然后,尝试加载"资源加载所需模块"
  381. *
  382. * 需要先加载模块的原因是:如果模块不存在,无法进行resourceId normalize化
  383. *
  384. * @inner
  385. * @param {string} id 模块id
  386. */
  387. function modPrepare(id) {
  388. var mod = modModules[id];
  389. if (!mod || modIs(id, MODULE_ANALYZED)) {
  390. return;
  391. }
  392. var deps = mod.deps;
  393. var factory = mod.factory;
  394. var hardDependsCount = 0;
  395. // 分析function body中的require
  396. // 如果包含显式依赖声明,根据AMD规定和性能考虑,可以不分析factoryBody
  397. if (typeof factory === 'function') {
  398. hardDependsCount = Math.min(factory.length, deps.length);
  399. // If the dependencies argument is present, the module loader
  400. // SHOULD NOT scan for dependencies within the factory function.
  401. !mod.depsDec && factory.toString()
  402. .replace(/(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg, '')
  403. .replace(/require\(\s*(['"'])([^'"]+)\1\s*\)/g,
  404. function ($0, $1, depId) {
  405. deps.push(depId);
  406. }
  407. );
  408. }
  409. var requireModules = [];
  410. var depResources = [];
  411. each(deps, function (depId, index) {
  412. var idInfo = parseId(depId);
  413. var absId = normalize(idInfo.mod, id);
  414. var moduleInfo;
  415. var resInfo;
  416. if (absId && !BUILDIN_MODULE[absId]) {
  417. // 如果依赖是一个资源,将其信息添加到module.depRs
  418. //
  419. // module.depRs中的项有可能是重复的。
  420. // 在这个阶段,加载resource的module可能还未defined,
  421. // 导致此时resource id无法被normalize。
  422. //
  423. // 比如对a/b/c而言,下面几个resource可能指的是同一个资源:
  424. // - js!../name.js
  425. // - js!a/name.js
  426. // - ../../js!../name.js
  427. //
  428. // 所以加载资源的module ready时,需要遍历module.depRs进行处理
  429. if (idInfo.res) {
  430. resInfo = {
  431. id: depId,
  432. mod: absId,
  433. res: idInfo.res
  434. };
  435. depResources.push(depId);
  436. mod.depRs.push(resInfo);
  437. }
  438. // 对依赖模块的id normalize能保证正确性,在此处进行去重
  439. moduleInfo = mod.depMkv[absId];
  440. if (!moduleInfo) {
  441. moduleInfo = {
  442. id: idInfo.mod,
  443. absId: absId,
  444. hard: index < hardDependsCount
  445. };
  446. mod.depMs.push(moduleInfo);
  447. mod.depMkv[absId] = moduleInfo;
  448. requireModules.push(absId);
  449. }
  450. }
  451. else {
  452. moduleInfo = {absId: absId};
  453. }
  454. // 如果当前正在分析的依赖项是define中声明的,
  455. // 则记录到module.factoryDeps中
  456. // 在factory invoke前将用于生成invoke arguments
  457. if (index < hardDependsCount) {
  458. mod.factoryDeps.push(resInfo || moduleInfo);
  459. }
  460. });
  461. mod.state = MODULE_ANALYZED;
  462. modInitFactoryInvoker(id);
  463. nativeAsyncRequire(requireModules);
  464. depResources.length && mod.require(
  465. depResources,
  466. function () {
  467. each(mod.depRs, function (res) {
  468. if (!res.absId) {
  469. res.absId = normalize(res.id, id);
  470. }
  471. });
  472. modAutoDefine();
  473. }
  474. );
  475. }
  476. /**
  477. * 对一些需要自动定义的模块进行自动定义
  478. *
  479. * @inner
  480. */
  481. function modAutoDefine() {
  482. for (var id in modAutoDefineModules) {
  483. modPrepare(id);
  484. modUpdatePreparedState(id);
  485. modTryInvokeFactory(id);
  486. }
  487. }
  488. /**
  489. * 更新模块的准备状态
  490. *
  491. * @inner
  492. * @param {string} id 模块id
  493. */
  494. function modUpdatePreparedState(id) {
  495. var visited = {};
  496. update(id);
  497. function update(id) {
  498. modPrepare(id);
  499. if (!modIs(id, MODULE_ANALYZED)) {
  500. return false;
  501. }
  502. if (modIs(id, MODULE_PREPARED) || visited[id]) {
  503. return true;
  504. }
  505. visited[id] = 1;
  506. var mod = modModules[id];
  507. var prepared = true;
  508. each(
  509. mod.depMs,
  510. function (dep) {
  511. return (prepared = update(dep.absId));
  512. }
  513. );
  514. // 判断resource是否加载完成。如果resource未加载完成,则认为未准备好
  515. /* jshint ignore:start */
  516. prepared && each(
  517. mod.depRs,
  518. function (dep) {
  519. prepared = !!dep.absId;
  520. return prepared;
  521. }
  522. );
  523. /* jshint ignore:end */
  524. if (prepared) {
  525. mod.state = MODULE_PREPARED;
  526. }
  527. return prepared;
  528. }
  529. }
  530. /**
  531. * 初始化模块定义时所需的factory执行器
  532. *
  533. * @inner
  534. * @param {string} id 模块id
  535. */
  536. function modInitFactoryInvoker(id) {
  537. var mod = modModules[id];
  538. var invoking;
  539. mod.invokeFactory = invokeFactory;
  540. /**
  541. * 初始化模块
  542. *
  543. * @inner
  544. */
  545. function invokeFactory() {
  546. if (invoking || mod.state !== MODULE_PREPARED) {
  547. return;
  548. }
  549. invoking = 1;
  550. // 拼接factory invoke所需的arguments
  551. var factoryReady = 1;
  552. each(
  553. mod.factoryDeps,
  554. function (dep) {
  555. var depId = dep.absId;
  556. if (!BUILDIN_MODULE[depId]) {
  557. modTryInvokeFactory(depId);
  558. return (factoryReady = modIs(depId, MODULE_DEFINED));
  559. }
  560. }
  561. );
  562. if (factoryReady) {
  563. try {
  564. // 调用factory函数初始化module
  565. var factory = mod.factory;
  566. var exports = typeof factory === 'function'
  567. ? factory.apply(global, modGetModulesExports(
  568. mod.factoryDeps,
  569. {
  570. require: mod.require,
  571. exports: mod.exports,
  572. module: mod
  573. }
  574. ))
  575. : factory;
  576. if (exports != null) {
  577. mod.exports = exports;
  578. }
  579. mod.invokeFactory = null;
  580. }
  581. catch (ex) {
  582. if (/^\[MODULE_MISS\]"([^"]+)/.test(ex.message)) {
  583. // 出错,则说明在factory的运行中,该require的模块是需要的
  584. // 所以把它加入强依赖中
  585. var hardCirclurDep = mod.depMkv[RegExp.$1];
  586. hardCirclurDep && (hardCirclurDep.hard = 1);
  587. // 如果是模块本身有问题导致的运行错误
  588. // 就不要把invoking置回去了,避免影响autoInvoke其他模块的初始化
  589. invoking = 0;
  590. return;
  591. }
  592. throw ex;
  593. }
  594. // 完成define
  595. // 不放在try里,避免后续的运行错误被这里吞掉
  596. modDefined(id);
  597. }
  598. }
  599. }
  600. /**
  601. * 判断模块是否完成相应的状态
  602. *
  603. * @inner
  604. * @param {string} id 模块标识
  605. * @param {number} state 状态码,使用时传入相应的枚举变量,比如`MODULE_DEFINED`
  606. * @return {boolean} 是否完成相应的状态
  607. */
  608. function modIs(id, state) {
  609. return modModules[id] && modModules[id].state >= state;
  610. }
  611. /**
  612. * 尝试执行模块factory函数,进行模块初始化
  613. *
  614. * @inner
  615. * @param {string} id 模块id
  616. */
  617. function modTryInvokeFactory(id) {
  618. var mod = modModules[id];
  619. if (mod && mod.invokeFactory) {
  620. mod.invokeFactory();
  621. }
  622. }
  623. /**
  624. * 根据模块id数组,获取其的exports数组
  625. * 用于模块初始化的factory参数或require的callback参数生成
  626. *
  627. * @inner
  628. * @param {Array} modules 模块id数组
  629. * @param {Object} buildinModules 内建模块对象
  630. * @return {Array} 模块exports数组
  631. */
  632. function modGetModulesExports(modules, buildinModules) {
  633. var args = [];
  634. each(
  635. modules,
  636. function (id, index) {
  637. if (typeof id === 'object') {
  638. id = id.absId;
  639. }
  640. args[index] = buildinModules[id] || modModules[id].exports;
  641. }
  642. );
  643. return args;
  644. }
  645. /**
  646. * 模块定义完成事件监听器容器
  647. *
  648. * @inner
  649. * @type {Object}
  650. */
  651. var modDefinedListeners = {};
  652. /**
  653. * 添加模块定义完成时间的监听器
  654. *
  655. * @inner
  656. * @param {string} id 模块标识
  657. * @param {Function} listener 监听函数
  658. */
  659. function modAddDefinedListener(id, listener) {
  660. if (modIs(id, MODULE_DEFINED)) {
  661. listener();
  662. return;
  663. }
  664. var listeners = modDefinedListeners[id];
  665. if (!listeners) {
  666. listeners = modDefinedListeners[id] = [];
  667. }
  668. listeners.push(listener);
  669. }
  670. /**
  671. * 模块状态切换为定义完成
  672. * 因为需要触发事件,MODULE_DEFINED状态切换通过该函数
  673. *
  674. * @inner
  675. * @param {string} id 模块标识
  676. */
  677. function modDefined(id) {
  678. var mod = modModules[id];
  679. mod.state = MODULE_DEFINED;
  680. delete modAutoDefineModules[id];
  681. var listeners = modDefinedListeners[id] || [];
  682. var len = listeners.length;
  683. while (len--) {
  684. // 这里不做function类型的检测
  685. // 因为listener都是通过modOn传入的,modOn为内部调用
  686. listeners[len]();
  687. }
  688. // 清理listeners
  689. listeners.length = 0;
  690. modDefinedListeners[id] = null;
  691. }
  692. /**
  693. * 异步加载模块
  694. * 内部使用,模块ID必须是经过normalize的Top-Level ID
  695. *
  696. * @inner
  697. * @param {Array} ids 模块名称或模块名称列表
  698. * @param {Function=} callback 获取模块完成时的回调函数
  699. * @param {string} baseId 基础id,用于当ids是relative id时的normalize
  700. */
  701. function nativeAsyncRequire(ids, callback, baseId) {
  702. var isCallbackCalled = 0;
  703. each(ids, function (id) {
  704. if (!(BUILDIN_MODULE[id] || modIs(id, MODULE_DEFINED))) {
  705. modAddDefinedListener(id, tryFinishRequire);
  706. (id.indexOf('!') > 0
  707. ? loadResource
  708. : loadModule
  709. )(id, baseId);
  710. }
  711. });
  712. tryFinishRequire();
  713. /**
  714. * 尝试完成require,调用callback
  715. * 在模块与其依赖模块都加载完时调用
  716. *
  717. * @inner
  718. */
  719. function tryFinishRequire() {
  720. if (typeof callback === 'function' && !isCallbackCalled) {
  721. var isAllCompleted = 1;
  722. each(ids, function (id) {
  723. if (!BUILDIN_MODULE[id]) {
  724. return (isAllCompleted = !!modIs(id, MODULE_DEFINED));
  725. }
  726. });
  727. // 检测并调用callback
  728. if (isAllCompleted) {
  729. isCallbackCalled = 1;
  730. callback.apply(
  731. global,
  732. modGetModulesExports(ids, BUILDIN_MODULE)
  733. );
  734. }
  735. }
  736. }
  737. }
  738. /**
  739. * 正在加载的模块列表
  740. *
  741. * @inner
  742. * @type {Object}
  743. */
  744. var loadingModules = {};
  745. /**
  746. * 加载模块
  747. *
  748. * @inner
  749. * @param {string} moduleId 模块标识
  750. */
  751. function loadModule(moduleId) {
  752. // 加载过的模块,就不要再继续了
  753. if (loadingModules[moduleId] || modModules[moduleId]) {
  754. return;
  755. }
  756. loadingModules[moduleId] = 1;
  757. // 初始化相关 shim 的配置
  758. var shimConf = requireConf.shim[moduleId];
  759. if (shimConf instanceof Array) {
  760. requireConf.shim[moduleId] = shimConf = {
  761. deps: shimConf
  762. };
  763. }
  764. // shim依赖的模块需要自动标识为shim
  765. // 无论是纯正的shim模块还是hybird模块
  766. var shimDeps = shimConf && (shimConf.deps || []);
  767. if (shimDeps) {
  768. each(shimDeps, function (dep) {
  769. if (!requireConf.shim[dep]) {
  770. requireConf.shim[dep] = {};
  771. }
  772. });
  773. actualGlobalRequire(shimDeps, load);
  774. }
  775. else {
  776. load();
  777. }
  778. /**
  779. * 发送请求去加载模块
  780. *
  781. * @inner
  782. */
  783. function load() {
  784. /* eslint-disable no-use-before-define */
  785. var bundleModuleId = bundlesIndex[moduleId];
  786. createScript(bundleModuleId || moduleId, loaded);
  787. /* eslint-enable no-use-before-define */
  788. }
  789. /**
  790. * script标签加载完成的事件处理函数
  791. *
  792. * @inner
  793. */
  794. function loaded() {
  795. if (shimConf) {
  796. var exports;
  797. if (typeof shimConf.init === 'function') {
  798. exports = shimConf.init.apply(
  799. global,
  800. modGetModulesExports(shimDeps, BUILDIN_MODULE)
  801. );
  802. }
  803. if (exports == null && shimConf.exports) {
  804. exports = global;
  805. each(
  806. shimConf.exports.split('.'),
  807. function (prop) {
  808. exports = exports[prop];
  809. return !!exports;
  810. }
  811. );
  812. }
  813. globalDefine(moduleId, shimDeps, exports || {});
  814. }
  815. else {
  816. modCompletePreDefine(moduleId);
  817. }
  818. modAutoDefine();
  819. }
  820. }
  821. /**
  822. * 加载资源
  823. *
  824. * @inner
  825. * @param {string} pluginAndResource 插件与资源标识
  826. * @param {string} baseId 当前环境的模块标识
  827. */
  828. function loadResource(pluginAndResource, baseId) {
  829. if (modModules[pluginAndResource]) {
  830. return;
  831. }
  832. /* eslint-disable no-use-before-define */
  833. var bundleModuleId = bundlesIndex[pluginAndResource];
  834. if (bundleModuleId) {
  835. loadModule(bundleModuleId);
  836. return;
  837. }
  838. /* eslint-enable no-use-before-define */
  839. var idInfo = parseId(pluginAndResource);
  840. var resource = {
  841. id: pluginAndResource,
  842. state: MODULE_ANALYZED
  843. };
  844. modModules[pluginAndResource] = resource;
  845. /**
  846. * plugin加载完成的回调函数
  847. *
  848. * @inner
  849. * @param {*} value resource的值
  850. */
  851. function pluginOnload(value) {
  852. resource.exports = value || true;
  853. modDefined(pluginAndResource);
  854. }
  855. /* jshint ignore:start */
  856. /**
  857. * 该方法允许plugin使用加载的资源声明模块
  858. *
  859. * @param {string} id 模块id
  860. * @param {string} text 模块声明字符串
  861. */
  862. pluginOnload.fromText = function (id, text) {
  863. new Function(text)();
  864. modCompletePreDefine(id);
  865. };
  866. /* jshint ignore:end */
  867. /**
  868. * 加载资源
  869. *
  870. * @inner
  871. * @param {Object} plugin 用于加载资源的插件模块
  872. */
  873. function load(plugin) {
  874. var pluginRequire = baseId
  875. ? modModules[baseId].require
  876. : actualGlobalRequire;
  877. plugin.load(
  878. idInfo.res,
  879. pluginRequire,
  880. pluginOnload,
  881. moduleConfigGetter.call({id: pluginAndResource})
  882. );
  883. }
  884. load(actualGlobalRequire(idInfo.mod));
  885. }
  886. /**
  887. * 配置require
  888. *
  889. * @param {Object} conf 配置对象
  890. */
  891. globalRequire.config = function (conf) {
  892. if (conf) {
  893. for (var key in requireConf) {
  894. var newValue = conf[key];
  895. var oldValue = requireConf[key];
  896. if (!newValue) {
  897. continue;
  898. }
  899. if (key === 'urlArgs' && typeof newValue === 'string') {
  900. requireConf.urlArgs['*'] = newValue;
  901. }
  902. else {
  903. // 简单的多处配置还是需要支持,所以配置实现为支持二级mix
  904. if (oldValue instanceof Array) {
  905. oldValue.push.apply(oldValue, newValue);
  906. }
  907. else if (typeof oldValue === 'object') {
  908. for (var k in newValue) {
  909. oldValue[k] = newValue[k];
  910. }
  911. }
  912. else {
  913. requireConf[key] = newValue;
  914. }
  915. }
  916. }
  917. createConfIndex();
  918. }
  919. };
  920. // 初始化时需要创建配置索引
  921. createConfIndex();
  922. /**
  923. * paths内部索引
  924. *
  925. * @inner
  926. * @type {Array}
  927. */
  928. var pathsIndex;
  929. /**
  930. * packages内部索引
  931. *
  932. * @inner
  933. * @type {Array}
  934. */
  935. var packagesIndex;
  936. /**
  937. * mapping内部索引
  938. *
  939. * @inner
  940. * @type {Array}
  941. */
  942. var mappingIdIndex;
  943. /**
  944. * bundles内部索引
  945. *
  946. * @inner
  947. * @type {Object}
  948. */
  949. var bundlesIndex;
  950. /**
  951. * urlArgs内部索引
  952. *
  953. * @inner
  954. * @type {Array}
  955. */
  956. var urlArgsIndex;
  957. /**
  958. * 将key为module id prefix的Object,生成数组形式的索引,并按照长度和字面排序
  959. *
  960. * @inner
  961. * @param {Object} value 源值
  962. * @param {boolean} allowAsterisk 是否允许*号表示匹配所有
  963. * @return {Array} 索引对象
  964. */
  965. function createKVSortedIndex(value, allowAsterisk) {
  966. var index = kv2List(value, 1, allowAsterisk);
  967. index.sort(descSorterByKOrName);
  968. return index;
  969. }
  970. /**
  971. * 创建配置信息内部索引
  972. *
  973. * @inner
  974. */
  975. function createConfIndex() {
  976. requireConf.baseUrl = requireConf.baseUrl.replace(/\/$/, '') + '/';
  977. // create paths index
  978. pathsIndex = createKVSortedIndex(requireConf.paths);
  979. // create mappingId index
  980. mappingIdIndex = createKVSortedIndex(requireConf.map, 1);
  981. each(
  982. mappingIdIndex,
  983. function (item) {
  984. item.v = createKVSortedIndex(item.v);
  985. }
  986. );
  987. // create packages index
  988. packagesIndex = [];
  989. each(
  990. requireConf.packages,
  991. function (packageConf) {
  992. var pkg = packageConf;
  993. if (typeof packageConf === 'string') {
  994. pkg = {
  995. name: packageConf.split('/')[0],
  996. location: packageConf,
  997. main: 'main'
  998. };
  999. }
  1000. pkg.location = pkg.location || pkg.name;
  1001. pkg.main = (pkg.main || 'main').replace(/\.js$/i, '');
  1002. pkg.reg = createPrefixRegexp(pkg.name);
  1003. packagesIndex.push(pkg);
  1004. }
  1005. );
  1006. packagesIndex.sort(descSorterByKOrName);
  1007. // create urlArgs index
  1008. urlArgsIndex = createKVSortedIndex(requireConf.urlArgs, 1);
  1009. // create bundles index
  1010. bundlesIndex = {};
  1011. /* eslint-disable no-use-before-define */
  1012. function bundlesIterator(id) {
  1013. bundlesIndex[id] = key;
  1014. }
  1015. /* eslint-enable no-use-before-define */
  1016. for (var key in requireConf.bundles) {
  1017. each(requireConf.bundles[key], bundlesIterator);
  1018. }
  1019. }
  1020. /**
  1021. * 对配置信息的索引进行检索
  1022. *
  1023. * @inner
  1024. * @param {string} value 要检索的值
  1025. * @param {Array} index 索引对象
  1026. * @param {Function} hitBehavior 索引命中的行为函数
  1027. */
  1028. function indexRetrieve(value, index, hitBehavior) {
  1029. each(index, function (item) {
  1030. if (item.reg.test(value)) {
  1031. hitBehavior(item.v, item.k, item);
  1032. return false;
  1033. }
  1034. });
  1035. }
  1036. /**
  1037. * 将`模块标识+'.extension'`形式的字符串转换成相对的url
  1038. *
  1039. * @inner
  1040. * @param {string} source 源字符串
  1041. * @return {string} url
  1042. */
  1043. function toUrl(source) {
  1044. // 分离 模块标识 和 .extension
  1045. var extReg = /(\.[a-z0-9]+)$/i;
  1046. var queryReg = /(\?[^#]*)$/;
  1047. var extname = '';
  1048. var id = source;
  1049. var query = '';
  1050. if (queryReg.test(source)) {
  1051. query = RegExp.$1;
  1052. source = source.replace(queryReg, '');
  1053. }
  1054. if (extReg.test(source)) {
  1055. extname = RegExp.$1;
  1056. id = source.replace(extReg, '');
  1057. }
  1058. var url = id;
  1059. // paths处理和匹配
  1060. var isPathMap;
  1061. indexRetrieve(id, pathsIndex, function (value, key) {
  1062. url = url.replace(key, value);
  1063. isPathMap = 1;
  1064. });
  1065. // packages处理和匹配
  1066. if (!isPathMap) {
  1067. indexRetrieve(id, packagesIndex, function (value, key, item) {
  1068. url = url.replace(item.name, item.location);
  1069. });
  1070. }
  1071. // 相对路径时,附加baseUrl
  1072. if (!/^([a-z]{2,10}:\/)?\//i.test(url)) {
  1073. url = requireConf.baseUrl + url;
  1074. }
  1075. // 附加 .extension 和 query
  1076. url += extname + query;
  1077. // urlArgs处理和匹配
  1078. indexRetrieve(id, urlArgsIndex, function (value) {
  1079. url += (url.indexOf('?') > 0 ? '&' : '?') + value;
  1080. });
  1081. return url;
  1082. }
  1083. /**
  1084. * 创建local require函数
  1085. *
  1086. * @inner
  1087. * @param {number} baseId 当前module id
  1088. * @return {Function} local require函数
  1089. */
  1090. function createLocalRequire(baseId) {
  1091. var requiredCache = {};
  1092. function req(requireId, callback) {
  1093. if (typeof requireId === 'string') {
  1094. if (!requiredCache[requireId]) {
  1095. var topLevelId = normalize(requireId, baseId);
  1096. // 根据 https://github.com/amdjs/amdjs-api/wiki/require
  1097. // It MUST throw an error if the module has not
  1098. // already been loaded and evaluated.
  1099. modTryInvokeFactory(topLevelId);
  1100. if (!modIs(topLevelId, MODULE_DEFINED)) {
  1101. throw new Error('[MODULE_MISS]"' + topLevelId + '" is not exists!');
  1102. }
  1103. requiredCache[requireId] = modModules[topLevelId].exports;
  1104. }
  1105. return requiredCache[requireId];
  1106. }
  1107. else if (requireId instanceof Array) {
  1108. // 分析是否有resource,取出pluginModule先
  1109. var pureModules = [];
  1110. var normalizedIds = [];
  1111. each(
  1112. requireId,
  1113. function (id, i) {
  1114. var idInfo = parseId(id);
  1115. var absId = normalize(idInfo.mod, baseId);
  1116. var resId = idInfo.res;
  1117. var normalizedId = absId;
  1118. if (resId) {
  1119. var trueResId = absId + '!' + resId;
  1120. if (resId.indexOf('.') !== 0 && bundlesIndex[trueResId]) {
  1121. absId = normalizedId = trueResId;
  1122. }
  1123. else {
  1124. normalizedId = null;
  1125. }
  1126. }
  1127. normalizedIds[i] = normalizedId;
  1128. modFlagAutoDefine(absId);
  1129. pureModules.push(absId);
  1130. }
  1131. );
  1132. // 加载模块
  1133. nativeAsyncRequire(
  1134. pureModules,
  1135. function () {
  1136. /* jshint ignore:start */
  1137. each(normalizedIds, function (id, i) {
  1138. if (id == null) {
  1139. id = normalizedIds[i] = normalize(requireId[i], baseId);
  1140. modFlagAutoDefine(id);
  1141. }
  1142. });
  1143. /* jshint ignore:end */
  1144. // modAutoDefine中,factory invoke可能发生错误
  1145. // 从而导致nativeAsyncRequire没有被调用,callback没挂上
  1146. // 所以nativeAsyncRequire要先运行
  1147. nativeAsyncRequire(normalizedIds, callback, baseId);
  1148. modAutoDefine();
  1149. },
  1150. baseId
  1151. );
  1152. modAutoDefine();
  1153. }
  1154. }
  1155. /**
  1156. * 将[module ID] + '.extension'格式的字符串转换成url
  1157. *
  1158. * @inner
  1159. * @param {string} id 符合描述格式的源字符串
  1160. * @return {string} url
  1161. */
  1162. req.toUrl = function (id) {
  1163. return toUrl(normalize(id, baseId));
  1164. };
  1165. return req;
  1166. }
  1167. /**
  1168. * id normalize化
  1169. *
  1170. * @inner
  1171. * @param {string} id 需要normalize的模块标识
  1172. * @param {string} baseId 当前环境的模块标识
  1173. * @return {string} normalize结果
  1174. */
  1175. function normalize(id, baseId) {
  1176. if (!id) {
  1177. return '';
  1178. }
  1179. baseId = baseId || '';
  1180. var idInfo = parseId(id);
  1181. if (!idInfo) {
  1182. return id;
  1183. }
  1184. var resourceId = idInfo.res;
  1185. var moduleId = relative2absolute(idInfo.mod, baseId);
  1186. each(
  1187. packagesIndex,
  1188. function (packageConf) {
  1189. var name = packageConf.name;
  1190. if (name === moduleId) {
  1191. moduleId = name + '/' + packageConf.main;
  1192. return false;
  1193. }
  1194. }
  1195. );
  1196. // 根据config中的map配置进行module id mapping
  1197. indexRetrieve(
  1198. baseId,
  1199. mappingIdIndex,
  1200. function (value) {
  1201. indexRetrieve(
  1202. moduleId,
  1203. value,
  1204. function (mdValue, mdKey) {
  1205. moduleId = moduleId.replace(mdKey, mdValue);
  1206. }
  1207. );
  1208. }
  1209. );
  1210. if (resourceId) {
  1211. var mod = modIs(moduleId, MODULE_DEFINED) && actualGlobalRequire(moduleId);
  1212. resourceId = mod && mod.normalize
  1213. ? mod.normalize(
  1214. resourceId,
  1215. function (resId) {
  1216. return normalize(resId, baseId);
  1217. }
  1218. )
  1219. : normalize(resourceId, baseId);
  1220. moduleId += '!' + resourceId;
  1221. }
  1222. return moduleId;
  1223. }
  1224. /**
  1225. * 相对id转换成绝对id
  1226. *
  1227. * @inner
  1228. * @param {string} id 要转换的相对id
  1229. * @param {string} baseId 当前所在环境id
  1230. * @return {string} 绝对id
  1231. */
  1232. function relative2absolute(id, baseId) {
  1233. if (id.indexOf('.') === 0) {
  1234. var basePath = baseId.split('/');
  1235. var namePath = id.split('/');
  1236. var baseLen = basePath.length - 1;
  1237. var nameLen = namePath.length;
  1238. var cutBaseTerms = 0;
  1239. var cutNameTerms = 0;
  1240. /* eslint-disable block-scoped-var */
  1241. pathLoop: for (var i = 0; i < nameLen; i++) {
  1242. switch (namePath[i]) {
  1243. case '..':
  1244. if (cutBaseTerms < baseLen) {
  1245. cutBaseTerms++;
  1246. cutNameTerms++;
  1247. }
  1248. else {
  1249. break pathLoop;
  1250. }
  1251. break;
  1252. case '.':
  1253. cutNameTerms++;
  1254. break;
  1255. default:
  1256. break pathLoop;
  1257. }
  1258. }
  1259. /* eslint-enable block-scoped-var */
  1260. basePath.length = baseLen - cutBaseTerms;
  1261. namePath = namePath.slice(cutNameTerms);
  1262. return basePath.concat(namePath).join('/');
  1263. }
  1264. return id;
  1265. }
  1266. /**
  1267. * 解析id,返回带有module和resource属性的Object
  1268. *
  1269. * @inner
  1270. * @param {string} id 标识
  1271. * @return {Object} id解析结果对象
  1272. */
  1273. function parseId(id) {
  1274. var segs = id.split('!');
  1275. if (segs[0]) {
  1276. return {
  1277. mod: segs[0],
  1278. res: segs[1]
  1279. };
  1280. }
  1281. }
  1282. /**
  1283. * 将对象数据转换成数组,数组每项是带有k和v的Object
  1284. *
  1285. * @inner
  1286. * @param {Object} source 对象数据
  1287. * @param {boolean} keyMatchable key是否允许被前缀匹配
  1288. * @param {boolean} allowAsterisk 是否支持*匹配所有
  1289. * @return {Array.<Object>} 对象转换数组
  1290. */
  1291. function kv2List(source, keyMatchable, allowAsterisk) {
  1292. var list = [];
  1293. for (var key in source) {
  1294. if (source.hasOwnProperty(key)) {
  1295. var item = {
  1296. k: key,
  1297. v: source[key]
  1298. };
  1299. list.push(item);
  1300. if (keyMatchable) {
  1301. item.reg = key === '*' && allowAsterisk
  1302. ? /^/
  1303. : createPrefixRegexp(key);
  1304. }
  1305. }
  1306. }
  1307. return list;
  1308. }
  1309. // 感谢requirejs,通过currentlyAddingScript兼容老旧ie
  1310. //
  1311. // For some cache cases in IE 6-8, the script executes before the end
  1312. // of the appendChild execution, so to tie an anonymous define
  1313. // call to the module name (which is stored on the node), hold on
  1314. // to a reference to this node, but clear after the DOM insertion.
  1315. var currentlyAddingScript;
  1316. var interactiveScript;
  1317. /**
  1318. * 获取当前script标签
  1319. * 用于ie下define未指定module id时获取id
  1320. *
  1321. * @inner
  1322. * @return {HTMLScriptElement} 当前script标签
  1323. */
  1324. function getCurrentScript() {
  1325. if (currentlyAddingScript) {
  1326. return currentlyAddingScript;
  1327. }
  1328. else if (
  1329. interactiveScript
  1330. && interactiveScript.readyState === 'interactive'
  1331. ) {
  1332. return interactiveScript;
  1333. }
  1334. var scripts = document.getElementsByTagName('script');
  1335. var scriptLen = scripts.length;
  1336. while (scriptLen--) {
  1337. var script = scripts[scriptLen];
  1338. if (script.readyState === 'interactive') {
  1339. interactiveScript = script;
  1340. return script;
  1341. }
  1342. }
  1343. }
  1344. var headElement = document.getElementsByTagName('head')[0];
  1345. var baseElement = document.getElementsByTagName('base')[0];
  1346. if (baseElement) {
  1347. headElement = baseElement.parentNode;
  1348. }
  1349. function createScript(moduleId, onload) {
  1350. // 创建script标签
  1351. //
  1352. // 这里不挂接onerror的错误处理
  1353. // 因为高级浏览器在devtool的console面板会报错
  1354. // 再throw一个Error多此一举了
  1355. var script = document.createElement('script');
  1356. script.setAttribute('data-require-id', moduleId);
  1357. script.src = toUrl(moduleId + '.js');
  1358. script.async = true;
  1359. if (script.readyState) {
  1360. script.onreadystatechange = innerOnload;
  1361. }
  1362. else {
  1363. script.onload = innerOnload;
  1364. }
  1365. function innerOnload() {
  1366. var readyState = script.readyState;
  1367. if (
  1368. typeof readyState === 'undefined'
  1369. || /^(loaded|complete)$/.test(readyState)
  1370. ) {
  1371. script.onload = script.onreadystatechange = null;
  1372. script = null;
  1373. onload();
  1374. }
  1375. }
  1376. currentlyAddingScript = script;
  1377. // If BASE tag is in play, using appendChild is a problem for IE6.
  1378. // See: http://dev.jquery.com/ticket/2709
  1379. baseElement
  1380. ? headElement.insertBefore(script, baseElement)
  1381. : headElement.appendChild(script);
  1382. currentlyAddingScript = null;
  1383. }
  1384. /**
  1385. * 创建id前缀匹配的正则对象
  1386. *
  1387. * @inner
  1388. * @param {string} prefix id前缀
  1389. * @return {RegExp} 前缀匹配的正则对象
  1390. */
  1391. function createPrefixRegexp(prefix) {
  1392. return new RegExp('^' + prefix + '(/|$)');
  1393. }
  1394. /**
  1395. * 循环遍历数组集合
  1396. *
  1397. * @inner
  1398. * @param {Array} source 数组源
  1399. * @param {function(Array,Number):boolean} iterator 遍历函数
  1400. */
  1401. function each(source, iterator) {
  1402. if (source instanceof Array) {
  1403. for (var i = 0, len = source.length; i < len; i++) {
  1404. if (iterator(source[i], i) === false) {
  1405. break;
  1406. }
  1407. }
  1408. }
  1409. }
  1410. /**
  1411. * 根据元素的k或name项进行数组字符数逆序的排序函数
  1412. *
  1413. * @inner
  1414. * @param {Object} a 要比较的对象a
  1415. * @param {Object} b 要比较的对象b
  1416. * @return {number} 比较结果
  1417. */
  1418. function descSorterByKOrName(a, b) {
  1419. var aValue = a.k || a.name;
  1420. var bValue = b.k || b.name;
  1421. if (bValue === '*') {
  1422. return -1;
  1423. }
  1424. if (aValue === '*') {
  1425. return 1;
  1426. }
  1427. return bValue.length - aValue.length;
  1428. }
  1429. // 暴露全局对象
  1430. if (!define) {
  1431. define = globalDefine;
  1432. // 可能碰到其他形式的loader,所以,不要覆盖人家
  1433. if (!require) {
  1434. require = globalRequire;
  1435. }
  1436. // 如果存在其他版本的esl,在define那里就判断过了,不会进入这个分支
  1437. // 所以这里就不判断了,直接写
  1438. esl = globalRequire;
  1439. }
  1440. })(this);
  1441. define('echarts', ['echarts/echarts'], function (main) {return main;});
  1442. define('echarts/echarts', [
  1443. 'require',
  1444. './config',
  1445. 'zrender/tool/util',
  1446. 'zrender/tool/event',
  1447. 'zrender/tool/env',
  1448. 'zrender',
  1449. 'zrender/config',
  1450. './chart/island',
  1451. './component/toolbox',
  1452. './component',
  1453. './component/title',
  1454. './component/tooltip',
  1455. './component/legend',
  1456. './util/ecData',
  1457. './chart',
  1458. 'zrender/tool/color',
  1459. './component/timeline',
  1460. 'zrender/shape/Image',
  1461. 'zrender/loadingEffect/Bar',
  1462. 'zrender/loadingEffect/Bubble',
  1463. 'zrender/loadingEffect/DynamicLine',
  1464. 'zrender/loadingEffect/Ring',
  1465. 'zrender/loadingEffect/Spin',
  1466. 'zrender/loadingEffect/Whirling',
  1467. './theme/macarons',
  1468. './theme/infographic'
  1469. ], function (require) {
  1470. var ecConfig = require('./config');
  1471. var zrUtil = require('zrender/tool/util');
  1472. var zrEvent = require('zrender/tool/event');
  1473. var self = {};
  1474. var _canvasSupported = require('zrender/tool/env').canvasSupported;
  1475. var _idBase = new Date() - 0;
  1476. var _instances = {};
  1477. var DOM_ATTRIBUTE_KEY = '_echarts_instance_';
  1478. self.version = '2.2.7';
  1479. self.dependencies = { zrender: '2.1.1' };
  1480. self.init = function (dom, theme) {
  1481. var zrender = require('zrender');
  1482. if (zrender.version.replace('.', '') - 0 < self.dependencies.zrender.replace('.', '') - 0) {
  1483. console.error('ZRender ' + zrender.version + ' is too old for ECharts ' + self.version + '. Current version need ZRender ' + self.dependencies.zrender + '+');
  1484. }
  1485. dom = dom instanceof Array ? dom[0] : dom;
  1486. var key = dom.getAttribute(DOM_ATTRIBUTE_KEY);
  1487. if (!key) {
  1488. key = _idBase++;
  1489. dom.setAttribute(DOM_ATTRIBUTE_KEY, key);
  1490. }
  1491. if (_instances[key]) {
  1492. _instances[key].dispose();
  1493. }
  1494. _instances[key] = new Echarts(dom);
  1495. _instances[key].id = key;
  1496. _instances[key].canvasSupported = _canvasSupported;
  1497. _instances[key].setTheme(theme);
  1498. return _instances[key];
  1499. };
  1500. self.getInstanceById = function (key) {
  1501. return _instances[key];
  1502. };
  1503. function MessageCenter() {
  1504. zrEvent.Dispatcher.call(this);
  1505. }
  1506. zrUtil.merge(MessageCenter.prototype, zrEvent.Dispatcher.prototype, true);
  1507. function Echarts(dom) {
  1508. dom.innerHTML = '';
  1509. this._themeConfig = {};
  1510. this.dom = dom;
  1511. this._connected = false;
  1512. this._status = {
  1513. dragIn: false,
  1514. dragOut: false,
  1515. needRefresh: false
  1516. };
  1517. this._curEventType = false;
  1518. this._chartList = [];
  1519. this._messageCenter = new MessageCenter();
  1520. this._messageCenterOutSide = new MessageCenter();
  1521. this.resize = this.resize();
  1522. this._init();
  1523. }
  1524. var ZR_EVENT = require('zrender/config').EVENT;
  1525. var ZR_EVENT_LISTENS = [
  1526. 'CLICK',
  1527. 'DBLCLICK',
  1528. 'MOUSEOVER',
  1529. 'MOUSEOUT',
  1530. 'DRAGSTART',
  1531. 'DRAGEND',
  1532. 'DRAGENTER',
  1533. 'DRAGOVER',
  1534. 'DRAGLEAVE',
  1535. 'DROP'
  1536. ];
  1537. function callChartListMethodReverse(ecInstance, methodName, arg0, arg1, arg2) {
  1538. var chartList = ecInstance._chartList;
  1539. var len = chartList.length;
  1540. while (len--) {
  1541. var chart = chartList[len];
  1542. if (typeof chart[methodName] === 'function') {
  1543. chart[methodName](arg0, arg1, arg2);
  1544. }
  1545. }
  1546. }
  1547. Echarts.prototype = {
  1548. _init: function () {
  1549. var self = this;
  1550. var _zr = require('zrender').init(this.dom);
  1551. this._zr = _zr;
  1552. this._messageCenter.dispatch = function (type, event, eventPackage, that) {
  1553. eventPackage = eventPackage || {};
  1554. eventPackage.type = type;
  1555. eventPackage.event = event;
  1556. self._messageCenter.dispatchWithContext(type, eventPackage, that);
  1557. self._messageCenterOutSide.dispatchWithContext(type, eventPackage, that);
  1558. };
  1559. this._onevent = function (param) {
  1560. return self.__onevent(param);
  1561. };
  1562. for (var e in ecConfig.EVENT) {
  1563. if (e != 'CLICK' && e != 'DBLCLICK' && e != 'HOVER' && e != 'MOUSEOUT' && e != 'MAP_ROAM') {
  1564. this._messageCenter.bind(ecConfig.EVENT[e], this._onevent, this);
  1565. }
  1566. }
  1567. var eventBehaviors = {};
  1568. this._onzrevent = function (param) {
  1569. return self[eventBehaviors[param.type]](param);
  1570. };
  1571. for (var i = 0, len = ZR_EVENT_LISTENS.length; i < len; i++) {
  1572. var eventName = ZR_EVENT_LISTENS[i];
  1573. var eventValue = ZR_EVENT[eventName];
  1574. eventBehaviors[eventValue] = '_on' + eventName.toLowerCase();
  1575. _zr.on(eventValue, this._onzrevent);
  1576. }
  1577. this.chart = {};
  1578. this.component = {};
  1579. var Island = require('./chart/island');
  1580. this._island = new Island(this._themeConfig, this._messageCenter, _zr, {}, this);
  1581. this.chart.island = this._island;
  1582. var Toolbox = require('./component/toolbox');
  1583. this._toolbox = new Toolbox(this._themeConfig, this._messageCenter, _zr, {}, this);
  1584. this.component.toolbox = this._toolbox;
  1585. var componentLibrary = require('./component');
  1586. componentLibrary.define('title', require('./component/title'));
  1587. componentLibrary.define('tooltip', require('./component/tooltip'));
  1588. componentLibrary.define('legend', require('./component/legend'));
  1589. if (_zr.getWidth() === 0 || _zr.getHeight() === 0) {
  1590. console.error('Dom’s width & height should be ready before init.');
  1591. }
  1592. },
  1593. __onevent: function (param) {
  1594. param.__echartsId = param.__echartsId || this.id;
  1595. var fromMyself = param.__echartsId === this.id;
  1596. if (!this._curEventType) {
  1597. this._curEventType = param.type;
  1598. }
  1599. switch (param.type) {
  1600. case ecConfig.EVENT.LEGEND_SELECTED:
  1601. this._onlegendSelected(param);
  1602. break;
  1603. case ecConfig.EVENT.DATA_ZOOM:
  1604. if (!fromMyself) {
  1605. var dz = this.component.dataZoom;
  1606. if (dz) {
  1607. dz.silence(true);
  1608. dz.absoluteZoom(param.zoom);
  1609. dz.silence(false);
  1610. }
  1611. }
  1612. this._ondataZoom(param);
  1613. break;
  1614. case ecConfig.EVENT.DATA_RANGE:
  1615. fromMyself && this._ondataRange(param);
  1616. break;
  1617. case ecConfig.EVENT.MAGIC_TYPE_CHANGED:
  1618. if (!fromMyself) {
  1619. var tb = this.component.toolbox;
  1620. if (tb) {
  1621. tb.silence(true);
  1622. tb.setMagicType(param.magicType);
  1623. tb.silence(false);
  1624. }
  1625. }
  1626. this._onmagicTypeChanged(param);
  1627. break;
  1628. case ecConfig.EVENT.DATA_VIEW_CHANGED:
  1629. fromMyself && this._ondataViewChanged(param);
  1630. break;
  1631. case ecConfig.EVENT.TOOLTIP_HOVER:
  1632. fromMyself && this._tooltipHover(param);
  1633. break;
  1634. case ecConfig.EVENT.RESTORE:
  1635. this._onrestore();
  1636. break;
  1637. case ecConfig.EVENT.REFRESH:
  1638. fromMyself && this._onrefresh(param);
  1639. break;
  1640. case ecConfig.EVENT.TOOLTIP_IN_GRID:
  1641. case ecConfig.EVENT.TOOLTIP_OUT_GRID:
  1642. if (!fromMyself) {
  1643. var grid = this.component.grid;
  1644. if (grid) {
  1645. this._zr.trigger('mousemove', {
  1646. connectTrigger: true,
  1647. zrenderX: grid.getX() + param.x * grid.getWidth(),
  1648. zrenderY: grid.getY() + param.y * grid.getHeight()
  1649. });
  1650. }
  1651. } else if (this._connected) {
  1652. var grid = this.component.grid;
  1653. if (grid) {
  1654. param.x = (param.event.zrenderX - grid.getX()) / grid.getWidth();
  1655. param.y = (param.event.zrenderY - grid.getY()) / grid.getHeight();
  1656. }
  1657. }
  1658. break;
  1659. }
  1660. if (this._connected && fromMyself && this._curEventType === param.type) {
  1661. for (var c in this._connected) {
  1662. this._connected[c].connectedEventHandler(param);
  1663. }
  1664. this._curEventType = null;
  1665. }
  1666. if (!fromMyself || !this._connected && fromMyself) {
  1667. this._curEventType = null;
  1668. }
  1669. },
  1670. _onclick: function (param) {
  1671. callChartListMethodReverse(this, 'onclick', param);
  1672. if (param.target) {
  1673. var ecData = this._eventPackage(param.target);
  1674. if (ecData && ecData.seriesIndex != null) {
  1675. this._messageCenter.dispatch(ecConfig.EVENT.CLICK, param.event, ecData, this);
  1676. }
  1677. }
  1678. },
  1679. _ondblclick: function (param) {
  1680. callChartListMethodReverse(this, 'ondblclick', param);
  1681. if (param.target) {
  1682. var ecData = this._eventPackage(param.target);
  1683. if (ecData && ecData.seriesIndex != null) {
  1684. this._messageCenter.dispatch(ecConfig.EVENT.DBLCLICK, param.event, ecData, this);
  1685. }
  1686. }
  1687. },
  1688. _onmouseover: function (param) {
  1689. if (param.target) {
  1690. var ecData = this._eventPackage(param.target);
  1691. if (ecData && ecData.seriesIndex != null) {
  1692. this._messageCenter.dispatch(ecConfig.EVENT.HOVER, param.event, ecData, this);
  1693. }
  1694. }
  1695. },
  1696. _onmouseout: function (param) {
  1697. if (param.target) {
  1698. var ecData = this._eventPackage(param.target);
  1699. if (ecData && ecData.seriesIndex != null) {
  1700. this._messageCenter.dispatch(ecConfig.EVENT.MOUSEOUT, param.event, ecData, this);
  1701. }
  1702. }
  1703. },
  1704. _ondragstart: function (param) {
  1705. this._status = {
  1706. dragIn: false,
  1707. dragOut: false,
  1708. needRefresh: false
  1709. };
  1710. callChartListMethodReverse(this, 'ondragstart', param);
  1711. },
  1712. _ondragenter: function (param) {
  1713. callChartListMethodReverse(this, 'ondragenter', param);
  1714. },
  1715. _ondragover: function (param) {
  1716. callChartListMethodReverse(this, 'ondragover', param);
  1717. },
  1718. _ondragleave: function (param) {
  1719. callChartListMethodReverse(this, 'ondragleave', param);
  1720. },
  1721. _ondrop: function (param) {
  1722. callChartListMethodReverse(this, 'ondrop', param, this._status);
  1723. this._island.ondrop(param, this._status);
  1724. },
  1725. _ondragend: function (param) {
  1726. callChartListMethodReverse(this, 'ondragend', param, this._status);
  1727. this._timeline && this._timeline.ondragend(param, this._status);
  1728. this._island.ondragend(param, this._status);
  1729. if (this._status.needRefresh) {
  1730. this._syncBackupData(this._option);
  1731. var messageCenter = this._messageCenter;
  1732. messageCenter.dispatch(ecConfig.EVENT.DATA_CHANGED, param.event, this._eventPackage(param.target), this);
  1733. messageCenter.dispatch(ecConfig.EVENT.REFRESH, null, null, this);
  1734. }
  1735. },
  1736. _onlegendSelected: function (param) {
  1737. this._status.needRefresh = false;
  1738. callChartListMethodReverse(this, 'onlegendSelected', param, this._status);
  1739. if (this._status.needRefresh) {
  1740. this._messageCenter.dispatch(ecConfig.EVENT.REFRESH, null, null, this);
  1741. }
  1742. },
  1743. _ondataZoom: function (param) {
  1744. this._status.needRefresh = false;
  1745. callChartListMethodReverse(this, 'ondataZoom', param, this._status);
  1746. if (this._status.needRefresh) {
  1747. this._messageCenter.dispatch(ecConfig.EVENT.REFRESH, null, null, this);
  1748. }
  1749. },
  1750. _ondataRange: function (param) {
  1751. this._clearEffect();
  1752. this._status.needRefresh = false;
  1753. callChartListMethodReverse(this, 'ondataRange', param, this._status);
  1754. if (this._status.needRefresh) {
  1755. this._zr.refreshNextFrame();
  1756. }
  1757. },
  1758. _onmagicTypeChanged: function () {
  1759. this._clearEffect();
  1760. this._render(this._toolbox.getMagicOption());
  1761. },
  1762. _ondataViewChanged: function (param) {
  1763. this._syncBackupData(param.option);
  1764. this._messageCenter.dispatch(ecConfig.EVENT.DATA_CHANGED, null, param, this);
  1765. this._messageCenter.dispatch(ecConfig.EVENT.REFRESH, null, null, this);
  1766. },
  1767. _tooltipHover: function (param) {
  1768. var tipShape = [];
  1769. callChartListMethodReverse(this, 'ontooltipHover', param, tipShape);
  1770. },
  1771. _onrestore: function () {
  1772. this.restore();
  1773. },
  1774. _onrefresh: function (param) {
  1775. this._refreshInside = true;
  1776. this.refresh(param);
  1777. this._refreshInside = false;
  1778. },
  1779. _syncBackupData: function (curOption) {
  1780. this.component.dataZoom && this.component.dataZoom.syncBackupData(curOption);
  1781. },
  1782. _eventPackage: function (target) {
  1783. if (target) {
  1784. var ecData = require('./util/ecData');
  1785. var seriesIndex = ecData.get(target, 'seriesIndex');
  1786. var dataIndex = ecData.get(target, 'dataIndex');
  1787. dataIndex = seriesIndex != -1 && this.component.dataZoom ? this.component.dataZoom.getRealDataIndex(seriesIndex, dataIndex) : dataIndex;
  1788. return {
  1789. seriesIndex: seriesIndex,
  1790. seriesName: (ecData.get(target, 'series') || {}).name,
  1791. dataIndex: dataIndex,
  1792. data: ecData.get(target, 'data'),
  1793. name: ecData.get(target, 'name'),
  1794. value: ecData.get(target, 'value'),
  1795. special: ecData.get(target, 'special')
  1796. };
  1797. }
  1798. return;
  1799. },
  1800. _noDataCheck: function (magicOption) {
  1801. var series = magicOption.series;
  1802. for (var i = 0, l = series.length; i < l; i++) {
  1803. if (series[i].type == ecConfig.CHART_TYPE_MAP || series[i].data && series[i].data.length > 0 || series[i].markPoint && series[i].markPoint.data && series[i].markPoint.data.length > 0 || series[i].markLine && series[i].markLine.data && series[i].markLine.data.length > 0 || series[i].nodes && series[i].nodes.length > 0 || series[i].links && series[i].links.length > 0 || series[i].matrix && series[i].matrix.length > 0 || series[i].eventList && series[i].eventList.length > 0) {
  1804. return false;
  1805. }
  1806. }
  1807. var loadOption = this._option && this._option.noDataLoadingOption || this._themeConfig.noDataLoadingOption || ecConfig.noDataLoadingOption || {
  1808. text: this._option && this._option.noDataText || this._themeConfig.noDataText || ecConfig.noDataText,
  1809. effect: this._option && this._option.noDataEffect || this._themeConfig.noDataEffect || ecConfig.noDataEffect
  1810. };
  1811. this.clear();
  1812. this.showLoading(loadOption);
  1813. return true;
  1814. },
  1815. _render: function (magicOption) {
  1816. this._mergeGlobalConifg(magicOption);
  1817. if (this._noDataCheck(magicOption)) {
  1818. return;
  1819. }
  1820. var bgColor = magicOption.backgroundColor;
  1821. if (bgColor) {
  1822. if (!_canvasSupported && bgColor.indexOf('rgba') != -1) {
  1823. var cList = bgColor.split(',');
  1824. this.dom.style.filter = 'alpha(opacity=' + cList[3].substring(0, cList[3].lastIndexOf(')')) * 100 + ')';
  1825. cList.length = 3;
  1826. cList[0] = cList[0].replace('a', '');
  1827. this.dom.style.backgroundColor = cList.join(',') + ')';
  1828. } else {
  1829. this.dom.style.backgroundColor = bgColor;
  1830. }
  1831. }
  1832. this._zr.clearAnimation();
  1833. this._chartList = [];
  1834. var chartLibrary = require('./chart');
  1835. var componentLibrary = require('./component');
  1836. if (magicOption.xAxis || magicOption.yAxis) {
  1837. magicOption.grid = magicOption.grid || {};
  1838. magicOption.dataZoom = magicOption.dataZoom || {};
  1839. }
  1840. var componentList = [
  1841. 'title',
  1842. 'legend',
  1843. 'tooltip',
  1844. 'dataRange',
  1845. 'roamController',
  1846. 'grid',
  1847. 'dataZoom',
  1848. 'xAxis',
  1849. 'yAxis',
  1850. 'polar'
  1851. ];
  1852. var ComponentClass;
  1853. var componentType;
  1854. var component;
  1855. for (var i = 0, l = componentList.length; i < l; i++) {
  1856. componentType = componentList[i];
  1857. component = this.component[componentType];
  1858. if (magicOption[componentType]) {
  1859. if (component) {
  1860. component.refresh && component.refresh(magicOption);
  1861. } else {
  1862. ComponentClass = componentLibrary.get(/^[xy]Axis$/.test(componentType) ? 'axis' : componentType);
  1863. component = new ComponentClass(this._themeConfig, this._messageCenter, this._zr, magicOption, this, componentType);
  1864. this.component[componentType] = component;
  1865. }
  1866. this._chartList.push(component);
  1867. } else if (component) {
  1868. component.dispose();
  1869. this.component[componentType] = null;
  1870. delete this.component[componentType];
  1871. }
  1872. }
  1873. var ChartClass;
  1874. var chartType;
  1875. var chart;
  1876. var chartMap = {};
  1877. for (var i = 0, l = magicOption.series.length; i < l; i++) {
  1878. chartType = magicOption.series[i].type;
  1879. if (!chartType) {
  1880. console.error('series[' + i + '] chart type has not been defined.');
  1881. continue;
  1882. }
  1883. if (!chartMap[chartType]) {
  1884. chartMap[chartType] = true;
  1885. ChartClass = chartLibrary.get(chartType);
  1886. if (ChartClass) {
  1887. if (this.chart[chartType]) {
  1888. chart = this.chart[chartType];
  1889. chart.refresh(magicOption);
  1890. } else {
  1891. chart = new ChartClass(this._themeConfig, this._messageCenter, this._zr, magicOption, this);
  1892. }
  1893. this._chartList.push(chart);
  1894. this.chart[chartType] = chart;
  1895. } else {
  1896. console.error(chartType + ' has not been required.');
  1897. }
  1898. }
  1899. }
  1900. for (chartType in this.chart) {
  1901. if (chartType != ecConfig.CHART_TYPE_ISLAND && !chartMap[chartType]) {
  1902. this.chart[chartType].dispose();
  1903. this.chart[chartType] = null;
  1904. delete this.chart[chartType];
  1905. }
  1906. }
  1907. this.component.grid && this.component.grid.refixAxisShape(this.component);
  1908. this._island.refresh(magicOption);
  1909. this._toolbox.refresh(magicOption);
  1910. magicOption.animation && !magicOption.renderAsImage ? this._zr.refresh() : this._zr.render();
  1911. var imgId = 'IMG' + this.id;
  1912. var img = document.getElementById(imgId);
  1913. if (magicOption.renderAsImage && _canvasSupported) {
  1914. if (img) {
  1915. img.src = this.getDataURL(magicOption.renderAsImage);
  1916. } else {
  1917. img = this.getImage(magicOption.renderAsImage);
  1918. img.id = imgId;
  1919. img.style.position = 'absolute';
  1920. img.style.left = 0;
  1921. img.style.top = 0;
  1922. this.dom.firstChild.appendChild(img);
  1923. }
  1924. this.un();
  1925. this._zr.un();
  1926. this._disposeChartList();
  1927. this._zr.clear();
  1928. } else if (img) {
  1929. img.parentNode.removeChild(img);
  1930. }
  1931. img = null;
  1932. this._option = magicOption;
  1933. },
  1934. restore: function () {
  1935. this._clearEffect();
  1936. this._option = zrUtil.clone(this._optionRestore);
  1937. this._disposeChartList();
  1938. this._island.clear();
  1939. this._toolbox.reset(this._option, true);
  1940. this._render(this._option);
  1941. },
  1942. refresh: function (param) {
  1943. this._clearEffect();
  1944. param = param || {};
  1945. var magicOption = param.option;
  1946. if (!this._refreshInside && magicOption) {
  1947. magicOption = this.getOption();
  1948. zrUtil.merge(magicOption, param.option, true);
  1949. zrUtil.merge(this._optionRestore, param.option, true);
  1950. this._toolbox.reset(magicOption);
  1951. }
  1952. this._island.refresh(magicOption);
  1953. this._toolbox.refresh(magicOption);
  1954. this._zr.clearAnimation();
  1955. for (var i = 0, l = this._chartList.length; i < l; i++) {
  1956. this._chartList[i].refresh && this._chartList[i].refresh(magicOption);
  1957. }
  1958. this.component.grid && this.component.grid.refixAxisShape(this.component);
  1959. this._zr.refresh();
  1960. },
  1961. _disposeChartList: function () {
  1962. this._clearEffect();
  1963. this._zr.clearAnimation();
  1964. var len = this._chartList.length;
  1965. while (len--) {
  1966. var chart = this._chartList[len];
  1967. if (chart) {
  1968. var chartType = chart.type;
  1969. this.chart[chartType] && delete this.chart[chartType];
  1970. this.component[chartType] && delete this.component[chartType];
  1971. chart.dispose && chart.dispose();
  1972. }
  1973. }
  1974. this._chartList = [];
  1975. },
  1976. _mergeGlobalConifg: function (magicOption) {
  1977. var mergeList = [
  1978. 'backgroundColor',
  1979. 'calculable',
  1980. 'calculableColor',
  1981. 'calculableHolderColor',
  1982. 'nameConnector',
  1983. 'valueConnector',
  1984. 'animation',
  1985. 'animationThreshold',
  1986. 'animationDuration',
  1987. 'animationDurationUpdate',
  1988. 'animationEasing',
  1989. 'addDataAnimation',
  1990. 'symbolList',
  1991. 'DRAG_ENABLE_TIME'
  1992. ];
  1993. var len = mergeList.length;
  1994. while (len--) {
  1995. var mergeItem = mergeList[len];
  1996. if (magicOption[mergeItem] == null) {
  1997. magicOption[mergeItem] = this._themeConfig[mergeItem] != null ? this._themeConfig[mergeItem] : ecConfig[mergeItem];
  1998. }
  1999. }
  2000. var themeColor = magicOption.color;
  2001. if (!(themeColor && themeColor.length)) {
  2002. themeColor = this._themeConfig.color || ecConfig.color;
  2003. }
  2004. this._zr.getColor = function (idx) {
  2005. var zrColor = require('zrender/tool/color');
  2006. return zrColor.getColor(idx, themeColor);
  2007. };
  2008. if (!_canvasSupported) {
  2009. magicOption.animation = false;
  2010. magicOption.addDataAnimation = false;
  2011. }
  2012. },
  2013. setOption: function (option, notMerge) {
  2014. if (!option.timeline) {
  2015. return this._setOption(option, notMerge);
  2016. } else {
  2017. return this._setTimelineOption(option);
  2018. }
  2019. },
  2020. _setOption: function (option, notMerge, keepTimeLine) {
  2021. if (!notMerge && this._option) {
  2022. this._option = zrUtil.merge(this.getOption(), zrUtil.clone(option), true);
  2023. } else {
  2024. this._option = zrUtil.clone(option);
  2025. !keepTimeLine && this._timeline && this._timeline.dispose();
  2026. }
  2027. this._optionRestore = zrUtil.clone(this._option);
  2028. if (!this._option.series || this._option.series.length === 0) {
  2029. this._zr.clear();
  2030. return;
  2031. }
  2032. if (this.component.dataZoom && (this._option.dataZoom || this._option.toolbox && this._option.toolbox.feature && this._option.toolbox.feature.dataZoom && this._option.toolbox.feature.dataZoom.show)) {
  2033. this.component.dataZoom.syncOption(this._option);
  2034. }
  2035. this._toolbox.reset(this._option);
  2036. this._render(this._option);
  2037. return this;
  2038. },
  2039. getOption: function () {
  2040. var magicOption = zrUtil.clone(this._option);
  2041. var self = this;
  2042. function restoreOption(prop) {
  2043. var restoreSource = self._optionRestore[prop];
  2044. if (restoreSource) {
  2045. if (restoreSource instanceof Array) {
  2046. var len = restoreSource.length;
  2047. while (len--) {
  2048. magicOption[prop][len].data = zrUtil.clone(restoreSource[len].data);
  2049. }
  2050. } else {
  2051. magicOption[prop].data = zrUtil.clone(restoreSource.data);
  2052. }
  2053. }
  2054. }
  2055. restoreOption('xAxis');
  2056. restoreOption('yAxis');
  2057. restoreOption('series');
  2058. return magicOption;
  2059. },
  2060. setSeries: function (series, notMerge) {
  2061. if (!notMerge) {
  2062. this.setOption({ series: series });
  2063. } else {
  2064. this._option.series = series;
  2065. this.setOption(this._option, notMerge);
  2066. }
  2067. return this;
  2068. },
  2069. getSeries: function () {
  2070. return this.getOption().series;
  2071. },
  2072. _setTimelineOption: function (option) {
  2073. this._timeline && this._timeline.dispose();
  2074. var Timeline = require('./component/timeline');
  2075. var timeline = new Timeline(this._themeConfig, this._messageCenter, this._zr, option, this);
  2076. this._timeline = timeline;
  2077. this.component.timeline = this._timeline;
  2078. return this;
  2079. },
  2080. addData: function (seriesIdx, data, isHead, dataGrow, additionData) {
  2081. var params = seriesIdx instanceof Array ? seriesIdx : [[
  2082. seriesIdx,
  2083. data,
  2084. isHead,
  2085. dataGrow,
  2086. additionData
  2087. ]];
  2088. var magicOption = this.getOption();
  2089. var optionRestore = this._optionRestore;
  2090. var self = this;
  2091. for (var i = 0, l = params.length; i < l; i++) {
  2092. seriesIdx = params[i][0];
  2093. data = params[i][1];
  2094. isHead = params[i][2];
  2095. dataGrow = params[i][3];
  2096. additionData = params[i][4];
  2097. var seriesItem = optionRestore.series[seriesIdx];
  2098. var inMethod = isHead ? 'unshift' : 'push';
  2099. var outMethod = isHead ? 'pop' : 'shift';
  2100. if (seriesItem) {
  2101. var seriesItemData = seriesItem.data;
  2102. var mSeriesItemData = magicOption.series[seriesIdx].data;
  2103. seriesItemData[inMethod](data);
  2104. mSeriesItemData[inMethod](data);
  2105. if (!dataGrow) {
  2106. seriesItemData[outMethod]();
  2107. data = mSeriesItemData[outMethod]();
  2108. }
  2109. if (additionData != null) {
  2110. var legend;
  2111. var legendData;
  2112. if (seriesItem.type === ecConfig.CHART_TYPE_PIE && (legend = optionRestore.legend) && (legendData = legend.data)) {
  2113. var mLegendData = magicOption.legend.data;
  2114. legendData[inMethod](additionData);
  2115. mLegendData[inMethod](additionData);
  2116. if (!dataGrow) {
  2117. var legendDataIdx = zrUtil.indexOf(legendData, data.name);
  2118. legendDataIdx != -1 && legendData.splice(legendDataIdx, 1);
  2119. legendDataIdx = zrUtil.indexOf(mLegendData, data.name);
  2120. legendDataIdx != -1 && mLegendData.splice(legendDataIdx, 1);
  2121. }
  2122. } else if (optionRestore.xAxis != null && optionRestore.yAxis != null) {
  2123. var axisData;
  2124. var mAxisData;
  2125. var axisIdx = seriesItem.xAxisIndex || 0;
  2126. if (optionRestore.xAxis[axisIdx].type == null || optionRestore.xAxis[axisIdx].type === 'category') {
  2127. axisData = optionRestore.xAxis[axisIdx].data;
  2128. mAxisData = magicOption.xAxis[axisIdx].data;
  2129. axisData[inMethod](additionData);
  2130. mAxisData[inMethod](additionData);
  2131. if (!dataGrow) {
  2132. axisData[outMethod]();
  2133. mAxisData[outMethod]();
  2134. }
  2135. }
  2136. axisIdx = seriesItem.yAxisIndex || 0;
  2137. if (optionRestore.yAxis[axisIdx].type === 'category') {
  2138. axisData = optionRestore.yAxis[axisIdx].data;
  2139. mAxisData = magicOption.yAxis[axisIdx].data;
  2140. axisData[inMethod](additionData);
  2141. mAxisData[inMethod](additionData);
  2142. if (!dataGrow) {
  2143. axisData[outMethod]();
  2144. mAxisData[outMethod]();
  2145. }
  2146. }
  2147. }
  2148. }
  2149. this._option.series[seriesIdx].data = magicOption.series[seriesIdx].data;
  2150. }
  2151. }
  2152. this._zr.clearAnimation();
  2153. var chartList = this._chartList;
  2154. var chartAnimationCount = 0;
  2155. var chartAnimationDone = function () {
  2156. chartAnimationCount--;
  2157. if (chartAnimationCount === 0) {
  2158. animationDone();
  2159. }
  2160. };
  2161. for (var i = 0, l = chartList.length; i < l; i++) {
  2162. if (magicOption.addDataAnimation && chartList[i].addDataAnimation) {
  2163. chartAnimationCount++;
  2164. chartList[i].addDataAnimation(params, chartAnimationDone);
  2165. }
  2166. }
  2167. this.component.dataZoom && this.component.dataZoom.syncOption(magicOption);
  2168. this._option = magicOption;
  2169. function animationDone() {
  2170. if (!self._zr) {
  2171. return;
  2172. }
  2173. self._zr.clearAnimation();
  2174. for (var i = 0, l = chartList.length; i < l; i++) {
  2175. chartList[i].motionlessOnce = magicOption.addDataAnimation && chartList[i].addDataAnimation;
  2176. }
  2177. self._messageCenter.dispatch(ecConfig.EVENT.REFRESH, null, { option: magicOption }, self);
  2178. }
  2179. if (!magicOption.addDataAnimation) {
  2180. setTimeout(animationDone, 0);
  2181. }
  2182. return this;
  2183. },
  2184. addMarkPoint: function (seriesIdx, markData) {
  2185. return this._addMark(seriesIdx, markData, 'markPoint');
  2186. },
  2187. addMarkLine: function (seriesIdx, markData) {
  2188. return this._addMark(seriesIdx, markData, 'markLine');
  2189. },
  2190. _addMark: function (seriesIdx, markData, markType) {
  2191. var series = this._option.series;
  2192. var seriesItem;
  2193. if (series && (seriesItem = series[seriesIdx])) {
  2194. var seriesR = this._optionRestore.series;
  2195. var seriesRItem = seriesR[seriesIdx];
  2196. var markOpt = seriesItem[markType];
  2197. var markOptR = seriesRItem[markType];
  2198. markOpt = seriesItem[markType] = markOpt || { data: [] };
  2199. markOptR = seriesRItem[markType] = markOptR || { data: [] };
  2200. for (var key in markData) {
  2201. if (key === 'data') {
  2202. markOpt.data = markOpt.data.concat(markData.data);
  2203. markOptR.data = markOptR.data.concat(markData.data);
  2204. } else if (typeof markData[key] != 'object' || markOpt[key] == null) {
  2205. markOpt[key] = markOptR[key] = markData[key];
  2206. } else {
  2207. zrUtil.merge(markOpt[key], markData[key], true);
  2208. zrUtil.merge(markOptR[key], markData[key], true);
  2209. }
  2210. }
  2211. var chart = this.chart[seriesItem.type];
  2212. chart && chart.addMark(seriesIdx, markData, markType);
  2213. }
  2214. return this;
  2215. },
  2216. delMarkPoint: function (seriesIdx, markName) {
  2217. return this._delMark(seriesIdx, markName, 'markPoint');
  2218. },
  2219. delMarkLine: function (seriesIdx, markName) {
  2220. return this._delMark(seriesIdx, markName, 'markLine');
  2221. },
  2222. _delMark: function (seriesIdx, markName, markType) {
  2223. var series = this._option.series;
  2224. var seriesItem;
  2225. var mark;
  2226. var dataArray;
  2227. if (!(series && (seriesItem = series[seriesIdx]) && (mark = seriesItem[markType]) && (dataArray = mark.data))) {
  2228. return this;
  2229. }
  2230. markName = markName.split(' > ');
  2231. var targetIndex = -1;
  2232. for (var i = 0, l = dataArray.length; i < l; i++) {
  2233. var dataItem = dataArray[i];
  2234. if (dataItem instanceof Array) {
  2235. if (dataItem[0].name === markName[0] && dataItem[1].name === markName[1]) {
  2236. targetIndex = i;
  2237. break;
  2238. }
  2239. } else if (dataItem.name === markName[0]) {
  2240. targetIndex = i;
  2241. break;
  2242. }
  2243. }
  2244. if (targetIndex > -1) {
  2245. dataArray.splice(targetIndex, 1);
  2246. this._optionRestore.series[seriesIdx][markType].data.splice(targetIndex, 1);
  2247. var chart = this.chart[seriesItem.type];
  2248. chart && chart.delMark(seriesIdx, markName.join(' > '), markType);
  2249. }
  2250. return this;
  2251. },
  2252. getDom: function () {
  2253. return this.dom;
  2254. },
  2255. getZrender: function () {
  2256. return this._zr;
  2257. },
  2258. getDataURL: function (imgType) {
  2259. if (!_canvasSupported) {
  2260. return '';
  2261. }
  2262. if (this._chartList.length === 0) {
  2263. var imgId = 'IMG' + this.id;
  2264. var img = document.getElementById(imgId);
  2265. if (img) {
  2266. return img.src;
  2267. }
  2268. }
  2269. var tooltip = this.component.tooltip;
  2270. tooltip && tooltip.hideTip();
  2271. switch (imgType) {
  2272. case 'jpeg':
  2273. break;
  2274. default:
  2275. imgType = 'png';
  2276. }
  2277. var bgColor = this._option.backgroundColor;
  2278. if (bgColor && bgColor.replace(' ', '') === 'rgba(0,0,0,0)') {
  2279. bgColor = '#fff';
  2280. }
  2281. return this._zr.toDataURL('image/' + imgType, bgColor);
  2282. },
  2283. getImage: function (imgType) {
  2284. var title = this._optionRestore.title;
  2285. var imgDom = document.createElement('img');
  2286. imgDom.src = this.getDataURL(imgType);
  2287. imgDom.title = title && title.text || 'ECharts';
  2288. return imgDom;
  2289. },
  2290. getConnectedDataURL: function (imgType) {
  2291. if (!this.isConnected()) {
  2292. return this.getDataURL(imgType);
  2293. }
  2294. var tempDom = this.dom;
  2295. var imgList = {
  2296. 'self': {
  2297. img: this.getDataURL(imgType),
  2298. left: tempDom.offsetLeft,
  2299. top: tempDom.offsetTop,
  2300. right: tempDom.offsetLeft + tempDom.offsetWidth,
  2301. bottom: tempDom.offsetTop + tempDom.offsetHeight
  2302. }
  2303. };
  2304. var minLeft = imgList.self.left;
  2305. var minTop = imgList.self.top;
  2306. var maxRight = imgList.self.right;
  2307. var maxBottom = imgList.self.bottom;
  2308. for (var c in this._connected) {
  2309. tempDom = this._connected[c].getDom();
  2310. imgList[c] = {
  2311. img: this._connected[c].getDataURL(imgType),
  2312. left: tempDom.offsetLeft,
  2313. top: tempDom.offsetTop,
  2314. right: tempDom.offsetLeft + tempDom.offsetWidth,
  2315. bottom: tempDom.offsetTop + tempDom.offsetHeight
  2316. };
  2317. minLeft = Math.min(minLeft, imgList[c].left);
  2318. minTop = Math.min(minTop, imgList[c].top);
  2319. maxRight = Math.max(maxRight, imgList[c].right);
  2320. maxBottom = Math.max(maxBottom, imgList[c].bottom);
  2321. }
  2322. var zrDom = document.createElement('div');
  2323. zrDom.style.position = 'absolute';
  2324. zrDom.style.left = '-4000px';
  2325. zrDom.style.width = maxRight - minLeft + 'px';
  2326. zrDom.style.height = maxBottom - minTop + 'px';
  2327. document.body.appendChild(zrDom);
  2328. var zrImg = require('zrender').init(zrDom);
  2329. var ImageShape = require('zrender/shape/Image');
  2330. for (var c in imgList) {
  2331. zrImg.addShape(new ImageShape({
  2332. style: {
  2333. x: imgList[c].left - minLeft,
  2334. y: imgList[c].top - minTop,
  2335. image: imgList[c].img
  2336. }
  2337. }));
  2338. }
  2339. zrImg.render();
  2340. var bgColor = this._option.backgroundColor;
  2341. if (bgColor && bgColor.replace(/ /g, '') === 'rgba(0,0,0,0)') {
  2342. bgColor = '#fff';
  2343. }
  2344. var image = zrImg.toDataURL('image/png', bgColor);
  2345. setTimeout(function () {
  2346. zrImg.dispose();
  2347. zrDom.parentNode.removeChild(zrDom);
  2348. zrDom = null;
  2349. }, 100);
  2350. return image;
  2351. },
  2352. getConnectedImage: function (imgType) {
  2353. var title = this._optionRestore.title;
  2354. var imgDom = document.createElement('img');
  2355. imgDom.src = this.getConnectedDataURL(imgType);
  2356. imgDom.title = title && title.text || 'ECharts';
  2357. return imgDom;
  2358. },
  2359. on: function (eventName, eventListener) {
  2360. this._messageCenterOutSide.bind(eventName, eventListener, this);
  2361. return this;
  2362. },
  2363. un: function (eventName, eventListener) {
  2364. this._messageCenterOutSide.unbind(eventName, eventListener);
  2365. return this;
  2366. },
  2367. connect: function (connectTarget) {
  2368. if (!connectTarget) {
  2369. return this;
  2370. }
  2371. if (!this._connected) {
  2372. this._connected = {};
  2373. }
  2374. if (connectTarget instanceof Array) {
  2375. for (var i = 0, l = connectTarget.length; i < l; i++) {
  2376. this._connected[connectTarget[i].id] = connectTarget[i];
  2377. }
  2378. } else {
  2379. this._connected[connectTarget.id] = connectTarget;
  2380. }
  2381. return this;
  2382. },
  2383. disConnect: function (connectTarget) {
  2384. if (!connectTarget || !this._connected) {
  2385. return this;
  2386. }
  2387. if (connectTarget instanceof Array) {
  2388. for (var i = 0, l = connectTarget.length; i < l; i++) {
  2389. delete this._connected[connectTarget[i].id];
  2390. }
  2391. } else {
  2392. delete this._connected[connectTarget.id];
  2393. }
  2394. for (var k in this._connected) {
  2395. return k, this;
  2396. }
  2397. this._connected = false;
  2398. return this;
  2399. },
  2400. connectedEventHandler: function (param) {
  2401. if (param.__echartsId != this.id) {
  2402. this._onevent(param);
  2403. }
  2404. },
  2405. isConnected: function () {
  2406. return !!this._connected;
  2407. },
  2408. showLoading: function (loadingOption) {
  2409. var effectList = {
  2410. bar: require('zrender/loadingEffect/Bar'),
  2411. bubble: require('zrender/loadingEffect/Bubble'),
  2412. dynamicLine: require('zrender/loadingEffect/DynamicLine'),
  2413. ring: require('zrender/loadingEffect/Ring'),
  2414. spin: require('zrender/loadingEffect/Spin'),
  2415. whirling: require('zrender/loadingEffect/Whirling')
  2416. };
  2417. this._toolbox.hideDataView();
  2418. loadingOption = loadingOption || {};
  2419. var textStyle = loadingOption.textStyle || {};
  2420. loadingOption.textStyle = textStyle;
  2421. var finalTextStyle = zrUtil.merge(zrUtil.merge(zrUtil.clone(textStyle), this._themeConfig.textStyle), ecConfig.textStyle);
  2422. textStyle.textFont = finalTextStyle.fontStyle + ' ' + finalTextStyle.fontWeight + ' ' + finalTextStyle.fontSize + 'px ' + finalTextStyle.fontFamily;
  2423. textStyle.text = loadingOption.text || this._option && this._option.loadingText || this._themeConfig.loadingText || ecConfig.loadingText;
  2424. if (loadingOption.x != null) {
  2425. textStyle.x = loadingOption.x;
  2426. }
  2427. if (loadingOption.y != null) {
  2428. textStyle.y = loadingOption.y;
  2429. }
  2430. loadingOption.effectOption = loadingOption.effectOption || {};
  2431. loadingOption.effectOption.textStyle = textStyle;
  2432. var Effect = loadingOption.effect;
  2433. if (typeof Effect === 'string' || Effect == null) {
  2434. Effect = effectList[loadingOption.effect || this._option && this._option.loadingEffect || this._themeConfig.loadingEffect || ecConfig.loadingEffect] || effectList.spin;
  2435. }
  2436. this._zr.showLoading(new Effect(loadingOption.effectOption));
  2437. return this;
  2438. },
  2439. hideLoading: function () {
  2440. this._zr.hideLoading();
  2441. return this;
  2442. },
  2443. setTheme: function (theme) {
  2444. if (theme) {
  2445. if (typeof theme === 'string') {
  2446. switch (theme) {
  2447. case 'macarons':
  2448. theme = require('./theme/macarons');
  2449. break;
  2450. case 'infographic':
  2451. theme = require('./theme/infographic');
  2452. break;
  2453. default:
  2454. theme = {};
  2455. }
  2456. } else {
  2457. theme = theme || {};
  2458. }
  2459. this._themeConfig = theme;
  2460. }
  2461. if (!_canvasSupported) {
  2462. var textStyle = this._themeConfig.textStyle;
  2463. textStyle && textStyle.fontFamily && textStyle.fontFamily2 && (textStyle.fontFamily = textStyle.fontFamily2);
  2464. textStyle = ecConfig.textStyle;
  2465. textStyle.fontFamily = textStyle.fontFamily2;
  2466. }
  2467. this._timeline && this._timeline.setTheme(true);
  2468. this._optionRestore && this.restore();
  2469. },
  2470. resize: function () {
  2471. var self = this;
  2472. return function () {
  2473. self._clearEffect();
  2474. self._zr.resize();
  2475. if (self._option && self._option.renderAsImage && _canvasSupported) {
  2476. self._render(self._option);
  2477. return self;
  2478. }
  2479. self._zr.clearAnimation();
  2480. self._island.resize();
  2481. self._toolbox.resize();
  2482. self._timeline && self._timeline.resize();
  2483. for (var i = 0, l = self._chartList.length; i < l; i++) {
  2484. self._chartList[i].resize && self._chartList[i].resize();
  2485. }
  2486. self.component.grid && self.component.grid.refixAxisShape(self.component);
  2487. self._zr.refresh();
  2488. self._messageCenter.dispatch(ecConfig.EVENT.RESIZE, null, null, self);
  2489. return self;
  2490. };
  2491. },
  2492. _clearEffect: function () {
  2493. this._zr.modLayer(ecConfig.EFFECT_ZLEVEL, { motionBlur: false });
  2494. this._zr.painter.clearLayer(ecConfig.EFFECT_ZLEVEL);
  2495. },
  2496. clear: function () {
  2497. this._disposeChartList();
  2498. this._zr.clear();
  2499. this._option = {};
  2500. this._optionRestore = {};
  2501. this.dom.style.backgroundColor = null;
  2502. return this;
  2503. },
  2504. dispose: function () {
  2505. var key = this.dom.getAttribute(DOM_ATTRIBUTE_KEY);
  2506. key && delete _instances[key];
  2507. this._island.dispose();
  2508. this._toolbox.dispose();
  2509. this._timeline && this._timeline.dispose();
  2510. this._messageCenter.unbind();
  2511. this.clear();
  2512. this._zr.dispose();
  2513. this._zr = null;
  2514. }
  2515. };
  2516. return self;
  2517. });define('echarts/config', [], function () {
  2518. var config = {
  2519. CHART_TYPE_LINE: 'line',
  2520. CHART_TYPE_BAR: 'bar',
  2521. CHART_TYPE_SCATTER: 'scatter',
  2522. CHART_TYPE_PIE: 'pie',
  2523. CHART_TYPE_RADAR: 'radar',
  2524. CHART_TYPE_VENN: 'venn',
  2525. CHART_TYPE_TREEMAP: 'treemap',
  2526. CHART_TYPE_TREE: 'tree',
  2527. CHART_TYPE_MAP: 'map',
  2528. CHART_TYPE_K: 'k',
  2529. CHART_TYPE_ISLAND: 'island',
  2530. CHART_TYPE_FORCE: 'force',
  2531. CHART_TYPE_CHORD: 'chord',
  2532. CHART_TYPE_GAUGE: 'gauge',
  2533. CHART_TYPE_FUNNEL: 'funnel',
  2534. CHART_TYPE_EVENTRIVER: 'eventRiver',
  2535. CHART_TYPE_WORDCLOUD: 'wordCloud',
  2536. CHART_TYPE_HEATMAP: 'heatmap',
  2537. COMPONENT_TYPE_TITLE: 'title',
  2538. COMPONENT_TYPE_LEGEND: 'legend',
  2539. COMPONENT_TYPE_DATARANGE: 'dataRange',
  2540. COMPONENT_TYPE_DATAVIEW: 'dataView',
  2541. COMPONENT_TYPE_DATAZOOM: 'dataZoom',
  2542. COMPONENT_TYPE_TOOLBOX: 'toolbox',
  2543. COMPONENT_TYPE_TOOLTIP: 'tooltip',
  2544. COMPONENT_TYPE_GRID: 'grid',
  2545. COMPONENT_TYPE_AXIS: 'axis',
  2546. COMPONENT_TYPE_POLAR: 'polar',
  2547. COMPONENT_TYPE_X_AXIS: 'xAxis',
  2548. COMPONENT_TYPE_Y_AXIS: 'yAxis',
  2549. COMPONENT_TYPE_AXIS_CATEGORY: 'categoryAxis',
  2550. COMPONENT_TYPE_AXIS_VALUE: 'valueAxis',
  2551. COMPONENT_TYPE_TIMELINE: 'timeline',
  2552. COMPONENT_TYPE_ROAMCONTROLLER: 'roamController',
  2553. backgroundColor: 'rgba(0,0,0,0)',
  2554. color: [
  2555. '#ff7f50',
  2556. '#87cefa',
  2557. '#da70d6',
  2558. '#32cd32',
  2559. '#6495ed',
  2560. '#ff69b4',
  2561. '#ba55d3',
  2562. '#cd5c5c',
  2563. '#ffa500',
  2564. '#40e0d0',
  2565. '#1e90ff',
  2566. '#ff6347',
  2567. '#7b68ee',
  2568. '#00fa9a',
  2569. '#ffd700',
  2570. '#6699FF',
  2571. '#ff6666',
  2572. '#3cb371',
  2573. '#b8860b',
  2574. '#30e0e0'
  2575. ],
  2576. markPoint: {
  2577. clickable: true,
  2578. symbol: 'pin',
  2579. symbolSize: 10,
  2580. large: false,
  2581. effect: {
  2582. show: false,
  2583. loop: true,
  2584. period: 15,
  2585. type: 'scale',
  2586. scaleSize: 2,
  2587. bounceDistance: 10
  2588. },
  2589. itemStyle: {
  2590. normal: {
  2591. borderWidth: 2,
  2592. label: {
  2593. show: true,
  2594. position: 'inside'
  2595. }
  2596. },
  2597. emphasis: { label: { show: true } }
  2598. }
  2599. },
  2600. markLine: {
  2601. clickable: true,
  2602. symbol: [
  2603. 'circle',
  2604. 'arrow'
  2605. ],
  2606. symbolSize: [
  2607. 2,
  2608. 4
  2609. ],
  2610. smoothness: 0.2,
  2611. precision: 2,
  2612. effect: {
  2613. show: false,
  2614. loop: true,
  2615. period: 15,
  2616. scaleSize: 2
  2617. },
  2618. bundling: {
  2619. enable: false,
  2620. maxTurningAngle: 45
  2621. },
  2622. itemStyle: {
  2623. normal: {
  2624. borderWidth: 1.5,
  2625. label: {
  2626. show: true,
  2627. position: 'end'
  2628. },
  2629. lineStyle: { type: 'dashed' }
  2630. },
  2631. emphasis: {
  2632. label: { show: false },
  2633. lineStyle: {}
  2634. }
  2635. }
  2636. },
  2637. textStyle: {
  2638. decoration: 'none',
  2639. fontFamily: 'Arial, Verdana, sans-serif',
  2640. fontFamily2: '微软雅黑',
  2641. fontSize: 12,
  2642. fontStyle: 'normal',
  2643. fontWeight: 'normal'
  2644. },
  2645. EVENT: {
  2646. REFRESH: 'refresh',
  2647. RESTORE: 'restore',
  2648. RESIZE: 'resize',
  2649. CLICK: 'click',
  2650. DBLCLICK: 'dblclick',
  2651. HOVER: 'hover',
  2652. MOUSEOUT: 'mouseout',
  2653. DATA_CHANGED: 'dataChanged',
  2654. DATA_ZOOM: 'dataZoom',
  2655. DATA_RANGE: 'dataRange',
  2656. DATA_RANGE_SELECTED: 'dataRangeSelected',
  2657. DATA_RANGE_HOVERLINK: 'dataRangeHoverLink',
  2658. LEGEND_SELECTED: 'legendSelected',
  2659. LEGEND_HOVERLINK: 'legendHoverLink',
  2660. MAP_SELECTED: 'mapSelected',
  2661. PIE_SELECTED: 'pieSelected',
  2662. MAGIC_TYPE_CHANGED: 'magicTypeChanged',
  2663. DATA_VIEW_CHANGED: 'dataViewChanged',
  2664. TIMELINE_CHANGED: 'timelineChanged',
  2665. MAP_ROAM: 'mapRoam',
  2666. FORCE_LAYOUT_END: 'forceLayoutEnd',
  2667. TOOLTIP_HOVER: 'tooltipHover',
  2668. TOOLTIP_IN_GRID: 'tooltipInGrid',
  2669. TOOLTIP_OUT_GRID: 'tooltipOutGrid',
  2670. ROAMCONTROLLER: 'roamController'
  2671. },
  2672. DRAG_ENABLE_TIME: 120,
  2673. EFFECT_ZLEVEL: 10,
  2674. effectBlendAlpha: 0.95,
  2675. symbolList: [
  2676. 'circle',
  2677. 'rectangle',
  2678. 'triangle',
  2679. 'diamond',
  2680. 'emptyCircle',
  2681. 'emptyRectangle',
  2682. 'emptyTriangle',
  2683. 'emptyDiamond'
  2684. ],
  2685. loadingEffect: 'spin',
  2686. loadingText: '数据读取中...',
  2687. noDataEffect: 'bubble',
  2688. noDataText: '暂无数据',
  2689. calculable: false,
  2690. calculableColor: 'rgba(255,165,0,0.6)',
  2691. calculableHolderColor: '#ccc',
  2692. nameConnector: ' & ',
  2693. valueConnector: ': ',
  2694. animation: true,
  2695. addDataAnimation: true,
  2696. animationThreshold: 2000,
  2697. animationDuration: 2000,
  2698. animationDurationUpdate: 500,
  2699. animationEasing: 'ExponentialOut'
  2700. };
  2701. return config;
  2702. });define('zrender/tool/util', [
  2703. 'require',
  2704. '../dep/excanvas'
  2705. ], function (require) {
  2706. var ArrayProto = Array.prototype;
  2707. var nativeForEach = ArrayProto.forEach;
  2708. var nativeMap = ArrayProto.map;
  2709. var nativeFilter = ArrayProto.filter;
  2710. var BUILTIN_OBJECT = {
  2711. '[object Function]': 1,
  2712. '[object RegExp]': 1,
  2713. '[object Date]': 1,
  2714. '[object Error]': 1,
  2715. '[object CanvasGradient]': 1
  2716. };
  2717. var objToString = Object.prototype.toString;
  2718. function isDom(obj) {
  2719. return obj && obj.nodeType === 1 && typeof obj.nodeName == 'string';
  2720. }
  2721. function clone(source) {
  2722. if (typeof source == 'object' && source !== null) {
  2723. var result = source;
  2724. if (source instanceof Array) {
  2725. result = [];
  2726. for (var i = 0, len = source.length; i < len; i++) {
  2727. result[i] = clone(source[i]);
  2728. }
  2729. } else if (!BUILTIN_OBJECT[objToString.call(source)] && !isDom(source)) {
  2730. result = {};
  2731. for (var key in source) {
  2732. if (source.hasOwnProperty(key)) {
  2733. result[key] = clone(source[key]);
  2734. }
  2735. }
  2736. }
  2737. return result;
  2738. }
  2739. return source;
  2740. }
  2741. function mergeItem(target, source, key, overwrite) {
  2742. if (source.hasOwnProperty(key)) {
  2743. var targetProp = target[key];
  2744. if (typeof targetProp == 'object' && !BUILTIN_OBJECT[objToString.call(targetProp)] && !isDom(targetProp)) {
  2745. merge(target[key], source[key], overwrite);
  2746. } else if (overwrite || !(key in target)) {
  2747. target[key] = source[key];
  2748. }
  2749. }
  2750. }
  2751. function merge(target, source, overwrite) {
  2752. for (var i in source) {
  2753. mergeItem(target, source, i, overwrite);
  2754. }
  2755. return target;
  2756. }
  2757. var _ctx;
  2758. function getContext() {
  2759. if (!_ctx) {
  2760. require('../dep/excanvas');
  2761. if (window['G_vmlCanvasManager']) {
  2762. var _div = document.createElement('div');
  2763. _div.style.position = 'absolute';
  2764. _div.style.top = '-1000px';
  2765. document.body.appendChild(_div);
  2766. _ctx = G_vmlCanvasManager.initElement(_div).getContext('2d');
  2767. } else {
  2768. _ctx = document.createElement('canvas').getContext('2d');
  2769. }
  2770. }
  2771. return _ctx;
  2772. }
  2773. function indexOf(array, value) {
  2774. if (array.indexOf) {
  2775. return array.indexOf(value);
  2776. }
  2777. for (var i = 0, len = array.length; i < len; i++) {
  2778. if (array[i] === value) {
  2779. return i;
  2780. }
  2781. }
  2782. return -1;
  2783. }
  2784. function inherits(clazz, baseClazz) {
  2785. var clazzPrototype = clazz.prototype;
  2786. function F() {
  2787. }
  2788. F.prototype = baseClazz.prototype;
  2789. clazz.prototype = new F();
  2790. for (var prop in clazzPrototype) {
  2791. clazz.prototype[prop] = clazzPrototype[prop];
  2792. }
  2793. clazz.constructor = clazz;
  2794. }
  2795. function each(obj, cb, context) {
  2796. if (!(obj && cb)) {
  2797. return;
  2798. }
  2799. if (obj.forEach && obj.forEach === nativeForEach) {
  2800. obj.forEach(cb, context);
  2801. } else if (obj.length === +obj.length) {
  2802. for (var i = 0, len = obj.length; i < len; i++) {
  2803. cb.call(context, obj[i], i, obj);
  2804. }
  2805. } else {
  2806. for (var key in obj) {
  2807. if (obj.hasOwnProperty(key)) {
  2808. cb.call(context, obj[key], key, obj);
  2809. }
  2810. }
  2811. }
  2812. }
  2813. function map(obj, cb, context) {
  2814. if (!(obj && cb)) {
  2815. return;
  2816. }
  2817. if (obj.map && obj.map === nativeMap) {
  2818. return obj.map(cb, context);
  2819. } else {
  2820. var result = [];
  2821. for (var i = 0, len = obj.length; i < len; i++) {
  2822. result.push(cb.call(context, obj[i], i, obj));
  2823. }
  2824. return result;
  2825. }
  2826. }
  2827. function filter(obj, cb, context) {
  2828. if (!(obj && cb)) {
  2829. return;
  2830. }
  2831. if (obj.filter && obj.filter === nativeFilter) {
  2832. return obj.filter(cb, context);
  2833. } else {
  2834. var result = [];
  2835. for (var i = 0, len = obj.length; i < len; i++) {
  2836. if (cb.call(context, obj[i], i, obj)) {
  2837. result.push(obj[i]);
  2838. }
  2839. }
  2840. return result;
  2841. }
  2842. }
  2843. function bind(func, context) {
  2844. return function () {
  2845. func.apply(context, arguments);
  2846. };
  2847. }
  2848. return {
  2849. inherits: inherits,
  2850. clone: clone,
  2851. merge: merge,
  2852. getContext: getContext,
  2853. indexOf: indexOf,
  2854. each: each,
  2855. map: map,
  2856. filter: filter,
  2857. bind: bind
  2858. };
  2859. });define('zrender/tool/event', [
  2860. 'require',
  2861. '../mixin/Eventful'
  2862. ], function (require) {
  2863. 'use strict';
  2864. var Eventful = require('../mixin/Eventful');
  2865. function getX(e) {
  2866. return typeof e.zrenderX != 'undefined' && e.zrenderX || typeof e.offsetX != 'undefined' && e.offsetX || typeof e.layerX != 'undefined' && e.layerX || typeof e.clientX != 'undefined' && e.clientX;
  2867. }
  2868. function getY(e) {
  2869. return typeof e.zrenderY != 'undefined' && e.zrenderY || typeof e.offsetY != 'undefined' && e.offsetY || typeof e.layerY != 'undefined' && e.layerY || typeof e.clientY != 'undefined' && e.clientY;
  2870. }
  2871. function getDelta(e) {
  2872. return typeof e.zrenderDelta != 'undefined' && e.zrenderDelta || typeof e.wheelDelta != 'undefined' && e.wheelDelta || typeof e.detail != 'undefined' && -e.detail;
  2873. }
  2874. var stop = typeof window.addEventListener === 'function' ? function (e) {
  2875. e.preventDefault();
  2876. e.stopPropagation();
  2877. e.cancelBubble = true;
  2878. } : function (e) {
  2879. e.returnValue = false;
  2880. e.cancelBubble = true;
  2881. };
  2882. return {
  2883. getX: getX,
  2884. getY: getY,
  2885. getDelta: getDelta,
  2886. stop: stop,
  2887. Dispatcher: Eventful
  2888. };
  2889. });define('zrender/tool/env', [], function () {
  2890. function detect(ua) {
  2891. var os = this.os = {};
  2892. var browser = this.browser = {};
  2893. var webkit = ua.match(/Web[kK]it[\/]{0,1}([\d.]+)/);
  2894. var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
  2895. var ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
  2896. var ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
  2897. var iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/);
  2898. var webos = ua.match(/(webOS|hpwOS)[\s\/]([\d.]+)/);
  2899. var touchpad = webos && ua.match(/TouchPad/);
  2900. var kindle = ua.match(/Kindle\/([\d.]+)/);
  2901. var silk = ua.match(/Silk\/([\d._]+)/);
  2902. var blackberry = ua.match(/(BlackBerry).*Version\/([\d.]+)/);
  2903. var bb10 = ua.match(/(BB10).*Version\/([\d.]+)/);
  2904. var rimtabletos = ua.match(/(RIM\sTablet\sOS)\s([\d.]+)/);
  2905. var playbook = ua.match(/PlayBook/);
  2906. var chrome = ua.match(/Chrome\/([\d.]+)/) || ua.match(/CriOS\/([\d.]+)/);
  2907. var firefox = ua.match(/Firefox\/([\d.]+)/);
  2908. var ie = ua.match(/MSIE ([\d.]+)/);
  2909. var safari = webkit && ua.match(/Mobile\//) && !chrome;
  2910. var webview = ua.match(/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/) && !chrome;
  2911. var ie = ua.match(/MSIE\s([\d.]+)/);
  2912. if (browser.webkit = !!webkit)
  2913. browser.version = webkit[1];
  2914. if (android)
  2915. os.android = true, os.version = android[2];
  2916. if (iphone && !ipod)
  2917. os.ios = os.iphone = true, os.version = iphone[2].replace(/_/g, '.');
  2918. if (ipad)
  2919. os.ios = os.ipad = true, os.version = ipad[2].replace(/_/g, '.');
  2920. if (ipod)
  2921. os.ios = os.ipod = true, os.version = ipod[3] ? ipod[3].replace(/_/g, '.') : null;
  2922. if (webos)
  2923. os.webos = true, os.version = webos[2];
  2924. if (touchpad)
  2925. os.touchpad = true;
  2926. if (blackberry)
  2927. os.blackberry = true, os.version = blackberry[2];
  2928. if (bb10)
  2929. os.bb10 = true, os.version = bb10[2];
  2930. if (rimtabletos)
  2931. os.rimtabletos = true, os.version = rimtabletos[2];
  2932. if (playbook)
  2933. browser.playbook = true;
  2934. if (kindle)
  2935. os.kindle = true, os.version = kindle[1];
  2936. if (silk)
  2937. browser.silk = true, browser.version = silk[1];
  2938. if (!silk && os.android && ua.match(/Kindle Fire/))
  2939. browser.silk = true;
  2940. if (chrome)
  2941. browser.chrome = true, browser.version = chrome[1];
  2942. if (firefox)
  2943. browser.firefox = true, browser.version = firefox[1];
  2944. if (ie)
  2945. browser.ie = true, browser.version = ie[1];
  2946. if (safari && (ua.match(/Safari/) || !!os.ios))
  2947. browser.safari = true;
  2948. if (webview)
  2949. browser.webview = true;
  2950. if (ie)
  2951. browser.ie = true, browser.version = ie[1];
  2952. os.tablet = !!(ipad || playbook || android && !ua.match(/Mobile/) || firefox && ua.match(/Tablet/) || ie && !ua.match(/Phone/) && ua.match(/Touch/));
  2953. os.phone = !!(!os.tablet && !os.ipod && (android || iphone || webos || blackberry || bb10 || chrome && ua.match(/Android/) || chrome && ua.match(/CriOS\/([\d.]+)/) || firefox && ua.match(/Mobile/) || ie && ua.match(/Touch/)));
  2954. return {
  2955. browser: browser,
  2956. os: os,
  2957. canvasSupported: document.createElement('canvas').getContext ? true : false
  2958. };
  2959. }
  2960. return detect(navigator.userAgent);
  2961. });define('zrender', ['zrender/zrender'], function (main) {return main;});
  2962. define('zrender/zrender', [
  2963. 'require',
  2964. './dep/excanvas',
  2965. './tool/util',
  2966. './tool/log',
  2967. './tool/guid',
  2968. './Handler',
  2969. './Painter',
  2970. './Storage',
  2971. './animation/Animation',
  2972. './tool/env'
  2973. ], function (require) {
  2974. require('./dep/excanvas');
  2975. var util = require('./tool/util');
  2976. var log = require('./tool/log');
  2977. var guid = require('./tool/guid');
  2978. var Handler = require('./Handler');
  2979. var Painter = require('./Painter');
  2980. var Storage = require('./Storage');
  2981. var Animation = require('./animation/Animation');
  2982. var _instances = {};
  2983. var zrender = {};
  2984. zrender.version = '2.1.1';
  2985. zrender.init = function (dom) {
  2986. var zr = new ZRender(guid(), dom);
  2987. _instances[zr.id] = zr;
  2988. return zr;
  2989. };
  2990. zrender.dispose = function (zr) {
  2991. if (zr) {
  2992. zr.dispose();
  2993. } else {
  2994. for (var key in _instances) {
  2995. _instances[key].dispose();
  2996. }
  2997. _instances = {};
  2998. }
  2999. return zrender;
  3000. };
  3001. zrender.getInstance = function (id) {
  3002. return _instances[id];
  3003. };
  3004. zrender.delInstance = function (id) {
  3005. delete _instances[id];
  3006. return zrender;
  3007. };
  3008. function getFrameCallback(zrInstance) {
  3009. return function () {
  3010. if (zrInstance._needsRefreshNextFrame) {
  3011. zrInstance.refresh();
  3012. }
  3013. };
  3014. }
  3015. var ZRender = function (id, dom) {
  3016. this.id = id;
  3017. this.env = require('./tool/env');
  3018. this.storage = new Storage();
  3019. this.painter = new Painter(dom, this.storage);
  3020. this.handler = new Handler(dom, this.storage, this.painter);
  3021. this.animation = new Animation({ stage: { update: getFrameCallback(this) } });
  3022. this.animation.start();
  3023. var self = this;
  3024. this.painter.refreshNextFrame = function () {
  3025. self.refreshNextFrame();
  3026. };
  3027. this._needsRefreshNextFrame = false;
  3028. var self = this;
  3029. var storage = this.storage;
  3030. var oldDelFromMap = storage.delFromMap;
  3031. storage.delFromMap = function (elId) {
  3032. var el = storage.get(elId);
  3033. self.stopAnimation(el);
  3034. oldDelFromMap.call(storage, elId);
  3035. };
  3036. };
  3037. ZRender.prototype.getId = function () {
  3038. return this.id;
  3039. };
  3040. ZRender.prototype.addShape = function (shape) {
  3041. this.addElement(shape);
  3042. return this;
  3043. };
  3044. ZRender.prototype.addGroup = function (group) {
  3045. this.addElement(group);
  3046. return this;
  3047. };
  3048. ZRender.prototype.delShape = function (shapeId) {
  3049. this.delElement(shapeId);
  3050. return this;
  3051. };
  3052. ZRender.prototype.delGroup = function (groupId) {
  3053. this.delElement(groupId);
  3054. return this;
  3055. };
  3056. ZRender.prototype.modShape = function (shapeId, shape) {
  3057. this.modElement(shapeId, shape);
  3058. return this;
  3059. };
  3060. ZRender.prototype.modGroup = function (groupId, group) {
  3061. this.modElement(groupId, group);
  3062. return this;
  3063. };
  3064. ZRender.prototype.addElement = function (el) {
  3065. this.storage.addRoot(el);
  3066. this._needsRefreshNextFrame = true;
  3067. return this;
  3068. };
  3069. ZRender.prototype.delElement = function (el) {
  3070. this.storage.delRoot(el);
  3071. this._needsRefreshNextFrame = true;
  3072. return this;
  3073. };
  3074. ZRender.prototype.modElement = function (el, params) {
  3075. this.storage.mod(el, params);
  3076. this._needsRefreshNextFrame = true;
  3077. return this;
  3078. };
  3079. ZRender.prototype.modLayer = function (zLevel, config) {
  3080. this.painter.modLayer(zLevel, config);
  3081. this._needsRefreshNextFrame = true;
  3082. return this;
  3083. };
  3084. ZRender.prototype.addHoverShape = function (shape) {
  3085. this.storage.addHover(shape);
  3086. return this;
  3087. };
  3088. ZRender.prototype.render = function (callback) {
  3089. this.painter.render(callback);
  3090. this._needsRefreshNextFrame = false;
  3091. return this;
  3092. };
  3093. ZRender.prototype.refresh = function (callback) {
  3094. this.painter.refresh(callback);
  3095. this._needsRefreshNextFrame = false;
  3096. return this;
  3097. };
  3098. ZRender.prototype.refreshNextFrame = function () {
  3099. this._needsRefreshNextFrame = true;
  3100. return this;
  3101. };
  3102. ZRender.prototype.refreshHover = function (callback) {
  3103. this.painter.refreshHover(callback);
  3104. return this;
  3105. };
  3106. ZRender.prototype.refreshShapes = function (shapeList, callback) {
  3107. this.painter.refreshShapes(shapeList, callback);
  3108. return this;
  3109. };
  3110. ZRender.prototype.resize = function () {
  3111. this.painter.resize();
  3112. return this;
  3113. };
  3114. ZRender.prototype.animate = function (el, path, loop) {
  3115. var self = this;
  3116. if (typeof el === 'string') {
  3117. el = this.storage.get(el);
  3118. }
  3119. if (el) {
  3120. var target;
  3121. if (path) {
  3122. var pathSplitted = path.split('.');
  3123. var prop = el;
  3124. for (var i = 0, l = pathSplitted.length; i < l; i++) {
  3125. if (!prop) {
  3126. continue;
  3127. }
  3128. prop = prop[pathSplitted[i]];
  3129. }
  3130. if (prop) {
  3131. target = prop;
  3132. }
  3133. } else {
  3134. target = el;
  3135. }
  3136. if (!target) {
  3137. log('Property "' + path + '" is not existed in element ' + el.id);
  3138. return;
  3139. }
  3140. if (el.__animators == null) {
  3141. el.__animators = [];
  3142. }
  3143. var animators = el.__animators;
  3144. var animator = this.animation.animate(target, { loop: loop }).during(function () {
  3145. self.modShape(el);
  3146. }).done(function () {
  3147. var idx = util.indexOf(el.__animators, animator);
  3148. if (idx >= 0) {
  3149. animators.splice(idx, 1);
  3150. }
  3151. });
  3152. animators.push(animator);
  3153. return animator;
  3154. } else {
  3155. log('Element not existed');
  3156. }
  3157. };
  3158. ZRender.prototype.stopAnimation = function (el) {
  3159. if (el.__animators) {
  3160. var animators = el.__animators;
  3161. var len = animators.length;
  3162. for (var i = 0; i < len; i++) {
  3163. animators[i].stop();
  3164. }
  3165. animators.length = 0;
  3166. }
  3167. return this;
  3168. };
  3169. ZRender.prototype.clearAnimation = function () {
  3170. this.animation.clear();
  3171. return this;
  3172. };
  3173. ZRender.prototype.showLoading = function (loadingEffect) {
  3174. this.painter.showLoading(loadingEffect);
  3175. return this;
  3176. };
  3177. ZRender.prototype.hideLoading = function () {
  3178. this.painter.hideLoading();
  3179. return this;
  3180. };
  3181. ZRender.prototype.getWidth = function () {
  3182. return this.painter.getWidth();
  3183. };
  3184. ZRender.prototype.getHeight = function () {
  3185. return this.painter.getHeight();
  3186. };
  3187. ZRender.prototype.toDataURL = function (type, backgroundColor, args) {
  3188. return this.painter.toDataURL(type, backgroundColor, args);
  3189. };
  3190. ZRender.prototype.shapeToImage = function (e, width, height) {
  3191. var id = guid();
  3192. return this.painter.shapeToImage(id, e, width, height);
  3193. };
  3194. ZRender.prototype.on = function (eventName, eventHandler, context) {
  3195. this.handler.on(eventName, eventHandler, context);
  3196. return this;
  3197. };
  3198. ZRender.prototype.un = function (eventName, eventHandler) {
  3199. this.handler.un(eventName, eventHandler);
  3200. return this;
  3201. };
  3202. ZRender.prototype.trigger = function (eventName, event) {
  3203. this.handler.trigger(eventName, event);
  3204. return this;
  3205. };
  3206. ZRender.prototype.clear = function () {
  3207. this.storage.delRoot();
  3208. this.painter.clear();
  3209. return this;
  3210. };
  3211. ZRender.prototype.dispose = function () {
  3212. this.animation.stop();
  3213. this.clear();
  3214. this.storage.dispose();
  3215. this.painter.dispose();
  3216. this.handler.dispose();
  3217. this.animation = this.storage = this.painter = this.handler = null;
  3218. zrender.delInstance(this.id);
  3219. };
  3220. return zrender;
  3221. });define('zrender/config', [], function () {
  3222. var config = {
  3223. EVENT: {
  3224. RESIZE: 'resize',
  3225. CLICK: 'click',
  3226. DBLCLICK: 'dblclick',
  3227. MOUSEWHEEL: 'mousewheel',
  3228. MOUSEMOVE: 'mousemove',
  3229. MOUSEOVER: 'mouseover',
  3230. MOUSEOUT: 'mouseout',
  3231. MOUSEDOWN: 'mousedown',
  3232. MOUSEUP: 'mouseup',
  3233. GLOBALOUT: 'globalout',
  3234. DRAGSTART: 'dragstart',
  3235. DRAGEND: 'dragend',
  3236. DRAGENTER: 'dragenter',
  3237. DRAGOVER: 'dragover',
  3238. DRAGLEAVE: 'dragleave',
  3239. DROP: 'drop',
  3240. touchClickDelay: 300
  3241. },
  3242. elementClassName: 'zr-element',
  3243. catchBrushException: false,
  3244. debugMode: 0,
  3245. devicePixelRatio: Math.max(window.devicePixelRatio || 1, 1)
  3246. };
  3247. return config;
  3248. });define('echarts/chart/island', [
  3249. 'require',
  3250. './base',
  3251. 'zrender/shape/Circle',
  3252. '../config',
  3253. '../util/ecData',
  3254. 'zrender/tool/util',
  3255. 'zrender/tool/event',
  3256. 'zrender/tool/color',
  3257. '../util/accMath',
  3258. '../chart'
  3259. ], function (require) {
  3260. var ChartBase = require('./base');
  3261. var CircleShape = require('zrender/shape/Circle');
  3262. var ecConfig = require('../config');
  3263. ecConfig.island = {
  3264. zlevel: 0,
  3265. z: 5,
  3266. r: 15,
  3267. calculateStep: 0.1
  3268. };
  3269. var ecData = require('../util/ecData');
  3270. var zrUtil = require('zrender/tool/util');
  3271. var zrEvent = require('zrender/tool/event');
  3272. function Island(ecTheme, messageCenter, zr, option, myChart) {
  3273. ChartBase.call(this, ecTheme, messageCenter, zr, option, myChart);
  3274. this._nameConnector;
  3275. this._valueConnector;
  3276. this._zrHeight = this.zr.getHeight();
  3277. this._zrWidth = this.zr.getWidth();
  3278. var self = this;
  3279. self.shapeHandler.onmousewheel = function (param) {
  3280. var shape = param.target;
  3281. var event = param.event;
  3282. var delta = zrEvent.getDelta(event);
  3283. delta = delta > 0 ? -1 : 1;
  3284. shape.style.r -= delta;
  3285. shape.style.r = shape.style.r < 5 ? 5 : shape.style.r;
  3286. var value = ecData.get(shape, 'value');
  3287. var dvalue = value * self.option.island.calculateStep;
  3288. value = dvalue > 1 ? Math.round(value - dvalue * delta) : +(value - dvalue * delta).toFixed(2);
  3289. var name = ecData.get(shape, 'name');
  3290. shape.style.text = name + ':' + value;
  3291. ecData.set(shape, 'value', value);
  3292. ecData.set(shape, 'name', name);
  3293. self.zr.modShape(shape.id);
  3294. self.zr.refreshNextFrame();
  3295. zrEvent.stop(event);
  3296. };
  3297. }
  3298. Island.prototype = {
  3299. type: ecConfig.CHART_TYPE_ISLAND,
  3300. _combine: function (tarShape, srcShape) {
  3301. var zrColor = require('zrender/tool/color');
  3302. var accMath = require('../util/accMath');
  3303. var value = accMath.accAdd(ecData.get(tarShape, 'value'), ecData.get(srcShape, 'value'));
  3304. var name = ecData.get(tarShape, 'name') + this._nameConnector + ecData.get(srcShape, 'name');
  3305. tarShape.style.text = name + this._valueConnector + value;
  3306. ecData.set(tarShape, 'value', value);
  3307. ecData.set(tarShape, 'name', name);
  3308. tarShape.style.r = this.option.island.r;
  3309. tarShape.style.color = zrColor.mix(tarShape.style.color, srcShape.style.color);
  3310. },
  3311. refresh: function (newOption) {
  3312. if (newOption) {
  3313. newOption.island = this.reformOption(newOption.island);
  3314. this.option = newOption;
  3315. this._nameConnector = this.option.nameConnector;
  3316. this._valueConnector = this.option.valueConnector;
  3317. }
  3318. },
  3319. getOption: function () {
  3320. return this.option;
  3321. },
  3322. resize: function () {
  3323. var newWidth = this.zr.getWidth();
  3324. var newHieght = this.zr.getHeight();
  3325. var xScale = newWidth / (this._zrWidth || newWidth);
  3326. var yScale = newHieght / (this._zrHeight || newHieght);
  3327. if (xScale === 1 && yScale === 1) {
  3328. return;
  3329. }
  3330. this._zrWidth = newWidth;
  3331. this._zrHeight = newHieght;
  3332. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  3333. this.zr.modShape(this.shapeList[i].id, {
  3334. style: {
  3335. x: Math.round(this.shapeList[i].style.x * xScale),
  3336. y: Math.round(this.shapeList[i].style.y * yScale)
  3337. }
  3338. });
  3339. }
  3340. },
  3341. add: function (shape) {
  3342. var name = ecData.get(shape, 'name');
  3343. var value = ecData.get(shape, 'value');
  3344. var seriesName = ecData.get(shape, 'series') != null ? ecData.get(shape, 'series').name : '';
  3345. var font = this.getFont(this.option.island.textStyle);
  3346. var islandOption = this.option.island;
  3347. var islandShape = {
  3348. zlevel: islandOption.zlevel,
  3349. z: islandOption.z,
  3350. style: {
  3351. x: shape.style.x,
  3352. y: shape.style.y,
  3353. r: this.option.island.r,
  3354. color: shape.style.color || shape.style.strokeColor,
  3355. text: name + this._valueConnector + value,
  3356. textFont: font
  3357. },
  3358. draggable: true,
  3359. hoverable: true,
  3360. onmousewheel: this.shapeHandler.onmousewheel,
  3361. _type: 'island'
  3362. };
  3363. if (islandShape.style.color === '#fff') {
  3364. islandShape.style.color = shape.style.strokeColor;
  3365. }
  3366. this.setCalculable(islandShape);
  3367. islandShape.dragEnableTime = 0;
  3368. ecData.pack(islandShape, { name: seriesName }, -1, value, -1, name);
  3369. islandShape = new CircleShape(islandShape);
  3370. this.shapeList.push(islandShape);
  3371. this.zr.addShape(islandShape);
  3372. },
  3373. del: function (shape) {
  3374. this.zr.delShape(shape.id);
  3375. var newShapeList = [];
  3376. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  3377. if (this.shapeList[i].id != shape.id) {
  3378. newShapeList.push(this.shapeList[i]);
  3379. }
  3380. }
  3381. this.shapeList = newShapeList;
  3382. },
  3383. ondrop: function (param, status) {
  3384. if (!this.isDrop || !param.target) {
  3385. return;
  3386. }
  3387. var target = param.target;
  3388. var dragged = param.dragged;
  3389. this._combine(target, dragged);
  3390. this.zr.modShape(target.id);
  3391. status.dragIn = true;
  3392. this.isDrop = false;
  3393. return;
  3394. },
  3395. ondragend: function (param, status) {
  3396. var target = param.target;
  3397. if (!this.isDragend) {
  3398. if (!status.dragIn) {
  3399. target.style.x = zrEvent.getX(param.event);
  3400. target.style.y = zrEvent.getY(param.event);
  3401. this.add(target);
  3402. status.needRefresh = true;
  3403. }
  3404. } else {
  3405. if (status.dragIn) {
  3406. this.del(target);
  3407. status.needRefresh = true;
  3408. }
  3409. }
  3410. this.isDragend = false;
  3411. return;
  3412. }
  3413. };
  3414. zrUtil.inherits(Island, ChartBase);
  3415. require('../chart').define('island', Island);
  3416. return Island;
  3417. });define('echarts/component/toolbox', [
  3418. 'require',
  3419. './base',
  3420. 'zrender/shape/Line',
  3421. 'zrender/shape/Image',
  3422. 'zrender/shape/Rectangle',
  3423. '../util/shape/Icon',
  3424. '../config',
  3425. 'zrender/tool/util',
  3426. 'zrender/config',
  3427. 'zrender/tool/event',
  3428. './dataView',
  3429. '../component'
  3430. ], function (require) {
  3431. var Base = require('./base');
  3432. var LineShape = require('zrender/shape/Line');
  3433. var ImageShape = require('zrender/shape/Image');
  3434. var RectangleShape = require('zrender/shape/Rectangle');
  3435. var IconShape = require('../util/shape/Icon');
  3436. var ecConfig = require('../config');
  3437. ecConfig.toolbox = {
  3438. zlevel: 0,
  3439. z: 6,
  3440. show: false,
  3441. orient: 'horizontal',
  3442. x: 'right',
  3443. y: 'top',
  3444. color: [
  3445. '#1e90ff',
  3446. '#22bb22',
  3447. '#4b0082',
  3448. '#d2691e'
  3449. ],
  3450. disableColor: '#ddd',
  3451. effectiveColor: 'red',
  3452. backgroundColor: 'rgba(0,0,0,0)',
  3453. borderColor: '#ccc',
  3454. borderWidth: 0,
  3455. padding: 5,
  3456. itemGap: 10,
  3457. itemSize: 16,
  3458. showTitle: true,
  3459. feature: {
  3460. mark: {
  3461. show: false,
  3462. title: {
  3463. mark: '辅助线开关',
  3464. markUndo: '删除辅助线',
  3465. markClear: '清空辅助线'
  3466. },
  3467. lineStyle: {
  3468. width: 1,
  3469. color: '#1e90ff',
  3470. type: 'dashed'
  3471. }
  3472. },
  3473. dataZoom: {
  3474. show: false,
  3475. title: {
  3476. dataZoom: '区域缩放',
  3477. dataZoomReset: '区域缩放后退'
  3478. }
  3479. },
  3480. dataView: {
  3481. show: false,
  3482. title: '数据视图',
  3483. readOnly: false,
  3484. lang: [
  3485. '数据视图',
  3486. '关闭',
  3487. '刷新'
  3488. ]
  3489. },
  3490. magicType: {
  3491. show: false,
  3492. title: {
  3493. line: '折线图切换',
  3494. bar: '柱形图切换',
  3495. stack: '堆积',
  3496. tiled: '平铺',
  3497. force: '力导向布局图切换',
  3498. chord: '和弦图切换',
  3499. pie: '饼图切换',
  3500. funnel: '漏斗图切换'
  3501. },
  3502. type: []
  3503. },
  3504. restore: {
  3505. show: false,
  3506. title: '还原'
  3507. },
  3508. saveAsImage: {
  3509. show: false,
  3510. title: '保存为图片',
  3511. type: 'png',
  3512. lang: ['点击保存']
  3513. }
  3514. }
  3515. };
  3516. var zrUtil = require('zrender/tool/util');
  3517. var zrConfig = require('zrender/config');
  3518. var zrEvent = require('zrender/tool/event');
  3519. var _MAGICTYPE_STACK = 'stack';
  3520. var _MAGICTYPE_TILED = 'tiled';
  3521. function Toolbox(ecTheme, messageCenter, zr, option, myChart) {
  3522. Base.call(this, ecTheme, messageCenter, zr, option, myChart);
  3523. this.dom = myChart.dom;
  3524. this._magicType = {};
  3525. this._magicMap = {};
  3526. this._isSilence = false;
  3527. this._iconList;
  3528. this._iconShapeMap = {};
  3529. this._featureTitle = {};
  3530. this._featureIcon = {};
  3531. this._featureColor = {};
  3532. this._featureOption = {};
  3533. this._enableColor = 'red';
  3534. this._disableColor = '#ccc';
  3535. this._markShapeList = [];
  3536. var self = this;
  3537. self._onMark = function (param) {
  3538. self.__onMark(param);
  3539. };
  3540. self._onMarkUndo = function (param) {
  3541. self.__onMarkUndo(param);
  3542. };
  3543. self._onMarkClear = function (param) {
  3544. self.__onMarkClear(param);
  3545. };
  3546. self._onDataZoom = function (param) {
  3547. self.__onDataZoom(param);
  3548. };
  3549. self._onDataZoomReset = function (param) {
  3550. self.__onDataZoomReset(param);
  3551. };
  3552. self._onDataView = function (param) {
  3553. self.__onDataView(param);
  3554. };
  3555. self._onRestore = function (param) {
  3556. self.__onRestore(param);
  3557. };
  3558. self._onSaveAsImage = function (param) {
  3559. self.__onSaveAsImage(param);
  3560. };
  3561. self._onMagicType = function (param) {
  3562. self.__onMagicType(param);
  3563. };
  3564. self._onCustomHandler = function (param) {
  3565. self.__onCustomHandler(param);
  3566. };
  3567. self._onmousemove = function (param) {
  3568. return self.__onmousemove(param);
  3569. };
  3570. self._onmousedown = function (param) {
  3571. return self.__onmousedown(param);
  3572. };
  3573. self._onmouseup = function (param) {
  3574. return self.__onmouseup(param);
  3575. };
  3576. self._onclick = function (param) {
  3577. return self.__onclick(param);
  3578. };
  3579. }
  3580. Toolbox.prototype = {
  3581. type: ecConfig.COMPONENT_TYPE_TOOLBOX,
  3582. _buildShape: function () {
  3583. this._iconList = [];
  3584. var toolboxOption = this.option.toolbox;
  3585. this._enableColor = toolboxOption.effectiveColor;
  3586. this._disableColor = toolboxOption.disableColor;
  3587. var feature = toolboxOption.feature;
  3588. var iconName = [];
  3589. for (var key in feature) {
  3590. if (feature[key].show) {
  3591. switch (key) {
  3592. case 'mark':
  3593. iconName.push({
  3594. key: key,
  3595. name: 'mark'
  3596. });
  3597. iconName.push({
  3598. key: key,
  3599. name: 'markUndo'
  3600. });
  3601. iconName.push({
  3602. key: key,
  3603. name: 'markClear'
  3604. });
  3605. break;
  3606. case 'magicType':
  3607. for (var i = 0, l = feature[key].type.length; i < l; i++) {
  3608. feature[key].title[feature[key].type[i] + 'Chart'] = feature[key].title[feature[key].type[i]];
  3609. if (feature[key].option) {
  3610. feature[key].option[feature[key].type[i] + 'Chart'] = feature[key].option[feature[key].type[i]];
  3611. }
  3612. iconName.push({
  3613. key: key,
  3614. name: feature[key].type[i] + 'Chart'
  3615. });
  3616. }
  3617. break;
  3618. case 'dataZoom':
  3619. iconName.push({
  3620. key: key,
  3621. name: 'dataZoom'
  3622. });
  3623. iconName.push({
  3624. key: key,
  3625. name: 'dataZoomReset'
  3626. });
  3627. break;
  3628. case 'saveAsImage':
  3629. if (this.canvasSupported) {
  3630. iconName.push({
  3631. key: key,
  3632. name: 'saveAsImage'
  3633. });
  3634. }
  3635. break;
  3636. default:
  3637. iconName.push({
  3638. key: key,
  3639. name: key
  3640. });
  3641. break;
  3642. }
  3643. }
  3644. }
  3645. if (iconName.length > 0) {
  3646. var name;
  3647. var key;
  3648. for (var i = 0, l = iconName.length; i < l; i++) {
  3649. name = iconName[i].name;
  3650. key = iconName[i].key;
  3651. this._iconList.push(name);
  3652. this._featureTitle[name] = feature[key].title[name] || feature[key].title;
  3653. if (feature[key].icon) {
  3654. this._featureIcon[name] = feature[key].icon[name] || feature[key].icon;
  3655. }
  3656. if (feature[key].color) {
  3657. this._featureColor[name] = feature[key].color[name] || feature[key].color;
  3658. }
  3659. if (feature[key].option) {
  3660. this._featureOption[name] = feature[key].option[name] || feature[key].option;
  3661. }
  3662. }
  3663. this._itemGroupLocation = this._getItemGroupLocation();
  3664. this._buildBackground();
  3665. this._buildItem();
  3666. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  3667. this.zr.addShape(this.shapeList[i]);
  3668. }
  3669. if (this._iconShapeMap['mark']) {
  3670. this._iconDisable(this._iconShapeMap['markUndo']);
  3671. this._iconDisable(this._iconShapeMap['markClear']);
  3672. }
  3673. if (this._iconShapeMap['dataZoomReset'] && this._zoomQueue.length === 0) {
  3674. this._iconDisable(this._iconShapeMap['dataZoomReset']);
  3675. }
  3676. }
  3677. },
  3678. _buildItem: function () {
  3679. var toolboxOption = this.option.toolbox;
  3680. var iconLength = this._iconList.length;
  3681. var lastX = this._itemGroupLocation.x;
  3682. var lastY = this._itemGroupLocation.y;
  3683. var itemSize = toolboxOption.itemSize;
  3684. var itemGap = toolboxOption.itemGap;
  3685. var itemShape;
  3686. var color = toolboxOption.color instanceof Array ? toolboxOption.color : [toolboxOption.color];
  3687. var textFont = this.getFont(toolboxOption.textStyle);
  3688. var textPosition;
  3689. var textAlign;
  3690. var textBaseline;
  3691. if (toolboxOption.orient === 'horizontal') {
  3692. textPosition = this._itemGroupLocation.y / this.zr.getHeight() < 0.5 ? 'bottom' : 'top';
  3693. textAlign = this._itemGroupLocation.x / this.zr.getWidth() < 0.5 ? 'left' : 'right';
  3694. textBaseline = this._itemGroupLocation.y / this.zr.getHeight() < 0.5 ? 'top' : 'bottom';
  3695. } else {
  3696. textPosition = this._itemGroupLocation.x / this.zr.getWidth() < 0.5 ? 'right' : 'left';
  3697. }
  3698. this._iconShapeMap = {};
  3699. var self = this;
  3700. for (var i = 0; i < iconLength; i++) {
  3701. itemShape = {
  3702. type: 'icon',
  3703. zlevel: this.getZlevelBase(),
  3704. z: this.getZBase(),
  3705. style: {
  3706. x: lastX,
  3707. y: lastY,
  3708. width: itemSize,
  3709. height: itemSize,
  3710. iconType: this._iconList[i],
  3711. lineWidth: 1,
  3712. strokeColor: this._featureColor[this._iconList[i]] || color[i % color.length],
  3713. brushType: 'stroke'
  3714. },
  3715. highlightStyle: {
  3716. lineWidth: 1,
  3717. text: toolboxOption.showTitle ? this._featureTitle[this._iconList[i]] : undefined,
  3718. textFont: textFont,
  3719. textPosition: textPosition,
  3720. strokeColor: this._featureColor[this._iconList[i]] || color[i % color.length]
  3721. },
  3722. hoverable: true,
  3723. clickable: true
  3724. };
  3725. if (this._featureIcon[this._iconList[i]]) {
  3726. itemShape.style.image = this._featureIcon[this._iconList[i]].replace(new RegExp('^image:\\/\\/'), '');
  3727. itemShape.style.opacity = 0.8;
  3728. itemShape.highlightStyle.opacity = 1;
  3729. itemShape.type = 'image';
  3730. }
  3731. if (toolboxOption.orient === 'horizontal') {
  3732. if (i === 0 && textAlign === 'left') {
  3733. itemShape.highlightStyle.textPosition = 'specific';
  3734. itemShape.highlightStyle.textAlign = textAlign;
  3735. itemShape.highlightStyle.textBaseline = textBaseline;
  3736. itemShape.highlightStyle.textX = lastX;
  3737. itemShape.highlightStyle.textY = textBaseline === 'top' ? lastY + itemSize + 10 : lastY - 10;
  3738. }
  3739. if (i === iconLength - 1 && textAlign === 'right') {
  3740. itemShape.highlightStyle.textPosition = 'specific';
  3741. itemShape.highlightStyle.textAlign = textAlign;
  3742. itemShape.highlightStyle.textBaseline = textBaseline;
  3743. itemShape.highlightStyle.textX = lastX + itemSize;
  3744. itemShape.highlightStyle.textY = textBaseline === 'top' ? lastY + itemSize + 10 : lastY - 10;
  3745. }
  3746. }
  3747. switch (this._iconList[i]) {
  3748. case 'mark':
  3749. itemShape.onclick = self._onMark;
  3750. break;
  3751. case 'markUndo':
  3752. itemShape.onclick = self._onMarkUndo;
  3753. break;
  3754. case 'markClear':
  3755. itemShape.onclick = self._onMarkClear;
  3756. break;
  3757. case 'dataZoom':
  3758. itemShape.onclick = self._onDataZoom;
  3759. break;
  3760. case 'dataZoomReset':
  3761. itemShape.onclick = self._onDataZoomReset;
  3762. break;
  3763. case 'dataView':
  3764. if (!this._dataView) {
  3765. var DataView = require('./dataView');
  3766. this._dataView = new DataView(this.ecTheme, this.messageCenter, this.zr, this.option, this.myChart);
  3767. }
  3768. itemShape.onclick = self._onDataView;
  3769. break;
  3770. case 'restore':
  3771. itemShape.onclick = self._onRestore;
  3772. break;
  3773. case 'saveAsImage':
  3774. itemShape.onclick = self._onSaveAsImage;
  3775. break;
  3776. default:
  3777. if (this._iconList[i].match('Chart')) {
  3778. itemShape._name = this._iconList[i].replace('Chart', '');
  3779. itemShape.onclick = self._onMagicType;
  3780. } else {
  3781. itemShape.onclick = self._onCustomHandler;
  3782. }
  3783. break;
  3784. }
  3785. if (itemShape.type === 'icon') {
  3786. itemShape = new IconShape(itemShape);
  3787. } else if (itemShape.type === 'image') {
  3788. itemShape = new ImageShape(itemShape);
  3789. }
  3790. this.shapeList.push(itemShape);
  3791. this._iconShapeMap[this._iconList[i]] = itemShape;
  3792. if (toolboxOption.orient === 'horizontal') {
  3793. lastX += itemSize + itemGap;
  3794. } else {
  3795. lastY += itemSize + itemGap;
  3796. }
  3797. }
  3798. },
  3799. _buildBackground: function () {
  3800. var toolboxOption = this.option.toolbox;
  3801. var padding = this.reformCssArray(this.option.toolbox.padding);
  3802. this.shapeList.push(new RectangleShape({
  3803. zlevel: this.getZlevelBase(),
  3804. z: this.getZBase(),
  3805. hoverable: false,
  3806. style: {
  3807. x: this._itemGroupLocation.x - padding[3],
  3808. y: this._itemGroupLocation.y - padding[0],
  3809. width: this._itemGroupLocation.width + padding[3] + padding[1],
  3810. height: this._itemGroupLocation.height + padding[0] + padding[2],
  3811. brushType: toolboxOption.borderWidth === 0 ? 'fill' : 'both',
  3812. color: toolboxOption.backgroundColor,
  3813. strokeColor: toolboxOption.borderColor,
  3814. lineWidth: toolboxOption.borderWidth
  3815. }
  3816. }));
  3817. },
  3818. _getItemGroupLocation: function () {
  3819. var toolboxOption = this.option.toolbox;
  3820. var padding = this.reformCssArray(this.option.toolbox.padding);
  3821. var iconLength = this._iconList.length;
  3822. var itemGap = toolboxOption.itemGap;
  3823. var itemSize = toolboxOption.itemSize;
  3824. var totalWidth = 0;
  3825. var totalHeight = 0;
  3826. if (toolboxOption.orient === 'horizontal') {
  3827. totalWidth = (itemSize + itemGap) * iconLength - itemGap;
  3828. totalHeight = itemSize;
  3829. } else {
  3830. totalHeight = (itemSize + itemGap) * iconLength - itemGap;
  3831. totalWidth = itemSize;
  3832. }
  3833. var x;
  3834. var zrWidth = this.zr.getWidth();
  3835. switch (toolboxOption.x) {
  3836. case 'center':
  3837. x = Math.floor((zrWidth - totalWidth) / 2);
  3838. break;
  3839. case 'left':
  3840. x = padding[3] + toolboxOption.borderWidth;
  3841. break;
  3842. case 'right':
  3843. x = zrWidth - totalWidth - padding[1] - toolboxOption.borderWidth;
  3844. break;
  3845. default:
  3846. x = toolboxOption.x - 0;
  3847. x = isNaN(x) ? 0 : x;
  3848. break;
  3849. }
  3850. var y;
  3851. var zrHeight = this.zr.getHeight();
  3852. switch (toolboxOption.y) {
  3853. case 'top':
  3854. y = padding[0] + toolboxOption.borderWidth;
  3855. break;
  3856. case 'bottom':
  3857. y = zrHeight - totalHeight - padding[2] - toolboxOption.borderWidth;
  3858. break;
  3859. case 'center':
  3860. y = Math.floor((zrHeight - totalHeight) / 2);
  3861. break;
  3862. default:
  3863. y = toolboxOption.y - 0;
  3864. y = isNaN(y) ? 0 : y;
  3865. break;
  3866. }
  3867. return {
  3868. x: x,
  3869. y: y,
  3870. width: totalWidth,
  3871. height: totalHeight
  3872. };
  3873. },
  3874. __onmousemove: function (param) {
  3875. if (this._marking) {
  3876. this._markShape.style.xEnd = zrEvent.getX(param.event);
  3877. this._markShape.style.yEnd = zrEvent.getY(param.event);
  3878. this.zr.addHoverShape(this._markShape);
  3879. }
  3880. if (this._zooming) {
  3881. this._zoomShape.style.width = zrEvent.getX(param.event) - this._zoomShape.style.x;
  3882. this._zoomShape.style.height = zrEvent.getY(param.event) - this._zoomShape.style.y;
  3883. this.zr.addHoverShape(this._zoomShape);
  3884. this.dom.style.cursor = 'crosshair';
  3885. zrEvent.stop(param.event);
  3886. }
  3887. if (this._zoomStart && (this.dom.style.cursor != 'pointer' && this.dom.style.cursor != 'move')) {
  3888. this.dom.style.cursor = 'crosshair';
  3889. }
  3890. },
  3891. __onmousedown: function (param) {
  3892. if (param.target) {
  3893. return;
  3894. }
  3895. this._zooming = true;
  3896. var x = zrEvent.getX(param.event);
  3897. var y = zrEvent.getY(param.event);
  3898. var zoomOption = this.option.dataZoom || {};
  3899. this._zoomShape = new RectangleShape({
  3900. zlevel: this.getZlevelBase(),
  3901. z: this.getZBase(),
  3902. style: {
  3903. x: x,
  3904. y: y,
  3905. width: 1,
  3906. height: 1,
  3907. brushType: 'both'
  3908. },
  3909. highlightStyle: {
  3910. lineWidth: 2,
  3911. color: zoomOption.fillerColor || ecConfig.dataZoom.fillerColor,
  3912. strokeColor: zoomOption.handleColor || ecConfig.dataZoom.handleColor,
  3913. brushType: 'both'
  3914. }
  3915. });
  3916. this.zr.addHoverShape(this._zoomShape);
  3917. return true;
  3918. },
  3919. __onmouseup: function () {
  3920. if (!this._zoomShape || Math.abs(this._zoomShape.style.width) < 10 || Math.abs(this._zoomShape.style.height) < 10) {
  3921. this._zooming = false;
  3922. return true;
  3923. }
  3924. if (this._zooming && this.component.dataZoom) {
  3925. this._zooming = false;
  3926. var zoom = this.component.dataZoom.rectZoom(this._zoomShape.style);
  3927. if (zoom) {
  3928. this._zoomQueue.push({
  3929. start: zoom.start,
  3930. end: zoom.end,
  3931. start2: zoom.start2,
  3932. end2: zoom.end2
  3933. });
  3934. this._iconEnable(this._iconShapeMap['dataZoomReset']);
  3935. this.zr.refreshNextFrame();
  3936. }
  3937. }
  3938. return true;
  3939. },
  3940. __onclick: function (param) {
  3941. if (param.target) {
  3942. return;
  3943. }
  3944. if (this._marking) {
  3945. this._marking = false;
  3946. this._markShapeList.push(this._markShape);
  3947. this._iconEnable(this._iconShapeMap['markUndo']);
  3948. this._iconEnable(this._iconShapeMap['markClear']);
  3949. this.zr.addShape(this._markShape);
  3950. this.zr.refreshNextFrame();
  3951. } else if (this._markStart) {
  3952. this._marking = true;
  3953. var x = zrEvent.getX(param.event);
  3954. var y = zrEvent.getY(param.event);
  3955. this._markShape = new LineShape({
  3956. zlevel: this.getZlevelBase(),
  3957. z: this.getZBase(),
  3958. style: {
  3959. xStart: x,
  3960. yStart: y,
  3961. xEnd: x,
  3962. yEnd: y,
  3963. lineWidth: this.query(this.option, 'toolbox.feature.mark.lineStyle.width'),
  3964. strokeColor: this.query(this.option, 'toolbox.feature.mark.lineStyle.color'),
  3965. lineType: this.query(this.option, 'toolbox.feature.mark.lineStyle.type')
  3966. }
  3967. });
  3968. this.zr.addHoverShape(this._markShape);
  3969. }
  3970. },
  3971. __onMark: function (param) {
  3972. var target = param.target;
  3973. if (this._marking || this._markStart) {
  3974. this._resetMark();
  3975. this.zr.refreshNextFrame();
  3976. } else {
  3977. this._resetZoom();
  3978. this.zr.modShape(target.id, { style: { strokeColor: this._enableColor } });
  3979. this.zr.refreshNextFrame();
  3980. this._markStart = true;
  3981. var self = this;
  3982. setTimeout(function () {
  3983. self.zr && self.zr.on(zrConfig.EVENT.CLICK, self._onclick) && self.zr.on(zrConfig.EVENT.MOUSEMOVE, self._onmousemove);
  3984. }, 10);
  3985. }
  3986. return true;
  3987. },
  3988. __onMarkUndo: function () {
  3989. if (this._marking) {
  3990. this._marking = false;
  3991. } else {
  3992. var len = this._markShapeList.length;
  3993. if (len >= 1) {
  3994. var target = this._markShapeList[len - 1];
  3995. this.zr.delShape(target.id);
  3996. this.zr.refreshNextFrame();
  3997. this._markShapeList.pop();
  3998. if (len === 1) {
  3999. this._iconDisable(this._iconShapeMap['markUndo']);
  4000. this._iconDisable(this._iconShapeMap['markClear']);
  4001. }
  4002. }
  4003. }
  4004. return true;
  4005. },
  4006. __onMarkClear: function () {
  4007. if (this._marking) {
  4008. this._marking = false;
  4009. }
  4010. var len = this._markShapeList.length;
  4011. if (len > 0) {
  4012. while (len--) {
  4013. this.zr.delShape(this._markShapeList.pop().id);
  4014. }
  4015. this._iconDisable(this._iconShapeMap['markUndo']);
  4016. this._iconDisable(this._iconShapeMap['markClear']);
  4017. this.zr.refreshNextFrame();
  4018. }
  4019. return true;
  4020. },
  4021. __onDataZoom: function (param) {
  4022. var target = param.target;
  4023. if (this._zooming || this._zoomStart) {
  4024. this._resetZoom();
  4025. this.zr.refreshNextFrame();
  4026. this.dom.style.cursor = 'default';
  4027. } else {
  4028. this._resetMark();
  4029. this.zr.modShape(target.id, { style: { strokeColor: this._enableColor } });
  4030. this.zr.refreshNextFrame();
  4031. this._zoomStart = true;
  4032. var self = this;
  4033. setTimeout(function () {
  4034. self.zr && self.zr.on(zrConfig.EVENT.MOUSEDOWN, self._onmousedown) && self.zr.on(zrConfig.EVENT.MOUSEUP, self._onmouseup) && self.zr.on(zrConfig.EVENT.MOUSEMOVE, self._onmousemove);
  4035. }, 10);
  4036. this.dom.style.cursor = 'crosshair';
  4037. }
  4038. return true;
  4039. },
  4040. __onDataZoomReset: function () {
  4041. if (this._zooming) {
  4042. this._zooming = false;
  4043. }
  4044. this._zoomQueue.pop();
  4045. if (this._zoomQueue.length > 0) {
  4046. this.component.dataZoom.absoluteZoom(this._zoomQueue[this._zoomQueue.length - 1]);
  4047. } else {
  4048. this.component.dataZoom.rectZoom();
  4049. this._iconDisable(this._iconShapeMap['dataZoomReset']);
  4050. this.zr.refreshNextFrame();
  4051. }
  4052. return true;
  4053. },
  4054. _resetMark: function () {
  4055. this._marking = false;
  4056. if (this._markStart) {
  4057. this._markStart = false;
  4058. if (this._iconShapeMap['mark']) {
  4059. this.zr.modShape(this._iconShapeMap['mark'].id, { style: { strokeColor: this._iconShapeMap['mark'].highlightStyle.strokeColor } });
  4060. }
  4061. this.zr.un(zrConfig.EVENT.CLICK, this._onclick);
  4062. this.zr.un(zrConfig.EVENT.MOUSEMOVE, this._onmousemove);
  4063. }
  4064. },
  4065. _resetZoom: function () {
  4066. this._zooming = false;
  4067. if (this._zoomStart) {
  4068. this._zoomStart = false;
  4069. if (this._iconShapeMap['dataZoom']) {
  4070. this.zr.modShape(this._iconShapeMap['dataZoom'].id, { style: { strokeColor: this._iconShapeMap['dataZoom'].highlightStyle.strokeColor } });
  4071. }
  4072. this.zr.un(zrConfig.EVENT.MOUSEDOWN, this._onmousedown);
  4073. this.zr.un(zrConfig.EVENT.MOUSEUP, this._onmouseup);
  4074. this.zr.un(zrConfig.EVENT.MOUSEMOVE, this._onmousemove);
  4075. }
  4076. },
  4077. _iconDisable: function (target) {
  4078. if (target.type != 'image') {
  4079. this.zr.modShape(target.id, {
  4080. hoverable: false,
  4081. clickable: false,
  4082. style: { strokeColor: this._disableColor }
  4083. });
  4084. } else {
  4085. this.zr.modShape(target.id, {
  4086. hoverable: false,
  4087. clickable: false,
  4088. style: { opacity: 0.3 }
  4089. });
  4090. }
  4091. },
  4092. _iconEnable: function (target) {
  4093. if (target.type != 'image') {
  4094. this.zr.modShape(target.id, {
  4095. hoverable: true,
  4096. clickable: true,
  4097. style: { strokeColor: target.highlightStyle.strokeColor }
  4098. });
  4099. } else {
  4100. this.zr.modShape(target.id, {
  4101. hoverable: true,
  4102. clickable: true,
  4103. style: { opacity: 0.8 }
  4104. });
  4105. }
  4106. },
  4107. __onDataView: function () {
  4108. this._dataView.show(this.option);
  4109. return true;
  4110. },
  4111. __onRestore: function () {
  4112. this._resetMark();
  4113. this._resetZoom();
  4114. this.messageCenter.dispatch(ecConfig.EVENT.RESTORE, null, null, this.myChart);
  4115. return true;
  4116. },
  4117. __onSaveAsImage: function () {
  4118. var saveOption = this.option.toolbox.feature.saveAsImage;
  4119. var imgType = saveOption.type || 'png';
  4120. if (imgType != 'png' && imgType != 'jpeg') {
  4121. imgType = 'png';
  4122. }
  4123. var image;
  4124. if (!this.myChart.isConnected()) {
  4125. image = this.zr.toDataURL('image/' + imgType, this.option.backgroundColor && this.option.backgroundColor.replace(' ', '') === 'rgba(0,0,0,0)' ? '#fff' : this.option.backgroundColor);
  4126. } else {
  4127. image = this.myChart.getConnectedDataURL(imgType);
  4128. }
  4129. var downloadDiv = document.createElement('div');
  4130. downloadDiv.id = '__echarts_download_wrap__';
  4131. downloadDiv.style.cssText = 'position:fixed;' + 'z-index:99999;' + 'display:block;' + 'top:0;left:0;' + 'background-color:rgba(33,33,33,0.5);' + 'text-align:center;' + 'width:100%;' + 'height:100%;' + 'line-height:' + document.documentElement.clientHeight + 'px;';
  4132. var downloadLink = document.createElement('a');
  4133. downloadLink.href = image;
  4134. downloadLink.setAttribute('download', (saveOption.name ? saveOption.name : this.option.title && (this.option.title.text || this.option.title.subtext) ? this.option.title.text || this.option.title.subtext : 'ECharts') + '.' + imgType);
  4135. downloadLink.innerHTML = '<img style="vertical-align:middle" src="' + image + '" title="' + (!!window.ActiveXObject || 'ActiveXObject' in window ? '右键->图片另存为' : saveOption.lang ? saveOption.lang[0] : '点击保存') + '"/>';
  4136. downloadDiv.appendChild(downloadLink);
  4137. document.body.appendChild(downloadDiv);
  4138. downloadLink = null;
  4139. downloadDiv = null;
  4140. setTimeout(function () {
  4141. var _d = document.getElementById('__echarts_download_wrap__');
  4142. if (_d) {
  4143. _d.onclick = function () {
  4144. var d = document.getElementById('__echarts_download_wrap__');
  4145. d.onclick = null;
  4146. d.innerHTML = '';
  4147. document.body.removeChild(d);
  4148. d = null;
  4149. };
  4150. _d = null;
  4151. }
  4152. }, 500);
  4153. return;
  4154. },
  4155. __onMagicType: function (param) {
  4156. this._resetMark();
  4157. var itemName = param.target._name;
  4158. if (!this._magicType[itemName]) {
  4159. this._magicType[itemName] = true;
  4160. if (itemName === ecConfig.CHART_TYPE_LINE) {
  4161. this._magicType[ecConfig.CHART_TYPE_BAR] = false;
  4162. } else if (itemName === ecConfig.CHART_TYPE_BAR) {
  4163. this._magicType[ecConfig.CHART_TYPE_LINE] = false;
  4164. }
  4165. if (itemName === ecConfig.CHART_TYPE_PIE) {
  4166. this._magicType[ecConfig.CHART_TYPE_FUNNEL] = false;
  4167. } else if (itemName === ecConfig.CHART_TYPE_FUNNEL) {
  4168. this._magicType[ecConfig.CHART_TYPE_PIE] = false;
  4169. }
  4170. if (itemName === ecConfig.CHART_TYPE_FORCE) {
  4171. this._magicType[ecConfig.CHART_TYPE_CHORD] = false;
  4172. } else if (itemName === ecConfig.CHART_TYPE_CHORD) {
  4173. this._magicType[ecConfig.CHART_TYPE_FORCE] = false;
  4174. }
  4175. if (itemName === _MAGICTYPE_STACK) {
  4176. this._magicType[_MAGICTYPE_TILED] = false;
  4177. } else if (itemName === _MAGICTYPE_TILED) {
  4178. this._magicType[_MAGICTYPE_STACK] = false;
  4179. }
  4180. this.messageCenter.dispatch(ecConfig.EVENT.MAGIC_TYPE_CHANGED, param.event, { magicType: this._magicType }, this.myChart);
  4181. }
  4182. return true;
  4183. },
  4184. setMagicType: function (magicType) {
  4185. this._resetMark();
  4186. this._magicType = magicType;
  4187. !this._isSilence && this.messageCenter.dispatch(ecConfig.EVENT.MAGIC_TYPE_CHANGED, null, { magicType: this._magicType }, this.myChart);
  4188. },
  4189. __onCustomHandler: function (param) {
  4190. var target = param.target.style.iconType;
  4191. var featureHandler = this.option.toolbox.feature[target].onclick;
  4192. if (typeof featureHandler === 'function') {
  4193. featureHandler.call(this, this.option);
  4194. }
  4195. },
  4196. reset: function (newOption, isRestore) {
  4197. isRestore && this.clear();
  4198. if (this.query(newOption, 'toolbox.show') && this.query(newOption, 'toolbox.feature.magicType.show')) {
  4199. var magicType = newOption.toolbox.feature.magicType.type;
  4200. var len = magicType.length;
  4201. this._magicMap = {};
  4202. while (len--) {
  4203. this._magicMap[magicType[len]] = true;
  4204. }
  4205. len = newOption.series.length;
  4206. var oriType;
  4207. var axis;
  4208. while (len--) {
  4209. oriType = newOption.series[len].type;
  4210. if (this._magicMap[oriType]) {
  4211. axis = newOption.xAxis instanceof Array ? newOption.xAxis[newOption.series[len].xAxisIndex || 0] : newOption.xAxis;
  4212. if (axis && (axis.type || 'category') === 'category') {
  4213. axis.__boundaryGap = axis.boundaryGap != null ? axis.boundaryGap : true;
  4214. }
  4215. axis = newOption.yAxis instanceof Array ? newOption.yAxis[newOption.series[len].yAxisIndex || 0] : newOption.yAxis;
  4216. if (axis && axis.type === 'category') {
  4217. axis.__boundaryGap = axis.boundaryGap != null ? axis.boundaryGap : true;
  4218. }
  4219. newOption.series[len].__type = oriType;
  4220. newOption.series[len].__itemStyle = zrUtil.clone(newOption.series[len].itemStyle || {});
  4221. }
  4222. if (this._magicMap[_MAGICTYPE_STACK] || this._magicMap[_MAGICTYPE_TILED]) {
  4223. newOption.series[len].__stack = newOption.series[len].stack;
  4224. }
  4225. }
  4226. }
  4227. this._magicType = isRestore ? {} : this._magicType || {};
  4228. for (var itemName in this._magicType) {
  4229. if (this._magicType[itemName]) {
  4230. this.option = newOption;
  4231. this.getMagicOption();
  4232. break;
  4233. }
  4234. }
  4235. var zoomOption = newOption.dataZoom;
  4236. if (zoomOption && zoomOption.show) {
  4237. var start = zoomOption.start != null && zoomOption.start >= 0 && zoomOption.start <= 100 ? zoomOption.start : 0;
  4238. var end = zoomOption.end != null && zoomOption.end >= 0 && zoomOption.end <= 100 ? zoomOption.end : 100;
  4239. if (start > end) {
  4240. start = start + end;
  4241. end = start - end;
  4242. start = start - end;
  4243. }
  4244. this._zoomQueue = [{
  4245. start: start,
  4246. end: end,
  4247. start2: 0,
  4248. end2: 100
  4249. }];
  4250. } else {
  4251. this._zoomQueue = [];
  4252. }
  4253. },
  4254. getMagicOption: function () {
  4255. var axis;
  4256. var chartType;
  4257. if (this._magicType[ecConfig.CHART_TYPE_LINE] || this._magicType[ecConfig.CHART_TYPE_BAR]) {
  4258. var boundaryGap = this._magicType[ecConfig.CHART_TYPE_LINE] ? false : true;
  4259. for (var i = 0, l = this.option.series.length; i < l; i++) {
  4260. chartType = this.option.series[i].type;
  4261. if (chartType == ecConfig.CHART_TYPE_LINE || chartType == ecConfig.CHART_TYPE_BAR) {
  4262. axis = this.option.xAxis instanceof Array ? this.option.xAxis[this.option.series[i].xAxisIndex || 0] : this.option.xAxis;
  4263. if (axis && (axis.type || 'category') === 'category') {
  4264. axis.boundaryGap = boundaryGap ? true : axis.__boundaryGap;
  4265. }
  4266. axis = this.option.yAxis instanceof Array ? this.option.yAxis[this.option.series[i].yAxisIndex || 0] : this.option.yAxis;
  4267. if (axis && axis.type === 'category') {
  4268. axis.boundaryGap = boundaryGap ? true : axis.__boundaryGap;
  4269. }
  4270. }
  4271. }
  4272. this._defaultMagic(ecConfig.CHART_TYPE_LINE, ecConfig.CHART_TYPE_BAR);
  4273. }
  4274. this._defaultMagic(ecConfig.CHART_TYPE_CHORD, ecConfig.CHART_TYPE_FORCE);
  4275. this._defaultMagic(ecConfig.CHART_TYPE_PIE, ecConfig.CHART_TYPE_FUNNEL);
  4276. if (this._magicType[_MAGICTYPE_STACK] || this._magicType[_MAGICTYPE_TILED]) {
  4277. for (var i = 0, l = this.option.series.length; i < l; i++) {
  4278. if (this._magicType[_MAGICTYPE_STACK]) {
  4279. this.option.series[i].stack = '_ECHARTS_STACK_KENER_2014_';
  4280. chartType = _MAGICTYPE_STACK;
  4281. } else if (this._magicType[_MAGICTYPE_TILED]) {
  4282. this.option.series[i].stack = null;
  4283. chartType = _MAGICTYPE_TILED;
  4284. }
  4285. if (this._featureOption[chartType + 'Chart']) {
  4286. zrUtil.merge(this.option.series[i], this._featureOption[chartType + 'Chart'] || {}, true);
  4287. }
  4288. }
  4289. }
  4290. return this.option;
  4291. },
  4292. _defaultMagic: function (cType1, cType2) {
  4293. if (this._magicType[cType1] || this._magicType[cType2]) {
  4294. for (var i = 0, l = this.option.series.length; i < l; i++) {
  4295. var chartType = this.option.series[i].type;
  4296. if (chartType == cType1 || chartType == cType2) {
  4297. this.option.series[i].type = this._magicType[cType1] ? cType1 : cType2;
  4298. this.option.series[i].itemStyle = zrUtil.clone(this.option.series[i].__itemStyle);
  4299. chartType = this.option.series[i].type;
  4300. if (this._featureOption[chartType + 'Chart']) {
  4301. zrUtil.merge(this.option.series[i], this._featureOption[chartType + 'Chart'] || {}, true);
  4302. }
  4303. }
  4304. }
  4305. }
  4306. },
  4307. silence: function (s) {
  4308. this._isSilence = s;
  4309. },
  4310. resize: function () {
  4311. this._resetMark();
  4312. this.clear();
  4313. if (this.option && this.option.toolbox && this.option.toolbox.show) {
  4314. this._buildShape();
  4315. }
  4316. if (this._dataView) {
  4317. this._dataView.resize();
  4318. }
  4319. },
  4320. hideDataView: function () {
  4321. if (this._dataView) {
  4322. this._dataView.hide();
  4323. }
  4324. },
  4325. clear: function (notMark) {
  4326. if (this.zr) {
  4327. this.zr.delShape(this.shapeList);
  4328. this.shapeList = [];
  4329. if (!notMark) {
  4330. this.zr.delShape(this._markShapeList);
  4331. this._markShapeList = [];
  4332. }
  4333. }
  4334. },
  4335. onbeforDispose: function () {
  4336. if (this._dataView) {
  4337. this._dataView.dispose();
  4338. this._dataView = null;
  4339. }
  4340. this._markShapeList = null;
  4341. },
  4342. refresh: function (newOption) {
  4343. if (newOption) {
  4344. this._resetMark();
  4345. this._resetZoom();
  4346. newOption.toolbox = this.reformOption(newOption.toolbox);
  4347. this.option = newOption;
  4348. this.clear(true);
  4349. if (newOption.toolbox.show) {
  4350. this._buildShape();
  4351. }
  4352. this.hideDataView();
  4353. }
  4354. }
  4355. };
  4356. zrUtil.inherits(Toolbox, Base);
  4357. require('../component').define('toolbox', Toolbox);
  4358. return Toolbox;
  4359. });define('echarts/component', [], function () {
  4360. var self = {};
  4361. var _componentLibrary = {};
  4362. self.define = function (name, clazz) {
  4363. _componentLibrary[name] = clazz;
  4364. return self;
  4365. };
  4366. self.get = function (name) {
  4367. return _componentLibrary[name];
  4368. };
  4369. return self;
  4370. });define('echarts/component/title', [
  4371. 'require',
  4372. './base',
  4373. 'zrender/shape/Text',
  4374. 'zrender/shape/Rectangle',
  4375. '../config',
  4376. 'zrender/tool/util',
  4377. 'zrender/tool/area',
  4378. 'zrender/tool/color',
  4379. '../component'
  4380. ], function (require) {
  4381. var Base = require('./base');
  4382. var TextShape = require('zrender/shape/Text');
  4383. var RectangleShape = require('zrender/shape/Rectangle');
  4384. var ecConfig = require('../config');
  4385. ecConfig.title = {
  4386. zlevel: 0,
  4387. z: 6,
  4388. show: true,
  4389. text: '',
  4390. subtext: '',
  4391. x: 'left',
  4392. y: 'top',
  4393. backgroundColor: 'rgba(0,0,0,0)',
  4394. borderColor: '#ccc',
  4395. borderWidth: 0,
  4396. padding: 5,
  4397. itemGap: 5,
  4398. textStyle: {
  4399. fontSize: 18,
  4400. fontWeight: 'bolder',
  4401. color: '#333'
  4402. },
  4403. subtextStyle: { color: '#aaa' }
  4404. };
  4405. var zrUtil = require('zrender/tool/util');
  4406. var zrArea = require('zrender/tool/area');
  4407. var zrColor = require('zrender/tool/color');
  4408. function Title(ecTheme, messageCenter, zr, option, myChart) {
  4409. Base.call(this, ecTheme, messageCenter, zr, option, myChart);
  4410. this.refresh(option);
  4411. }
  4412. Title.prototype = {
  4413. type: ecConfig.COMPONENT_TYPE_TITLE,
  4414. _buildShape: function () {
  4415. if (!this.titleOption.show) {
  4416. return;
  4417. }
  4418. this._itemGroupLocation = this._getItemGroupLocation();
  4419. this._buildBackground();
  4420. this._buildItem();
  4421. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  4422. this.zr.addShape(this.shapeList[i]);
  4423. }
  4424. },
  4425. _buildItem: function () {
  4426. var text = this.titleOption.text;
  4427. var link = this.titleOption.link;
  4428. var target = this.titleOption.target;
  4429. var subtext = this.titleOption.subtext;
  4430. var sublink = this.titleOption.sublink;
  4431. var subtarget = this.titleOption.subtarget;
  4432. var font = this.getFont(this.titleOption.textStyle);
  4433. var subfont = this.getFont(this.titleOption.subtextStyle);
  4434. var x = this._itemGroupLocation.x;
  4435. var y = this._itemGroupLocation.y;
  4436. var width = this._itemGroupLocation.width;
  4437. var height = this._itemGroupLocation.height;
  4438. var textShape = {
  4439. zlevel: this.getZlevelBase(),
  4440. z: this.getZBase(),
  4441. style: {
  4442. y: y,
  4443. color: this.titleOption.textStyle.color,
  4444. text: text,
  4445. textFont: font,
  4446. textBaseline: 'top'
  4447. },
  4448. highlightStyle: {
  4449. color: zrColor.lift(this.titleOption.textStyle.color, 1),
  4450. brushType: 'fill'
  4451. },
  4452. hoverable: false
  4453. };
  4454. if (link) {
  4455. textShape.hoverable = true;
  4456. textShape.clickable = true;
  4457. textShape.onclick = function () {
  4458. if (!target || target != 'self') {
  4459. window.open(link);
  4460. } else {
  4461. window.location = link;
  4462. }
  4463. };
  4464. }
  4465. var subtextShape = {
  4466. zlevel: this.getZlevelBase(),
  4467. z: this.getZBase(),
  4468. style: {
  4469. y: y + height,
  4470. color: this.titleOption.subtextStyle.color,
  4471. text: subtext,
  4472. textFont: subfont,
  4473. textBaseline: 'bottom'
  4474. },
  4475. highlightStyle: {
  4476. color: zrColor.lift(this.titleOption.subtextStyle.color, 1),
  4477. brushType: 'fill'
  4478. },
  4479. hoverable: false
  4480. };
  4481. if (sublink) {
  4482. subtextShape.hoverable = true;
  4483. subtextShape.clickable = true;
  4484. subtextShape.onclick = function () {
  4485. if (!subtarget || subtarget != 'self') {
  4486. window.open(sublink);
  4487. } else {
  4488. window.location = sublink;
  4489. }
  4490. };
  4491. }
  4492. switch (this.titleOption.x) {
  4493. case 'center':
  4494. textShape.style.x = subtextShape.style.x = x + width / 2;
  4495. textShape.style.textAlign = subtextShape.style.textAlign = 'center';
  4496. break;
  4497. case 'left':
  4498. textShape.style.x = subtextShape.style.x = x;
  4499. textShape.style.textAlign = subtextShape.style.textAlign = 'left';
  4500. break;
  4501. case 'right':
  4502. textShape.style.x = subtextShape.style.x = x + width;
  4503. textShape.style.textAlign = subtextShape.style.textAlign = 'right';
  4504. break;
  4505. default:
  4506. x = this.titleOption.x - 0;
  4507. x = isNaN(x) ? 0 : x;
  4508. textShape.style.x = subtextShape.style.x = x;
  4509. break;
  4510. }
  4511. if (this.titleOption.textAlign) {
  4512. textShape.style.textAlign = subtextShape.style.textAlign = this.titleOption.textAlign;
  4513. }
  4514. this.shapeList.push(new TextShape(textShape));
  4515. subtext !== '' && this.shapeList.push(new TextShape(subtextShape));
  4516. },
  4517. _buildBackground: function () {
  4518. var padding = this.reformCssArray(this.titleOption.padding);
  4519. this.shapeList.push(new RectangleShape({
  4520. zlevel: this.getZlevelBase(),
  4521. z: this.getZBase(),
  4522. hoverable: false,
  4523. style: {
  4524. x: this._itemGroupLocation.x - padding[3],
  4525. y: this._itemGroupLocation.y - padding[0],
  4526. width: this._itemGroupLocation.width + padding[3] + padding[1],
  4527. height: this._itemGroupLocation.height + padding[0] + padding[2],
  4528. brushType: this.titleOption.borderWidth === 0 ? 'fill' : 'both',
  4529. color: this.titleOption.backgroundColor,
  4530. strokeColor: this.titleOption.borderColor,
  4531. lineWidth: this.titleOption.borderWidth
  4532. }
  4533. }));
  4534. },
  4535. _getItemGroupLocation: function () {
  4536. var padding = this.reformCssArray(this.titleOption.padding);
  4537. var text = this.titleOption.text;
  4538. var subtext = this.titleOption.subtext;
  4539. var font = this.getFont(this.titleOption.textStyle);
  4540. var subfont = this.getFont(this.titleOption.subtextStyle);
  4541. var totalWidth = Math.max(zrArea.getTextWidth(text, font), zrArea.getTextWidth(subtext, subfont));
  4542. var totalHeight = zrArea.getTextHeight(text, font) + (subtext === '' ? 0 : this.titleOption.itemGap + zrArea.getTextHeight(subtext, subfont));
  4543. var x;
  4544. var zrWidth = this.zr.getWidth();
  4545. switch (this.titleOption.x) {
  4546. case 'center':
  4547. x = Math.floor((zrWidth - totalWidth) / 2);
  4548. break;
  4549. case 'left':
  4550. x = padding[3] + this.titleOption.borderWidth;
  4551. break;
  4552. case 'right':
  4553. x = zrWidth - totalWidth - padding[1] - this.titleOption.borderWidth;
  4554. break;
  4555. default:
  4556. x = this.titleOption.x - 0;
  4557. x = isNaN(x) ? 0 : x;
  4558. break;
  4559. }
  4560. var y;
  4561. var zrHeight = this.zr.getHeight();
  4562. switch (this.titleOption.y) {
  4563. case 'top':
  4564. y = padding[0] + this.titleOption.borderWidth;
  4565. break;
  4566. case 'bottom':
  4567. y = zrHeight - totalHeight - padding[2] - this.titleOption.borderWidth;
  4568. break;
  4569. case 'center':
  4570. y = Math.floor((zrHeight - totalHeight) / 2);
  4571. break;
  4572. default:
  4573. y = this.titleOption.y - 0;
  4574. y = isNaN(y) ? 0 : y;
  4575. break;
  4576. }
  4577. return {
  4578. x: x,
  4579. y: y,
  4580. width: totalWidth,
  4581. height: totalHeight
  4582. };
  4583. },
  4584. refresh: function (newOption) {
  4585. if (newOption) {
  4586. this.option = newOption;
  4587. this.option.title = this.reformOption(this.option.title);
  4588. this.titleOption = this.option.title;
  4589. this.titleOption.textStyle = this.getTextStyle(this.titleOption.textStyle);
  4590. this.titleOption.subtextStyle = this.getTextStyle(this.titleOption.subtextStyle);
  4591. }
  4592. this.clear();
  4593. this._buildShape();
  4594. }
  4595. };
  4596. zrUtil.inherits(Title, Base);
  4597. require('../component').define('title', Title);
  4598. return Title;
  4599. });define('echarts/component/tooltip', [
  4600. 'require',
  4601. './base',
  4602. '../util/shape/Cross',
  4603. 'zrender/shape/Line',
  4604. 'zrender/shape/Rectangle',
  4605. '../config',
  4606. '../util/ecData',
  4607. 'zrender/config',
  4608. 'zrender/tool/event',
  4609. 'zrender/tool/area',
  4610. 'zrender/tool/color',
  4611. 'zrender/tool/util',
  4612. 'zrender/shape/Base',
  4613. '../component'
  4614. ], function (require) {
  4615. var Base = require('./base');
  4616. var CrossShape = require('../util/shape/Cross');
  4617. var LineShape = require('zrender/shape/Line');
  4618. var RectangleShape = require('zrender/shape/Rectangle');
  4619. var rectangleInstance = new RectangleShape({});
  4620. var ecConfig = require('../config');
  4621. ecConfig.tooltip = {
  4622. zlevel: 1,
  4623. z: 8,
  4624. show: true,
  4625. showContent: true,
  4626. trigger: 'item',
  4627. islandFormatter: '{a} <br/>{b} : {c}',
  4628. showDelay: 20,
  4629. hideDelay: 100,
  4630. transitionDuration: 0.4,
  4631. enterable: false,
  4632. backgroundColor: 'rgba(0,0,0,0.7)',
  4633. borderColor: '#333',
  4634. borderRadius: 4,
  4635. borderWidth: 0,
  4636. padding: 5,
  4637. axisPointer: {
  4638. type: 'line',
  4639. lineStyle: {
  4640. color: '#48b',
  4641. width: 2,
  4642. type: 'solid'
  4643. },
  4644. crossStyle: {
  4645. color: '#1e90ff',
  4646. width: 1,
  4647. type: 'dashed'
  4648. },
  4649. shadowStyle: {
  4650. color: 'rgba(150,150,150,0.3)',
  4651. width: 'auto',
  4652. type: 'default'
  4653. }
  4654. },
  4655. textStyle: { color: '#fff' }
  4656. };
  4657. var ecData = require('../util/ecData');
  4658. var zrConfig = require('zrender/config');
  4659. var zrEvent = require('zrender/tool/event');
  4660. var zrArea = require('zrender/tool/area');
  4661. var zrColor = require('zrender/tool/color');
  4662. var zrUtil = require('zrender/tool/util');
  4663. var zrShapeBase = require('zrender/shape/Base');
  4664. function Tooltip(ecTheme, messageCenter, zr, option, myChart) {
  4665. Base.call(this, ecTheme, messageCenter, zr, option, myChart);
  4666. this.dom = myChart.dom;
  4667. var self = this;
  4668. self._onmousemove = function (param) {
  4669. return self.__onmousemove(param);
  4670. };
  4671. self._onglobalout = function (param) {
  4672. return self.__onglobalout(param);
  4673. };
  4674. this.zr.on(zrConfig.EVENT.MOUSEMOVE, self._onmousemove);
  4675. this.zr.on(zrConfig.EVENT.GLOBALOUT, self._onglobalout);
  4676. self._hide = function (param) {
  4677. return self.__hide(param);
  4678. };
  4679. self._tryShow = function (param) {
  4680. return self.__tryShow(param);
  4681. };
  4682. self._refixed = function (param) {
  4683. return self.__refixed(param);
  4684. };
  4685. self._setContent = function (ticket, res) {
  4686. return self.__setContent(ticket, res);
  4687. };
  4688. this._tDom = this._tDom || document.createElement('div');
  4689. this._tDom.onselectstart = function () {
  4690. return false;
  4691. };
  4692. this._tDom.onmouseover = function () {
  4693. self._mousein = true;
  4694. };
  4695. this._tDom.onmouseout = function () {
  4696. self._mousein = false;
  4697. };
  4698. this._tDom.className = 'echarts-tooltip';
  4699. this._tDom.style.position = 'absolute';
  4700. this.hasAppend = false;
  4701. this._axisLineShape && this.zr.delShape(this._axisLineShape.id);
  4702. this._axisLineShape = new LineShape({
  4703. zlevel: this.getZlevelBase(),
  4704. z: this.getZBase(),
  4705. invisible: true,
  4706. hoverable: false
  4707. });
  4708. this.shapeList.push(this._axisLineShape);
  4709. this.zr.addShape(this._axisLineShape);
  4710. this._axisShadowShape && this.zr.delShape(this._axisShadowShape.id);
  4711. this._axisShadowShape = new LineShape({
  4712. zlevel: this.getZlevelBase(),
  4713. z: 1,
  4714. invisible: true,
  4715. hoverable: false
  4716. });
  4717. this.shapeList.push(this._axisShadowShape);
  4718. this.zr.addShape(this._axisShadowShape);
  4719. this._axisCrossShape && this.zr.delShape(this._axisCrossShape.id);
  4720. this._axisCrossShape = new CrossShape({
  4721. zlevel: this.getZlevelBase(),
  4722. z: this.getZBase(),
  4723. invisible: true,
  4724. hoverable: false
  4725. });
  4726. this.shapeList.push(this._axisCrossShape);
  4727. this.zr.addShape(this._axisCrossShape);
  4728. this.showing = false;
  4729. this.refresh(option);
  4730. }
  4731. Tooltip.prototype = {
  4732. type: ecConfig.COMPONENT_TYPE_TOOLTIP,
  4733. _gCssText: 'position:absolute;display:block;border-style:solid;white-space:nowrap;',
  4734. _style: function (opt) {
  4735. if (!opt) {
  4736. return '';
  4737. }
  4738. var cssText = [];
  4739. if (opt.transitionDuration) {
  4740. var transitionText = 'left ' + opt.transitionDuration + 's,' + 'top ' + opt.transitionDuration + 's';
  4741. cssText.push('transition:' + transitionText);
  4742. cssText.push('-moz-transition:' + transitionText);
  4743. cssText.push('-webkit-transition:' + transitionText);
  4744. cssText.push('-o-transition:' + transitionText);
  4745. }
  4746. if (opt.backgroundColor) {
  4747. cssText.push('background-Color:' + zrColor.toHex(opt.backgroundColor));
  4748. cssText.push('filter:alpha(opacity=70)');
  4749. cssText.push('background-Color:' + opt.backgroundColor);
  4750. }
  4751. if (opt.borderWidth != null) {
  4752. cssText.push('border-width:' + opt.borderWidth + 'px');
  4753. }
  4754. if (opt.borderColor != null) {
  4755. cssText.push('border-color:' + opt.borderColor);
  4756. }
  4757. if (opt.borderRadius != null) {
  4758. cssText.push('border-radius:' + opt.borderRadius + 'px');
  4759. cssText.push('-moz-border-radius:' + opt.borderRadius + 'px');
  4760. cssText.push('-webkit-border-radius:' + opt.borderRadius + 'px');
  4761. cssText.push('-o-border-radius:' + opt.borderRadius + 'px');
  4762. }
  4763. var textStyle = opt.textStyle;
  4764. if (textStyle) {
  4765. textStyle.color && cssText.push('color:' + textStyle.color);
  4766. textStyle.decoration && cssText.push('text-decoration:' + textStyle.decoration);
  4767. textStyle.align && cssText.push('text-align:' + textStyle.align);
  4768. textStyle.fontFamily && cssText.push('font-family:' + textStyle.fontFamily);
  4769. textStyle.fontSize && cssText.push('font-size:' + textStyle.fontSize + 'px');
  4770. textStyle.fontSize && cssText.push('line-height:' + Math.round(textStyle.fontSize * 3 / 2) + 'px');
  4771. textStyle.fontStyle && cssText.push('font-style:' + textStyle.fontStyle);
  4772. textStyle.fontWeight && cssText.push('font-weight:' + textStyle.fontWeight);
  4773. }
  4774. var padding = opt.padding;
  4775. if (padding != null) {
  4776. padding = this.reformCssArray(padding);
  4777. cssText.push('padding:' + padding[0] + 'px ' + padding[1] + 'px ' + padding[2] + 'px ' + padding[3] + 'px');
  4778. }
  4779. cssText = cssText.join(';') + ';';
  4780. return cssText;
  4781. },
  4782. __hide: function () {
  4783. this._lastDataIndex = -1;
  4784. this._lastSeriesIndex = -1;
  4785. this._lastItemTriggerId = -1;
  4786. if (this._tDom) {
  4787. this._tDom.style.display = 'none';
  4788. }
  4789. var needRefresh = false;
  4790. if (!this._axisLineShape.invisible) {
  4791. this._axisLineShape.invisible = true;
  4792. this.zr.modShape(this._axisLineShape.id);
  4793. needRefresh = true;
  4794. }
  4795. if (!this._axisShadowShape.invisible) {
  4796. this._axisShadowShape.invisible = true;
  4797. this.zr.modShape(this._axisShadowShape.id);
  4798. needRefresh = true;
  4799. }
  4800. if (!this._axisCrossShape.invisible) {
  4801. this._axisCrossShape.invisible = true;
  4802. this.zr.modShape(this._axisCrossShape.id);
  4803. needRefresh = true;
  4804. }
  4805. if (this._lastTipShape && this._lastTipShape.tipShape.length > 0) {
  4806. this.zr.delShape(this._lastTipShape.tipShape);
  4807. this._lastTipShape = false;
  4808. this.shapeList.length = 2;
  4809. }
  4810. needRefresh && this.zr.refreshNextFrame();
  4811. this.showing = false;
  4812. },
  4813. _show: function (position, x, y, specialCssText) {
  4814. var domHeight = this._tDom.offsetHeight;
  4815. var domWidth = this._tDom.offsetWidth;
  4816. if (position) {
  4817. if (typeof position === 'function') {
  4818. position = position([
  4819. x,
  4820. y
  4821. ]);
  4822. }
  4823. if (position instanceof Array) {
  4824. x = position[0];
  4825. y = position[1];
  4826. }
  4827. }
  4828. if (x + domWidth > this._zrWidth) {
  4829. x -= domWidth + 40;
  4830. }
  4831. if (y + domHeight > this._zrHeight) {
  4832. y -= domHeight - 20;
  4833. }
  4834. if (y < 20) {
  4835. y = 0;
  4836. }
  4837. this._tDom.style.cssText = this._gCssText + this._defaultCssText + (specialCssText ? specialCssText : '') + 'left:' + x + 'px;top:' + y + 'px;';
  4838. if (domHeight < 10 || domWidth < 10) {
  4839. setTimeout(this._refixed, 20);
  4840. }
  4841. this.showing = true;
  4842. },
  4843. __refixed: function () {
  4844. if (this._tDom) {
  4845. var cssText = '';
  4846. var domHeight = this._tDom.offsetHeight;
  4847. var domWidth = this._tDom.offsetWidth;
  4848. if (this._tDom.offsetLeft + domWidth > this._zrWidth) {
  4849. cssText += 'left:' + (this._zrWidth - domWidth - 20) + 'px;';
  4850. }
  4851. if (this._tDom.offsetTop + domHeight > this._zrHeight) {
  4852. cssText += 'top:' + (this._zrHeight - domHeight - 10) + 'px;';
  4853. }
  4854. if (cssText !== '') {
  4855. this._tDom.style.cssText += cssText;
  4856. }
  4857. }
  4858. },
  4859. __tryShow: function () {
  4860. var needShow;
  4861. var trigger;
  4862. if (!this._curTarget) {
  4863. this._findPolarTrigger() || this._findAxisTrigger();
  4864. } else {
  4865. if (this._curTarget._type === 'island' && this.option.tooltip.show) {
  4866. this._showItemTrigger();
  4867. return;
  4868. }
  4869. var serie = ecData.get(this._curTarget, 'series');
  4870. var data = ecData.get(this._curTarget, 'data');
  4871. needShow = this.deepQuery([
  4872. data,
  4873. serie,
  4874. this.option
  4875. ], 'tooltip.show');
  4876. if (serie == null || data == null || !needShow) {
  4877. clearTimeout(this._hidingTicket);
  4878. clearTimeout(this._showingTicket);
  4879. this._hidingTicket = setTimeout(this._hide, this._hideDelay);
  4880. } else {
  4881. trigger = this.deepQuery([
  4882. data,
  4883. serie,
  4884. this.option
  4885. ], 'tooltip.trigger');
  4886. trigger === 'axis' ? this._showAxisTrigger(serie.xAxisIndex, serie.yAxisIndex, ecData.get(this._curTarget, 'dataIndex')) : this._showItemTrigger();
  4887. }
  4888. }
  4889. },
  4890. _findAxisTrigger: function () {
  4891. if (!this.component.xAxis || !this.component.yAxis) {
  4892. this._hidingTicket = setTimeout(this._hide, this._hideDelay);
  4893. return;
  4894. }
  4895. var series = this.option.series;
  4896. var xAxisIndex;
  4897. var yAxisIndex;
  4898. for (var i = 0, l = series.length; i < l; i++) {
  4899. if (this.deepQuery([
  4900. series[i],
  4901. this.option
  4902. ], 'tooltip.trigger') === 'axis') {
  4903. xAxisIndex = series[i].xAxisIndex || 0;
  4904. yAxisIndex = series[i].yAxisIndex || 0;
  4905. if (this.component.xAxis.getAxis(xAxisIndex) && this.component.xAxis.getAxis(xAxisIndex).type === ecConfig.COMPONENT_TYPE_AXIS_CATEGORY) {
  4906. this._showAxisTrigger(xAxisIndex, yAxisIndex, this._getNearestDataIndex('x', this.component.xAxis.getAxis(xAxisIndex)));
  4907. return;
  4908. } else if (this.component.yAxis.getAxis(yAxisIndex) && this.component.yAxis.getAxis(yAxisIndex).type === ecConfig.COMPONENT_TYPE_AXIS_CATEGORY) {
  4909. this._showAxisTrigger(xAxisIndex, yAxisIndex, this._getNearestDataIndex('y', this.component.yAxis.getAxis(yAxisIndex)));
  4910. return;
  4911. } else {
  4912. this._showAxisTrigger(xAxisIndex, yAxisIndex, -1);
  4913. return;
  4914. }
  4915. }
  4916. }
  4917. if (this.option.tooltip.axisPointer.type === 'cross') {
  4918. this._showAxisTrigger(-1, -1, -1);
  4919. }
  4920. },
  4921. _findPolarTrigger: function () {
  4922. if (!this.component.polar) {
  4923. return false;
  4924. }
  4925. var x = zrEvent.getX(this._event);
  4926. var y = zrEvent.getY(this._event);
  4927. var polarIndex = this.component.polar.getNearestIndex([
  4928. x,
  4929. y
  4930. ]);
  4931. var valueIndex;
  4932. if (polarIndex) {
  4933. valueIndex = polarIndex.valueIndex;
  4934. polarIndex = polarIndex.polarIndex;
  4935. } else {
  4936. polarIndex = -1;
  4937. }
  4938. if (polarIndex != -1) {
  4939. return this._showPolarTrigger(polarIndex, valueIndex);
  4940. }
  4941. return false;
  4942. },
  4943. _getNearestDataIndex: function (direction, categoryAxis) {
  4944. var dataIndex = -1;
  4945. var x = zrEvent.getX(this._event);
  4946. var y = zrEvent.getY(this._event);
  4947. if (direction === 'x') {
  4948. var left;
  4949. var right;
  4950. var xEnd = this.component.grid.getXend();
  4951. var curCoord = categoryAxis.getCoordByIndex(dataIndex);
  4952. while (curCoord < xEnd) {
  4953. right = curCoord;
  4954. if (curCoord <= x) {
  4955. left = curCoord;
  4956. } else {
  4957. break;
  4958. }
  4959. curCoord = categoryAxis.getCoordByIndex(++dataIndex);
  4960. }
  4961. if (dataIndex <= 0) {
  4962. dataIndex = 0;
  4963. } else if (x - left <= right - x) {
  4964. dataIndex -= 1;
  4965. } else {
  4966. if (categoryAxis.getNameByIndex(dataIndex) == null) {
  4967. dataIndex -= 1;
  4968. }
  4969. }
  4970. return dataIndex;
  4971. } else {
  4972. var top;
  4973. var bottom;
  4974. var yStart = this.component.grid.getY();
  4975. var curCoord = categoryAxis.getCoordByIndex(dataIndex);
  4976. while (curCoord > yStart) {
  4977. top = curCoord;
  4978. if (curCoord >= y) {
  4979. bottom = curCoord;
  4980. } else {
  4981. break;
  4982. }
  4983. curCoord = categoryAxis.getCoordByIndex(++dataIndex);
  4984. }
  4985. if (dataIndex <= 0) {
  4986. dataIndex = 0;
  4987. } else if (y - top >= bottom - y) {
  4988. dataIndex -= 1;
  4989. } else {
  4990. if (categoryAxis.getNameByIndex(dataIndex) == null) {
  4991. dataIndex -= 1;
  4992. }
  4993. }
  4994. return dataIndex;
  4995. }
  4996. return -1;
  4997. },
  4998. _showAxisTrigger: function (xAxisIndex, yAxisIndex, dataIndex) {
  4999. !this._event.connectTrigger && this.messageCenter.dispatch(ecConfig.EVENT.TOOLTIP_IN_GRID, this._event, null, this.myChart);
  5000. if (this.component.xAxis == null || this.component.yAxis == null || xAxisIndex == null || yAxisIndex == null) {
  5001. clearTimeout(this._hidingTicket);
  5002. clearTimeout(this._showingTicket);
  5003. this._hidingTicket = setTimeout(this._hide, this._hideDelay);
  5004. return;
  5005. }
  5006. var series = this.option.series;
  5007. var seriesArray = [];
  5008. var seriesIndex = [];
  5009. var categoryAxis;
  5010. var formatter;
  5011. var position;
  5012. var showContent;
  5013. var specialCssText = '';
  5014. if (this.option.tooltip.trigger === 'axis') {
  5015. if (!this.option.tooltip.show) {
  5016. return;
  5017. }
  5018. formatter = this.option.tooltip.formatter;
  5019. position = this.option.tooltip.position;
  5020. }
  5021. var axisLayout = xAxisIndex != -1 && this.component.xAxis.getAxis(xAxisIndex).type === ecConfig.COMPONENT_TYPE_AXIS_CATEGORY ? 'xAxis' : yAxisIndex != -1 && this.component.yAxis.getAxis(yAxisIndex).type === ecConfig.COMPONENT_TYPE_AXIS_CATEGORY ? 'yAxis' : false;
  5022. var x;
  5023. var y;
  5024. if (axisLayout) {
  5025. var axisIndex = axisLayout == 'xAxis' ? xAxisIndex : yAxisIndex;
  5026. categoryAxis = this.component[axisLayout].getAxis(axisIndex);
  5027. for (var i = 0, l = series.length; i < l; i++) {
  5028. if (!this._isSelected(series[i].name)) {
  5029. continue;
  5030. }
  5031. if (series[i][axisLayout + 'Index'] === axisIndex && this.deepQuery([
  5032. series[i],
  5033. this.option
  5034. ], 'tooltip.trigger') === 'axis') {
  5035. showContent = this.query(series[i], 'tooltip.showContent') || showContent;
  5036. formatter = this.query(series[i], 'tooltip.formatter') || formatter;
  5037. position = this.query(series[i], 'tooltip.position') || position;
  5038. specialCssText += this._style(this.query(series[i], 'tooltip'));
  5039. if (series[i].stack != null && axisLayout == 'xAxis') {
  5040. seriesArray.unshift(series[i]);
  5041. seriesIndex.unshift(i);
  5042. } else {
  5043. seriesArray.push(series[i]);
  5044. seriesIndex.push(i);
  5045. }
  5046. }
  5047. }
  5048. this.messageCenter.dispatch(ecConfig.EVENT.TOOLTIP_HOVER, this._event, {
  5049. seriesIndex: seriesIndex,
  5050. dataIndex: dataIndex
  5051. }, this.myChart);
  5052. var rect;
  5053. if (axisLayout == 'xAxis') {
  5054. x = this.subPixelOptimize(categoryAxis.getCoordByIndex(dataIndex), this._axisLineWidth);
  5055. y = zrEvent.getY(this._event);
  5056. rect = [
  5057. x,
  5058. this.component.grid.getY(),
  5059. x,
  5060. this.component.grid.getYend()
  5061. ];
  5062. } else {
  5063. x = zrEvent.getX(this._event);
  5064. y = this.subPixelOptimize(categoryAxis.getCoordByIndex(dataIndex), this._axisLineWidth);
  5065. rect = [
  5066. this.component.grid.getX(),
  5067. y,
  5068. this.component.grid.getXend(),
  5069. y
  5070. ];
  5071. }
  5072. this._styleAxisPointer(seriesArray, rect[0], rect[1], rect[2], rect[3], categoryAxis.getGap(), x, y);
  5073. } else {
  5074. x = zrEvent.getX(this._event);
  5075. y = zrEvent.getY(this._event);
  5076. this._styleAxisPointer(series, this.component.grid.getX(), y, this.component.grid.getXend(), y, 0, x, y);
  5077. if (dataIndex >= 0) {
  5078. this._showItemTrigger(true);
  5079. } else {
  5080. clearTimeout(this._hidingTicket);
  5081. clearTimeout(this._showingTicket);
  5082. this._tDom.style.display = 'none';
  5083. }
  5084. }
  5085. if (seriesArray.length > 0) {
  5086. this._lastItemTriggerId = -1;
  5087. if (this._lastDataIndex != dataIndex || this._lastSeriesIndex != seriesIndex[0]) {
  5088. this._lastDataIndex = dataIndex;
  5089. this._lastSeriesIndex = seriesIndex[0];
  5090. var data;
  5091. var value;
  5092. if (typeof formatter === 'function') {
  5093. var params = [];
  5094. for (var i = 0, l = seriesArray.length; i < l; i++) {
  5095. data = seriesArray[i].data[dataIndex];
  5096. value = this.getDataFromOption(data, '-');
  5097. params.push({
  5098. seriesIndex: seriesIndex[i],
  5099. seriesName: seriesArray[i].name || '',
  5100. series: seriesArray[i],
  5101. dataIndex: dataIndex,
  5102. data: data,
  5103. name: categoryAxis.getNameByIndex(dataIndex),
  5104. value: value,
  5105. 0: seriesArray[i].name || '',
  5106. 1: categoryAxis.getNameByIndex(dataIndex),
  5107. 2: value,
  5108. 3: data
  5109. });
  5110. }
  5111. this._curTicket = 'axis:' + dataIndex;
  5112. this._tDom.innerHTML = formatter.call(this.myChart, params, this._curTicket, this._setContent);
  5113. } else if (typeof formatter === 'string') {
  5114. this._curTicket = NaN;
  5115. formatter = formatter.replace('{a}', '{a0}').replace('{b}', '{b0}').replace('{c}', '{c0}');
  5116. for (var i = 0, l = seriesArray.length; i < l; i++) {
  5117. formatter = formatter.replace('{a' + i + '}', this._encodeHTML(seriesArray[i].name || ''));
  5118. formatter = formatter.replace('{b' + i + '}', this._encodeHTML(categoryAxis.getNameByIndex(dataIndex)));
  5119. data = seriesArray[i].data[dataIndex];
  5120. data = this.getDataFromOption(data, '-');
  5121. formatter = formatter.replace('{c' + i + '}', data instanceof Array ? data : this.numAddCommas(data));
  5122. }
  5123. this._tDom.innerHTML = formatter;
  5124. } else {
  5125. this._curTicket = NaN;
  5126. formatter = this._encodeHTML(categoryAxis.getNameByIndex(dataIndex));
  5127. for (var i = 0, l = seriesArray.length; i < l; i++) {
  5128. formatter += '<br/>' + this._encodeHTML(seriesArray[i].name || '') + ' : ';
  5129. data = seriesArray[i].data[dataIndex];
  5130. data = this.getDataFromOption(data, '-');
  5131. formatter += data instanceof Array ? data : this.numAddCommas(data);
  5132. }
  5133. this._tDom.innerHTML = formatter;
  5134. }
  5135. }
  5136. if (showContent === false || !this.option.tooltip.showContent) {
  5137. return;
  5138. }
  5139. if (!this.hasAppend) {
  5140. this._tDom.style.left = this._zrWidth / 2 + 'px';
  5141. this._tDom.style.top = this._zrHeight / 2 + 'px';
  5142. this.dom.firstChild.appendChild(this._tDom);
  5143. this.hasAppend = true;
  5144. }
  5145. this._show(position, x + 10, y + 10, specialCssText);
  5146. }
  5147. },
  5148. _showPolarTrigger: function (polarIndex, dataIndex) {
  5149. if (this.component.polar == null || polarIndex == null || dataIndex == null || dataIndex < 0) {
  5150. return false;
  5151. }
  5152. var series = this.option.series;
  5153. var seriesArray = [];
  5154. var seriesIndex = [];
  5155. var formatter;
  5156. var position;
  5157. var showContent;
  5158. var specialCssText = '';
  5159. if (this.option.tooltip.trigger === 'axis') {
  5160. if (!this.option.tooltip.show) {
  5161. return false;
  5162. }
  5163. formatter = this.option.tooltip.formatter;
  5164. position = this.option.tooltip.position;
  5165. }
  5166. var indicatorName = this.option.polar[polarIndex].indicator[dataIndex].text;
  5167. for (var i = 0, l = series.length; i < l; i++) {
  5168. if (!this._isSelected(series[i].name)) {
  5169. continue;
  5170. }
  5171. if (series[i].polarIndex === polarIndex && this.deepQuery([
  5172. series[i],
  5173. this.option
  5174. ], 'tooltip.trigger') === 'axis') {
  5175. showContent = this.query(series[i], 'tooltip.showContent') || showContent;
  5176. formatter = this.query(series[i], 'tooltip.formatter') || formatter;
  5177. position = this.query(series[i], 'tooltip.position') || position;
  5178. specialCssText += this._style(this.query(series[i], 'tooltip'));
  5179. seriesArray.push(series[i]);
  5180. seriesIndex.push(i);
  5181. }
  5182. }
  5183. if (seriesArray.length > 0) {
  5184. var polarData;
  5185. var data;
  5186. var value;
  5187. var params = [];
  5188. for (var i = 0, l = seriesArray.length; i < l; i++) {
  5189. polarData = seriesArray[i].data;
  5190. for (var j = 0, k = polarData.length; j < k; j++) {
  5191. data = polarData[j];
  5192. if (!this._isSelected(data.name)) {
  5193. continue;
  5194. }
  5195. data = data != null ? data : {
  5196. name: '',
  5197. value: { dataIndex: '-' }
  5198. };
  5199. value = this.getDataFromOption(data.value[dataIndex]);
  5200. params.push({
  5201. seriesIndex: seriesIndex[i],
  5202. seriesName: seriesArray[i].name || '',
  5203. series: seriesArray[i],
  5204. dataIndex: dataIndex,
  5205. data: data,
  5206. name: data.name,
  5207. indicator: indicatorName,
  5208. value: value,
  5209. 0: seriesArray[i].name || '',
  5210. 1: data.name,
  5211. 2: value,
  5212. 3: indicatorName
  5213. });
  5214. }
  5215. }
  5216. if (params.length <= 0) {
  5217. return;
  5218. }
  5219. this._lastItemTriggerId = -1;
  5220. if (this._lastDataIndex != dataIndex || this._lastSeriesIndex != seriesIndex[0]) {
  5221. this._lastDataIndex = dataIndex;
  5222. this._lastSeriesIndex = seriesIndex[0];
  5223. if (typeof formatter === 'function') {
  5224. this._curTicket = 'axis:' + dataIndex;
  5225. this._tDom.innerHTML = formatter.call(this.myChart, params, this._curTicket, this._setContent);
  5226. } else if (typeof formatter === 'string') {
  5227. formatter = formatter.replace('{a}', '{a0}').replace('{b}', '{b0}').replace('{c}', '{c0}').replace('{d}', '{d0}');
  5228. for (var i = 0, l = params.length; i < l; i++) {
  5229. formatter = formatter.replace('{a' + i + '}', this._encodeHTML(params[i].seriesName));
  5230. formatter = formatter.replace('{b' + i + '}', this._encodeHTML(params[i].name));
  5231. formatter = formatter.replace('{c' + i + '}', this.numAddCommas(params[i].value));
  5232. formatter = formatter.replace('{d' + i + '}', this._encodeHTML(params[i].indicator));
  5233. }
  5234. this._tDom.innerHTML = formatter;
  5235. } else {
  5236. formatter = this._encodeHTML(params[0].name) + '<br/>' + this._encodeHTML(params[0].indicator) + ' : ' + this.numAddCommas(params[0].value);
  5237. for (var i = 1, l = params.length; i < l; i++) {
  5238. formatter += '<br/>' + this._encodeHTML(params[i].name) + '<br/>';
  5239. formatter += this._encodeHTML(params[i].indicator) + ' : ' + this.numAddCommas(params[i].value);
  5240. }
  5241. this._tDom.innerHTML = formatter;
  5242. }
  5243. }
  5244. if (showContent === false || !this.option.tooltip.showContent) {
  5245. return;
  5246. }
  5247. if (!this.hasAppend) {
  5248. this._tDom.style.left = this._zrWidth / 2 + 'px';
  5249. this._tDom.style.top = this._zrHeight / 2 + 'px';
  5250. this.dom.firstChild.appendChild(this._tDom);
  5251. this.hasAppend = true;
  5252. }
  5253. this._show(position, zrEvent.getX(this._event), zrEvent.getY(this._event), specialCssText);
  5254. return true;
  5255. }
  5256. },
  5257. _showItemTrigger: function (axisTrigger) {
  5258. if (!this._curTarget) {
  5259. return;
  5260. }
  5261. var serie = ecData.get(this._curTarget, 'series');
  5262. var seriesIndex = ecData.get(this._curTarget, 'seriesIndex');
  5263. var data = ecData.get(this._curTarget, 'data');
  5264. var dataIndex = ecData.get(this._curTarget, 'dataIndex');
  5265. var name = ecData.get(this._curTarget, 'name');
  5266. var value = ecData.get(this._curTarget, 'value');
  5267. var special = ecData.get(this._curTarget, 'special');
  5268. var special2 = ecData.get(this._curTarget, 'special2');
  5269. var queryTarget = [
  5270. data,
  5271. serie,
  5272. this.option
  5273. ];
  5274. var formatter;
  5275. var position;
  5276. var showContent;
  5277. var specialCssText = '';
  5278. if (this._curTarget._type != 'island') {
  5279. var trigger = axisTrigger ? 'axis' : 'item';
  5280. if (this.option.tooltip.trigger === trigger) {
  5281. formatter = this.option.tooltip.formatter;
  5282. position = this.option.tooltip.position;
  5283. }
  5284. if (this.query(serie, 'tooltip.trigger') === trigger) {
  5285. showContent = this.query(serie, 'tooltip.showContent') || showContent;
  5286. formatter = this.query(serie, 'tooltip.formatter') || formatter;
  5287. position = this.query(serie, 'tooltip.position') || position;
  5288. specialCssText += this._style(this.query(serie, 'tooltip'));
  5289. }
  5290. showContent = this.query(data, 'tooltip.showContent') || showContent;
  5291. formatter = this.query(data, 'tooltip.formatter') || formatter;
  5292. position = this.query(data, 'tooltip.position') || position;
  5293. specialCssText += this._style(this.query(data, 'tooltip'));
  5294. } else {
  5295. this._lastItemTriggerId = NaN;
  5296. showContent = this.deepQuery(queryTarget, 'tooltip.showContent');
  5297. formatter = this.deepQuery(queryTarget, 'tooltip.islandFormatter');
  5298. position = this.deepQuery(queryTarget, 'tooltip.islandPosition');
  5299. }
  5300. this._lastDataIndex = -1;
  5301. this._lastSeriesIndex = -1;
  5302. if (this._lastItemTriggerId !== this._curTarget.id) {
  5303. this._lastItemTriggerId = this._curTarget.id;
  5304. if (typeof formatter === 'function') {
  5305. this._curTicket = (serie.name || '') + ':' + dataIndex;
  5306. this._tDom.innerHTML = formatter.call(this.myChart, {
  5307. seriesIndex: seriesIndex,
  5308. seriesName: serie.name || '',
  5309. series: serie,
  5310. dataIndex: dataIndex,
  5311. data: data,
  5312. name: name,
  5313. value: value,
  5314. percent: special,
  5315. indicator: special,
  5316. value2: special2,
  5317. indicator2: special2,
  5318. 0: serie.name || '',
  5319. 1: name,
  5320. 2: value,
  5321. 3: special,
  5322. 4: special2,
  5323. 5: data,
  5324. 6: seriesIndex,
  5325. 7: dataIndex
  5326. }, this._curTicket, this._setContent);
  5327. } else if (typeof formatter === 'string') {
  5328. this._curTicket = NaN;
  5329. formatter = formatter.replace('{a}', '{a0}').replace('{b}', '{b0}').replace('{c}', '{c0}');
  5330. formatter = formatter.replace('{a0}', this._encodeHTML(serie.name || '')).replace('{b0}', this._encodeHTML(name)).replace('{c0}', value instanceof Array ? value : this.numAddCommas(value));
  5331. formatter = formatter.replace('{d}', '{d0}').replace('{d0}', special || '');
  5332. formatter = formatter.replace('{e}', '{e0}').replace('{e0}', ecData.get(this._curTarget, 'special2') || '');
  5333. this._tDom.innerHTML = formatter;
  5334. } else {
  5335. this._curTicket = NaN;
  5336. if (serie.type === ecConfig.CHART_TYPE_RADAR && special) {
  5337. this._tDom.innerHTML = this._itemFormatter.radar.call(this, serie, name, value, special);
  5338. } else if (serie.type === ecConfig.CHART_TYPE_EVENTRIVER) {
  5339. this._tDom.innerHTML = this._itemFormatter.eventRiver.call(this, serie, name, value, data);
  5340. } else {
  5341. this._tDom.innerHTML = '' + (serie.name != null ? this._encodeHTML(serie.name) + '<br/>' : '') + (name === '' ? '' : this._encodeHTML(name) + ' : ') + (value instanceof Array ? value : this.numAddCommas(value));
  5342. }
  5343. }
  5344. }
  5345. var x = zrEvent.getX(this._event);
  5346. var y = zrEvent.getY(this._event);
  5347. if (this.deepQuery(queryTarget, 'tooltip.axisPointer.show') && this.component.grid) {
  5348. this._styleAxisPointer([serie], this.component.grid.getX(), y, this.component.grid.getXend(), y, 0, x, y);
  5349. } else {
  5350. this._hide();
  5351. }
  5352. if (showContent === false || !this.option.tooltip.showContent) {
  5353. return;
  5354. }
  5355. if (!this.hasAppend) {
  5356. this._tDom.style.left = this._zrWidth / 2 + 'px';
  5357. this._tDom.style.top = this._zrHeight / 2 + 'px';
  5358. this.dom.firstChild.appendChild(this._tDom);
  5359. this.hasAppend = true;
  5360. }
  5361. this._show(position, x + 20, y - 20, specialCssText);
  5362. },
  5363. _itemFormatter: {
  5364. radar: function (serie, name, value, indicator) {
  5365. var html = '';
  5366. html += this._encodeHTML(name === '' ? serie.name || '' : name);
  5367. html += html === '' ? '' : '<br />';
  5368. for (var i = 0; i < indicator.length; i++) {
  5369. html += this._encodeHTML(indicator[i].text) + ' : ' + this.numAddCommas(value[i]) + '<br />';
  5370. }
  5371. return html;
  5372. },
  5373. chord: function (serie, name, value, special, special2) {
  5374. if (special2 == null) {
  5375. return this._encodeHTML(name) + ' (' + this.numAddCommas(value) + ')';
  5376. } else {
  5377. var name1 = this._encodeHTML(name);
  5378. var name2 = this._encodeHTML(special);
  5379. return '' + (serie.name != null ? this._encodeHTML(serie.name) + '<br/>' : '') + name1 + ' -> ' + name2 + ' (' + this.numAddCommas(value) + ')' + '<br />' + name2 + ' -> ' + name1 + ' (' + this.numAddCommas(special2) + ')';
  5380. }
  5381. },
  5382. eventRiver: function (serie, name, value, data) {
  5383. var html = '';
  5384. html += this._encodeHTML(serie.name === '' ? '' : serie.name + ' : ');
  5385. html += this._encodeHTML(name);
  5386. html += html === '' ? '' : '<br />';
  5387. data = data.evolution;
  5388. for (var i = 0, l = data.length; i < l; i++) {
  5389. html += '<div style="padding-top:5px;">';
  5390. if (!data[i].detail) {
  5391. continue;
  5392. }
  5393. if (data[i].detail.img) {
  5394. html += '<img src="' + data[i].detail.img + '" style="float:left;width:40px;height:40px;">';
  5395. }
  5396. html += '<div style="margin-left:45px;">' + data[i].time + '<br/>';
  5397. html += '<a href="' + data[i].detail.link + '" target="_blank">';
  5398. html += data[i].detail.text + '</a></div>';
  5399. html += '</div>';
  5400. }
  5401. return html;
  5402. }
  5403. },
  5404. _styleAxisPointer: function (seriesArray, xStart, yStart, xEnd, yEnd, gap, x, y) {
  5405. if (seriesArray.length > 0) {
  5406. var queryTarget;
  5407. var curType;
  5408. var axisPointer = this.option.tooltip.axisPointer;
  5409. var pointType = axisPointer.type;
  5410. var style = {
  5411. line: {},
  5412. cross: {},
  5413. shadow: {}
  5414. };
  5415. for (var pType in style) {
  5416. style[pType].color = axisPointer[pType + 'Style'].color;
  5417. style[pType].width = axisPointer[pType + 'Style'].width;
  5418. style[pType].type = axisPointer[pType + 'Style'].type;
  5419. }
  5420. for (var i = 0, l = seriesArray.length; i < l; i++) {
  5421. queryTarget = seriesArray[i];
  5422. curType = this.query(queryTarget, 'tooltip.axisPointer.type');
  5423. pointType = curType || pointType;
  5424. if (curType) {
  5425. style[curType].color = this.query(queryTarget, 'tooltip.axisPointer.' + curType + 'Style.color') || style[curType].color;
  5426. style[curType].width = this.query(queryTarget, 'tooltip.axisPointer.' + curType + 'Style.width') || style[curType].width;
  5427. style[curType].type = this.query(queryTarget, 'tooltip.axisPointer.' + curType + 'Style.type') || style[curType].type;
  5428. }
  5429. }
  5430. if (pointType === 'line') {
  5431. var lineWidth = style.line.width;
  5432. var isVertical = xStart == xEnd;
  5433. this._axisLineShape.style = {
  5434. xStart: isVertical ? this.subPixelOptimize(xStart, lineWidth) : xStart,
  5435. yStart: isVertical ? yStart : this.subPixelOptimize(yStart, lineWidth),
  5436. xEnd: isVertical ? this.subPixelOptimize(xEnd, lineWidth) : xEnd,
  5437. yEnd: isVertical ? yEnd : this.subPixelOptimize(yEnd, lineWidth),
  5438. strokeColor: style.line.color,
  5439. lineWidth: lineWidth,
  5440. lineType: style.line.type
  5441. };
  5442. this._axisLineShape.invisible = false;
  5443. this.zr.modShape(this._axisLineShape.id);
  5444. } else if (pointType === 'cross') {
  5445. var crossWidth = style.cross.width;
  5446. this._axisCrossShape.style = {
  5447. brushType: 'stroke',
  5448. rect: this.component.grid.getArea(),
  5449. x: this.subPixelOptimize(x, crossWidth),
  5450. y: this.subPixelOptimize(y, crossWidth),
  5451. text: ('( ' + this.component.xAxis.getAxis(0).getValueFromCoord(x) + ' , ' + this.component.yAxis.getAxis(0).getValueFromCoord(y) + ' )').replace(' , ', ' ').replace(' , ', ' '),
  5452. textPosition: 'specific',
  5453. strokeColor: style.cross.color,
  5454. lineWidth: crossWidth,
  5455. lineType: style.cross.type
  5456. };
  5457. if (this.component.grid.getXend() - x > 100) {
  5458. this._axisCrossShape.style.textAlign = 'left';
  5459. this._axisCrossShape.style.textX = x + 10;
  5460. } else {
  5461. this._axisCrossShape.style.textAlign = 'right';
  5462. this._axisCrossShape.style.textX = x - 10;
  5463. }
  5464. if (y - this.component.grid.getY() > 50) {
  5465. this._axisCrossShape.style.textBaseline = 'bottom';
  5466. this._axisCrossShape.style.textY = y - 10;
  5467. } else {
  5468. this._axisCrossShape.style.textBaseline = 'top';
  5469. this._axisCrossShape.style.textY = y + 10;
  5470. }
  5471. this._axisCrossShape.invisible = false;
  5472. this.zr.modShape(this._axisCrossShape.id);
  5473. } else if (pointType === 'shadow') {
  5474. if (style.shadow.width == null || style.shadow.width === 'auto' || isNaN(style.shadow.width)) {
  5475. style.shadow.width = gap;
  5476. }
  5477. if (xStart === xEnd) {
  5478. if (Math.abs(this.component.grid.getX() - xStart) < 2) {
  5479. style.shadow.width /= 2;
  5480. xStart = xEnd = xEnd + style.shadow.width / 2;
  5481. } else if (Math.abs(this.component.grid.getXend() - xStart) < 2) {
  5482. style.shadow.width /= 2;
  5483. xStart = xEnd = xEnd - style.shadow.width / 2;
  5484. }
  5485. } else if (yStart === yEnd) {
  5486. if (Math.abs(this.component.grid.getY() - yStart) < 2) {
  5487. style.shadow.width /= 2;
  5488. yStart = yEnd = yEnd + style.shadow.width / 2;
  5489. } else if (Math.abs(this.component.grid.getYend() - yStart) < 2) {
  5490. style.shadow.width /= 2;
  5491. yStart = yEnd = yEnd - style.shadow.width / 2;
  5492. }
  5493. }
  5494. this._axisShadowShape.style = {
  5495. xStart: xStart,
  5496. yStart: yStart,
  5497. xEnd: xEnd,
  5498. yEnd: yEnd,
  5499. strokeColor: style.shadow.color,
  5500. lineWidth: style.shadow.width
  5501. };
  5502. this._axisShadowShape.invisible = false;
  5503. this.zr.modShape(this._axisShadowShape.id);
  5504. }
  5505. this.zr.refreshNextFrame();
  5506. }
  5507. },
  5508. __onmousemove: function (param) {
  5509. clearTimeout(this._hidingTicket);
  5510. clearTimeout(this._showingTicket);
  5511. if (this._mousein && this._enterable) {
  5512. return;
  5513. }
  5514. var target = param.target;
  5515. var mx = zrEvent.getX(param.event);
  5516. var my = zrEvent.getY(param.event);
  5517. if (!target) {
  5518. this._curTarget = false;
  5519. this._event = param.event;
  5520. this._event.zrenderX = mx;
  5521. this._event.zrenderY = my;
  5522. if (this._needAxisTrigger && this.component.grid && zrArea.isInside(rectangleInstance, this.component.grid.getArea(), mx, my)) {
  5523. this._showingTicket = setTimeout(this._tryShow, this._showDelay);
  5524. } else if (this._needAxisTrigger && this.component.polar && this.component.polar.isInside([
  5525. mx,
  5526. my
  5527. ]) != -1) {
  5528. this._showingTicket = setTimeout(this._tryShow, this._showDelay);
  5529. } else {
  5530. !this._event.connectTrigger && this.messageCenter.dispatch(ecConfig.EVENT.TOOLTIP_OUT_GRID, this._event, null, this.myChart);
  5531. this._hidingTicket = setTimeout(this._hide, this._hideDelay);
  5532. }
  5533. } else {
  5534. this._curTarget = target;
  5535. this._event = param.event;
  5536. this._event.zrenderX = mx;
  5537. this._event.zrenderY = my;
  5538. var polarIndex;
  5539. if (this._needAxisTrigger && this.component.polar && (polarIndex = this.component.polar.isInside([
  5540. mx,
  5541. my
  5542. ])) != -1) {
  5543. var series = this.option.series;
  5544. for (var i = 0, l = series.length; i < l; i++) {
  5545. if (series[i].polarIndex === polarIndex && this.deepQuery([
  5546. series[i],
  5547. this.option
  5548. ], 'tooltip.trigger') === 'axis') {
  5549. this._curTarget = null;
  5550. break;
  5551. }
  5552. }
  5553. }
  5554. this._showingTicket = setTimeout(this._tryShow, this._showDelay);
  5555. }
  5556. },
  5557. __onglobalout: function () {
  5558. clearTimeout(this._hidingTicket);
  5559. clearTimeout(this._showingTicket);
  5560. this._hidingTicket = setTimeout(this._hide, this._hideDelay);
  5561. },
  5562. __setContent: function (ticket, content) {
  5563. if (!this._tDom) {
  5564. return;
  5565. }
  5566. if (ticket === this._curTicket) {
  5567. this._tDom.innerHTML = content;
  5568. }
  5569. setTimeout(this._refixed, 20);
  5570. },
  5571. ontooltipHover: function (param, tipShape) {
  5572. if (!this._lastTipShape || this._lastTipShape && this._lastTipShape.dataIndex != param.dataIndex) {
  5573. if (this._lastTipShape && this._lastTipShape.tipShape.length > 0) {
  5574. this.zr.delShape(this._lastTipShape.tipShape);
  5575. this.shapeList.length = 2;
  5576. }
  5577. for (var i = 0, l = tipShape.length; i < l; i++) {
  5578. tipShape[i].zlevel = this.getZlevelBase();
  5579. tipShape[i].z = this.getZBase();
  5580. tipShape[i].style = zrShapeBase.prototype.getHighlightStyle(tipShape[i].style, tipShape[i].highlightStyle);
  5581. tipShape[i].draggable = false;
  5582. tipShape[i].hoverable = false;
  5583. tipShape[i].clickable = false;
  5584. tipShape[i].ondragend = null;
  5585. tipShape[i].ondragover = null;
  5586. tipShape[i].ondrop = null;
  5587. this.shapeList.push(tipShape[i]);
  5588. this.zr.addShape(tipShape[i]);
  5589. }
  5590. this._lastTipShape = {
  5591. dataIndex: param.dataIndex,
  5592. tipShape: tipShape
  5593. };
  5594. }
  5595. },
  5596. ondragend: function () {
  5597. this._hide();
  5598. },
  5599. onlegendSelected: function (param) {
  5600. this._selectedMap = param.selected;
  5601. },
  5602. _setSelectedMap: function () {
  5603. if (this.component.legend) {
  5604. this._selectedMap = zrUtil.clone(this.component.legend.getSelectedMap());
  5605. } else {
  5606. this._selectedMap = {};
  5607. }
  5608. },
  5609. _isSelected: function (itemName) {
  5610. if (this._selectedMap[itemName] != null) {
  5611. return this._selectedMap[itemName];
  5612. } else {
  5613. return true;
  5614. }
  5615. },
  5616. showTip: function (params) {
  5617. if (!params) {
  5618. return;
  5619. }
  5620. var seriesIndex;
  5621. var series = this.option.series;
  5622. if (params.seriesIndex != null) {
  5623. seriesIndex = params.seriesIndex;
  5624. } else {
  5625. var seriesName = params.seriesName;
  5626. for (var i = 0, l = series.length; i < l; i++) {
  5627. if (series[i].name === seriesName) {
  5628. seriesIndex = i;
  5629. break;
  5630. }
  5631. }
  5632. }
  5633. var serie = series[seriesIndex];
  5634. if (serie == null) {
  5635. return;
  5636. }
  5637. var chart = this.myChart.chart[serie.type];
  5638. var isAxisTrigger = this.deepQuery([
  5639. serie,
  5640. this.option
  5641. ], 'tooltip.trigger') === 'axis';
  5642. if (!chart) {
  5643. return;
  5644. }
  5645. if (isAxisTrigger) {
  5646. var dataIndex = params.dataIndex;
  5647. switch (chart.type) {
  5648. case ecConfig.CHART_TYPE_LINE:
  5649. case ecConfig.CHART_TYPE_BAR:
  5650. case ecConfig.CHART_TYPE_K:
  5651. case ecConfig.CHART_TYPE_RADAR:
  5652. if (this.component.polar == null || serie.data[0].value.length <= dataIndex) {
  5653. return;
  5654. }
  5655. var polarIndex = serie.polarIndex || 0;
  5656. var vector = this.component.polar.getVector(polarIndex, dataIndex, 'max');
  5657. this._event = {
  5658. zrenderX: vector[0],
  5659. zrenderY: vector[1]
  5660. };
  5661. this._showPolarTrigger(polarIndex, dataIndex);
  5662. break;
  5663. }
  5664. } else {
  5665. var shapeList = chart.shapeList;
  5666. var x;
  5667. var y;
  5668. switch (chart.type) {
  5669. case ecConfig.CHART_TYPE_LINE:
  5670. case ecConfig.CHART_TYPE_BAR:
  5671. case ecConfig.CHART_TYPE_K:
  5672. case ecConfig.CHART_TYPE_TREEMAP:
  5673. case ecConfig.CHART_TYPE_SCATTER:
  5674. var dataIndex = params.dataIndex;
  5675. for (var i = 0, l = shapeList.length; i < l; i++) {
  5676. if (shapeList[i]._mark == null && ecData.get(shapeList[i], 'seriesIndex') == seriesIndex && ecData.get(shapeList[i], 'dataIndex') == dataIndex) {
  5677. this._curTarget = shapeList[i];
  5678. x = shapeList[i].style.x;
  5679. y = chart.type != ecConfig.CHART_TYPE_K ? shapeList[i].style.y : shapeList[i].style.y[0];
  5680. break;
  5681. }
  5682. }
  5683. break;
  5684. case ecConfig.CHART_TYPE_RADAR:
  5685. var dataIndex = params.dataIndex;
  5686. for (var i = 0, l = shapeList.length; i < l; i++) {
  5687. if (shapeList[i].type === 'polygon' && ecData.get(shapeList[i], 'seriesIndex') == seriesIndex && ecData.get(shapeList[i], 'dataIndex') == dataIndex) {
  5688. this._curTarget = shapeList[i];
  5689. var vector = this.component.polar.getCenter(serie.polarIndex || 0);
  5690. x = vector[0];
  5691. y = vector[1];
  5692. break;
  5693. }
  5694. }
  5695. break;
  5696. case ecConfig.CHART_TYPE_PIE:
  5697. var name = params.name;
  5698. for (var i = 0, l = shapeList.length; i < l; i++) {
  5699. if (shapeList[i].type === 'sector' && ecData.get(shapeList[i], 'seriesIndex') == seriesIndex && ecData.get(shapeList[i], 'name') == name) {
  5700. this._curTarget = shapeList[i];
  5701. var style = this._curTarget.style;
  5702. var midAngle = (style.startAngle + style.endAngle) / 2 * Math.PI / 180;
  5703. x = this._curTarget.style.x + Math.cos(midAngle) * style.r / 1.5;
  5704. y = this._curTarget.style.y - Math.sin(midAngle) * style.r / 1.5;
  5705. break;
  5706. }
  5707. }
  5708. break;
  5709. case ecConfig.CHART_TYPE_MAP:
  5710. var name = params.name;
  5711. var mapType = serie.mapType;
  5712. for (var i = 0, l = shapeList.length; i < l; i++) {
  5713. if (shapeList[i].type === 'text' && shapeList[i]._mapType === mapType && shapeList[i].style._name === name) {
  5714. this._curTarget = shapeList[i];
  5715. x = this._curTarget.style.x + this._curTarget.position[0];
  5716. y = this._curTarget.style.y + this._curTarget.position[1];
  5717. break;
  5718. }
  5719. }
  5720. break;
  5721. case ecConfig.CHART_TYPE_CHORD:
  5722. var name = params.name;
  5723. for (var i = 0, l = shapeList.length; i < l; i++) {
  5724. if (shapeList[i].type === 'sector' && ecData.get(shapeList[i], 'name') == name) {
  5725. this._curTarget = shapeList[i];
  5726. var style = this._curTarget.style;
  5727. var midAngle = (style.startAngle + style.endAngle) / 2 * Math.PI / 180;
  5728. x = this._curTarget.style.x + Math.cos(midAngle) * (style.r - 2);
  5729. y = this._curTarget.style.y - Math.sin(midAngle) * (style.r - 2);
  5730. this.zr.trigger(zrConfig.EVENT.MOUSEMOVE, {
  5731. zrenderX: x,
  5732. zrenderY: y
  5733. });
  5734. return;
  5735. }
  5736. }
  5737. break;
  5738. case ecConfig.CHART_TYPE_FORCE:
  5739. var name = params.name;
  5740. for (var i = 0, l = shapeList.length; i < l; i++) {
  5741. if (shapeList[i].type === 'circle' && ecData.get(shapeList[i], 'name') == name) {
  5742. this._curTarget = shapeList[i];
  5743. x = this._curTarget.position[0];
  5744. y = this._curTarget.position[1];
  5745. break;
  5746. }
  5747. }
  5748. break;
  5749. }
  5750. if (x != null && y != null) {
  5751. this._event = {
  5752. zrenderX: x,
  5753. zrenderY: y
  5754. };
  5755. this.zr.addHoverShape(this._curTarget);
  5756. this.zr.refreshHover();
  5757. this._showItemTrigger();
  5758. }
  5759. }
  5760. },
  5761. hideTip: function () {
  5762. this._hide();
  5763. },
  5764. refresh: function (newOption) {
  5765. this._zrHeight = this.zr.getHeight();
  5766. this._zrWidth = this.zr.getWidth();
  5767. if (this._lastTipShape && this._lastTipShape.tipShape.length > 0) {
  5768. this.zr.delShape(this._lastTipShape.tipShape);
  5769. }
  5770. this._lastTipShape = false;
  5771. this.shapeList.length = 2;
  5772. this._lastDataIndex = -1;
  5773. this._lastSeriesIndex = -1;
  5774. this._lastItemTriggerId = -1;
  5775. if (newOption) {
  5776. this.option = newOption;
  5777. this.option.tooltip = this.reformOption(this.option.tooltip);
  5778. this.option.tooltip.textStyle = zrUtil.merge(this.option.tooltip.textStyle, this.ecTheme.textStyle);
  5779. this._needAxisTrigger = false;
  5780. if (this.option.tooltip.trigger === 'axis') {
  5781. this._needAxisTrigger = true;
  5782. }
  5783. var series = this.option.series;
  5784. for (var i = 0, l = series.length; i < l; i++) {
  5785. if (this.query(series[i], 'tooltip.trigger') === 'axis') {
  5786. this._needAxisTrigger = true;
  5787. break;
  5788. }
  5789. }
  5790. this._showDelay = this.option.tooltip.showDelay;
  5791. this._hideDelay = this.option.tooltip.hideDelay;
  5792. this._defaultCssText = this._style(this.option.tooltip);
  5793. this._setSelectedMap();
  5794. this._axisLineWidth = this.option.tooltip.axisPointer.lineStyle.width;
  5795. this._enterable = this.option.tooltip.enterable;
  5796. if (!this._enterable && this._tDom.className.indexOf(zrConfig.elementClassName) < 0) {
  5797. this._tDom.className += ' ' + zrConfig.elementClassName;
  5798. }
  5799. }
  5800. if (this.showing) {
  5801. var self = this;
  5802. setTimeout(function () {
  5803. self.zr.trigger(zrConfig.EVENT.MOUSEMOVE, self.zr.handler._event);
  5804. }, 50);
  5805. }
  5806. },
  5807. onbeforDispose: function () {
  5808. if (this._lastTipShape && this._lastTipShape.tipShape.length > 0) {
  5809. this.zr.delShape(this._lastTipShape.tipShape);
  5810. }
  5811. clearTimeout(this._hidingTicket);
  5812. clearTimeout(this._showingTicket);
  5813. this.zr.un(zrConfig.EVENT.MOUSEMOVE, this._onmousemove);
  5814. this.zr.un(zrConfig.EVENT.GLOBALOUT, this._onglobalout);
  5815. if (this.hasAppend && !!this.dom.firstChild) {
  5816. this.dom.firstChild.removeChild(this._tDom);
  5817. }
  5818. this._tDom = null;
  5819. },
  5820. _encodeHTML: function (source) {
  5821. return String(source).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
  5822. }
  5823. };
  5824. zrUtil.inherits(Tooltip, Base);
  5825. require('../component').define('tooltip', Tooltip);
  5826. return Tooltip;
  5827. });define('echarts/component/legend', [
  5828. 'require',
  5829. './base',
  5830. 'zrender/shape/Text',
  5831. 'zrender/shape/Rectangle',
  5832. 'zrender/shape/Sector',
  5833. '../util/shape/Icon',
  5834. '../util/shape/Candle',
  5835. '../config',
  5836. 'zrender/tool/util',
  5837. 'zrender/tool/area',
  5838. '../component'
  5839. ], function (require) {
  5840. var Base = require('./base');
  5841. var TextShape = require('zrender/shape/Text');
  5842. var RectangleShape = require('zrender/shape/Rectangle');
  5843. var SectorShape = require('zrender/shape/Sector');
  5844. var IconShape = require('../util/shape/Icon');
  5845. var CandleShape = require('../util/shape/Candle');
  5846. var ecConfig = require('../config');
  5847. ecConfig.legend = {
  5848. zlevel: 0,
  5849. z: 4,
  5850. show: true,
  5851. orient: 'horizontal',
  5852. x: 'center',
  5853. y: 'top',
  5854. backgroundColor: 'rgba(0,0,0,0)',
  5855. borderColor: '#ccc',
  5856. borderWidth: 0,
  5857. padding: 5,
  5858. itemGap: 10,
  5859. itemWidth: 20,
  5860. itemHeight: 14,
  5861. textStyle: { color: '#333' },
  5862. selectedMode: true
  5863. };
  5864. var zrUtil = require('zrender/tool/util');
  5865. var zrArea = require('zrender/tool/area');
  5866. function Legend(ecTheme, messageCenter, zr, option, myChart) {
  5867. if (!this.query(option, 'legend.data')) {
  5868. console.error('option.legend.data has not been defined.');
  5869. return;
  5870. }
  5871. Base.call(this, ecTheme, messageCenter, zr, option, myChart);
  5872. var self = this;
  5873. self._legendSelected = function (param) {
  5874. self.__legendSelected(param);
  5875. };
  5876. self._dispatchHoverLink = function (param) {
  5877. return self.__dispatchHoverLink(param);
  5878. };
  5879. this._colorIndex = 0;
  5880. this._colorMap = {};
  5881. this._selectedMap = {};
  5882. this._hasDataMap = {};
  5883. this.refresh(option);
  5884. }
  5885. Legend.prototype = {
  5886. type: ecConfig.COMPONENT_TYPE_LEGEND,
  5887. _buildShape: function () {
  5888. if (!this.legendOption.show) {
  5889. return;
  5890. }
  5891. this._itemGroupLocation = this._getItemGroupLocation();
  5892. this._buildBackground();
  5893. this._buildItem();
  5894. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  5895. this.zr.addShape(this.shapeList[i]);
  5896. }
  5897. },
  5898. _buildItem: function () {
  5899. var data = this.legendOption.data;
  5900. var dataLength = data.length;
  5901. var itemName;
  5902. var itemType;
  5903. var itemShape;
  5904. var textShape;
  5905. var textStyle = this.legendOption.textStyle;
  5906. var dataTextStyle;
  5907. var dataFont;
  5908. var formattedName;
  5909. var zrWidth = this.zr.getWidth();
  5910. var zrHeight = this.zr.getHeight();
  5911. var lastX = this._itemGroupLocation.x;
  5912. var lastY = this._itemGroupLocation.y;
  5913. var itemWidth = this.legendOption.itemWidth;
  5914. var itemHeight = this.legendOption.itemHeight;
  5915. var itemGap = this.legendOption.itemGap;
  5916. var color;
  5917. if (this.legendOption.orient === 'vertical' && this.legendOption.x === 'right') {
  5918. lastX = this._itemGroupLocation.x + this._itemGroupLocation.width - itemWidth;
  5919. }
  5920. for (var i = 0; i < dataLength; i++) {
  5921. dataTextStyle = zrUtil.merge(data[i].textStyle || {}, textStyle);
  5922. dataFont = this.getFont(dataTextStyle);
  5923. itemName = this._getName(data[i]);
  5924. formattedName = this._getFormatterName(itemName);
  5925. if (itemName === '') {
  5926. if (this.legendOption.orient === 'horizontal') {
  5927. lastX = this._itemGroupLocation.x;
  5928. lastY += itemHeight + itemGap;
  5929. } else {
  5930. this.legendOption.x === 'right' ? lastX -= this._itemGroupLocation.maxWidth + itemGap : lastX += this._itemGroupLocation.maxWidth + itemGap;
  5931. lastY = this._itemGroupLocation.y;
  5932. }
  5933. continue;
  5934. }
  5935. itemType = data[i].icon || this._getSomethingByName(itemName).type;
  5936. color = this.getColor(itemName);
  5937. if (this.legendOption.orient === 'horizontal') {
  5938. if (zrWidth - lastX < 200 && itemWidth + 5 + zrArea.getTextWidth(formattedName, dataFont) + (i === dataLength - 1 || data[i + 1] === '' ? 0 : itemGap) >= zrWidth - lastX) {
  5939. lastX = this._itemGroupLocation.x;
  5940. lastY += itemHeight + itemGap;
  5941. }
  5942. } else {
  5943. if (zrHeight - lastY < 200 && itemHeight + (i === dataLength - 1 || data[i + 1] === '' ? 0 : itemGap) >= zrHeight - lastY) {
  5944. this.legendOption.x === 'right' ? lastX -= this._itemGroupLocation.maxWidth + itemGap : lastX += this._itemGroupLocation.maxWidth + itemGap;
  5945. lastY = this._itemGroupLocation.y;
  5946. }
  5947. }
  5948. itemShape = this._getItemShapeByType(lastX, lastY, itemWidth, itemHeight, this._selectedMap[itemName] && this._hasDataMap[itemName] ? color : '#ccc', itemType, color);
  5949. itemShape._name = itemName;
  5950. itemShape = new IconShape(itemShape);
  5951. textShape = {
  5952. zlevel: this.getZlevelBase(),
  5953. z: this.getZBase(),
  5954. style: {
  5955. x: lastX + itemWidth + 5,
  5956. y: lastY + itemHeight / 2,
  5957. color: this._selectedMap[itemName] ? dataTextStyle.color === 'auto' ? color : dataTextStyle.color : '#ccc',
  5958. text: formattedName,
  5959. textFont: dataFont,
  5960. textBaseline: 'middle'
  5961. },
  5962. highlightStyle: {
  5963. color: color,
  5964. brushType: 'fill'
  5965. },
  5966. hoverable: !!this.legendOption.selectedMode,
  5967. clickable: !!this.legendOption.selectedMode
  5968. };
  5969. if (this.legendOption.orient === 'vertical' && this.legendOption.x === 'right') {
  5970. textShape.style.x -= itemWidth + 10;
  5971. textShape.style.textAlign = 'right';
  5972. }
  5973. textShape._name = itemName;
  5974. textShape = new TextShape(textShape);
  5975. if (this.legendOption.selectedMode) {
  5976. itemShape.onclick = textShape.onclick = this._legendSelected;
  5977. itemShape.onmouseover = textShape.onmouseover = this._dispatchHoverLink;
  5978. itemShape.hoverConnect = textShape.id;
  5979. textShape.hoverConnect = itemShape.id;
  5980. }
  5981. this.shapeList.push(itemShape);
  5982. this.shapeList.push(textShape);
  5983. if (this.legendOption.orient === 'horizontal') {
  5984. lastX += itemWidth + 5 + zrArea.getTextWidth(formattedName, dataFont) + itemGap;
  5985. } else {
  5986. lastY += itemHeight + itemGap;
  5987. }
  5988. }
  5989. if (this.legendOption.orient === 'horizontal' && this.legendOption.x === 'center' && lastY != this._itemGroupLocation.y) {
  5990. this._mLineOptimize();
  5991. }
  5992. },
  5993. _getName: function (data) {
  5994. return typeof data.name != 'undefined' ? data.name : data;
  5995. },
  5996. _getFormatterName: function (itemName) {
  5997. var formatter = this.legendOption.formatter;
  5998. var formattedName;
  5999. if (typeof formatter === 'function') {
  6000. formattedName = formatter.call(this.myChart, itemName);
  6001. } else if (typeof formatter === 'string') {
  6002. formattedName = formatter.replace('{name}', itemName);
  6003. } else {
  6004. formattedName = itemName;
  6005. }
  6006. return formattedName;
  6007. },
  6008. _getFormatterNameFromData: function (data) {
  6009. var itemName = this._getName(data);
  6010. return this._getFormatterName(itemName);
  6011. },
  6012. _mLineOptimize: function () {
  6013. var lineOffsetArray = [];
  6014. var lastX = this._itemGroupLocation.x;
  6015. for (var i = 2, l = this.shapeList.length; i < l; i++) {
  6016. if (this.shapeList[i].style.x === lastX) {
  6017. lineOffsetArray.push((this._itemGroupLocation.width - (this.shapeList[i - 1].style.x + zrArea.getTextWidth(this.shapeList[i - 1].style.text, this.shapeList[i - 1].style.textFont) - lastX)) / 2);
  6018. } else if (i === l - 1) {
  6019. lineOffsetArray.push((this._itemGroupLocation.width - (this.shapeList[i].style.x + zrArea.getTextWidth(this.shapeList[i].style.text, this.shapeList[i].style.textFont) - lastX)) / 2);
  6020. }
  6021. }
  6022. var curLineIndex = -1;
  6023. for (var i = 1, l = this.shapeList.length; i < l; i++) {
  6024. if (this.shapeList[i].style.x === lastX) {
  6025. curLineIndex++;
  6026. }
  6027. if (lineOffsetArray[curLineIndex] === 0) {
  6028. continue;
  6029. } else {
  6030. this.shapeList[i].style.x += lineOffsetArray[curLineIndex];
  6031. }
  6032. }
  6033. },
  6034. _buildBackground: function () {
  6035. var padding = this.reformCssArray(this.legendOption.padding);
  6036. this.shapeList.push(new RectangleShape({
  6037. zlevel: this.getZlevelBase(),
  6038. z: this.getZBase(),
  6039. hoverable: false,
  6040. style: {
  6041. x: this._itemGroupLocation.x - padding[3],
  6042. y: this._itemGroupLocation.y - padding[0],
  6043. width: this._itemGroupLocation.width + padding[3] + padding[1],
  6044. height: this._itemGroupLocation.height + padding[0] + padding[2],
  6045. brushType: this.legendOption.borderWidth === 0 ? 'fill' : 'both',
  6046. color: this.legendOption.backgroundColor,
  6047. strokeColor: this.legendOption.borderColor,
  6048. lineWidth: this.legendOption.borderWidth
  6049. }
  6050. }));
  6051. },
  6052. _getItemGroupLocation: function () {
  6053. var data = this.legendOption.data;
  6054. var dataLength = data.length;
  6055. var itemGap = this.legendOption.itemGap;
  6056. var itemWidth = this.legendOption.itemWidth + 5;
  6057. var itemHeight = this.legendOption.itemHeight;
  6058. var textStyle = this.legendOption.textStyle;
  6059. var font = this.getFont(textStyle);
  6060. var totalWidth = 0;
  6061. var totalHeight = 0;
  6062. var padding = this.reformCssArray(this.legendOption.padding);
  6063. var zrWidth = this.zr.getWidth() - padding[1] - padding[3];
  6064. var zrHeight = this.zr.getHeight() - padding[0] - padding[2];
  6065. var temp = 0;
  6066. var maxWidth = 0;
  6067. if (this.legendOption.orient === 'horizontal') {
  6068. totalHeight = itemHeight;
  6069. for (var i = 0; i < dataLength; i++) {
  6070. if (this._getName(data[i]) === '') {
  6071. temp -= itemGap;
  6072. totalWidth = Math.max(totalWidth, temp);
  6073. totalHeight += itemHeight + itemGap;
  6074. temp = 0;
  6075. continue;
  6076. }
  6077. var tempTextWidth = zrArea.getTextWidth(this._getFormatterNameFromData(data[i]), data[i].textStyle ? this.getFont(zrUtil.merge(data[i].textStyle || {}, textStyle)) : font);
  6078. if (temp + itemWidth + tempTextWidth + itemGap > zrWidth) {
  6079. temp -= itemGap;
  6080. totalWidth = Math.max(totalWidth, temp);
  6081. totalHeight += itemHeight + itemGap;
  6082. temp = 0;
  6083. } else {
  6084. temp += itemWidth + tempTextWidth + itemGap;
  6085. totalWidth = Math.max(totalWidth, temp - itemGap);
  6086. }
  6087. }
  6088. } else {
  6089. for (var i = 0; i < dataLength; i++) {
  6090. maxWidth = Math.max(maxWidth, zrArea.getTextWidth(this._getFormatterNameFromData(data[i]), data[i].textStyle ? this.getFont(zrUtil.merge(data[i].textStyle || {}, textStyle)) : font));
  6091. }
  6092. maxWidth += itemWidth;
  6093. totalWidth = maxWidth;
  6094. for (var i = 0; i < dataLength; i++) {
  6095. if (this._getName(data[i]) === '') {
  6096. totalWidth += maxWidth + itemGap;
  6097. temp -= itemGap;
  6098. totalHeight = Math.max(totalHeight, temp);
  6099. temp = 0;
  6100. continue;
  6101. }
  6102. if (temp + itemHeight + itemGap > zrHeight) {
  6103. totalWidth += maxWidth + itemGap;
  6104. temp -= itemGap;
  6105. totalHeight = Math.max(totalHeight, temp);
  6106. temp = 0;
  6107. } else {
  6108. temp += itemHeight + itemGap;
  6109. totalHeight = Math.max(totalHeight, temp - itemGap);
  6110. }
  6111. }
  6112. }
  6113. zrWidth = this.zr.getWidth();
  6114. zrHeight = this.zr.getHeight();
  6115. var x;
  6116. switch (this.legendOption.x) {
  6117. case 'center':
  6118. x = Math.floor((zrWidth - totalWidth) / 2);
  6119. break;
  6120. case 'left':
  6121. x = padding[3] + this.legendOption.borderWidth;
  6122. break;
  6123. case 'right':
  6124. x = zrWidth - totalWidth - padding[1] - padding[3] - this.legendOption.borderWidth * 2;
  6125. break;
  6126. default:
  6127. x = this.parsePercent(this.legendOption.x, zrWidth);
  6128. break;
  6129. }
  6130. var y;
  6131. switch (this.legendOption.y) {
  6132. case 'top':
  6133. y = padding[0] + this.legendOption.borderWidth;
  6134. break;
  6135. case 'bottom':
  6136. y = zrHeight - totalHeight - padding[0] - padding[2] - this.legendOption.borderWidth * 2;
  6137. break;
  6138. case 'center':
  6139. y = Math.floor((zrHeight - totalHeight) / 2);
  6140. break;
  6141. default:
  6142. y = this.parsePercent(this.legendOption.y, zrHeight);
  6143. break;
  6144. }
  6145. return {
  6146. x: x,
  6147. y: y,
  6148. width: totalWidth,
  6149. height: totalHeight,
  6150. maxWidth: maxWidth
  6151. };
  6152. },
  6153. _getSomethingByName: function (name) {
  6154. var series = this.option.series;
  6155. var data;
  6156. for (var i = 0, l = series.length; i < l; i++) {
  6157. if (series[i].name === name) {
  6158. return {
  6159. type: series[i].type,
  6160. series: series[i],
  6161. seriesIndex: i,
  6162. data: null,
  6163. dataIndex: -1
  6164. };
  6165. }
  6166. if (series[i].type === ecConfig.CHART_TYPE_PIE || series[i].type === ecConfig.CHART_TYPE_RADAR || series[i].type === ecConfig.CHART_TYPE_CHORD || series[i].type === ecConfig.CHART_TYPE_FORCE || series[i].type === ecConfig.CHART_TYPE_FUNNEL || series[i].type === ecConfig.CHART_TYPE_TREEMAP) {
  6167. data = series[i].categories || series[i].data || series[i].nodes;
  6168. for (var j = 0, k = data.length; j < k; j++) {
  6169. if (data[j].name === name) {
  6170. return {
  6171. type: series[i].type,
  6172. series: series[i],
  6173. seriesIndex: i,
  6174. data: data[j],
  6175. dataIndex: j
  6176. };
  6177. }
  6178. }
  6179. }
  6180. }
  6181. return {
  6182. type: 'bar',
  6183. series: null,
  6184. seriesIndex: -1,
  6185. data: null,
  6186. dataIndex: -1
  6187. };
  6188. },
  6189. _getItemShapeByType: function (x, y, width, height, color, itemType, defaultColor) {
  6190. var highlightColor = color === '#ccc' ? defaultColor : color;
  6191. var itemShape = {
  6192. zlevel: this.getZlevelBase(),
  6193. z: this.getZBase(),
  6194. style: {
  6195. iconType: 'legendicon' + itemType,
  6196. x: x,
  6197. y: y,
  6198. width: width,
  6199. height: height,
  6200. color: color,
  6201. strokeColor: color,
  6202. lineWidth: 2
  6203. },
  6204. highlightStyle: {
  6205. color: highlightColor,
  6206. strokeColor: highlightColor,
  6207. lineWidth: 1
  6208. },
  6209. hoverable: this.legendOption.selectedMode,
  6210. clickable: this.legendOption.selectedMode
  6211. };
  6212. var imageLocation;
  6213. if (itemType.match('image')) {
  6214. var imageLocation = itemType.replace(new RegExp('^image:\\/\\/'), '');
  6215. itemType = 'image';
  6216. }
  6217. switch (itemType) {
  6218. case 'line':
  6219. itemShape.style.brushType = 'stroke';
  6220. itemShape.highlightStyle.lineWidth = 3;
  6221. break;
  6222. case 'radar':
  6223. case 'venn':
  6224. case 'tree':
  6225. case 'treemap':
  6226. case 'scatter':
  6227. itemShape.highlightStyle.lineWidth = 3;
  6228. break;
  6229. case 'k':
  6230. itemShape.style.brushType = 'both';
  6231. itemShape.highlightStyle.lineWidth = 3;
  6232. itemShape.highlightStyle.color = itemShape.style.color = this.deepQuery([
  6233. this.ecTheme,
  6234. ecConfig
  6235. ], 'k.itemStyle.normal.color') || '#fff';
  6236. itemShape.style.strokeColor = color != '#ccc' ? this.deepQuery([
  6237. this.ecTheme,
  6238. ecConfig
  6239. ], 'k.itemStyle.normal.lineStyle.color') || '#ff3200' : color;
  6240. break;
  6241. case 'image':
  6242. itemShape.style.iconType = 'image';
  6243. itemShape.style.image = imageLocation;
  6244. if (color === '#ccc') {
  6245. itemShape.style.opacity = 0.5;
  6246. }
  6247. break;
  6248. }
  6249. return itemShape;
  6250. },
  6251. __legendSelected: function (param) {
  6252. var itemName = param.target._name;
  6253. if (this.legendOption.selectedMode === 'single') {
  6254. for (var k in this._selectedMap) {
  6255. this._selectedMap[k] = false;
  6256. }
  6257. }
  6258. this._selectedMap[itemName] = !this._selectedMap[itemName];
  6259. this.messageCenter.dispatch(ecConfig.EVENT.LEGEND_SELECTED, param.event, {
  6260. selected: this._selectedMap,
  6261. target: itemName
  6262. }, this.myChart);
  6263. },
  6264. __dispatchHoverLink: function (param) {
  6265. this.messageCenter.dispatch(ecConfig.EVENT.LEGEND_HOVERLINK, param.event, { target: param.target._name }, this.myChart);
  6266. return;
  6267. },
  6268. refresh: function (newOption) {
  6269. if (newOption) {
  6270. this.option = newOption || this.option;
  6271. this.option.legend = this.reformOption(this.option.legend);
  6272. this.legendOption = this.option.legend;
  6273. var data = this.legendOption.data || [];
  6274. var itemName;
  6275. var something;
  6276. var color;
  6277. var queryTarget;
  6278. if (this.legendOption.selected) {
  6279. for (var k in this.legendOption.selected) {
  6280. this._selectedMap[k] = typeof this._selectedMap[k] != 'undefined' ? this._selectedMap[k] : this.legendOption.selected[k];
  6281. }
  6282. }
  6283. for (var i = 0, dataLength = data.length; i < dataLength; i++) {
  6284. itemName = this._getName(data[i]);
  6285. if (itemName === '') {
  6286. continue;
  6287. }
  6288. something = this._getSomethingByName(itemName);
  6289. if (!something.series) {
  6290. this._hasDataMap[itemName] = false;
  6291. } else {
  6292. this._hasDataMap[itemName] = true;
  6293. if (something.data && (something.type === ecConfig.CHART_TYPE_PIE || something.type === ecConfig.CHART_TYPE_FORCE || something.type === ecConfig.CHART_TYPE_FUNNEL)) {
  6294. queryTarget = [
  6295. something.data,
  6296. something.series
  6297. ];
  6298. } else {
  6299. queryTarget = [something.series];
  6300. }
  6301. color = this.getItemStyleColor(this.deepQuery(queryTarget, 'itemStyle.normal.color'), something.seriesIndex, something.dataIndex, something.data);
  6302. if (color && something.type != ecConfig.CHART_TYPE_K) {
  6303. this.setColor(itemName, color);
  6304. }
  6305. this._selectedMap[itemName] = this._selectedMap[itemName] != null ? this._selectedMap[itemName] : true;
  6306. }
  6307. }
  6308. }
  6309. this.clear();
  6310. this._buildShape();
  6311. },
  6312. getRelatedAmount: function (name) {
  6313. var amount = 0;
  6314. var series = this.option.series;
  6315. var data;
  6316. for (var i = 0, l = series.length; i < l; i++) {
  6317. if (series[i].name === name) {
  6318. amount++;
  6319. }
  6320. if (series[i].type === ecConfig.CHART_TYPE_PIE || series[i].type === ecConfig.CHART_TYPE_RADAR || series[i].type === ecConfig.CHART_TYPE_CHORD || series[i].type === ecConfig.CHART_TYPE_FORCE || series[i].type === ecConfig.CHART_TYPE_FUNNEL) {
  6321. data = series[i].type != ecConfig.CHART_TYPE_FORCE ? series[i].data : series[i].categories;
  6322. for (var j = 0, k = data.length; j < k; j++) {
  6323. if (data[j].name === name && data[j].value != '-') {
  6324. amount++;
  6325. }
  6326. }
  6327. }
  6328. }
  6329. return amount;
  6330. },
  6331. setColor: function (legendName, color) {
  6332. this._colorMap[legendName] = color;
  6333. },
  6334. getColor: function (legendName) {
  6335. if (!this._colorMap[legendName]) {
  6336. this._colorMap[legendName] = this.zr.getColor(this._colorIndex++);
  6337. }
  6338. return this._colorMap[legendName];
  6339. },
  6340. hasColor: function (legendName) {
  6341. return this._colorMap[legendName] ? this._colorMap[legendName] : false;
  6342. },
  6343. add: function (name, color) {
  6344. var data = this.legendOption.data;
  6345. for (var i = 0, dataLength = data.length; i < dataLength; i++) {
  6346. if (this._getName(data[i]) === name) {
  6347. return;
  6348. }
  6349. }
  6350. this.legendOption.data.push(name);
  6351. this.setColor(name, color);
  6352. this._selectedMap[name] = true;
  6353. this._hasDataMap[name] = true;
  6354. },
  6355. del: function (name) {
  6356. var data = this.legendOption.data;
  6357. for (var i = 0, dataLength = data.length; i < dataLength; i++) {
  6358. if (this._getName(data[i]) === name) {
  6359. return this.legendOption.data.splice(i, 1);
  6360. }
  6361. }
  6362. },
  6363. getItemShape: function (name) {
  6364. if (name == null) {
  6365. return;
  6366. }
  6367. var shape;
  6368. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  6369. shape = this.shapeList[i];
  6370. if (shape._name === name && shape.type != 'text') {
  6371. return shape;
  6372. }
  6373. }
  6374. },
  6375. setItemShape: function (name, itemShape) {
  6376. var shape;
  6377. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  6378. shape = this.shapeList[i];
  6379. if (shape._name === name && shape.type != 'text') {
  6380. if (!this._selectedMap[name]) {
  6381. itemShape.style.color = '#ccc';
  6382. itemShape.style.strokeColor = '#ccc';
  6383. }
  6384. this.zr.modShape(shape.id, itemShape);
  6385. }
  6386. }
  6387. },
  6388. isSelected: function (itemName) {
  6389. if (typeof this._selectedMap[itemName] != 'undefined') {
  6390. return this._selectedMap[itemName];
  6391. } else {
  6392. return true;
  6393. }
  6394. },
  6395. getSelectedMap: function () {
  6396. return this._selectedMap;
  6397. },
  6398. setSelected: function (itemName, selectStatus) {
  6399. if (this.legendOption.selectedMode === 'single') {
  6400. for (var k in this._selectedMap) {
  6401. this._selectedMap[k] = false;
  6402. }
  6403. }
  6404. this._selectedMap[itemName] = selectStatus;
  6405. this.messageCenter.dispatch(ecConfig.EVENT.LEGEND_SELECTED, null, {
  6406. selected: this._selectedMap,
  6407. target: itemName
  6408. }, this.myChart);
  6409. },
  6410. onlegendSelected: function (param, status) {
  6411. var legendSelected = param.selected;
  6412. for (var itemName in legendSelected) {
  6413. if (this._selectedMap[itemName] != legendSelected[itemName]) {
  6414. status.needRefresh = true;
  6415. }
  6416. this._selectedMap[itemName] = legendSelected[itemName];
  6417. }
  6418. return;
  6419. }
  6420. };
  6421. var legendIcon = {
  6422. line: function (ctx, style) {
  6423. var dy = style.height / 2;
  6424. ctx.moveTo(style.x, style.y + dy);
  6425. ctx.lineTo(style.x + style.width, style.y + dy);
  6426. },
  6427. pie: function (ctx, style) {
  6428. var x = style.x;
  6429. var y = style.y;
  6430. var width = style.width;
  6431. var height = style.height;
  6432. SectorShape.prototype.buildPath(ctx, {
  6433. x: x + width / 2,
  6434. y: y + height + 2,
  6435. r: height,
  6436. r0: 6,
  6437. startAngle: 45,
  6438. endAngle: 135
  6439. });
  6440. },
  6441. eventRiver: function (ctx, style) {
  6442. var x = style.x;
  6443. var y = style.y;
  6444. var width = style.width;
  6445. var height = style.height;
  6446. ctx.moveTo(x, y + height);
  6447. ctx.bezierCurveTo(x + width, y + height, x, y + 4, x + width, y + 4);
  6448. ctx.lineTo(x + width, y);
  6449. ctx.bezierCurveTo(x, y, x + width, y + height - 4, x, y + height - 4);
  6450. ctx.lineTo(x, y + height);
  6451. },
  6452. k: function (ctx, style) {
  6453. var x = style.x;
  6454. var y = style.y;
  6455. var width = style.width;
  6456. var height = style.height;
  6457. CandleShape.prototype.buildPath(ctx, {
  6458. x: x + width / 2,
  6459. y: [
  6460. y + 1,
  6461. y + 1,
  6462. y + height - 6,
  6463. y + height
  6464. ],
  6465. width: width - 6
  6466. });
  6467. },
  6468. bar: function (ctx, style) {
  6469. var x = style.x;
  6470. var y = style.y + 1;
  6471. var width = style.width;
  6472. var height = style.height - 2;
  6473. var r = 3;
  6474. ctx.moveTo(x + r, y);
  6475. ctx.lineTo(x + width - r, y);
  6476. ctx.quadraticCurveTo(x + width, y, x + width, y + r);
  6477. ctx.lineTo(x + width, y + height - r);
  6478. ctx.quadraticCurveTo(x + width, y + height, x + width - r, y + height);
  6479. ctx.lineTo(x + r, y + height);
  6480. ctx.quadraticCurveTo(x, y + height, x, y + height - r);
  6481. ctx.lineTo(x, y + r);
  6482. ctx.quadraticCurveTo(x, y, x + r, y);
  6483. },
  6484. force: function (ctx, style) {
  6485. IconShape.prototype.iconLibrary.circle(ctx, style);
  6486. },
  6487. radar: function (ctx, style) {
  6488. var n = 6;
  6489. var x = style.x + style.width / 2;
  6490. var y = style.y + style.height / 2;
  6491. var r = style.height / 2;
  6492. var dStep = 2 * Math.PI / n;
  6493. var deg = -Math.PI / 2;
  6494. var xStart = x + r * Math.cos(deg);
  6495. var yStart = y + r * Math.sin(deg);
  6496. ctx.moveTo(xStart, yStart);
  6497. deg += dStep;
  6498. for (var i = 0, end = n - 1; i < end; i++) {
  6499. ctx.lineTo(x + r * Math.cos(deg), y + r * Math.sin(deg));
  6500. deg += dStep;
  6501. }
  6502. ctx.lineTo(xStart, yStart);
  6503. }
  6504. };
  6505. legendIcon.chord = legendIcon.pie;
  6506. legendIcon.map = legendIcon.bar;
  6507. for (var k in legendIcon) {
  6508. IconShape.prototype.iconLibrary['legendicon' + k] = legendIcon[k];
  6509. }
  6510. zrUtil.inherits(Legend, Base);
  6511. require('../component').define('legend', Legend);
  6512. return Legend;
  6513. });define('echarts/util/ecData', [], function () {
  6514. function pack(shape, series, seriesIndex, data, dataIndex, name, special, special2) {
  6515. var value;
  6516. if (typeof data != 'undefined') {
  6517. value = data.value == null ? data : data.value;
  6518. }
  6519. shape._echartsData = {
  6520. '_series': series,
  6521. '_seriesIndex': seriesIndex,
  6522. '_data': data,
  6523. '_dataIndex': dataIndex,
  6524. '_name': name,
  6525. '_value': value,
  6526. '_special': special,
  6527. '_special2': special2
  6528. };
  6529. return shape._echartsData;
  6530. }
  6531. function get(shape, key) {
  6532. var data = shape._echartsData;
  6533. if (!key) {
  6534. return data;
  6535. }
  6536. switch (key) {
  6537. case 'series':
  6538. case 'seriesIndex':
  6539. case 'data':
  6540. case 'dataIndex':
  6541. case 'name':
  6542. case 'value':
  6543. case 'special':
  6544. case 'special2':
  6545. return data && data['_' + key];
  6546. }
  6547. return null;
  6548. }
  6549. function set(shape, key, value) {
  6550. shape._echartsData = shape._echartsData || {};
  6551. switch (key) {
  6552. case 'series':
  6553. case 'seriesIndex':
  6554. case 'data':
  6555. case 'dataIndex':
  6556. case 'name':
  6557. case 'value':
  6558. case 'special':
  6559. case 'special2':
  6560. shape._echartsData['_' + key] = value;
  6561. break;
  6562. }
  6563. }
  6564. function clone(source, target) {
  6565. target._echartsData = {
  6566. '_series': source._echartsData._series,
  6567. '_seriesIndex': source._echartsData._seriesIndex,
  6568. '_data': source._echartsData._data,
  6569. '_dataIndex': source._echartsData._dataIndex,
  6570. '_name': source._echartsData._name,
  6571. '_value': source._echartsData._value,
  6572. '_special': source._echartsData._special,
  6573. '_special2': source._echartsData._special2
  6574. };
  6575. }
  6576. return {
  6577. pack: pack,
  6578. set: set,
  6579. get: get,
  6580. clone: clone
  6581. };
  6582. });define('echarts/chart', [], function () {
  6583. var self = {};
  6584. var _chartLibrary = {};
  6585. self.define = function (name, clazz) {
  6586. _chartLibrary[name] = clazz;
  6587. return self;
  6588. };
  6589. self.get = function (name) {
  6590. return _chartLibrary[name];
  6591. };
  6592. return self;
  6593. });define('zrender/tool/color', [
  6594. 'require',
  6595. '../tool/util'
  6596. ], function (require) {
  6597. var util = require('../tool/util');
  6598. var _ctx;
  6599. var palette = [
  6600. '#ff9277',
  6601. ' #dddd00',
  6602. ' #ffc877',
  6603. ' #bbe3ff',
  6604. ' #d5ffbb',
  6605. '#bbbbff',
  6606. ' #ddb000',
  6607. ' #b0dd00',
  6608. ' #e2bbff',
  6609. ' #ffbbe3',
  6610. '#ff7777',
  6611. ' #ff9900',
  6612. ' #83dd00',
  6613. ' #77e3ff',
  6614. ' #778fff',
  6615. '#c877ff',
  6616. ' #ff77ab',
  6617. ' #ff6600',
  6618. ' #aa8800',
  6619. ' #77c7ff',
  6620. '#ad77ff',
  6621. ' #ff77ff',
  6622. ' #dd0083',
  6623. ' #777700',
  6624. ' #00aa00',
  6625. '#0088aa',
  6626. ' #8400dd',
  6627. ' #aa0088',
  6628. ' #dd0000',
  6629. ' #772e00'
  6630. ];
  6631. var _palette = palette;
  6632. var highlightColor = 'rgba(255,255,0,0.5)';
  6633. var _highlightColor = highlightColor;
  6634. var colorRegExp = /^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgba?\(\s*([\d\.]+%?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+%?(?:\s*,\s*[\d\.]+%?)?)\s*\)|hsba?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+%?(?:\s*,\s*[\d\.]+)?)%?\s*\)|hsla?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+%?(?:\s*,\s*[\d\.]+)?)%?\s*\))\s*$/i;
  6635. var _nameColors = {
  6636. aliceblue: '#f0f8ff',
  6637. antiquewhite: '#faebd7',
  6638. aqua: '#0ff',
  6639. aquamarine: '#7fffd4',
  6640. azure: '#f0ffff',
  6641. beige: '#f5f5dc',
  6642. bisque: '#ffe4c4',
  6643. black: '#000',
  6644. blanchedalmond: '#ffebcd',
  6645. blue: '#00f',
  6646. blueviolet: '#8a2be2',
  6647. brown: '#a52a2a',
  6648. burlywood: '#deb887',
  6649. cadetblue: '#5f9ea0',
  6650. chartreuse: '#7fff00',
  6651. chocolate: '#d2691e',
  6652. coral: '#ff7f50',
  6653. cornflowerblue: '#6495ed',
  6654. cornsilk: '#fff8dc',
  6655. crimson: '#dc143c',
  6656. cyan: '#0ff',
  6657. darkblue: '#00008b',
  6658. darkcyan: '#008b8b',
  6659. darkgoldenrod: '#b8860b',
  6660. darkgray: '#a9a9a9',
  6661. darkgrey: '#a9a9a9',
  6662. darkgreen: '#006400',
  6663. darkkhaki: '#bdb76b',
  6664. darkmagenta: '#8b008b',
  6665. darkolivegreen: '#556b2f',
  6666. darkorange: '#ff8c00',
  6667. darkorchid: '#9932cc',
  6668. darkred: '#8b0000',
  6669. darksalmon: '#e9967a',
  6670. darkseagreen: '#8fbc8f',
  6671. darkslateblue: '#483d8b',
  6672. darkslategray: '#2f4f4f',
  6673. darkslategrey: '#2f4f4f',
  6674. darkturquoise: '#00ced1',
  6675. darkviolet: '#9400d3',
  6676. deeppink: '#ff1493',
  6677. deepskyblue: '#00bfff',
  6678. dimgray: '#696969',
  6679. dimgrey: '#696969',
  6680. dodgerblue: '#1e90ff',
  6681. firebrick: '#b22222',
  6682. floralwhite: '#fffaf0',
  6683. forestgreen: '#228b22',
  6684. fuchsia: '#f0f',
  6685. gainsboro: '#dcdcdc',
  6686. ghostwhite: '#f8f8ff',
  6687. gold: '#ffd700',
  6688. goldenrod: '#daa520',
  6689. gray: '#808080',
  6690. grey: '#808080',
  6691. green: '#008000',
  6692. greenyellow: '#adff2f',
  6693. honeydew: '#f0fff0',
  6694. hotpink: '#ff69b4',
  6695. indianred: '#cd5c5c',
  6696. indigo: '#4b0082',
  6697. ivory: '#fffff0',
  6698. khaki: '#f0e68c',
  6699. lavender: '#e6e6fa',
  6700. lavenderblush: '#fff0f5',
  6701. lawngreen: '#7cfc00',
  6702. lemonchiffon: '#fffacd',
  6703. lightblue: '#add8e6',
  6704. lightcoral: '#f08080',
  6705. lightcyan: '#e0ffff',
  6706. lightgoldenrodyellow: '#fafad2',
  6707. lightgray: '#d3d3d3',
  6708. lightgrey: '#d3d3d3',
  6709. lightgreen: '#90ee90',
  6710. lightpink: '#ffb6c1',
  6711. lightsalmon: '#ffa07a',
  6712. lightseagreen: '#20b2aa',
  6713. lightskyblue: '#87cefa',
  6714. lightslategray: '#789',
  6715. lightslategrey: '#789',
  6716. lightsteelblue: '#b0c4de',
  6717. lightyellow: '#ffffe0',
  6718. lime: '#0f0',
  6719. limegreen: '#32cd32',
  6720. linen: '#faf0e6',
  6721. magenta: '#f0f',
  6722. maroon: '#800000',
  6723. mediumaquamarine: '#66cdaa',
  6724. mediumblue: '#0000cd',
  6725. mediumorchid: '#ba55d3',
  6726. mediumpurple: '#9370d8',
  6727. mediumseagreen: '#3cb371',
  6728. mediumslateblue: '#7b68ee',
  6729. mediumspringgreen: '#00fa9a',
  6730. mediumturquoise: '#48d1cc',
  6731. mediumvioletred: '#c71585',
  6732. midnightblue: '#191970',
  6733. mintcream: '#f5fffa',
  6734. mistyrose: '#ffe4e1',
  6735. moccasin: '#ffe4b5',
  6736. navajowhite: '#ffdead',
  6737. navy: '#000080',
  6738. oldlace: '#fdf5e6',
  6739. olive: '#808000',
  6740. olivedrab: '#6b8e23',
  6741. orange: '#ffa500',
  6742. orangered: '#ff4500',
  6743. orchid: '#da70d6',
  6744. palegoldenrod: '#eee8aa',
  6745. palegreen: '#98fb98',
  6746. paleturquoise: '#afeeee',
  6747. palevioletred: '#d87093',
  6748. papayawhip: '#ffefd5',
  6749. peachpuff: '#ffdab9',
  6750. peru: '#cd853f',
  6751. pink: '#ffc0cb',
  6752. plum: '#dda0dd',
  6753. powderblue: '#b0e0e6',
  6754. purple: '#800080',
  6755. red: '#f00',
  6756. rosybrown: '#bc8f8f',
  6757. royalblue: '#4169e1',
  6758. saddlebrown: '#8b4513',
  6759. salmon: '#fa8072',
  6760. sandybrown: '#f4a460',
  6761. seagreen: '#2e8b57',
  6762. seashell: '#fff5ee',
  6763. sienna: '#a0522d',
  6764. silver: '#c0c0c0',
  6765. skyblue: '#87ceeb',
  6766. slateblue: '#6a5acd',
  6767. slategray: '#708090',
  6768. slategrey: '#708090',
  6769. snow: '#fffafa',
  6770. springgreen: '#00ff7f',
  6771. steelblue: '#4682b4',
  6772. tan: '#d2b48c',
  6773. teal: '#008080',
  6774. thistle: '#d8bfd8',
  6775. tomato: '#ff6347',
  6776. turquoise: '#40e0d0',
  6777. violet: '#ee82ee',
  6778. wheat: '#f5deb3',
  6779. white: '#fff',
  6780. whitesmoke: '#f5f5f5',
  6781. yellow: '#ff0',
  6782. yellowgreen: '#9acd32'
  6783. };
  6784. function customPalette(userPalete) {
  6785. palette = userPalete;
  6786. }
  6787. function resetPalette() {
  6788. palette = _palette;
  6789. }
  6790. function getColor(idx, userPalete) {
  6791. idx = idx | 0;
  6792. userPalete = userPalete || palette;
  6793. return userPalete[idx % userPalete.length];
  6794. }
  6795. function customHighlight(userHighlightColor) {
  6796. highlightColor = userHighlightColor;
  6797. }
  6798. function resetHighlight() {
  6799. _highlightColor = highlightColor;
  6800. }
  6801. function getHighlightColor() {
  6802. return highlightColor;
  6803. }
  6804. function getRadialGradient(x0, y0, r0, x1, y1, r1, colorList) {
  6805. if (!_ctx) {
  6806. _ctx = util.getContext();
  6807. }
  6808. var gradient = _ctx.createRadialGradient(x0, y0, r0, x1, y1, r1);
  6809. for (var i = 0, l = colorList.length; i < l; i++) {
  6810. gradient.addColorStop(colorList[i][0], colorList[i][1]);
  6811. }
  6812. gradient.__nonRecursion = true;
  6813. return gradient;
  6814. }
  6815. function getLinearGradient(x0, y0, x1, y1, colorList) {
  6816. if (!_ctx) {
  6817. _ctx = util.getContext();
  6818. }
  6819. var gradient = _ctx.createLinearGradient(x0, y0, x1, y1);
  6820. for (var i = 0, l = colorList.length; i < l; i++) {
  6821. gradient.addColorStop(colorList[i][0], colorList[i][1]);
  6822. }
  6823. gradient.__nonRecursion = true;
  6824. return gradient;
  6825. }
  6826. function getStepColors(start, end, step) {
  6827. start = toRGBA(start);
  6828. end = toRGBA(end);
  6829. start = getData(start);
  6830. end = getData(end);
  6831. var colors = [];
  6832. var stepR = (end[0] - start[0]) / step;
  6833. var stepG = (end[1] - start[1]) / step;
  6834. var stepB = (end[2] - start[2]) / step;
  6835. var stepA = (end[3] - start[3]) / step;
  6836. for (var i = 0, r = start[0], g = start[1], b = start[2], a = start[3]; i < step; i++) {
  6837. colors[i] = toColor([
  6838. adjust(Math.floor(r), [
  6839. 0,
  6840. 255
  6841. ]),
  6842. adjust(Math.floor(g), [
  6843. 0,
  6844. 255
  6845. ]),
  6846. adjust(Math.floor(b), [
  6847. 0,
  6848. 255
  6849. ]),
  6850. a.toFixed(4) - 0
  6851. ], 'rgba');
  6852. r += stepR;
  6853. g += stepG;
  6854. b += stepB;
  6855. a += stepA;
  6856. }
  6857. r = end[0];
  6858. g = end[1];
  6859. b = end[2];
  6860. a = end[3];
  6861. colors[i] = toColor([
  6862. r,
  6863. g,
  6864. b,
  6865. a
  6866. ], 'rgba');
  6867. return colors;
  6868. }
  6869. function getGradientColors(colors, step) {
  6870. var ret = [];
  6871. var len = colors.length;
  6872. if (step === undefined) {
  6873. step = 20;
  6874. }
  6875. if (len === 1) {
  6876. ret = getStepColors(colors[0], colors[0], step);
  6877. } else if (len > 1) {
  6878. for (var i = 0, n = len - 1; i < n; i++) {
  6879. var steps = getStepColors(colors[i], colors[i + 1], step);
  6880. if (i < n - 1) {
  6881. steps.pop();
  6882. }
  6883. ret = ret.concat(steps);
  6884. }
  6885. }
  6886. return ret;
  6887. }
  6888. function toColor(data, format) {
  6889. format = format || 'rgb';
  6890. if (data && (data.length === 3 || data.length === 4)) {
  6891. data = map(data, function (c) {
  6892. return c > 1 ? Math.ceil(c) : c;
  6893. });
  6894. if (format.indexOf('hex') > -1) {
  6895. return '#' + ((1 << 24) + (data[0] << 16) + (data[1] << 8) + +data[2]).toString(16).slice(1);
  6896. } else if (format.indexOf('hs') > -1) {
  6897. var sx = map(data.slice(1, 3), function (c) {
  6898. return c + '%';
  6899. });
  6900. data[1] = sx[0];
  6901. data[2] = sx[1];
  6902. }
  6903. if (format.indexOf('a') > -1) {
  6904. if (data.length === 3) {
  6905. data.push(1);
  6906. }
  6907. data[3] = adjust(data[3], [
  6908. 0,
  6909. 1
  6910. ]);
  6911. return format + '(' + data.slice(0, 4).join(',') + ')';
  6912. }
  6913. return format + '(' + data.slice(0, 3).join(',') + ')';
  6914. }
  6915. }
  6916. function toArray(color) {
  6917. color = trim(color);
  6918. if (color.indexOf('rgba') < 0) {
  6919. color = toRGBA(color);
  6920. }
  6921. var data = [];
  6922. var i = 0;
  6923. color.replace(/[\d.]+/g, function (n) {
  6924. if (i < 3) {
  6925. n = n | 0;
  6926. } else {
  6927. n = +n;
  6928. }
  6929. data[i++] = n;
  6930. });
  6931. return data;
  6932. }
  6933. function convert(color, format) {
  6934. if (!isCalculableColor(color)) {
  6935. return color;
  6936. }
  6937. var data = getData(color);
  6938. var alpha = data[3];
  6939. if (typeof alpha === 'undefined') {
  6940. alpha = 1;
  6941. }
  6942. if (color.indexOf('hsb') > -1) {
  6943. data = _HSV_2_RGB(data);
  6944. } else if (color.indexOf('hsl') > -1) {
  6945. data = _HSL_2_RGB(data);
  6946. }
  6947. if (format.indexOf('hsb') > -1 || format.indexOf('hsv') > -1) {
  6948. data = _RGB_2_HSB(data);
  6949. } else if (format.indexOf('hsl') > -1) {
  6950. data = _RGB_2_HSL(data);
  6951. }
  6952. data[3] = alpha;
  6953. return toColor(data, format);
  6954. }
  6955. function toRGBA(color) {
  6956. return convert(color, 'rgba');
  6957. }
  6958. function toRGB(color) {
  6959. return convert(color, 'rgb');
  6960. }
  6961. function toHex(color) {
  6962. return convert(color, 'hex');
  6963. }
  6964. function toHSVA(color) {
  6965. return convert(color, 'hsva');
  6966. }
  6967. function toHSV(color) {
  6968. return convert(color, 'hsv');
  6969. }
  6970. function toHSBA(color) {
  6971. return convert(color, 'hsba');
  6972. }
  6973. function toHSB(color) {
  6974. return convert(color, 'hsb');
  6975. }
  6976. function toHSLA(color) {
  6977. return convert(color, 'hsla');
  6978. }
  6979. function toHSL(color) {
  6980. return convert(color, 'hsl');
  6981. }
  6982. function toName(color) {
  6983. for (var key in _nameColors) {
  6984. if (toHex(_nameColors[key]) === toHex(color)) {
  6985. return key;
  6986. }
  6987. }
  6988. return null;
  6989. }
  6990. function trim(color) {
  6991. return String(color).replace(/\s+/g, '');
  6992. }
  6993. function normalize(color) {
  6994. if (_nameColors[color]) {
  6995. color = _nameColors[color];
  6996. }
  6997. color = trim(color);
  6998. color = color.replace(/hsv/i, 'hsb');
  6999. if (/^#[\da-f]{3}$/i.test(color)) {
  7000. color = parseInt(color.slice(1), 16);
  7001. var r = (color & 3840) << 8;
  7002. var g = (color & 240) << 4;
  7003. var b = color & 15;
  7004. color = '#' + ((1 << 24) + (r << 4) + r + (g << 4) + g + (b << 4) + b).toString(16).slice(1);
  7005. }
  7006. return color;
  7007. }
  7008. function lift(color, level) {
  7009. if (!isCalculableColor(color)) {
  7010. return color;
  7011. }
  7012. var direct = level > 0 ? 1 : -1;
  7013. if (typeof level === 'undefined') {
  7014. level = 0;
  7015. }
  7016. level = Math.abs(level) > 1 ? 1 : Math.abs(level);
  7017. color = toRGB(color);
  7018. var data = getData(color);
  7019. for (var i = 0; i < 3; i++) {
  7020. if (direct === 1) {
  7021. data[i] = data[i] * (1 - level) | 0;
  7022. } else {
  7023. data[i] = (255 - data[i]) * level + data[i] | 0;
  7024. }
  7025. }
  7026. return 'rgb(' + data.join(',') + ')';
  7027. }
  7028. function reverse(color) {
  7029. if (!isCalculableColor(color)) {
  7030. return color;
  7031. }
  7032. var data = getData(toRGBA(color));
  7033. data = map(data, function (c) {
  7034. return 255 - c;
  7035. });
  7036. return toColor(data, 'rgb');
  7037. }
  7038. function mix(color1, color2, weight) {
  7039. if (!isCalculableColor(color1) || !isCalculableColor(color2)) {
  7040. return color1;
  7041. }
  7042. if (typeof weight === 'undefined') {
  7043. weight = 0.5;
  7044. }
  7045. weight = 1 - adjust(weight, [
  7046. 0,
  7047. 1
  7048. ]);
  7049. var w = weight * 2 - 1;
  7050. var data1 = getData(toRGBA(color1));
  7051. var data2 = getData(toRGBA(color2));
  7052. var d = data1[3] - data2[3];
  7053. var weight1 = ((w * d === -1 ? w : (w + d) / (1 + w * d)) + 1) / 2;
  7054. var weight2 = 1 - weight1;
  7055. var data = [];
  7056. for (var i = 0; i < 3; i++) {
  7057. data[i] = data1[i] * weight1 + data2[i] * weight2;
  7058. }
  7059. var alpha = data1[3] * weight + data2[3] * (1 - weight);
  7060. alpha = Math.max(0, Math.min(1, alpha));
  7061. if (data1[3] === 1 && data2[3] === 1) {
  7062. return toColor(data, 'rgb');
  7063. }
  7064. data[3] = alpha;
  7065. return toColor(data, 'rgba');
  7066. }
  7067. function random() {
  7068. return '#' + (Math.random().toString(16) + '0000').slice(2, 8);
  7069. }
  7070. function getData(color) {
  7071. color = normalize(color);
  7072. var r = color.match(colorRegExp);
  7073. if (r === null) {
  7074. throw new Error('The color format error');
  7075. }
  7076. var d;
  7077. var a;
  7078. var data = [];
  7079. var rgb;
  7080. if (r[2]) {
  7081. d = r[2].replace('#', '').split('');
  7082. rgb = [
  7083. d[0] + d[1],
  7084. d[2] + d[3],
  7085. d[4] + d[5]
  7086. ];
  7087. data = map(rgb, function (c) {
  7088. return adjust(parseInt(c, 16), [
  7089. 0,
  7090. 255
  7091. ]);
  7092. });
  7093. } else if (r[4]) {
  7094. var rgba = r[4].split(',');
  7095. a = rgba[3];
  7096. rgb = rgba.slice(0, 3);
  7097. data = map(rgb, function (c) {
  7098. c = Math.floor(c.indexOf('%') > 0 ? parseInt(c, 0) * 2.55 : c);
  7099. return adjust(c, [
  7100. 0,
  7101. 255
  7102. ]);
  7103. });
  7104. if (typeof a !== 'undefined') {
  7105. data.push(adjust(parseFloat(a), [
  7106. 0,
  7107. 1
  7108. ]));
  7109. }
  7110. } else if (r[5] || r[6]) {
  7111. var hsxa = (r[5] || r[6]).split(',');
  7112. var h = parseInt(hsxa[0], 0) / 360;
  7113. var s = hsxa[1];
  7114. var x = hsxa[2];
  7115. a = hsxa[3];
  7116. data = map([
  7117. s,
  7118. x
  7119. ], function (c) {
  7120. return adjust(parseFloat(c) / 100, [
  7121. 0,
  7122. 1
  7123. ]);
  7124. });
  7125. data.unshift(h);
  7126. if (typeof a !== 'undefined') {
  7127. data.push(adjust(parseFloat(a), [
  7128. 0,
  7129. 1
  7130. ]));
  7131. }
  7132. }
  7133. return data;
  7134. }
  7135. function alpha(color, a) {
  7136. if (!isCalculableColor(color)) {
  7137. return color;
  7138. }
  7139. if (a === null) {
  7140. a = 1;
  7141. }
  7142. var data = getData(toRGBA(color));
  7143. data[3] = adjust(Number(a).toFixed(4), [
  7144. 0,
  7145. 1
  7146. ]);
  7147. return toColor(data, 'rgba');
  7148. }
  7149. function map(array, fun) {
  7150. if (typeof fun !== 'function') {
  7151. throw new TypeError();
  7152. }
  7153. var len = array ? array.length : 0;
  7154. for (var i = 0; i < len; i++) {
  7155. array[i] = fun(array[i]);
  7156. }
  7157. return array;
  7158. }
  7159. function adjust(value, region) {
  7160. if (value <= region[0]) {
  7161. value = region[0];
  7162. } else if (value >= region[1]) {
  7163. value = region[1];
  7164. }
  7165. return value;
  7166. }
  7167. function isCalculableColor(color) {
  7168. return color instanceof Array || typeof color === 'string';
  7169. }
  7170. function _HSV_2_RGB(data) {
  7171. var H = data[0];
  7172. var S = data[1];
  7173. var V = data[2];
  7174. var R;
  7175. var G;
  7176. var B;
  7177. if (S === 0) {
  7178. R = V * 255;
  7179. G = V * 255;
  7180. B = V * 255;
  7181. } else {
  7182. var h = H * 6;
  7183. if (h === 6) {
  7184. h = 0;
  7185. }
  7186. var i = h | 0;
  7187. var v1 = V * (1 - S);
  7188. var v2 = V * (1 - S * (h - i));
  7189. var v3 = V * (1 - S * (1 - (h - i)));
  7190. var r = 0;
  7191. var g = 0;
  7192. var b = 0;
  7193. if (i === 0) {
  7194. r = V;
  7195. g = v3;
  7196. b = v1;
  7197. } else if (i === 1) {
  7198. r = v2;
  7199. g = V;
  7200. b = v1;
  7201. } else if (i === 2) {
  7202. r = v1;
  7203. g = V;
  7204. b = v3;
  7205. } else if (i === 3) {
  7206. r = v1;
  7207. g = v2;
  7208. b = V;
  7209. } else if (i === 4) {
  7210. r = v3;
  7211. g = v1;
  7212. b = V;
  7213. } else {
  7214. r = V;
  7215. g = v1;
  7216. b = v2;
  7217. }
  7218. R = r * 255;
  7219. G = g * 255;
  7220. B = b * 255;
  7221. }
  7222. return [
  7223. R,
  7224. G,
  7225. B
  7226. ];
  7227. }
  7228. function _HSL_2_RGB(data) {
  7229. var H = data[0];
  7230. var S = data[1];
  7231. var L = data[2];
  7232. var R;
  7233. var G;
  7234. var B;
  7235. if (S === 0) {
  7236. R = L * 255;
  7237. G = L * 255;
  7238. B = L * 255;
  7239. } else {
  7240. var v2;
  7241. if (L < 0.5) {
  7242. v2 = L * (1 + S);
  7243. } else {
  7244. v2 = L + S - S * L;
  7245. }
  7246. var v1 = 2 * L - v2;
  7247. R = 255 * _HUE_2_RGB(v1, v2, H + 1 / 3);
  7248. G = 255 * _HUE_2_RGB(v1, v2, H);
  7249. B = 255 * _HUE_2_RGB(v1, v2, H - 1 / 3);
  7250. }
  7251. return [
  7252. R,
  7253. G,
  7254. B
  7255. ];
  7256. }
  7257. function _HUE_2_RGB(v1, v2, vH) {
  7258. if (vH < 0) {
  7259. vH += 1;
  7260. }
  7261. if (vH > 1) {
  7262. vH -= 1;
  7263. }
  7264. if (6 * vH < 1) {
  7265. return v1 + (v2 - v1) * 6 * vH;
  7266. }
  7267. if (2 * vH < 1) {
  7268. return v2;
  7269. }
  7270. if (3 * vH < 2) {
  7271. return v1 + (v2 - v1) * (2 / 3 - vH) * 6;
  7272. }
  7273. return v1;
  7274. }
  7275. function _RGB_2_HSB(data) {
  7276. var R = data[0] / 255;
  7277. var G = data[1] / 255;
  7278. var B = data[2] / 255;
  7279. var vMin = Math.min(R, G, B);
  7280. var vMax = Math.max(R, G, B);
  7281. var delta = vMax - vMin;
  7282. var V = vMax;
  7283. var H;
  7284. var S;
  7285. if (delta === 0) {
  7286. H = 0;
  7287. S = 0;
  7288. } else {
  7289. S = delta / vMax;
  7290. var deltaR = ((vMax - R) / 6 + delta / 2) / delta;
  7291. var deltaG = ((vMax - G) / 6 + delta / 2) / delta;
  7292. var deltaB = ((vMax - B) / 6 + delta / 2) / delta;
  7293. if (R === vMax) {
  7294. H = deltaB - deltaG;
  7295. } else if (G === vMax) {
  7296. H = 1 / 3 + deltaR - deltaB;
  7297. } else if (B === vMax) {
  7298. H = 2 / 3 + deltaG - deltaR;
  7299. }
  7300. if (H < 0) {
  7301. H += 1;
  7302. }
  7303. if (H > 1) {
  7304. H -= 1;
  7305. }
  7306. }
  7307. H = H * 360;
  7308. S = S * 100;
  7309. V = V * 100;
  7310. return [
  7311. H,
  7312. S,
  7313. V
  7314. ];
  7315. }
  7316. function _RGB_2_HSL(data) {
  7317. var R = data[0] / 255;
  7318. var G = data[1] / 255;
  7319. var B = data[2] / 255;
  7320. var vMin = Math.min(R, G, B);
  7321. var vMax = Math.max(R, G, B);
  7322. var delta = vMax - vMin;
  7323. var L = (vMax + vMin) / 2;
  7324. var H;
  7325. var S;
  7326. if (delta === 0) {
  7327. H = 0;
  7328. S = 0;
  7329. } else {
  7330. if (L < 0.5) {
  7331. S = delta / (vMax + vMin);
  7332. } else {
  7333. S = delta / (2 - vMax - vMin);
  7334. }
  7335. var deltaR = ((vMax - R) / 6 + delta / 2) / delta;
  7336. var deltaG = ((vMax - G) / 6 + delta / 2) / delta;
  7337. var deltaB = ((vMax - B) / 6 + delta / 2) / delta;
  7338. if (R === vMax) {
  7339. H = deltaB - deltaG;
  7340. } else if (G === vMax) {
  7341. H = 1 / 3 + deltaR - deltaB;
  7342. } else if (B === vMax) {
  7343. H = 2 / 3 + deltaG - deltaR;
  7344. }
  7345. if (H < 0) {
  7346. H += 1;
  7347. }
  7348. if (H > 1) {
  7349. H -= 1;
  7350. }
  7351. }
  7352. H = H * 360;
  7353. S = S * 100;
  7354. L = L * 100;
  7355. return [
  7356. H,
  7357. S,
  7358. L
  7359. ];
  7360. }
  7361. return {
  7362. customPalette: customPalette,
  7363. resetPalette: resetPalette,
  7364. getColor: getColor,
  7365. getHighlightColor: getHighlightColor,
  7366. customHighlight: customHighlight,
  7367. resetHighlight: resetHighlight,
  7368. getRadialGradient: getRadialGradient,
  7369. getLinearGradient: getLinearGradient,
  7370. getGradientColors: getGradientColors,
  7371. getStepColors: getStepColors,
  7372. reverse: reverse,
  7373. mix: mix,
  7374. lift: lift,
  7375. trim: trim,
  7376. random: random,
  7377. toRGB: toRGB,
  7378. toRGBA: toRGBA,
  7379. toHex: toHex,
  7380. toHSL: toHSL,
  7381. toHSLA: toHSLA,
  7382. toHSB: toHSB,
  7383. toHSBA: toHSBA,
  7384. toHSV: toHSV,
  7385. toHSVA: toHSVA,
  7386. toName: toName,
  7387. toColor: toColor,
  7388. toArray: toArray,
  7389. alpha: alpha,
  7390. getData: getData
  7391. };
  7392. });define('echarts/component/timeline', [
  7393. 'require',
  7394. './base',
  7395. 'zrender/shape/Rectangle',
  7396. '../util/shape/Icon',
  7397. '../util/shape/Chain',
  7398. '../config',
  7399. 'zrender/tool/util',
  7400. 'zrender/tool/area',
  7401. 'zrender/tool/event',
  7402. '../component'
  7403. ], function (require) {
  7404. var Base = require('./base');
  7405. var RectangleShape = require('zrender/shape/Rectangle');
  7406. var IconShape = require('../util/shape/Icon');
  7407. var ChainShape = require('../util/shape/Chain');
  7408. var ecConfig = require('../config');
  7409. ecConfig.timeline = {
  7410. zlevel: 0,
  7411. z: 4,
  7412. show: true,
  7413. type: 'time',
  7414. notMerge: false,
  7415. realtime: true,
  7416. x: 80,
  7417. x2: 80,
  7418. y2: 0,
  7419. height: 50,
  7420. backgroundColor: 'rgba(0,0,0,0)',
  7421. borderColor: '#ccc',
  7422. borderWidth: 0,
  7423. padding: 5,
  7424. controlPosition: 'left',
  7425. autoPlay: false,
  7426. loop: true,
  7427. playInterval: 2000,
  7428. lineStyle: {
  7429. width: 1,
  7430. color: '#666',
  7431. type: 'dashed'
  7432. },
  7433. label: {
  7434. show: true,
  7435. interval: 'auto',
  7436. rotate: 0,
  7437. textStyle: { color: '#333' }
  7438. },
  7439. checkpointStyle: {
  7440. symbol: 'auto',
  7441. symbolSize: 'auto',
  7442. color: 'auto',
  7443. borderColor: 'auto',
  7444. borderWidth: 'auto',
  7445. label: {
  7446. show: false,
  7447. textStyle: { color: 'auto' }
  7448. }
  7449. },
  7450. controlStyle: {
  7451. itemSize: 15,
  7452. itemGap: 5,
  7453. normal: { color: '#333' },
  7454. emphasis: { color: '#1e90ff' }
  7455. },
  7456. symbol: 'emptyDiamond',
  7457. symbolSize: 4,
  7458. currentIndex: 0
  7459. };
  7460. var zrUtil = require('zrender/tool/util');
  7461. var zrArea = require('zrender/tool/area');
  7462. var zrEvent = require('zrender/tool/event');
  7463. function Timeline(ecTheme, messageCenter, zr, option, myChart) {
  7464. Base.call(this, ecTheme, messageCenter, zr, option, myChart);
  7465. var self = this;
  7466. self._onclick = function (param) {
  7467. return self.__onclick(param);
  7468. };
  7469. self._ondrift = function (dx, dy) {
  7470. return self.__ondrift(this, dx, dy);
  7471. };
  7472. self._ondragend = function () {
  7473. return self.__ondragend();
  7474. };
  7475. self._setCurrentOption = function () {
  7476. var timelineOption = self.timelineOption;
  7477. self.currentIndex %= timelineOption.data.length;
  7478. var curOption = self.options[self.currentIndex] || {};
  7479. self.myChart._setOption(curOption, timelineOption.notMerge, true);
  7480. self.messageCenter.dispatch(ecConfig.EVENT.TIMELINE_CHANGED, null, {
  7481. currentIndex: self.currentIndex,
  7482. data: timelineOption.data[self.currentIndex].name != null ? timelineOption.data[self.currentIndex].name : timelineOption.data[self.currentIndex]
  7483. }, self.myChart);
  7484. };
  7485. self._onFrame = function () {
  7486. self._setCurrentOption();
  7487. self._syncHandleShape();
  7488. if (self.timelineOption.autoPlay) {
  7489. self.playTicket = setTimeout(function () {
  7490. self.currentIndex += 1;
  7491. if (!self.timelineOption.loop && self.currentIndex >= self.timelineOption.data.length) {
  7492. self.currentIndex = self.timelineOption.data.length - 1;
  7493. self.stop();
  7494. return;
  7495. }
  7496. self._onFrame();
  7497. }, self.timelineOption.playInterval);
  7498. }
  7499. };
  7500. this.setTheme(false);
  7501. this.options = this.option.options;
  7502. this.currentIndex = this.timelineOption.currentIndex % this.timelineOption.data.length;
  7503. if (!this.timelineOption.notMerge && this.currentIndex !== 0) {
  7504. this.options[this.currentIndex] = zrUtil.merge(this.options[this.currentIndex], this.options[0]);
  7505. }
  7506. if (this.timelineOption.show) {
  7507. this._buildShape();
  7508. this._syncHandleShape();
  7509. }
  7510. this._setCurrentOption();
  7511. if (this.timelineOption.autoPlay) {
  7512. var self = this;
  7513. this.playTicket = setTimeout(function () {
  7514. self.play();
  7515. }, this.ecTheme.animationDuration != null ? this.ecTheme.animationDuration : ecConfig.animationDuration);
  7516. }
  7517. }
  7518. Timeline.prototype = {
  7519. type: ecConfig.COMPONENT_TYPE_TIMELINE,
  7520. _buildShape: function () {
  7521. this._location = this._getLocation();
  7522. this._buildBackground();
  7523. this._buildControl();
  7524. this._chainPoint = this._getChainPoint();
  7525. if (this.timelineOption.label.show) {
  7526. var interval = this._getInterval();
  7527. for (var i = 0, len = this._chainPoint.length; i < len; i += interval) {
  7528. this._chainPoint[i].showLabel = true;
  7529. }
  7530. }
  7531. this._buildChain();
  7532. this._buildHandle();
  7533. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  7534. this.zr.addShape(this.shapeList[i]);
  7535. }
  7536. },
  7537. _getLocation: function () {
  7538. var timelineOption = this.timelineOption;
  7539. var padding = this.reformCssArray(this.timelineOption.padding);
  7540. var zrWidth = this.zr.getWidth();
  7541. var x = this.parsePercent(timelineOption.x, zrWidth);
  7542. var x2 = this.parsePercent(timelineOption.x2, zrWidth);
  7543. var width;
  7544. if (timelineOption.width == null) {
  7545. width = zrWidth - x - x2;
  7546. x2 = zrWidth - x2;
  7547. } else {
  7548. width = this.parsePercent(timelineOption.width, zrWidth);
  7549. x2 = x + width;
  7550. }
  7551. var zrHeight = this.zr.getHeight();
  7552. var height = this.parsePercent(timelineOption.height, zrHeight);
  7553. var y;
  7554. var y2;
  7555. if (timelineOption.y != null) {
  7556. y = this.parsePercent(timelineOption.y, zrHeight);
  7557. y2 = y + height;
  7558. } else {
  7559. y2 = zrHeight - this.parsePercent(timelineOption.y2, zrHeight);
  7560. y = y2 - height;
  7561. }
  7562. return {
  7563. x: x + padding[3],
  7564. y: y + padding[0],
  7565. x2: x2 - padding[1],
  7566. y2: y2 - padding[2],
  7567. width: width - padding[1] - padding[3],
  7568. height: height - padding[0] - padding[2]
  7569. };
  7570. },
  7571. _getReformedLabel: function (idx) {
  7572. var timelineOption = this.timelineOption;
  7573. var data = timelineOption.data[idx].name != null ? timelineOption.data[idx].name : timelineOption.data[idx];
  7574. var formatter = timelineOption.data[idx].formatter || timelineOption.label.formatter;
  7575. if (formatter) {
  7576. if (typeof formatter === 'function') {
  7577. data = formatter.call(this.myChart, data);
  7578. } else if (typeof formatter === 'string') {
  7579. data = formatter.replace('{value}', data);
  7580. }
  7581. }
  7582. return data;
  7583. },
  7584. _getInterval: function () {
  7585. var chainPoint = this._chainPoint;
  7586. var timelineOption = this.timelineOption;
  7587. var interval = timelineOption.label.interval;
  7588. if (interval === 'auto') {
  7589. var fontSize = timelineOption.label.textStyle.fontSize;
  7590. var data = timelineOption.data;
  7591. var dataLength = timelineOption.data.length;
  7592. if (dataLength > 3) {
  7593. var isEnough = false;
  7594. var labelSpace;
  7595. var labelSize;
  7596. interval = 0;
  7597. while (!isEnough && interval < dataLength) {
  7598. interval++;
  7599. isEnough = true;
  7600. for (var i = interval; i < dataLength; i += interval) {
  7601. labelSpace = chainPoint[i].x - chainPoint[i - interval].x;
  7602. if (timelineOption.label.rotate !== 0) {
  7603. labelSize = fontSize;
  7604. } else if (data[i].textStyle) {
  7605. labelSize = zrArea.getTextWidth(chainPoint[i].name, chainPoint[i].textFont);
  7606. } else {
  7607. var label = chainPoint[i].name + '';
  7608. var wLen = (label.match(/\w/g) || '').length;
  7609. var oLen = label.length - wLen;
  7610. labelSize = wLen * fontSize * 2 / 3 + oLen * fontSize;
  7611. }
  7612. if (labelSpace < labelSize) {
  7613. isEnough = false;
  7614. break;
  7615. }
  7616. }
  7617. }
  7618. } else {
  7619. interval = 1;
  7620. }
  7621. } else {
  7622. interval = interval - 0 + 1;
  7623. }
  7624. return interval;
  7625. },
  7626. _getChainPoint: function () {
  7627. var timelineOption = this.timelineOption;
  7628. var symbol = timelineOption.symbol.toLowerCase();
  7629. var symbolSize = timelineOption.symbolSize;
  7630. var rotate = timelineOption.label.rotate;
  7631. var textStyle = timelineOption.label.textStyle;
  7632. var textFont = this.getFont(textStyle);
  7633. var dataTextStyle;
  7634. var data = timelineOption.data;
  7635. var x = this._location.x;
  7636. var y = this._location.y + this._location.height / 4 * 3;
  7637. var width = this._location.x2 - this._location.x;
  7638. var len = data.length;
  7639. function _getName(i) {
  7640. return data[i].name != null ? data[i].name : data[i] + '';
  7641. }
  7642. var xList = [];
  7643. if (len > 1) {
  7644. var boundaryGap = width / len;
  7645. boundaryGap = boundaryGap > 50 ? 50 : boundaryGap < 20 ? 5 : boundaryGap;
  7646. width -= boundaryGap * 2;
  7647. if (timelineOption.type === 'number') {
  7648. for (var i = 0; i < len; i++) {
  7649. xList.push(x + boundaryGap + width / (len - 1) * i);
  7650. }
  7651. } else {
  7652. xList[0] = new Date(_getName(0).replace(/-/g, '/'));
  7653. xList[len - 1] = new Date(_getName(len - 1).replace(/-/g, '/')) - xList[0];
  7654. for (var i = 1; i < len; i++) {
  7655. xList[i] = x + boundaryGap + width * (new Date(_getName(i).replace(/-/g, '/')) - xList[0]) / xList[len - 1];
  7656. }
  7657. xList[0] = x + boundaryGap;
  7658. }
  7659. } else {
  7660. xList.push(x + width / 2);
  7661. }
  7662. var list = [];
  7663. var curSymbol;
  7664. var n;
  7665. var isEmpty;
  7666. var textAlign;
  7667. var rotation;
  7668. for (var i = 0; i < len; i++) {
  7669. x = xList[i];
  7670. curSymbol = data[i].symbol && data[i].symbol.toLowerCase() || symbol;
  7671. if (curSymbol.match('empty')) {
  7672. curSymbol = curSymbol.replace('empty', '');
  7673. isEmpty = true;
  7674. } else {
  7675. isEmpty = false;
  7676. }
  7677. if (curSymbol.match('star')) {
  7678. n = curSymbol.replace('star', '') - 0 || 5;
  7679. curSymbol = 'star';
  7680. }
  7681. dataTextStyle = data[i].textStyle ? zrUtil.merge(data[i].textStyle || {}, textStyle) : textStyle;
  7682. textAlign = dataTextStyle.align || 'center';
  7683. if (rotate) {
  7684. textAlign = rotate > 0 ? 'right' : 'left';
  7685. rotation = [
  7686. rotate * Math.PI / 180,
  7687. x,
  7688. y - 5
  7689. ];
  7690. } else {
  7691. rotation = false;
  7692. }
  7693. list.push({
  7694. x: x,
  7695. n: n,
  7696. isEmpty: isEmpty,
  7697. symbol: curSymbol,
  7698. symbolSize: data[i].symbolSize || symbolSize,
  7699. color: data[i].color,
  7700. borderColor: data[i].borderColor,
  7701. borderWidth: data[i].borderWidth,
  7702. name: this._getReformedLabel(i),
  7703. textColor: dataTextStyle.color,
  7704. textAlign: textAlign,
  7705. textBaseline: dataTextStyle.baseline || 'middle',
  7706. textX: x,
  7707. textY: y - (rotate ? 5 : 0),
  7708. textFont: data[i].textStyle ? this.getFont(dataTextStyle) : textFont,
  7709. rotation: rotation,
  7710. showLabel: false
  7711. });
  7712. }
  7713. return list;
  7714. },
  7715. _buildBackground: function () {
  7716. var timelineOption = this.timelineOption;
  7717. var padding = this.reformCssArray(this.timelineOption.padding);
  7718. var width = this._location.width;
  7719. var height = this._location.height;
  7720. if (timelineOption.borderWidth !== 0 || timelineOption.backgroundColor.replace(/\s/g, '') != 'rgba(0,0,0,0)') {
  7721. this.shapeList.push(new RectangleShape({
  7722. zlevel: this.getZlevelBase(),
  7723. z: this.getZBase(),
  7724. hoverable: false,
  7725. style: {
  7726. x: this._location.x - padding[3],
  7727. y: this._location.y - padding[0],
  7728. width: width + padding[1] + padding[3],
  7729. height: height + padding[0] + padding[2],
  7730. brushType: timelineOption.borderWidth === 0 ? 'fill' : 'both',
  7731. color: timelineOption.backgroundColor,
  7732. strokeColor: timelineOption.borderColor,
  7733. lineWidth: timelineOption.borderWidth
  7734. }
  7735. }));
  7736. }
  7737. },
  7738. _buildControl: function () {
  7739. var self = this;
  7740. var timelineOption = this.timelineOption;
  7741. var lineStyle = timelineOption.lineStyle;
  7742. var controlStyle = timelineOption.controlStyle;
  7743. if (timelineOption.controlPosition === 'none') {
  7744. return;
  7745. }
  7746. var iconSize = controlStyle.itemSize;
  7747. var iconGap = controlStyle.itemGap;
  7748. var x;
  7749. if (timelineOption.controlPosition === 'left') {
  7750. x = this._location.x;
  7751. this._location.x += (iconSize + iconGap) * 3;
  7752. } else {
  7753. x = this._location.x2 - ((iconSize + iconGap) * 3 - iconGap);
  7754. this._location.x2 -= (iconSize + iconGap) * 3;
  7755. }
  7756. var y = this._location.y;
  7757. var iconStyle = {
  7758. zlevel: this.getZlevelBase(),
  7759. z: this.getZBase() + 1,
  7760. style: {
  7761. iconType: 'timelineControl',
  7762. symbol: 'last',
  7763. x: x,
  7764. y: y,
  7765. width: iconSize,
  7766. height: iconSize,
  7767. brushType: 'stroke',
  7768. color: controlStyle.normal.color,
  7769. strokeColor: controlStyle.normal.color,
  7770. lineWidth: lineStyle.width
  7771. },
  7772. highlightStyle: {
  7773. color: controlStyle.emphasis.color,
  7774. strokeColor: controlStyle.emphasis.color,
  7775. lineWidth: lineStyle.width + 1
  7776. },
  7777. clickable: true
  7778. };
  7779. this._ctrLastShape = new IconShape(iconStyle);
  7780. this._ctrLastShape.onclick = function () {
  7781. self.last();
  7782. };
  7783. this.shapeList.push(this._ctrLastShape);
  7784. x += iconSize + iconGap;
  7785. this._ctrPlayShape = new IconShape(zrUtil.clone(iconStyle));
  7786. this._ctrPlayShape.style.brushType = 'fill';
  7787. this._ctrPlayShape.style.symbol = 'play';
  7788. this._ctrPlayShape.style.status = this.timelineOption.autoPlay ? 'playing' : 'stop';
  7789. this._ctrPlayShape.style.x = x;
  7790. this._ctrPlayShape.onclick = function () {
  7791. if (self._ctrPlayShape.style.status === 'stop') {
  7792. self.play();
  7793. } else {
  7794. self.stop();
  7795. }
  7796. };
  7797. this.shapeList.push(this._ctrPlayShape);
  7798. x += iconSize + iconGap;
  7799. this._ctrNextShape = new IconShape(zrUtil.clone(iconStyle));
  7800. this._ctrNextShape.style.symbol = 'next';
  7801. this._ctrNextShape.style.x = x;
  7802. this._ctrNextShape.onclick = function () {
  7803. self.next();
  7804. };
  7805. this.shapeList.push(this._ctrNextShape);
  7806. },
  7807. _buildChain: function () {
  7808. var timelineOption = this.timelineOption;
  7809. var lineStyle = timelineOption.lineStyle;
  7810. this._timelineShae = {
  7811. zlevel: this.getZlevelBase(),
  7812. z: this.getZBase(),
  7813. style: {
  7814. x: this._location.x,
  7815. y: this.subPixelOptimize(this._location.y, lineStyle.width),
  7816. width: this._location.x2 - this._location.x,
  7817. height: this._location.height,
  7818. chainPoint: this._chainPoint,
  7819. brushType: 'both',
  7820. strokeColor: lineStyle.color,
  7821. lineWidth: lineStyle.width,
  7822. lineType: lineStyle.type
  7823. },
  7824. hoverable: false,
  7825. clickable: true,
  7826. onclick: this._onclick
  7827. };
  7828. this._timelineShae = new ChainShape(this._timelineShae);
  7829. this.shapeList.push(this._timelineShae);
  7830. },
  7831. _buildHandle: function () {
  7832. var curPoint = this._chainPoint[this.currentIndex];
  7833. var symbolSize = curPoint.symbolSize + 1;
  7834. symbolSize = symbolSize < 5 ? 5 : symbolSize;
  7835. this._handleShape = {
  7836. zlevel: this.getZlevelBase(),
  7837. z: this.getZBase() + 1,
  7838. hoverable: false,
  7839. draggable: true,
  7840. style: {
  7841. iconType: 'diamond',
  7842. n: curPoint.n,
  7843. x: curPoint.x - symbolSize,
  7844. y: this._location.y + this._location.height / 4 - symbolSize,
  7845. width: symbolSize * 2,
  7846. height: symbolSize * 2,
  7847. brushType: 'both',
  7848. textPosition: 'specific',
  7849. textX: curPoint.x,
  7850. textY: this._location.y - this._location.height / 4,
  7851. textAlign: 'center',
  7852. textBaseline: 'middle'
  7853. },
  7854. highlightStyle: {},
  7855. ondrift: this._ondrift,
  7856. ondragend: this._ondragend
  7857. };
  7858. this._handleShape = new IconShape(this._handleShape);
  7859. this.shapeList.push(this._handleShape);
  7860. },
  7861. _syncHandleShape: function () {
  7862. if (!this.timelineOption.show) {
  7863. return;
  7864. }
  7865. var timelineOption = this.timelineOption;
  7866. var cpStyle = timelineOption.checkpointStyle;
  7867. var curPoint = this._chainPoint[this.currentIndex];
  7868. this._handleShape.style.text = cpStyle.label.show ? curPoint.name : '';
  7869. this._handleShape.style.textFont = curPoint.textFont;
  7870. this._handleShape.style.n = curPoint.n;
  7871. if (cpStyle.symbol === 'auto') {
  7872. this._handleShape.style.iconType = curPoint.symbol != 'none' ? curPoint.symbol : 'diamond';
  7873. } else {
  7874. this._handleShape.style.iconType = cpStyle.symbol;
  7875. if (cpStyle.symbol.match('star')) {
  7876. this._handleShape.style.n = cpStyle.symbol.replace('star', '') - 0 || 5;
  7877. this._handleShape.style.iconType = 'star';
  7878. }
  7879. }
  7880. var symbolSize;
  7881. if (cpStyle.symbolSize === 'auto') {
  7882. symbolSize = curPoint.symbolSize + 2;
  7883. symbolSize = symbolSize < 5 ? 5 : symbolSize;
  7884. } else {
  7885. symbolSize = cpStyle.symbolSize - 0;
  7886. }
  7887. this._handleShape.style.color = cpStyle.color === 'auto' ? curPoint.color ? curPoint.color : timelineOption.controlStyle.emphasis.color : cpStyle.color;
  7888. this._handleShape.style.textColor = cpStyle.label.textStyle.color === 'auto' ? this._handleShape.style.color : cpStyle.label.textStyle.color;
  7889. this._handleShape.highlightStyle.strokeColor = this._handleShape.style.strokeColor = cpStyle.borderColor === 'auto' ? curPoint.borderColor ? curPoint.borderColor : '#fff' : cpStyle.borderColor;
  7890. this._handleShape.style.lineWidth = cpStyle.borderWidth === 'auto' ? curPoint.borderWidth ? curPoint.borderWidth : 0 : cpStyle.borderWidth - 0;
  7891. this._handleShape.highlightStyle.lineWidth = this._handleShape.style.lineWidth + 1;
  7892. this.zr.animate(this._handleShape.id, 'style').when(500, {
  7893. x: curPoint.x - symbolSize,
  7894. textX: curPoint.x,
  7895. y: this._location.y + this._location.height / 4 - symbolSize,
  7896. width: symbolSize * 2,
  7897. height: symbolSize * 2
  7898. }).start('ExponentialOut');
  7899. },
  7900. _findChainIndex: function (x) {
  7901. var chainPoint = this._chainPoint;
  7902. var len = chainPoint.length;
  7903. if (x <= chainPoint[0].x) {
  7904. return 0;
  7905. } else if (x >= chainPoint[len - 1].x) {
  7906. return len - 1;
  7907. }
  7908. for (var i = 0; i < len - 1; i++) {
  7909. if (x >= chainPoint[i].x && x <= chainPoint[i + 1].x) {
  7910. return Math.abs(x - chainPoint[i].x) < Math.abs(x - chainPoint[i + 1].x) ? i : i + 1;
  7911. }
  7912. }
  7913. },
  7914. __onclick: function (param) {
  7915. var x = zrEvent.getX(param.event);
  7916. var newIndex = this._findChainIndex(x);
  7917. if (newIndex === this.currentIndex) {
  7918. return true;
  7919. }
  7920. this.currentIndex = newIndex;
  7921. this.timelineOption.autoPlay && this.stop();
  7922. clearTimeout(this.playTicket);
  7923. this._onFrame();
  7924. },
  7925. __ondrift: function (shape, dx) {
  7926. this.timelineOption.autoPlay && this.stop();
  7927. var chainPoint = this._chainPoint;
  7928. var len = chainPoint.length;
  7929. var newIndex;
  7930. if (shape.style.x + dx <= chainPoint[0].x - chainPoint[0].symbolSize) {
  7931. shape.style.x = chainPoint[0].x - chainPoint[0].symbolSize;
  7932. newIndex = 0;
  7933. } else if (shape.style.x + dx >= chainPoint[len - 1].x - chainPoint[len - 1].symbolSize) {
  7934. shape.style.x = chainPoint[len - 1].x - chainPoint[len - 1].symbolSize;
  7935. newIndex = len - 1;
  7936. } else {
  7937. shape.style.x += dx;
  7938. newIndex = this._findChainIndex(shape.style.x);
  7939. }
  7940. var curPoint = chainPoint[newIndex];
  7941. var symbolSize = curPoint.symbolSize + 2;
  7942. shape.style.iconType = curPoint.symbol;
  7943. shape.style.n = curPoint.n;
  7944. shape.style.textX = shape.style.x + symbolSize / 2;
  7945. shape.style.y = this._location.y + this._location.height / 4 - symbolSize;
  7946. shape.style.width = symbolSize * 2;
  7947. shape.style.height = symbolSize * 2;
  7948. shape.style.text = curPoint.name;
  7949. if (newIndex === this.currentIndex) {
  7950. return true;
  7951. }
  7952. this.currentIndex = newIndex;
  7953. if (this.timelineOption.realtime) {
  7954. clearTimeout(this.playTicket);
  7955. var self = this;
  7956. this.playTicket = setTimeout(function () {
  7957. self._setCurrentOption();
  7958. }, 200);
  7959. }
  7960. return true;
  7961. },
  7962. __ondragend: function () {
  7963. this.isDragend = true;
  7964. },
  7965. ondragend: function (param, status) {
  7966. if (!this.isDragend || !param.target) {
  7967. return;
  7968. }
  7969. !this.timelineOption.realtime && this._setCurrentOption();
  7970. status.dragOut = true;
  7971. status.dragIn = true;
  7972. status.needRefresh = false;
  7973. this.isDragend = false;
  7974. this._syncHandleShape();
  7975. return;
  7976. },
  7977. last: function () {
  7978. this.timelineOption.autoPlay && this.stop();
  7979. this.currentIndex -= 1;
  7980. if (this.currentIndex < 0) {
  7981. this.currentIndex = this.timelineOption.data.length - 1;
  7982. }
  7983. this._onFrame();
  7984. return this.currentIndex;
  7985. },
  7986. next: function () {
  7987. this.timelineOption.autoPlay && this.stop();
  7988. this.currentIndex += 1;
  7989. if (this.currentIndex >= this.timelineOption.data.length) {
  7990. this.currentIndex = 0;
  7991. }
  7992. this._onFrame();
  7993. return this.currentIndex;
  7994. },
  7995. play: function (targetIndex, autoPlay) {
  7996. if (this._ctrPlayShape && this._ctrPlayShape.style.status != 'playing') {
  7997. this._ctrPlayShape.style.status = 'playing';
  7998. this.zr.modShape(this._ctrPlayShape.id);
  7999. this.zr.refreshNextFrame();
  8000. }
  8001. this.timelineOption.autoPlay = autoPlay != null ? autoPlay : true;
  8002. if (!this.timelineOption.autoPlay) {
  8003. clearTimeout(this.playTicket);
  8004. }
  8005. this.currentIndex = targetIndex != null ? targetIndex : this.currentIndex + 1;
  8006. if (this.currentIndex >= this.timelineOption.data.length) {
  8007. this.currentIndex = 0;
  8008. }
  8009. this._onFrame();
  8010. return this.currentIndex;
  8011. },
  8012. stop: function () {
  8013. if (this._ctrPlayShape && this._ctrPlayShape.style.status != 'stop') {
  8014. this._ctrPlayShape.style.status = 'stop';
  8015. this.zr.modShape(this._ctrPlayShape.id);
  8016. this.zr.refreshNextFrame();
  8017. }
  8018. this.timelineOption.autoPlay = false;
  8019. clearTimeout(this.playTicket);
  8020. return this.currentIndex;
  8021. },
  8022. resize: function () {
  8023. if (this.timelineOption.show) {
  8024. this.clear();
  8025. this._buildShape();
  8026. this._syncHandleShape();
  8027. }
  8028. },
  8029. setTheme: function (needRefresh) {
  8030. this.timelineOption = this.reformOption(zrUtil.clone(this.option.timeline));
  8031. this.timelineOption.label.textStyle = this.getTextStyle(this.timelineOption.label.textStyle);
  8032. this.timelineOption.checkpointStyle.label.textStyle = this.getTextStyle(this.timelineOption.checkpointStyle.label.textStyle);
  8033. if (!this.myChart.canvasSupported) {
  8034. this.timelineOption.realtime = false;
  8035. }
  8036. if (this.timelineOption.show && needRefresh) {
  8037. this.clear();
  8038. this._buildShape();
  8039. this._syncHandleShape();
  8040. }
  8041. },
  8042. onbeforDispose: function () {
  8043. clearTimeout(this.playTicket);
  8044. }
  8045. };
  8046. function timelineControl(ctx, style) {
  8047. var lineWidth = 2;
  8048. var x = style.x + lineWidth;
  8049. var y = style.y + lineWidth + 2;
  8050. var width = style.width - lineWidth;
  8051. var height = style.height - lineWidth;
  8052. var symbol = style.symbol;
  8053. if (symbol === 'last') {
  8054. ctx.moveTo(x + width - 2, y + height / 3);
  8055. ctx.lineTo(x + width - 2, y);
  8056. ctx.lineTo(x + 2, y + height / 2);
  8057. ctx.lineTo(x + width - 2, y + height);
  8058. ctx.lineTo(x + width - 2, y + height / 3 * 2);
  8059. ctx.moveTo(x, y);
  8060. ctx.lineTo(x, y);
  8061. } else if (symbol === 'next') {
  8062. ctx.moveTo(x + 2, y + height / 3);
  8063. ctx.lineTo(x + 2, y);
  8064. ctx.lineTo(x + width - 2, y + height / 2);
  8065. ctx.lineTo(x + 2, y + height);
  8066. ctx.lineTo(x + 2, y + height / 3 * 2);
  8067. ctx.moveTo(x, y);
  8068. ctx.lineTo(x, y);
  8069. } else if (symbol === 'play') {
  8070. if (style.status === 'stop') {
  8071. ctx.moveTo(x + 2, y);
  8072. ctx.lineTo(x + width - 2, y + height / 2);
  8073. ctx.lineTo(x + 2, y + height);
  8074. ctx.lineTo(x + 2, y);
  8075. } else {
  8076. var delta = style.brushType === 'both' ? 2 : 3;
  8077. ctx.rect(x + 2, y, delta, height);
  8078. ctx.rect(x + width - delta - 2, y, delta, height);
  8079. }
  8080. } else if (symbol.match('image')) {
  8081. var imageLocation = '';
  8082. imageLocation = symbol.replace(new RegExp('^image:\\/\\/'), '');
  8083. symbol = IconShape.prototype.iconLibrary.image;
  8084. symbol(ctx, {
  8085. x: x,
  8086. y: y,
  8087. width: width,
  8088. height: height,
  8089. image: imageLocation
  8090. });
  8091. }
  8092. }
  8093. IconShape.prototype.iconLibrary['timelineControl'] = timelineControl;
  8094. zrUtil.inherits(Timeline, Base);
  8095. require('../component').define('timeline', Timeline);
  8096. return Timeline;
  8097. });define('zrender/shape/Image', [
  8098. 'require',
  8099. './Base',
  8100. '../tool/util'
  8101. ], function (require) {
  8102. var Base = require('./Base');
  8103. var ZImage = function (options) {
  8104. Base.call(this, options);
  8105. };
  8106. ZImage.prototype = {
  8107. type: 'image',
  8108. brush: function (ctx, isHighlight, refreshNextFrame) {
  8109. var style = this.style || {};
  8110. if (isHighlight) {
  8111. style = this.getHighlightStyle(style, this.highlightStyle || {});
  8112. }
  8113. var image = style.image;
  8114. var self = this;
  8115. if (!this._imageCache) {
  8116. this._imageCache = {};
  8117. }
  8118. if (typeof image === 'string') {
  8119. var src = image;
  8120. if (this._imageCache[src]) {
  8121. image = this._imageCache[src];
  8122. } else {
  8123. image = new Image();
  8124. image.onload = function () {
  8125. image.onload = null;
  8126. self.modSelf();
  8127. refreshNextFrame();
  8128. };
  8129. image.src = src;
  8130. this._imageCache[src] = image;
  8131. }
  8132. }
  8133. if (image) {
  8134. if (image.nodeName.toUpperCase() == 'IMG') {
  8135. if (window.ActiveXObject) {
  8136. if (image.readyState != 'complete') {
  8137. return;
  8138. }
  8139. } else {
  8140. if (!image.complete) {
  8141. return;
  8142. }
  8143. }
  8144. }
  8145. var width = style.width || image.width;
  8146. var height = style.height || image.height;
  8147. var x = style.x;
  8148. var y = style.y;
  8149. if (!image.width || !image.height) {
  8150. return;
  8151. }
  8152. ctx.save();
  8153. this.doClip(ctx);
  8154. this.setContext(ctx, style);
  8155. this.setTransform(ctx);
  8156. if (style.sWidth && style.sHeight) {
  8157. var sx = style.sx || 0;
  8158. var sy = style.sy || 0;
  8159. ctx.drawImage(image, sx, sy, style.sWidth, style.sHeight, x, y, width, height);
  8160. } else if (style.sx && style.sy) {
  8161. var sx = style.sx;
  8162. var sy = style.sy;
  8163. var sWidth = width - sx;
  8164. var sHeight = height - sy;
  8165. ctx.drawImage(image, sx, sy, sWidth, sHeight, x, y, width, height);
  8166. } else {
  8167. ctx.drawImage(image, x, y, width, height);
  8168. }
  8169. if (!style.width) {
  8170. style.width = width;
  8171. }
  8172. if (!style.height) {
  8173. style.height = height;
  8174. }
  8175. if (!this.style.width) {
  8176. this.style.width = width;
  8177. }
  8178. if (!this.style.height) {
  8179. this.style.height = height;
  8180. }
  8181. this.drawText(ctx, style, this.style);
  8182. ctx.restore();
  8183. }
  8184. },
  8185. getRect: function (style) {
  8186. return {
  8187. x: style.x,
  8188. y: style.y,
  8189. width: style.width,
  8190. height: style.height
  8191. };
  8192. },
  8193. clearCache: function () {
  8194. this._imageCache = {};
  8195. }
  8196. };
  8197. require('../tool/util').inherits(ZImage, Base);
  8198. return ZImage;
  8199. });define('zrender/loadingEffect/Bar', [
  8200. 'require',
  8201. './Base',
  8202. '../tool/util',
  8203. '../tool/color',
  8204. '../shape/Rectangle'
  8205. ], function (require) {
  8206. var Base = require('./Base');
  8207. var util = require('../tool/util');
  8208. var zrColor = require('../tool/color');
  8209. var RectangleShape = require('../shape/Rectangle');
  8210. function Bar(options) {
  8211. Base.call(this, options);
  8212. }
  8213. util.inherits(Bar, Base);
  8214. Bar.prototype._start = function (addShapeHandle, refreshHandle) {
  8215. var options = util.merge(this.options, {
  8216. textStyle: { color: '#888' },
  8217. backgroundColor: 'rgba(250, 250, 250, 0.8)',
  8218. effectOption: {
  8219. x: 0,
  8220. y: this.canvasHeight / 2 - 30,
  8221. width: this.canvasWidth,
  8222. height: 5,
  8223. brushType: 'fill',
  8224. timeInterval: 100
  8225. }
  8226. });
  8227. var textShape = this.createTextShape(options.textStyle);
  8228. var background = this.createBackgroundShape(options.backgroundColor);
  8229. var effectOption = options.effectOption;
  8230. var barShape = new RectangleShape({ highlightStyle: util.clone(effectOption) });
  8231. barShape.highlightStyle.color = effectOption.color || zrColor.getLinearGradient(effectOption.x, effectOption.y, effectOption.x + effectOption.width, effectOption.y + effectOption.height, [
  8232. [
  8233. 0,
  8234. '#ff6400'
  8235. ],
  8236. [
  8237. 0.5,
  8238. '#ffe100'
  8239. ],
  8240. [
  8241. 1,
  8242. '#b1ff00'
  8243. ]
  8244. ]);
  8245. if (options.progress != null) {
  8246. addShapeHandle(background);
  8247. barShape.highlightStyle.width = this.adjust(options.progress, [
  8248. 0,
  8249. 1
  8250. ]) * options.effectOption.width;
  8251. addShapeHandle(barShape);
  8252. addShapeHandle(textShape);
  8253. refreshHandle();
  8254. return;
  8255. } else {
  8256. barShape.highlightStyle.width = 0;
  8257. return setInterval(function () {
  8258. addShapeHandle(background);
  8259. if (barShape.highlightStyle.width < effectOption.width) {
  8260. barShape.highlightStyle.width += 8;
  8261. } else {
  8262. barShape.highlightStyle.width = 0;
  8263. }
  8264. addShapeHandle(barShape);
  8265. addShapeHandle(textShape);
  8266. refreshHandle();
  8267. }, effectOption.timeInterval);
  8268. }
  8269. };
  8270. return Bar;
  8271. });define('zrender/loadingEffect/Bubble', [
  8272. 'require',
  8273. './Base',
  8274. '../tool/util',
  8275. '../tool/color',
  8276. '../shape/Circle'
  8277. ], function (require) {
  8278. var Base = require('./Base');
  8279. var util = require('../tool/util');
  8280. var zrColor = require('../tool/color');
  8281. var CircleShape = require('../shape/Circle');
  8282. function Bubble(options) {
  8283. Base.call(this, options);
  8284. }
  8285. util.inherits(Bubble, Base);
  8286. Bubble.prototype._start = function (addShapeHandle, refreshHandle) {
  8287. var options = util.merge(this.options, {
  8288. textStyle: { color: '#888' },
  8289. backgroundColor: 'rgba(250, 250, 250, 0.8)',
  8290. effect: {
  8291. n: 50,
  8292. lineWidth: 2,
  8293. brushType: 'stroke',
  8294. color: 'random',
  8295. timeInterval: 100
  8296. }
  8297. });
  8298. var textShape = this.createTextShape(options.textStyle);
  8299. var background = this.createBackgroundShape(options.backgroundColor);
  8300. var effectOption = options.effect;
  8301. var n = effectOption.n;
  8302. var brushType = effectOption.brushType;
  8303. var lineWidth = effectOption.lineWidth;
  8304. var shapeList = [];
  8305. var canvasWidth = this.canvasWidth;
  8306. var canvasHeight = this.canvasHeight;
  8307. for (var i = 0; i < n; i++) {
  8308. var color = effectOption.color == 'random' ? zrColor.alpha(zrColor.random(), 0.3) : effectOption.color;
  8309. shapeList[i] = new CircleShape({
  8310. highlightStyle: {
  8311. x: Math.ceil(Math.random() * canvasWidth),
  8312. y: Math.ceil(Math.random() * canvasHeight),
  8313. r: Math.ceil(Math.random() * 40),
  8314. brushType: brushType,
  8315. color: color,
  8316. strokeColor: color,
  8317. lineWidth: lineWidth
  8318. },
  8319. animationY: Math.ceil(Math.random() * 20)
  8320. });
  8321. }
  8322. return setInterval(function () {
  8323. addShapeHandle(background);
  8324. for (var i = 0; i < n; i++) {
  8325. var style = shapeList[i].highlightStyle;
  8326. if (style.y - shapeList[i].animationY + style.r <= 0) {
  8327. shapeList[i].highlightStyle.y = canvasHeight + style.r;
  8328. shapeList[i].highlightStyle.x = Math.ceil(Math.random() * canvasWidth);
  8329. }
  8330. shapeList[i].highlightStyle.y -= shapeList[i].animationY;
  8331. addShapeHandle(shapeList[i]);
  8332. }
  8333. addShapeHandle(textShape);
  8334. refreshHandle();
  8335. }, effectOption.timeInterval);
  8336. };
  8337. return Bubble;
  8338. });define('zrender/loadingEffect/DynamicLine', [
  8339. 'require',
  8340. './Base',
  8341. '../tool/util',
  8342. '../tool/color',
  8343. '../shape/Line'
  8344. ], function (require) {
  8345. var Base = require('./Base');
  8346. var util = require('../tool/util');
  8347. var zrColor = require('../tool/color');
  8348. var LineShape = require('../shape/Line');
  8349. function DynamicLine(options) {
  8350. Base.call(this, options);
  8351. }
  8352. util.inherits(DynamicLine, Base);
  8353. DynamicLine.prototype._start = function (addShapeHandle, refreshHandle) {
  8354. var options = util.merge(this.options, {
  8355. textStyle: { color: '#fff' },
  8356. backgroundColor: 'rgba(0, 0, 0, 0.8)',
  8357. effectOption: {
  8358. n: 30,
  8359. lineWidth: 1,
  8360. color: 'random',
  8361. timeInterval: 100
  8362. }
  8363. });
  8364. var textShape = this.createTextShape(options.textStyle);
  8365. var background = this.createBackgroundShape(options.backgroundColor);
  8366. var effectOption = options.effectOption;
  8367. var n = effectOption.n;
  8368. var lineWidth = effectOption.lineWidth;
  8369. var shapeList = [];
  8370. var canvasWidth = this.canvasWidth;
  8371. var canvasHeight = this.canvasHeight;
  8372. for (var i = 0; i < n; i++) {
  8373. var xStart = -Math.ceil(Math.random() * 1000);
  8374. var len = Math.ceil(Math.random() * 400);
  8375. var pos = Math.ceil(Math.random() * canvasHeight);
  8376. var color = effectOption.color == 'random' ? zrColor.random() : effectOption.color;
  8377. shapeList[i] = new LineShape({
  8378. highlightStyle: {
  8379. xStart: xStart,
  8380. yStart: pos,
  8381. xEnd: xStart + len,
  8382. yEnd: pos,
  8383. strokeColor: color,
  8384. lineWidth: lineWidth
  8385. },
  8386. animationX: Math.ceil(Math.random() * 100),
  8387. len: len
  8388. });
  8389. }
  8390. return setInterval(function () {
  8391. addShapeHandle(background);
  8392. for (var i = 0; i < n; i++) {
  8393. var style = shapeList[i].highlightStyle;
  8394. if (style.xStart >= canvasWidth) {
  8395. shapeList[i].len = Math.ceil(Math.random() * 400);
  8396. style.xStart = -400;
  8397. style.xEnd = -400 + shapeList[i].len;
  8398. style.yStart = Math.ceil(Math.random() * canvasHeight);
  8399. style.yEnd = style.yStart;
  8400. }
  8401. style.xStart += shapeList[i].animationX;
  8402. style.xEnd += shapeList[i].animationX;
  8403. addShapeHandle(shapeList[i]);
  8404. }
  8405. addShapeHandle(textShape);
  8406. refreshHandle();
  8407. }, effectOption.timeInterval);
  8408. };
  8409. return DynamicLine;
  8410. });define('zrender/loadingEffect/Ring', [
  8411. 'require',
  8412. './Base',
  8413. '../tool/util',
  8414. '../tool/color',
  8415. '../shape/Ring',
  8416. '../shape/Sector'
  8417. ], function (require) {
  8418. var Base = require('./Base');
  8419. var util = require('../tool/util');
  8420. var zrColor = require('../tool/color');
  8421. var RingShape = require('../shape/Ring');
  8422. var SectorShape = require('../shape/Sector');
  8423. function Ring(options) {
  8424. Base.call(this, options);
  8425. }
  8426. util.inherits(Ring, Base);
  8427. Ring.prototype._start = function (addShapeHandle, refreshHandle) {
  8428. var options = util.merge(this.options, {
  8429. textStyle: { color: '#07a' },
  8430. backgroundColor: 'rgba(250, 250, 250, 0.8)',
  8431. effect: {
  8432. x: this.canvasWidth / 2,
  8433. y: this.canvasHeight / 2,
  8434. r0: 60,
  8435. r: 100,
  8436. color: '#bbdcff',
  8437. brushType: 'fill',
  8438. textPosition: 'inside',
  8439. textFont: 'normal 30px verdana',
  8440. textColor: 'rgba(30, 144, 255, 0.6)',
  8441. timeInterval: 100
  8442. }
  8443. });
  8444. var effectOption = options.effect;
  8445. var textStyle = options.textStyle;
  8446. if (textStyle.x == null) {
  8447. textStyle.x = effectOption.x;
  8448. }
  8449. if (textStyle.y == null) {
  8450. textStyle.y = effectOption.y + (effectOption.r0 + effectOption.r) / 2 - 5;
  8451. }
  8452. var textShape = this.createTextShape(options.textStyle);
  8453. var background = this.createBackgroundShape(options.backgroundColor);
  8454. var x = effectOption.x;
  8455. var y = effectOption.y;
  8456. var r0 = effectOption.r0 + 6;
  8457. var r = effectOption.r - 6;
  8458. var color = effectOption.color;
  8459. var darkColor = zrColor.lift(color, 0.1);
  8460. var shapeRing = new RingShape({ highlightStyle: util.clone(effectOption) });
  8461. var shapeList = [];
  8462. var clolrList = zrColor.getGradientColors([
  8463. '#ff6400',
  8464. '#ffe100',
  8465. '#97ff00'
  8466. ], 25);
  8467. var preAngle = 15;
  8468. var endAngle = 240;
  8469. for (var i = 0; i < 16; i++) {
  8470. shapeList.push(new SectorShape({
  8471. highlightStyle: {
  8472. x: x,
  8473. y: y,
  8474. r0: r0,
  8475. r: r,
  8476. startAngle: endAngle - preAngle,
  8477. endAngle: endAngle,
  8478. brushType: 'fill',
  8479. color: darkColor
  8480. },
  8481. _color: zrColor.getLinearGradient(x + r0 * Math.cos(endAngle, true), y - r0 * Math.sin(endAngle, true), x + r0 * Math.cos(endAngle - preAngle, true), y - r0 * Math.sin(endAngle - preAngle, true), [
  8482. [
  8483. 0,
  8484. clolrList[i * 2]
  8485. ],
  8486. [
  8487. 1,
  8488. clolrList[i * 2 + 1]
  8489. ]
  8490. ])
  8491. }));
  8492. endAngle -= preAngle;
  8493. }
  8494. endAngle = 360;
  8495. for (var i = 0; i < 4; i++) {
  8496. shapeList.push(new SectorShape({
  8497. highlightStyle: {
  8498. x: x,
  8499. y: y,
  8500. r0: r0,
  8501. r: r,
  8502. startAngle: endAngle - preAngle,
  8503. endAngle: endAngle,
  8504. brushType: 'fill',
  8505. color: darkColor
  8506. },
  8507. _color: zrColor.getLinearGradient(x + r0 * Math.cos(endAngle, true), y - r0 * Math.sin(endAngle, true), x + r0 * Math.cos(endAngle - preAngle, true), y - r0 * Math.sin(endAngle - preAngle, true), [
  8508. [
  8509. 0,
  8510. clolrList[i * 2 + 32]
  8511. ],
  8512. [
  8513. 1,
  8514. clolrList[i * 2 + 33]
  8515. ]
  8516. ])
  8517. }));
  8518. endAngle -= preAngle;
  8519. }
  8520. var n = 0;
  8521. if (options.progress != null) {
  8522. addShapeHandle(background);
  8523. n = this.adjust(options.progress, [
  8524. 0,
  8525. 1
  8526. ]).toFixed(2) * 100 / 5;
  8527. shapeRing.highlightStyle.text = n * 5 + '%';
  8528. addShapeHandle(shapeRing);
  8529. for (var i = 0; i < 20; i++) {
  8530. shapeList[i].highlightStyle.color = i < n ? shapeList[i]._color : darkColor;
  8531. addShapeHandle(shapeList[i]);
  8532. }
  8533. addShapeHandle(textShape);
  8534. refreshHandle();
  8535. return;
  8536. }
  8537. return setInterval(function () {
  8538. addShapeHandle(background);
  8539. n += n >= 20 ? -20 : 1;
  8540. addShapeHandle(shapeRing);
  8541. for (var i = 0; i < 20; i++) {
  8542. shapeList[i].highlightStyle.color = i < n ? shapeList[i]._color : darkColor;
  8543. addShapeHandle(shapeList[i]);
  8544. }
  8545. addShapeHandle(textShape);
  8546. refreshHandle();
  8547. }, effectOption.timeInterval);
  8548. };
  8549. return Ring;
  8550. });define('zrender/loadingEffect/Spin', [
  8551. 'require',
  8552. './Base',
  8553. '../tool/util',
  8554. '../tool/color',
  8555. '../tool/area',
  8556. '../shape/Sector'
  8557. ], function (require) {
  8558. var Base = require('./Base');
  8559. var util = require('../tool/util');
  8560. var zrColor = require('../tool/color');
  8561. var zrArea = require('../tool/area');
  8562. var SectorShape = require('../shape/Sector');
  8563. function Spin(options) {
  8564. Base.call(this, options);
  8565. }
  8566. util.inherits(Spin, Base);
  8567. Spin.prototype._start = function (addShapeHandle, refreshHandle) {
  8568. var options = util.merge(this.options, {
  8569. textStyle: {
  8570. color: '#fff',
  8571. textAlign: 'start'
  8572. },
  8573. backgroundColor: 'rgba(0, 0, 0, 0.8)'
  8574. });
  8575. var textShape = this.createTextShape(options.textStyle);
  8576. var textGap = 10;
  8577. var textWidth = zrArea.getTextWidth(textShape.highlightStyle.text, textShape.highlightStyle.textFont);
  8578. var textHeight = zrArea.getTextHeight(textShape.highlightStyle.text, textShape.highlightStyle.textFont);
  8579. var effectOption = util.merge(this.options.effect || {}, {
  8580. r0: 9,
  8581. r: 15,
  8582. n: 18,
  8583. color: '#fff',
  8584. timeInterval: 100
  8585. });
  8586. var location = this.getLocation(this.options.textStyle, textWidth + textGap + effectOption.r * 2, Math.max(effectOption.r * 2, textHeight));
  8587. effectOption.x = location.x + effectOption.r;
  8588. effectOption.y = textShape.highlightStyle.y = location.y + location.height / 2;
  8589. textShape.highlightStyle.x = effectOption.x + effectOption.r + textGap;
  8590. var background = this.createBackgroundShape(options.backgroundColor);
  8591. var n = effectOption.n;
  8592. var x = effectOption.x;
  8593. var y = effectOption.y;
  8594. var r0 = effectOption.r0;
  8595. var r = effectOption.r;
  8596. var color = effectOption.color;
  8597. var shapeList = [];
  8598. var preAngle = Math.round(180 / n);
  8599. for (var i = 0; i < n; i++) {
  8600. shapeList[i] = new SectorShape({
  8601. highlightStyle: {
  8602. x: x,
  8603. y: y,
  8604. r0: r0,
  8605. r: r,
  8606. startAngle: preAngle * i * 2,
  8607. endAngle: preAngle * i * 2 + preAngle,
  8608. color: zrColor.alpha(color, (i + 1) / n),
  8609. brushType: 'fill'
  8610. }
  8611. });
  8612. }
  8613. var pos = [
  8614. 0,
  8615. x,
  8616. y
  8617. ];
  8618. return setInterval(function () {
  8619. addShapeHandle(background);
  8620. pos[0] -= 0.3;
  8621. for (var i = 0; i < n; i++) {
  8622. shapeList[i].rotation = pos;
  8623. addShapeHandle(shapeList[i]);
  8624. }
  8625. addShapeHandle(textShape);
  8626. refreshHandle();
  8627. }, effectOption.timeInterval);
  8628. };
  8629. return Spin;
  8630. });define('zrender/loadingEffect/Whirling', [
  8631. 'require',
  8632. './Base',
  8633. '../tool/util',
  8634. '../tool/area',
  8635. '../shape/Ring',
  8636. '../shape/Droplet',
  8637. '../shape/Circle'
  8638. ], function (require) {
  8639. var Base = require('./Base');
  8640. var util = require('../tool/util');
  8641. var zrArea = require('../tool/area');
  8642. var RingShape = require('../shape/Ring');
  8643. var DropletShape = require('../shape/Droplet');
  8644. var CircleShape = require('../shape/Circle');
  8645. function Whirling(options) {
  8646. Base.call(this, options);
  8647. }
  8648. util.inherits(Whirling, Base);
  8649. Whirling.prototype._start = function (addShapeHandle, refreshHandle) {
  8650. var options = util.merge(this.options, {
  8651. textStyle: {
  8652. color: '#888',
  8653. textAlign: 'start'
  8654. },
  8655. backgroundColor: 'rgba(250, 250, 250, 0.8)'
  8656. });
  8657. var textShape = this.createTextShape(options.textStyle);
  8658. var textGap = 10;
  8659. var textWidth = zrArea.getTextWidth(textShape.highlightStyle.text, textShape.highlightStyle.textFont);
  8660. var textHeight = zrArea.getTextHeight(textShape.highlightStyle.text, textShape.highlightStyle.textFont);
  8661. var effectOption = util.merge(this.options.effect || {}, {
  8662. r: 18,
  8663. colorIn: '#fff',
  8664. colorOut: '#555',
  8665. colorWhirl: '#6cf',
  8666. timeInterval: 50
  8667. });
  8668. var location = this.getLocation(this.options.textStyle, textWidth + textGap + effectOption.r * 2, Math.max(effectOption.r * 2, textHeight));
  8669. effectOption.x = location.x + effectOption.r;
  8670. effectOption.y = textShape.highlightStyle.y = location.y + location.height / 2;
  8671. textShape.highlightStyle.x = effectOption.x + effectOption.r + textGap;
  8672. var background = this.createBackgroundShape(options.backgroundColor);
  8673. var droplet = new DropletShape({
  8674. highlightStyle: {
  8675. a: Math.round(effectOption.r / 2),
  8676. b: Math.round(effectOption.r - effectOption.r / 6),
  8677. brushType: 'fill',
  8678. color: effectOption.colorWhirl
  8679. }
  8680. });
  8681. var circleIn = new CircleShape({
  8682. highlightStyle: {
  8683. r: Math.round(effectOption.r / 6),
  8684. brushType: 'fill',
  8685. color: effectOption.colorIn
  8686. }
  8687. });
  8688. var circleOut = new RingShape({
  8689. highlightStyle: {
  8690. r0: Math.round(effectOption.r - effectOption.r / 3),
  8691. r: effectOption.r,
  8692. brushType: 'fill',
  8693. color: effectOption.colorOut
  8694. }
  8695. });
  8696. var pos = [
  8697. 0,
  8698. effectOption.x,
  8699. effectOption.y
  8700. ];
  8701. droplet.highlightStyle.x = circleIn.highlightStyle.x = circleOut.highlightStyle.x = pos[1];
  8702. droplet.highlightStyle.y = circleIn.highlightStyle.y = circleOut.highlightStyle.y = pos[2];
  8703. return setInterval(function () {
  8704. addShapeHandle(background);
  8705. addShapeHandle(circleOut);
  8706. pos[0] -= 0.3;
  8707. droplet.rotation = pos;
  8708. addShapeHandle(droplet);
  8709. addShapeHandle(circleIn);
  8710. addShapeHandle(textShape);
  8711. refreshHandle();
  8712. }, effectOption.timeInterval);
  8713. };
  8714. return Whirling;
  8715. });define('echarts/theme/macarons', [], function () {
  8716. var theme = {
  8717. color: [
  8718. '#2ec7c9',
  8719. '#b6a2de',
  8720. '#5ab1ef',
  8721. '#ffb980',
  8722. '#d87a80',
  8723. '#8d98b3',
  8724. '#e5cf0d',
  8725. '#97b552',
  8726. '#95706d',
  8727. '#dc69aa',
  8728. '#07a2a4',
  8729. '#9a7fd1',
  8730. '#588dd5',
  8731. '#f5994e',
  8732. '#c05050',
  8733. '#59678c',
  8734. '#c9ab00',
  8735. '#7eb00a',
  8736. '#6f5553',
  8737. '#c14089'
  8738. ],
  8739. title: {
  8740. textStyle: {
  8741. fontWeight: 'normal',
  8742. color: '#008acd'
  8743. }
  8744. },
  8745. dataRange: {
  8746. itemWidth: 15,
  8747. color: [
  8748. '#5ab1ef',
  8749. '#e0ffff'
  8750. ]
  8751. },
  8752. toolbox: {
  8753. color: [
  8754. '#1e90ff',
  8755. '#1e90ff',
  8756. '#1e90ff',
  8757. '#1e90ff'
  8758. ],
  8759. effectiveColor: '#ff4500'
  8760. },
  8761. tooltip: {
  8762. backgroundColor: 'rgba(50,50,50,0.5)',
  8763. axisPointer: {
  8764. type: 'line',
  8765. lineStyle: { color: '#008acd' },
  8766. crossStyle: { color: '#008acd' },
  8767. shadowStyle: { color: 'rgba(200,200,200,0.2)' }
  8768. }
  8769. },
  8770. dataZoom: {
  8771. dataBackgroundColor: '#efefff',
  8772. fillerColor: 'rgba(182,162,222,0.2)',
  8773. handleColor: '#008acd'
  8774. },
  8775. grid: { borderColor: '#eee' },
  8776. categoryAxis: {
  8777. axisLine: { lineStyle: { color: '#008acd' } },
  8778. splitLine: { lineStyle: { color: ['#eee'] } }
  8779. },
  8780. valueAxis: {
  8781. axisLine: { lineStyle: { color: '#008acd' } },
  8782. splitArea: {
  8783. show: true,
  8784. areaStyle: {
  8785. color: [
  8786. 'rgba(250,250,250,0.1)',
  8787. 'rgba(200,200,200,0.1)'
  8788. ]
  8789. }
  8790. },
  8791. splitLine: { lineStyle: { color: ['#eee'] } }
  8792. },
  8793. polar: {
  8794. axisLine: { lineStyle: { color: '#ddd' } },
  8795. splitArea: {
  8796. show: true,
  8797. areaStyle: {
  8798. color: [
  8799. 'rgba(250,250,250,0.2)',
  8800. 'rgba(200,200,200,0.2)'
  8801. ]
  8802. }
  8803. },
  8804. splitLine: { lineStyle: { color: '#ddd' } }
  8805. },
  8806. timeline: {
  8807. lineStyle: { color: '#008acd' },
  8808. controlStyle: {
  8809. normal: { color: '#008acd' },
  8810. emphasis: { color: '#008acd' }
  8811. },
  8812. symbol: 'emptyCircle',
  8813. symbolSize: 3
  8814. },
  8815. bar: {
  8816. itemStyle: {
  8817. normal: { barBorderRadius: 5 },
  8818. emphasis: { barBorderRadius: 5 }
  8819. }
  8820. },
  8821. line: {
  8822. smooth: true,
  8823. symbol: 'emptyCircle',
  8824. symbolSize: 3
  8825. },
  8826. k: {
  8827. itemStyle: {
  8828. normal: {
  8829. color: '#d87a80',
  8830. color0: '#2ec7c9',
  8831. lineStyle: {
  8832. color: '#d87a80',
  8833. color0: '#2ec7c9'
  8834. }
  8835. }
  8836. }
  8837. },
  8838. scatter: {
  8839. symbol: 'circle',
  8840. symbolSize: 4
  8841. },
  8842. radar: {
  8843. symbol: 'emptyCircle',
  8844. symbolSize: 3
  8845. },
  8846. map: {
  8847. itemStyle: {
  8848. normal: {
  8849. areaStyle: { color: '#ddd' },
  8850. label: { textStyle: { color: '#d87a80' } }
  8851. },
  8852. emphasis: { areaStyle: { color: '#fe994e' } }
  8853. }
  8854. },
  8855. force: { itemStyle: { normal: { linkStyle: { color: '#1e90ff' } } } },
  8856. chord: {
  8857. itemStyle: {
  8858. normal: {
  8859. borderWidth: 1,
  8860. borderColor: 'rgba(128, 128, 128, 0.5)',
  8861. chordStyle: { lineStyle: { color: 'rgba(128, 128, 128, 0.5)' } }
  8862. },
  8863. emphasis: {
  8864. borderWidth: 1,
  8865. borderColor: 'rgba(128, 128, 128, 0.5)',
  8866. chordStyle: { lineStyle: { color: 'rgba(128, 128, 128, 0.5)' } }
  8867. }
  8868. }
  8869. },
  8870. gauge: {
  8871. axisLine: {
  8872. lineStyle: {
  8873. color: [
  8874. [
  8875. 0.2,
  8876. '#2ec7c9'
  8877. ],
  8878. [
  8879. 0.8,
  8880. '#5ab1ef'
  8881. ],
  8882. [
  8883. 1,
  8884. '#d87a80'
  8885. ]
  8886. ],
  8887. width: 10
  8888. }
  8889. },
  8890. axisTick: {
  8891. splitNumber: 10,
  8892. length: 15,
  8893. lineStyle: { color: 'auto' }
  8894. },
  8895. splitLine: {
  8896. length: 22,
  8897. lineStyle: { color: 'auto' }
  8898. },
  8899. pointer: { width: 5 }
  8900. },
  8901. textStyle: { fontFamily: '微软雅黑, Arial, Verdana, sans-serif' }
  8902. };
  8903. return theme;
  8904. });define('echarts/theme/infographic', [], function () {
  8905. var theme = {
  8906. color: [
  8907. '#C1232B',
  8908. '#B5C334',
  8909. '#FCCE10',
  8910. '#E87C25',
  8911. '#27727B',
  8912. '#FE8463',
  8913. '#9BCA63',
  8914. '#FAD860',
  8915. '#F3A43B',
  8916. '#60C0DD',
  8917. '#D7504B',
  8918. '#C6E579',
  8919. '#F4E001',
  8920. '#F0805A',
  8921. '#26C0C0'
  8922. ],
  8923. title: {
  8924. textStyle: {
  8925. fontWeight: 'normal',
  8926. color: '#27727B'
  8927. }
  8928. },
  8929. dataRange: {
  8930. x: 'right',
  8931. y: 'center',
  8932. itemWidth: 5,
  8933. itemHeight: 25,
  8934. color: [
  8935. '#C1232B',
  8936. '#FCCE10'
  8937. ]
  8938. },
  8939. toolbox: {
  8940. color: [
  8941. '#C1232B',
  8942. '#B5C334',
  8943. '#FCCE10',
  8944. '#E87C25',
  8945. '#27727B',
  8946. '#FE8463',
  8947. '#9BCA63',
  8948. '#FAD860',
  8949. '#F3A43B',
  8950. '#60C0DD'
  8951. ],
  8952. effectiveColor: '#ff4500'
  8953. },
  8954. tooltip: {
  8955. backgroundColor: 'rgba(50,50,50,0.5)',
  8956. axisPointer: {
  8957. type: 'line',
  8958. lineStyle: {
  8959. color: '#27727B',
  8960. type: 'dashed'
  8961. },
  8962. crossStyle: { color: '#27727B' },
  8963. shadowStyle: { color: 'rgba(200,200,200,0.3)' }
  8964. }
  8965. },
  8966. dataZoom: {
  8967. dataBackgroundColor: 'rgba(181,195,52,0.3)',
  8968. fillerColor: 'rgba(181,195,52,0.2)',
  8969. handleColor: '#27727B'
  8970. },
  8971. grid: { borderWidth: 0 },
  8972. categoryAxis: {
  8973. axisLine: { lineStyle: { color: '#27727B' } },
  8974. splitLine: { show: false }
  8975. },
  8976. valueAxis: {
  8977. axisLine: { show: false },
  8978. splitArea: { show: false },
  8979. splitLine: {
  8980. lineStyle: {
  8981. color: ['#ccc'],
  8982. type: 'dashed'
  8983. }
  8984. }
  8985. },
  8986. polar: {
  8987. axisLine: { lineStyle: { color: '#ddd' } },
  8988. splitArea: {
  8989. show: true,
  8990. areaStyle: {
  8991. color: [
  8992. 'rgba(250,250,250,0.2)',
  8993. 'rgba(200,200,200,0.2)'
  8994. ]
  8995. }
  8996. },
  8997. splitLine: { lineStyle: { color: '#ddd' } }
  8998. },
  8999. timeline: {
  9000. lineStyle: { color: '#27727B' },
  9001. controlStyle: {
  9002. normal: { color: '#27727B' },
  9003. emphasis: { color: '#27727B' }
  9004. },
  9005. symbol: 'emptyCircle',
  9006. symbolSize: 3
  9007. },
  9008. line: {
  9009. itemStyle: {
  9010. normal: {
  9011. borderWidth: 2,
  9012. borderColor: '#fff',
  9013. lineStyle: { width: 3 }
  9014. },
  9015. emphasis: { borderWidth: 0 }
  9016. },
  9017. symbol: 'circle',
  9018. symbolSize: 3.5
  9019. },
  9020. k: {
  9021. itemStyle: {
  9022. normal: {
  9023. color: '#C1232B',
  9024. color0: '#B5C334',
  9025. lineStyle: {
  9026. width: 1,
  9027. color: '#C1232B',
  9028. color0: '#B5C334'
  9029. }
  9030. }
  9031. }
  9032. },
  9033. scatter: {
  9034. itemStyle: {
  9035. normal: {
  9036. borderWidth: 1,
  9037. borderColor: 'rgba(200,200,200,0.5)'
  9038. },
  9039. emphasis: { borderWidth: 0 }
  9040. },
  9041. symbol: 'star4',
  9042. symbolSize: 4
  9043. },
  9044. radar: {
  9045. symbol: 'emptyCircle',
  9046. symbolSize: 3
  9047. },
  9048. map: {
  9049. itemStyle: {
  9050. normal: {
  9051. areaStyle: { color: '#ddd' },
  9052. label: { textStyle: { color: '#C1232B' } }
  9053. },
  9054. emphasis: {
  9055. areaStyle: { color: '#fe994e' },
  9056. label: { textStyle: { color: 'rgb(100,0,0)' } }
  9057. }
  9058. }
  9059. },
  9060. force: { itemStyle: { normal: { linkStyle: { color: '#27727B' } } } },
  9061. chord: {
  9062. itemStyle: {
  9063. normal: {
  9064. borderWidth: 1,
  9065. borderColor: 'rgba(128, 128, 128, 0.5)',
  9066. chordStyle: { lineStyle: { color: 'rgba(128, 128, 128, 0.5)' } }
  9067. },
  9068. emphasis: {
  9069. borderWidth: 1,
  9070. borderColor: 'rgba(128, 128, 128, 0.5)',
  9071. chordStyle: { lineStyle: { color: 'rgba(128, 128, 128, 0.5)' } }
  9072. }
  9073. }
  9074. },
  9075. gauge: {
  9076. center: [
  9077. '50%',
  9078. '80%'
  9079. ],
  9080. radius: '100%',
  9081. startAngle: 180,
  9082. endAngle: 0,
  9083. axisLine: {
  9084. show: true,
  9085. lineStyle: {
  9086. color: [
  9087. [
  9088. 0.2,
  9089. '#B5C334'
  9090. ],
  9091. [
  9092. 0.8,
  9093. '#27727B'
  9094. ],
  9095. [
  9096. 1,
  9097. '#C1232B'
  9098. ]
  9099. ],
  9100. width: '40%'
  9101. }
  9102. },
  9103. axisTick: {
  9104. splitNumber: 2,
  9105. length: 5,
  9106. lineStyle: { color: '#fff' }
  9107. },
  9108. axisLabel: {
  9109. textStyle: {
  9110. color: '#fff',
  9111. fontWeight: 'bolder'
  9112. }
  9113. },
  9114. splitLine: {
  9115. length: '5%',
  9116. lineStyle: { color: '#fff' }
  9117. },
  9118. pointer: {
  9119. width: '40%',
  9120. length: '80%',
  9121. color: '#fff'
  9122. },
  9123. title: {
  9124. offsetCenter: [
  9125. 0,
  9126. -20
  9127. ],
  9128. textStyle: {
  9129. color: 'auto',
  9130. fontSize: 20
  9131. }
  9132. },
  9133. detail: {
  9134. offsetCenter: [
  9135. 0,
  9136. 0
  9137. ],
  9138. textStyle: {
  9139. color: 'auto',
  9140. fontSize: 40
  9141. }
  9142. }
  9143. },
  9144. textStyle: { fontFamily: '微软雅黑, Arial, Verdana, sans-serif' }
  9145. };
  9146. return theme;
  9147. });define('zrender/dep/excanvas', ['require'], function (require) {
  9148. if (!document.createElement('canvas').getContext) {
  9149. (function () {
  9150. var m = Math;
  9151. var mr = m.round;
  9152. var ms = m.sin;
  9153. var mc = m.cos;
  9154. var abs = m.abs;
  9155. var sqrt = m.sqrt;
  9156. var Z = 10;
  9157. var Z2 = Z / 2;
  9158. var IE_VERSION = +navigator.userAgent.match(/MSIE ([\d.]+)?/)[1];
  9159. function getContext() {
  9160. return this.context_ || (this.context_ = new CanvasRenderingContext2D_(this));
  9161. }
  9162. var slice = Array.prototype.slice;
  9163. function bind(f, obj, var_args) {
  9164. var a = slice.call(arguments, 2);
  9165. return function () {
  9166. return f.apply(obj, a.concat(slice.call(arguments)));
  9167. };
  9168. }
  9169. function encodeHtmlAttribute(s) {
  9170. return String(s).replace(/&/g, '&amp;').replace(/"/g, '&quot;');
  9171. }
  9172. function addNamespace(doc, prefix, urn) {
  9173. if (!doc.namespaces[prefix]) {
  9174. doc.namespaces.add(prefix, urn, '#default#VML');
  9175. }
  9176. }
  9177. function addNamespacesAndStylesheet(doc) {
  9178. addNamespace(doc, 'g_vml_', 'urn:schemas-microsoft-com:vml');
  9179. addNamespace(doc, 'g_o_', 'urn:schemas-microsoft-com:office:office');
  9180. if (!doc.styleSheets['ex_canvas_']) {
  9181. var ss = doc.createStyleSheet();
  9182. ss.owningElement.id = 'ex_canvas_';
  9183. ss.cssText = 'canvas{display:inline-block;overflow:hidden;' + 'text-align:left;width:300px;height:150px}';
  9184. }
  9185. }
  9186. addNamespacesAndStylesheet(document);
  9187. var G_vmlCanvasManager_ = {
  9188. init: function (opt_doc) {
  9189. var doc = opt_doc || document;
  9190. doc.createElement('canvas');
  9191. doc.attachEvent('onreadystatechange', bind(this.init_, this, doc));
  9192. },
  9193. init_: function (doc) {
  9194. var els = doc.getElementsByTagName('canvas');
  9195. for (var i = 0; i < els.length; i++) {
  9196. this.initElement(els[i]);
  9197. }
  9198. },
  9199. initElement: function (el) {
  9200. if (!el.getContext) {
  9201. el.getContext = getContext;
  9202. addNamespacesAndStylesheet(el.ownerDocument);
  9203. el.innerHTML = '';
  9204. el.attachEvent('onpropertychange', onPropertyChange);
  9205. el.attachEvent('onresize', onResize);
  9206. var attrs = el.attributes;
  9207. if (attrs.width && attrs.width.specified) {
  9208. el.style.width = attrs.width.nodeValue + 'px';
  9209. } else {
  9210. el.width = el.clientWidth;
  9211. }
  9212. if (attrs.height && attrs.height.specified) {
  9213. el.style.height = attrs.height.nodeValue + 'px';
  9214. } else {
  9215. el.height = el.clientHeight;
  9216. }
  9217. }
  9218. return el;
  9219. }
  9220. };
  9221. function onPropertyChange(e) {
  9222. var el = e.srcElement;
  9223. switch (e.propertyName) {
  9224. case 'width':
  9225. el.getContext().clearRect();
  9226. el.style.width = el.attributes.width.nodeValue + 'px';
  9227. el.firstChild.style.width = el.clientWidth + 'px';
  9228. break;
  9229. case 'height':
  9230. el.getContext().clearRect();
  9231. el.style.height = el.attributes.height.nodeValue + 'px';
  9232. el.firstChild.style.height = el.clientHeight + 'px';
  9233. break;
  9234. }
  9235. }
  9236. function onResize(e) {
  9237. var el = e.srcElement;
  9238. if (el.firstChild) {
  9239. el.firstChild.style.width = el.clientWidth + 'px';
  9240. el.firstChild.style.height = el.clientHeight + 'px';
  9241. }
  9242. }
  9243. G_vmlCanvasManager_.init();
  9244. var decToHex = [];
  9245. for (var i = 0; i < 16; i++) {
  9246. for (var j = 0; j < 16; j++) {
  9247. decToHex[i * 16 + j] = i.toString(16) + j.toString(16);
  9248. }
  9249. }
  9250. function createMatrixIdentity() {
  9251. return [
  9252. [
  9253. 1,
  9254. 0,
  9255. 0
  9256. ],
  9257. [
  9258. 0,
  9259. 1,
  9260. 0
  9261. ],
  9262. [
  9263. 0,
  9264. 0,
  9265. 1
  9266. ]
  9267. ];
  9268. }
  9269. function matrixMultiply(m1, m2) {
  9270. var result = createMatrixIdentity();
  9271. for (var x = 0; x < 3; x++) {
  9272. for (var y = 0; y < 3; y++) {
  9273. var sum = 0;
  9274. for (var z = 0; z < 3; z++) {
  9275. sum += m1[x][z] * m2[z][y];
  9276. }
  9277. result[x][y] = sum;
  9278. }
  9279. }
  9280. return result;
  9281. }
  9282. function copyState(o1, o2) {
  9283. o2.fillStyle = o1.fillStyle;
  9284. o2.lineCap = o1.lineCap;
  9285. o2.lineJoin = o1.lineJoin;
  9286. o2.lineWidth = o1.lineWidth;
  9287. o2.miterLimit = o1.miterLimit;
  9288. o2.shadowBlur = o1.shadowBlur;
  9289. o2.shadowColor = o1.shadowColor;
  9290. o2.shadowOffsetX = o1.shadowOffsetX;
  9291. o2.shadowOffsetY = o1.shadowOffsetY;
  9292. o2.strokeStyle = o1.strokeStyle;
  9293. o2.globalAlpha = o1.globalAlpha;
  9294. o2.font = o1.font;
  9295. o2.textAlign = o1.textAlign;
  9296. o2.textBaseline = o1.textBaseline;
  9297. o2.scaleX_ = o1.scaleX_;
  9298. o2.scaleY_ = o1.scaleY_;
  9299. o2.lineScale_ = o1.lineScale_;
  9300. }
  9301. var colorData = {
  9302. aliceblue: '#F0F8FF',
  9303. antiquewhite: '#FAEBD7',
  9304. aquamarine: '#7FFFD4',
  9305. azure: '#F0FFFF',
  9306. beige: '#F5F5DC',
  9307. bisque: '#FFE4C4',
  9308. black: '#000000',
  9309. blanchedalmond: '#FFEBCD',
  9310. blueviolet: '#8A2BE2',
  9311. brown: '#A52A2A',
  9312. burlywood: '#DEB887',
  9313. cadetblue: '#5F9EA0',
  9314. chartreuse: '#7FFF00',
  9315. chocolate: '#D2691E',
  9316. coral: '#FF7F50',
  9317. cornflowerblue: '#6495ED',
  9318. cornsilk: '#FFF8DC',
  9319. crimson: '#DC143C',
  9320. cyan: '#00FFFF',
  9321. darkblue: '#00008B',
  9322. darkcyan: '#008B8B',
  9323. darkgoldenrod: '#B8860B',
  9324. darkgray: '#A9A9A9',
  9325. darkgreen: '#006400',
  9326. darkgrey: '#A9A9A9',
  9327. darkkhaki: '#BDB76B',
  9328. darkmagenta: '#8B008B',
  9329. darkolivegreen: '#556B2F',
  9330. darkorange: '#FF8C00',
  9331. darkorchid: '#9932CC',
  9332. darkred: '#8B0000',
  9333. darksalmon: '#E9967A',
  9334. darkseagreen: '#8FBC8F',
  9335. darkslateblue: '#483D8B',
  9336. darkslategray: '#2F4F4F',
  9337. darkslategrey: '#2F4F4F',
  9338. darkturquoise: '#00CED1',
  9339. darkviolet: '#9400D3',
  9340. deeppink: '#FF1493',
  9341. deepskyblue: '#00BFFF',
  9342. dimgray: '#696969',
  9343. dimgrey: '#696969',
  9344. dodgerblue: '#1E90FF',
  9345. firebrick: '#B22222',
  9346. floralwhite: '#FFFAF0',
  9347. forestgreen: '#228B22',
  9348. gainsboro: '#DCDCDC',
  9349. ghostwhite: '#F8F8FF',
  9350. gold: '#FFD700',
  9351. goldenrod: '#DAA520',
  9352. grey: '#808080',
  9353. greenyellow: '#ADFF2F',
  9354. honeydew: '#F0FFF0',
  9355. hotpink: '#FF69B4',
  9356. indianred: '#CD5C5C',
  9357. indigo: '#4B0082',
  9358. ivory: '#FFFFF0',
  9359. khaki: '#F0E68C',
  9360. lavender: '#E6E6FA',
  9361. lavenderblush: '#FFF0F5',
  9362. lawngreen: '#7CFC00',
  9363. lemonchiffon: '#FFFACD',
  9364. lightblue: '#ADD8E6',
  9365. lightcoral: '#F08080',
  9366. lightcyan: '#E0FFFF',
  9367. lightgoldenrodyellow: '#FAFAD2',
  9368. lightgreen: '#90EE90',
  9369. lightgrey: '#D3D3D3',
  9370. lightpink: '#FFB6C1',
  9371. lightsalmon: '#FFA07A',
  9372. lightseagreen: '#20B2AA',
  9373. lightskyblue: '#87CEFA',
  9374. lightslategray: '#778899',
  9375. lightslategrey: '#778899',
  9376. lightsteelblue: '#B0C4DE',
  9377. lightyellow: '#FFFFE0',
  9378. limegreen: '#32CD32',
  9379. linen: '#FAF0E6',
  9380. magenta: '#FF00FF',
  9381. mediumaquamarine: '#66CDAA',
  9382. mediumblue: '#0000CD',
  9383. mediumorchid: '#BA55D3',
  9384. mediumpurple: '#9370DB',
  9385. mediumseagreen: '#3CB371',
  9386. mediumslateblue: '#7B68EE',
  9387. mediumspringgreen: '#00FA9A',
  9388. mediumturquoise: '#48D1CC',
  9389. mediumvioletred: '#C71585',
  9390. midnightblue: '#191970',
  9391. mintcream: '#F5FFFA',
  9392. mistyrose: '#FFE4E1',
  9393. moccasin: '#FFE4B5',
  9394. navajowhite: '#FFDEAD',
  9395. oldlace: '#FDF5E6',
  9396. olivedrab: '#6B8E23',
  9397. orange: '#FFA500',
  9398. orangered: '#FF4500',
  9399. orchid: '#DA70D6',
  9400. palegoldenrod: '#EEE8AA',
  9401. palegreen: '#98FB98',
  9402. paleturquoise: '#AFEEEE',
  9403. palevioletred: '#DB7093',
  9404. papayawhip: '#FFEFD5',
  9405. peachpuff: '#FFDAB9',
  9406. peru: '#CD853F',
  9407. pink: '#FFC0CB',
  9408. plum: '#DDA0DD',
  9409. powderblue: '#B0E0E6',
  9410. rosybrown: '#BC8F8F',
  9411. royalblue: '#4169E1',
  9412. saddlebrown: '#8B4513',
  9413. salmon: '#FA8072',
  9414. sandybrown: '#F4A460',
  9415. seagreen: '#2E8B57',
  9416. seashell: '#FFF5EE',
  9417. sienna: '#A0522D',
  9418. skyblue: '#87CEEB',
  9419. slateblue: '#6A5ACD',
  9420. slategray: '#708090',
  9421. slategrey: '#708090',
  9422. snow: '#FFFAFA',
  9423. springgreen: '#00FF7F',
  9424. steelblue: '#4682B4',
  9425. tan: '#D2B48C',
  9426. thistle: '#D8BFD8',
  9427. tomato: '#FF6347',
  9428. turquoise: '#40E0D0',
  9429. violet: '#EE82EE',
  9430. wheat: '#F5DEB3',
  9431. whitesmoke: '#F5F5F5',
  9432. yellowgreen: '#9ACD32'
  9433. };
  9434. function getRgbHslContent(styleString) {
  9435. var start = styleString.indexOf('(', 3);
  9436. var end = styleString.indexOf(')', start + 1);
  9437. var parts = styleString.substring(start + 1, end).split(',');
  9438. if (parts.length != 4 || styleString.charAt(3) != 'a') {
  9439. parts[3] = 1;
  9440. }
  9441. return parts;
  9442. }
  9443. function percent(s) {
  9444. return parseFloat(s) / 100;
  9445. }
  9446. function clamp(v, min, max) {
  9447. return Math.min(max, Math.max(min, v));
  9448. }
  9449. function hslToRgb(parts) {
  9450. var r, g, b, h, s, l;
  9451. h = parseFloat(parts[0]) / 360 % 360;
  9452. if (h < 0)
  9453. h++;
  9454. s = clamp(percent(parts[1]), 0, 1);
  9455. l = clamp(percent(parts[2]), 0, 1);
  9456. if (s == 0) {
  9457. r = g = b = l;
  9458. } else {
  9459. var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
  9460. var p = 2 * l - q;
  9461. r = hueToRgb(p, q, h + 1 / 3);
  9462. g = hueToRgb(p, q, h);
  9463. b = hueToRgb(p, q, h - 1 / 3);
  9464. }
  9465. return '#' + decToHex[Math.floor(r * 255)] + decToHex[Math.floor(g * 255)] + decToHex[Math.floor(b * 255)];
  9466. }
  9467. function hueToRgb(m1, m2, h) {
  9468. if (h < 0)
  9469. h++;
  9470. if (h > 1)
  9471. h--;
  9472. if (6 * h < 1)
  9473. return m1 + (m2 - m1) * 6 * h;
  9474. else if (2 * h < 1)
  9475. return m2;
  9476. else if (3 * h < 2)
  9477. return m1 + (m2 - m1) * (2 / 3 - h) * 6;
  9478. else
  9479. return m1;
  9480. }
  9481. var processStyleCache = {};
  9482. function processStyle(styleString) {
  9483. if (styleString in processStyleCache) {
  9484. return processStyleCache[styleString];
  9485. }
  9486. var str, alpha = 1;
  9487. styleString = String(styleString);
  9488. if (styleString.charAt(0) == '#') {
  9489. str = styleString;
  9490. } else if (/^rgb/.test(styleString)) {
  9491. var parts = getRgbHslContent(styleString);
  9492. var str = '#', n;
  9493. for (var i = 0; i < 3; i++) {
  9494. if (parts[i].indexOf('%') != -1) {
  9495. n = Math.floor(percent(parts[i]) * 255);
  9496. } else {
  9497. n = +parts[i];
  9498. }
  9499. str += decToHex[clamp(n, 0, 255)];
  9500. }
  9501. alpha = +parts[3];
  9502. } else if (/^hsl/.test(styleString)) {
  9503. var parts = getRgbHslContent(styleString);
  9504. str = hslToRgb(parts);
  9505. alpha = parts[3];
  9506. } else {
  9507. str = colorData[styleString] || styleString;
  9508. }
  9509. return processStyleCache[styleString] = {
  9510. color: str,
  9511. alpha: alpha
  9512. };
  9513. }
  9514. var DEFAULT_STYLE = {
  9515. style: 'normal',
  9516. variant: 'normal',
  9517. weight: 'normal',
  9518. size: 12,
  9519. family: '微软雅黑'
  9520. };
  9521. var fontStyleCache = {};
  9522. function processFontStyle(styleString) {
  9523. if (fontStyleCache[styleString]) {
  9524. return fontStyleCache[styleString];
  9525. }
  9526. var el = document.createElement('div');
  9527. var style = el.style;
  9528. var fontFamily;
  9529. try {
  9530. style.font = styleString;
  9531. fontFamily = style.fontFamily.split(',')[0];
  9532. } catch (ex) {
  9533. }
  9534. return fontStyleCache[styleString] = {
  9535. style: style.fontStyle || DEFAULT_STYLE.style,
  9536. variant: style.fontVariant || DEFAULT_STYLE.variant,
  9537. weight: style.fontWeight || DEFAULT_STYLE.weight,
  9538. size: style.fontSize || DEFAULT_STYLE.size,
  9539. family: fontFamily || DEFAULT_STYLE.family
  9540. };
  9541. }
  9542. function getComputedStyle(style, element) {
  9543. var computedStyle = {};
  9544. for (var p in style) {
  9545. computedStyle[p] = style[p];
  9546. }
  9547. var canvasFontSize = parseFloat(element.currentStyle.fontSize), fontSize = parseFloat(style.size);
  9548. if (typeof style.size == 'number') {
  9549. computedStyle.size = style.size;
  9550. } else if (style.size.indexOf('px') != -1) {
  9551. computedStyle.size = fontSize;
  9552. } else if (style.size.indexOf('em') != -1) {
  9553. computedStyle.size = canvasFontSize * fontSize;
  9554. } else if (style.size.indexOf('%') != -1) {
  9555. computedStyle.size = canvasFontSize / 100 * fontSize;
  9556. } else if (style.size.indexOf('pt') != -1) {
  9557. computedStyle.size = fontSize / 0.75;
  9558. } else {
  9559. computedStyle.size = canvasFontSize;
  9560. }
  9561. return computedStyle;
  9562. }
  9563. function buildStyle(style) {
  9564. return style.style + ' ' + style.variant + ' ' + style.weight + ' ' + style.size + 'px \'' + style.family + '\'';
  9565. }
  9566. var lineCapMap = {
  9567. 'butt': 'flat',
  9568. 'round': 'round'
  9569. };
  9570. function processLineCap(lineCap) {
  9571. return lineCapMap[lineCap] || 'square';
  9572. }
  9573. function CanvasRenderingContext2D_(canvasElement) {
  9574. this.m_ = createMatrixIdentity();
  9575. this.mStack_ = [];
  9576. this.aStack_ = [];
  9577. this.currentPath_ = [];
  9578. this.strokeStyle = '#000';
  9579. this.fillStyle = '#000';
  9580. this.lineWidth = 1;
  9581. this.lineJoin = 'miter';
  9582. this.lineCap = 'butt';
  9583. this.miterLimit = Z * 1;
  9584. this.globalAlpha = 1;
  9585. this.font = '12px 微软雅黑';
  9586. this.textAlign = 'left';
  9587. this.textBaseline = 'alphabetic';
  9588. this.canvas = canvasElement;
  9589. var cssText = 'width:' + canvasElement.clientWidth + 'px;height:' + canvasElement.clientHeight + 'px;overflow:hidden;position:absolute';
  9590. var el = canvasElement.ownerDocument.createElement('div');
  9591. el.style.cssText = cssText;
  9592. canvasElement.appendChild(el);
  9593. var overlayEl = el.cloneNode(false);
  9594. overlayEl.style.backgroundColor = '#fff';
  9595. overlayEl.style.filter = 'alpha(opacity=0)';
  9596. canvasElement.appendChild(overlayEl);
  9597. this.element_ = el;
  9598. this.scaleX_ = 1;
  9599. this.scaleY_ = 1;
  9600. this.lineScale_ = 1;
  9601. }
  9602. var contextPrototype = CanvasRenderingContext2D_.prototype;
  9603. contextPrototype.clearRect = function () {
  9604. if (this.textMeasureEl_) {
  9605. this.textMeasureEl_.removeNode(true);
  9606. this.textMeasureEl_ = null;
  9607. }
  9608. this.element_.innerHTML = '';
  9609. };
  9610. contextPrototype.beginPath = function () {
  9611. this.currentPath_ = [];
  9612. };
  9613. contextPrototype.moveTo = function (aX, aY) {
  9614. var p = getCoords(this, aX, aY);
  9615. this.currentPath_.push({
  9616. type: 'moveTo',
  9617. x: p.x,
  9618. y: p.y
  9619. });
  9620. this.currentX_ = p.x;
  9621. this.currentY_ = p.y;
  9622. };
  9623. contextPrototype.lineTo = function (aX, aY) {
  9624. var p = getCoords(this, aX, aY);
  9625. this.currentPath_.push({
  9626. type: 'lineTo',
  9627. x: p.x,
  9628. y: p.y
  9629. });
  9630. this.currentX_ = p.x;
  9631. this.currentY_ = p.y;
  9632. };
  9633. contextPrototype.bezierCurveTo = function (aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  9634. var p = getCoords(this, aX, aY);
  9635. var cp1 = getCoords(this, aCP1x, aCP1y);
  9636. var cp2 = getCoords(this, aCP2x, aCP2y);
  9637. bezierCurveTo(this, cp1, cp2, p);
  9638. };
  9639. function bezierCurveTo(self, cp1, cp2, p) {
  9640. self.currentPath_.push({
  9641. type: 'bezierCurveTo',
  9642. cp1x: cp1.x,
  9643. cp1y: cp1.y,
  9644. cp2x: cp2.x,
  9645. cp2y: cp2.y,
  9646. x: p.x,
  9647. y: p.y
  9648. });
  9649. self.currentX_ = p.x;
  9650. self.currentY_ = p.y;
  9651. }
  9652. contextPrototype.quadraticCurveTo = function (aCPx, aCPy, aX, aY) {
  9653. var cp = getCoords(this, aCPx, aCPy);
  9654. var p = getCoords(this, aX, aY);
  9655. var cp1 = {
  9656. x: this.currentX_ + 2 / 3 * (cp.x - this.currentX_),
  9657. y: this.currentY_ + 2 / 3 * (cp.y - this.currentY_)
  9658. };
  9659. var cp2 = {
  9660. x: cp1.x + (p.x - this.currentX_) / 3,
  9661. y: cp1.y + (p.y - this.currentY_) / 3
  9662. };
  9663. bezierCurveTo(this, cp1, cp2, p);
  9664. };
  9665. contextPrototype.arc = function (aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  9666. aRadius *= Z;
  9667. var arcType = aClockwise ? 'at' : 'wa';
  9668. var xStart = aX + mc(aStartAngle) * aRadius - Z2;
  9669. var yStart = aY + ms(aStartAngle) * aRadius - Z2;
  9670. var xEnd = aX + mc(aEndAngle) * aRadius - Z2;
  9671. var yEnd = aY + ms(aEndAngle) * aRadius - Z2;
  9672. if (xStart == xEnd && !aClockwise) {
  9673. xStart += 0.125;
  9674. }
  9675. var p = getCoords(this, aX, aY);
  9676. var pStart = getCoords(this, xStart, yStart);
  9677. var pEnd = getCoords(this, xEnd, yEnd);
  9678. this.currentPath_.push({
  9679. type: arcType,
  9680. x: p.x,
  9681. y: p.y,
  9682. radius: aRadius,
  9683. xStart: pStart.x,
  9684. yStart: pStart.y,
  9685. xEnd: pEnd.x,
  9686. yEnd: pEnd.y
  9687. });
  9688. };
  9689. contextPrototype.rect = function (aX, aY, aWidth, aHeight) {
  9690. this.moveTo(aX, aY);
  9691. this.lineTo(aX + aWidth, aY);
  9692. this.lineTo(aX + aWidth, aY + aHeight);
  9693. this.lineTo(aX, aY + aHeight);
  9694. this.closePath();
  9695. };
  9696. contextPrototype.strokeRect = function (aX, aY, aWidth, aHeight) {
  9697. var oldPath = this.currentPath_;
  9698. this.beginPath();
  9699. this.moveTo(aX, aY);
  9700. this.lineTo(aX + aWidth, aY);
  9701. this.lineTo(aX + aWidth, aY + aHeight);
  9702. this.lineTo(aX, aY + aHeight);
  9703. this.closePath();
  9704. this.stroke();
  9705. this.currentPath_ = oldPath;
  9706. };
  9707. contextPrototype.fillRect = function (aX, aY, aWidth, aHeight) {
  9708. var oldPath = this.currentPath_;
  9709. this.beginPath();
  9710. this.moveTo(aX, aY);
  9711. this.lineTo(aX + aWidth, aY);
  9712. this.lineTo(aX + aWidth, aY + aHeight);
  9713. this.lineTo(aX, aY + aHeight);
  9714. this.closePath();
  9715. this.fill();
  9716. this.currentPath_ = oldPath;
  9717. };
  9718. contextPrototype.createLinearGradient = function (aX0, aY0, aX1, aY1) {
  9719. var gradient = new CanvasGradient_('gradient');
  9720. gradient.x0_ = aX0;
  9721. gradient.y0_ = aY0;
  9722. gradient.x1_ = aX1;
  9723. gradient.y1_ = aY1;
  9724. return gradient;
  9725. };
  9726. contextPrototype.createRadialGradient = function (aX0, aY0, aR0, aX1, aY1, aR1) {
  9727. var gradient = new CanvasGradient_('gradientradial');
  9728. gradient.x0_ = aX0;
  9729. gradient.y0_ = aY0;
  9730. gradient.r0_ = aR0;
  9731. gradient.x1_ = aX1;
  9732. gradient.y1_ = aY1;
  9733. gradient.r1_ = aR1;
  9734. return gradient;
  9735. };
  9736. contextPrototype.drawImage = function (image, var_args) {
  9737. var dx, dy, dw, dh, sx, sy, sw, sh;
  9738. var oldRuntimeWidth = image.runtimeStyle.width;
  9739. var oldRuntimeHeight = image.runtimeStyle.height;
  9740. image.runtimeStyle.width = 'auto';
  9741. image.runtimeStyle.height = 'auto';
  9742. var w = image.width;
  9743. var h = image.height;
  9744. image.runtimeStyle.width = oldRuntimeWidth;
  9745. image.runtimeStyle.height = oldRuntimeHeight;
  9746. if (arguments.length == 3) {
  9747. dx = arguments[1];
  9748. dy = arguments[2];
  9749. sx = sy = 0;
  9750. sw = dw = w;
  9751. sh = dh = h;
  9752. } else if (arguments.length == 5) {
  9753. dx = arguments[1];
  9754. dy = arguments[2];
  9755. dw = arguments[3];
  9756. dh = arguments[4];
  9757. sx = sy = 0;
  9758. sw = w;
  9759. sh = h;
  9760. } else if (arguments.length == 9) {
  9761. sx = arguments[1];
  9762. sy = arguments[2];
  9763. sw = arguments[3];
  9764. sh = arguments[4];
  9765. dx = arguments[5];
  9766. dy = arguments[6];
  9767. dw = arguments[7];
  9768. dh = arguments[8];
  9769. } else {
  9770. throw Error('Invalid number of arguments');
  9771. }
  9772. var d = getCoords(this, dx, dy);
  9773. var w2 = sw / 2;
  9774. var h2 = sh / 2;
  9775. var vmlStr = [];
  9776. var W = 10;
  9777. var H = 10;
  9778. var scaleX = scaleY = 1;
  9779. vmlStr.push(' <g_vml_:group', ' coordsize="', Z * W, ',', Z * H, '"', ' coordorigin="0,0"', ' style="width:', W, 'px;height:', H, 'px;position:absolute;');
  9780. if (this.m_[0][0] != 1 || this.m_[0][1] || this.m_[1][1] != 1 || this.m_[1][0]) {
  9781. var filter = [];
  9782. var scaleX = this.scaleX_;
  9783. var scaleY = this.scaleY_;
  9784. filter.push('M11=', this.m_[0][0] / scaleX, ',', 'M12=', this.m_[1][0] / scaleY, ',', 'M21=', this.m_[0][1] / scaleX, ',', 'M22=', this.m_[1][1] / scaleY, ',', 'Dx=', mr(d.x / Z), ',', 'Dy=', mr(d.y / Z), '');
  9785. var max = d;
  9786. var c2 = getCoords(this, dx + dw, dy);
  9787. var c3 = getCoords(this, dx, dy + dh);
  9788. var c4 = getCoords(this, dx + dw, dy + dh);
  9789. max.x = m.max(max.x, c2.x, c3.x, c4.x);
  9790. max.y = m.max(max.y, c2.y, c3.y, c4.y);
  9791. vmlStr.push('padding:0 ', mr(max.x / Z), 'px ', mr(max.y / Z), 'px 0;filter:progid:DXImageTransform.Microsoft.Matrix(', filter.join(''), ', SizingMethod=\'clip\');');
  9792. } else {
  9793. vmlStr.push('top:', mr(d.y / Z), 'px;left:', mr(d.x / Z), 'px;');
  9794. }
  9795. vmlStr.push(' ">');
  9796. if (sx || sy) {
  9797. vmlStr.push('<div style="overflow: hidden; width:', Math.ceil((dw + sx * dw / sw) * scaleX), 'px;', ' height:', Math.ceil((dh + sy * dh / sh) * scaleY), 'px;', ' filter:progid:DxImageTransform.Microsoft.Matrix(Dx=', -sx * dw / sw * scaleX, ',Dy=', -sy * dh / sh * scaleY, ');">');
  9798. }
  9799. vmlStr.push('<div style="width:', Math.round(scaleX * w * dw / sw), 'px;', ' height:', Math.round(scaleY * h * dh / sh), 'px;', ' filter:');
  9800. if (this.globalAlpha < 1) {
  9801. vmlStr.push(' progid:DXImageTransform.Microsoft.Alpha(opacity=' + this.globalAlpha * 100 + ')');
  9802. }
  9803. vmlStr.push(' progid:DXImageTransform.Microsoft.AlphaImageLoader(src=', image.src, ',sizingMethod=scale)">');
  9804. if (sx || sy)
  9805. vmlStr.push('</div>');
  9806. vmlStr.push('</div></div>');
  9807. this.element_.insertAdjacentHTML('BeforeEnd', vmlStr.join(''));
  9808. };
  9809. contextPrototype.stroke = function (aFill) {
  9810. var lineStr = [];
  9811. var lineOpen = false;
  9812. var W = 10;
  9813. var H = 10;
  9814. lineStr.push('<g_vml_:shape', ' filled="', !!aFill, '"', ' style="position:absolute;width:', W, 'px;height:', H, 'px;"', ' coordorigin="0,0"', ' coordsize="', Z * W, ',', Z * H, '"', ' stroked="', !aFill, '"', ' path="');
  9815. var newSeq = false;
  9816. var min = {
  9817. x: null,
  9818. y: null
  9819. };
  9820. var max = {
  9821. x: null,
  9822. y: null
  9823. };
  9824. for (var i = 0; i < this.currentPath_.length; i++) {
  9825. var p = this.currentPath_[i];
  9826. var c;
  9827. switch (p.type) {
  9828. case 'moveTo':
  9829. c = p;
  9830. lineStr.push(' m ', mr(p.x), ',', mr(p.y));
  9831. break;
  9832. case 'lineTo':
  9833. lineStr.push(' l ', mr(p.x), ',', mr(p.y));
  9834. break;
  9835. case 'close':
  9836. lineStr.push(' x ');
  9837. p = null;
  9838. break;
  9839. case 'bezierCurveTo':
  9840. lineStr.push(' c ', mr(p.cp1x), ',', mr(p.cp1y), ',', mr(p.cp2x), ',', mr(p.cp2y), ',', mr(p.x), ',', mr(p.y));
  9841. break;
  9842. case 'at':
  9843. case 'wa':
  9844. lineStr.push(' ', p.type, ' ', mr(p.x - this.scaleX_ * p.radius), ',', mr(p.y - this.scaleY_ * p.radius), ' ', mr(p.x + this.scaleX_ * p.radius), ',', mr(p.y + this.scaleY_ * p.radius), ' ', mr(p.xStart), ',', mr(p.yStart), ' ', mr(p.xEnd), ',', mr(p.yEnd));
  9845. break;
  9846. }
  9847. if (p) {
  9848. if (min.x == null || p.x < min.x) {
  9849. min.x = p.x;
  9850. }
  9851. if (max.x == null || p.x > max.x) {
  9852. max.x = p.x;
  9853. }
  9854. if (min.y == null || p.y < min.y) {
  9855. min.y = p.y;
  9856. }
  9857. if (max.y == null || p.y > max.y) {
  9858. max.y = p.y;
  9859. }
  9860. }
  9861. }
  9862. lineStr.push(' ">');
  9863. if (!aFill) {
  9864. appendStroke(this, lineStr);
  9865. } else {
  9866. appendFill(this, lineStr, min, max);
  9867. }
  9868. lineStr.push('</g_vml_:shape>');
  9869. this.element_.insertAdjacentHTML('beforeEnd', lineStr.join(''));
  9870. };
  9871. function appendStroke(ctx, lineStr) {
  9872. var a = processStyle(ctx.strokeStyle);
  9873. var color = a.color;
  9874. var opacity = a.alpha * ctx.globalAlpha;
  9875. var lineWidth = ctx.lineScale_ * ctx.lineWidth;
  9876. if (lineWidth < 1) {
  9877. opacity *= lineWidth;
  9878. }
  9879. lineStr.push('<g_vml_:stroke', ' opacity="', opacity, '"', ' joinstyle="', ctx.lineJoin, '"', ' miterlimit="', ctx.miterLimit, '"', ' endcap="', processLineCap(ctx.lineCap), '"', ' weight="', lineWidth, 'px"', ' color="', color, '" />');
  9880. }
  9881. function appendFill(ctx, lineStr, min, max) {
  9882. var fillStyle = ctx.fillStyle;
  9883. var arcScaleX = ctx.scaleX_;
  9884. var arcScaleY = ctx.scaleY_;
  9885. var width = max.x - min.x;
  9886. var height = max.y - min.y;
  9887. if (fillStyle instanceof CanvasGradient_) {
  9888. var angle = 0;
  9889. var focus = {
  9890. x: 0,
  9891. y: 0
  9892. };
  9893. var shift = 0;
  9894. var expansion = 1;
  9895. if (fillStyle.type_ == 'gradient') {
  9896. var x0 = fillStyle.x0_ / arcScaleX;
  9897. var y0 = fillStyle.y0_ / arcScaleY;
  9898. var x1 = fillStyle.x1_ / arcScaleX;
  9899. var y1 = fillStyle.y1_ / arcScaleY;
  9900. var p0 = getCoords(ctx, x0, y0);
  9901. var p1 = getCoords(ctx, x1, y1);
  9902. var dx = p1.x - p0.x;
  9903. var dy = p1.y - p0.y;
  9904. angle = Math.atan2(dx, dy) * 180 / Math.PI;
  9905. if (angle < 0) {
  9906. angle += 360;
  9907. }
  9908. if (angle < 0.000001) {
  9909. angle = 0;
  9910. }
  9911. } else {
  9912. var p0 = getCoords(ctx, fillStyle.x0_, fillStyle.y0_);
  9913. focus = {
  9914. x: (p0.x - min.x) / width,
  9915. y: (p0.y - min.y) / height
  9916. };
  9917. width /= arcScaleX * Z;
  9918. height /= arcScaleY * Z;
  9919. var dimension = m.max(width, height);
  9920. shift = 2 * fillStyle.r0_ / dimension;
  9921. expansion = 2 * fillStyle.r1_ / dimension - shift;
  9922. }
  9923. var stops = fillStyle.colors_;
  9924. stops.sort(function (cs1, cs2) {
  9925. return cs1.offset - cs2.offset;
  9926. });
  9927. var length = stops.length;
  9928. var color1 = stops[0].color;
  9929. var color2 = stops[length - 1].color;
  9930. var opacity1 = stops[0].alpha * ctx.globalAlpha;
  9931. var opacity2 = stops[length - 1].alpha * ctx.globalAlpha;
  9932. var colors = [];
  9933. for (var i = 0; i < length; i++) {
  9934. var stop = stops[i];
  9935. colors.push(stop.offset * expansion + shift + ' ' + stop.color);
  9936. }
  9937. lineStr.push('<g_vml_:fill type="', fillStyle.type_, '"', ' method="none" focus="100%"', ' color="', color1, '"', ' color2="', color2, '"', ' colors="', colors.join(','), '"', ' opacity="', opacity2, '"', ' g_o_:opacity2="', opacity1, '"', ' angle="', angle, '"', ' focusposition="', focus.x, ',', focus.y, '" />');
  9938. } else if (fillStyle instanceof CanvasPattern_) {
  9939. if (width && height) {
  9940. var deltaLeft = -min.x;
  9941. var deltaTop = -min.y;
  9942. lineStr.push('<g_vml_:fill', ' position="', deltaLeft / width * arcScaleX * arcScaleX, ',', deltaTop / height * arcScaleY * arcScaleY, '"', ' type="tile"', ' src="', fillStyle.src_, '" />');
  9943. }
  9944. } else {
  9945. var a = processStyle(ctx.fillStyle);
  9946. var color = a.color;
  9947. var opacity = a.alpha * ctx.globalAlpha;
  9948. lineStr.push('<g_vml_:fill color="', color, '" opacity="', opacity, '" />');
  9949. }
  9950. }
  9951. contextPrototype.fill = function () {
  9952. this.stroke(true);
  9953. };
  9954. contextPrototype.closePath = function () {
  9955. this.currentPath_.push({ type: 'close' });
  9956. };
  9957. function getCoords(ctx, aX, aY) {
  9958. var m = ctx.m_;
  9959. return {
  9960. x: Z * (aX * m[0][0] + aY * m[1][0] + m[2][0]) - Z2,
  9961. y: Z * (aX * m[0][1] + aY * m[1][1] + m[2][1]) - Z2
  9962. };
  9963. }
  9964. ;
  9965. contextPrototype.save = function () {
  9966. var o = {};
  9967. copyState(this, o);
  9968. this.aStack_.push(o);
  9969. this.mStack_.push(this.m_);
  9970. this.m_ = matrixMultiply(createMatrixIdentity(), this.m_);
  9971. };
  9972. contextPrototype.restore = function () {
  9973. if (this.aStack_.length) {
  9974. copyState(this.aStack_.pop(), this);
  9975. this.m_ = this.mStack_.pop();
  9976. }
  9977. };
  9978. function matrixIsFinite(m) {
  9979. return isFinite(m[0][0]) && isFinite(m[0][1]) && isFinite(m[1][0]) && isFinite(m[1][1]) && isFinite(m[2][0]) && isFinite(m[2][1]);
  9980. }
  9981. function setM(ctx, m, updateLineScale) {
  9982. if (!matrixIsFinite(m)) {
  9983. return;
  9984. }
  9985. ctx.m_ = m;
  9986. ctx.scaleX_ = Math.sqrt(m[0][0] * m[0][0] + m[0][1] * m[0][1]);
  9987. ctx.scaleY_ = Math.sqrt(m[1][0] * m[1][0] + m[1][1] * m[1][1]);
  9988. if (updateLineScale) {
  9989. var det = m[0][0] * m[1][1] - m[0][1] * m[1][0];
  9990. ctx.lineScale_ = sqrt(abs(det));
  9991. }
  9992. }
  9993. contextPrototype.translate = function (aX, aY) {
  9994. var m1 = [
  9995. [
  9996. 1,
  9997. 0,
  9998. 0
  9999. ],
  10000. [
  10001. 0,
  10002. 1,
  10003. 0
  10004. ],
  10005. [
  10006. aX,
  10007. aY,
  10008. 1
  10009. ]
  10010. ];
  10011. setM(this, matrixMultiply(m1, this.m_), false);
  10012. };
  10013. contextPrototype.rotate = function (aRot) {
  10014. var c = mc(aRot);
  10015. var s = ms(aRot);
  10016. var m1 = [
  10017. [
  10018. c,
  10019. s,
  10020. 0
  10021. ],
  10022. [
  10023. -s,
  10024. c,
  10025. 0
  10026. ],
  10027. [
  10028. 0,
  10029. 0,
  10030. 1
  10031. ]
  10032. ];
  10033. setM(this, matrixMultiply(m1, this.m_), false);
  10034. };
  10035. contextPrototype.scale = function (aX, aY) {
  10036. var m1 = [
  10037. [
  10038. aX,
  10039. 0,
  10040. 0
  10041. ],
  10042. [
  10043. 0,
  10044. aY,
  10045. 0
  10046. ],
  10047. [
  10048. 0,
  10049. 0,
  10050. 1
  10051. ]
  10052. ];
  10053. setM(this, matrixMultiply(m1, this.m_), true);
  10054. };
  10055. contextPrototype.transform = function (m11, m12, m21, m22, dx, dy) {
  10056. var m1 = [
  10057. [
  10058. m11,
  10059. m12,
  10060. 0
  10061. ],
  10062. [
  10063. m21,
  10064. m22,
  10065. 0
  10066. ],
  10067. [
  10068. dx,
  10069. dy,
  10070. 1
  10071. ]
  10072. ];
  10073. setM(this, matrixMultiply(m1, this.m_), true);
  10074. };
  10075. contextPrototype.setTransform = function (m11, m12, m21, m22, dx, dy) {
  10076. var m = [
  10077. [
  10078. m11,
  10079. m12,
  10080. 0
  10081. ],
  10082. [
  10083. m21,
  10084. m22,
  10085. 0
  10086. ],
  10087. [
  10088. dx,
  10089. dy,
  10090. 1
  10091. ]
  10092. ];
  10093. setM(this, m, true);
  10094. };
  10095. contextPrototype.drawText_ = function (text, x, y, maxWidth, stroke) {
  10096. var m = this.m_, delta = 1000, left = 0, right = delta, offset = {
  10097. x: 0,
  10098. y: 0
  10099. }, lineStr = [];
  10100. var fontStyle = getComputedStyle(processFontStyle(this.font), this.element_);
  10101. var fontStyleString = buildStyle(fontStyle);
  10102. var elementStyle = this.element_.currentStyle;
  10103. var textAlign = this.textAlign.toLowerCase();
  10104. switch (textAlign) {
  10105. case 'left':
  10106. case 'center':
  10107. case 'right':
  10108. break;
  10109. case 'end':
  10110. textAlign = elementStyle.direction == 'ltr' ? 'right' : 'left';
  10111. break;
  10112. case 'start':
  10113. textAlign = elementStyle.direction == 'rtl' ? 'right' : 'left';
  10114. break;
  10115. default:
  10116. textAlign = 'left';
  10117. }
  10118. switch (this.textBaseline) {
  10119. case 'hanging':
  10120. case 'top':
  10121. offset.y = fontStyle.size / 1.75;
  10122. break;
  10123. case 'middle':
  10124. break;
  10125. default:
  10126. case null:
  10127. case 'alphabetic':
  10128. case 'ideographic':
  10129. case 'bottom':
  10130. offset.y = -fontStyle.size / 2.25;
  10131. break;
  10132. }
  10133. switch (textAlign) {
  10134. case 'right':
  10135. left = delta;
  10136. right = 0.05;
  10137. break;
  10138. case 'center':
  10139. left = right = delta / 2;
  10140. break;
  10141. }
  10142. var d = getCoords(this, x + offset.x, y + offset.y);
  10143. lineStr.push('<g_vml_:line from="', -left, ' 0" to="', right, ' 0.05" ', ' coordsize="100 100" coordorigin="0 0"', ' filled="', !stroke, '" stroked="', !!stroke, '" style="position:absolute;width:1px;height:1px;">');
  10144. if (stroke) {
  10145. appendStroke(this, lineStr);
  10146. } else {
  10147. appendFill(this, lineStr, {
  10148. x: -left,
  10149. y: 0
  10150. }, {
  10151. x: right,
  10152. y: fontStyle.size
  10153. });
  10154. }
  10155. var skewM = m[0][0].toFixed(3) + ',' + m[1][0].toFixed(3) + ',' + m[0][1].toFixed(3) + ',' + m[1][1].toFixed(3) + ',0,0';
  10156. var skewOffset = mr(d.x / Z) + ',' + mr(d.y / Z);
  10157. lineStr.push('<g_vml_:skew on="t" matrix="', skewM, '" ', ' offset="', skewOffset, '" origin="', left, ' 0" />', '<g_vml_:path textpathok="true" />', '<g_vml_:textpath on="true" string="', encodeHtmlAttribute(text), '" style="v-text-align:', textAlign, ';font:', encodeHtmlAttribute(fontStyleString), '" /></g_vml_:line>');
  10158. this.element_.insertAdjacentHTML('beforeEnd', lineStr.join(''));
  10159. };
  10160. contextPrototype.fillText = function (text, x, y, maxWidth) {
  10161. this.drawText_(text, x, y, maxWidth, false);
  10162. };
  10163. contextPrototype.strokeText = function (text, x, y, maxWidth) {
  10164. this.drawText_(text, x, y, maxWidth, true);
  10165. };
  10166. contextPrototype.measureText = function (text) {
  10167. if (!this.textMeasureEl_) {
  10168. var s = '<span style="position:absolute;' + 'top:-20000px;left:0;padding:0;margin:0;border:none;' + 'white-space:pre;"></span>';
  10169. this.element_.insertAdjacentHTML('beforeEnd', s);
  10170. this.textMeasureEl_ = this.element_.lastChild;
  10171. }
  10172. var doc = this.element_.ownerDocument;
  10173. this.textMeasureEl_.innerHTML = '';
  10174. try {
  10175. this.textMeasureEl_.style.font = this.font;
  10176. } catch (ex) {
  10177. }
  10178. this.textMeasureEl_.appendChild(doc.createTextNode(text));
  10179. return { width: this.textMeasureEl_.offsetWidth };
  10180. };
  10181. contextPrototype.clip = function () {
  10182. };
  10183. contextPrototype.arcTo = function () {
  10184. };
  10185. contextPrototype.createPattern = function (image, repetition) {
  10186. return new CanvasPattern_(image, repetition);
  10187. };
  10188. function CanvasGradient_(aType) {
  10189. this.type_ = aType;
  10190. this.x0_ = 0;
  10191. this.y0_ = 0;
  10192. this.r0_ = 0;
  10193. this.x1_ = 0;
  10194. this.y1_ = 0;
  10195. this.r1_ = 0;
  10196. this.colors_ = [];
  10197. }
  10198. CanvasGradient_.prototype.addColorStop = function (aOffset, aColor) {
  10199. aColor = processStyle(aColor);
  10200. this.colors_.push({
  10201. offset: aOffset,
  10202. color: aColor.color,
  10203. alpha: aColor.alpha
  10204. });
  10205. };
  10206. function CanvasPattern_(image, repetition) {
  10207. assertImageIsValid(image);
  10208. switch (repetition) {
  10209. case 'repeat':
  10210. case null:
  10211. case '':
  10212. this.repetition_ = 'repeat';
  10213. break;
  10214. case 'repeat-x':
  10215. case 'repeat-y':
  10216. case 'no-repeat':
  10217. this.repetition_ = repetition;
  10218. break;
  10219. default:
  10220. throwException('SYNTAX_ERR');
  10221. }
  10222. this.src_ = image.src;
  10223. this.width_ = image.width;
  10224. this.height_ = image.height;
  10225. }
  10226. function throwException(s) {
  10227. throw new DOMException_(s);
  10228. }
  10229. function assertImageIsValid(img) {
  10230. if (!img || img.nodeType != 1 || img.tagName != 'IMG') {
  10231. throwException('TYPE_MISMATCH_ERR');
  10232. }
  10233. if (img.readyState != 'complete') {
  10234. throwException('INVALID_STATE_ERR');
  10235. }
  10236. }
  10237. function DOMException_(s) {
  10238. this.code = this[s];
  10239. this.message = s + ': DOM Exception ' + this.code;
  10240. }
  10241. var p = DOMException_.prototype = new Error();
  10242. p.INDEX_SIZE_ERR = 1;
  10243. p.DOMSTRING_SIZE_ERR = 2;
  10244. p.HIERARCHY_REQUEST_ERR = 3;
  10245. p.WRONG_DOCUMENT_ERR = 4;
  10246. p.INVALID_CHARACTER_ERR = 5;
  10247. p.NO_DATA_ALLOWED_ERR = 6;
  10248. p.NO_MODIFICATION_ALLOWED_ERR = 7;
  10249. p.NOT_FOUND_ERR = 8;
  10250. p.NOT_SUPPORTED_ERR = 9;
  10251. p.INUSE_ATTRIBUTE_ERR = 10;
  10252. p.INVALID_STATE_ERR = 11;
  10253. p.SYNTAX_ERR = 12;
  10254. p.INVALID_MODIFICATION_ERR = 13;
  10255. p.NAMESPACE_ERR = 14;
  10256. p.INVALID_ACCESS_ERR = 15;
  10257. p.VALIDATION_ERR = 16;
  10258. p.TYPE_MISMATCH_ERR = 17;
  10259. G_vmlCanvasManager = G_vmlCanvasManager_;
  10260. CanvasRenderingContext2D = CanvasRenderingContext2D_;
  10261. CanvasGradient = CanvasGradient_;
  10262. CanvasPattern = CanvasPattern_;
  10263. DOMException = DOMException_;
  10264. }());
  10265. } else {
  10266. G_vmlCanvasManager = false;
  10267. }
  10268. return G_vmlCanvasManager;
  10269. });define('zrender/mixin/Eventful', ['require'], function (require) {
  10270. var Eventful = function () {
  10271. this._handlers = {};
  10272. };
  10273. Eventful.prototype.one = function (event, handler, context) {
  10274. var _h = this._handlers;
  10275. if (!handler || !event) {
  10276. return this;
  10277. }
  10278. if (!_h[event]) {
  10279. _h[event] = [];
  10280. }
  10281. _h[event].push({
  10282. h: handler,
  10283. one: true,
  10284. ctx: context || this
  10285. });
  10286. return this;
  10287. };
  10288. Eventful.prototype.bind = function (event, handler, context) {
  10289. var _h = this._handlers;
  10290. if (!handler || !event) {
  10291. return this;
  10292. }
  10293. if (!_h[event]) {
  10294. _h[event] = [];
  10295. }
  10296. _h[event].push({
  10297. h: handler,
  10298. one: false,
  10299. ctx: context || this
  10300. });
  10301. return this;
  10302. };
  10303. Eventful.prototype.unbind = function (event, handler) {
  10304. var _h = this._handlers;
  10305. if (!event) {
  10306. this._handlers = {};
  10307. return this;
  10308. }
  10309. if (handler) {
  10310. if (_h[event]) {
  10311. var newList = [];
  10312. for (var i = 0, l = _h[event].length; i < l; i++) {
  10313. if (_h[event][i]['h'] != handler) {
  10314. newList.push(_h[event][i]);
  10315. }
  10316. }
  10317. _h[event] = newList;
  10318. }
  10319. if (_h[event] && _h[event].length === 0) {
  10320. delete _h[event];
  10321. }
  10322. } else {
  10323. delete _h[event];
  10324. }
  10325. return this;
  10326. };
  10327. Eventful.prototype.dispatch = function (type) {
  10328. if (this._handlers[type]) {
  10329. var args = arguments;
  10330. var argLen = args.length;
  10331. if (argLen > 3) {
  10332. args = Array.prototype.slice.call(args, 1);
  10333. }
  10334. var _h = this._handlers[type];
  10335. var len = _h.length;
  10336. for (var i = 0; i < len;) {
  10337. switch (argLen) {
  10338. case 1:
  10339. _h[i]['h'].call(_h[i]['ctx']);
  10340. break;
  10341. case 2:
  10342. _h[i]['h'].call(_h[i]['ctx'], args[1]);
  10343. break;
  10344. case 3:
  10345. _h[i]['h'].call(_h[i]['ctx'], args[1], args[2]);
  10346. break;
  10347. default:
  10348. _h[i]['h'].apply(_h[i]['ctx'], args);
  10349. break;
  10350. }
  10351. if (_h[i]['one']) {
  10352. _h.splice(i, 1);
  10353. len--;
  10354. } else {
  10355. i++;
  10356. }
  10357. }
  10358. }
  10359. return this;
  10360. };
  10361. Eventful.prototype.dispatchWithContext = function (type) {
  10362. if (this._handlers[type]) {
  10363. var args = arguments;
  10364. var argLen = args.length;
  10365. if (argLen > 4) {
  10366. args = Array.prototype.slice.call(args, 1, args.length - 1);
  10367. }
  10368. var ctx = args[args.length - 1];
  10369. var _h = this._handlers[type];
  10370. var len = _h.length;
  10371. for (var i = 0; i < len;) {
  10372. switch (argLen) {
  10373. case 1:
  10374. _h[i]['h'].call(ctx);
  10375. break;
  10376. case 2:
  10377. _h[i]['h'].call(ctx, args[1]);
  10378. break;
  10379. case 3:
  10380. _h[i]['h'].call(ctx, args[1], args[2]);
  10381. break;
  10382. default:
  10383. _h[i]['h'].apply(ctx, args);
  10384. break;
  10385. }
  10386. if (_h[i]['one']) {
  10387. _h.splice(i, 1);
  10388. len--;
  10389. } else {
  10390. i++;
  10391. }
  10392. }
  10393. }
  10394. return this;
  10395. };
  10396. return Eventful;
  10397. });define('zrender/tool/log', [
  10398. 'require',
  10399. '../config'
  10400. ], function (require) {
  10401. var config = require('../config');
  10402. return function () {
  10403. if (config.debugMode === 0) {
  10404. return;
  10405. } else if (config.debugMode == 1) {
  10406. for (var k in arguments) {
  10407. throw new Error(arguments[k]);
  10408. }
  10409. } else if (config.debugMode > 1) {
  10410. for (var k in arguments) {
  10411. console.log(arguments[k]);
  10412. }
  10413. }
  10414. };
  10415. });define('zrender/tool/guid', [], function () {
  10416. var idStart = 2311;
  10417. return function () {
  10418. return 'zrender__' + idStart++;
  10419. };
  10420. });define('zrender/Handler', [
  10421. 'require',
  10422. './config',
  10423. './tool/env',
  10424. './tool/event',
  10425. './tool/util',
  10426. './tool/vector',
  10427. './tool/matrix',
  10428. './mixin/Eventful'
  10429. ], function (require) {
  10430. 'use strict';
  10431. var config = require('./config');
  10432. var env = require('./tool/env');
  10433. var eventTool = require('./tool/event');
  10434. var util = require('./tool/util');
  10435. var vec2 = require('./tool/vector');
  10436. var mat2d = require('./tool/matrix');
  10437. var EVENT = config.EVENT;
  10438. var Eventful = require('./mixin/Eventful');
  10439. var domHandlerNames = [
  10440. 'resize',
  10441. 'click',
  10442. 'dblclick',
  10443. 'mousewheel',
  10444. 'mousemove',
  10445. 'mouseout',
  10446. 'mouseup',
  10447. 'mousedown',
  10448. 'touchstart',
  10449. 'touchend',
  10450. 'touchmove'
  10451. ];
  10452. var isZRenderElement = function (event) {
  10453. if (window.G_vmlCanvasManager) {
  10454. return true;
  10455. }
  10456. event = event || window.event;
  10457. var target = event.toElement || event.relatedTarget || event.srcElement || event.target;
  10458. return target && target.className.match(config.elementClassName);
  10459. };
  10460. var domHandlers = {
  10461. resize: function (event) {
  10462. event = event || window.event;
  10463. this._lastHover = null;
  10464. this._isMouseDown = 0;
  10465. this.dispatch(EVENT.RESIZE, event);
  10466. },
  10467. click: function (event, manually) {
  10468. if (!isZRenderElement(event) && !manually) {
  10469. return;
  10470. }
  10471. event = this._zrenderEventFixed(event);
  10472. var _lastHover = this._lastHover;
  10473. if (_lastHover && _lastHover.clickable || !_lastHover) {
  10474. if (this._clickThreshold < 5) {
  10475. this._dispatchAgency(_lastHover, EVENT.CLICK, event);
  10476. }
  10477. }
  10478. this._mousemoveHandler(event);
  10479. },
  10480. dblclick: function (event, manually) {
  10481. if (!isZRenderElement(event) && !manually) {
  10482. return;
  10483. }
  10484. event = event || window.event;
  10485. event = this._zrenderEventFixed(event);
  10486. var _lastHover = this._lastHover;
  10487. if (_lastHover && _lastHover.clickable || !_lastHover) {
  10488. if (this._clickThreshold < 5) {
  10489. this._dispatchAgency(_lastHover, EVENT.DBLCLICK, event);
  10490. }
  10491. }
  10492. this._mousemoveHandler(event);
  10493. },
  10494. mousewheel: function (event, manually) {
  10495. if (!isZRenderElement(event) && !manually) {
  10496. return;
  10497. }
  10498. event = this._zrenderEventFixed(event);
  10499. var delta = event.wheelDelta || -event.detail;
  10500. var scale = delta > 0 ? 1.1 : 1 / 1.1;
  10501. var needsRefresh = false;
  10502. var mouseX = this._mouseX;
  10503. var mouseY = this._mouseY;
  10504. this.painter.eachBuildinLayer(function (layer) {
  10505. var pos = layer.position;
  10506. if (layer.zoomable) {
  10507. layer.__zoom = layer.__zoom || 1;
  10508. var newZoom = layer.__zoom;
  10509. newZoom *= scale;
  10510. newZoom = Math.max(Math.min(layer.maxZoom, newZoom), layer.minZoom);
  10511. scale = newZoom / layer.__zoom;
  10512. layer.__zoom = newZoom;
  10513. pos[0] -= (mouseX - pos[0]) * (scale - 1);
  10514. pos[1] -= (mouseY - pos[1]) * (scale - 1);
  10515. layer.scale[0] *= scale;
  10516. layer.scale[1] *= scale;
  10517. layer.dirty = true;
  10518. needsRefresh = true;
  10519. eventTool.stop(event);
  10520. }
  10521. });
  10522. if (needsRefresh) {
  10523. this.painter.refresh();
  10524. }
  10525. this._dispatchAgency(this._lastHover, EVENT.MOUSEWHEEL, event);
  10526. this._mousemoveHandler(event);
  10527. },
  10528. mousemove: function (event, manually) {
  10529. if (!isZRenderElement(event) && !manually) {
  10530. return;
  10531. }
  10532. if (this.painter.isLoading()) {
  10533. return;
  10534. }
  10535. event = this._zrenderEventFixed(event);
  10536. this._lastX = this._mouseX;
  10537. this._lastY = this._mouseY;
  10538. this._mouseX = eventTool.getX(event);
  10539. this._mouseY = eventTool.getY(event);
  10540. var dx = this._mouseX - this._lastX;
  10541. var dy = this._mouseY - this._lastY;
  10542. this._processDragStart(event);
  10543. this._hasfound = 0;
  10544. this._event = event;
  10545. this._iterateAndFindHover();
  10546. if (!this._hasfound) {
  10547. if (!this._draggingTarget || this._lastHover && this._lastHover != this._draggingTarget) {
  10548. this._processOutShape(event);
  10549. this._processDragLeave(event);
  10550. }
  10551. this._lastHover = null;
  10552. this.storage.delHover();
  10553. this.painter.clearHover();
  10554. }
  10555. var cursor = 'default';
  10556. if (this._draggingTarget) {
  10557. this.storage.drift(this._draggingTarget.id, dx, dy);
  10558. this._draggingTarget.modSelf();
  10559. this.storage.addHover(this._draggingTarget);
  10560. this._clickThreshold++;
  10561. } else if (this._isMouseDown) {
  10562. var needsRefresh = false;
  10563. this.painter.eachBuildinLayer(function (layer) {
  10564. if (layer.panable) {
  10565. cursor = 'move';
  10566. layer.position[0] += dx;
  10567. layer.position[1] += dy;
  10568. needsRefresh = true;
  10569. layer.dirty = true;
  10570. }
  10571. });
  10572. if (needsRefresh) {
  10573. this.painter.refresh();
  10574. }
  10575. }
  10576. if (this._draggingTarget || this._hasfound && this._lastHover.draggable) {
  10577. cursor = 'move';
  10578. } else if (this._hasfound && this._lastHover.clickable) {
  10579. cursor = 'pointer';
  10580. }
  10581. this.root.style.cursor = cursor;
  10582. this._dispatchAgency(this._lastHover, EVENT.MOUSEMOVE, event);
  10583. if (this._draggingTarget || this._hasfound || this.storage.hasHoverShape()) {
  10584. this.painter.refreshHover();
  10585. }
  10586. },
  10587. mouseout: function (event, manually) {
  10588. if (!isZRenderElement(event) && !manually) {
  10589. return;
  10590. }
  10591. event = this._zrenderEventFixed(event);
  10592. var element = event.toElement || event.relatedTarget;
  10593. if (element != this.root) {
  10594. while (element && element.nodeType != 9) {
  10595. if (element == this.root) {
  10596. this._mousemoveHandler(event);
  10597. return;
  10598. }
  10599. element = element.parentNode;
  10600. }
  10601. }
  10602. event.zrenderX = this._lastX;
  10603. event.zrenderY = this._lastY;
  10604. this.root.style.cursor = 'default';
  10605. this._isMouseDown = 0;
  10606. this._processOutShape(event);
  10607. this._processDrop(event);
  10608. this._processDragEnd(event);
  10609. if (!this.painter.isLoading()) {
  10610. this.painter.refreshHover();
  10611. }
  10612. this.dispatch(EVENT.GLOBALOUT, event);
  10613. },
  10614. mousedown: function (event, manually) {
  10615. if (!isZRenderElement(event) && !manually) {
  10616. return;
  10617. }
  10618. this._clickThreshold = 0;
  10619. if (this._lastDownButton == 2) {
  10620. this._lastDownButton = event.button;
  10621. this._mouseDownTarget = null;
  10622. return;
  10623. }
  10624. this._lastMouseDownMoment = new Date();
  10625. event = this._zrenderEventFixed(event);
  10626. this._isMouseDown = 1;
  10627. this._mouseDownTarget = this._lastHover;
  10628. this._dispatchAgency(this._lastHover, EVENT.MOUSEDOWN, event);
  10629. this._lastDownButton = event.button;
  10630. },
  10631. mouseup: function (event, manually) {
  10632. if (!isZRenderElement(event) && !manually) {
  10633. return;
  10634. }
  10635. event = this._zrenderEventFixed(event);
  10636. this.root.style.cursor = 'default';
  10637. this._isMouseDown = 0;
  10638. this._mouseDownTarget = null;
  10639. this._dispatchAgency(this._lastHover, EVENT.MOUSEUP, event);
  10640. this._processDrop(event);
  10641. this._processDragEnd(event);
  10642. },
  10643. touchstart: function (event, manually) {
  10644. if (!isZRenderElement(event) && !manually) {
  10645. return;
  10646. }
  10647. event = this._zrenderEventFixed(event, true);
  10648. this._lastTouchMoment = new Date();
  10649. this._mobileFindFixed(event);
  10650. this._mousedownHandler(event);
  10651. },
  10652. touchmove: function (event, manually) {
  10653. if (!isZRenderElement(event) && !manually) {
  10654. return;
  10655. }
  10656. event = this._zrenderEventFixed(event, true);
  10657. this._mousemoveHandler(event);
  10658. if (this._isDragging) {
  10659. eventTool.stop(event);
  10660. }
  10661. },
  10662. touchend: function (event, manually) {
  10663. if (!isZRenderElement(event) && !manually) {
  10664. return;
  10665. }
  10666. event = this._zrenderEventFixed(event, true);
  10667. this._mouseupHandler(event);
  10668. var now = new Date();
  10669. if (now - this._lastTouchMoment < EVENT.touchClickDelay) {
  10670. this._mobileFindFixed(event);
  10671. this._clickHandler(event);
  10672. if (now - this._lastClickMoment < EVENT.touchClickDelay / 2) {
  10673. this._dblclickHandler(event);
  10674. if (this._lastHover && this._lastHover.clickable) {
  10675. eventTool.stop(event);
  10676. }
  10677. }
  10678. this._lastClickMoment = now;
  10679. }
  10680. this.painter.clearHover();
  10681. }
  10682. };
  10683. function bind2Arg(handler, context) {
  10684. return function (arg1, arg2) {
  10685. return handler.call(context, arg1, arg2);
  10686. };
  10687. }
  10688. function bind3Arg(handler, context) {
  10689. return function (arg1, arg2, arg3) {
  10690. return handler.call(context, arg1, arg2, arg3);
  10691. };
  10692. }
  10693. function initDomHandler(instance) {
  10694. var len = domHandlerNames.length;
  10695. while (len--) {
  10696. var name = domHandlerNames[len];
  10697. instance['_' + name + 'Handler'] = bind2Arg(domHandlers[name], instance);
  10698. }
  10699. }
  10700. var Handler = function (root, storage, painter) {
  10701. Eventful.call(this);
  10702. this.root = root;
  10703. this.storage = storage;
  10704. this.painter = painter;
  10705. this._lastX = this._lastY = this._mouseX = this._mouseY = 0;
  10706. this._findHover = bind3Arg(findHover, this);
  10707. this._domHover = painter.getDomHover();
  10708. initDomHandler(this);
  10709. if (window.addEventListener) {
  10710. window.addEventListener('resize', this._resizeHandler);
  10711. if (env.os.tablet || env.os.phone) {
  10712. root.addEventListener('touchstart', this._touchstartHandler);
  10713. root.addEventListener('touchmove', this._touchmoveHandler);
  10714. root.addEventListener('touchend', this._touchendHandler);
  10715. } else {
  10716. root.addEventListener('click', this._clickHandler);
  10717. root.addEventListener('dblclick', this._dblclickHandler);
  10718. root.addEventListener('mousewheel', this._mousewheelHandler);
  10719. root.addEventListener('mousemove', this._mousemoveHandler);
  10720. root.addEventListener('mousedown', this._mousedownHandler);
  10721. root.addEventListener('mouseup', this._mouseupHandler);
  10722. }
  10723. root.addEventListener('DOMMouseScroll', this._mousewheelHandler);
  10724. root.addEventListener('mouseout', this._mouseoutHandler);
  10725. } else {
  10726. window.attachEvent('onresize', this._resizeHandler);
  10727. root.attachEvent('onclick', this._clickHandler);
  10728. root.ondblclick = this._dblclickHandler;
  10729. root.attachEvent('onmousewheel', this._mousewheelHandler);
  10730. root.attachEvent('onmousemove', this._mousemoveHandler);
  10731. root.attachEvent('onmouseout', this._mouseoutHandler);
  10732. root.attachEvent('onmousedown', this._mousedownHandler);
  10733. root.attachEvent('onmouseup', this._mouseupHandler);
  10734. }
  10735. };
  10736. Handler.prototype.on = function (eventName, handler, context) {
  10737. this.bind(eventName, handler, context);
  10738. return this;
  10739. };
  10740. Handler.prototype.un = function (eventName, handler) {
  10741. this.unbind(eventName, handler);
  10742. return this;
  10743. };
  10744. Handler.prototype.trigger = function (eventName, eventArgs) {
  10745. switch (eventName) {
  10746. case EVENT.RESIZE:
  10747. case EVENT.CLICK:
  10748. case EVENT.DBLCLICK:
  10749. case EVENT.MOUSEWHEEL:
  10750. case EVENT.MOUSEMOVE:
  10751. case EVENT.MOUSEDOWN:
  10752. case EVENT.MOUSEUP:
  10753. case EVENT.MOUSEOUT:
  10754. this['_' + eventName + 'Handler'](eventArgs, true);
  10755. break;
  10756. }
  10757. };
  10758. Handler.prototype.dispose = function () {
  10759. var root = this.root;
  10760. if (window.removeEventListener) {
  10761. window.removeEventListener('resize', this._resizeHandler);
  10762. if (env.os.tablet || env.os.phone) {
  10763. root.removeEventListener('touchstart', this._touchstartHandler);
  10764. root.removeEventListener('touchmove', this._touchmoveHandler);
  10765. root.removeEventListener('touchend', this._touchendHandler);
  10766. } else {
  10767. root.removeEventListener('click', this._clickHandler);
  10768. root.removeEventListener('dblclick', this._dblclickHandler);
  10769. root.removeEventListener('mousewheel', this._mousewheelHandler);
  10770. root.removeEventListener('mousemove', this._mousemoveHandler);
  10771. root.removeEventListener('mousedown', this._mousedownHandler);
  10772. root.removeEventListener('mouseup', this._mouseupHandler);
  10773. }
  10774. root.removeEventListener('DOMMouseScroll', this._mousewheelHandler);
  10775. root.removeEventListener('mouseout', this._mouseoutHandler);
  10776. } else {
  10777. window.detachEvent('onresize', this._resizeHandler);
  10778. root.detachEvent('onclick', this._clickHandler);
  10779. root.detachEvent('dblclick', this._dblclickHandler);
  10780. root.detachEvent('onmousewheel', this._mousewheelHandler);
  10781. root.detachEvent('onmousemove', this._mousemoveHandler);
  10782. root.detachEvent('onmouseout', this._mouseoutHandler);
  10783. root.detachEvent('onmousedown', this._mousedownHandler);
  10784. root.detachEvent('onmouseup', this._mouseupHandler);
  10785. }
  10786. this.root = this._domHover = this.storage = this.painter = null;
  10787. this.un();
  10788. };
  10789. Handler.prototype._processDragStart = function (event) {
  10790. var _lastHover = this._lastHover;
  10791. if (this._isMouseDown && _lastHover && _lastHover.draggable && !this._draggingTarget && this._mouseDownTarget == _lastHover) {
  10792. if (_lastHover.dragEnableTime && new Date() - this._lastMouseDownMoment < _lastHover.dragEnableTime) {
  10793. return;
  10794. }
  10795. var _draggingTarget = _lastHover;
  10796. this._draggingTarget = _draggingTarget;
  10797. this._isDragging = 1;
  10798. _draggingTarget.invisible = true;
  10799. this.storage.mod(_draggingTarget.id);
  10800. this._dispatchAgency(_draggingTarget, EVENT.DRAGSTART, event);
  10801. this.painter.refresh();
  10802. }
  10803. };
  10804. Handler.prototype._processDragEnter = function (event) {
  10805. if (this._draggingTarget) {
  10806. this._dispatchAgency(this._lastHover, EVENT.DRAGENTER, event, this._draggingTarget);
  10807. }
  10808. };
  10809. Handler.prototype._processDragOver = function (event) {
  10810. if (this._draggingTarget) {
  10811. this._dispatchAgency(this._lastHover, EVENT.DRAGOVER, event, this._draggingTarget);
  10812. }
  10813. };
  10814. Handler.prototype._processDragLeave = function (event) {
  10815. if (this._draggingTarget) {
  10816. this._dispatchAgency(this._lastHover, EVENT.DRAGLEAVE, event, this._draggingTarget);
  10817. }
  10818. };
  10819. Handler.prototype._processDrop = function (event) {
  10820. if (this._draggingTarget) {
  10821. this._draggingTarget.invisible = false;
  10822. this.storage.mod(this._draggingTarget.id);
  10823. this.painter.refresh();
  10824. this._dispatchAgency(this._lastHover, EVENT.DROP, event, this._draggingTarget);
  10825. }
  10826. };
  10827. Handler.prototype._processDragEnd = function (event) {
  10828. if (this._draggingTarget) {
  10829. this._dispatchAgency(this._draggingTarget, EVENT.DRAGEND, event);
  10830. this._lastHover = null;
  10831. }
  10832. this._isDragging = 0;
  10833. this._draggingTarget = null;
  10834. };
  10835. Handler.prototype._processOverShape = function (event) {
  10836. this._dispatchAgency(this._lastHover, EVENT.MOUSEOVER, event);
  10837. };
  10838. Handler.prototype._processOutShape = function (event) {
  10839. this._dispatchAgency(this._lastHover, EVENT.MOUSEOUT, event);
  10840. };
  10841. Handler.prototype._dispatchAgency = function (targetShape, eventName, event, draggedShape) {
  10842. var eventHandler = 'on' + eventName;
  10843. var eventPacket = {
  10844. type: eventName,
  10845. event: event,
  10846. target: targetShape,
  10847. cancelBubble: false
  10848. };
  10849. var el = targetShape;
  10850. if (draggedShape) {
  10851. eventPacket.dragged = draggedShape;
  10852. }
  10853. while (el) {
  10854. el[eventHandler] && (eventPacket.cancelBubble = el[eventHandler](eventPacket));
  10855. el.dispatch(eventName, eventPacket);
  10856. el = el.parent;
  10857. if (eventPacket.cancelBubble) {
  10858. break;
  10859. }
  10860. }
  10861. if (targetShape) {
  10862. if (!eventPacket.cancelBubble) {
  10863. this.dispatch(eventName, eventPacket);
  10864. }
  10865. } else if (!draggedShape) {
  10866. var eveObj = {
  10867. type: eventName,
  10868. event: event
  10869. };
  10870. this.dispatch(eventName, eveObj);
  10871. this.painter.eachOtherLayer(function (layer) {
  10872. if (typeof layer[eventHandler] == 'function') {
  10873. layer[eventHandler](eveObj);
  10874. }
  10875. if (layer.dispatch) {
  10876. layer.dispatch(eventName, eveObj);
  10877. }
  10878. });
  10879. }
  10880. };
  10881. Handler.prototype._iterateAndFindHover = function () {
  10882. var invTransform = mat2d.create();
  10883. return function () {
  10884. var list = this.storage.getShapeList();
  10885. var currentZLevel;
  10886. var currentLayer;
  10887. var tmp = [
  10888. 0,
  10889. 0
  10890. ];
  10891. for (var i = list.length - 1; i >= 0; i--) {
  10892. var shape = list[i];
  10893. if (currentZLevel !== shape.zlevel) {
  10894. currentLayer = this.painter.getLayer(shape.zlevel, currentLayer);
  10895. tmp[0] = this._mouseX;
  10896. tmp[1] = this._mouseY;
  10897. if (currentLayer.needTransform) {
  10898. mat2d.invert(invTransform, currentLayer.transform);
  10899. vec2.applyTransform(tmp, tmp, invTransform);
  10900. }
  10901. }
  10902. if (this._findHover(shape, tmp[0], tmp[1])) {
  10903. break;
  10904. }
  10905. }
  10906. };
  10907. }();
  10908. var MOBILE_TOUCH_OFFSETS = [
  10909. { x: 10 },
  10910. { x: -20 },
  10911. {
  10912. x: 10,
  10913. y: 10
  10914. },
  10915. { y: -20 }
  10916. ];
  10917. Handler.prototype._mobileFindFixed = function (event) {
  10918. this._lastHover = null;
  10919. this._mouseX = event.zrenderX;
  10920. this._mouseY = event.zrenderY;
  10921. this._event = event;
  10922. this._iterateAndFindHover();
  10923. for (var i = 0; !this._lastHover && i < MOBILE_TOUCH_OFFSETS.length; i++) {
  10924. var offset = MOBILE_TOUCH_OFFSETS[i];
  10925. offset.x && (this._mouseX += offset.x);
  10926. offset.y && (this._mouseY += offset.y);
  10927. this._iterateAndFindHover();
  10928. }
  10929. if (this._lastHover) {
  10930. event.zrenderX = this._mouseX;
  10931. event.zrenderY = this._mouseY;
  10932. }
  10933. };
  10934. function findHover(shape, x, y) {
  10935. if (this._draggingTarget && this._draggingTarget.id == shape.id || shape.isSilent()) {
  10936. return false;
  10937. }
  10938. var event = this._event;
  10939. if (shape.isCover(x, y)) {
  10940. if (shape.hoverable) {
  10941. this.storage.addHover(shape);
  10942. }
  10943. var p = shape.parent;
  10944. while (p) {
  10945. if (p.clipShape && !p.clipShape.isCover(this._mouseX, this._mouseY)) {
  10946. return false;
  10947. }
  10948. p = p.parent;
  10949. }
  10950. if (this._lastHover != shape) {
  10951. this._processOutShape(event);
  10952. this._processDragLeave(event);
  10953. this._lastHover = shape;
  10954. this._processDragEnter(event);
  10955. }
  10956. this._processOverShape(event);
  10957. this._processDragOver(event);
  10958. this._hasfound = 1;
  10959. return true;
  10960. }
  10961. return false;
  10962. }
  10963. Handler.prototype._zrenderEventFixed = function (event, isTouch) {
  10964. if (event.zrenderFixed) {
  10965. return event;
  10966. }
  10967. if (!isTouch) {
  10968. event = event || window.event;
  10969. var target = event.toElement || event.relatedTarget || event.srcElement || event.target;
  10970. if (target && target != this._domHover) {
  10971. event.zrenderX = (typeof event.offsetX != 'undefined' ? event.offsetX : event.layerX) + target.offsetLeft;
  10972. event.zrenderY = (typeof event.offsetY != 'undefined' ? event.offsetY : event.layerY) + target.offsetTop;
  10973. }
  10974. } else {
  10975. var touch = event.type != 'touchend' ? event.targetTouches[0] : event.changedTouches[0];
  10976. if (touch) {
  10977. var rBounding = this.painter._domRoot.getBoundingClientRect();
  10978. event.zrenderX = touch.clientX - rBounding.left;
  10979. event.zrenderY = touch.clientY - rBounding.top;
  10980. }
  10981. }
  10982. event.zrenderFixed = 1;
  10983. return event;
  10984. };
  10985. util.merge(Handler.prototype, Eventful.prototype, true);
  10986. return Handler;
  10987. });define('zrender/Painter', [
  10988. 'require',
  10989. './config',
  10990. './tool/util',
  10991. './tool/log',
  10992. './loadingEffect/Base',
  10993. './Layer',
  10994. './shape/Image'
  10995. ], function (require) {
  10996. 'use strict';
  10997. var config = require('./config');
  10998. var util = require('./tool/util');
  10999. var log = require('./tool/log');
  11000. var BaseLoadingEffect = require('./loadingEffect/Base');
  11001. var Layer = require('./Layer');
  11002. function returnFalse() {
  11003. return false;
  11004. }
  11005. function doNothing() {
  11006. }
  11007. function isLayerValid(layer) {
  11008. if (!layer) {
  11009. return false;
  11010. }
  11011. if (layer.isBuildin) {
  11012. return true;
  11013. }
  11014. if (typeof layer.resize !== 'function' || typeof layer.refresh !== 'function') {
  11015. return false;
  11016. }
  11017. return true;
  11018. }
  11019. var Painter = function (root, storage) {
  11020. this.root = root;
  11021. root.style['-webkit-tap-highlight-color'] = 'transparent';
  11022. root.style['-webkit-user-select'] = 'none';
  11023. root.style['user-select'] = 'none';
  11024. root.style['-webkit-touch-callout'] = 'none';
  11025. this.storage = storage;
  11026. root.innerHTML = '';
  11027. this._width = this._getWidth();
  11028. this._height = this._getHeight();
  11029. var domRoot = document.createElement('div');
  11030. this._domRoot = domRoot;
  11031. domRoot.style.position = 'relative';
  11032. domRoot.style.overflow = 'hidden';
  11033. domRoot.style.width = this._width + 'px';
  11034. domRoot.style.height = this._height + 'px';
  11035. root.appendChild(domRoot);
  11036. this._layers = {};
  11037. this._zlevelList = [];
  11038. this._layerConfig = {};
  11039. this._loadingEffect = new BaseLoadingEffect({});
  11040. this.shapeToImage = this._createShapeToImageProcessor();
  11041. this._bgDom = document.createElement('div');
  11042. this._bgDom.style.cssText = [
  11043. 'position:absolute;left:0px;top:0px;width:',
  11044. this._width,
  11045. 'px;height:',
  11046. this._height + 'px;',
  11047. '-webkit-user-select:none;user-select;none;',
  11048. '-webkit-touch-callout:none;'
  11049. ].join('');
  11050. this._bgDom.setAttribute('data-zr-dom-id', 'bg');
  11051. this._bgDom.className = config.elementClassName;
  11052. domRoot.appendChild(this._bgDom);
  11053. this._bgDom.onselectstart = returnFalse;
  11054. var hoverLayer = new Layer('_zrender_hover_', this);
  11055. this._layers['hover'] = hoverLayer;
  11056. domRoot.appendChild(hoverLayer.dom);
  11057. hoverLayer.initContext();
  11058. hoverLayer.dom.onselectstart = returnFalse;
  11059. hoverLayer.dom.style['-webkit-user-select'] = 'none';
  11060. hoverLayer.dom.style['user-select'] = 'none';
  11061. hoverLayer.dom.style['-webkit-touch-callout'] = 'none';
  11062. this.refreshNextFrame = null;
  11063. };
  11064. Painter.prototype.render = function (callback) {
  11065. if (this.isLoading()) {
  11066. this.hideLoading();
  11067. }
  11068. this.refresh(callback, true);
  11069. return this;
  11070. };
  11071. Painter.prototype.refresh = function (callback, paintAll) {
  11072. var list = this.storage.getShapeList(true);
  11073. this._paintList(list, paintAll);
  11074. for (var i = 0; i < this._zlevelList.length; i++) {
  11075. var z = this._zlevelList[i];
  11076. var layer = this._layers[z];
  11077. if (!layer.isBuildin && layer.refresh) {
  11078. layer.refresh();
  11079. }
  11080. }
  11081. if (typeof callback == 'function') {
  11082. callback();
  11083. }
  11084. return this;
  11085. };
  11086. Painter.prototype._preProcessLayer = function (layer) {
  11087. layer.unusedCount++;
  11088. layer.updateTransform();
  11089. };
  11090. Painter.prototype._postProcessLayer = function (layer) {
  11091. layer.dirty = false;
  11092. if (layer.unusedCount == 1) {
  11093. layer.clear();
  11094. }
  11095. };
  11096. Painter.prototype._paintList = function (list, paintAll) {
  11097. if (typeof paintAll == 'undefined') {
  11098. paintAll = false;
  11099. }
  11100. this._updateLayerStatus(list);
  11101. var currentLayer;
  11102. var currentZLevel;
  11103. var ctx;
  11104. this.eachBuildinLayer(this._preProcessLayer);
  11105. for (var i = 0, l = list.length; i < l; i++) {
  11106. var shape = list[i];
  11107. if (currentZLevel !== shape.zlevel) {
  11108. if (currentLayer) {
  11109. if (currentLayer.needTransform) {
  11110. ctx.restore();
  11111. }
  11112. ctx.flush && ctx.flush();
  11113. }
  11114. currentZLevel = shape.zlevel;
  11115. currentLayer = this.getLayer(currentZLevel);
  11116. if (!currentLayer.isBuildin) {
  11117. log('ZLevel ' + currentZLevel + ' has been used by unkown layer ' + currentLayer.id);
  11118. }
  11119. ctx = currentLayer.ctx;
  11120. currentLayer.unusedCount = 0;
  11121. if (currentLayer.dirty || paintAll) {
  11122. currentLayer.clear();
  11123. }
  11124. if (currentLayer.needTransform) {
  11125. ctx.save();
  11126. currentLayer.setTransform(ctx);
  11127. }
  11128. }
  11129. if ((currentLayer.dirty || paintAll) && !shape.invisible) {
  11130. if (!shape.onbrush || shape.onbrush && !shape.onbrush(ctx, false)) {
  11131. if (config.catchBrushException) {
  11132. try {
  11133. shape.brush(ctx, false, this.refreshNextFrame);
  11134. } catch (error) {
  11135. log(error, 'brush error of ' + shape.type, shape);
  11136. }
  11137. } else {
  11138. shape.brush(ctx, false, this.refreshNextFrame);
  11139. }
  11140. }
  11141. }
  11142. shape.__dirty = false;
  11143. }
  11144. if (currentLayer) {
  11145. if (currentLayer.needTransform) {
  11146. ctx.restore();
  11147. }
  11148. ctx.flush && ctx.flush();
  11149. }
  11150. this.eachBuildinLayer(this._postProcessLayer);
  11151. };
  11152. Painter.prototype.getLayer = function (zlevel) {
  11153. var layer = this._layers[zlevel];
  11154. if (!layer) {
  11155. layer = new Layer(zlevel, this);
  11156. layer.isBuildin = true;
  11157. if (this._layerConfig[zlevel]) {
  11158. util.merge(layer, this._layerConfig[zlevel], true);
  11159. }
  11160. layer.updateTransform();
  11161. this.insertLayer(zlevel, layer);
  11162. layer.initContext();
  11163. }
  11164. return layer;
  11165. };
  11166. Painter.prototype.insertLayer = function (zlevel, layer) {
  11167. if (this._layers[zlevel]) {
  11168. log('ZLevel ' + zlevel + ' has been used already');
  11169. return;
  11170. }
  11171. if (!isLayerValid(layer)) {
  11172. log('Layer of zlevel ' + zlevel + ' is not valid');
  11173. return;
  11174. }
  11175. var len = this._zlevelList.length;
  11176. var prevLayer = null;
  11177. var i = -1;
  11178. if (len > 0 && zlevel > this._zlevelList[0]) {
  11179. for (i = 0; i < len - 1; i++) {
  11180. if (this._zlevelList[i] < zlevel && this._zlevelList[i + 1] > zlevel) {
  11181. break;
  11182. }
  11183. }
  11184. prevLayer = this._layers[this._zlevelList[i]];
  11185. }
  11186. this._zlevelList.splice(i + 1, 0, zlevel);
  11187. var prevDom = prevLayer ? prevLayer.dom : this._bgDom;
  11188. if (prevDom.nextSibling) {
  11189. prevDom.parentNode.insertBefore(layer.dom, prevDom.nextSibling);
  11190. } else {
  11191. prevDom.parentNode.appendChild(layer.dom);
  11192. }
  11193. this._layers[zlevel] = layer;
  11194. };
  11195. Painter.prototype.eachLayer = function (cb, context) {
  11196. for (var i = 0; i < this._zlevelList.length; i++) {
  11197. var z = this._zlevelList[i];
  11198. cb.call(context, this._layers[z], z);
  11199. }
  11200. };
  11201. Painter.prototype.eachBuildinLayer = function (cb, context) {
  11202. for (var i = 0; i < this._zlevelList.length; i++) {
  11203. var z = this._zlevelList[i];
  11204. var layer = this._layers[z];
  11205. if (layer.isBuildin) {
  11206. cb.call(context, layer, z);
  11207. }
  11208. }
  11209. };
  11210. Painter.prototype.eachOtherLayer = function (cb, context) {
  11211. for (var i = 0; i < this._zlevelList.length; i++) {
  11212. var z = this._zlevelList[i];
  11213. var layer = this._layers[z];
  11214. if (!layer.isBuildin) {
  11215. cb.call(context, layer, z);
  11216. }
  11217. }
  11218. };
  11219. Painter.prototype.getLayers = function () {
  11220. return this._layers;
  11221. };
  11222. Painter.prototype._updateLayerStatus = function (list) {
  11223. var layers = this._layers;
  11224. var elCounts = {};
  11225. this.eachBuildinLayer(function (layer, z) {
  11226. elCounts[z] = layer.elCount;
  11227. layer.elCount = 0;
  11228. });
  11229. for (var i = 0, l = list.length; i < l; i++) {
  11230. var shape = list[i];
  11231. var zlevel = shape.zlevel;
  11232. var layer = layers[zlevel];
  11233. if (layer) {
  11234. layer.elCount++;
  11235. if (layer.dirty) {
  11236. continue;
  11237. }
  11238. layer.dirty = shape.__dirty;
  11239. }
  11240. }
  11241. this.eachBuildinLayer(function (layer, z) {
  11242. if (elCounts[z] !== layer.elCount) {
  11243. layer.dirty = true;
  11244. }
  11245. });
  11246. };
  11247. Painter.prototype.refreshShapes = function (shapeList, callback) {
  11248. for (var i = 0, l = shapeList.length; i < l; i++) {
  11249. var shape = shapeList[i];
  11250. shape.modSelf();
  11251. }
  11252. this.refresh(callback);
  11253. return this;
  11254. };
  11255. Painter.prototype.setLoadingEffect = function (loadingEffect) {
  11256. this._loadingEffect = loadingEffect;
  11257. return this;
  11258. };
  11259. Painter.prototype.clear = function () {
  11260. this.eachBuildinLayer(this._clearLayer);
  11261. return this;
  11262. };
  11263. Painter.prototype._clearLayer = function (layer) {
  11264. layer.clear();
  11265. };
  11266. Painter.prototype.modLayer = function (zlevel, config) {
  11267. if (config) {
  11268. if (!this._layerConfig[zlevel]) {
  11269. this._layerConfig[zlevel] = config;
  11270. } else {
  11271. util.merge(this._layerConfig[zlevel], config, true);
  11272. }
  11273. var layer = this._layers[zlevel];
  11274. if (layer) {
  11275. util.merge(layer, this._layerConfig[zlevel], true);
  11276. }
  11277. }
  11278. };
  11279. Painter.prototype.delLayer = function (zlevel) {
  11280. var layer = this._layers[zlevel];
  11281. if (!layer) {
  11282. return;
  11283. }
  11284. this.modLayer(zlevel, {
  11285. position: layer.position,
  11286. rotation: layer.rotation,
  11287. scale: layer.scale
  11288. });
  11289. layer.dom.parentNode.removeChild(layer.dom);
  11290. delete this._layers[zlevel];
  11291. this._zlevelList.splice(util.indexOf(this._zlevelList, zlevel), 1);
  11292. };
  11293. Painter.prototype.refreshHover = function () {
  11294. this.clearHover();
  11295. var list = this.storage.getHoverShapes(true);
  11296. for (var i = 0, l = list.length; i < l; i++) {
  11297. this._brushHover(list[i]);
  11298. }
  11299. var ctx = this._layers.hover.ctx;
  11300. ctx.flush && ctx.flush();
  11301. this.storage.delHover();
  11302. return this;
  11303. };
  11304. Painter.prototype.clearHover = function () {
  11305. var hover = this._layers.hover;
  11306. hover && hover.clear();
  11307. return this;
  11308. };
  11309. Painter.prototype.showLoading = function (loadingEffect) {
  11310. this._loadingEffect && this._loadingEffect.stop();
  11311. loadingEffect && this.setLoadingEffect(loadingEffect);
  11312. this._loadingEffect.start(this);
  11313. this.loading = true;
  11314. return this;
  11315. };
  11316. Painter.prototype.hideLoading = function () {
  11317. this._loadingEffect.stop();
  11318. this.clearHover();
  11319. this.loading = false;
  11320. return this;
  11321. };
  11322. Painter.prototype.isLoading = function () {
  11323. return this.loading;
  11324. };
  11325. Painter.prototype.resize = function () {
  11326. var domRoot = this._domRoot;
  11327. domRoot.style.display = 'none';
  11328. var width = this._getWidth();
  11329. var height = this._getHeight();
  11330. domRoot.style.display = '';
  11331. if (this._width != width || height != this._height) {
  11332. this._width = width;
  11333. this._height = height;
  11334. domRoot.style.width = width + 'px';
  11335. domRoot.style.height = height + 'px';
  11336. for (var id in this._layers) {
  11337. this._layers[id].resize(width, height);
  11338. }
  11339. this.refresh(null, true);
  11340. }
  11341. return this;
  11342. };
  11343. Painter.prototype.clearLayer = function (zLevel) {
  11344. var layer = this._layers[zLevel];
  11345. if (layer) {
  11346. layer.clear();
  11347. }
  11348. };
  11349. Painter.prototype.dispose = function () {
  11350. if (this.isLoading()) {
  11351. this.hideLoading();
  11352. }
  11353. this.root.innerHTML = '';
  11354. this.root = this.storage = this._domRoot = this._layers = null;
  11355. };
  11356. Painter.prototype.getDomHover = function () {
  11357. return this._layers.hover.dom;
  11358. };
  11359. Painter.prototype.toDataURL = function (type, backgroundColor, args) {
  11360. if (window['G_vmlCanvasManager']) {
  11361. return null;
  11362. }
  11363. var imageLayer = new Layer('image', this);
  11364. this._bgDom.appendChild(imageLayer.dom);
  11365. imageLayer.initContext();
  11366. var ctx = imageLayer.ctx;
  11367. imageLayer.clearColor = backgroundColor || '#fff';
  11368. imageLayer.clear();
  11369. var self = this;
  11370. this.storage.iterShape(function (shape) {
  11371. if (!shape.invisible) {
  11372. if (!shape.onbrush || shape.onbrush && !shape.onbrush(ctx, false)) {
  11373. if (config.catchBrushException) {
  11374. try {
  11375. shape.brush(ctx, false, self.refreshNextFrame);
  11376. } catch (error) {
  11377. log(error, 'brush error of ' + shape.type, shape);
  11378. }
  11379. } else {
  11380. shape.brush(ctx, false, self.refreshNextFrame);
  11381. }
  11382. }
  11383. }
  11384. }, {
  11385. normal: 'up',
  11386. update: true
  11387. });
  11388. var image = imageLayer.dom.toDataURL(type, args);
  11389. ctx = null;
  11390. this._bgDom.removeChild(imageLayer.dom);
  11391. return image;
  11392. };
  11393. Painter.prototype.getWidth = function () {
  11394. return this._width;
  11395. };
  11396. Painter.prototype.getHeight = function () {
  11397. return this._height;
  11398. };
  11399. Painter.prototype._getWidth = function () {
  11400. var root = this.root;
  11401. var stl = root.currentStyle || document.defaultView.getComputedStyle(root);
  11402. return ((root.clientWidth || parseInt(stl.width, 10)) - parseInt(stl.paddingLeft, 10) - parseInt(stl.paddingRight, 10)).toFixed(0) - 0;
  11403. };
  11404. Painter.prototype._getHeight = function () {
  11405. var root = this.root;
  11406. var stl = root.currentStyle || document.defaultView.getComputedStyle(root);
  11407. return ((root.clientHeight || parseInt(stl.height, 10)) - parseInt(stl.paddingTop, 10) - parseInt(stl.paddingBottom, 10)).toFixed(0) - 0;
  11408. };
  11409. Painter.prototype._brushHover = function (shape) {
  11410. var ctx = this._layers.hover.ctx;
  11411. if (!shape.onbrush || shape.onbrush && !shape.onbrush(ctx, true)) {
  11412. var layer = this.getLayer(shape.zlevel);
  11413. if (layer.needTransform) {
  11414. ctx.save();
  11415. layer.setTransform(ctx);
  11416. }
  11417. if (config.catchBrushException) {
  11418. try {
  11419. shape.brush(ctx, true, this.refreshNextFrame);
  11420. } catch (error) {
  11421. log(error, 'hoverBrush error of ' + shape.type, shape);
  11422. }
  11423. } else {
  11424. shape.brush(ctx, true, this.refreshNextFrame);
  11425. }
  11426. if (layer.needTransform) {
  11427. ctx.restore();
  11428. }
  11429. }
  11430. };
  11431. Painter.prototype._shapeToImage = function (id, shape, width, height, devicePixelRatio) {
  11432. var canvas = document.createElement('canvas');
  11433. var ctx = canvas.getContext('2d');
  11434. canvas.style.width = width + 'px';
  11435. canvas.style.height = height + 'px';
  11436. canvas.setAttribute('width', width * devicePixelRatio);
  11437. canvas.setAttribute('height', height * devicePixelRatio);
  11438. ctx.clearRect(0, 0, width * devicePixelRatio, height * devicePixelRatio);
  11439. var shapeTransform = {
  11440. position: shape.position,
  11441. rotation: shape.rotation,
  11442. scale: shape.scale
  11443. };
  11444. shape.position = [
  11445. 0,
  11446. 0,
  11447. 0
  11448. ];
  11449. shape.rotation = 0;
  11450. shape.scale = [
  11451. 1,
  11452. 1
  11453. ];
  11454. if (shape) {
  11455. shape.brush(ctx, false);
  11456. }
  11457. var ImageShape = require('./shape/Image');
  11458. var imgShape = new ImageShape({
  11459. id: id,
  11460. style: {
  11461. x: 0,
  11462. y: 0,
  11463. image: canvas
  11464. }
  11465. });
  11466. if (shapeTransform.position != null) {
  11467. imgShape.position = shape.position = shapeTransform.position;
  11468. }
  11469. if (shapeTransform.rotation != null) {
  11470. imgShape.rotation = shape.rotation = shapeTransform.rotation;
  11471. }
  11472. if (shapeTransform.scale != null) {
  11473. imgShape.scale = shape.scale = shapeTransform.scale;
  11474. }
  11475. return imgShape;
  11476. };
  11477. Painter.prototype._createShapeToImageProcessor = function () {
  11478. if (window['G_vmlCanvasManager']) {
  11479. return doNothing;
  11480. }
  11481. var me = this;
  11482. return function (id, e, width, height) {
  11483. return me._shapeToImage(id, e, width, height, config.devicePixelRatio);
  11484. };
  11485. };
  11486. return Painter;
  11487. });define('zrender/Storage', [
  11488. 'require',
  11489. './tool/util',
  11490. './Group'
  11491. ], function (require) {
  11492. 'use strict';
  11493. var util = require('./tool/util');
  11494. var Group = require('./Group');
  11495. var defaultIterateOption = {
  11496. hover: false,
  11497. normal: 'down',
  11498. update: false
  11499. };
  11500. function shapeCompareFunc(a, b) {
  11501. if (a.zlevel == b.zlevel) {
  11502. if (a.z == b.z) {
  11503. return a.__renderidx - b.__renderidx;
  11504. }
  11505. return a.z - b.z;
  11506. }
  11507. return a.zlevel - b.zlevel;
  11508. }
  11509. var Storage = function () {
  11510. this._elements = {};
  11511. this._hoverElements = [];
  11512. this._roots = [];
  11513. this._shapeList = [];
  11514. this._shapeListOffset = 0;
  11515. };
  11516. Storage.prototype.iterShape = function (fun, option) {
  11517. if (!option) {
  11518. option = defaultIterateOption;
  11519. }
  11520. if (option.hover) {
  11521. for (var i = 0, l = this._hoverElements.length; i < l; i++) {
  11522. var el = this._hoverElements[i];
  11523. el.updateTransform();
  11524. if (fun(el)) {
  11525. return this;
  11526. }
  11527. }
  11528. }
  11529. if (option.update) {
  11530. this.updateShapeList();
  11531. }
  11532. switch (option.normal) {
  11533. case 'down':
  11534. var l = this._shapeList.length;
  11535. while (l--) {
  11536. if (fun(this._shapeList[l])) {
  11537. return this;
  11538. }
  11539. }
  11540. break;
  11541. default:
  11542. for (var i = 0, l = this._shapeList.length; i < l; i++) {
  11543. if (fun(this._shapeList[i])) {
  11544. return this;
  11545. }
  11546. }
  11547. break;
  11548. }
  11549. return this;
  11550. };
  11551. Storage.prototype.getHoverShapes = function (update) {
  11552. var hoverElements = [];
  11553. for (var i = 0, l = this._hoverElements.length; i < l; i++) {
  11554. hoverElements.push(this._hoverElements[i]);
  11555. var target = this._hoverElements[i].hoverConnect;
  11556. if (target) {
  11557. var shape;
  11558. target = target instanceof Array ? target : [target];
  11559. for (var j = 0, k = target.length; j < k; j++) {
  11560. shape = target[j].id ? target[j] : this.get(target[j]);
  11561. if (shape) {
  11562. hoverElements.push(shape);
  11563. }
  11564. }
  11565. }
  11566. }
  11567. hoverElements.sort(shapeCompareFunc);
  11568. if (update) {
  11569. for (var i = 0, l = hoverElements.length; i < l; i++) {
  11570. hoverElements[i].updateTransform();
  11571. }
  11572. }
  11573. return hoverElements;
  11574. };
  11575. Storage.prototype.getShapeList = function (update) {
  11576. if (update) {
  11577. this.updateShapeList();
  11578. }
  11579. return this._shapeList;
  11580. };
  11581. Storage.prototype.updateShapeList = function () {
  11582. this._shapeListOffset = 0;
  11583. for (var i = 0, len = this._roots.length; i < len; i++) {
  11584. var root = this._roots[i];
  11585. this._updateAndAddShape(root);
  11586. }
  11587. this._shapeList.length = this._shapeListOffset;
  11588. for (var i = 0, len = this._shapeList.length; i < len; i++) {
  11589. this._shapeList[i].__renderidx = i;
  11590. }
  11591. this._shapeList.sort(shapeCompareFunc);
  11592. };
  11593. Storage.prototype._updateAndAddShape = function (el, clipShapes) {
  11594. if (el.ignore) {
  11595. return;
  11596. }
  11597. el.updateTransform();
  11598. if (el.clipShape) {
  11599. el.clipShape.parent = el;
  11600. el.clipShape.updateTransform();
  11601. if (clipShapes) {
  11602. clipShapes = clipShapes.slice();
  11603. clipShapes.push(el.clipShape);
  11604. } else {
  11605. clipShapes = [el.clipShape];
  11606. }
  11607. }
  11608. if (el.type == 'group') {
  11609. for (var i = 0; i < el._children.length; i++) {
  11610. var child = el._children[i];
  11611. child.__dirty = el.__dirty || child.__dirty;
  11612. this._updateAndAddShape(child, clipShapes);
  11613. }
  11614. el.__dirty = false;
  11615. } else {
  11616. el.__clipShapes = clipShapes;
  11617. this._shapeList[this._shapeListOffset++] = el;
  11618. }
  11619. };
  11620. Storage.prototype.mod = function (el, params) {
  11621. if (typeof el === 'string') {
  11622. el = this._elements[el];
  11623. }
  11624. if (el) {
  11625. el.modSelf();
  11626. if (params) {
  11627. if (params.parent || params._storage || params.__clipShapes) {
  11628. var target = {};
  11629. for (var name in params) {
  11630. if (name === 'parent' || name === '_storage' || name === '__clipShapes') {
  11631. continue;
  11632. }
  11633. if (params.hasOwnProperty(name)) {
  11634. target[name] = params[name];
  11635. }
  11636. }
  11637. util.merge(el, target, true);
  11638. } else {
  11639. util.merge(el, params, true);
  11640. }
  11641. }
  11642. }
  11643. return this;
  11644. };
  11645. Storage.prototype.drift = function (shapeId, dx, dy) {
  11646. var shape = this._elements[shapeId];
  11647. if (shape) {
  11648. shape.needTransform = true;
  11649. if (shape.draggable === 'horizontal') {
  11650. dy = 0;
  11651. } else if (shape.draggable === 'vertical') {
  11652. dx = 0;
  11653. }
  11654. if (!shape.ondrift || shape.ondrift && !shape.ondrift(dx, dy)) {
  11655. shape.drift(dx, dy);
  11656. }
  11657. }
  11658. return this;
  11659. };
  11660. Storage.prototype.addHover = function (shape) {
  11661. shape.updateNeedTransform();
  11662. this._hoverElements.push(shape);
  11663. return this;
  11664. };
  11665. Storage.prototype.delHover = function () {
  11666. this._hoverElements = [];
  11667. return this;
  11668. };
  11669. Storage.prototype.hasHoverShape = function () {
  11670. return this._hoverElements.length > 0;
  11671. };
  11672. Storage.prototype.addRoot = function (el) {
  11673. if (this._elements[el.id]) {
  11674. return;
  11675. }
  11676. if (el instanceof Group) {
  11677. el.addChildrenToStorage(this);
  11678. }
  11679. this.addToMap(el);
  11680. this._roots.push(el);
  11681. };
  11682. Storage.prototype.delRoot = function (elId) {
  11683. if (typeof elId == 'undefined') {
  11684. for (var i = 0; i < this._roots.length; i++) {
  11685. var root = this._roots[i];
  11686. if (root instanceof Group) {
  11687. root.delChildrenFromStorage(this);
  11688. }
  11689. }
  11690. this._elements = {};
  11691. this._hoverElements = [];
  11692. this._roots = [];
  11693. this._shapeList = [];
  11694. this._shapeListOffset = 0;
  11695. return;
  11696. }
  11697. if (elId instanceof Array) {
  11698. for (var i = 0, l = elId.length; i < l; i++) {
  11699. this.delRoot(elId[i]);
  11700. }
  11701. return;
  11702. }
  11703. var el;
  11704. if (typeof elId == 'string') {
  11705. el = this._elements[elId];
  11706. } else {
  11707. el = elId;
  11708. }
  11709. var idx = util.indexOf(this._roots, el);
  11710. if (idx >= 0) {
  11711. this.delFromMap(el.id);
  11712. this._roots.splice(idx, 1);
  11713. if (el instanceof Group) {
  11714. el.delChildrenFromStorage(this);
  11715. }
  11716. }
  11717. };
  11718. Storage.prototype.addToMap = function (el) {
  11719. if (el instanceof Group) {
  11720. el._storage = this;
  11721. }
  11722. el.modSelf();
  11723. this._elements[el.id] = el;
  11724. return this;
  11725. };
  11726. Storage.prototype.get = function (elId) {
  11727. return this._elements[elId];
  11728. };
  11729. Storage.prototype.delFromMap = function (elId) {
  11730. var el = this._elements[elId];
  11731. if (el) {
  11732. delete this._elements[elId];
  11733. if (el instanceof Group) {
  11734. el._storage = null;
  11735. }
  11736. }
  11737. return this;
  11738. };
  11739. Storage.prototype.dispose = function () {
  11740. this._elements = this._renderList = this._roots = this._hoverElements = null;
  11741. };
  11742. return Storage;
  11743. });define('zrender/animation/Animation', [
  11744. 'require',
  11745. './Clip',
  11746. '../tool/color',
  11747. '../tool/util',
  11748. '../tool/event'
  11749. ], function (require) {
  11750. 'use strict';
  11751. var Clip = require('./Clip');
  11752. var color = require('../tool/color');
  11753. var util = require('../tool/util');
  11754. var Dispatcher = require('../tool/event').Dispatcher;
  11755. var requestAnimationFrame = window.requestAnimationFrame || window.msRequestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || function (func) {
  11756. setTimeout(func, 16);
  11757. };
  11758. var arraySlice = Array.prototype.slice;
  11759. var Animation = function (options) {
  11760. options = options || {};
  11761. this.stage = options.stage || {};
  11762. this.onframe = options.onframe || function () {
  11763. };
  11764. this._clips = [];
  11765. this._running = false;
  11766. this._time = 0;
  11767. Dispatcher.call(this);
  11768. };
  11769. Animation.prototype = {
  11770. add: function (clip) {
  11771. this._clips.push(clip);
  11772. },
  11773. remove: function (clip) {
  11774. if (clip.__inStep) {
  11775. clip.__needsRemove = true;
  11776. } else {
  11777. var idx = util.indexOf(this._clips, clip);
  11778. if (idx >= 0) {
  11779. this._clips.splice(idx, 1);
  11780. }
  11781. }
  11782. },
  11783. _update: function () {
  11784. var time = new Date().getTime();
  11785. var delta = time - this._time;
  11786. var clips = this._clips;
  11787. var len = clips.length;
  11788. var deferredEvents = [];
  11789. var deferredClips = [];
  11790. for (var i = 0; i < len; i++) {
  11791. var clip = clips[i];
  11792. clip.__inStep = true;
  11793. var e = clip.step(time);
  11794. clip.__inStep = false;
  11795. if (e) {
  11796. deferredEvents.push(e);
  11797. deferredClips.push(clip);
  11798. }
  11799. }
  11800. for (var i = 0; i < len;) {
  11801. if (clips[i].__needsRemove) {
  11802. clips[i] = clips[len - 1];
  11803. clips.pop();
  11804. len--;
  11805. } else {
  11806. i++;
  11807. }
  11808. }
  11809. len = deferredEvents.length;
  11810. for (var i = 0; i < len; i++) {
  11811. deferredClips[i].fire(deferredEvents[i]);
  11812. }
  11813. this._time = time;
  11814. this.onframe(delta);
  11815. this.dispatch('frame', delta);
  11816. if (this.stage.update) {
  11817. this.stage.update();
  11818. }
  11819. },
  11820. start: function () {
  11821. var self = this;
  11822. this._running = true;
  11823. function step() {
  11824. if (self._running) {
  11825. requestAnimationFrame(step);
  11826. self._update();
  11827. }
  11828. }
  11829. this._time = new Date().getTime();
  11830. requestAnimationFrame(step);
  11831. },
  11832. stop: function () {
  11833. this._running = false;
  11834. },
  11835. clear: function () {
  11836. this._clips = [];
  11837. },
  11838. animate: function (target, options) {
  11839. options = options || {};
  11840. var deferred = new Animator(target, options.loop, options.getter, options.setter);
  11841. deferred.animation = this;
  11842. return deferred;
  11843. },
  11844. constructor: Animation
  11845. };
  11846. util.merge(Animation.prototype, Dispatcher.prototype, true);
  11847. function _defaultGetter(target, key) {
  11848. return target[key];
  11849. }
  11850. function _defaultSetter(target, key, value) {
  11851. target[key] = value;
  11852. }
  11853. function _interpolateNumber(p0, p1, percent) {
  11854. return (p1 - p0) * percent + p0;
  11855. }
  11856. function _interpolateArray(p0, p1, percent, out, arrDim) {
  11857. var len = p0.length;
  11858. if (arrDim == 1) {
  11859. for (var i = 0; i < len; i++) {
  11860. out[i] = _interpolateNumber(p0[i], p1[i], percent);
  11861. }
  11862. } else {
  11863. var len2 = p0[0].length;
  11864. for (var i = 0; i < len; i++) {
  11865. for (var j = 0; j < len2; j++) {
  11866. out[i][j] = _interpolateNumber(p0[i][j], p1[i][j], percent);
  11867. }
  11868. }
  11869. }
  11870. }
  11871. function _isArrayLike(data) {
  11872. switch (typeof data) {
  11873. case 'undefined':
  11874. case 'string':
  11875. return false;
  11876. }
  11877. return typeof data.length !== 'undefined';
  11878. }
  11879. function _catmullRomInterpolateArray(p0, p1, p2, p3, t, t2, t3, out, arrDim) {
  11880. var len = p0.length;
  11881. if (arrDim == 1) {
  11882. for (var i = 0; i < len; i++) {
  11883. out[i] = _catmullRomInterpolate(p0[i], p1[i], p2[i], p3[i], t, t2, t3);
  11884. }
  11885. } else {
  11886. var len2 = p0[0].length;
  11887. for (var i = 0; i < len; i++) {
  11888. for (var j = 0; j < len2; j++) {
  11889. out[i][j] = _catmullRomInterpolate(p0[i][j], p1[i][j], p2[i][j], p3[i][j], t, t2, t3);
  11890. }
  11891. }
  11892. }
  11893. }
  11894. function _catmullRomInterpolate(p0, p1, p2, p3, t, t2, t3) {
  11895. var v0 = (p2 - p0) * 0.5;
  11896. var v1 = (p3 - p1) * 0.5;
  11897. return (2 * (p1 - p2) + v0 + v1) * t3 + (-3 * (p1 - p2) - 2 * v0 - v1) * t2 + v0 * t + p1;
  11898. }
  11899. function _cloneValue(value) {
  11900. if (_isArrayLike(value)) {
  11901. var len = value.length;
  11902. if (_isArrayLike(value[0])) {
  11903. var ret = [];
  11904. for (var i = 0; i < len; i++) {
  11905. ret.push(arraySlice.call(value[i]));
  11906. }
  11907. return ret;
  11908. } else {
  11909. return arraySlice.call(value);
  11910. }
  11911. } else {
  11912. return value;
  11913. }
  11914. }
  11915. function rgba2String(rgba) {
  11916. rgba[0] = Math.floor(rgba[0]);
  11917. rgba[1] = Math.floor(rgba[1]);
  11918. rgba[2] = Math.floor(rgba[2]);
  11919. return 'rgba(' + rgba.join(',') + ')';
  11920. }
  11921. var Animator = function (target, loop, getter, setter) {
  11922. this._tracks = {};
  11923. this._target = target;
  11924. this._loop = loop || false;
  11925. this._getter = getter || _defaultGetter;
  11926. this._setter = setter || _defaultSetter;
  11927. this._clipCount = 0;
  11928. this._delay = 0;
  11929. this._doneList = [];
  11930. this._onframeList = [];
  11931. this._clipList = [];
  11932. };
  11933. Animator.prototype = {
  11934. when: function (time, props) {
  11935. for (var propName in props) {
  11936. if (!this._tracks[propName]) {
  11937. this._tracks[propName] = [];
  11938. if (time !== 0) {
  11939. this._tracks[propName].push({
  11940. time: 0,
  11941. value: _cloneValue(this._getter(this._target, propName))
  11942. });
  11943. }
  11944. }
  11945. this._tracks[propName].push({
  11946. time: parseInt(time, 10),
  11947. value: props[propName]
  11948. });
  11949. }
  11950. return this;
  11951. },
  11952. during: function (callback) {
  11953. this._onframeList.push(callback);
  11954. return this;
  11955. },
  11956. start: function (easing) {
  11957. var self = this;
  11958. var setter = this._setter;
  11959. var getter = this._getter;
  11960. var useSpline = easing === 'spline';
  11961. var ondestroy = function () {
  11962. self._clipCount--;
  11963. if (self._clipCount === 0) {
  11964. self._tracks = {};
  11965. var len = self._doneList.length;
  11966. for (var i = 0; i < len; i++) {
  11967. self._doneList[i].call(self);
  11968. }
  11969. }
  11970. };
  11971. var createTrackClip = function (keyframes, propName) {
  11972. var trackLen = keyframes.length;
  11973. if (!trackLen) {
  11974. return;
  11975. }
  11976. var firstVal = keyframes[0].value;
  11977. var isValueArray = _isArrayLike(firstVal);
  11978. var isValueColor = false;
  11979. var arrDim = isValueArray && _isArrayLike(firstVal[0]) ? 2 : 1;
  11980. keyframes.sort(function (a, b) {
  11981. return a.time - b.time;
  11982. });
  11983. var trackMaxTime;
  11984. if (trackLen) {
  11985. trackMaxTime = keyframes[trackLen - 1].time;
  11986. } else {
  11987. return;
  11988. }
  11989. var kfPercents = [];
  11990. var kfValues = [];
  11991. for (var i = 0; i < trackLen; i++) {
  11992. kfPercents.push(keyframes[i].time / trackMaxTime);
  11993. var value = keyframes[i].value;
  11994. if (typeof value == 'string') {
  11995. value = color.toArray(value);
  11996. if (value.length === 0) {
  11997. value[0] = value[1] = value[2] = 0;
  11998. value[3] = 1;
  11999. }
  12000. isValueColor = true;
  12001. }
  12002. kfValues.push(value);
  12003. }
  12004. var cacheKey = 0;
  12005. var cachePercent = 0;
  12006. var start;
  12007. var i;
  12008. var w;
  12009. var p0;
  12010. var p1;
  12011. var p2;
  12012. var p3;
  12013. if (isValueColor) {
  12014. var rgba = [
  12015. 0,
  12016. 0,
  12017. 0,
  12018. 0
  12019. ];
  12020. }
  12021. var onframe = function (target, percent) {
  12022. if (percent < cachePercent) {
  12023. start = Math.min(cacheKey + 1, trackLen - 1);
  12024. for (i = start; i >= 0; i--) {
  12025. if (kfPercents[i] <= percent) {
  12026. break;
  12027. }
  12028. }
  12029. i = Math.min(i, trackLen - 2);
  12030. } else {
  12031. for (i = cacheKey; i < trackLen; i++) {
  12032. if (kfPercents[i] > percent) {
  12033. break;
  12034. }
  12035. }
  12036. i = Math.min(i - 1, trackLen - 2);
  12037. }
  12038. cacheKey = i;
  12039. cachePercent = percent;
  12040. var range = kfPercents[i + 1] - kfPercents[i];
  12041. if (range === 0) {
  12042. return;
  12043. } else {
  12044. w = (percent - kfPercents[i]) / range;
  12045. }
  12046. if (useSpline) {
  12047. p1 = kfValues[i];
  12048. p0 = kfValues[i === 0 ? i : i - 1];
  12049. p2 = kfValues[i > trackLen - 2 ? trackLen - 1 : i + 1];
  12050. p3 = kfValues[i > trackLen - 3 ? trackLen - 1 : i + 2];
  12051. if (isValueArray) {
  12052. _catmullRomInterpolateArray(p0, p1, p2, p3, w, w * w, w * w * w, getter(target, propName), arrDim);
  12053. } else {
  12054. var value;
  12055. if (isValueColor) {
  12056. value = _catmullRomInterpolateArray(p0, p1, p2, p3, w, w * w, w * w * w, rgba, 1);
  12057. value = rgba2String(rgba);
  12058. } else {
  12059. value = _catmullRomInterpolate(p0, p1, p2, p3, w, w * w, w * w * w);
  12060. }
  12061. setter(target, propName, value);
  12062. }
  12063. } else {
  12064. if (isValueArray) {
  12065. _interpolateArray(kfValues[i], kfValues[i + 1], w, getter(target, propName), arrDim);
  12066. } else {
  12067. var value;
  12068. if (isValueColor) {
  12069. _interpolateArray(kfValues[i], kfValues[i + 1], w, rgba, 1);
  12070. value = rgba2String(rgba);
  12071. } else {
  12072. value = _interpolateNumber(kfValues[i], kfValues[i + 1], w);
  12073. }
  12074. setter(target, propName, value);
  12075. }
  12076. }
  12077. for (i = 0; i < self._onframeList.length; i++) {
  12078. self._onframeList[i](target, percent);
  12079. }
  12080. };
  12081. var clip = new Clip({
  12082. target: self._target,
  12083. life: trackMaxTime,
  12084. loop: self._loop,
  12085. delay: self._delay,
  12086. onframe: onframe,
  12087. ondestroy: ondestroy
  12088. });
  12089. if (easing && easing !== 'spline') {
  12090. clip.easing = easing;
  12091. }
  12092. self._clipList.push(clip);
  12093. self._clipCount++;
  12094. self.animation.add(clip);
  12095. };
  12096. for (var propName in this._tracks) {
  12097. createTrackClip(this._tracks[propName], propName);
  12098. }
  12099. return this;
  12100. },
  12101. stop: function () {
  12102. for (var i = 0; i < this._clipList.length; i++) {
  12103. var clip = this._clipList[i];
  12104. this.animation.remove(clip);
  12105. }
  12106. this._clipList = [];
  12107. },
  12108. delay: function (time) {
  12109. this._delay = time;
  12110. return this;
  12111. },
  12112. done: function (cb) {
  12113. if (cb) {
  12114. this._doneList.push(cb);
  12115. }
  12116. return this;
  12117. }
  12118. };
  12119. return Animation;
  12120. });define('zrender/tool/vector', [], function () {
  12121. var ArrayCtor = typeof Float32Array === 'undefined' ? Array : Float32Array;
  12122. var vector = {
  12123. create: function (x, y) {
  12124. var out = new ArrayCtor(2);
  12125. out[0] = x || 0;
  12126. out[1] = y || 0;
  12127. return out;
  12128. },
  12129. copy: function (out, v) {
  12130. out[0] = v[0];
  12131. out[1] = v[1];
  12132. return out;
  12133. },
  12134. clone: function (v) {
  12135. var out = new ArrayCtor(2);
  12136. out[0] = v[0];
  12137. out[1] = v[1];
  12138. return out;
  12139. },
  12140. set: function (out, a, b) {
  12141. out[0] = a;
  12142. out[1] = b;
  12143. return out;
  12144. },
  12145. add: function (out, v1, v2) {
  12146. out[0] = v1[0] + v2[0];
  12147. out[1] = v1[1] + v2[1];
  12148. return out;
  12149. },
  12150. scaleAndAdd: function (out, v1, v2, a) {
  12151. out[0] = v1[0] + v2[0] * a;
  12152. out[1] = v1[1] + v2[1] * a;
  12153. return out;
  12154. },
  12155. sub: function (out, v1, v2) {
  12156. out[0] = v1[0] - v2[0];
  12157. out[1] = v1[1] - v2[1];
  12158. return out;
  12159. },
  12160. len: function (v) {
  12161. return Math.sqrt(this.lenSquare(v));
  12162. },
  12163. lenSquare: function (v) {
  12164. return v[0] * v[0] + v[1] * v[1];
  12165. },
  12166. mul: function (out, v1, v2) {
  12167. out[0] = v1[0] * v2[0];
  12168. out[1] = v1[1] * v2[1];
  12169. return out;
  12170. },
  12171. div: function (out, v1, v2) {
  12172. out[0] = v1[0] / v2[0];
  12173. out[1] = v1[1] / v2[1];
  12174. return out;
  12175. },
  12176. dot: function (v1, v2) {
  12177. return v1[0] * v2[0] + v1[1] * v2[1];
  12178. },
  12179. scale: function (out, v, s) {
  12180. out[0] = v[0] * s;
  12181. out[1] = v[1] * s;
  12182. return out;
  12183. },
  12184. normalize: function (out, v) {
  12185. var d = vector.len(v);
  12186. if (d === 0) {
  12187. out[0] = 0;
  12188. out[1] = 0;
  12189. } else {
  12190. out[0] = v[0] / d;
  12191. out[1] = v[1] / d;
  12192. }
  12193. return out;
  12194. },
  12195. distance: function (v1, v2) {
  12196. return Math.sqrt((v1[0] - v2[0]) * (v1[0] - v2[0]) + (v1[1] - v2[1]) * (v1[1] - v2[1]));
  12197. },
  12198. distanceSquare: function (v1, v2) {
  12199. return (v1[0] - v2[0]) * (v1[0] - v2[0]) + (v1[1] - v2[1]) * (v1[1] - v2[1]);
  12200. },
  12201. negate: function (out, v) {
  12202. out[0] = -v[0];
  12203. out[1] = -v[1];
  12204. return out;
  12205. },
  12206. lerp: function (out, v1, v2, t) {
  12207. out[0] = v1[0] + t * (v2[0] - v1[0]);
  12208. out[1] = v1[1] + t * (v2[1] - v1[1]);
  12209. return out;
  12210. },
  12211. applyTransform: function (out, v, m) {
  12212. var x = v[0];
  12213. var y = v[1];
  12214. out[0] = m[0] * x + m[2] * y + m[4];
  12215. out[1] = m[1] * x + m[3] * y + m[5];
  12216. return out;
  12217. },
  12218. min: function (out, v1, v2) {
  12219. out[0] = Math.min(v1[0], v2[0]);
  12220. out[1] = Math.min(v1[1], v2[1]);
  12221. return out;
  12222. },
  12223. max: function (out, v1, v2) {
  12224. out[0] = Math.max(v1[0], v2[0]);
  12225. out[1] = Math.max(v1[1], v2[1]);
  12226. return out;
  12227. }
  12228. };
  12229. vector.length = vector.len;
  12230. vector.lengthSquare = vector.lenSquare;
  12231. vector.dist = vector.distance;
  12232. vector.distSquare = vector.distanceSquare;
  12233. return vector;
  12234. });define('zrender/tool/matrix', [], function () {
  12235. var ArrayCtor = typeof Float32Array === 'undefined' ? Array : Float32Array;
  12236. var matrix = {
  12237. create: function () {
  12238. var out = new ArrayCtor(6);
  12239. matrix.identity(out);
  12240. return out;
  12241. },
  12242. identity: function (out) {
  12243. out[0] = 1;
  12244. out[1] = 0;
  12245. out[2] = 0;
  12246. out[3] = 1;
  12247. out[4] = 0;
  12248. out[5] = 0;
  12249. return out;
  12250. },
  12251. copy: function (out, m) {
  12252. out[0] = m[0];
  12253. out[1] = m[1];
  12254. out[2] = m[2];
  12255. out[3] = m[3];
  12256. out[4] = m[4];
  12257. out[5] = m[5];
  12258. return out;
  12259. },
  12260. mul: function (out, m1, m2) {
  12261. out[0] = m1[0] * m2[0] + m1[2] * m2[1];
  12262. out[1] = m1[1] * m2[0] + m1[3] * m2[1];
  12263. out[2] = m1[0] * m2[2] + m1[2] * m2[3];
  12264. out[3] = m1[1] * m2[2] + m1[3] * m2[3];
  12265. out[4] = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  12266. out[5] = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  12267. return out;
  12268. },
  12269. translate: function (out, a, v) {
  12270. out[0] = a[0];
  12271. out[1] = a[1];
  12272. out[2] = a[2];
  12273. out[3] = a[3];
  12274. out[4] = a[4] + v[0];
  12275. out[5] = a[5] + v[1];
  12276. return out;
  12277. },
  12278. rotate: function (out, a, rad) {
  12279. var aa = a[0];
  12280. var ac = a[2];
  12281. var atx = a[4];
  12282. var ab = a[1];
  12283. var ad = a[3];
  12284. var aty = a[5];
  12285. var st = Math.sin(rad);
  12286. var ct = Math.cos(rad);
  12287. out[0] = aa * ct + ab * st;
  12288. out[1] = -aa * st + ab * ct;
  12289. out[2] = ac * ct + ad * st;
  12290. out[3] = -ac * st + ct * ad;
  12291. out[4] = ct * atx + st * aty;
  12292. out[5] = ct * aty - st * atx;
  12293. return out;
  12294. },
  12295. scale: function (out, a, v) {
  12296. var vx = v[0];
  12297. var vy = v[1];
  12298. out[0] = a[0] * vx;
  12299. out[1] = a[1] * vy;
  12300. out[2] = a[2] * vx;
  12301. out[3] = a[3] * vy;
  12302. out[4] = a[4] * vx;
  12303. out[5] = a[5] * vy;
  12304. return out;
  12305. },
  12306. invert: function (out, a) {
  12307. var aa = a[0];
  12308. var ac = a[2];
  12309. var atx = a[4];
  12310. var ab = a[1];
  12311. var ad = a[3];
  12312. var aty = a[5];
  12313. var det = aa * ad - ab * ac;
  12314. if (!det) {
  12315. return null;
  12316. }
  12317. det = 1 / det;
  12318. out[0] = ad * det;
  12319. out[1] = -ab * det;
  12320. out[2] = -ac * det;
  12321. out[3] = aa * det;
  12322. out[4] = (ac * aty - ad * atx) * det;
  12323. out[5] = (ab * atx - aa * aty) * det;
  12324. return out;
  12325. }
  12326. };
  12327. return matrix;
  12328. });define('zrender/loadingEffect/Base', [
  12329. 'require',
  12330. '../tool/util',
  12331. '../shape/Text',
  12332. '../shape/Rectangle'
  12333. ], function (require) {
  12334. var util = require('../tool/util');
  12335. var TextShape = require('../shape/Text');
  12336. var RectangleShape = require('../shape/Rectangle');
  12337. var DEFAULT_TEXT = 'Loading...';
  12338. var DEFAULT_TEXT_FONT = 'normal 16px Arial';
  12339. function Base(options) {
  12340. this.setOptions(options);
  12341. }
  12342. Base.prototype.createTextShape = function (textStyle) {
  12343. return new TextShape({
  12344. highlightStyle: util.merge({
  12345. x: this.canvasWidth / 2,
  12346. y: this.canvasHeight / 2,
  12347. text: DEFAULT_TEXT,
  12348. textAlign: 'center',
  12349. textBaseline: 'middle',
  12350. textFont: DEFAULT_TEXT_FONT,
  12351. color: '#333',
  12352. brushType: 'fill'
  12353. }, textStyle, true)
  12354. });
  12355. };
  12356. Base.prototype.createBackgroundShape = function (color) {
  12357. return new RectangleShape({
  12358. highlightStyle: {
  12359. x: 0,
  12360. y: 0,
  12361. width: this.canvasWidth,
  12362. height: this.canvasHeight,
  12363. brushType: 'fill',
  12364. color: color
  12365. }
  12366. });
  12367. };
  12368. Base.prototype.start = function (painter) {
  12369. this.canvasWidth = painter._width;
  12370. this.canvasHeight = painter._height;
  12371. function addShapeHandle(param) {
  12372. painter.storage.addHover(param);
  12373. }
  12374. function refreshHandle() {
  12375. painter.refreshHover();
  12376. }
  12377. this.loadingTimer = this._start(addShapeHandle, refreshHandle);
  12378. };
  12379. Base.prototype._start = function () {
  12380. return setInterval(function () {
  12381. }, 10000);
  12382. };
  12383. Base.prototype.stop = function () {
  12384. clearInterval(this.loadingTimer);
  12385. };
  12386. Base.prototype.setOptions = function (options) {
  12387. this.options = options || {};
  12388. };
  12389. Base.prototype.adjust = function (value, region) {
  12390. if (value <= region[0]) {
  12391. value = region[0];
  12392. } else if (value >= region[1]) {
  12393. value = region[1];
  12394. }
  12395. return value;
  12396. };
  12397. Base.prototype.getLocation = function (loc, totalWidth, totalHeight) {
  12398. var x = loc.x != null ? loc.x : 'center';
  12399. switch (x) {
  12400. case 'center':
  12401. x = Math.floor((this.canvasWidth - totalWidth) / 2);
  12402. break;
  12403. case 'left':
  12404. x = 0;
  12405. break;
  12406. case 'right':
  12407. x = this.canvasWidth - totalWidth;
  12408. break;
  12409. }
  12410. var y = loc.y != null ? loc.y : 'center';
  12411. switch (y) {
  12412. case 'center':
  12413. y = Math.floor((this.canvasHeight - totalHeight) / 2);
  12414. break;
  12415. case 'top':
  12416. y = 0;
  12417. break;
  12418. case 'bottom':
  12419. y = this.canvasHeight - totalHeight;
  12420. break;
  12421. }
  12422. return {
  12423. x: x,
  12424. y: y,
  12425. width: totalWidth,
  12426. height: totalHeight
  12427. };
  12428. };
  12429. return Base;
  12430. });define('zrender/Layer', [
  12431. 'require',
  12432. './mixin/Transformable',
  12433. './tool/util',
  12434. './config'
  12435. ], function (require) {
  12436. var Transformable = require('./mixin/Transformable');
  12437. var util = require('./tool/util');
  12438. var vmlCanvasManager = window['G_vmlCanvasManager'];
  12439. var config = require('./config');
  12440. function returnFalse() {
  12441. return false;
  12442. }
  12443. function createDom(id, type, painter) {
  12444. var newDom = document.createElement(type);
  12445. var width = painter.getWidth();
  12446. var height = painter.getHeight();
  12447. newDom.style.position = 'absolute';
  12448. newDom.style.left = 0;
  12449. newDom.style.top = 0;
  12450. newDom.style.width = width + 'px';
  12451. newDom.style.height = height + 'px';
  12452. newDom.width = width * config.devicePixelRatio;
  12453. newDom.height = height * config.devicePixelRatio;
  12454. newDom.setAttribute('data-zr-dom-id', id);
  12455. return newDom;
  12456. }
  12457. var Layer = function (id, painter) {
  12458. this.id = id;
  12459. this.dom = createDom(id, 'canvas', painter);
  12460. this.dom.onselectstart = returnFalse;
  12461. this.dom.style['-webkit-user-select'] = 'none';
  12462. this.dom.style['user-select'] = 'none';
  12463. this.dom.style['-webkit-touch-callout'] = 'none';
  12464. this.dom.style['-webkit-tap-highlight-color'] = 'rgba(0,0,0,0)';
  12465. this.dom.className = config.elementClassName;
  12466. vmlCanvasManager && vmlCanvasManager.initElement(this.dom);
  12467. this.domBack = null;
  12468. this.ctxBack = null;
  12469. this.painter = painter;
  12470. this.unusedCount = 0;
  12471. this.config = null;
  12472. this.dirty = true;
  12473. this.elCount = 0;
  12474. this.clearColor = 0;
  12475. this.motionBlur = false;
  12476. this.lastFrameAlpha = 0.7;
  12477. this.zoomable = false;
  12478. this.panable = false;
  12479. this.maxZoom = Infinity;
  12480. this.minZoom = 0;
  12481. Transformable.call(this);
  12482. };
  12483. Layer.prototype.initContext = function () {
  12484. this.ctx = this.dom.getContext('2d');
  12485. var dpr = config.devicePixelRatio;
  12486. if (dpr != 1) {
  12487. this.ctx.scale(dpr, dpr);
  12488. }
  12489. };
  12490. Layer.prototype.createBackBuffer = function () {
  12491. if (vmlCanvasManager) {
  12492. return;
  12493. }
  12494. this.domBack = createDom('back-' + this.id, 'canvas', this.painter);
  12495. this.ctxBack = this.domBack.getContext('2d');
  12496. var dpr = config.devicePixelRatio;
  12497. if (dpr != 1) {
  12498. this.ctxBack.scale(dpr, dpr);
  12499. }
  12500. };
  12501. Layer.prototype.resize = function (width, height) {
  12502. var dpr = config.devicePixelRatio;
  12503. this.dom.style.width = width + 'px';
  12504. this.dom.style.height = height + 'px';
  12505. this.dom.setAttribute('width', width * dpr);
  12506. this.dom.setAttribute('height', height * dpr);
  12507. if (dpr != 1) {
  12508. this.ctx.scale(dpr, dpr);
  12509. }
  12510. if (this.domBack) {
  12511. this.domBack.setAttribute('width', width * dpr);
  12512. this.domBack.setAttribute('height', height * dpr);
  12513. if (dpr != 1) {
  12514. this.ctxBack.scale(dpr, dpr);
  12515. }
  12516. }
  12517. };
  12518. Layer.prototype.clear = function () {
  12519. var dom = this.dom;
  12520. var ctx = this.ctx;
  12521. var width = dom.width;
  12522. var height = dom.height;
  12523. var haveClearColor = this.clearColor && !vmlCanvasManager;
  12524. var haveMotionBLur = this.motionBlur && !vmlCanvasManager;
  12525. var lastFrameAlpha = this.lastFrameAlpha;
  12526. var dpr = config.devicePixelRatio;
  12527. if (haveMotionBLur) {
  12528. if (!this.domBack) {
  12529. this.createBackBuffer();
  12530. }
  12531. this.ctxBack.globalCompositeOperation = 'copy';
  12532. this.ctxBack.drawImage(dom, 0, 0, width / dpr, height / dpr);
  12533. }
  12534. ctx.clearRect(0, 0, width / dpr, height / dpr);
  12535. if (haveClearColor) {
  12536. ctx.save();
  12537. ctx.fillStyle = this.clearColor;
  12538. ctx.fillRect(0, 0, width / dpr, height / dpr);
  12539. ctx.restore();
  12540. }
  12541. if (haveMotionBLur) {
  12542. var domBack = this.domBack;
  12543. ctx.save();
  12544. ctx.globalAlpha = lastFrameAlpha;
  12545. ctx.drawImage(domBack, 0, 0, width / dpr, height / dpr);
  12546. ctx.restore();
  12547. }
  12548. };
  12549. util.merge(Layer.prototype, Transformable.prototype);
  12550. return Layer;
  12551. });define('zrender/shape/Text', [
  12552. 'require',
  12553. '../tool/area',
  12554. './Base',
  12555. '../tool/util'
  12556. ], function (require) {
  12557. var area = require('../tool/area');
  12558. var Base = require('./Base');
  12559. var Text = function (options) {
  12560. Base.call(this, options);
  12561. };
  12562. Text.prototype = {
  12563. type: 'text',
  12564. brush: function (ctx, isHighlight) {
  12565. var style = this.style;
  12566. if (isHighlight) {
  12567. style = this.getHighlightStyle(style, this.highlightStyle || {});
  12568. }
  12569. if (typeof style.text == 'undefined' || style.text === false) {
  12570. return;
  12571. }
  12572. ctx.save();
  12573. this.doClip(ctx);
  12574. this.setContext(ctx, style);
  12575. this.setTransform(ctx);
  12576. if (style.textFont) {
  12577. ctx.font = style.textFont;
  12578. }
  12579. ctx.textAlign = style.textAlign || 'start';
  12580. ctx.textBaseline = style.textBaseline || 'middle';
  12581. var text = (style.text + '').split('\n');
  12582. var lineHeight = area.getTextHeight('国', style.textFont);
  12583. var rect = this.getRect(style);
  12584. var x = style.x;
  12585. var y;
  12586. if (style.textBaseline == 'top') {
  12587. y = rect.y;
  12588. } else if (style.textBaseline == 'bottom') {
  12589. y = rect.y + lineHeight;
  12590. } else {
  12591. y = rect.y + lineHeight / 2;
  12592. }
  12593. for (var i = 0, l = text.length; i < l; i++) {
  12594. if (style.maxWidth) {
  12595. switch (style.brushType) {
  12596. case 'fill':
  12597. ctx.fillText(text[i], x, y, style.maxWidth);
  12598. break;
  12599. case 'stroke':
  12600. ctx.strokeText(text[i], x, y, style.maxWidth);
  12601. break;
  12602. case 'both':
  12603. ctx.fillText(text[i], x, y, style.maxWidth);
  12604. ctx.strokeText(text[i], x, y, style.maxWidth);
  12605. break;
  12606. default:
  12607. ctx.fillText(text[i], x, y, style.maxWidth);
  12608. }
  12609. } else {
  12610. switch (style.brushType) {
  12611. case 'fill':
  12612. ctx.fillText(text[i], x, y);
  12613. break;
  12614. case 'stroke':
  12615. ctx.strokeText(text[i], x, y);
  12616. break;
  12617. case 'both':
  12618. ctx.fillText(text[i], x, y);
  12619. ctx.strokeText(text[i], x, y);
  12620. break;
  12621. default:
  12622. ctx.fillText(text[i], x, y);
  12623. }
  12624. }
  12625. y += lineHeight;
  12626. }
  12627. ctx.restore();
  12628. return;
  12629. },
  12630. getRect: function (style) {
  12631. if (style.__rect) {
  12632. return style.__rect;
  12633. }
  12634. var width = area.getTextWidth(style.text, style.textFont);
  12635. var height = area.getTextHeight(style.text, style.textFont);
  12636. var textX = style.x;
  12637. if (style.textAlign == 'end' || style.textAlign == 'right') {
  12638. textX -= width;
  12639. } else if (style.textAlign == 'center') {
  12640. textX -= width / 2;
  12641. }
  12642. var textY;
  12643. if (style.textBaseline == 'top') {
  12644. textY = style.y;
  12645. } else if (style.textBaseline == 'bottom') {
  12646. textY = style.y - height;
  12647. } else {
  12648. textY = style.y - height / 2;
  12649. }
  12650. style.__rect = {
  12651. x: textX,
  12652. y: textY,
  12653. width: width,
  12654. height: height
  12655. };
  12656. return style.__rect;
  12657. }
  12658. };
  12659. require('../tool/util').inherits(Text, Base);
  12660. return Text;
  12661. });define('zrender/shape/Rectangle', [
  12662. 'require',
  12663. './Base',
  12664. '../tool/util'
  12665. ], function (require) {
  12666. var Base = require('./Base');
  12667. var Rectangle = function (options) {
  12668. Base.call(this, options);
  12669. };
  12670. Rectangle.prototype = {
  12671. type: 'rectangle',
  12672. _buildRadiusPath: function (ctx, style) {
  12673. var x = style.x;
  12674. var y = style.y;
  12675. var width = style.width;
  12676. var height = style.height;
  12677. var r = style.radius;
  12678. var r1;
  12679. var r2;
  12680. var r3;
  12681. var r4;
  12682. if (typeof r === 'number') {
  12683. r1 = r2 = r3 = r4 = r;
  12684. } else if (r instanceof Array) {
  12685. if (r.length === 1) {
  12686. r1 = r2 = r3 = r4 = r[0];
  12687. } else if (r.length === 2) {
  12688. r1 = r3 = r[0];
  12689. r2 = r4 = r[1];
  12690. } else if (r.length === 3) {
  12691. r1 = r[0];
  12692. r2 = r4 = r[1];
  12693. r3 = r[2];
  12694. } else {
  12695. r1 = r[0];
  12696. r2 = r[1];
  12697. r3 = r[2];
  12698. r4 = r[3];
  12699. }
  12700. } else {
  12701. r1 = r2 = r3 = r4 = 0;
  12702. }
  12703. var total;
  12704. if (r1 + r2 > width) {
  12705. total = r1 + r2;
  12706. r1 *= width / total;
  12707. r2 *= width / total;
  12708. }
  12709. if (r3 + r4 > width) {
  12710. total = r3 + r4;
  12711. r3 *= width / total;
  12712. r4 *= width / total;
  12713. }
  12714. if (r2 + r3 > height) {
  12715. total = r2 + r3;
  12716. r2 *= height / total;
  12717. r3 *= height / total;
  12718. }
  12719. if (r1 + r4 > height) {
  12720. total = r1 + r4;
  12721. r1 *= height / total;
  12722. r4 *= height / total;
  12723. }
  12724. ctx.moveTo(x + r1, y);
  12725. ctx.lineTo(x + width - r2, y);
  12726. r2 !== 0 && ctx.quadraticCurveTo(x + width, y, x + width, y + r2);
  12727. ctx.lineTo(x + width, y + height - r3);
  12728. r3 !== 0 && ctx.quadraticCurveTo(x + width, y + height, x + width - r3, y + height);
  12729. ctx.lineTo(x + r4, y + height);
  12730. r4 !== 0 && ctx.quadraticCurveTo(x, y + height, x, y + height - r4);
  12731. ctx.lineTo(x, y + r1);
  12732. r1 !== 0 && ctx.quadraticCurveTo(x, y, x + r1, y);
  12733. },
  12734. buildPath: function (ctx, style) {
  12735. if (!style.radius) {
  12736. ctx.moveTo(style.x, style.y);
  12737. ctx.lineTo(style.x + style.width, style.y);
  12738. ctx.lineTo(style.x + style.width, style.y + style.height);
  12739. ctx.lineTo(style.x, style.y + style.height);
  12740. ctx.lineTo(style.x, style.y);
  12741. } else {
  12742. this._buildRadiusPath(ctx, style);
  12743. }
  12744. ctx.closePath();
  12745. return;
  12746. },
  12747. getRect: function (style) {
  12748. if (style.__rect) {
  12749. return style.__rect;
  12750. }
  12751. var lineWidth;
  12752. if (style.brushType == 'stroke' || style.brushType == 'fill') {
  12753. lineWidth = style.lineWidth || 1;
  12754. } else {
  12755. lineWidth = 0;
  12756. }
  12757. style.__rect = {
  12758. x: Math.round(style.x - lineWidth / 2),
  12759. y: Math.round(style.y - lineWidth / 2),
  12760. width: style.width + lineWidth,
  12761. height: style.height + lineWidth
  12762. };
  12763. return style.__rect;
  12764. }
  12765. };
  12766. require('../tool/util').inherits(Rectangle, Base);
  12767. return Rectangle;
  12768. });define('zrender/tool/area', [
  12769. 'require',
  12770. './util',
  12771. './curve'
  12772. ], function (require) {
  12773. 'use strict';
  12774. var util = require('./util');
  12775. var curve = require('./curve');
  12776. var _ctx;
  12777. var _textWidthCache = {};
  12778. var _textHeightCache = {};
  12779. var _textWidthCacheCounter = 0;
  12780. var _textHeightCacheCounter = 0;
  12781. var TEXT_CACHE_MAX = 5000;
  12782. var PI2 = Math.PI * 2;
  12783. function normalizeRadian(angle) {
  12784. angle %= PI2;
  12785. if (angle < 0) {
  12786. angle += PI2;
  12787. }
  12788. return angle;
  12789. }
  12790. function isInside(shape, area, x, y) {
  12791. if (!area || !shape) {
  12792. return false;
  12793. }
  12794. var zoneType = shape.type;
  12795. _ctx = _ctx || util.getContext();
  12796. var _mathReturn = _mathMethod(shape, area, x, y);
  12797. if (typeof _mathReturn != 'undefined') {
  12798. return _mathReturn;
  12799. }
  12800. if (shape.buildPath && _ctx.isPointInPath) {
  12801. return _buildPathMethod(shape, _ctx, area, x, y);
  12802. }
  12803. switch (zoneType) {
  12804. case 'ellipse':
  12805. return true;
  12806. case 'trochoid':
  12807. var _r = area.location == 'out' ? area.r1 + area.r2 + area.d : area.r1 - area.r2 + area.d;
  12808. return isInsideCircle(area, x, y, _r);
  12809. case 'rose':
  12810. return isInsideCircle(area, x, y, area.maxr);
  12811. default:
  12812. return false;
  12813. }
  12814. }
  12815. function _mathMethod(shape, area, x, y) {
  12816. var zoneType = shape.type;
  12817. switch (zoneType) {
  12818. case 'bezier-curve':
  12819. if (typeof area.cpX2 === 'undefined') {
  12820. return isInsideQuadraticStroke(area.xStart, area.yStart, area.cpX1, area.cpY1, area.xEnd, area.yEnd, area.lineWidth, x, y);
  12821. }
  12822. return isInsideCubicStroke(area.xStart, area.yStart, area.cpX1, area.cpY1, area.cpX2, area.cpY2, area.xEnd, area.yEnd, area.lineWidth, x, y);
  12823. case 'line':
  12824. return isInsideLine(area.xStart, area.yStart, area.xEnd, area.yEnd, area.lineWidth, x, y);
  12825. case 'polyline':
  12826. return isInsidePolyline(area.pointList, area.lineWidth, x, y);
  12827. case 'ring':
  12828. return isInsideRing(area.x, area.y, area.r0, area.r, x, y);
  12829. case 'circle':
  12830. return isInsideCircle(area.x, area.y, area.r, x, y);
  12831. case 'sector':
  12832. var startAngle = area.startAngle * Math.PI / 180;
  12833. var endAngle = area.endAngle * Math.PI / 180;
  12834. if (!area.clockWise) {
  12835. startAngle = -startAngle;
  12836. endAngle = -endAngle;
  12837. }
  12838. return isInsideSector(area.x, area.y, area.r0, area.r, startAngle, endAngle, !area.clockWise, x, y);
  12839. case 'path':
  12840. return area.pathArray && isInsidePath(area.pathArray, Math.max(area.lineWidth, 5), area.brushType, x, y);
  12841. case 'polygon':
  12842. case 'star':
  12843. case 'isogon':
  12844. return isInsidePolygon(area.pointList, x, y);
  12845. case 'text':
  12846. var rect = area.__rect || shape.getRect(area);
  12847. return isInsideRect(rect.x, rect.y, rect.width, rect.height, x, y);
  12848. case 'rectangle':
  12849. case 'image':
  12850. return isInsideRect(area.x, area.y, area.width, area.height, x, y);
  12851. }
  12852. }
  12853. function _buildPathMethod(shape, context, area, x, y) {
  12854. context.beginPath();
  12855. shape.buildPath(context, area);
  12856. context.closePath();
  12857. return context.isPointInPath(x, y);
  12858. }
  12859. function isOutside(shape, area, x, y) {
  12860. return !isInside(shape, area, x, y);
  12861. }
  12862. function isInsideLine(x0, y0, x1, y1, lineWidth, x, y) {
  12863. if (lineWidth === 0) {
  12864. return false;
  12865. }
  12866. var _l = Math.max(lineWidth, 5);
  12867. var _a = 0;
  12868. var _b = x0;
  12869. if (y > y0 + _l && y > y1 + _l || y < y0 - _l && y < y1 - _l || x > x0 + _l && x > x1 + _l || x < x0 - _l && x < x1 - _l) {
  12870. return false;
  12871. }
  12872. if (x0 !== x1) {
  12873. _a = (y0 - y1) / (x0 - x1);
  12874. _b = (x0 * y1 - x1 * y0) / (x0 - x1);
  12875. } else {
  12876. return Math.abs(x - x0) <= _l / 2;
  12877. }
  12878. var tmp = _a * x - y + _b;
  12879. var _s = tmp * tmp / (_a * _a + 1);
  12880. return _s <= _l / 2 * _l / 2;
  12881. }
  12882. function isInsideCubicStroke(x0, y0, x1, y1, x2, y2, x3, y3, lineWidth, x, y) {
  12883. if (lineWidth === 0) {
  12884. return false;
  12885. }
  12886. var _l = Math.max(lineWidth, 5);
  12887. if (y > y0 + _l && y > y1 + _l && y > y2 + _l && y > y3 + _l || y < y0 - _l && y < y1 - _l && y < y2 - _l && y < y3 - _l || x > x0 + _l && x > x1 + _l && x > x2 + _l && x > x3 + _l || x < x0 - _l && x < x1 - _l && x < x2 - _l && x < x3 - _l) {
  12888. return false;
  12889. }
  12890. var d = curve.cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, null);
  12891. return d <= _l / 2;
  12892. }
  12893. function isInsideQuadraticStroke(x0, y0, x1, y1, x2, y2, lineWidth, x, y) {
  12894. if (lineWidth === 0) {
  12895. return false;
  12896. }
  12897. var _l = Math.max(lineWidth, 5);
  12898. if (y > y0 + _l && y > y1 + _l && y > y2 + _l || y < y0 - _l && y < y1 - _l && y < y2 - _l || x > x0 + _l && x > x1 + _l && x > x2 + _l || x < x0 - _l && x < x1 - _l && x < x2 - _l) {
  12899. return false;
  12900. }
  12901. var d = curve.quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, null);
  12902. return d <= _l / 2;
  12903. }
  12904. function isInsideArcStroke(cx, cy, r, startAngle, endAngle, anticlockwise, lineWidth, x, y) {
  12905. if (lineWidth === 0) {
  12906. return false;
  12907. }
  12908. var _l = Math.max(lineWidth, 5);
  12909. x -= cx;
  12910. y -= cy;
  12911. var d = Math.sqrt(x * x + y * y);
  12912. if (d - _l > r || d + _l < r) {
  12913. return false;
  12914. }
  12915. if (Math.abs(startAngle - endAngle) >= PI2) {
  12916. return true;
  12917. }
  12918. if (anticlockwise) {
  12919. var tmp = startAngle;
  12920. startAngle = normalizeRadian(endAngle);
  12921. endAngle = normalizeRadian(tmp);
  12922. } else {
  12923. startAngle = normalizeRadian(startAngle);
  12924. endAngle = normalizeRadian(endAngle);
  12925. }
  12926. if (startAngle > endAngle) {
  12927. endAngle += PI2;
  12928. }
  12929. var angle = Math.atan2(y, x);
  12930. if (angle < 0) {
  12931. angle += PI2;
  12932. }
  12933. return angle >= startAngle && angle <= endAngle || angle + PI2 >= startAngle && angle + PI2 <= endAngle;
  12934. }
  12935. function isInsidePolyline(points, lineWidth, x, y) {
  12936. var lineWidth = Math.max(lineWidth, 10);
  12937. for (var i = 0, l = points.length - 1; i < l; i++) {
  12938. var x0 = points[i][0];
  12939. var y0 = points[i][1];
  12940. var x1 = points[i + 1][0];
  12941. var y1 = points[i + 1][1];
  12942. if (isInsideLine(x0, y0, x1, y1, lineWidth, x, y)) {
  12943. return true;
  12944. }
  12945. }
  12946. return false;
  12947. }
  12948. function isInsideRing(cx, cy, r0, r, x, y) {
  12949. var d = (x - cx) * (x - cx) + (y - cy) * (y - cy);
  12950. return d < r * r && d > r0 * r0;
  12951. }
  12952. function isInsideRect(x0, y0, width, height, x, y) {
  12953. return x >= x0 && x <= x0 + width && y >= y0 && y <= y0 + height;
  12954. }
  12955. function isInsideCircle(x0, y0, r, x, y) {
  12956. return (x - x0) * (x - x0) + (y - y0) * (y - y0) < r * r;
  12957. }
  12958. function isInsideSector(cx, cy, r0, r, startAngle, endAngle, anticlockwise, x, y) {
  12959. return isInsideArcStroke(cx, cy, (r0 + r) / 2, startAngle, endAngle, anticlockwise, r - r0, x, y);
  12960. }
  12961. function isInsidePolygon(points, x, y) {
  12962. var N = points.length;
  12963. var w = 0;
  12964. for (var i = 0, j = N - 1; i < N; i++) {
  12965. var x0 = points[j][0];
  12966. var y0 = points[j][1];
  12967. var x1 = points[i][0];
  12968. var y1 = points[i][1];
  12969. w += windingLine(x0, y0, x1, y1, x, y);
  12970. j = i;
  12971. }
  12972. return w !== 0;
  12973. }
  12974. function windingLine(x0, y0, x1, y1, x, y) {
  12975. if (y > y0 && y > y1 || y < y0 && y < y1) {
  12976. return 0;
  12977. }
  12978. if (y1 == y0) {
  12979. return 0;
  12980. }
  12981. var dir = y1 < y0 ? 1 : -1;
  12982. var t = (y - y0) / (y1 - y0);
  12983. var x_ = t * (x1 - x0) + x0;
  12984. return x_ > x ? dir : 0;
  12985. }
  12986. var roots = [
  12987. -1,
  12988. -1,
  12989. -1
  12990. ];
  12991. var extrema = [
  12992. -1,
  12993. -1
  12994. ];
  12995. function swapExtrema() {
  12996. var tmp = extrema[0];
  12997. extrema[0] = extrema[1];
  12998. extrema[1] = tmp;
  12999. }
  13000. function windingCubic(x0, y0, x1, y1, x2, y2, x3, y3, x, y) {
  13001. if (y > y0 && y > y1 && y > y2 && y > y3 || y < y0 && y < y1 && y < y2 && y < y3) {
  13002. return 0;
  13003. }
  13004. var nRoots = curve.cubicRootAt(y0, y1, y2, y3, y, roots);
  13005. if (nRoots === 0) {
  13006. return 0;
  13007. } else {
  13008. var w = 0;
  13009. var nExtrema = -1;
  13010. var y0_, y1_;
  13011. for (var i = 0; i < nRoots; i++) {
  13012. var t = roots[i];
  13013. var x_ = curve.cubicAt(x0, x1, x2, x3, t);
  13014. if (x_ < x) {
  13015. continue;
  13016. }
  13017. if (nExtrema < 0) {
  13018. nExtrema = curve.cubicExtrema(y0, y1, y2, y3, extrema);
  13019. if (extrema[1] < extrema[0] && nExtrema > 1) {
  13020. swapExtrema();
  13021. }
  13022. y0_ = curve.cubicAt(y0, y1, y2, y3, extrema[0]);
  13023. if (nExtrema > 1) {
  13024. y1_ = curve.cubicAt(y0, y1, y2, y3, extrema[1]);
  13025. }
  13026. }
  13027. if (nExtrema == 2) {
  13028. if (t < extrema[0]) {
  13029. w += y0_ < y0 ? 1 : -1;
  13030. } else if (t < extrema[1]) {
  13031. w += y1_ < y0_ ? 1 : -1;
  13032. } else {
  13033. w += y3 < y1_ ? 1 : -1;
  13034. }
  13035. } else {
  13036. if (t < extrema[0]) {
  13037. w += y0_ < y0 ? 1 : -1;
  13038. } else {
  13039. w += y3 < y0_ ? 1 : -1;
  13040. }
  13041. }
  13042. }
  13043. return w;
  13044. }
  13045. }
  13046. function windingQuadratic(x0, y0, x1, y1, x2, y2, x, y) {
  13047. if (y > y0 && y > y1 && y > y2 || y < y0 && y < y1 && y < y2) {
  13048. return 0;
  13049. }
  13050. var nRoots = curve.quadraticRootAt(y0, y1, y2, y, roots);
  13051. if (nRoots === 0) {
  13052. return 0;
  13053. } else {
  13054. var t = curve.quadraticExtremum(y0, y1, y2);
  13055. if (t >= 0 && t <= 1) {
  13056. var w = 0;
  13057. var y_ = curve.quadraticAt(y0, y1, y2, t);
  13058. for (var i = 0; i < nRoots; i++) {
  13059. var x_ = curve.quadraticAt(x0, x1, x2, roots[i]);
  13060. if (x_ < x) {
  13061. continue;
  13062. }
  13063. if (roots[i] < t) {
  13064. w += y_ < y0 ? 1 : -1;
  13065. } else {
  13066. w += y2 < y_ ? 1 : -1;
  13067. }
  13068. }
  13069. return w;
  13070. } else {
  13071. var x_ = curve.quadraticAt(x0, x1, x2, roots[0]);
  13072. if (x_ < x) {
  13073. return 0;
  13074. }
  13075. return y2 < y0 ? 1 : -1;
  13076. }
  13077. }
  13078. }
  13079. function windingArc(cx, cy, r, startAngle, endAngle, anticlockwise, x, y) {
  13080. y -= cy;
  13081. if (y > r || y < -r) {
  13082. return 0;
  13083. }
  13084. var tmp = Math.sqrt(r * r - y * y);
  13085. roots[0] = -tmp;
  13086. roots[1] = tmp;
  13087. if (Math.abs(startAngle - endAngle) >= PI2) {
  13088. startAngle = 0;
  13089. endAngle = PI2;
  13090. var dir = anticlockwise ? 1 : -1;
  13091. if (x >= roots[0] + cx && x <= roots[1] + cx) {
  13092. return dir;
  13093. } else {
  13094. return 0;
  13095. }
  13096. }
  13097. if (anticlockwise) {
  13098. var tmp = startAngle;
  13099. startAngle = normalizeRadian(endAngle);
  13100. endAngle = normalizeRadian(tmp);
  13101. } else {
  13102. startAngle = normalizeRadian(startAngle);
  13103. endAngle = normalizeRadian(endAngle);
  13104. }
  13105. if (startAngle > endAngle) {
  13106. endAngle += PI2;
  13107. }
  13108. var w = 0;
  13109. for (var i = 0; i < 2; i++) {
  13110. var x_ = roots[i];
  13111. if (x_ + cx > x) {
  13112. var angle = Math.atan2(y, x_);
  13113. var dir = anticlockwise ? 1 : -1;
  13114. if (angle < 0) {
  13115. angle = PI2 + angle;
  13116. }
  13117. if (angle >= startAngle && angle <= endAngle || angle + PI2 >= startAngle && angle + PI2 <= endAngle) {
  13118. if (angle > Math.PI / 2 && angle < Math.PI * 1.5) {
  13119. dir = -dir;
  13120. }
  13121. w += dir;
  13122. }
  13123. }
  13124. }
  13125. return w;
  13126. }
  13127. function isInsidePath(pathArray, lineWidth, brushType, x, y) {
  13128. var w = 0;
  13129. var xi = 0;
  13130. var yi = 0;
  13131. var x0 = 0;
  13132. var y0 = 0;
  13133. var beginSubpath = true;
  13134. var firstCmd = true;
  13135. brushType = brushType || 'fill';
  13136. var hasStroke = brushType === 'stroke' || brushType === 'both';
  13137. var hasFill = brushType === 'fill' || brushType === 'both';
  13138. for (var i = 0; i < pathArray.length; i++) {
  13139. var seg = pathArray[i];
  13140. var p = seg.points;
  13141. if (beginSubpath || seg.command === 'M') {
  13142. if (i > 0) {
  13143. if (hasFill) {
  13144. w += windingLine(xi, yi, x0, y0, x, y);
  13145. }
  13146. if (w !== 0) {
  13147. return true;
  13148. }
  13149. }
  13150. x0 = p[p.length - 2];
  13151. y0 = p[p.length - 1];
  13152. beginSubpath = false;
  13153. if (firstCmd && seg.command !== 'A') {
  13154. firstCmd = false;
  13155. xi = x0;
  13156. yi = y0;
  13157. }
  13158. }
  13159. switch (seg.command) {
  13160. case 'M':
  13161. xi = p[0];
  13162. yi = p[1];
  13163. break;
  13164. case 'L':
  13165. if (hasStroke) {
  13166. if (isInsideLine(xi, yi, p[0], p[1], lineWidth, x, y)) {
  13167. return true;
  13168. }
  13169. }
  13170. if (hasFill) {
  13171. w += windingLine(xi, yi, p[0], p[1], x, y);
  13172. }
  13173. xi = p[0];
  13174. yi = p[1];
  13175. break;
  13176. case 'C':
  13177. if (hasStroke) {
  13178. if (isInsideCubicStroke(xi, yi, p[0], p[1], p[2], p[3], p[4], p[5], lineWidth, x, y)) {
  13179. return true;
  13180. }
  13181. }
  13182. if (hasFill) {
  13183. w += windingCubic(xi, yi, p[0], p[1], p[2], p[3], p[4], p[5], x, y);
  13184. }
  13185. xi = p[4];
  13186. yi = p[5];
  13187. break;
  13188. case 'Q':
  13189. if (hasStroke) {
  13190. if (isInsideQuadraticStroke(xi, yi, p[0], p[1], p[2], p[3], lineWidth, x, y)) {
  13191. return true;
  13192. }
  13193. }
  13194. if (hasFill) {
  13195. w += windingQuadratic(xi, yi, p[0], p[1], p[2], p[3], x, y);
  13196. }
  13197. xi = p[2];
  13198. yi = p[3];
  13199. break;
  13200. case 'A':
  13201. var cx = p[0];
  13202. var cy = p[1];
  13203. var rx = p[2];
  13204. var ry = p[3];
  13205. var theta = p[4];
  13206. var dTheta = p[5];
  13207. var x1 = Math.cos(theta) * rx + cx;
  13208. var y1 = Math.sin(theta) * ry + cy;
  13209. if (!firstCmd) {
  13210. w += windingLine(xi, yi, x1, y1);
  13211. } else {
  13212. firstCmd = false;
  13213. x0 = x1;
  13214. y0 = y1;
  13215. }
  13216. var _x = (x - cx) * ry / rx + cx;
  13217. if (hasStroke) {
  13218. if (isInsideArcStroke(cx, cy, ry, theta, theta + dTheta, 1 - p[7], lineWidth, _x, y)) {
  13219. return true;
  13220. }
  13221. }
  13222. if (hasFill) {
  13223. w += windingArc(cx, cy, ry, theta, theta + dTheta, 1 - p[7], _x, y);
  13224. }
  13225. xi = Math.cos(theta + dTheta) * rx + cx;
  13226. yi = Math.sin(theta + dTheta) * ry + cy;
  13227. break;
  13228. case 'z':
  13229. if (hasStroke) {
  13230. if (isInsideLine(xi, yi, x0, y0, lineWidth, x, y)) {
  13231. return true;
  13232. }
  13233. }
  13234. beginSubpath = true;
  13235. break;
  13236. }
  13237. }
  13238. if (hasFill) {
  13239. w += windingLine(xi, yi, x0, y0, x, y);
  13240. }
  13241. return w !== 0;
  13242. }
  13243. function getTextWidth(text, textFont) {
  13244. var key = text + ':' + textFont;
  13245. if (_textWidthCache[key]) {
  13246. return _textWidthCache[key];
  13247. }
  13248. _ctx = _ctx || util.getContext();
  13249. _ctx.save();
  13250. if (textFont) {
  13251. _ctx.font = textFont;
  13252. }
  13253. text = (text + '').split('\n');
  13254. var width = 0;
  13255. for (var i = 0, l = text.length; i < l; i++) {
  13256. width = Math.max(_ctx.measureText(text[i]).width, width);
  13257. }
  13258. _ctx.restore();
  13259. _textWidthCache[key] = width;
  13260. if (++_textWidthCacheCounter > TEXT_CACHE_MAX) {
  13261. _textWidthCacheCounter = 0;
  13262. _textWidthCache = {};
  13263. }
  13264. return width;
  13265. }
  13266. function getTextHeight(text, textFont) {
  13267. var key = text + ':' + textFont;
  13268. if (_textHeightCache[key]) {
  13269. return _textHeightCache[key];
  13270. }
  13271. _ctx = _ctx || util.getContext();
  13272. _ctx.save();
  13273. if (textFont) {
  13274. _ctx.font = textFont;
  13275. }
  13276. text = (text + '').split('\n');
  13277. var height = (_ctx.measureText('国').width + 2) * text.length;
  13278. _ctx.restore();
  13279. _textHeightCache[key] = height;
  13280. if (++_textHeightCacheCounter > TEXT_CACHE_MAX) {
  13281. _textHeightCacheCounter = 0;
  13282. _textHeightCache = {};
  13283. }
  13284. return height;
  13285. }
  13286. return {
  13287. isInside: isInside,
  13288. isOutside: isOutside,
  13289. getTextWidth: getTextWidth,
  13290. getTextHeight: getTextHeight,
  13291. isInsidePath: isInsidePath,
  13292. isInsidePolygon: isInsidePolygon,
  13293. isInsideSector: isInsideSector,
  13294. isInsideCircle: isInsideCircle,
  13295. isInsideLine: isInsideLine,
  13296. isInsideRect: isInsideRect,
  13297. isInsidePolyline: isInsidePolyline,
  13298. isInsideCubicStroke: isInsideCubicStroke,
  13299. isInsideQuadraticStroke: isInsideQuadraticStroke
  13300. };
  13301. });define('zrender/shape/Base', [
  13302. 'require',
  13303. '../tool/matrix',
  13304. '../tool/guid',
  13305. '../tool/util',
  13306. '../tool/log',
  13307. '../mixin/Transformable',
  13308. '../mixin/Eventful',
  13309. '../tool/area',
  13310. '../tool/color'
  13311. ], function (require) {
  13312. var vmlCanvasManager = window['G_vmlCanvasManager'];
  13313. var matrix = require('../tool/matrix');
  13314. var guid = require('../tool/guid');
  13315. var util = require('../tool/util');
  13316. var log = require('../tool/log');
  13317. var Transformable = require('../mixin/Transformable');
  13318. var Eventful = require('../mixin/Eventful');
  13319. function _fillText(ctx, text, x, y, textFont, textAlign, textBaseline) {
  13320. if (textFont) {
  13321. ctx.font = textFont;
  13322. }
  13323. ctx.textAlign = textAlign;
  13324. ctx.textBaseline = textBaseline;
  13325. var rect = _getTextRect(text, x, y, textFont, textAlign, textBaseline);
  13326. text = (text + '').split('\n');
  13327. var lineHeight = require('../tool/area').getTextHeight('国', textFont);
  13328. switch (textBaseline) {
  13329. case 'top':
  13330. y = rect.y;
  13331. break;
  13332. case 'bottom':
  13333. y = rect.y + lineHeight;
  13334. break;
  13335. default:
  13336. y = rect.y + lineHeight / 2;
  13337. }
  13338. for (var i = 0, l = text.length; i < l; i++) {
  13339. ctx.fillText(text[i], x, y);
  13340. y += lineHeight;
  13341. }
  13342. }
  13343. function _getTextRect(text, x, y, textFont, textAlign, textBaseline) {
  13344. var area = require('../tool/area');
  13345. var width = area.getTextWidth(text, textFont);
  13346. var lineHeight = area.getTextHeight('国', textFont);
  13347. text = (text + '').split('\n');
  13348. switch (textAlign) {
  13349. case 'end':
  13350. case 'right':
  13351. x -= width;
  13352. break;
  13353. case 'center':
  13354. x -= width / 2;
  13355. break;
  13356. }
  13357. switch (textBaseline) {
  13358. case 'top':
  13359. break;
  13360. case 'bottom':
  13361. y -= lineHeight * text.length;
  13362. break;
  13363. default:
  13364. y -= lineHeight * text.length / 2;
  13365. }
  13366. return {
  13367. x: x,
  13368. y: y,
  13369. width: width,
  13370. height: lineHeight * text.length
  13371. };
  13372. }
  13373. var Base = function (options) {
  13374. options = options || {};
  13375. this.id = options.id || guid();
  13376. for (var key in options) {
  13377. this[key] = options[key];
  13378. }
  13379. this.style = this.style || {};
  13380. this.highlightStyle = this.highlightStyle || null;
  13381. this.parent = null;
  13382. this.__dirty = true;
  13383. this.__clipShapes = [];
  13384. Transformable.call(this);
  13385. Eventful.call(this);
  13386. };
  13387. Base.prototype.invisible = false;
  13388. Base.prototype.ignore = false;
  13389. Base.prototype.zlevel = 0;
  13390. Base.prototype.draggable = false;
  13391. Base.prototype.clickable = false;
  13392. Base.prototype.hoverable = true;
  13393. Base.prototype.z = 0;
  13394. Base.prototype.brush = function (ctx, isHighlight) {
  13395. var style = this.beforeBrush(ctx, isHighlight);
  13396. ctx.beginPath();
  13397. this.buildPath(ctx, style);
  13398. switch (style.brushType) {
  13399. case 'both':
  13400. ctx.fill();
  13401. case 'stroke':
  13402. style.lineWidth > 0 && ctx.stroke();
  13403. break;
  13404. default:
  13405. ctx.fill();
  13406. }
  13407. this.drawText(ctx, style, this.style);
  13408. this.afterBrush(ctx);
  13409. };
  13410. Base.prototype.beforeBrush = function (ctx, isHighlight) {
  13411. var style = this.style;
  13412. if (this.brushTypeOnly) {
  13413. style.brushType = this.brushTypeOnly;
  13414. }
  13415. if (isHighlight) {
  13416. style = this.getHighlightStyle(style, this.highlightStyle || {}, this.brushTypeOnly);
  13417. }
  13418. if (this.brushTypeOnly == 'stroke') {
  13419. style.strokeColor = style.strokeColor || style.color;
  13420. }
  13421. ctx.save();
  13422. this.doClip(ctx);
  13423. this.setContext(ctx, style);
  13424. this.setTransform(ctx);
  13425. return style;
  13426. };
  13427. Base.prototype.afterBrush = function (ctx) {
  13428. ctx.restore();
  13429. };
  13430. var STYLE_CTX_MAP = [
  13431. [
  13432. 'color',
  13433. 'fillStyle'
  13434. ],
  13435. [
  13436. 'strokeColor',
  13437. 'strokeStyle'
  13438. ],
  13439. [
  13440. 'opacity',
  13441. 'globalAlpha'
  13442. ],
  13443. [
  13444. 'lineCap',
  13445. 'lineCap'
  13446. ],
  13447. [
  13448. 'lineJoin',
  13449. 'lineJoin'
  13450. ],
  13451. [
  13452. 'miterLimit',
  13453. 'miterLimit'
  13454. ],
  13455. [
  13456. 'lineWidth',
  13457. 'lineWidth'
  13458. ],
  13459. [
  13460. 'shadowBlur',
  13461. 'shadowBlur'
  13462. ],
  13463. [
  13464. 'shadowColor',
  13465. 'shadowColor'
  13466. ],
  13467. [
  13468. 'shadowOffsetX',
  13469. 'shadowOffsetX'
  13470. ],
  13471. [
  13472. 'shadowOffsetY',
  13473. 'shadowOffsetY'
  13474. ]
  13475. ];
  13476. Base.prototype.setContext = function (ctx, style) {
  13477. for (var i = 0, len = STYLE_CTX_MAP.length; i < len; i++) {
  13478. var styleProp = STYLE_CTX_MAP[i][0];
  13479. var styleValue = style[styleProp];
  13480. var ctxProp = STYLE_CTX_MAP[i][1];
  13481. if (typeof styleValue != 'undefined') {
  13482. ctx[ctxProp] = styleValue;
  13483. }
  13484. }
  13485. };
  13486. var clipShapeInvTransform = matrix.create();
  13487. Base.prototype.doClip = function (ctx) {
  13488. if (this.__clipShapes && !vmlCanvasManager) {
  13489. for (var i = 0; i < this.__clipShapes.length; i++) {
  13490. var clipShape = this.__clipShapes[i];
  13491. if (clipShape.needTransform) {
  13492. var m = clipShape.transform;
  13493. matrix.invert(clipShapeInvTransform, m);
  13494. ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
  13495. }
  13496. ctx.beginPath();
  13497. clipShape.buildPath(ctx, clipShape.style);
  13498. ctx.clip();
  13499. if (clipShape.needTransform) {
  13500. var m = clipShapeInvTransform;
  13501. ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
  13502. }
  13503. }
  13504. }
  13505. };
  13506. Base.prototype.getHighlightStyle = function (style, highlightStyle, brushTypeOnly) {
  13507. var newStyle = {};
  13508. for (var k in style) {
  13509. newStyle[k] = style[k];
  13510. }
  13511. var color = require('../tool/color');
  13512. var highlightColor = color.getHighlightColor();
  13513. if (style.brushType != 'stroke') {
  13514. newStyle.strokeColor = highlightColor;
  13515. newStyle.lineWidth = (style.lineWidth || 1) + this.getHighlightZoom();
  13516. newStyle.brushType = 'both';
  13517. } else {
  13518. if (brushTypeOnly != 'stroke') {
  13519. newStyle.strokeColor = highlightColor;
  13520. newStyle.lineWidth = (style.lineWidth || 1) + this.getHighlightZoom();
  13521. } else {
  13522. newStyle.strokeColor = highlightStyle.strokeColor || color.mix(style.strokeColor, color.toRGB(highlightColor));
  13523. }
  13524. }
  13525. for (var k in highlightStyle) {
  13526. if (typeof highlightStyle[k] != 'undefined') {
  13527. newStyle[k] = highlightStyle[k];
  13528. }
  13529. }
  13530. return newStyle;
  13531. };
  13532. Base.prototype.getHighlightZoom = function () {
  13533. return this.type != 'text' ? 6 : 2;
  13534. };
  13535. Base.prototype.drift = function (dx, dy) {
  13536. this.position[0] += dx;
  13537. this.position[1] += dy;
  13538. };
  13539. Base.prototype.buildPath = function (ctx, style) {
  13540. log('buildPath not implemented in ' + this.type);
  13541. };
  13542. Base.prototype.getRect = function (style) {
  13543. log('getRect not implemented in ' + this.type);
  13544. };
  13545. Base.prototype.isCover = function (x, y) {
  13546. var originPos = this.transformCoordToLocal(x, y);
  13547. x = originPos[0];
  13548. y = originPos[1];
  13549. if (this.isCoverRect(x, y)) {
  13550. return require('../tool/area').isInside(this, this.style, x, y);
  13551. }
  13552. return false;
  13553. };
  13554. Base.prototype.isCoverRect = function (x, y) {
  13555. var rect = this.style.__rect;
  13556. if (!rect) {
  13557. rect = this.style.__rect = this.getRect(this.style);
  13558. }
  13559. return x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height;
  13560. };
  13561. Base.prototype.drawText = function (ctx, style, normalStyle) {
  13562. if (typeof style.text == 'undefined' || style.text === false) {
  13563. return;
  13564. }
  13565. var textColor = style.textColor || style.color || style.strokeColor;
  13566. ctx.fillStyle = textColor;
  13567. var dd = 10;
  13568. var al;
  13569. var bl;
  13570. var tx;
  13571. var ty;
  13572. var textPosition = style.textPosition || this.textPosition || 'top';
  13573. switch (textPosition) {
  13574. case 'inside':
  13575. case 'top':
  13576. case 'bottom':
  13577. case 'left':
  13578. case 'right':
  13579. if (this.getRect) {
  13580. var rect = (normalStyle || style).__rect || this.getRect(normalStyle || style);
  13581. switch (textPosition) {
  13582. case 'inside':
  13583. tx = rect.x + rect.width / 2;
  13584. ty = rect.y + rect.height / 2;
  13585. al = 'center';
  13586. bl = 'middle';
  13587. if (style.brushType != 'stroke' && textColor == style.color) {
  13588. ctx.fillStyle = '#fff';
  13589. }
  13590. break;
  13591. case 'left':
  13592. tx = rect.x - dd;
  13593. ty = rect.y + rect.height / 2;
  13594. al = 'end';
  13595. bl = 'middle';
  13596. break;
  13597. case 'right':
  13598. tx = rect.x + rect.width + dd;
  13599. ty = rect.y + rect.height / 2;
  13600. al = 'start';
  13601. bl = 'middle';
  13602. break;
  13603. case 'top':
  13604. tx = rect.x + rect.width / 2;
  13605. ty = rect.y - dd;
  13606. al = 'center';
  13607. bl = 'bottom';
  13608. break;
  13609. case 'bottom':
  13610. tx = rect.x + rect.width / 2;
  13611. ty = rect.y + rect.height + dd;
  13612. al = 'center';
  13613. bl = 'top';
  13614. break;
  13615. }
  13616. }
  13617. break;
  13618. case 'start':
  13619. case 'end':
  13620. var pointList = style.pointList || [
  13621. [
  13622. style.xStart || 0,
  13623. style.yStart || 0
  13624. ],
  13625. [
  13626. style.xEnd || 0,
  13627. style.yEnd || 0
  13628. ]
  13629. ];
  13630. var length = pointList.length;
  13631. if (length < 2) {
  13632. return;
  13633. }
  13634. var xStart;
  13635. var xEnd;
  13636. var yStart;
  13637. var yEnd;
  13638. switch (textPosition) {
  13639. case 'start':
  13640. xStart = pointList[1][0];
  13641. xEnd = pointList[0][0];
  13642. yStart = pointList[1][1];
  13643. yEnd = pointList[0][1];
  13644. break;
  13645. case 'end':
  13646. xStart = pointList[length - 2][0];
  13647. xEnd = pointList[length - 1][0];
  13648. yStart = pointList[length - 2][1];
  13649. yEnd = pointList[length - 1][1];
  13650. break;
  13651. }
  13652. tx = xEnd;
  13653. ty = yEnd;
  13654. var angle = Math.atan((yStart - yEnd) / (xEnd - xStart)) / Math.PI * 180;
  13655. if (xEnd - xStart < 0) {
  13656. angle += 180;
  13657. } else if (yStart - yEnd < 0) {
  13658. angle += 360;
  13659. }
  13660. dd = 5;
  13661. if (angle >= 30 && angle <= 150) {
  13662. al = 'center';
  13663. bl = 'bottom';
  13664. ty -= dd;
  13665. } else if (angle > 150 && angle < 210) {
  13666. al = 'right';
  13667. bl = 'middle';
  13668. tx -= dd;
  13669. } else if (angle >= 210 && angle <= 330) {
  13670. al = 'center';
  13671. bl = 'top';
  13672. ty += dd;
  13673. } else {
  13674. al = 'left';
  13675. bl = 'middle';
  13676. tx += dd;
  13677. }
  13678. break;
  13679. case 'specific':
  13680. tx = style.textX || 0;
  13681. ty = style.textY || 0;
  13682. al = 'start';
  13683. bl = 'middle';
  13684. break;
  13685. }
  13686. if (tx != null && ty != null) {
  13687. _fillText(ctx, style.text, tx, ty, style.textFont, style.textAlign || al, style.textBaseline || bl);
  13688. }
  13689. };
  13690. Base.prototype.modSelf = function () {
  13691. this.__dirty = true;
  13692. if (this.style) {
  13693. this.style.__rect = null;
  13694. }
  13695. if (this.highlightStyle) {
  13696. this.highlightStyle.__rect = null;
  13697. }
  13698. };
  13699. Base.prototype.isSilent = function () {
  13700. return !(this.hoverable || this.draggable || this.clickable || this.onmousemove || this.onmouseover || this.onmouseout || this.onmousedown || this.onmouseup || this.onclick || this.ondragenter || this.ondragover || this.ondragleave || this.ondrop);
  13701. };
  13702. util.merge(Base.prototype, Transformable.prototype, true);
  13703. util.merge(Base.prototype, Eventful.prototype, true);
  13704. return Base;
  13705. });define('zrender/tool/curve', [
  13706. 'require',
  13707. './vector'
  13708. ], function (require) {
  13709. var vector = require('./vector');
  13710. 'use strict';
  13711. var EPSILON = 0.0001;
  13712. var THREE_SQRT = Math.sqrt(3);
  13713. var ONE_THIRD = 1 / 3;
  13714. var _v0 = vector.create();
  13715. var _v1 = vector.create();
  13716. var _v2 = vector.create();
  13717. function isAroundZero(val) {
  13718. return val > -EPSILON && val < EPSILON;
  13719. }
  13720. function isNotAroundZero(val) {
  13721. return val > EPSILON || val < -EPSILON;
  13722. }
  13723. function cubicAt(p0, p1, p2, p3, t) {
  13724. var onet = 1 - t;
  13725. return onet * onet * (onet * p0 + 3 * t * p1) + t * t * (t * p3 + 3 * onet * p2);
  13726. }
  13727. function cubicDerivativeAt(p0, p1, p2, p3, t) {
  13728. var onet = 1 - t;
  13729. return 3 * (((p1 - p0) * onet + 2 * (p2 - p1) * t) * onet + (p3 - p2) * t * t);
  13730. }
  13731. function cubicRootAt(p0, p1, p2, p3, val, roots) {
  13732. var a = p3 + 3 * (p1 - p2) - p0;
  13733. var b = 3 * (p2 - p1 * 2 + p0);
  13734. var c = 3 * (p1 - p0);
  13735. var d = p0 - val;
  13736. var A = b * b - 3 * a * c;
  13737. var B = b * c - 9 * a * d;
  13738. var C = c * c - 3 * b * d;
  13739. var n = 0;
  13740. if (isAroundZero(A) && isAroundZero(B)) {
  13741. if (isAroundZero(b)) {
  13742. roots[0] = 0;
  13743. } else {
  13744. var t1 = -c / b;
  13745. if (t1 >= 0 && t1 <= 1) {
  13746. roots[n++] = t1;
  13747. }
  13748. }
  13749. } else {
  13750. var disc = B * B - 4 * A * C;
  13751. if (isAroundZero(disc)) {
  13752. var K = B / A;
  13753. var t1 = -b / a + K;
  13754. var t2 = -K / 2;
  13755. if (t1 >= 0 && t1 <= 1) {
  13756. roots[n++] = t1;
  13757. }
  13758. if (t2 >= 0 && t2 <= 1) {
  13759. roots[n++] = t2;
  13760. }
  13761. } else if (disc > 0) {
  13762. var discSqrt = Math.sqrt(disc);
  13763. var Y1 = A * b + 1.5 * a * (-B + discSqrt);
  13764. var Y2 = A * b + 1.5 * a * (-B - discSqrt);
  13765. if (Y1 < 0) {
  13766. Y1 = -Math.pow(-Y1, ONE_THIRD);
  13767. } else {
  13768. Y1 = Math.pow(Y1, ONE_THIRD);
  13769. }
  13770. if (Y2 < 0) {
  13771. Y2 = -Math.pow(-Y2, ONE_THIRD);
  13772. } else {
  13773. Y2 = Math.pow(Y2, ONE_THIRD);
  13774. }
  13775. var t1 = (-b - (Y1 + Y2)) / (3 * a);
  13776. if (t1 >= 0 && t1 <= 1) {
  13777. roots[n++] = t1;
  13778. }
  13779. } else {
  13780. var T = (2 * A * b - 3 * a * B) / (2 * Math.sqrt(A * A * A));
  13781. var theta = Math.acos(T) / 3;
  13782. var ASqrt = Math.sqrt(A);
  13783. var tmp = Math.cos(theta);
  13784. var t1 = (-b - 2 * ASqrt * tmp) / (3 * a);
  13785. var t2 = (-b + ASqrt * (tmp + THREE_SQRT * Math.sin(theta))) / (3 * a);
  13786. var t3 = (-b + ASqrt * (tmp - THREE_SQRT * Math.sin(theta))) / (3 * a);
  13787. if (t1 >= 0 && t1 <= 1) {
  13788. roots[n++] = t1;
  13789. }
  13790. if (t2 >= 0 && t2 <= 1) {
  13791. roots[n++] = t2;
  13792. }
  13793. if (t3 >= 0 && t3 <= 1) {
  13794. roots[n++] = t3;
  13795. }
  13796. }
  13797. }
  13798. return n;
  13799. }
  13800. function cubicExtrema(p0, p1, p2, p3, extrema) {
  13801. var b = 6 * p2 - 12 * p1 + 6 * p0;
  13802. var a = 9 * p1 + 3 * p3 - 3 * p0 - 9 * p2;
  13803. var c = 3 * p1 - 3 * p0;
  13804. var n = 0;
  13805. if (isAroundZero(a)) {
  13806. if (isNotAroundZero(b)) {
  13807. var t1 = -c / b;
  13808. if (t1 >= 0 && t1 <= 1) {
  13809. extrema[n++] = t1;
  13810. }
  13811. }
  13812. } else {
  13813. var disc = b * b - 4 * a * c;
  13814. if (isAroundZero(disc)) {
  13815. extrema[0] = -b / (2 * a);
  13816. } else if (disc > 0) {
  13817. var discSqrt = Math.sqrt(disc);
  13818. var t1 = (-b + discSqrt) / (2 * a);
  13819. var t2 = (-b - discSqrt) / (2 * a);
  13820. if (t1 >= 0 && t1 <= 1) {
  13821. extrema[n++] = t1;
  13822. }
  13823. if (t2 >= 0 && t2 <= 1) {
  13824. extrema[n++] = t2;
  13825. }
  13826. }
  13827. }
  13828. return n;
  13829. }
  13830. function cubicSubdivide(p0, p1, p2, p3, t, out) {
  13831. var p01 = (p1 - p0) * t + p0;
  13832. var p12 = (p2 - p1) * t + p1;
  13833. var p23 = (p3 - p2) * t + p2;
  13834. var p012 = (p12 - p01) * t + p01;
  13835. var p123 = (p23 - p12) * t + p12;
  13836. var p0123 = (p123 - p012) * t + p012;
  13837. out[0] = p0;
  13838. out[1] = p01;
  13839. out[2] = p012;
  13840. out[3] = p0123;
  13841. out[4] = p0123;
  13842. out[5] = p123;
  13843. out[6] = p23;
  13844. out[7] = p3;
  13845. }
  13846. function cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, out) {
  13847. var t;
  13848. var interval = 0.005;
  13849. var d = Infinity;
  13850. _v0[0] = x;
  13851. _v0[1] = y;
  13852. for (var _t = 0; _t < 1; _t += 0.05) {
  13853. _v1[0] = cubicAt(x0, x1, x2, x3, _t);
  13854. _v1[1] = cubicAt(y0, y1, y2, y3, _t);
  13855. var d1 = vector.distSquare(_v0, _v1);
  13856. if (d1 < d) {
  13857. t = _t;
  13858. d = d1;
  13859. }
  13860. }
  13861. d = Infinity;
  13862. for (var i = 0; i < 32; i++) {
  13863. if (interval < EPSILON) {
  13864. break;
  13865. }
  13866. var prev = t - interval;
  13867. var next = t + interval;
  13868. _v1[0] = cubicAt(x0, x1, x2, x3, prev);
  13869. _v1[1] = cubicAt(y0, y1, y2, y3, prev);
  13870. var d1 = vector.distSquare(_v1, _v0);
  13871. if (prev >= 0 && d1 < d) {
  13872. t = prev;
  13873. d = d1;
  13874. } else {
  13875. _v2[0] = cubicAt(x0, x1, x2, x3, next);
  13876. _v2[1] = cubicAt(y0, y1, y2, y3, next);
  13877. var d2 = vector.distSquare(_v2, _v0);
  13878. if (next <= 1 && d2 < d) {
  13879. t = next;
  13880. d = d2;
  13881. } else {
  13882. interval *= 0.5;
  13883. }
  13884. }
  13885. }
  13886. if (out) {
  13887. out[0] = cubicAt(x0, x1, x2, x3, t);
  13888. out[1] = cubicAt(y0, y1, y2, y3, t);
  13889. }
  13890. return Math.sqrt(d);
  13891. }
  13892. function quadraticAt(p0, p1, p2, t) {
  13893. var onet = 1 - t;
  13894. return onet * (onet * p0 + 2 * t * p1) + t * t * p2;
  13895. }
  13896. function quadraticDerivativeAt(p0, p1, p2, t) {
  13897. return 2 * ((1 - t) * (p1 - p0) + t * (p2 - p1));
  13898. }
  13899. function quadraticRootAt(p0, p1, p2, val, roots) {
  13900. var a = p0 - 2 * p1 + p2;
  13901. var b = 2 * (p1 - p0);
  13902. var c = p0 - val;
  13903. var n = 0;
  13904. if (isAroundZero(a)) {
  13905. if (isNotAroundZero(b)) {
  13906. var t1 = -c / b;
  13907. if (t1 >= 0 && t1 <= 1) {
  13908. roots[n++] = t1;
  13909. }
  13910. }
  13911. } else {
  13912. var disc = b * b - 4 * a * c;
  13913. if (isAroundZero(disc)) {
  13914. var t1 = -b / (2 * a);
  13915. if (t1 >= 0 && t1 <= 1) {
  13916. roots[n++] = t1;
  13917. }
  13918. } else if (disc > 0) {
  13919. var discSqrt = Math.sqrt(disc);
  13920. var t1 = (-b + discSqrt) / (2 * a);
  13921. var t2 = (-b - discSqrt) / (2 * a);
  13922. if (t1 >= 0 && t1 <= 1) {
  13923. roots[n++] = t1;
  13924. }
  13925. if (t2 >= 0 && t2 <= 1) {
  13926. roots[n++] = t2;
  13927. }
  13928. }
  13929. }
  13930. return n;
  13931. }
  13932. function quadraticExtremum(p0, p1, p2) {
  13933. var divider = p0 + p2 - 2 * p1;
  13934. if (divider === 0) {
  13935. return 0.5;
  13936. } else {
  13937. return (p0 - p1) / divider;
  13938. }
  13939. }
  13940. function quadraticSubdivide(p0, p1, p2, t, out) {
  13941. var p01 = (p1 - p0) * t + p0;
  13942. var p12 = (p2 - p1) * t + p1;
  13943. var p012 = (p12 - p01) * t + p01;
  13944. out[0] = p0;
  13945. out[1] = p01;
  13946. out[2] = p012;
  13947. out[3] = p012;
  13948. out[4] = p12;
  13949. out[5] = p2;
  13950. }
  13951. function quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, out) {
  13952. var t;
  13953. var interval = 0.005;
  13954. var d = Infinity;
  13955. _v0[0] = x;
  13956. _v0[1] = y;
  13957. for (var _t = 0; _t < 1; _t += 0.05) {
  13958. _v1[0] = quadraticAt(x0, x1, x2, _t);
  13959. _v1[1] = quadraticAt(y0, y1, y2, _t);
  13960. var d1 = vector.distSquare(_v0, _v1);
  13961. if (d1 < d) {
  13962. t = _t;
  13963. d = d1;
  13964. }
  13965. }
  13966. d = Infinity;
  13967. for (var i = 0; i < 32; i++) {
  13968. if (interval < EPSILON) {
  13969. break;
  13970. }
  13971. var prev = t - interval;
  13972. var next = t + interval;
  13973. _v1[0] = quadraticAt(x0, x1, x2, prev);
  13974. _v1[1] = quadraticAt(y0, y1, y2, prev);
  13975. var d1 = vector.distSquare(_v1, _v0);
  13976. if (prev >= 0 && d1 < d) {
  13977. t = prev;
  13978. d = d1;
  13979. } else {
  13980. _v2[0] = quadraticAt(x0, x1, x2, next);
  13981. _v2[1] = quadraticAt(y0, y1, y2, next);
  13982. var d2 = vector.distSquare(_v2, _v0);
  13983. if (next <= 1 && d2 < d) {
  13984. t = next;
  13985. d = d2;
  13986. } else {
  13987. interval *= 0.5;
  13988. }
  13989. }
  13990. }
  13991. if (out) {
  13992. out[0] = quadraticAt(x0, x1, x2, t);
  13993. out[1] = quadraticAt(y0, y1, y2, t);
  13994. }
  13995. return Math.sqrt(d);
  13996. }
  13997. return {
  13998. cubicAt: cubicAt,
  13999. cubicDerivativeAt: cubicDerivativeAt,
  14000. cubicRootAt: cubicRootAt,
  14001. cubicExtrema: cubicExtrema,
  14002. cubicSubdivide: cubicSubdivide,
  14003. cubicProjectPoint: cubicProjectPoint,
  14004. quadraticAt: quadraticAt,
  14005. quadraticDerivativeAt: quadraticDerivativeAt,
  14006. quadraticRootAt: quadraticRootAt,
  14007. quadraticExtremum: quadraticExtremum,
  14008. quadraticSubdivide: quadraticSubdivide,
  14009. quadraticProjectPoint: quadraticProjectPoint
  14010. };
  14011. });define('zrender/mixin/Transformable', [
  14012. 'require',
  14013. '../tool/matrix',
  14014. '../tool/vector'
  14015. ], function (require) {
  14016. 'use strict';
  14017. var matrix = require('../tool/matrix');
  14018. var vector = require('../tool/vector');
  14019. var origin = [
  14020. 0,
  14021. 0
  14022. ];
  14023. var mTranslate = matrix.translate;
  14024. var EPSILON = 0.00005;
  14025. function isAroundZero(val) {
  14026. return val > -EPSILON && val < EPSILON;
  14027. }
  14028. function isNotAroundZero(val) {
  14029. return val > EPSILON || val < -EPSILON;
  14030. }
  14031. var Transformable = function () {
  14032. if (!this.position) {
  14033. this.position = [
  14034. 0,
  14035. 0
  14036. ];
  14037. }
  14038. if (typeof this.rotation == 'undefined') {
  14039. this.rotation = [
  14040. 0,
  14041. 0,
  14042. 0
  14043. ];
  14044. }
  14045. if (!this.scale) {
  14046. this.scale = [
  14047. 1,
  14048. 1,
  14049. 0,
  14050. 0
  14051. ];
  14052. }
  14053. this.needLocalTransform = false;
  14054. this.needTransform = false;
  14055. };
  14056. Transformable.prototype = {
  14057. constructor: Transformable,
  14058. updateNeedTransform: function () {
  14059. this.needLocalTransform = isNotAroundZero(this.rotation[0]) || isNotAroundZero(this.position[0]) || isNotAroundZero(this.position[1]) || isNotAroundZero(this.scale[0] - 1) || isNotAroundZero(this.scale[1] - 1);
  14060. },
  14061. updateTransform: function () {
  14062. this.updateNeedTransform();
  14063. var parentHasTransform = this.parent && this.parent.needTransform;
  14064. this.needTransform = this.needLocalTransform || parentHasTransform;
  14065. if (!this.needTransform) {
  14066. return;
  14067. }
  14068. var m = this.transform || matrix.create();
  14069. matrix.identity(m);
  14070. if (this.needLocalTransform) {
  14071. var scale = this.scale;
  14072. if (isNotAroundZero(scale[0]) || isNotAroundZero(scale[1])) {
  14073. origin[0] = -scale[2] || 0;
  14074. origin[1] = -scale[3] || 0;
  14075. var haveOrigin = isNotAroundZero(origin[0]) || isNotAroundZero(origin[1]);
  14076. if (haveOrigin) {
  14077. mTranslate(m, m, origin);
  14078. }
  14079. matrix.scale(m, m, scale);
  14080. if (haveOrigin) {
  14081. origin[0] = -origin[0];
  14082. origin[1] = -origin[1];
  14083. mTranslate(m, m, origin);
  14084. }
  14085. }
  14086. if (this.rotation instanceof Array) {
  14087. if (this.rotation[0] !== 0) {
  14088. origin[0] = -this.rotation[1] || 0;
  14089. origin[1] = -this.rotation[2] || 0;
  14090. var haveOrigin = isNotAroundZero(origin[0]) || isNotAroundZero(origin[1]);
  14091. if (haveOrigin) {
  14092. mTranslate(m, m, origin);
  14093. }
  14094. matrix.rotate(m, m, this.rotation[0]);
  14095. if (haveOrigin) {
  14096. origin[0] = -origin[0];
  14097. origin[1] = -origin[1];
  14098. mTranslate(m, m, origin);
  14099. }
  14100. }
  14101. } else {
  14102. if (this.rotation !== 0) {
  14103. matrix.rotate(m, m, this.rotation);
  14104. }
  14105. }
  14106. if (isNotAroundZero(this.position[0]) || isNotAroundZero(this.position[1])) {
  14107. mTranslate(m, m, this.position);
  14108. }
  14109. }
  14110. if (parentHasTransform) {
  14111. if (this.needLocalTransform) {
  14112. matrix.mul(m, this.parent.transform, m);
  14113. } else {
  14114. matrix.copy(m, this.parent.transform);
  14115. }
  14116. }
  14117. this.transform = m;
  14118. this.invTransform = this.invTransform || matrix.create();
  14119. matrix.invert(this.invTransform, m);
  14120. },
  14121. setTransform: function (ctx) {
  14122. if (this.needTransform) {
  14123. var m = this.transform;
  14124. ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
  14125. }
  14126. },
  14127. lookAt: function () {
  14128. var v = vector.create();
  14129. return function (target) {
  14130. if (!this.transform) {
  14131. this.transform = matrix.create();
  14132. }
  14133. var m = this.transform;
  14134. vector.sub(v, target, this.position);
  14135. if (isAroundZero(v[0]) && isAroundZero(v[1])) {
  14136. return;
  14137. }
  14138. vector.normalize(v, v);
  14139. var scale = this.scale;
  14140. m[2] = v[0] * scale[1];
  14141. m[3] = v[1] * scale[1];
  14142. m[0] = v[1] * scale[0];
  14143. m[1] = -v[0] * scale[0];
  14144. m[4] = this.position[0];
  14145. m[5] = this.position[1];
  14146. this.decomposeTransform();
  14147. };
  14148. }(),
  14149. decomposeTransform: function () {
  14150. if (!this.transform) {
  14151. return;
  14152. }
  14153. var m = this.transform;
  14154. var sx = m[0] * m[0] + m[1] * m[1];
  14155. var position = this.position;
  14156. var scale = this.scale;
  14157. var rotation = this.rotation;
  14158. if (isNotAroundZero(sx - 1)) {
  14159. sx = Math.sqrt(sx);
  14160. }
  14161. var sy = m[2] * m[2] + m[3] * m[3];
  14162. if (isNotAroundZero(sy - 1)) {
  14163. sy = Math.sqrt(sy);
  14164. }
  14165. position[0] = m[4];
  14166. position[1] = m[5];
  14167. scale[0] = sx;
  14168. scale[1] = sy;
  14169. scale[2] = scale[3] = 0;
  14170. rotation[0] = Math.atan2(-m[1] / sy, m[0] / sx);
  14171. rotation[1] = rotation[2] = 0;
  14172. },
  14173. transformCoordToLocal: function (x, y) {
  14174. var v2 = [
  14175. x,
  14176. y
  14177. ];
  14178. if (this.needTransform && this.invTransform) {
  14179. vector.applyTransform(v2, v2, this.invTransform);
  14180. }
  14181. return v2;
  14182. }
  14183. };
  14184. return Transformable;
  14185. });define('zrender/Group', [
  14186. 'require',
  14187. './tool/guid',
  14188. './tool/util',
  14189. './mixin/Transformable',
  14190. './mixin/Eventful'
  14191. ], function (require) {
  14192. var guid = require('./tool/guid');
  14193. var util = require('./tool/util');
  14194. var Transformable = require('./mixin/Transformable');
  14195. var Eventful = require('./mixin/Eventful');
  14196. var Group = function (options) {
  14197. options = options || {};
  14198. this.id = options.id || guid();
  14199. for (var key in options) {
  14200. this[key] = options[key];
  14201. }
  14202. this.type = 'group';
  14203. this.clipShape = null;
  14204. this._children = [];
  14205. this._storage = null;
  14206. this.__dirty = true;
  14207. Transformable.call(this);
  14208. Eventful.call(this);
  14209. };
  14210. Group.prototype.ignore = false;
  14211. Group.prototype.children = function () {
  14212. return this._children.slice();
  14213. };
  14214. Group.prototype.childAt = function (idx) {
  14215. return this._children[idx];
  14216. };
  14217. Group.prototype.addChild = function (child) {
  14218. if (child == this) {
  14219. return;
  14220. }
  14221. if (child.parent == this) {
  14222. return;
  14223. }
  14224. if (child.parent) {
  14225. child.parent.removeChild(child);
  14226. }
  14227. this._children.push(child);
  14228. child.parent = this;
  14229. if (this._storage && this._storage !== child._storage) {
  14230. this._storage.addToMap(child);
  14231. if (child instanceof Group) {
  14232. child.addChildrenToStorage(this._storage);
  14233. }
  14234. }
  14235. };
  14236. Group.prototype.removeChild = function (child) {
  14237. var idx = util.indexOf(this._children, child);
  14238. if (idx >= 0) {
  14239. this._children.splice(idx, 1);
  14240. }
  14241. child.parent = null;
  14242. if (this._storage) {
  14243. this._storage.delFromMap(child.id);
  14244. if (child instanceof Group) {
  14245. child.delChildrenFromStorage(this._storage);
  14246. }
  14247. }
  14248. };
  14249. Group.prototype.clearChildren = function () {
  14250. for (var i = 0; i < this._children.length; i++) {
  14251. var child = this._children[i];
  14252. if (this._storage) {
  14253. this._storage.delFromMap(child.id);
  14254. if (child instanceof Group) {
  14255. child.delChildrenFromStorage(this._storage);
  14256. }
  14257. }
  14258. }
  14259. this._children.length = 0;
  14260. };
  14261. Group.prototype.eachChild = function (cb, context) {
  14262. var haveContext = !!context;
  14263. for (var i = 0; i < this._children.length; i++) {
  14264. var child = this._children[i];
  14265. if (haveContext) {
  14266. cb.call(context, child);
  14267. } else {
  14268. cb(child);
  14269. }
  14270. }
  14271. };
  14272. Group.prototype.traverse = function (cb, context) {
  14273. var haveContext = !!context;
  14274. for (var i = 0; i < this._children.length; i++) {
  14275. var child = this._children[i];
  14276. if (haveContext) {
  14277. cb.call(context, child);
  14278. } else {
  14279. cb(child);
  14280. }
  14281. if (child.type === 'group') {
  14282. child.traverse(cb, context);
  14283. }
  14284. }
  14285. };
  14286. Group.prototype.addChildrenToStorage = function (storage) {
  14287. for (var i = 0; i < this._children.length; i++) {
  14288. var child = this._children[i];
  14289. storage.addToMap(child);
  14290. if (child instanceof Group) {
  14291. child.addChildrenToStorage(storage);
  14292. }
  14293. }
  14294. };
  14295. Group.prototype.delChildrenFromStorage = function (storage) {
  14296. for (var i = 0; i < this._children.length; i++) {
  14297. var child = this._children[i];
  14298. storage.delFromMap(child.id);
  14299. if (child instanceof Group) {
  14300. child.delChildrenFromStorage(storage);
  14301. }
  14302. }
  14303. };
  14304. Group.prototype.modSelf = function () {
  14305. this.__dirty = true;
  14306. };
  14307. util.merge(Group.prototype, Transformable.prototype, true);
  14308. util.merge(Group.prototype, Eventful.prototype, true);
  14309. return Group;
  14310. });define('zrender/animation/Clip', [
  14311. 'require',
  14312. './easing'
  14313. ], function (require) {
  14314. var Easing = require('./easing');
  14315. function Clip(options) {
  14316. this._targetPool = options.target || {};
  14317. if (!(this._targetPool instanceof Array)) {
  14318. this._targetPool = [this._targetPool];
  14319. }
  14320. this._life = options.life || 1000;
  14321. this._delay = options.delay || 0;
  14322. this._startTime = new Date().getTime() + this._delay;
  14323. this._endTime = this._startTime + this._life * 1000;
  14324. this.loop = typeof options.loop == 'undefined' ? false : options.loop;
  14325. this.gap = options.gap || 0;
  14326. this.easing = options.easing || 'Linear';
  14327. this.onframe = options.onframe;
  14328. this.ondestroy = options.ondestroy;
  14329. this.onrestart = options.onrestart;
  14330. }
  14331. Clip.prototype = {
  14332. step: function (time) {
  14333. var percent = (time - this._startTime) / this._life;
  14334. if (percent < 0) {
  14335. return;
  14336. }
  14337. percent = Math.min(percent, 1);
  14338. var easingFunc = typeof this.easing == 'string' ? Easing[this.easing] : this.easing;
  14339. var schedule = typeof easingFunc === 'function' ? easingFunc(percent) : percent;
  14340. this.fire('frame', schedule);
  14341. if (percent == 1) {
  14342. if (this.loop) {
  14343. this.restart();
  14344. return 'restart';
  14345. }
  14346. this.__needsRemove = true;
  14347. return 'destroy';
  14348. }
  14349. return null;
  14350. },
  14351. restart: function () {
  14352. var time = new Date().getTime();
  14353. var remainder = (time - this._startTime) % this._life;
  14354. this._startTime = new Date().getTime() - remainder + this.gap;
  14355. this.__needsRemove = false;
  14356. },
  14357. fire: function (eventType, arg) {
  14358. for (var i = 0, len = this._targetPool.length; i < len; i++) {
  14359. if (this['on' + eventType]) {
  14360. this['on' + eventType](this._targetPool[i], arg);
  14361. }
  14362. }
  14363. },
  14364. constructor: Clip
  14365. };
  14366. return Clip;
  14367. });define('zrender/animation/easing', [], function () {
  14368. var easing = {
  14369. Linear: function (k) {
  14370. return k;
  14371. },
  14372. QuadraticIn: function (k) {
  14373. return k * k;
  14374. },
  14375. QuadraticOut: function (k) {
  14376. return k * (2 - k);
  14377. },
  14378. QuadraticInOut: function (k) {
  14379. if ((k *= 2) < 1) {
  14380. return 0.5 * k * k;
  14381. }
  14382. return -0.5 * (--k * (k - 2) - 1);
  14383. },
  14384. CubicIn: function (k) {
  14385. return k * k * k;
  14386. },
  14387. CubicOut: function (k) {
  14388. return --k * k * k + 1;
  14389. },
  14390. CubicInOut: function (k) {
  14391. if ((k *= 2) < 1) {
  14392. return 0.5 * k * k * k;
  14393. }
  14394. return 0.5 * ((k -= 2) * k * k + 2);
  14395. },
  14396. QuarticIn: function (k) {
  14397. return k * k * k * k;
  14398. },
  14399. QuarticOut: function (k) {
  14400. return 1 - --k * k * k * k;
  14401. },
  14402. QuarticInOut: function (k) {
  14403. if ((k *= 2) < 1) {
  14404. return 0.5 * k * k * k * k;
  14405. }
  14406. return -0.5 * ((k -= 2) * k * k * k - 2);
  14407. },
  14408. QuinticIn: function (k) {
  14409. return k * k * k * k * k;
  14410. },
  14411. QuinticOut: function (k) {
  14412. return --k * k * k * k * k + 1;
  14413. },
  14414. QuinticInOut: function (k) {
  14415. if ((k *= 2) < 1) {
  14416. return 0.5 * k * k * k * k * k;
  14417. }
  14418. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  14419. },
  14420. SinusoidalIn: function (k) {
  14421. return 1 - Math.cos(k * Math.PI / 2);
  14422. },
  14423. SinusoidalOut: function (k) {
  14424. return Math.sin(k * Math.PI / 2);
  14425. },
  14426. SinusoidalInOut: function (k) {
  14427. return 0.5 * (1 - Math.cos(Math.PI * k));
  14428. },
  14429. ExponentialIn: function (k) {
  14430. return k === 0 ? 0 : Math.pow(1024, k - 1);
  14431. },
  14432. ExponentialOut: function (k) {
  14433. return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
  14434. },
  14435. ExponentialInOut: function (k) {
  14436. if (k === 0) {
  14437. return 0;
  14438. }
  14439. if (k === 1) {
  14440. return 1;
  14441. }
  14442. if ((k *= 2) < 1) {
  14443. return 0.5 * Math.pow(1024, k - 1);
  14444. }
  14445. return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
  14446. },
  14447. CircularIn: function (k) {
  14448. return 1 - Math.sqrt(1 - k * k);
  14449. },
  14450. CircularOut: function (k) {
  14451. return Math.sqrt(1 - --k * k);
  14452. },
  14453. CircularInOut: function (k) {
  14454. if ((k *= 2) < 1) {
  14455. return -0.5 * (Math.sqrt(1 - k * k) - 1);
  14456. }
  14457. return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
  14458. },
  14459. ElasticIn: function (k) {
  14460. var s;
  14461. var a = 0.1;
  14462. var p = 0.4;
  14463. if (k === 0) {
  14464. return 0;
  14465. }
  14466. if (k === 1) {
  14467. return 1;
  14468. }
  14469. if (!a || a < 1) {
  14470. a = 1;
  14471. s = p / 4;
  14472. } else {
  14473. s = p * Math.asin(1 / a) / (2 * Math.PI);
  14474. }
  14475. return -(a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
  14476. },
  14477. ElasticOut: function (k) {
  14478. var s;
  14479. var a = 0.1;
  14480. var p = 0.4;
  14481. if (k === 0) {
  14482. return 0;
  14483. }
  14484. if (k === 1) {
  14485. return 1;
  14486. }
  14487. if (!a || a < 1) {
  14488. a = 1;
  14489. s = p / 4;
  14490. } else {
  14491. s = p * Math.asin(1 / a) / (2 * Math.PI);
  14492. }
  14493. return a * Math.pow(2, -10 * k) * Math.sin((k - s) * (2 * Math.PI) / p) + 1;
  14494. },
  14495. ElasticInOut: function (k) {
  14496. var s;
  14497. var a = 0.1;
  14498. var p = 0.4;
  14499. if (k === 0) {
  14500. return 0;
  14501. }
  14502. if (k === 1) {
  14503. return 1;
  14504. }
  14505. if (!a || a < 1) {
  14506. a = 1;
  14507. s = p / 4;
  14508. } else {
  14509. s = p * Math.asin(1 / a) / (2 * Math.PI);
  14510. }
  14511. if ((k *= 2) < 1) {
  14512. return -0.5 * (a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
  14513. }
  14514. return a * Math.pow(2, -10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
  14515. },
  14516. BackIn: function (k) {
  14517. var s = 1.70158;
  14518. return k * k * ((s + 1) * k - s);
  14519. },
  14520. BackOut: function (k) {
  14521. var s = 1.70158;
  14522. return --k * k * ((s + 1) * k + s) + 1;
  14523. },
  14524. BackInOut: function (k) {
  14525. var s = 1.70158 * 1.525;
  14526. if ((k *= 2) < 1) {
  14527. return 0.5 * (k * k * ((s + 1) * k - s));
  14528. }
  14529. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  14530. },
  14531. BounceIn: function (k) {
  14532. return 1 - easing.BounceOut(1 - k);
  14533. },
  14534. BounceOut: function (k) {
  14535. if (k < 1 / 2.75) {
  14536. return 7.5625 * k * k;
  14537. } else if (k < 2 / 2.75) {
  14538. return 7.5625 * (k -= 1.5 / 2.75) * k + 0.75;
  14539. } else if (k < 2.5 / 2.75) {
  14540. return 7.5625 * (k -= 2.25 / 2.75) * k + 0.9375;
  14541. } else {
  14542. return 7.5625 * (k -= 2.625 / 2.75) * k + 0.984375;
  14543. }
  14544. },
  14545. BounceInOut: function (k) {
  14546. if (k < 0.5) {
  14547. return easing.BounceIn(k * 2) * 0.5;
  14548. }
  14549. return easing.BounceOut(k * 2 - 1) * 0.5 + 0.5;
  14550. }
  14551. };
  14552. return easing;
  14553. });define('echarts/chart/base', [
  14554. 'require',
  14555. 'zrender/shape/Image',
  14556. '../util/shape/Icon',
  14557. '../util/shape/MarkLine',
  14558. '../util/shape/Symbol',
  14559. 'zrender/shape/Polyline',
  14560. 'zrender/shape/ShapeBundle',
  14561. '../config',
  14562. '../util/ecData',
  14563. '../util/ecAnimation',
  14564. '../util/ecEffect',
  14565. '../util/accMath',
  14566. '../component/base',
  14567. '../layout/EdgeBundling',
  14568. 'zrender/tool/util',
  14569. 'zrender/tool/area'
  14570. ], function (require) {
  14571. var ImageShape = require('zrender/shape/Image');
  14572. var IconShape = require('../util/shape/Icon');
  14573. var MarkLineShape = require('../util/shape/MarkLine');
  14574. var SymbolShape = require('../util/shape/Symbol');
  14575. var PolylineShape = require('zrender/shape/Polyline');
  14576. var ShapeBundle = require('zrender/shape/ShapeBundle');
  14577. var ecConfig = require('../config');
  14578. var ecData = require('../util/ecData');
  14579. var ecAnimation = require('../util/ecAnimation');
  14580. var ecEffect = require('../util/ecEffect');
  14581. var accMath = require('../util/accMath');
  14582. var ComponentBase = require('../component/base');
  14583. var EdgeBundling = require('../layout/EdgeBundling');
  14584. var zrUtil = require('zrender/tool/util');
  14585. var zrArea = require('zrender/tool/area');
  14586. function isCoordAvailable(coord) {
  14587. return coord.x != null && coord.y != null;
  14588. }
  14589. function Base(ecTheme, messageCenter, zr, option, myChart) {
  14590. ComponentBase.call(this, ecTheme, messageCenter, zr, option, myChart);
  14591. var self = this;
  14592. this.selectedMap = {};
  14593. this.lastShapeList = [];
  14594. this.shapeHandler = {
  14595. onclick: function () {
  14596. self.isClick = true;
  14597. },
  14598. ondragover: function (param) {
  14599. var calculableShape = param.target;
  14600. calculableShape.highlightStyle = calculableShape.highlightStyle || {};
  14601. var highlightStyle = calculableShape.highlightStyle;
  14602. var brushType = highlightStyle.brushTyep;
  14603. var strokeColor = highlightStyle.strokeColor;
  14604. var lineWidth = highlightStyle.lineWidth;
  14605. highlightStyle.brushType = 'stroke';
  14606. highlightStyle.strokeColor = self.ecTheme.calculableColor || ecConfig.calculableColor;
  14607. highlightStyle.lineWidth = calculableShape.type === 'icon' ? 30 : 10;
  14608. self.zr.addHoverShape(calculableShape);
  14609. setTimeout(function () {
  14610. if (highlightStyle) {
  14611. highlightStyle.brushType = brushType;
  14612. highlightStyle.strokeColor = strokeColor;
  14613. highlightStyle.lineWidth = lineWidth;
  14614. }
  14615. }, 20);
  14616. },
  14617. ondrop: function (param) {
  14618. if (ecData.get(param.dragged, 'data') != null) {
  14619. self.isDrop = true;
  14620. }
  14621. },
  14622. ondragend: function () {
  14623. self.isDragend = true;
  14624. }
  14625. };
  14626. }
  14627. Base.prototype = {
  14628. setCalculable: function (shape) {
  14629. shape.dragEnableTime = this.ecTheme.DRAG_ENABLE_TIME || ecConfig.DRAG_ENABLE_TIME;
  14630. shape.ondragover = this.shapeHandler.ondragover;
  14631. shape.ondragend = this.shapeHandler.ondragend;
  14632. shape.ondrop = this.shapeHandler.ondrop;
  14633. return shape;
  14634. },
  14635. ondrop: function (param, status) {
  14636. if (!this.isDrop || !param.target || status.dragIn) {
  14637. return;
  14638. }
  14639. var target = param.target;
  14640. var dragged = param.dragged;
  14641. var seriesIndex = ecData.get(target, 'seriesIndex');
  14642. var dataIndex = ecData.get(target, 'dataIndex');
  14643. var series = this.series;
  14644. var data;
  14645. var legend = this.component.legend;
  14646. if (dataIndex === -1) {
  14647. if (ecData.get(dragged, 'seriesIndex') == seriesIndex) {
  14648. status.dragOut = status.dragIn = status.needRefresh = true;
  14649. this.isDrop = false;
  14650. return;
  14651. }
  14652. data = {
  14653. value: ecData.get(dragged, 'value'),
  14654. name: ecData.get(dragged, 'name')
  14655. };
  14656. if (this.type === ecConfig.CHART_TYPE_PIE && data.value < 0) {
  14657. data.value = 0;
  14658. }
  14659. var hasFind = false;
  14660. var sData = series[seriesIndex].data;
  14661. for (var i = 0, l = sData.length; i < l; i++) {
  14662. if (sData[i].name === data.name && sData[i].value === '-') {
  14663. series[seriesIndex].data[i].value = data.value;
  14664. hasFind = true;
  14665. }
  14666. }
  14667. !hasFind && series[seriesIndex].data.push(data);
  14668. legend && legend.add(data.name, dragged.style.color || dragged.style.strokeColor);
  14669. } else {
  14670. data = series[seriesIndex].data[dataIndex] || '-';
  14671. if (data.value != null) {
  14672. if (data.value != '-') {
  14673. series[seriesIndex].data[dataIndex].value = accMath.accAdd(series[seriesIndex].data[dataIndex].value, ecData.get(dragged, 'value'));
  14674. } else {
  14675. series[seriesIndex].data[dataIndex].value = ecData.get(dragged, 'value');
  14676. }
  14677. if (this.type === ecConfig.CHART_TYPE_FUNNEL || this.type === ecConfig.CHART_TYPE_PIE) {
  14678. legend && legend.getRelatedAmount(data.name) === 1 && this.component.legend.del(data.name);
  14679. data.name += this.option.nameConnector + ecData.get(dragged, 'name');
  14680. legend && legend.add(data.name, dragged.style.color || dragged.style.strokeColor);
  14681. }
  14682. } else {
  14683. if (data != '-') {
  14684. series[seriesIndex].data[dataIndex] = accMath.accAdd(series[seriesIndex].data[dataIndex], ecData.get(dragged, 'value'));
  14685. } else {
  14686. series[seriesIndex].data[dataIndex] = ecData.get(dragged, 'value');
  14687. }
  14688. }
  14689. }
  14690. status.dragIn = status.dragIn || true;
  14691. this.isDrop = false;
  14692. var self = this;
  14693. setTimeout(function () {
  14694. self.zr.trigger('mousemove', param.event);
  14695. }, 300);
  14696. return;
  14697. },
  14698. ondragend: function (param, status) {
  14699. if (!this.isDragend || !param.target || status.dragOut) {
  14700. return;
  14701. }
  14702. var target = param.target;
  14703. var seriesIndex = ecData.get(target, 'seriesIndex');
  14704. var dataIndex = ecData.get(target, 'dataIndex');
  14705. var series = this.series;
  14706. if (series[seriesIndex].data[dataIndex].value != null) {
  14707. series[seriesIndex].data[dataIndex].value = '-';
  14708. var name = series[seriesIndex].data[dataIndex].name;
  14709. var legend = this.component.legend;
  14710. if (legend && legend.getRelatedAmount(name) === 0) {
  14711. legend.del(name);
  14712. }
  14713. } else {
  14714. series[seriesIndex].data[dataIndex] = '-';
  14715. }
  14716. status.dragOut = true;
  14717. status.needRefresh = true;
  14718. this.isDragend = false;
  14719. return;
  14720. },
  14721. onlegendSelected: function (param, status) {
  14722. var legendSelected = param.selected;
  14723. for (var itemName in this.selectedMap) {
  14724. if (this.selectedMap[itemName] != legendSelected[itemName]) {
  14725. status.needRefresh = true;
  14726. }
  14727. this.selectedMap[itemName] = legendSelected[itemName];
  14728. }
  14729. return;
  14730. },
  14731. _buildPosition: function () {
  14732. this._symbol = this.option.symbolList;
  14733. this._sIndex2ShapeMap = {};
  14734. this._sIndex2ColorMap = {};
  14735. this.selectedMap = {};
  14736. this.xMarkMap = {};
  14737. var series = this.series;
  14738. var _position2sIndexMap = {
  14739. top: [],
  14740. bottom: [],
  14741. left: [],
  14742. right: [],
  14743. other: []
  14744. };
  14745. var xAxisIndex;
  14746. var yAxisIndex;
  14747. var xAxis;
  14748. var yAxis;
  14749. for (var i = 0, l = series.length; i < l; i++) {
  14750. if (series[i].type === this.type) {
  14751. series[i] = this.reformOption(series[i]);
  14752. this.legendHoverLink = series[i].legendHoverLink || this.legendHoverLink;
  14753. xAxisIndex = series[i].xAxisIndex;
  14754. yAxisIndex = series[i].yAxisIndex;
  14755. xAxis = this.component.xAxis.getAxis(xAxisIndex);
  14756. yAxis = this.component.yAxis.getAxis(yAxisIndex);
  14757. if (xAxis.type === ecConfig.COMPONENT_TYPE_AXIS_CATEGORY) {
  14758. _position2sIndexMap[xAxis.getPosition()].push(i);
  14759. } else if (yAxis.type === ecConfig.COMPONENT_TYPE_AXIS_CATEGORY) {
  14760. _position2sIndexMap[yAxis.getPosition()].push(i);
  14761. } else {
  14762. _position2sIndexMap.other.push(i);
  14763. }
  14764. }
  14765. }
  14766. for (var position in _position2sIndexMap) {
  14767. if (_position2sIndexMap[position].length > 0) {
  14768. this._buildSinglePosition(position, _position2sIndexMap[position]);
  14769. }
  14770. }
  14771. this.addShapeList();
  14772. },
  14773. _buildSinglePosition: function (position, seriesArray) {
  14774. var mapData = this._mapData(seriesArray);
  14775. var locationMap = mapData.locationMap;
  14776. var maxDataLength = mapData.maxDataLength;
  14777. if (maxDataLength === 0 || locationMap.length === 0) {
  14778. return;
  14779. }
  14780. switch (position) {
  14781. case 'bottom':
  14782. case 'top':
  14783. this._buildHorizontal(seriesArray, maxDataLength, locationMap, this.xMarkMap);
  14784. break;
  14785. case 'left':
  14786. case 'right':
  14787. this._buildVertical(seriesArray, maxDataLength, locationMap, this.xMarkMap);
  14788. break;
  14789. case 'other':
  14790. this._buildOther(seriesArray, maxDataLength, locationMap, this.xMarkMap);
  14791. break;
  14792. }
  14793. for (var i = 0, l = seriesArray.length; i < l; i++) {
  14794. this.buildMark(seriesArray[i]);
  14795. }
  14796. },
  14797. _mapData: function (seriesArray) {
  14798. var series = this.series;
  14799. var serie;
  14800. var dataIndex = 0;
  14801. var stackMap = {};
  14802. var magicStackKey = '__kener__stack__';
  14803. var stackKey;
  14804. var serieName;
  14805. var legend = this.component.legend;
  14806. var locationMap = [];
  14807. var maxDataLength = 0;
  14808. var iconShape;
  14809. for (var i = 0, l = seriesArray.length; i < l; i++) {
  14810. serie = series[seriesArray[i]];
  14811. serieName = serie.name;
  14812. this._sIndex2ShapeMap[seriesArray[i]] = this._sIndex2ShapeMap[seriesArray[i]] || this.query(serie, 'symbol') || this._symbol[i % this._symbol.length];
  14813. if (legend) {
  14814. this.selectedMap[serieName] = legend.isSelected(serieName);
  14815. this._sIndex2ColorMap[seriesArray[i]] = legend.getColor(serieName);
  14816. iconShape = legend.getItemShape(serieName);
  14817. if (iconShape) {
  14818. var style = iconShape.style;
  14819. if (this.type == ecConfig.CHART_TYPE_LINE) {
  14820. style.iconType = 'legendLineIcon';
  14821. style.symbol = this._sIndex2ShapeMap[seriesArray[i]];
  14822. } else if (serie.itemStyle.normal.barBorderWidth > 0) {
  14823. var highlightStyle = iconShape.highlightStyle;
  14824. style.brushType = 'both';
  14825. style.x += 1;
  14826. style.y += 1;
  14827. style.width -= 2;
  14828. style.height -= 2;
  14829. style.strokeColor = highlightStyle.strokeColor = serie.itemStyle.normal.barBorderColor;
  14830. highlightStyle.lineWidth = 3;
  14831. }
  14832. legend.setItemShape(serieName, iconShape);
  14833. }
  14834. } else {
  14835. this.selectedMap[serieName] = true;
  14836. this._sIndex2ColorMap[seriesArray[i]] = this.zr.getColor(seriesArray[i]);
  14837. }
  14838. if (this.selectedMap[serieName]) {
  14839. stackKey = serie.stack || magicStackKey + seriesArray[i];
  14840. if (stackMap[stackKey] == null) {
  14841. stackMap[stackKey] = dataIndex;
  14842. locationMap[dataIndex] = [seriesArray[i]];
  14843. dataIndex++;
  14844. } else {
  14845. locationMap[stackMap[stackKey]].push(seriesArray[i]);
  14846. }
  14847. }
  14848. maxDataLength = Math.max(maxDataLength, serie.data.length);
  14849. }
  14850. return {
  14851. locationMap: locationMap,
  14852. maxDataLength: maxDataLength
  14853. };
  14854. },
  14855. _calculMarkMapXY: function (xMarkMap, locationMap, xy) {
  14856. var series = this.series;
  14857. for (var j = 0, k = locationMap.length; j < k; j++) {
  14858. for (var m = 0, n = locationMap[j].length; m < n; m++) {
  14859. var seriesIndex = locationMap[j][m];
  14860. var valueIndex = xy == 'xy' ? 0 : '';
  14861. var grid = this.component.grid;
  14862. var tarMark = xMarkMap[seriesIndex];
  14863. if (xy.indexOf('x') != '-1') {
  14864. if (tarMark['counter' + valueIndex] > 0) {
  14865. tarMark['average' + valueIndex] = tarMark['sum' + valueIndex] / tarMark['counter' + valueIndex];
  14866. }
  14867. var x = this.component.xAxis.getAxis(series[seriesIndex].xAxisIndex || 0).getCoord(tarMark['average' + valueIndex]);
  14868. tarMark['averageLine' + valueIndex] = [
  14869. [
  14870. x,
  14871. grid.getYend()
  14872. ],
  14873. [
  14874. x,
  14875. grid.getY()
  14876. ]
  14877. ];
  14878. tarMark['minLine' + valueIndex] = [
  14879. [
  14880. tarMark['minX' + valueIndex],
  14881. grid.getYend()
  14882. ],
  14883. [
  14884. tarMark['minX' + valueIndex],
  14885. grid.getY()
  14886. ]
  14887. ];
  14888. tarMark['maxLine' + valueIndex] = [
  14889. [
  14890. tarMark['maxX' + valueIndex],
  14891. grid.getYend()
  14892. ],
  14893. [
  14894. tarMark['maxX' + valueIndex],
  14895. grid.getY()
  14896. ]
  14897. ];
  14898. tarMark.isHorizontal = false;
  14899. }
  14900. valueIndex = xy == 'xy' ? 1 : '';
  14901. if (xy.indexOf('y') != '-1') {
  14902. if (tarMark['counter' + valueIndex] > 0) {
  14903. tarMark['average' + valueIndex] = tarMark['sum' + valueIndex] / tarMark['counter' + valueIndex];
  14904. }
  14905. var y = this.component.yAxis.getAxis(series[seriesIndex].yAxisIndex || 0).getCoord(tarMark['average' + valueIndex]);
  14906. tarMark['averageLine' + valueIndex] = [
  14907. [
  14908. grid.getX(),
  14909. y
  14910. ],
  14911. [
  14912. grid.getXend(),
  14913. y
  14914. ]
  14915. ];
  14916. tarMark['minLine' + valueIndex] = [
  14917. [
  14918. grid.getX(),
  14919. tarMark['minY' + valueIndex]
  14920. ],
  14921. [
  14922. grid.getXend(),
  14923. tarMark['minY' + valueIndex]
  14924. ]
  14925. ];
  14926. tarMark['maxLine' + valueIndex] = [
  14927. [
  14928. grid.getX(),
  14929. tarMark['maxY' + valueIndex]
  14930. ],
  14931. [
  14932. grid.getXend(),
  14933. tarMark['maxY' + valueIndex]
  14934. ]
  14935. ];
  14936. tarMark.isHorizontal = true;
  14937. }
  14938. }
  14939. }
  14940. },
  14941. addLabel: function (tarShape, serie, data, name, orient) {
  14942. var queryTarget = [
  14943. data,
  14944. serie
  14945. ];
  14946. var nLabel = this.deepMerge(queryTarget, 'itemStyle.normal.label');
  14947. var eLabel = this.deepMerge(queryTarget, 'itemStyle.emphasis.label');
  14948. var nTextStyle = nLabel.textStyle || {};
  14949. var eTextStyle = eLabel.textStyle || {};
  14950. if (nLabel.show) {
  14951. var style = tarShape.style;
  14952. style.text = this._getLabelText(serie, data, name, 'normal');
  14953. style.textPosition = nLabel.position == null ? orient === 'horizontal' ? 'right' : 'top' : nLabel.position;
  14954. style.textColor = nTextStyle.color;
  14955. style.textFont = this.getFont(nTextStyle);
  14956. style.textAlign = nTextStyle.align;
  14957. style.textBaseline = nTextStyle.baseline;
  14958. }
  14959. if (eLabel.show) {
  14960. var highlightStyle = tarShape.highlightStyle;
  14961. highlightStyle.text = this._getLabelText(serie, data, name, 'emphasis');
  14962. highlightStyle.textPosition = nLabel.show ? tarShape.style.textPosition : eLabel.position == null ? orient === 'horizontal' ? 'right' : 'top' : eLabel.position;
  14963. highlightStyle.textColor = eTextStyle.color;
  14964. highlightStyle.textFont = this.getFont(eTextStyle);
  14965. highlightStyle.textAlign = eTextStyle.align;
  14966. highlightStyle.textBaseline = eTextStyle.baseline;
  14967. }
  14968. return tarShape;
  14969. },
  14970. _getLabelText: function (serie, data, name, status) {
  14971. var formatter = this.deepQuery([
  14972. data,
  14973. serie
  14974. ], 'itemStyle.' + status + '.label.formatter');
  14975. if (!formatter && status === 'emphasis') {
  14976. formatter = this.deepQuery([
  14977. data,
  14978. serie
  14979. ], 'itemStyle.normal.label.formatter');
  14980. }
  14981. var value = this.getDataFromOption(data, '-');
  14982. if (formatter) {
  14983. if (typeof formatter === 'function') {
  14984. return formatter.call(this.myChart, {
  14985. seriesName: serie.name,
  14986. series: serie,
  14987. name: name,
  14988. value: value,
  14989. data: data,
  14990. status: status
  14991. });
  14992. } else if (typeof formatter === 'string') {
  14993. formatter = formatter.replace('{a}', '{a0}').replace('{b}', '{b0}').replace('{c}', '{c0}').replace('{a0}', serie.name).replace('{b0}', name).replace('{c0}', this.numAddCommas(value));
  14994. return formatter;
  14995. }
  14996. } else {
  14997. if (value instanceof Array) {
  14998. return value[2] != null ? this.numAddCommas(value[2]) : value[0] + ' , ' + value[1];
  14999. } else {
  15000. return this.numAddCommas(value);
  15001. }
  15002. }
  15003. },
  15004. buildMark: function (seriesIndex) {
  15005. var serie = this.series[seriesIndex];
  15006. if (this.selectedMap[serie.name]) {
  15007. serie.markLine && this._buildMarkLine(seriesIndex);
  15008. serie.markPoint && this._buildMarkPoint(seriesIndex);
  15009. }
  15010. },
  15011. _buildMarkPoint: function (seriesIndex) {
  15012. var attachStyle = (this.markAttachStyle || {})[seriesIndex];
  15013. var serie = this.series[seriesIndex];
  15014. var mpData;
  15015. var pos;
  15016. var markPoint = zrUtil.clone(serie.markPoint);
  15017. for (var i = 0, l = markPoint.data.length; i < l; i++) {
  15018. mpData = markPoint.data[i];
  15019. pos = this.getMarkCoord(seriesIndex, mpData);
  15020. mpData.x = mpData.x != null ? mpData.x : pos[0];
  15021. mpData.y = mpData.y != null ? mpData.y : pos[1];
  15022. if (mpData.type && (mpData.type === 'max' || mpData.type === 'min')) {
  15023. mpData.value = pos[3];
  15024. mpData.name = mpData.name || mpData.type;
  15025. mpData.symbolSize = mpData.symbolSize || zrArea.getTextWidth(pos[3], this.getFont()) / 2 + 5;
  15026. }
  15027. }
  15028. var shapeList = this._markPoint(seriesIndex, markPoint);
  15029. for (var i = 0, l = shapeList.length; i < l; i++) {
  15030. var tarShape = shapeList[i];
  15031. tarShape.zlevel = serie.zlevel;
  15032. tarShape.z = serie.z + 1;
  15033. for (var key in attachStyle) {
  15034. tarShape[key] = zrUtil.clone(attachStyle[key]);
  15035. }
  15036. this.shapeList.push(tarShape);
  15037. }
  15038. if (this.type === ecConfig.CHART_TYPE_FORCE || this.type === ecConfig.CHART_TYPE_CHORD) {
  15039. for (var i = 0, l = shapeList.length; i < l; i++) {
  15040. this.zr.addShape(shapeList[i]);
  15041. }
  15042. }
  15043. },
  15044. _buildMarkLine: function (seriesIndex) {
  15045. var attachStyle = (this.markAttachStyle || {})[seriesIndex];
  15046. var serie = this.series[seriesIndex];
  15047. var pos;
  15048. var markLine = zrUtil.clone(serie.markLine);
  15049. for (var i = 0, l = markLine.data.length; i < l; i++) {
  15050. var mlData = markLine.data[i];
  15051. if (mlData.type && (mlData.type === 'max' || mlData.type === 'min' || mlData.type === 'average')) {
  15052. pos = this.getMarkCoord(seriesIndex, mlData);
  15053. markLine.data[i] = [
  15054. zrUtil.clone(mlData),
  15055. {}
  15056. ];
  15057. markLine.data[i][0].name = mlData.name || mlData.type;
  15058. markLine.data[i][0].value = mlData.type !== 'average' ? pos[3] : +pos[3].toFixed(markLine.precision != null ? markLine.precision : this.deepQuery([
  15059. this.ecTheme,
  15060. ecConfig
  15061. ], 'markLine.precision'));
  15062. pos = pos[2];
  15063. mlData = [
  15064. {},
  15065. {}
  15066. ];
  15067. } else {
  15068. pos = [
  15069. this.getMarkCoord(seriesIndex, mlData[0]),
  15070. this.getMarkCoord(seriesIndex, mlData[1])
  15071. ];
  15072. }
  15073. if (pos == null || pos[0] == null || pos[1] == null) {
  15074. continue;
  15075. }
  15076. markLine.data[i][0].x = mlData[0].x != null ? mlData[0].x : pos[0][0];
  15077. markLine.data[i][0].y = mlData[0].y != null ? mlData[0].y : pos[0][1];
  15078. markLine.data[i][1].x = mlData[1].x != null ? mlData[1].x : pos[1][0];
  15079. markLine.data[i][1].y = mlData[1].y != null ? mlData[1].y : pos[1][1];
  15080. }
  15081. var shapeList = this._markLine(seriesIndex, markLine);
  15082. var isLarge = markLine.large;
  15083. if (isLarge) {
  15084. var shapeBundle = new ShapeBundle({ style: { shapeList: shapeList } });
  15085. var firstShape = shapeList[0];
  15086. if (firstShape) {
  15087. zrUtil.merge(shapeBundle.style, firstShape.style);
  15088. zrUtil.merge(shapeBundle.highlightStyle = {}, firstShape.highlightStyle);
  15089. shapeBundle.style.brushType = 'stroke';
  15090. shapeBundle.zlevel = serie.zlevel;
  15091. shapeBundle.z = serie.z + 1;
  15092. shapeBundle.hoverable = false;
  15093. for (var key in attachStyle) {
  15094. shapeBundle[key] = zrUtil.clone(attachStyle[key]);
  15095. }
  15096. }
  15097. this.shapeList.push(shapeBundle);
  15098. this.zr.addShape(shapeBundle);
  15099. shapeBundle._mark = 'largeLine';
  15100. var effect = markLine.effect;
  15101. if (effect.show) {
  15102. shapeBundle.effect = effect;
  15103. }
  15104. } else {
  15105. for (var i = 0, l = shapeList.length; i < l; i++) {
  15106. var tarShape = shapeList[i];
  15107. tarShape.zlevel = serie.zlevel;
  15108. tarShape.z = serie.z + 1;
  15109. for (var key in attachStyle) {
  15110. tarShape[key] = zrUtil.clone(attachStyle[key]);
  15111. }
  15112. this.shapeList.push(tarShape);
  15113. }
  15114. if (this.type === ecConfig.CHART_TYPE_FORCE || this.type === ecConfig.CHART_TYPE_CHORD) {
  15115. for (var i = 0, l = shapeList.length; i < l; i++) {
  15116. this.zr.addShape(shapeList[i]);
  15117. }
  15118. }
  15119. }
  15120. },
  15121. _markPoint: function (seriesIndex, mpOption) {
  15122. var serie = this.series[seriesIndex];
  15123. var component = this.component;
  15124. zrUtil.merge(zrUtil.merge(mpOption, zrUtil.clone(this.ecTheme.markPoint || {})), zrUtil.clone(ecConfig.markPoint));
  15125. mpOption.name = serie.name;
  15126. var pList = [];
  15127. var data = mpOption.data;
  15128. var itemShape;
  15129. var dataRange = component.dataRange;
  15130. var legend = component.legend;
  15131. var color;
  15132. var value;
  15133. var queryTarget;
  15134. var nColor;
  15135. var eColor;
  15136. var effect;
  15137. var zrWidth = this.zr.getWidth();
  15138. var zrHeight = this.zr.getHeight();
  15139. if (!mpOption.large) {
  15140. for (var i = 0, l = data.length; i < l; i++) {
  15141. if (data[i].x == null || data[i].y == null) {
  15142. continue;
  15143. }
  15144. value = data[i].value != null ? data[i].value : '';
  15145. if (legend) {
  15146. color = legend.getColor(serie.name);
  15147. }
  15148. if (dataRange) {
  15149. color = isNaN(value) ? color : dataRange.getColor(value);
  15150. queryTarget = [
  15151. data[i],
  15152. mpOption
  15153. ];
  15154. nColor = this.deepQuery(queryTarget, 'itemStyle.normal.color') || color;
  15155. eColor = this.deepQuery(queryTarget, 'itemStyle.emphasis.color') || nColor;
  15156. if (nColor == null && eColor == null) {
  15157. continue;
  15158. }
  15159. }
  15160. color = color == null ? this.zr.getColor(seriesIndex) : color;
  15161. data[i].tooltip = data[i].tooltip || mpOption.tooltip || { trigger: 'item' };
  15162. data[i].name = data[i].name != null ? data[i].name : '';
  15163. data[i].value = value;
  15164. itemShape = this.getSymbolShape(mpOption, seriesIndex, data[i], i, data[i].name, this.parsePercent(data[i].x, zrWidth), this.parsePercent(data[i].y, zrHeight), 'pin', color, 'rgba(0,0,0,0)', 'horizontal');
  15165. itemShape._mark = 'point';
  15166. effect = this.deepMerge([
  15167. data[i],
  15168. mpOption
  15169. ], 'effect');
  15170. if (effect.show) {
  15171. itemShape.effect = effect;
  15172. }
  15173. if (serie.type === ecConfig.CHART_TYPE_MAP) {
  15174. itemShape._geo = this.getMarkGeo(data[i]);
  15175. }
  15176. ecData.pack(itemShape, serie, seriesIndex, data[i], i, data[i].name, value);
  15177. pList.push(itemShape);
  15178. }
  15179. } else {
  15180. itemShape = this.getLargeMarkPointShape(seriesIndex, mpOption);
  15181. itemShape._mark = 'largePoint';
  15182. itemShape && pList.push(itemShape);
  15183. }
  15184. return pList;
  15185. },
  15186. _markLine: function () {
  15187. function normalizeOptionValue(mlOption, key) {
  15188. mlOption[key] = mlOption[key] instanceof Array ? mlOption[key].length > 1 ? mlOption[key] : [
  15189. mlOption[key][0],
  15190. mlOption[key][0]
  15191. ] : [
  15192. mlOption[key],
  15193. mlOption[key]
  15194. ];
  15195. }
  15196. return function (seriesIndex, mlOption) {
  15197. var serie = this.series[seriesIndex];
  15198. var component = this.component;
  15199. var dataRange = component.dataRange;
  15200. var legend = component.legend;
  15201. zrUtil.merge(zrUtil.merge(mlOption, zrUtil.clone(this.ecTheme.markLine || {})), zrUtil.clone(ecConfig.markLine));
  15202. var defaultColor = legend ? legend.getColor(serie.name) : this.zr.getColor(seriesIndex);
  15203. normalizeOptionValue(mlOption, 'symbol');
  15204. normalizeOptionValue(mlOption, 'symbolSize');
  15205. normalizeOptionValue(mlOption, 'symbolRotate');
  15206. var data = mlOption.data;
  15207. var edges = [];
  15208. var zrWidth = this.zr.getWidth();
  15209. var zrHeight = this.zr.getHeight();
  15210. for (var i = 0; i < data.length; i++) {
  15211. var mlData = data[i];
  15212. if (isCoordAvailable(mlData[0]) && isCoordAvailable(mlData[1])) {
  15213. var mergeData = this.deepMerge(mlData);
  15214. var queryTarget = [
  15215. mergeData,
  15216. mlOption
  15217. ];
  15218. var color = defaultColor;
  15219. var value = mergeData.value != null ? mergeData.value : '';
  15220. if (dataRange) {
  15221. color = isNaN(value) ? color : dataRange.getColor(value);
  15222. var nColor = this.deepQuery(queryTarget, 'itemStyle.normal.color') || color;
  15223. var eColor = this.deepQuery(queryTarget, 'itemStyle.emphasis.color') || nColor;
  15224. if (nColor == null && eColor == null) {
  15225. continue;
  15226. }
  15227. }
  15228. mlData[0].tooltip = mergeData.tooltip || mlOption.tooltip || { trigger: 'item' };
  15229. mlData[0].name = mlData[0].name || '';
  15230. mlData[1].name = mlData[1].name || '';
  15231. mlData[0].value = value;
  15232. edges.push({
  15233. points: [
  15234. [
  15235. this.parsePercent(mlData[0].x, zrWidth),
  15236. this.parsePercent(mlData[0].y, zrHeight)
  15237. ],
  15238. [
  15239. this.parsePercent(mlData[1].x, zrWidth),
  15240. this.parsePercent(mlData[1].y, zrHeight)
  15241. ]
  15242. ],
  15243. rawData: mlData,
  15244. color: color
  15245. });
  15246. }
  15247. }
  15248. var enableBundling = this.query(mlOption, 'bundling.enable');
  15249. if (enableBundling) {
  15250. var edgeBundling = new EdgeBundling();
  15251. edgeBundling.maxTurningAngle = this.query(mlOption, 'bundling.maxTurningAngle') / 180 * Math.PI;
  15252. edges = edgeBundling.run(edges);
  15253. }
  15254. mlOption.name = serie.name;
  15255. var shapeList = [];
  15256. for (var i = 0, l = edges.length; i < l; i++) {
  15257. var edge = edges[i];
  15258. var rawEdge = edge.rawEdge || edge;
  15259. var mlData = rawEdge.rawData;
  15260. var value = mlData.value != null ? mlData.value : '';
  15261. var itemShape = this.getMarkLineShape(mlOption, seriesIndex, mlData, i, edge.points, enableBundling, rawEdge.color);
  15262. itemShape._mark = 'line';
  15263. var effect = this.deepMerge([
  15264. mlData[0],
  15265. mlData[1],
  15266. mlOption
  15267. ], 'effect');
  15268. if (effect.show) {
  15269. itemShape.effect = effect;
  15270. itemShape.effect.large = mlOption.large;
  15271. }
  15272. if (serie.type === ecConfig.CHART_TYPE_MAP) {
  15273. itemShape._geo = [
  15274. this.getMarkGeo(mlData[0]),
  15275. this.getMarkGeo(mlData[1])
  15276. ];
  15277. }
  15278. ecData.pack(itemShape, serie, seriesIndex, mlData[0], i, mlData[0].name + (mlData[1].name !== '' ? ' > ' + mlData[1].name : ''), value);
  15279. shapeList.push(itemShape);
  15280. }
  15281. return shapeList;
  15282. };
  15283. }(),
  15284. getMarkCoord: function () {
  15285. return [
  15286. 0,
  15287. 0
  15288. ];
  15289. },
  15290. getSymbolShape: function (serie, seriesIndex, data, dataIndex, name, x, y, symbol, color, emptyColor, orient) {
  15291. var queryTarget = [
  15292. data,
  15293. serie
  15294. ];
  15295. var value = this.getDataFromOption(data, '-');
  15296. symbol = this.deepQuery(queryTarget, 'symbol') || symbol;
  15297. var symbolSize = this.deepQuery(queryTarget, 'symbolSize');
  15298. symbolSize = typeof symbolSize === 'function' ? symbolSize(value) : symbolSize;
  15299. if (typeof symbolSize === 'number') {
  15300. symbolSize = [
  15301. symbolSize,
  15302. symbolSize
  15303. ];
  15304. }
  15305. var symbolRotate = this.deepQuery(queryTarget, 'symbolRotate');
  15306. var normal = this.deepMerge(queryTarget, 'itemStyle.normal');
  15307. var emphasis = this.deepMerge(queryTarget, 'itemStyle.emphasis');
  15308. var nBorderWidth = normal.borderWidth != null ? normal.borderWidth : normal.lineStyle && normal.lineStyle.width;
  15309. if (nBorderWidth == null) {
  15310. nBorderWidth = symbol.match('empty') ? 2 : 0;
  15311. }
  15312. var eBorderWidth = emphasis.borderWidth != null ? emphasis.borderWidth : emphasis.lineStyle && emphasis.lineStyle.width;
  15313. if (eBorderWidth == null) {
  15314. eBorderWidth = nBorderWidth + 2;
  15315. }
  15316. var nColor = this.getItemStyleColor(normal.color, seriesIndex, dataIndex, data);
  15317. var eColor = this.getItemStyleColor(emphasis.color, seriesIndex, dataIndex, data);
  15318. var width = symbolSize[0];
  15319. var height = symbolSize[1];
  15320. var itemShape = new IconShape({
  15321. style: {
  15322. iconType: symbol.replace('empty', '').toLowerCase(),
  15323. x: x - width,
  15324. y: y - height,
  15325. width: width * 2,
  15326. height: height * 2,
  15327. brushType: 'both',
  15328. color: symbol.match('empty') ? emptyColor : nColor || color,
  15329. strokeColor: normal.borderColor || nColor || color,
  15330. lineWidth: nBorderWidth
  15331. },
  15332. highlightStyle: {
  15333. color: symbol.match('empty') ? emptyColor : eColor || nColor || color,
  15334. strokeColor: emphasis.borderColor || normal.borderColor || eColor || nColor || color,
  15335. lineWidth: eBorderWidth
  15336. },
  15337. clickable: this.deepQuery(queryTarget, 'clickable')
  15338. });
  15339. if (symbol.match('image')) {
  15340. itemShape.style.image = symbol.replace(new RegExp('^image:\\/\\/'), '');
  15341. itemShape = new ImageShape({
  15342. style: itemShape.style,
  15343. highlightStyle: itemShape.highlightStyle,
  15344. clickable: this.deepQuery(queryTarget, 'clickable')
  15345. });
  15346. }
  15347. if (symbolRotate != null) {
  15348. itemShape.rotation = [
  15349. symbolRotate * Math.PI / 180,
  15350. x,
  15351. y
  15352. ];
  15353. }
  15354. if (symbol.match('star')) {
  15355. itemShape.style.iconType = 'star';
  15356. itemShape.style.n = symbol.replace('empty', '').replace('star', '') - 0 || 5;
  15357. }
  15358. if (symbol === 'none') {
  15359. itemShape.invisible = true;
  15360. itemShape.hoverable = false;
  15361. }
  15362. itemShape = this.addLabel(itemShape, serie, data, name, orient);
  15363. if (symbol.match('empty')) {
  15364. if (itemShape.style.textColor == null) {
  15365. itemShape.style.textColor = itemShape.style.strokeColor;
  15366. }
  15367. if (itemShape.highlightStyle.textColor == null) {
  15368. itemShape.highlightStyle.textColor = itemShape.highlightStyle.strokeColor;
  15369. }
  15370. }
  15371. ecData.pack(itemShape, serie, seriesIndex, data, dataIndex, name);
  15372. itemShape._x = x;
  15373. itemShape._y = y;
  15374. itemShape._dataIndex = dataIndex;
  15375. itemShape._seriesIndex = seriesIndex;
  15376. return itemShape;
  15377. },
  15378. getMarkLineShape: function (mlOption, seriesIndex, data, dataIndex, points, bundling, color) {
  15379. var value0 = data[0].value != null ? data[0].value : '-';
  15380. var value1 = data[1].value != null ? data[1].value : '-';
  15381. var symbol = [
  15382. data[0].symbol || mlOption.symbol[0],
  15383. data[1].symbol || mlOption.symbol[1]
  15384. ];
  15385. var symbolSize = [
  15386. data[0].symbolSize || mlOption.symbolSize[0],
  15387. data[1].symbolSize || mlOption.symbolSize[1]
  15388. ];
  15389. symbolSize[0] = typeof symbolSize[0] === 'function' ? symbolSize[0](value0) : symbolSize[0];
  15390. symbolSize[1] = typeof symbolSize[1] === 'function' ? symbolSize[1](value1) : symbolSize[1];
  15391. var symbolRotate = [
  15392. this.query(data[0], 'symbolRotate') || mlOption.symbolRotate[0],
  15393. this.query(data[1], 'symbolRotate') || mlOption.symbolRotate[1]
  15394. ];
  15395. var queryTarget = [
  15396. data[0],
  15397. data[1],
  15398. mlOption
  15399. ];
  15400. var normal = this.deepMerge(queryTarget, 'itemStyle.normal');
  15401. normal.color = this.getItemStyleColor(normal.color, seriesIndex, dataIndex, data);
  15402. var emphasis = this.deepMerge(queryTarget, 'itemStyle.emphasis');
  15403. emphasis.color = this.getItemStyleColor(emphasis.color, seriesIndex, dataIndex, data);
  15404. var nlineStyle = normal.lineStyle;
  15405. var elineStyle = emphasis.lineStyle;
  15406. var nBorderWidth = nlineStyle.width;
  15407. if (nBorderWidth == null) {
  15408. nBorderWidth = normal.borderWidth;
  15409. }
  15410. var eBorderWidth = elineStyle.width;
  15411. if (eBorderWidth == null) {
  15412. eBorderWidth = emphasis.borderWidth != null ? emphasis.borderWidth : nBorderWidth + 2;
  15413. }
  15414. var smoothness = this.deepQuery(queryTarget, 'smoothness');
  15415. if (!this.deepQuery(queryTarget, 'smooth')) {
  15416. smoothness = 0;
  15417. }
  15418. var ShapeCtor = bundling ? PolylineShape : MarkLineShape;
  15419. var itemShape = new ShapeCtor({
  15420. style: {
  15421. symbol: symbol,
  15422. symbolSize: symbolSize,
  15423. symbolRotate: symbolRotate,
  15424. brushType: 'both',
  15425. lineType: nlineStyle.type,
  15426. shadowColor: nlineStyle.shadowColor || nlineStyle.color || normal.borderColor || normal.color || color,
  15427. shadowBlur: nlineStyle.shadowBlur,
  15428. shadowOffsetX: nlineStyle.shadowOffsetX,
  15429. shadowOffsetY: nlineStyle.shadowOffsetY,
  15430. color: normal.color || color,
  15431. strokeColor: nlineStyle.color || normal.borderColor || normal.color || color,
  15432. lineWidth: nBorderWidth,
  15433. symbolBorderColor: normal.borderColor || normal.color || color,
  15434. symbolBorder: normal.borderWidth
  15435. },
  15436. highlightStyle: {
  15437. shadowColor: elineStyle.shadowColor,
  15438. shadowBlur: elineStyle.shadowBlur,
  15439. shadowOffsetX: elineStyle.shadowOffsetX,
  15440. shadowOffsetY: elineStyle.shadowOffsetY,
  15441. color: emphasis.color || normal.color || color,
  15442. strokeColor: elineStyle.color || nlineStyle.color || emphasis.borderColor || normal.borderColor || emphasis.color || normal.color || color,
  15443. lineWidth: eBorderWidth,
  15444. symbolBorderColor: emphasis.borderColor || normal.borderColor || emphasis.color || normal.color || color,
  15445. symbolBorder: emphasis.borderWidth == null ? normal.borderWidth + 2 : emphasis.borderWidth
  15446. },
  15447. clickable: this.deepQuery(queryTarget, 'clickable')
  15448. });
  15449. var shapeStyle = itemShape.style;
  15450. if (bundling) {
  15451. shapeStyle.pointList = points;
  15452. shapeStyle.smooth = smoothness;
  15453. } else {
  15454. shapeStyle.xStart = points[0][0];
  15455. shapeStyle.yStart = points[0][1];
  15456. shapeStyle.xEnd = points[1][0];
  15457. shapeStyle.yEnd = points[1][1];
  15458. shapeStyle.curveness = smoothness;
  15459. itemShape.updatePoints(itemShape.style);
  15460. }
  15461. itemShape = this.addLabel(itemShape, mlOption, data[0], data[0].name + ' : ' + data[1].name);
  15462. return itemShape;
  15463. },
  15464. getLargeMarkPointShape: function (seriesIndex, mpOption) {
  15465. var serie = this.series[seriesIndex];
  15466. var component = this.component;
  15467. var data = mpOption.data;
  15468. var itemShape;
  15469. var dataRange = component.dataRange;
  15470. var legend = component.legend;
  15471. var color;
  15472. var value;
  15473. var queryTarget = [
  15474. data[0],
  15475. mpOption
  15476. ];
  15477. var nColor;
  15478. var eColor;
  15479. var effect;
  15480. if (legend) {
  15481. color = legend.getColor(serie.name);
  15482. }
  15483. if (dataRange) {
  15484. value = data[0].value != null ? data[0].value : '';
  15485. color = isNaN(value) ? color : dataRange.getColor(value);
  15486. nColor = this.deepQuery(queryTarget, 'itemStyle.normal.color') || color;
  15487. eColor = this.deepQuery(queryTarget, 'itemStyle.emphasis.color') || nColor;
  15488. if (nColor == null && eColor == null) {
  15489. return;
  15490. }
  15491. }
  15492. color = this.deepMerge(queryTarget, 'itemStyle.normal').color || color;
  15493. var symbol = this.deepQuery(queryTarget, 'symbol') || 'circle';
  15494. symbol = symbol.replace('empty', '').replace(/\d/g, '');
  15495. effect = this.deepMerge([
  15496. data[0],
  15497. mpOption
  15498. ], 'effect');
  15499. var devicePixelRatio = window.devicePixelRatio || 1;
  15500. itemShape = new SymbolShape({
  15501. style: {
  15502. pointList: data,
  15503. color: color,
  15504. strokeColor: color,
  15505. shadowColor: effect.shadowColor || color,
  15506. shadowBlur: (effect.shadowBlur != null ? effect.shadowBlur : 8) * devicePixelRatio,
  15507. size: this.deepQuery(queryTarget, 'symbolSize'),
  15508. iconType: symbol,
  15509. brushType: 'fill',
  15510. lineWidth: 1
  15511. },
  15512. draggable: false,
  15513. hoverable: false
  15514. });
  15515. if (effect.show) {
  15516. itemShape.effect = effect;
  15517. }
  15518. return itemShape;
  15519. },
  15520. backupShapeList: function () {
  15521. if (this.shapeList && this.shapeList.length > 0) {
  15522. this.lastShapeList = this.shapeList;
  15523. this.shapeList = [];
  15524. } else {
  15525. this.lastShapeList = [];
  15526. }
  15527. },
  15528. addShapeList: function () {
  15529. var maxLenth = this.option.animationThreshold / (this.canvasSupported ? 2 : 4);
  15530. var lastShapeList = this.lastShapeList;
  15531. var shapeList = this.shapeList;
  15532. var isUpdate = lastShapeList.length > 0;
  15533. var duration = isUpdate ? this.query(this.option, 'animationDurationUpdate') : this.query(this.option, 'animationDuration');
  15534. var easing = this.query(this.option, 'animationEasing');
  15535. var delay;
  15536. var key;
  15537. var oldMap = {};
  15538. var newMap = {};
  15539. if (this.option.animation && !this.option.renderAsImage && shapeList.length < maxLenth && !this.motionlessOnce) {
  15540. for (var i = 0, l = lastShapeList.length; i < l; i++) {
  15541. key = this._getAnimationKey(lastShapeList[i]);
  15542. if (key.match('undefined')) {
  15543. this.zr.delShape(lastShapeList[i].id);
  15544. } else {
  15545. key += lastShapeList[i].type;
  15546. if (oldMap[key]) {
  15547. this.zr.delShape(lastShapeList[i].id);
  15548. } else {
  15549. oldMap[key] = lastShapeList[i];
  15550. }
  15551. }
  15552. }
  15553. for (var i = 0, l = shapeList.length; i < l; i++) {
  15554. key = this._getAnimationKey(shapeList[i]);
  15555. if (key.match('undefined')) {
  15556. this.zr.addShape(shapeList[i]);
  15557. } else {
  15558. key += shapeList[i].type;
  15559. newMap[key] = shapeList[i];
  15560. }
  15561. }
  15562. for (key in oldMap) {
  15563. if (!newMap[key]) {
  15564. this.zr.delShape(oldMap[key].id);
  15565. }
  15566. }
  15567. for (key in newMap) {
  15568. if (oldMap[key]) {
  15569. this.zr.delShape(oldMap[key].id);
  15570. this._animateMod(oldMap[key], newMap[key], duration, easing, 0, isUpdate);
  15571. } else {
  15572. delay = (this.type == ecConfig.CHART_TYPE_LINE || this.type == ecConfig.CHART_TYPE_RADAR) && key.indexOf('icon') !== 0 ? duration / 2 : 0;
  15573. this._animateMod(false, newMap[key], duration, easing, delay, isUpdate);
  15574. }
  15575. }
  15576. this.zr.refresh();
  15577. this.animationEffect();
  15578. } else {
  15579. this.motionlessOnce = false;
  15580. this.zr.delShape(lastShapeList);
  15581. for (var i = 0, l = shapeList.length; i < l; i++) {
  15582. this.zr.addShape(shapeList[i]);
  15583. }
  15584. }
  15585. },
  15586. _getAnimationKey: function (shape) {
  15587. if (this.type != ecConfig.CHART_TYPE_MAP && this.type != ecConfig.CHART_TYPE_TREEMAP && this.type != ecConfig.CHART_TYPE_VENN && this.type != ecConfig.CHART_TYPE_TREE) {
  15588. return ecData.get(shape, 'seriesIndex') + '_' + ecData.get(shape, 'dataIndex') + (shape._mark ? shape._mark : '') + (this.type === ecConfig.CHART_TYPE_RADAR ? ecData.get(shape, 'special') : '');
  15589. } else {
  15590. return ecData.get(shape, 'seriesIndex') + '_' + ecData.get(shape, 'dataIndex') + (shape._mark ? shape._mark : 'undefined');
  15591. }
  15592. },
  15593. _animateMod: function (oldShape, newShape, duration, easing, delay, isUpdate) {
  15594. switch (newShape.type) {
  15595. case 'polyline':
  15596. case 'half-smooth-polygon':
  15597. ecAnimation.pointList(this.zr, oldShape, newShape, duration, easing);
  15598. break;
  15599. case 'rectangle':
  15600. ecAnimation.rectangle(this.zr, oldShape, newShape, duration, easing);
  15601. break;
  15602. case 'image':
  15603. case 'icon':
  15604. ecAnimation.icon(this.zr, oldShape, newShape, duration, easing, delay);
  15605. break;
  15606. case 'candle':
  15607. if (!isUpdate) {
  15608. ecAnimation.candle(this.zr, oldShape, newShape, duration, easing);
  15609. } else {
  15610. this.zr.addShape(newShape);
  15611. }
  15612. break;
  15613. case 'ring':
  15614. case 'sector':
  15615. case 'circle':
  15616. if (!isUpdate) {
  15617. ecAnimation.ring(this.zr, oldShape, newShape, duration + (ecData.get(newShape, 'dataIndex') || 0) % 20 * 100, easing);
  15618. } else if (newShape.type === 'sector') {
  15619. ecAnimation.sector(this.zr, oldShape, newShape, duration, easing);
  15620. } else {
  15621. this.zr.addShape(newShape);
  15622. }
  15623. break;
  15624. case 'text':
  15625. ecAnimation.text(this.zr, oldShape, newShape, duration, easing);
  15626. break;
  15627. case 'polygon':
  15628. if (!isUpdate) {
  15629. ecAnimation.polygon(this.zr, oldShape, newShape, duration, easing);
  15630. } else {
  15631. ecAnimation.pointList(this.zr, oldShape, newShape, duration, easing);
  15632. }
  15633. break;
  15634. case 'ribbon':
  15635. ecAnimation.ribbon(this.zr, oldShape, newShape, duration, easing);
  15636. break;
  15637. case 'gauge-pointer':
  15638. ecAnimation.gaugePointer(this.zr, oldShape, newShape, duration, easing);
  15639. break;
  15640. case 'mark-line':
  15641. ecAnimation.markline(this.zr, oldShape, newShape, duration, easing);
  15642. break;
  15643. case 'bezier-curve':
  15644. case 'line':
  15645. ecAnimation.line(this.zr, oldShape, newShape, duration, easing);
  15646. break;
  15647. default:
  15648. this.zr.addShape(newShape);
  15649. break;
  15650. }
  15651. },
  15652. animationMark: function (duration, easing, shapeList) {
  15653. var shapeList = shapeList || this.shapeList;
  15654. for (var i = 0, l = shapeList.length; i < l; i++) {
  15655. if (!shapeList[i]._mark) {
  15656. continue;
  15657. }
  15658. this._animateMod(false, shapeList[i], duration, easing, 0, true);
  15659. }
  15660. this.animationEffect(shapeList);
  15661. },
  15662. animationEffect: function (shapeList) {
  15663. !shapeList && this.clearEffectShape();
  15664. shapeList = shapeList || this.shapeList;
  15665. if (shapeList == null) {
  15666. return;
  15667. }
  15668. var zlevel = ecConfig.EFFECT_ZLEVEL;
  15669. if (this.canvasSupported) {
  15670. this.zr.modLayer(zlevel, {
  15671. motionBlur: true,
  15672. lastFrameAlpha: this.option.effectBlendAlpha || ecConfig.effectBlendAlpha
  15673. });
  15674. }
  15675. var shape;
  15676. for (var i = 0, l = shapeList.length; i < l; i++) {
  15677. shape = shapeList[i];
  15678. if (!(shape._mark && shape.effect && shape.effect.show && ecEffect[shape._mark])) {
  15679. continue;
  15680. }
  15681. ecEffect[shape._mark](this.zr, this.effectList, shape, zlevel);
  15682. this.effectList[this.effectList.length - 1]._mark = shape._mark;
  15683. }
  15684. },
  15685. clearEffectShape: function (clearMotionBlur) {
  15686. var effectList = this.effectList;
  15687. if (this.zr && effectList && effectList.length > 0) {
  15688. clearMotionBlur && this.zr.modLayer(ecConfig.EFFECT_ZLEVEL, { motionBlur: false });
  15689. this.zr.delShape(effectList);
  15690. for (var i = 0; i < effectList.length; i++) {
  15691. if (effectList[i].effectAnimator) {
  15692. effectList[i].effectAnimator.stop();
  15693. }
  15694. }
  15695. }
  15696. this.effectList = [];
  15697. },
  15698. addMark: function (seriesIndex, markData, markType) {
  15699. var serie = this.series[seriesIndex];
  15700. if (this.selectedMap[serie.name]) {
  15701. var duration = this.query(this.option, 'animationDurationUpdate');
  15702. var easing = this.query(this.option, 'animationEasing');
  15703. var oriMarkData = serie[markType].data;
  15704. var lastLength = this.shapeList.length;
  15705. serie[markType].data = markData.data;
  15706. this['_build' + markType.replace('m', 'M')](seriesIndex);
  15707. if (this.option.animation && !this.option.renderAsImage) {
  15708. this.animationMark(duration, easing, this.shapeList.slice(lastLength));
  15709. } else {
  15710. for (var i = lastLength, l = this.shapeList.length; i < l; i++) {
  15711. this.zr.addShape(this.shapeList[i]);
  15712. }
  15713. this.zr.refreshNextFrame();
  15714. }
  15715. serie[markType].data = oriMarkData;
  15716. }
  15717. },
  15718. delMark: function (seriesIndex, markName, markType) {
  15719. markType = markType.replace('mark', '').replace('large', '').toLowerCase();
  15720. var serie = this.series[seriesIndex];
  15721. if (this.selectedMap[serie.name]) {
  15722. var needRefresh = false;
  15723. var shapeList = [
  15724. this.shapeList,
  15725. this.effectList
  15726. ];
  15727. var len = 2;
  15728. while (len--) {
  15729. for (var i = 0, l = shapeList[len].length; i < l; i++) {
  15730. if (shapeList[len][i]._mark == markType && ecData.get(shapeList[len][i], 'seriesIndex') == seriesIndex && ecData.get(shapeList[len][i], 'name') == markName) {
  15731. this.zr.delShape(shapeList[len][i].id);
  15732. shapeList[len].splice(i, 1);
  15733. needRefresh = true;
  15734. break;
  15735. }
  15736. }
  15737. }
  15738. needRefresh && this.zr.refreshNextFrame();
  15739. }
  15740. }
  15741. };
  15742. zrUtil.inherits(Base, ComponentBase);
  15743. return Base;
  15744. });define('zrender/shape/Circle', [
  15745. 'require',
  15746. './Base',
  15747. '../tool/util'
  15748. ], function (require) {
  15749. 'use strict';
  15750. var Base = require('./Base');
  15751. var Circle = function (options) {
  15752. Base.call(this, options);
  15753. };
  15754. Circle.prototype = {
  15755. type: 'circle',
  15756. buildPath: function (ctx, style) {
  15757. ctx.moveTo(style.x + style.r, style.y);
  15758. ctx.arc(style.x, style.y, style.r, 0, Math.PI * 2, true);
  15759. return;
  15760. },
  15761. getRect: function (style) {
  15762. if (style.__rect) {
  15763. return style.__rect;
  15764. }
  15765. var lineWidth;
  15766. if (style.brushType == 'stroke' || style.brushType == 'fill') {
  15767. lineWidth = style.lineWidth || 1;
  15768. } else {
  15769. lineWidth = 0;
  15770. }
  15771. style.__rect = {
  15772. x: Math.round(style.x - style.r - lineWidth / 2),
  15773. y: Math.round(style.y - style.r - lineWidth / 2),
  15774. width: style.r * 2 + lineWidth,
  15775. height: style.r * 2 + lineWidth
  15776. };
  15777. return style.__rect;
  15778. }
  15779. };
  15780. require('../tool/util').inherits(Circle, Base);
  15781. return Circle;
  15782. });define('echarts/util/accMath', [], function () {
  15783. function accDiv(arg1, arg2) {
  15784. var s1 = arg1.toString();
  15785. var s2 = arg2.toString();
  15786. var m = 0;
  15787. try {
  15788. m = s2.split('.')[1].length;
  15789. } catch (e) {
  15790. }
  15791. try {
  15792. m -= s1.split('.')[1].length;
  15793. } catch (e) {
  15794. }
  15795. return (s1.replace('.', '') - 0) / (s2.replace('.', '') - 0) * Math.pow(10, m);
  15796. }
  15797. function accMul(arg1, arg2) {
  15798. var s1 = arg1.toString();
  15799. var s2 = arg2.toString();
  15800. var m = 0;
  15801. try {
  15802. m += s1.split('.')[1].length;
  15803. } catch (e) {
  15804. }
  15805. try {
  15806. m += s2.split('.')[1].length;
  15807. } catch (e) {
  15808. }
  15809. return (s1.replace('.', '') - 0) * (s2.replace('.', '') - 0) / Math.pow(10, m);
  15810. }
  15811. function accAdd(arg1, arg2) {
  15812. var r1 = 0;
  15813. var r2 = 0;
  15814. try {
  15815. r1 = arg1.toString().split('.')[1].length;
  15816. } catch (e) {
  15817. }
  15818. try {
  15819. r2 = arg2.toString().split('.')[1].length;
  15820. } catch (e) {
  15821. }
  15822. var m = Math.pow(10, Math.max(r1, r2));
  15823. return (Math.round(arg1 * m) + Math.round(arg2 * m)) / m;
  15824. }
  15825. function accSub(arg1, arg2) {
  15826. return accAdd(arg1, -arg2);
  15827. }
  15828. return {
  15829. accDiv: accDiv,
  15830. accMul: accMul,
  15831. accAdd: accAdd,
  15832. accSub: accSub
  15833. };
  15834. });define('echarts/util/shape/Icon', [
  15835. 'require',
  15836. 'zrender/tool/util',
  15837. 'zrender/shape/Star',
  15838. 'zrender/shape/Heart',
  15839. 'zrender/shape/Droplet',
  15840. 'zrender/shape/Image',
  15841. 'zrender/shape/Base'
  15842. ], function (require) {
  15843. var zrUtil = require('zrender/tool/util');
  15844. function _iconMark(ctx, style) {
  15845. var x = style.x;
  15846. var y = style.y;
  15847. var dx = style.width / 16;
  15848. var dy = style.height / 16;
  15849. ctx.moveTo(x, y + style.height);
  15850. ctx.lineTo(x + 5 * dx, y + 14 * dy);
  15851. ctx.lineTo(x + style.width, y + 3 * dy);
  15852. ctx.lineTo(x + 13 * dx, y);
  15853. ctx.lineTo(x + 2 * dx, y + 11 * dy);
  15854. ctx.lineTo(x, y + style.height);
  15855. ctx.moveTo(x + 6 * dx, y + 10 * dy);
  15856. ctx.lineTo(x + 14 * dx, y + 2 * dy);
  15857. ctx.moveTo(x + 10 * dx, y + 13 * dy);
  15858. ctx.lineTo(x + style.width, y + 13 * dy);
  15859. ctx.moveTo(x + 13 * dx, y + 10 * dy);
  15860. ctx.lineTo(x + 13 * dx, y + style.height);
  15861. }
  15862. function _iconMarkUndo(ctx, style) {
  15863. var x = style.x;
  15864. var y = style.y;
  15865. var dx = style.width / 16;
  15866. var dy = style.height / 16;
  15867. ctx.moveTo(x, y + style.height);
  15868. ctx.lineTo(x + 5 * dx, y + 14 * dy);
  15869. ctx.lineTo(x + style.width, y + 3 * dy);
  15870. ctx.lineTo(x + 13 * dx, y);
  15871. ctx.lineTo(x + 2 * dx, y + 11 * dy);
  15872. ctx.lineTo(x, y + style.height);
  15873. ctx.moveTo(x + 6 * dx, y + 10 * dy);
  15874. ctx.lineTo(x + 14 * dx, y + 2 * dy);
  15875. ctx.moveTo(x + 10 * dx, y + 13 * dy);
  15876. ctx.lineTo(x + style.width, y + 13 * dy);
  15877. }
  15878. function _iconMarkClear(ctx, style) {
  15879. var x = style.x;
  15880. var y = style.y;
  15881. var dx = style.width / 16;
  15882. var dy = style.height / 16;
  15883. ctx.moveTo(x + 4 * dx, y + 15 * dy);
  15884. ctx.lineTo(x + 9 * dx, y + 13 * dy);
  15885. ctx.lineTo(x + 14 * dx, y + 8 * dy);
  15886. ctx.lineTo(x + 11 * dx, y + 5 * dy);
  15887. ctx.lineTo(x + 6 * dx, y + 10 * dy);
  15888. ctx.lineTo(x + 4 * dx, y + 15 * dy);
  15889. ctx.moveTo(x + 5 * dx, y);
  15890. ctx.lineTo(x + 11 * dx, y);
  15891. ctx.moveTo(x + 5 * dx, y + dy);
  15892. ctx.lineTo(x + 11 * dx, y + dy);
  15893. ctx.moveTo(x, y + 2 * dy);
  15894. ctx.lineTo(x + style.width, y + 2 * dy);
  15895. ctx.moveTo(x, y + 5 * dy);
  15896. ctx.lineTo(x + 3 * dx, y + style.height);
  15897. ctx.lineTo(x + 13 * dx, y + style.height);
  15898. ctx.lineTo(x + style.width, y + 5 * dy);
  15899. }
  15900. function _iconDataZoom(ctx, style) {
  15901. var x = style.x;
  15902. var y = style.y;
  15903. var dx = style.width / 16;
  15904. var dy = style.height / 16;
  15905. ctx.moveTo(x, y + 3 * dy);
  15906. ctx.lineTo(x + 6 * dx, y + 3 * dy);
  15907. ctx.moveTo(x + 3 * dx, y);
  15908. ctx.lineTo(x + 3 * dx, y + 6 * dy);
  15909. ctx.moveTo(x + 3 * dx, y + 8 * dy);
  15910. ctx.lineTo(x + 3 * dx, y + style.height);
  15911. ctx.lineTo(x + style.width, y + style.height);
  15912. ctx.lineTo(x + style.width, y + 3 * dy);
  15913. ctx.lineTo(x + 8 * dx, y + 3 * dy);
  15914. }
  15915. function _iconDataZoomReset(ctx, style) {
  15916. var x = style.x;
  15917. var y = style.y;
  15918. var dx = style.width / 16;
  15919. var dy = style.height / 16;
  15920. ctx.moveTo(x + 6 * dx, y);
  15921. ctx.lineTo(x + 2 * dx, y + 3 * dy);
  15922. ctx.lineTo(x + 6 * dx, y + 6 * dy);
  15923. ctx.moveTo(x + 2 * dx, y + 3 * dy);
  15924. ctx.lineTo(x + 14 * dx, y + 3 * dy);
  15925. ctx.lineTo(x + 14 * dx, y + 11 * dy);
  15926. ctx.moveTo(x + 2 * dx, y + 5 * dy);
  15927. ctx.lineTo(x + 2 * dx, y + 13 * dy);
  15928. ctx.lineTo(x + 14 * dx, y + 13 * dy);
  15929. ctx.moveTo(x + 10 * dx, y + 10 * dy);
  15930. ctx.lineTo(x + 14 * dx, y + 13 * dy);
  15931. ctx.lineTo(x + 10 * dx, y + style.height);
  15932. }
  15933. function _iconRestore(ctx, style) {
  15934. var x = style.x;
  15935. var y = style.y;
  15936. var dx = style.width / 16;
  15937. var dy = style.height / 16;
  15938. var r = style.width / 2;
  15939. ctx.lineWidth = 1.5;
  15940. ctx.arc(x + r, y + r, r - dx, 0, Math.PI * 2 / 3);
  15941. ctx.moveTo(x + 3 * dx, y + style.height);
  15942. ctx.lineTo(x + 0 * dx, y + 12 * dy);
  15943. ctx.lineTo(x + 5 * dx, y + 11 * dy);
  15944. ctx.moveTo(x, y + 8 * dy);
  15945. ctx.arc(x + r, y + r, r - dx, Math.PI, Math.PI * 5 / 3);
  15946. ctx.moveTo(x + 13 * dx, y);
  15947. ctx.lineTo(x + style.width, y + 4 * dy);
  15948. ctx.lineTo(x + 11 * dx, y + 5 * dy);
  15949. }
  15950. function _iconLineChart(ctx, style) {
  15951. var x = style.x;
  15952. var y = style.y;
  15953. var dx = style.width / 16;
  15954. var dy = style.height / 16;
  15955. ctx.moveTo(x, y);
  15956. ctx.lineTo(x, y + style.height);
  15957. ctx.lineTo(x + style.width, y + style.height);
  15958. ctx.moveTo(x + 2 * dx, y + 14 * dy);
  15959. ctx.lineTo(x + 7 * dx, y + 6 * dy);
  15960. ctx.lineTo(x + 11 * dx, y + 11 * dy);
  15961. ctx.lineTo(x + 15 * dx, y + 2 * dy);
  15962. }
  15963. function _iconBarChart(ctx, style) {
  15964. var x = style.x;
  15965. var y = style.y;
  15966. var dx = style.width / 16;
  15967. var dy = style.height / 16;
  15968. ctx.moveTo(x, y);
  15969. ctx.lineTo(x, y + style.height);
  15970. ctx.lineTo(x + style.width, y + style.height);
  15971. ctx.moveTo(x + 3 * dx, y + 14 * dy);
  15972. ctx.lineTo(x + 3 * dx, y + 6 * dy);
  15973. ctx.lineTo(x + 4 * dx, y + 6 * dy);
  15974. ctx.lineTo(x + 4 * dx, y + 14 * dy);
  15975. ctx.moveTo(x + 7 * dx, y + 14 * dy);
  15976. ctx.lineTo(x + 7 * dx, y + 2 * dy);
  15977. ctx.lineTo(x + 8 * dx, y + 2 * dy);
  15978. ctx.lineTo(x + 8 * dx, y + 14 * dy);
  15979. ctx.moveTo(x + 11 * dx, y + 14 * dy);
  15980. ctx.lineTo(x + 11 * dx, y + 9 * dy);
  15981. ctx.lineTo(x + 12 * dx, y + 9 * dy);
  15982. ctx.lineTo(x + 12 * dx, y + 14 * dy);
  15983. }
  15984. function _iconPieChart(ctx, style) {
  15985. var x = style.x;
  15986. var y = style.y;
  15987. var width = style.width - 2;
  15988. var height = style.height - 2;
  15989. var r = Math.min(width, height) / 2;
  15990. y += 2;
  15991. ctx.moveTo(x + r + 3, y + r - 3);
  15992. ctx.arc(x + r + 3, y + r - 3, r - 1, 0, -Math.PI / 2, true);
  15993. ctx.lineTo(x + r + 3, y + r - 3);
  15994. ctx.moveTo(x + r, y);
  15995. ctx.lineTo(x + r, y + r);
  15996. ctx.arc(x + r, y + r, r, -Math.PI / 2, Math.PI * 2, true);
  15997. ctx.lineTo(x + r, y + r);
  15998. ctx.lineWidth = 1.5;
  15999. }
  16000. function _iconFunnelChart(ctx, style) {
  16001. var x = style.x;
  16002. var y = style.y;
  16003. var dx = style.width / 16;
  16004. var dy = style.height / 16;
  16005. y -= dy;
  16006. ctx.moveTo(x + 1 * dx, y + 2 * dy);
  16007. ctx.lineTo(x + 15 * dx, y + 2 * dy);
  16008. ctx.lineTo(x + 14 * dx, y + 3 * dy);
  16009. ctx.lineTo(x + 2 * dx, y + 3 * dy);
  16010. ctx.moveTo(x + 3 * dx, y + 6 * dy);
  16011. ctx.lineTo(x + 13 * dx, y + 6 * dy);
  16012. ctx.lineTo(x + 12 * dx, y + 7 * dy);
  16013. ctx.lineTo(x + 4 * dx, y + 7 * dy);
  16014. ctx.moveTo(x + 5 * dx, y + 10 * dy);
  16015. ctx.lineTo(x + 11 * dx, y + 10 * dy);
  16016. ctx.lineTo(x + 10 * dx, y + 11 * dy);
  16017. ctx.lineTo(x + 6 * dx, y + 11 * dy);
  16018. ctx.moveTo(x + 7 * dx, y + 14 * dy);
  16019. ctx.lineTo(x + 9 * dx, y + 14 * dy);
  16020. ctx.lineTo(x + 8 * dx, y + 15 * dy);
  16021. ctx.lineTo(x + 7 * dx, y + 15 * dy);
  16022. }
  16023. function _iconForceChart(ctx, style) {
  16024. var x = style.x;
  16025. var y = style.y;
  16026. var width = style.width;
  16027. var height = style.height;
  16028. var dx = width / 16;
  16029. var dy = height / 16;
  16030. var r = Math.min(dx, dy) * 2;
  16031. ctx.moveTo(x + dx + r, y + dy + r);
  16032. ctx.arc(x + dx, y + dy, r, Math.PI / 4, Math.PI * 3);
  16033. ctx.lineTo(x + 7 * dx - r, y + 6 * dy - r);
  16034. ctx.arc(x + 7 * dx, y + 6 * dy, r, Math.PI / 4 * 5, Math.PI * 4);
  16035. ctx.arc(x + 7 * dx, y + 6 * dy, r / 2, Math.PI / 4 * 5, Math.PI * 4);
  16036. ctx.moveTo(x + 7 * dx - r / 2, y + 6 * dy + r);
  16037. ctx.lineTo(x + dx + r, y + 14 * dy - r);
  16038. ctx.arc(x + dx, y + 14 * dy, r, -Math.PI / 4, Math.PI * 2);
  16039. ctx.moveTo(x + 7 * dx + r / 2, y + 6 * dy);
  16040. ctx.lineTo(x + 14 * dx - r, y + 10 * dy - r / 2);
  16041. ctx.moveTo(x + 16 * dx, y + 10 * dy);
  16042. ctx.arc(x + 14 * dx, y + 10 * dy, r, 0, Math.PI * 3);
  16043. ctx.lineWidth = 1.5;
  16044. }
  16045. function _iconChordChart(ctx, style) {
  16046. var x = style.x;
  16047. var y = style.y;
  16048. var width = style.width;
  16049. var height = style.height;
  16050. var r = Math.min(width, height) / 2;
  16051. ctx.moveTo(x + width, y + height / 2);
  16052. ctx.arc(x + r, y + r, r, 0, Math.PI * 2);
  16053. ctx.arc(x + r, y, r, Math.PI / 4, Math.PI / 5 * 4);
  16054. ctx.arc(x, y + r, r, -Math.PI / 3, Math.PI / 3);
  16055. ctx.arc(x + width, y + height, r, Math.PI, Math.PI / 2 * 3);
  16056. ctx.lineWidth = 1.5;
  16057. }
  16058. function _iconStackChart(ctx, style) {
  16059. var x = style.x;
  16060. var y = style.y;
  16061. var width = style.width;
  16062. var height = style.height;
  16063. var dy = Math.round(height / 3);
  16064. var delta = Math.round((dy - 2) / 2);
  16065. var len = 3;
  16066. while (len--) {
  16067. ctx.rect(x, y + dy * len + delta, width, 2);
  16068. }
  16069. }
  16070. function _iconTiledChart(ctx, style) {
  16071. var x = style.x;
  16072. var y = style.y;
  16073. var width = style.width;
  16074. var height = style.height;
  16075. var dx = Math.round(width / 3);
  16076. var delta = Math.round((dx - 2) / 2);
  16077. var len = 3;
  16078. while (len--) {
  16079. ctx.rect(x + dx * len + delta, y, 2, height);
  16080. }
  16081. }
  16082. function _iconDataView(ctx, style) {
  16083. var x = style.x;
  16084. var y = style.y;
  16085. var dx = style.width / 16;
  16086. ctx.moveTo(x + dx, y);
  16087. ctx.lineTo(x + dx, y + style.height);
  16088. ctx.lineTo(x + 15 * dx, y + style.height);
  16089. ctx.lineTo(x + 15 * dx, y);
  16090. ctx.lineTo(x + dx, y);
  16091. ctx.moveTo(x + 3 * dx, y + 3 * dx);
  16092. ctx.lineTo(x + 13 * dx, y + 3 * dx);
  16093. ctx.moveTo(x + 3 * dx, y + 6 * dx);
  16094. ctx.lineTo(x + 13 * dx, y + 6 * dx);
  16095. ctx.moveTo(x + 3 * dx, y + 9 * dx);
  16096. ctx.lineTo(x + 13 * dx, y + 9 * dx);
  16097. ctx.moveTo(x + 3 * dx, y + 12 * dx);
  16098. ctx.lineTo(x + 9 * dx, y + 12 * dx);
  16099. }
  16100. function _iconSave(ctx, style) {
  16101. var x = style.x;
  16102. var y = style.y;
  16103. var dx = style.width / 16;
  16104. var dy = style.height / 16;
  16105. ctx.moveTo(x, y);
  16106. ctx.lineTo(x, y + style.height);
  16107. ctx.lineTo(x + style.width, y + style.height);
  16108. ctx.lineTo(x + style.width, y);
  16109. ctx.lineTo(x, y);
  16110. ctx.moveTo(x + 4 * dx, y);
  16111. ctx.lineTo(x + 4 * dx, y + 8 * dy);
  16112. ctx.lineTo(x + 12 * dx, y + 8 * dy);
  16113. ctx.lineTo(x + 12 * dx, y);
  16114. ctx.moveTo(x + 6 * dx, y + 11 * dy);
  16115. ctx.lineTo(x + 6 * dx, y + 13 * dy);
  16116. ctx.lineTo(x + 10 * dx, y + 13 * dy);
  16117. ctx.lineTo(x + 10 * dx, y + 11 * dy);
  16118. ctx.lineTo(x + 6 * dx, y + 11 * dy);
  16119. }
  16120. function _iconCross(ctx, style) {
  16121. var x = style.x;
  16122. var y = style.y;
  16123. var width = style.width;
  16124. var height = style.height;
  16125. ctx.moveTo(x, y + height / 2);
  16126. ctx.lineTo(x + width, y + height / 2);
  16127. ctx.moveTo(x + width / 2, y);
  16128. ctx.lineTo(x + width / 2, y + height);
  16129. }
  16130. function _iconCircle(ctx, style) {
  16131. var width = style.width / 2;
  16132. var height = style.height / 2;
  16133. var r = Math.min(width, height);
  16134. ctx.moveTo(style.x + width + r, style.y + height);
  16135. ctx.arc(style.x + width, style.y + height, r, 0, Math.PI * 2);
  16136. ctx.closePath();
  16137. }
  16138. function _iconRectangle(ctx, style) {
  16139. ctx.rect(style.x, style.y, style.width, style.height);
  16140. ctx.closePath();
  16141. }
  16142. function _iconTriangle(ctx, style) {
  16143. var width = style.width / 2;
  16144. var height = style.height / 2;
  16145. var x = style.x + width;
  16146. var y = style.y + height;
  16147. var symbolSize = Math.min(width, height);
  16148. ctx.moveTo(x, y - symbolSize);
  16149. ctx.lineTo(x + symbolSize, y + symbolSize);
  16150. ctx.lineTo(x - symbolSize, y + symbolSize);
  16151. ctx.lineTo(x, y - symbolSize);
  16152. ctx.closePath();
  16153. }
  16154. function _iconDiamond(ctx, style) {
  16155. var width = style.width / 2;
  16156. var height = style.height / 2;
  16157. var x = style.x + width;
  16158. var y = style.y + height;
  16159. var symbolSize = Math.min(width, height);
  16160. ctx.moveTo(x, y - symbolSize);
  16161. ctx.lineTo(x + symbolSize, y);
  16162. ctx.lineTo(x, y + symbolSize);
  16163. ctx.lineTo(x - symbolSize, y);
  16164. ctx.lineTo(x, y - symbolSize);
  16165. ctx.closePath();
  16166. }
  16167. function _iconArrow(ctx, style) {
  16168. var x = style.x;
  16169. var y = style.y;
  16170. var dx = style.width / 16;
  16171. ctx.moveTo(x + 8 * dx, y);
  16172. ctx.lineTo(x + dx, y + style.height);
  16173. ctx.lineTo(x + 8 * dx, y + style.height / 4 * 3);
  16174. ctx.lineTo(x + 15 * dx, y + style.height);
  16175. ctx.lineTo(x + 8 * dx, y);
  16176. ctx.closePath();
  16177. }
  16178. function _iconStar(ctx, style) {
  16179. var StarShape = require('zrender/shape/Star');
  16180. var width = style.width / 2;
  16181. var height = style.height / 2;
  16182. StarShape.prototype.buildPath(ctx, {
  16183. x: style.x + width,
  16184. y: style.y + height,
  16185. r: Math.min(width, height),
  16186. n: style.n || 5
  16187. });
  16188. }
  16189. function _iconHeart(ctx, style) {
  16190. var HeartShape = require('zrender/shape/Heart');
  16191. HeartShape.prototype.buildPath(ctx, {
  16192. x: style.x + style.width / 2,
  16193. y: style.y + style.height * 0.2,
  16194. a: style.width / 2,
  16195. b: style.height * 0.8
  16196. });
  16197. }
  16198. function _iconDroplet(ctx, style) {
  16199. var DropletShape = require('zrender/shape/Droplet');
  16200. DropletShape.prototype.buildPath(ctx, {
  16201. x: style.x + style.width * 0.5,
  16202. y: style.y + style.height * 0.5,
  16203. a: style.width * 0.5,
  16204. b: style.height * 0.8
  16205. });
  16206. }
  16207. function _iconPin(ctx, style) {
  16208. var x = style.x;
  16209. var y = style.y - style.height / 2 * 1.5;
  16210. var width = style.width / 2;
  16211. var height = style.height / 2;
  16212. var r = Math.min(width, height);
  16213. ctx.arc(x + width, y + height, r, Math.PI / 5 * 4, Math.PI / 5);
  16214. ctx.lineTo(x + width, y + height + r * 1.5);
  16215. ctx.closePath();
  16216. }
  16217. function _iconImage(ctx, style, refreshNextFrame) {
  16218. var ImageShape = require('zrender/shape/Image');
  16219. this._imageShape = this._imageShape || new ImageShape({ style: {} });
  16220. for (var name in style) {
  16221. this._imageShape.style[name] = style[name];
  16222. }
  16223. this._imageShape.brush(ctx, false, refreshNextFrame);
  16224. }
  16225. var Base = require('zrender/shape/Base');
  16226. function Icon(options) {
  16227. Base.call(this, options);
  16228. }
  16229. Icon.prototype = {
  16230. type: 'icon',
  16231. iconLibrary: {
  16232. mark: _iconMark,
  16233. markUndo: _iconMarkUndo,
  16234. markClear: _iconMarkClear,
  16235. dataZoom: _iconDataZoom,
  16236. dataZoomReset: _iconDataZoomReset,
  16237. restore: _iconRestore,
  16238. lineChart: _iconLineChart,
  16239. barChart: _iconBarChart,
  16240. pieChart: _iconPieChart,
  16241. funnelChart: _iconFunnelChart,
  16242. forceChart: _iconForceChart,
  16243. chordChart: _iconChordChart,
  16244. stackChart: _iconStackChart,
  16245. tiledChart: _iconTiledChart,
  16246. dataView: _iconDataView,
  16247. saveAsImage: _iconSave,
  16248. cross: _iconCross,
  16249. circle: _iconCircle,
  16250. rectangle: _iconRectangle,
  16251. triangle: _iconTriangle,
  16252. diamond: _iconDiamond,
  16253. arrow: _iconArrow,
  16254. star: _iconStar,
  16255. heart: _iconHeart,
  16256. droplet: _iconDroplet,
  16257. pin: _iconPin,
  16258. image: _iconImage
  16259. },
  16260. brush: function (ctx, isHighlight, refreshNextFrame) {
  16261. var style = isHighlight ? this.highlightStyle : this.style;
  16262. style = style || {};
  16263. var iconType = style.iconType || this.style.iconType;
  16264. if (iconType === 'image') {
  16265. var ImageShape = require('zrender/shape/Image');
  16266. ImageShape.prototype.brush.call(this, ctx, isHighlight, refreshNextFrame);
  16267. } else {
  16268. var style = this.beforeBrush(ctx, isHighlight);
  16269. ctx.beginPath();
  16270. this.buildPath(ctx, style, refreshNextFrame);
  16271. switch (style.brushType) {
  16272. case 'both':
  16273. ctx.fill();
  16274. case 'stroke':
  16275. style.lineWidth > 0 && ctx.stroke();
  16276. break;
  16277. default:
  16278. ctx.fill();
  16279. }
  16280. this.drawText(ctx, style, this.style);
  16281. this.afterBrush(ctx);
  16282. }
  16283. },
  16284. buildPath: function (ctx, style, refreshNextFrame) {
  16285. if (this.iconLibrary[style.iconType]) {
  16286. this.iconLibrary[style.iconType].call(this, ctx, style, refreshNextFrame);
  16287. } else {
  16288. ctx.moveTo(style.x, style.y);
  16289. ctx.lineTo(style.x + style.width, style.y);
  16290. ctx.lineTo(style.x + style.width, style.y + style.height);
  16291. ctx.lineTo(style.x, style.y + style.height);
  16292. ctx.lineTo(style.x, style.y);
  16293. ctx.closePath();
  16294. }
  16295. return;
  16296. },
  16297. getRect: function (style) {
  16298. if (style.__rect) {
  16299. return style.__rect;
  16300. }
  16301. style.__rect = {
  16302. x: Math.round(style.x),
  16303. y: Math.round(style.y - (style.iconType == 'pin' ? style.height / 2 * 1.5 : 0)),
  16304. width: style.width,
  16305. height: style.height * (style.iconType === 'pin' ? 1.25 : 1)
  16306. };
  16307. return style.__rect;
  16308. },
  16309. isCover: function (x, y) {
  16310. var originPos = this.transformCoordToLocal(x, y);
  16311. x = originPos[0];
  16312. y = originPos[1];
  16313. var rect = this.style.__rect;
  16314. if (!rect) {
  16315. rect = this.style.__rect = this.getRect(this.style);
  16316. }
  16317. var delta = rect.height < 8 || rect.width < 8 ? 4 : 0;
  16318. return x >= rect.x - delta && x <= rect.x + rect.width + delta && y >= rect.y - delta && y <= rect.y + rect.height + delta;
  16319. }
  16320. };
  16321. zrUtil.inherits(Icon, Base);
  16322. return Icon;
  16323. });define('echarts/util/shape/MarkLine', [
  16324. 'require',
  16325. 'zrender/shape/Base',
  16326. './Icon',
  16327. 'zrender/shape/Line',
  16328. 'zrender/shape/BezierCurve',
  16329. 'zrender/tool/area',
  16330. 'zrender/shape/util/dashedLineTo',
  16331. 'zrender/tool/util',
  16332. 'zrender/tool/curve'
  16333. ], function (require) {
  16334. var Base = require('zrender/shape/Base');
  16335. var IconShape = require('./Icon');
  16336. var LineShape = require('zrender/shape/Line');
  16337. var lineInstance = new LineShape({});
  16338. var CurveShape = require('zrender/shape/BezierCurve');
  16339. var curveInstance = new CurveShape({});
  16340. var area = require('zrender/tool/area');
  16341. var dashedLineTo = require('zrender/shape/util/dashedLineTo');
  16342. var zrUtil = require('zrender/tool/util');
  16343. var curveTool = require('zrender/tool/curve');
  16344. function MarkLine(options) {
  16345. Base.call(this, options);
  16346. if (this.style.curveness > 0) {
  16347. this.updatePoints(this.style);
  16348. }
  16349. if (this.highlightStyle.curveness > 0) {
  16350. this.updatePoints(this.highlightStyle);
  16351. }
  16352. }
  16353. MarkLine.prototype = {
  16354. type: 'mark-line',
  16355. brush: function (ctx, isHighlight) {
  16356. var style = this.style;
  16357. if (isHighlight) {
  16358. style = this.getHighlightStyle(style, this.highlightStyle || {});
  16359. }
  16360. ctx.save();
  16361. this.setContext(ctx, style);
  16362. this.setTransform(ctx);
  16363. ctx.save();
  16364. ctx.beginPath();
  16365. this.buildPath(ctx, style);
  16366. ctx.stroke();
  16367. ctx.restore();
  16368. this.brushSymbol(ctx, style, 0);
  16369. this.brushSymbol(ctx, style, 1);
  16370. this.drawText(ctx, style, this.style);
  16371. ctx.restore();
  16372. },
  16373. buildPath: function (ctx, style) {
  16374. var lineType = style.lineType || 'solid';
  16375. ctx.moveTo(style.xStart, style.yStart);
  16376. if (style.curveness > 0) {
  16377. var lineDash = null;
  16378. switch (lineType) {
  16379. case 'dashed':
  16380. lineDash = [
  16381. 5,
  16382. 5
  16383. ];
  16384. break;
  16385. case 'dotted':
  16386. lineDash = [
  16387. 1,
  16388. 1
  16389. ];
  16390. break;
  16391. }
  16392. if (lineDash && ctx.setLineDash) {
  16393. ctx.setLineDash(lineDash);
  16394. }
  16395. ctx.quadraticCurveTo(style.cpX1, style.cpY1, style.xEnd, style.yEnd);
  16396. } else {
  16397. if (lineType == 'solid') {
  16398. ctx.lineTo(style.xEnd, style.yEnd);
  16399. } else {
  16400. var dashLength = (style.lineWidth || 1) * (style.lineType == 'dashed' ? 5 : 1);
  16401. dashedLineTo(ctx, style.xStart, style.yStart, style.xEnd, style.yEnd, dashLength);
  16402. }
  16403. }
  16404. },
  16405. updatePoints: function (style) {
  16406. var curveness = style.curveness || 0;
  16407. var inv = 1;
  16408. var x0 = style.xStart;
  16409. var y0 = style.yStart;
  16410. var x2 = style.xEnd;
  16411. var y2 = style.yEnd;
  16412. var x1 = (x0 + x2) / 2 - inv * (y0 - y2) * curveness;
  16413. var y1 = (y0 + y2) / 2 - inv * (x2 - x0) * curveness;
  16414. style.cpX1 = x1;
  16415. style.cpY1 = y1;
  16416. },
  16417. brushSymbol: function (ctx, style, idx) {
  16418. if (style.symbol[idx] == 'none') {
  16419. return;
  16420. }
  16421. ctx.save();
  16422. ctx.beginPath();
  16423. ctx.lineWidth = style.symbolBorder;
  16424. ctx.strokeStyle = style.symbolBorderColor;
  16425. var symbol = style.symbol[idx].replace('empty', '').toLowerCase();
  16426. if (style.symbol[idx].match('empty')) {
  16427. ctx.fillStyle = '#fff';
  16428. }
  16429. var x0 = style.xStart;
  16430. var y0 = style.yStart;
  16431. var x2 = style.xEnd;
  16432. var y2 = style.yEnd;
  16433. var x = idx === 0 ? x0 : x2;
  16434. var y = idx === 0 ? y0 : y2;
  16435. var curveness = style.curveness || 0;
  16436. var rotate = style.symbolRotate[idx] != null ? style.symbolRotate[idx] - 0 : 0;
  16437. rotate = rotate / 180 * Math.PI;
  16438. if (symbol == 'arrow' && rotate === 0) {
  16439. if (curveness === 0) {
  16440. var sign = idx === 0 ? -1 : 1;
  16441. rotate = Math.PI / 2 + Math.atan2(sign * (y2 - y0), sign * (x2 - x0));
  16442. } else {
  16443. var x1 = style.cpX1;
  16444. var y1 = style.cpY1;
  16445. var quadraticDerivativeAt = curveTool.quadraticDerivativeAt;
  16446. var dx = quadraticDerivativeAt(x0, x1, x2, idx);
  16447. var dy = quadraticDerivativeAt(y0, y1, y2, idx);
  16448. rotate = Math.PI / 2 + Math.atan2(dy, dx);
  16449. }
  16450. }
  16451. ctx.translate(x, y);
  16452. if (rotate !== 0) {
  16453. ctx.rotate(rotate);
  16454. }
  16455. var symbolSize = style.symbolSize[idx];
  16456. IconShape.prototype.buildPath(ctx, {
  16457. x: -symbolSize,
  16458. y: -symbolSize,
  16459. width: symbolSize * 2,
  16460. height: symbolSize * 2,
  16461. iconType: symbol
  16462. });
  16463. ctx.closePath();
  16464. ctx.fill();
  16465. ctx.stroke();
  16466. ctx.restore();
  16467. },
  16468. getRect: function (style) {
  16469. style.curveness > 0 ? curveInstance.getRect(style) : lineInstance.getRect(style);
  16470. return style.__rect;
  16471. },
  16472. isCover: function (x, y) {
  16473. var originPos = this.transformCoordToLocal(x, y);
  16474. x = originPos[0];
  16475. y = originPos[1];
  16476. if (this.isCoverRect(x, y)) {
  16477. return this.style.curveness > 0 ? area.isInside(curveInstance, this.style, x, y) : area.isInside(lineInstance, this.style, x, y);
  16478. }
  16479. return false;
  16480. }
  16481. };
  16482. zrUtil.inherits(MarkLine, Base);
  16483. return MarkLine;
  16484. });define('echarts/util/shape/Symbol', [
  16485. 'require',
  16486. 'zrender/shape/Base',
  16487. 'zrender/shape/Polygon',
  16488. 'zrender/tool/util',
  16489. './normalIsCover'
  16490. ], function (require) {
  16491. var Base = require('zrender/shape/Base');
  16492. var PolygonShape = require('zrender/shape/Polygon');
  16493. var polygonInstance = new PolygonShape({});
  16494. var zrUtil = require('zrender/tool/util');
  16495. function Symbol(options) {
  16496. Base.call(this, options);
  16497. }
  16498. Symbol.prototype = {
  16499. type: 'symbol',
  16500. buildPath: function (ctx, style) {
  16501. var pointList = style.pointList;
  16502. var len = pointList.length;
  16503. if (len === 0) {
  16504. return;
  16505. }
  16506. var subSize = 10000;
  16507. var subSetLength = Math.ceil(len / subSize);
  16508. var sub;
  16509. var subLen;
  16510. var isArray = pointList[0] instanceof Array;
  16511. var size = style.size ? style.size : 2;
  16512. var curSize = size;
  16513. var halfSize = size / 2;
  16514. var PI2 = Math.PI * 2;
  16515. var percent;
  16516. var x;
  16517. var y;
  16518. for (var j = 0; j < subSetLength; j++) {
  16519. ctx.beginPath();
  16520. sub = j * subSize;
  16521. subLen = sub + subSize;
  16522. subLen = subLen > len ? len : subLen;
  16523. for (var i = sub; i < subLen; i++) {
  16524. if (style.random) {
  16525. percent = style['randomMap' + i % 20] / 100;
  16526. curSize = size * percent * percent;
  16527. halfSize = curSize / 2;
  16528. }
  16529. if (isArray) {
  16530. x = pointList[i][0];
  16531. y = pointList[i][1];
  16532. } else {
  16533. x = pointList[i].x;
  16534. y = pointList[i].y;
  16535. }
  16536. if (curSize < 3) {
  16537. ctx.rect(x - halfSize, y - halfSize, curSize, curSize);
  16538. } else {
  16539. switch (style.iconType) {
  16540. case 'circle':
  16541. ctx.moveTo(x, y);
  16542. ctx.arc(x, y, halfSize, 0, PI2, true);
  16543. break;
  16544. case 'diamond':
  16545. ctx.moveTo(x, y - halfSize);
  16546. ctx.lineTo(x + halfSize / 3, y - halfSize / 3);
  16547. ctx.lineTo(x + halfSize, y);
  16548. ctx.lineTo(x + halfSize / 3, y + halfSize / 3);
  16549. ctx.lineTo(x, y + halfSize);
  16550. ctx.lineTo(x - halfSize / 3, y + halfSize / 3);
  16551. ctx.lineTo(x - halfSize, y);
  16552. ctx.lineTo(x - halfSize / 3, y - halfSize / 3);
  16553. ctx.lineTo(x, y - halfSize);
  16554. break;
  16555. default:
  16556. ctx.rect(x - halfSize, y - halfSize, curSize, curSize);
  16557. }
  16558. }
  16559. }
  16560. ctx.closePath();
  16561. if (j < subSetLength - 1) {
  16562. switch (style.brushType) {
  16563. case 'both':
  16564. ctx.fill();
  16565. style.lineWidth > 0 && ctx.stroke();
  16566. break;
  16567. case 'stroke':
  16568. style.lineWidth > 0 && ctx.stroke();
  16569. break;
  16570. default:
  16571. ctx.fill();
  16572. }
  16573. }
  16574. }
  16575. },
  16576. getRect: function (style) {
  16577. return style.__rect || polygonInstance.getRect(style);
  16578. },
  16579. isCover: require('./normalIsCover')
  16580. };
  16581. zrUtil.inherits(Symbol, Base);
  16582. return Symbol;
  16583. });define('zrender/shape/Polyline', [
  16584. 'require',
  16585. './Base',
  16586. './util/smoothSpline',
  16587. './util/smoothBezier',
  16588. './util/dashedLineTo',
  16589. './Polygon',
  16590. '../tool/util'
  16591. ], function (require) {
  16592. var Base = require('./Base');
  16593. var smoothSpline = require('./util/smoothSpline');
  16594. var smoothBezier = require('./util/smoothBezier');
  16595. var dashedLineTo = require('./util/dashedLineTo');
  16596. var Polyline = function (options) {
  16597. this.brushTypeOnly = 'stroke';
  16598. this.textPosition = 'end';
  16599. Base.call(this, options);
  16600. };
  16601. Polyline.prototype = {
  16602. type: 'polyline',
  16603. buildPath: function (ctx, style) {
  16604. var pointList = style.pointList;
  16605. if (pointList.length < 2) {
  16606. return;
  16607. }
  16608. var len = Math.min(style.pointList.length, Math.round(style.pointListLength || style.pointList.length));
  16609. if (style.smooth && style.smooth !== 'spline') {
  16610. if (!style.controlPointList) {
  16611. this.updateControlPoints(style);
  16612. }
  16613. var controlPointList = style.controlPointList;
  16614. ctx.moveTo(pointList[0][0], pointList[0][1]);
  16615. var cp1;
  16616. var cp2;
  16617. var p;
  16618. for (var i = 0; i < len - 1; i++) {
  16619. cp1 = controlPointList[i * 2];
  16620. cp2 = controlPointList[i * 2 + 1];
  16621. p = pointList[i + 1];
  16622. ctx.bezierCurveTo(cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]);
  16623. }
  16624. } else {
  16625. if (style.smooth === 'spline') {
  16626. pointList = smoothSpline(pointList);
  16627. len = pointList.length;
  16628. }
  16629. if (!style.lineType || style.lineType == 'solid') {
  16630. ctx.moveTo(pointList[0][0], pointList[0][1]);
  16631. for (var i = 1; i < len; i++) {
  16632. ctx.lineTo(pointList[i][0], pointList[i][1]);
  16633. }
  16634. } else if (style.lineType == 'dashed' || style.lineType == 'dotted') {
  16635. var dashLength = (style.lineWidth || 1) * (style.lineType == 'dashed' ? 5 : 1);
  16636. ctx.moveTo(pointList[0][0], pointList[0][1]);
  16637. for (var i = 1; i < len; i++) {
  16638. dashedLineTo(ctx, pointList[i - 1][0], pointList[i - 1][1], pointList[i][0], pointList[i][1], dashLength);
  16639. }
  16640. }
  16641. }
  16642. return;
  16643. },
  16644. updateControlPoints: function (style) {
  16645. style.controlPointList = smoothBezier(style.pointList, style.smooth, false, style.smoothConstraint);
  16646. },
  16647. getRect: function (style) {
  16648. return require('./Polygon').prototype.getRect(style);
  16649. }
  16650. };
  16651. require('../tool/util').inherits(Polyline, Base);
  16652. return Polyline;
  16653. });define('zrender/shape/ShapeBundle', [
  16654. 'require',
  16655. './Base',
  16656. '../tool/util'
  16657. ], function (require) {
  16658. var Base = require('./Base');
  16659. var ShapeBundle = function (options) {
  16660. Base.call(this, options);
  16661. };
  16662. ShapeBundle.prototype = {
  16663. constructor: ShapeBundle,
  16664. type: 'shape-bundle',
  16665. brush: function (ctx, isHighlight) {
  16666. var style = this.beforeBrush(ctx, isHighlight);
  16667. ctx.beginPath();
  16668. for (var i = 0; i < style.shapeList.length; i++) {
  16669. var subShape = style.shapeList[i];
  16670. var subShapeStyle = subShape.style;
  16671. if (isHighlight) {
  16672. subShapeStyle = subShape.getHighlightStyle(subShapeStyle, subShape.highlightStyle || {}, subShape.brushTypeOnly);
  16673. }
  16674. subShape.buildPath(ctx, subShapeStyle);
  16675. }
  16676. switch (style.brushType) {
  16677. case 'both':
  16678. ctx.fill();
  16679. case 'stroke':
  16680. style.lineWidth > 0 && ctx.stroke();
  16681. break;
  16682. default:
  16683. ctx.fill();
  16684. }
  16685. this.drawText(ctx, style, this.style);
  16686. this.afterBrush(ctx);
  16687. },
  16688. getRect: function (style) {
  16689. if (style.__rect) {
  16690. return style.__rect;
  16691. }
  16692. var minX = Infinity;
  16693. var maxX = -Infinity;
  16694. var minY = Infinity;
  16695. var maxY = -Infinity;
  16696. for (var i = 0; i < style.shapeList.length; i++) {
  16697. var subShape = style.shapeList[i];
  16698. var subRect = subShape.getRect(subShape.style);
  16699. var minX = Math.min(subRect.x, minX);
  16700. var minY = Math.min(subRect.y, minY);
  16701. var maxX = Math.max(subRect.x + subRect.width, maxX);
  16702. var maxY = Math.max(subRect.y + subRect.height, maxY);
  16703. }
  16704. style.__rect = {
  16705. x: minX,
  16706. y: minY,
  16707. width: maxX - minX,
  16708. height: maxY - minY
  16709. };
  16710. return style.__rect;
  16711. },
  16712. isCover: function (x, y) {
  16713. var originPos = this.transformCoordToLocal(x, y);
  16714. x = originPos[0];
  16715. y = originPos[1];
  16716. if (this.isCoverRect(x, y)) {
  16717. for (var i = 0; i < this.style.shapeList.length; i++) {
  16718. var subShape = this.style.shapeList[i];
  16719. if (subShape.isCover(x, y)) {
  16720. return true;
  16721. }
  16722. }
  16723. }
  16724. return false;
  16725. }
  16726. };
  16727. require('../tool/util').inherits(ShapeBundle, Base);
  16728. return ShapeBundle;
  16729. });define('echarts/util/ecAnimation', [
  16730. 'require',
  16731. 'zrender/tool/util',
  16732. 'zrender/tool/curve',
  16733. 'zrender/shape/Polygon'
  16734. ], function (require) {
  16735. var zrUtil = require('zrender/tool/util');
  16736. var curveTool = require('zrender/tool/curve');
  16737. function pointList(zr, oldShape, newShape, duration, easing) {
  16738. var newPointList = newShape.style.pointList;
  16739. var newPointListLen = newPointList.length;
  16740. var oldPointList;
  16741. if (!oldShape) {
  16742. oldPointList = [];
  16743. if (newShape._orient != 'vertical') {
  16744. var y = newPointList[0][1];
  16745. for (var i = 0; i < newPointListLen; i++) {
  16746. oldPointList[i] = [
  16747. newPointList[i][0],
  16748. y
  16749. ];
  16750. }
  16751. } else {
  16752. var x = newPointList[0][0];
  16753. for (var i = 0; i < newPointListLen; i++) {
  16754. oldPointList[i] = [
  16755. x,
  16756. newPointList[i][1]
  16757. ];
  16758. }
  16759. }
  16760. if (newShape.type == 'half-smooth-polygon') {
  16761. oldPointList[newPointListLen - 1] = zrUtil.clone(newPointList[newPointListLen - 1]);
  16762. oldPointList[newPointListLen - 2] = zrUtil.clone(newPointList[newPointListLen - 2]);
  16763. }
  16764. oldShape = { style: { pointList: oldPointList } };
  16765. }
  16766. oldPointList = oldShape.style.pointList;
  16767. var oldPointListLen = oldPointList.length;
  16768. if (oldPointListLen == newPointListLen) {
  16769. newShape.style.pointList = oldPointList;
  16770. } else if (oldPointListLen < newPointListLen) {
  16771. newShape.style.pointList = oldPointList.concat(newPointList.slice(oldPointListLen));
  16772. } else {
  16773. newShape.style.pointList = oldPointList.slice(0, newPointListLen);
  16774. }
  16775. zr.addShape(newShape);
  16776. newShape.__animating = true;
  16777. zr.animate(newShape.id, 'style').when(duration, { pointList: newPointList }).during(function () {
  16778. if (newShape.updateControlPoints) {
  16779. newShape.updateControlPoints(newShape.style);
  16780. }
  16781. }).done(function () {
  16782. newShape.__animating = false;
  16783. }).start(easing);
  16784. }
  16785. function cloneStyle(target, source) {
  16786. var len = arguments.length;
  16787. for (var i = 2; i < len; i++) {
  16788. var prop = arguments[i];
  16789. target.style[prop] = source.style[prop];
  16790. }
  16791. }
  16792. function rectangle(zr, oldShape, newShape, duration, easing) {
  16793. var newShapeStyle = newShape.style;
  16794. if (!oldShape) {
  16795. oldShape = {
  16796. position: newShape.position,
  16797. style: {
  16798. x: newShapeStyle.x,
  16799. y: newShape._orient == 'vertical' ? newShapeStyle.y + newShapeStyle.height : newShapeStyle.y,
  16800. width: newShape._orient == 'vertical' ? newShapeStyle.width : 0,
  16801. height: newShape._orient != 'vertical' ? newShapeStyle.height : 0
  16802. }
  16803. };
  16804. }
  16805. var newX = newShapeStyle.x;
  16806. var newY = newShapeStyle.y;
  16807. var newWidth = newShapeStyle.width;
  16808. var newHeight = newShapeStyle.height;
  16809. var newPosition = [
  16810. newShape.position[0],
  16811. newShape.position[1]
  16812. ];
  16813. cloneStyle(newShape, oldShape, 'x', 'y', 'width', 'height');
  16814. newShape.position = oldShape.position;
  16815. zr.addShape(newShape);
  16816. if (newPosition[0] != oldShape.position[0] || newPosition[1] != oldShape.position[1]) {
  16817. zr.animate(newShape.id, '').when(duration, { position: newPosition }).start(easing);
  16818. }
  16819. newShape.__animating = true;
  16820. zr.animate(newShape.id, 'style').when(duration, {
  16821. x: newX,
  16822. y: newY,
  16823. width: newWidth,
  16824. height: newHeight
  16825. }).done(function () {
  16826. newShape.__animating = false;
  16827. }).start(easing);
  16828. }
  16829. function candle(zr, oldShape, newShape, duration, easing) {
  16830. if (!oldShape) {
  16831. var y = newShape.style.y;
  16832. oldShape = {
  16833. style: {
  16834. y: [
  16835. y[0],
  16836. y[0],
  16837. y[0],
  16838. y[0]
  16839. ]
  16840. }
  16841. };
  16842. }
  16843. var newY = newShape.style.y;
  16844. newShape.style.y = oldShape.style.y;
  16845. zr.addShape(newShape);
  16846. newShape.__animating = true;
  16847. zr.animate(newShape.id, 'style').when(duration, { y: newY }).done(function () {
  16848. newShape.__animating = false;
  16849. }).start(easing);
  16850. }
  16851. function ring(zr, oldShape, newShape, duration, easing) {
  16852. var x = newShape.style.x;
  16853. var y = newShape.style.y;
  16854. var r0 = newShape.style.r0;
  16855. var r = newShape.style.r;
  16856. newShape.__animating = true;
  16857. if (newShape._animationAdd != 'r') {
  16858. newShape.style.r0 = 0;
  16859. newShape.style.r = 0;
  16860. newShape.rotation = [
  16861. Math.PI * 2,
  16862. x,
  16863. y
  16864. ];
  16865. zr.addShape(newShape);
  16866. zr.animate(newShape.id, 'style').when(duration, {
  16867. r0: r0,
  16868. r: r
  16869. }).done(function () {
  16870. newShape.__animating = false;
  16871. }).start(easing);
  16872. zr.animate(newShape.id, '').when(duration, {
  16873. rotation: [
  16874. 0,
  16875. x,
  16876. y
  16877. ]
  16878. }).start(easing);
  16879. } else {
  16880. newShape.style.r0 = newShape.style.r;
  16881. zr.addShape(newShape);
  16882. zr.animate(newShape.id, 'style').when(duration, { r0: r0 }).done(function () {
  16883. newShape.__animating = false;
  16884. }).start(easing);
  16885. }
  16886. }
  16887. function sector(zr, oldShape, newShape, duration, easing) {
  16888. if (!oldShape) {
  16889. if (newShape._animationAdd != 'r') {
  16890. oldShape = {
  16891. style: {
  16892. startAngle: newShape.style.startAngle,
  16893. endAngle: newShape.style.startAngle
  16894. }
  16895. };
  16896. } else {
  16897. oldShape = { style: { r0: newShape.style.r } };
  16898. }
  16899. }
  16900. var startAngle = newShape.style.startAngle;
  16901. var endAngle = newShape.style.endAngle;
  16902. cloneStyle(newShape, oldShape, 'startAngle', 'endAngle');
  16903. zr.addShape(newShape);
  16904. newShape.__animating = true;
  16905. zr.animate(newShape.id, 'style').when(duration, {
  16906. startAngle: startAngle,
  16907. endAngle: endAngle
  16908. }).done(function () {
  16909. newShape.__animating = false;
  16910. }).start(easing);
  16911. }
  16912. function text(zr, oldShape, newShape, duration, easing) {
  16913. if (!oldShape) {
  16914. oldShape = {
  16915. style: {
  16916. x: newShape.style.textAlign == 'left' ? newShape.style.x + 100 : newShape.style.x - 100,
  16917. y: newShape.style.y
  16918. }
  16919. };
  16920. }
  16921. var x = newShape.style.x;
  16922. var y = newShape.style.y;
  16923. cloneStyle(newShape, oldShape, 'x', 'y');
  16924. zr.addShape(newShape);
  16925. newShape.__animating = true;
  16926. zr.animate(newShape.id, 'style').when(duration, {
  16927. x: x,
  16928. y: y
  16929. }).done(function () {
  16930. newShape.__animating = false;
  16931. }).start(easing);
  16932. }
  16933. function polygon(zr, oldShape, newShape, duration, easing) {
  16934. var rect = require('zrender/shape/Polygon').prototype.getRect(newShape.style);
  16935. var x = rect.x + rect.width / 2;
  16936. var y = rect.y + rect.height / 2;
  16937. newShape.scale = [
  16938. 0.1,
  16939. 0.1,
  16940. x,
  16941. y
  16942. ];
  16943. zr.addShape(newShape);
  16944. newShape.__animating = true;
  16945. zr.animate(newShape.id, '').when(duration, {
  16946. scale: [
  16947. 1,
  16948. 1,
  16949. x,
  16950. y
  16951. ]
  16952. }).done(function () {
  16953. newShape.__animating = false;
  16954. }).start(easing);
  16955. }
  16956. function ribbon(zr, oldShape, newShape, duration, easing) {
  16957. if (!oldShape) {
  16958. oldShape = {
  16959. style: {
  16960. source0: 0,
  16961. source1: newShape.style.source1 > 0 ? 360 : -360,
  16962. target0: 0,
  16963. target1: newShape.style.target1 > 0 ? 360 : -360
  16964. }
  16965. };
  16966. }
  16967. var source0 = newShape.style.source0;
  16968. var source1 = newShape.style.source1;
  16969. var target0 = newShape.style.target0;
  16970. var target1 = newShape.style.target1;
  16971. if (oldShape.style) {
  16972. cloneStyle(newShape, oldShape, 'source0', 'source1', 'target0', 'target1');
  16973. }
  16974. zr.addShape(newShape);
  16975. newShape.__animating = true;
  16976. zr.animate(newShape.id, 'style').when(duration, {
  16977. source0: source0,
  16978. source1: source1,
  16979. target0: target0,
  16980. target1: target1
  16981. }).done(function () {
  16982. newShape.__animating = false;
  16983. }).start(easing);
  16984. }
  16985. function gaugePointer(zr, oldShape, newShape, duration, easing) {
  16986. if (!oldShape) {
  16987. oldShape = { style: { angle: newShape.style.startAngle } };
  16988. }
  16989. var angle = newShape.style.angle;
  16990. newShape.style.angle = oldShape.style.angle;
  16991. zr.addShape(newShape);
  16992. newShape.__animating = true;
  16993. zr.animate(newShape.id, 'style').when(duration, { angle: angle }).done(function () {
  16994. newShape.__animating = false;
  16995. }).start(easing);
  16996. }
  16997. function icon(zr, oldShape, newShape, duration, easing, delay) {
  16998. newShape.style._x = newShape.style.x;
  16999. newShape.style._y = newShape.style.y;
  17000. newShape.style._width = newShape.style.width;
  17001. newShape.style._height = newShape.style.height;
  17002. if (!oldShape) {
  17003. var x = newShape._x || 0;
  17004. var y = newShape._y || 0;
  17005. newShape.scale = [
  17006. 0.01,
  17007. 0.01,
  17008. x,
  17009. y
  17010. ];
  17011. zr.addShape(newShape);
  17012. newShape.__animating = true;
  17013. zr.animate(newShape.id, '').delay(delay).when(duration, {
  17014. scale: [
  17015. 1,
  17016. 1,
  17017. x,
  17018. y
  17019. ]
  17020. }).done(function () {
  17021. newShape.__animating = false;
  17022. }).start(easing || 'QuinticOut');
  17023. } else {
  17024. rectangle(zr, oldShape, newShape, duration, easing);
  17025. }
  17026. }
  17027. function line(zr, oldShape, newShape, duration, easing) {
  17028. if (!oldShape) {
  17029. oldShape = {
  17030. style: {
  17031. xStart: newShape.style.xStart,
  17032. yStart: newShape.style.yStart,
  17033. xEnd: newShape.style.xStart,
  17034. yEnd: newShape.style.yStart
  17035. }
  17036. };
  17037. }
  17038. var xStart = newShape.style.xStart;
  17039. var xEnd = newShape.style.xEnd;
  17040. var yStart = newShape.style.yStart;
  17041. var yEnd = newShape.style.yEnd;
  17042. cloneStyle(newShape, oldShape, 'xStart', 'xEnd', 'yStart', 'yEnd');
  17043. zr.addShape(newShape);
  17044. newShape.__animating = true;
  17045. zr.animate(newShape.id, 'style').when(duration, {
  17046. xStart: xStart,
  17047. xEnd: xEnd,
  17048. yStart: yStart,
  17049. yEnd: yEnd
  17050. }).done(function () {
  17051. newShape.__animating = false;
  17052. }).start(easing);
  17053. }
  17054. function markline(zr, oldShape, newShape, duration, easing) {
  17055. easing = easing || 'QuinticOut';
  17056. newShape.__animating = true;
  17057. zr.addShape(newShape);
  17058. var newShapeStyle = newShape.style;
  17059. var animationDone = function () {
  17060. newShape.__animating = false;
  17061. };
  17062. var x0 = newShapeStyle.xStart;
  17063. var y0 = newShapeStyle.yStart;
  17064. var x2 = newShapeStyle.xEnd;
  17065. var y2 = newShapeStyle.yEnd;
  17066. if (newShapeStyle.curveness > 0) {
  17067. newShape.updatePoints(newShapeStyle);
  17068. var obj = { p: 0 };
  17069. var x1 = newShapeStyle.cpX1;
  17070. var y1 = newShapeStyle.cpY1;
  17071. var newXArr = [];
  17072. var newYArr = [];
  17073. var subdivide = curveTool.quadraticSubdivide;
  17074. zr.animation.animate(obj).when(duration, { p: 1 }).during(function () {
  17075. subdivide(x0, x1, x2, obj.p, newXArr);
  17076. subdivide(y0, y1, y2, obj.p, newYArr);
  17077. newShapeStyle.cpX1 = newXArr[1];
  17078. newShapeStyle.cpY1 = newYArr[1];
  17079. newShapeStyle.xEnd = newXArr[2];
  17080. newShapeStyle.yEnd = newYArr[2];
  17081. zr.modShape(newShape);
  17082. }).done(animationDone).start(easing);
  17083. } else {
  17084. zr.animate(newShape.id, 'style').when(0, {
  17085. xEnd: x0,
  17086. yEnd: y0
  17087. }).when(duration, {
  17088. xEnd: x2,
  17089. yEnd: y2
  17090. }).done(animationDone).start(easing);
  17091. }
  17092. }
  17093. return {
  17094. pointList: pointList,
  17095. rectangle: rectangle,
  17096. candle: candle,
  17097. ring: ring,
  17098. sector: sector,
  17099. text: text,
  17100. polygon: polygon,
  17101. ribbon: ribbon,
  17102. gaugePointer: gaugePointer,
  17103. icon: icon,
  17104. line: line,
  17105. markline: markline
  17106. };
  17107. });define('echarts/util/ecEffect', [
  17108. 'require',
  17109. '../util/ecData',
  17110. 'zrender/shape/Circle',
  17111. 'zrender/shape/Image',
  17112. 'zrender/tool/curve',
  17113. '../util/shape/Icon',
  17114. '../util/shape/Symbol',
  17115. 'zrender/shape/ShapeBundle',
  17116. 'zrender/shape/Polyline',
  17117. 'zrender/tool/vector',
  17118. 'zrender/tool/env'
  17119. ], function (require) {
  17120. var ecData = require('../util/ecData');
  17121. var CircleShape = require('zrender/shape/Circle');
  17122. var ImageShape = require('zrender/shape/Image');
  17123. var curveTool = require('zrender/tool/curve');
  17124. var IconShape = require('../util/shape/Icon');
  17125. var SymbolShape = require('../util/shape/Symbol');
  17126. var ShapeBundle = require('zrender/shape/ShapeBundle');
  17127. var Polyline = require('zrender/shape/Polyline');
  17128. var vec2 = require('zrender/tool/vector');
  17129. var canvasSupported = require('zrender/tool/env').canvasSupported;
  17130. function point(zr, effectList, shape, zlevel) {
  17131. var effect = shape.effect;
  17132. var color = effect.color || shape.style.strokeColor || shape.style.color;
  17133. var shadowColor = effect.shadowColor || color;
  17134. var size = effect.scaleSize;
  17135. var distance = effect.bounceDistance;
  17136. var shadowBlur = typeof effect.shadowBlur != 'undefined' ? effect.shadowBlur : size;
  17137. var effectShape;
  17138. if (shape.type !== 'image') {
  17139. effectShape = new IconShape({
  17140. zlevel: zlevel,
  17141. style: {
  17142. brushType: 'stroke',
  17143. iconType: shape.style.iconType != 'droplet' ? shape.style.iconType : 'circle',
  17144. x: shadowBlur + 1,
  17145. y: shadowBlur + 1,
  17146. n: shape.style.n,
  17147. width: shape.style._width * size,
  17148. height: shape.style._height * size,
  17149. lineWidth: 1,
  17150. strokeColor: color,
  17151. shadowColor: shadowColor,
  17152. shadowBlur: shadowBlur
  17153. },
  17154. draggable: false,
  17155. hoverable: false
  17156. });
  17157. if (shape.style.iconType == 'pin') {
  17158. effectShape.style.y += effectShape.style.height / 2 * 1.5;
  17159. }
  17160. if (canvasSupported) {
  17161. effectShape.style.image = zr.shapeToImage(effectShape, effectShape.style.width + shadowBlur * 2 + 2, effectShape.style.height + shadowBlur * 2 + 2).style.image;
  17162. effectShape = new ImageShape({
  17163. zlevel: effectShape.zlevel,
  17164. style: effectShape.style,
  17165. draggable: false,
  17166. hoverable: false
  17167. });
  17168. }
  17169. } else {
  17170. effectShape = new ImageShape({
  17171. zlevel: zlevel,
  17172. style: shape.style,
  17173. draggable: false,
  17174. hoverable: false
  17175. });
  17176. }
  17177. ecData.clone(shape, effectShape);
  17178. effectShape.position = shape.position;
  17179. effectList.push(effectShape);
  17180. zr.addShape(effectShape);
  17181. var devicePixelRatio = shape.type !== 'image' ? window.devicePixelRatio || 1 : 1;
  17182. var offset = (effectShape.style.width / devicePixelRatio - shape.style._width) / 2;
  17183. effectShape.style.x = shape.style._x - offset;
  17184. effectShape.style.y = shape.style._y - offset;
  17185. if (shape.style.iconType == 'pin') {
  17186. effectShape.style.y -= shape.style.height / 2 * 1.5;
  17187. }
  17188. var duration = (effect.period + Math.random() * 10) * 100;
  17189. zr.modShape(shape.id, { invisible: true });
  17190. var centerX = effectShape.style.x + effectShape.style.width / 2 / devicePixelRatio;
  17191. var centerY = effectShape.style.y + effectShape.style.height / 2 / devicePixelRatio;
  17192. if (effect.type === 'scale') {
  17193. zr.modShape(effectShape.id, {
  17194. scale: [
  17195. 0.1,
  17196. 0.1,
  17197. centerX,
  17198. centerY
  17199. ]
  17200. });
  17201. zr.animate(effectShape.id, '', effect.loop).when(duration, {
  17202. scale: [
  17203. 1,
  17204. 1,
  17205. centerX,
  17206. centerY
  17207. ]
  17208. }).done(function () {
  17209. shape.effect.show = false;
  17210. zr.delShape(effectShape.id);
  17211. }).start();
  17212. } else {
  17213. zr.animate(effectShape.id, 'style', effect.loop).when(duration, { y: effectShape.style.y - distance }).when(duration * 2, { y: effectShape.style.y }).done(function () {
  17214. shape.effect.show = false;
  17215. zr.delShape(effectShape.id);
  17216. }).start();
  17217. }
  17218. }
  17219. function largePoint(zr, effectList, shape, zlevel) {
  17220. var effect = shape.effect;
  17221. var color = effect.color || shape.style.strokeColor || shape.style.color;
  17222. var size = effect.scaleSize;
  17223. var shadowColor = effect.shadowColor || color;
  17224. var shadowBlur = typeof effect.shadowBlur != 'undefined' ? effect.shadowBlur : size * 2;
  17225. var devicePixelRatio = window.devicePixelRatio || 1;
  17226. var effectShape = new SymbolShape({
  17227. zlevel: zlevel,
  17228. position: shape.position,
  17229. scale: shape.scale,
  17230. style: {
  17231. pointList: shape.style.pointList,
  17232. iconType: shape.style.iconType,
  17233. color: color,
  17234. strokeColor: color,
  17235. shadowColor: shadowColor,
  17236. shadowBlur: shadowBlur * devicePixelRatio,
  17237. random: true,
  17238. brushType: 'fill',
  17239. lineWidth: 1,
  17240. size: shape.style.size
  17241. },
  17242. draggable: false,
  17243. hoverable: false
  17244. });
  17245. effectList.push(effectShape);
  17246. zr.addShape(effectShape);
  17247. zr.modShape(shape.id, { invisible: true });
  17248. var duration = Math.round(effect.period * 100);
  17249. var clip1 = {};
  17250. var clip2 = {};
  17251. for (var i = 0; i < 20; i++) {
  17252. effectShape.style['randomMap' + i] = 0;
  17253. clip1 = {};
  17254. clip1['randomMap' + i] = 100;
  17255. clip2 = {};
  17256. clip2['randomMap' + i] = 0;
  17257. effectShape.style['randomMap' + i] = Math.random() * 100;
  17258. zr.animate(effectShape.id, 'style', true).when(duration, clip1).when(duration * 2, clip2).when(duration * 3, clip1).when(duration * 4, clip1).delay(Math.random() * duration * i).start();
  17259. }
  17260. }
  17261. function line(zr, effectList, shape, zlevel, isLarge) {
  17262. var effect = shape.effect;
  17263. var shapeStyle = shape.style;
  17264. var color = effect.color || shapeStyle.strokeColor || shapeStyle.color;
  17265. var shadowColor = effect.shadowColor || shapeStyle.strokeColor || color;
  17266. var size = shapeStyle.lineWidth * effect.scaleSize;
  17267. var shadowBlur = typeof effect.shadowBlur != 'undefined' ? effect.shadowBlur : size;
  17268. var effectShape = new CircleShape({
  17269. zlevel: zlevel,
  17270. style: {
  17271. x: shadowBlur,
  17272. y: shadowBlur,
  17273. r: size,
  17274. color: color,
  17275. shadowColor: shadowColor,
  17276. shadowBlur: shadowBlur
  17277. },
  17278. hoverable: false
  17279. });
  17280. var offset = 0;
  17281. if (canvasSupported && !isLarge) {
  17282. var zlevel = effectShape.zlevel;
  17283. effectShape = zr.shapeToImage(effectShape, (size + shadowBlur) * 2, (size + shadowBlur) * 2);
  17284. effectShape.zlevel = zlevel;
  17285. effectShape.hoverable = false;
  17286. offset = shadowBlur;
  17287. }
  17288. if (!isLarge) {
  17289. ecData.clone(shape, effectShape);
  17290. effectShape.position = shape.position;
  17291. effectList.push(effectShape);
  17292. zr.addShape(effectShape);
  17293. }
  17294. var effectDone = function () {
  17295. if (!isLarge) {
  17296. shape.effect.show = false;
  17297. zr.delShape(effectShape.id);
  17298. }
  17299. effectShape.effectAnimator = null;
  17300. };
  17301. if (shape instanceof Polyline) {
  17302. var distanceList = [0];
  17303. var totalDist = 0;
  17304. var pointList = shapeStyle.pointList;
  17305. var controlPointList = shapeStyle.controlPointList;
  17306. for (var i = 1; i < pointList.length; i++) {
  17307. if (controlPointList) {
  17308. var cp1 = controlPointList[(i - 1) * 2];
  17309. var cp2 = controlPointList[(i - 1) * 2 + 1];
  17310. totalDist += vec2.dist(pointList[i - 1], cp1) + vec2.dist(cp1, cp2) + vec2.dist(cp2, pointList[i]);
  17311. } else {
  17312. totalDist += vec2.dist(pointList[i - 1], pointList[i]);
  17313. }
  17314. distanceList.push(totalDist);
  17315. }
  17316. var obj = { p: 0 };
  17317. var animator = zr.animation.animate(obj, { loop: effect.loop });
  17318. for (var i = 0; i < distanceList.length; i++) {
  17319. animator.when(distanceList[i] * effect.period, { p: i });
  17320. }
  17321. animator.during(function () {
  17322. var i = Math.floor(obj.p);
  17323. var x, y;
  17324. if (i == pointList.length - 1) {
  17325. x = pointList[i][0];
  17326. y = pointList[i][1];
  17327. } else {
  17328. var t = obj.p - i;
  17329. var p0 = pointList[i];
  17330. var p1 = pointList[i + 1];
  17331. if (controlPointList) {
  17332. var cp1 = controlPointList[i * 2];
  17333. var cp2 = controlPointList[i * 2 + 1];
  17334. x = curveTool.cubicAt(p0[0], cp1[0], cp2[0], p1[0], t);
  17335. y = curveTool.cubicAt(p0[1], cp1[1], cp2[1], p1[1], t);
  17336. } else {
  17337. x = (p1[0] - p0[0]) * t + p0[0];
  17338. y = (p1[1] - p0[1]) * t + p0[1];
  17339. }
  17340. }
  17341. effectShape.style.x = x;
  17342. effectShape.style.y = y;
  17343. if (!isLarge) {
  17344. zr.modShape(effectShape);
  17345. }
  17346. }).done(effectDone).start();
  17347. animator.duration = totalDist * effect.period;
  17348. effectShape.effectAnimator = animator;
  17349. } else {
  17350. var x0 = shapeStyle.xStart - offset;
  17351. var y0 = shapeStyle.yStart - offset;
  17352. var x2 = shapeStyle.xEnd - offset;
  17353. var y2 = shapeStyle.yEnd - offset;
  17354. effectShape.style.x = x0;
  17355. effectShape.style.y = y0;
  17356. var distance = (x2 - x0) * (x2 - x0) + (y2 - y0) * (y2 - y0);
  17357. var duration = Math.round(Math.sqrt(Math.round(distance * effect.period * effect.period)));
  17358. if (shape.style.curveness > 0) {
  17359. var x1 = shapeStyle.cpX1 - offset;
  17360. var y1 = shapeStyle.cpY1 - offset;
  17361. effectShape.effectAnimator = zr.animation.animate(effectShape, { loop: effect.loop }).when(duration, { p: 1 }).during(function (target, t) {
  17362. effectShape.style.x = curveTool.quadraticAt(x0, x1, x2, t);
  17363. effectShape.style.y = curveTool.quadraticAt(y0, y1, y2, t);
  17364. if (!isLarge) {
  17365. zr.modShape(effectShape);
  17366. }
  17367. }).done(effectDone).start();
  17368. } else {
  17369. effectShape.effectAnimator = zr.animation.animate(effectShape.style, { loop: effect.loop }).when(duration, {
  17370. x: x2,
  17371. y: y2
  17372. }).during(function () {
  17373. if (!isLarge) {
  17374. zr.modShape(effectShape);
  17375. }
  17376. }).done(effectDone).start();
  17377. }
  17378. effectShape.effectAnimator.duration = duration;
  17379. }
  17380. return effectShape;
  17381. }
  17382. function largeLine(zr, effectList, shape, zlevel) {
  17383. var effectShape = new ShapeBundle({
  17384. style: { shapeList: [] },
  17385. zlevel: zlevel,
  17386. hoverable: false
  17387. });
  17388. var shapeList = shape.style.shapeList;
  17389. var effect = shape.effect;
  17390. effectShape.position = shape.position;
  17391. var maxDuration = 0;
  17392. var subEffectAnimators = [];
  17393. for (var i = 0; i < shapeList.length; i++) {
  17394. shapeList[i].effect = effect;
  17395. var subEffectShape = line(zr, null, shapeList[i], zlevel, true);
  17396. var subEffectAnimator = subEffectShape.effectAnimator;
  17397. effectShape.style.shapeList.push(subEffectShape);
  17398. if (subEffectAnimator.duration > maxDuration) {
  17399. maxDuration = subEffectAnimator.duration;
  17400. }
  17401. if (i === 0) {
  17402. effectShape.style.color = subEffectShape.style.color;
  17403. effectShape.style.shadowBlur = subEffectShape.style.shadowBlur;
  17404. effectShape.style.shadowColor = subEffectShape.style.shadowColor;
  17405. }
  17406. subEffectAnimators.push(subEffectAnimator);
  17407. }
  17408. effectList.push(effectShape);
  17409. zr.addShape(effectShape);
  17410. var clearAllAnimators = function () {
  17411. for (var i = 0; i < subEffectAnimators.length; i++) {
  17412. subEffectAnimators[i].stop();
  17413. }
  17414. };
  17415. if (maxDuration) {
  17416. effectShape.__dummy = 0;
  17417. var animator = zr.animate(effectShape.id, '', effect.loop).when(maxDuration, { __dummy: 1 }).during(function () {
  17418. zr.modShape(effectShape);
  17419. }).done(function () {
  17420. shape.effect.show = false;
  17421. zr.delShape(effectShape.id);
  17422. }).start();
  17423. var oldStop = animator.stop;
  17424. animator.stop = function () {
  17425. clearAllAnimators();
  17426. oldStop.call(this);
  17427. };
  17428. }
  17429. }
  17430. return {
  17431. point: point,
  17432. largePoint: largePoint,
  17433. line: line,
  17434. largeLine: largeLine
  17435. };
  17436. });define('echarts/component/base', [
  17437. 'require',
  17438. '../config',
  17439. '../util/ecData',
  17440. '../util/ecQuery',
  17441. '../util/number',
  17442. 'zrender/tool/util',
  17443. 'zrender/tool/env'
  17444. ], function (require) {
  17445. var ecConfig = require('../config');
  17446. var ecData = require('../util/ecData');
  17447. var ecQuery = require('../util/ecQuery');
  17448. var number = require('../util/number');
  17449. var zrUtil = require('zrender/tool/util');
  17450. function Base(ecTheme, messageCenter, zr, option, myChart) {
  17451. this.ecTheme = ecTheme;
  17452. this.messageCenter = messageCenter;
  17453. this.zr = zr;
  17454. this.option = option;
  17455. this.series = option.series;
  17456. this.myChart = myChart;
  17457. this.component = myChart.component;
  17458. this.shapeList = [];
  17459. this.effectList = [];
  17460. var self = this;
  17461. self._onlegendhoverlink = function (param) {
  17462. if (self.legendHoverLink) {
  17463. var targetName = param.target;
  17464. var name;
  17465. for (var i = self.shapeList.length - 1; i >= 0; i--) {
  17466. name = self.type == ecConfig.CHART_TYPE_PIE || self.type == ecConfig.CHART_TYPE_FUNNEL ? ecData.get(self.shapeList[i], 'name') : (ecData.get(self.shapeList[i], 'series') || {}).name;
  17467. if (name == targetName && !self.shapeList[i].invisible && !self.shapeList[i].__animating) {
  17468. self.zr.addHoverShape(self.shapeList[i]);
  17469. }
  17470. }
  17471. }
  17472. };
  17473. messageCenter && messageCenter.bind(ecConfig.EVENT.LEGEND_HOVERLINK, this._onlegendhoverlink);
  17474. }
  17475. Base.prototype = {
  17476. canvasSupported: require('zrender/tool/env').canvasSupported,
  17477. _getZ: function (zWhat) {
  17478. if (this[zWhat] != null) {
  17479. return this[zWhat];
  17480. }
  17481. var opt = this.ecTheme[this.type];
  17482. if (opt && opt[zWhat] != null) {
  17483. return opt[zWhat];
  17484. }
  17485. opt = ecConfig[this.type];
  17486. if (opt && opt[zWhat] != null) {
  17487. return opt[zWhat];
  17488. }
  17489. return 0;
  17490. },
  17491. getZlevelBase: function () {
  17492. return this._getZ('zlevel');
  17493. },
  17494. getZBase: function () {
  17495. return this._getZ('z');
  17496. },
  17497. reformOption: function (opt) {
  17498. opt = zrUtil.merge(zrUtil.merge(opt || {}, zrUtil.clone(this.ecTheme[this.type] || {})), zrUtil.clone(ecConfig[this.type] || {}));
  17499. this.z = opt.z;
  17500. this.zlevel = opt.zlevel;
  17501. return opt;
  17502. },
  17503. reformCssArray: function (p) {
  17504. if (p instanceof Array) {
  17505. switch (p.length + '') {
  17506. case '4':
  17507. return p;
  17508. case '3':
  17509. return [
  17510. p[0],
  17511. p[1],
  17512. p[2],
  17513. p[1]
  17514. ];
  17515. case '2':
  17516. return [
  17517. p[0],
  17518. p[1],
  17519. p[0],
  17520. p[1]
  17521. ];
  17522. case '1':
  17523. return [
  17524. p[0],
  17525. p[0],
  17526. p[0],
  17527. p[0]
  17528. ];
  17529. case '0':
  17530. return [
  17531. 0,
  17532. 0,
  17533. 0,
  17534. 0
  17535. ];
  17536. }
  17537. } else {
  17538. return [
  17539. p,
  17540. p,
  17541. p,
  17542. p
  17543. ];
  17544. }
  17545. },
  17546. getShapeById: function (id) {
  17547. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  17548. if (this.shapeList[i].id === id) {
  17549. return this.shapeList[i];
  17550. }
  17551. }
  17552. return null;
  17553. },
  17554. getFont: function (textStyle) {
  17555. var finalTextStyle = this.getTextStyle(zrUtil.clone(textStyle));
  17556. return finalTextStyle.fontStyle + ' ' + finalTextStyle.fontWeight + ' ' + finalTextStyle.fontSize + 'px ' + finalTextStyle.fontFamily;
  17557. },
  17558. getTextStyle: function (targetStyle) {
  17559. return zrUtil.merge(zrUtil.merge(targetStyle || {}, this.ecTheme.textStyle), ecConfig.textStyle);
  17560. },
  17561. getItemStyleColor: function (itemColor, seriesIndex, dataIndex, data) {
  17562. return typeof itemColor === 'function' ? itemColor.call(this.myChart, {
  17563. seriesIndex: seriesIndex,
  17564. series: this.series[seriesIndex],
  17565. dataIndex: dataIndex,
  17566. data: data
  17567. }) : itemColor;
  17568. },
  17569. getDataFromOption: function (data, defaultData) {
  17570. return data != null ? data.value != null ? data.value : data : defaultData;
  17571. },
  17572. subPixelOptimize: function (position, lineWidth) {
  17573. if (lineWidth % 2 === 1) {
  17574. position = Math.floor(position) + 0.5;
  17575. } else {
  17576. position = Math.round(position);
  17577. }
  17578. return position;
  17579. },
  17580. resize: function () {
  17581. this.refresh && this.refresh();
  17582. this.clearEffectShape && this.clearEffectShape(true);
  17583. var self = this;
  17584. setTimeout(function () {
  17585. self.animationEffect && self.animationEffect();
  17586. }, 200);
  17587. },
  17588. clear: function () {
  17589. this.clearEffectShape && this.clearEffectShape();
  17590. this.zr && this.zr.delShape(this.shapeList);
  17591. this.shapeList = [];
  17592. },
  17593. dispose: function () {
  17594. this.onbeforDispose && this.onbeforDispose();
  17595. this.clear();
  17596. this.shapeList = null;
  17597. this.effectList = null;
  17598. this.messageCenter && this.messageCenter.unbind(ecConfig.EVENT.LEGEND_HOVERLINK, this._onlegendhoverlink);
  17599. this.onafterDispose && this.onafterDispose();
  17600. },
  17601. query: ecQuery.query,
  17602. deepQuery: ecQuery.deepQuery,
  17603. deepMerge: ecQuery.deepMerge,
  17604. parsePercent: number.parsePercent,
  17605. parseCenter: number.parseCenter,
  17606. parseRadius: number.parseRadius,
  17607. numAddCommas: number.addCommas,
  17608. getPrecision: number.getPrecision
  17609. };
  17610. return Base;
  17611. });define('echarts/layout/EdgeBundling', [
  17612. 'require',
  17613. '../data/KDTree',
  17614. 'zrender/tool/vector'
  17615. ], function (require) {
  17616. var KDTree = require('../data/KDTree');
  17617. var vec2 = require('zrender/tool/vector');
  17618. var v2Create = vec2.create;
  17619. var v2DistSquare = vec2.distSquare;
  17620. var v2Dist = vec2.dist;
  17621. var v2Copy = vec2.copy;
  17622. var v2Clone = vec2.clone;
  17623. function squaredDistance(a, b) {
  17624. a = a.array;
  17625. b = b.array;
  17626. var x = b[0] - a[0];
  17627. var y = b[1] - a[1];
  17628. var z = b[2] - a[2];
  17629. var w = b[3] - a[3];
  17630. return x * x + y * y + z * z + w * w;
  17631. }
  17632. function CoarsenedEdge(group) {
  17633. this.points = [
  17634. group.mp0,
  17635. group.mp1
  17636. ];
  17637. this.group = group;
  17638. }
  17639. function Edge(edge) {
  17640. var points = edge.points;
  17641. if (points[0][1] < points[1][1] || edge instanceof CoarsenedEdge) {
  17642. this.array = [
  17643. points[0][0],
  17644. points[0][1],
  17645. points[1][0],
  17646. points[1][1]
  17647. ];
  17648. this._startPoint = points[0];
  17649. this._endPoint = points[1];
  17650. } else {
  17651. this.array = [
  17652. points[1][0],
  17653. points[1][1],
  17654. points[0][0],
  17655. points[0][1]
  17656. ];
  17657. this._startPoint = points[1];
  17658. this._endPoint = points[0];
  17659. }
  17660. this.ink = v2Dist(points[0], points[1]);
  17661. this.edge = edge;
  17662. this.group = null;
  17663. }
  17664. Edge.prototype.getStartPoint = function () {
  17665. return this._startPoint;
  17666. };
  17667. Edge.prototype.getEndPoint = function () {
  17668. return this._endPoint;
  17669. };
  17670. function BundledEdgeGroup() {
  17671. this.edgeList = [];
  17672. this.mp0 = v2Create();
  17673. this.mp1 = v2Create();
  17674. this.ink = 0;
  17675. }
  17676. BundledEdgeGroup.prototype.addEdge = function (edge) {
  17677. edge.group = this;
  17678. this.edgeList.push(edge);
  17679. };
  17680. BundledEdgeGroup.prototype.removeEdge = function (edge) {
  17681. edge.group = null;
  17682. this.edgeList.splice(this.edgeList.indexOf(edge), 1);
  17683. };
  17684. function EdgeBundling() {
  17685. this.maxNearestEdge = 6;
  17686. this.maxTurningAngle = Math.PI / 4;
  17687. this.maxIteration = 20;
  17688. }
  17689. EdgeBundling.prototype = {
  17690. constructor: EdgeBundling,
  17691. run: function (rawEdges) {
  17692. var res = this._iterate(rawEdges);
  17693. var nIterate = 0;
  17694. while (nIterate++ < this.maxIteration) {
  17695. var coarsenedEdges = [];
  17696. for (var i = 0; i < res.groups.length; i++) {
  17697. coarsenedEdges.push(new CoarsenedEdge(res.groups[i]));
  17698. }
  17699. var newRes = this._iterate(coarsenedEdges);
  17700. if (newRes.savedInk <= 0) {
  17701. break;
  17702. } else {
  17703. res = newRes;
  17704. }
  17705. }
  17706. var newEdges = [];
  17707. function pointApproxEqual(p0, p1) {
  17708. return v2DistSquare(p0, p1) < 1e-10;
  17709. }
  17710. function cleanEdgePoints(edgePoints, rawEdgePoints) {
  17711. var res = [];
  17712. var off = 0;
  17713. for (var i = 0; i < edgePoints.length; i++) {
  17714. if (!(off > 0 && pointApproxEqual(edgePoints[i], res[off - 1]))) {
  17715. res[off++] = v2Clone(edgePoints[i]);
  17716. }
  17717. }
  17718. if (rawEdgePoints[0] && !pointApproxEqual(res[0], rawEdgePoints[0])) {
  17719. res = res.reverse();
  17720. }
  17721. return res;
  17722. }
  17723. var buildNewEdges = function (groups, fromEdgePoints) {
  17724. var newEdgePoints;
  17725. for (var i = 0; i < groups.length; i++) {
  17726. var group = groups[i];
  17727. if (group.edgeList[0] && group.edgeList[0].edge instanceof CoarsenedEdge) {
  17728. var newGroups = [];
  17729. for (var j = 0; j < group.edgeList.length; j++) {
  17730. newGroups.push(group.edgeList[j].edge.group);
  17731. }
  17732. if (!fromEdgePoints) {
  17733. newEdgePoints = [];
  17734. } else {
  17735. newEdgePoints = fromEdgePoints.slice();
  17736. }
  17737. newEdgePoints.unshift(group.mp0);
  17738. newEdgePoints.push(group.mp1);
  17739. buildNewEdges(newGroups, newEdgePoints);
  17740. } else {
  17741. for (var j = 0; j < group.edgeList.length; j++) {
  17742. var edge = group.edgeList[j];
  17743. if (!fromEdgePoints) {
  17744. newEdgePoints = [];
  17745. } else {
  17746. newEdgePoints = fromEdgePoints.slice();
  17747. }
  17748. newEdgePoints.unshift(group.mp0);
  17749. newEdgePoints.push(group.mp1);
  17750. newEdgePoints.unshift(edge.getStartPoint());
  17751. newEdgePoints.push(edge.getEndPoint());
  17752. newEdges.push({
  17753. points: cleanEdgePoints(newEdgePoints, edge.edge.points),
  17754. rawEdge: edge.edge
  17755. });
  17756. }
  17757. }
  17758. }
  17759. };
  17760. buildNewEdges(res.groups);
  17761. return newEdges;
  17762. },
  17763. _iterate: function (rawEdges) {
  17764. var edges = [];
  17765. var groups = [];
  17766. var totalSavedInk = 0;
  17767. for (var i = 0; i < rawEdges.length; i++) {
  17768. var edge = new Edge(rawEdges[i]);
  17769. edges.push(edge);
  17770. }
  17771. var tree = new KDTree(edges, 4);
  17772. var nearests = [];
  17773. var _mp0 = v2Create();
  17774. var _mp1 = v2Create();
  17775. var _newGroupInk = 0;
  17776. var mp0 = v2Create();
  17777. var mp1 = v2Create();
  17778. var newGroupInk = 0;
  17779. for (var i = 0; i < edges.length; i++) {
  17780. var edge = edges[i];
  17781. if (edge.group) {
  17782. continue;
  17783. }
  17784. tree.nearestN(edge, this.maxNearestEdge, squaredDistance, nearests);
  17785. var maxSavedInk = 0;
  17786. var mostSavingInkEdge = null;
  17787. var lastCheckedGroup = null;
  17788. for (var j = 0; j < nearests.length; j++) {
  17789. var nearest = nearests[j];
  17790. var savedInk = 0;
  17791. if (nearest.group) {
  17792. if (nearest.group !== lastCheckedGroup) {
  17793. lastCheckedGroup = nearest.group;
  17794. _newGroupInk = this._calculateGroupEdgeInk(nearest.group, edge, _mp0, _mp1);
  17795. savedInk = nearest.group.ink + edge.ink - _newGroupInk;
  17796. }
  17797. } else {
  17798. _newGroupInk = this._calculateEdgeEdgeInk(edge, nearest, _mp0, _mp1);
  17799. savedInk = nearest.ink + edge.ink - _newGroupInk;
  17800. }
  17801. if (savedInk > maxSavedInk) {
  17802. maxSavedInk = savedInk;
  17803. mostSavingInkEdge = nearest;
  17804. v2Copy(mp1, _mp1);
  17805. v2Copy(mp0, _mp0);
  17806. newGroupInk = _newGroupInk;
  17807. }
  17808. }
  17809. if (mostSavingInkEdge) {
  17810. totalSavedInk += maxSavedInk;
  17811. var group;
  17812. if (!mostSavingInkEdge.group) {
  17813. group = new BundledEdgeGroup();
  17814. groups.push(group);
  17815. group.addEdge(mostSavingInkEdge);
  17816. }
  17817. group = mostSavingInkEdge.group;
  17818. v2Copy(group.mp0, mp0);
  17819. v2Copy(group.mp1, mp1);
  17820. group.ink = newGroupInk;
  17821. mostSavingInkEdge.group.addEdge(edge);
  17822. } else {
  17823. var group = new BundledEdgeGroup();
  17824. groups.push(group);
  17825. v2Copy(group.mp0, edge.getStartPoint());
  17826. v2Copy(group.mp1, edge.getEndPoint());
  17827. group.ink = edge.ink;
  17828. group.addEdge(edge);
  17829. }
  17830. }
  17831. return {
  17832. groups: groups,
  17833. edges: edges,
  17834. savedInk: totalSavedInk
  17835. };
  17836. },
  17837. _calculateEdgeEdgeInk: function () {
  17838. var startPointSet = [];
  17839. var endPointSet = [];
  17840. return function (e0, e1, mp0, mp1) {
  17841. startPointSet[0] = e0.getStartPoint();
  17842. startPointSet[1] = e1.getStartPoint();
  17843. endPointSet[0] = e0.getEndPoint();
  17844. endPointSet[1] = e1.getEndPoint();
  17845. this._calculateMeetPoints(startPointSet, endPointSet, mp0, mp1);
  17846. var ink = v2Dist(startPointSet[0], mp0) + v2Dist(mp0, mp1) + v2Dist(mp1, endPointSet[0]) + v2Dist(startPointSet[1], mp0) + v2Dist(mp1, endPointSet[1]);
  17847. return ink;
  17848. };
  17849. }(),
  17850. _calculateGroupEdgeInk: function (group, edgeTryAdd, mp0, mp1) {
  17851. var startPointSet = [];
  17852. var endPointSet = [];
  17853. for (var i = 0; i < group.edgeList.length; i++) {
  17854. var edge = group.edgeList[i];
  17855. startPointSet.push(edge.getStartPoint());
  17856. endPointSet.push(edge.getEndPoint());
  17857. }
  17858. startPointSet.push(edgeTryAdd.getStartPoint());
  17859. endPointSet.push(edgeTryAdd.getEndPoint());
  17860. this._calculateMeetPoints(startPointSet, endPointSet, mp0, mp1);
  17861. var ink = v2Dist(mp0, mp1);
  17862. for (var i = 0; i < startPointSet.length; i++) {
  17863. ink += v2Dist(startPointSet[i], mp0) + v2Dist(endPointSet[i], mp1);
  17864. }
  17865. return ink;
  17866. },
  17867. _calculateMeetPoints: function () {
  17868. var cp0 = v2Create();
  17869. var cp1 = v2Create();
  17870. return function (startPointSet, endPointSet, mp0, mp1) {
  17871. vec2.set(cp0, 0, 0);
  17872. vec2.set(cp1, 0, 0);
  17873. var len = startPointSet.length;
  17874. for (var i = 0; i < len; i++) {
  17875. vec2.add(cp0, cp0, startPointSet[i]);
  17876. }
  17877. vec2.scale(cp0, cp0, 1 / len);
  17878. len = endPointSet.length;
  17879. for (var i = 0; i < len; i++) {
  17880. vec2.add(cp1, cp1, endPointSet[i]);
  17881. }
  17882. vec2.scale(cp1, cp1, 1 / len);
  17883. this._limitTurningAngle(startPointSet, cp0, cp1, mp0);
  17884. this._limitTurningAngle(endPointSet, cp1, cp0, mp1);
  17885. };
  17886. }(),
  17887. _limitTurningAngle: function () {
  17888. var v10 = v2Create();
  17889. var vTmp = v2Create();
  17890. var project = v2Create();
  17891. var tmpOut = v2Create();
  17892. return function (pointSet, p0, p1, out) {
  17893. var maxTurningAngleCos = Math.cos(this.maxTurningAngle);
  17894. var maxTurningAngleTan = Math.tan(this.maxTurningAngle);
  17895. vec2.sub(v10, p0, p1);
  17896. vec2.normalize(v10, v10);
  17897. vec2.copy(out, p0);
  17898. var maxMovement = 0;
  17899. for (var i = 0; i < pointSet.length; i++) {
  17900. var p = pointSet[i];
  17901. vec2.sub(vTmp, p, p0);
  17902. var len = vec2.len(vTmp);
  17903. vec2.scale(vTmp, vTmp, 1 / len);
  17904. var turningAngleCos = vec2.dot(vTmp, v10);
  17905. if (turningAngleCos < maxTurningAngleCos) {
  17906. vec2.scaleAndAdd(project, p0, v10, len * turningAngleCos);
  17907. var distance = v2Dist(project, p);
  17908. var d = distance / maxTurningAngleTan;
  17909. vec2.scaleAndAdd(tmpOut, project, v10, -d);
  17910. var movement = v2DistSquare(tmpOut, p0);
  17911. if (movement > maxMovement) {
  17912. maxMovement = movement;
  17913. vec2.copy(out, tmpOut);
  17914. }
  17915. }
  17916. }
  17917. };
  17918. }()
  17919. };
  17920. return EdgeBundling;
  17921. });define('zrender/shape/Star', [
  17922. 'require',
  17923. '../tool/math',
  17924. './Base',
  17925. '../tool/util'
  17926. ], function (require) {
  17927. var math = require('../tool/math');
  17928. var sin = math.sin;
  17929. var cos = math.cos;
  17930. var PI = Math.PI;
  17931. var Base = require('./Base');
  17932. var Star = function (options) {
  17933. Base.call(this, options);
  17934. };
  17935. Star.prototype = {
  17936. type: 'star',
  17937. buildPath: function (ctx, style) {
  17938. var n = style.n;
  17939. if (!n || n < 2) {
  17940. return;
  17941. }
  17942. var x = style.x;
  17943. var y = style.y;
  17944. var r = style.r;
  17945. var r0 = style.r0;
  17946. if (r0 == null) {
  17947. r0 = n > 4 ? r * cos(2 * PI / n) / cos(PI / n) : r / 3;
  17948. }
  17949. var dStep = PI / n;
  17950. var deg = -PI / 2;
  17951. var xStart = x + r * cos(deg);
  17952. var yStart = y + r * sin(deg);
  17953. deg += dStep;
  17954. var pointList = style.pointList = [];
  17955. pointList.push([
  17956. xStart,
  17957. yStart
  17958. ]);
  17959. for (var i = 0, end = n * 2 - 1, ri; i < end; i++) {
  17960. ri = i % 2 === 0 ? r0 : r;
  17961. pointList.push([
  17962. x + ri * cos(deg),
  17963. y + ri * sin(deg)
  17964. ]);
  17965. deg += dStep;
  17966. }
  17967. pointList.push([
  17968. xStart,
  17969. yStart
  17970. ]);
  17971. ctx.moveTo(pointList[0][0], pointList[0][1]);
  17972. for (var i = 0; i < pointList.length; i++) {
  17973. ctx.lineTo(pointList[i][0], pointList[i][1]);
  17974. }
  17975. ctx.closePath();
  17976. return;
  17977. },
  17978. getRect: function (style) {
  17979. if (style.__rect) {
  17980. return style.__rect;
  17981. }
  17982. var lineWidth;
  17983. if (style.brushType == 'stroke' || style.brushType == 'fill') {
  17984. lineWidth = style.lineWidth || 1;
  17985. } else {
  17986. lineWidth = 0;
  17987. }
  17988. style.__rect = {
  17989. x: Math.round(style.x - style.r - lineWidth / 2),
  17990. y: Math.round(style.y - style.r - lineWidth / 2),
  17991. width: style.r * 2 + lineWidth,
  17992. height: style.r * 2 + lineWidth
  17993. };
  17994. return style.__rect;
  17995. }
  17996. };
  17997. require('../tool/util').inherits(Star, Base);
  17998. return Star;
  17999. });define('zrender/shape/Heart', [
  18000. 'require',
  18001. './Base',
  18002. './util/PathProxy',
  18003. '../tool/area',
  18004. '../tool/util'
  18005. ], function (require) {
  18006. 'use strict';
  18007. var Base = require('./Base');
  18008. var PathProxy = require('./util/PathProxy');
  18009. var area = require('../tool/area');
  18010. var Heart = function (options) {
  18011. Base.call(this, options);
  18012. this._pathProxy = new PathProxy();
  18013. };
  18014. Heart.prototype = {
  18015. type: 'heart',
  18016. buildPath: function (ctx, style) {
  18017. var path = this._pathProxy || new PathProxy();
  18018. path.begin(ctx);
  18019. path.moveTo(style.x, style.y);
  18020. path.bezierCurveTo(style.x + style.a / 2, style.y - style.b * 2 / 3, style.x + style.a * 2, style.y + style.b / 3, style.x, style.y + style.b);
  18021. path.bezierCurveTo(style.x - style.a * 2, style.y + style.b / 3, style.x - style.a / 2, style.y - style.b * 2 / 3, style.x, style.y);
  18022. path.closePath();
  18023. return;
  18024. },
  18025. getRect: function (style) {
  18026. if (style.__rect) {
  18027. return style.__rect;
  18028. }
  18029. if (!this._pathProxy.isEmpty()) {
  18030. this.buildPath(null, style);
  18031. }
  18032. return this._pathProxy.fastBoundingRect();
  18033. },
  18034. isCover: function (x, y) {
  18035. var originPos = this.transformCoordToLocal(x, y);
  18036. x = originPos[0];
  18037. y = originPos[1];
  18038. if (this.isCoverRect(x, y)) {
  18039. return area.isInsidePath(this._pathProxy.pathCommands, this.style.lineWidth, this.style.brushType, x, y);
  18040. }
  18041. }
  18042. };
  18043. require('../tool/util').inherits(Heart, Base);
  18044. return Heart;
  18045. });define('zrender/shape/Droplet', [
  18046. 'require',
  18047. './Base',
  18048. './util/PathProxy',
  18049. '../tool/area',
  18050. '../tool/util'
  18051. ], function (require) {
  18052. 'use strict';
  18053. var Base = require('./Base');
  18054. var PathProxy = require('./util/PathProxy');
  18055. var area = require('../tool/area');
  18056. var Droplet = function (options) {
  18057. Base.call(this, options);
  18058. this._pathProxy = new PathProxy();
  18059. };
  18060. Droplet.prototype = {
  18061. type: 'droplet',
  18062. buildPath: function (ctx, style) {
  18063. var path = this._pathProxy || new PathProxy();
  18064. path.begin(ctx);
  18065. path.moveTo(style.x, style.y + style.a);
  18066. path.bezierCurveTo(style.x + style.a, style.y + style.a, style.x + style.a * 3 / 2, style.y - style.a / 3, style.x, style.y - style.b);
  18067. path.bezierCurveTo(style.x - style.a * 3 / 2, style.y - style.a / 3, style.x - style.a, style.y + style.a, style.x, style.y + style.a);
  18068. path.closePath();
  18069. },
  18070. getRect: function (style) {
  18071. if (style.__rect) {
  18072. return style.__rect;
  18073. }
  18074. if (!this._pathProxy.isEmpty()) {
  18075. this.buildPath(null, style);
  18076. }
  18077. return this._pathProxy.fastBoundingRect();
  18078. },
  18079. isCover: function (x, y) {
  18080. var originPos = this.transformCoordToLocal(x, y);
  18081. x = originPos[0];
  18082. y = originPos[1];
  18083. if (this.isCoverRect(x, y)) {
  18084. return area.isInsidePath(this._pathProxy.pathCommands, this.style.lineWidth, this.style.brushType, x, y);
  18085. }
  18086. }
  18087. };
  18088. require('../tool/util').inherits(Droplet, Base);
  18089. return Droplet;
  18090. });define('zrender/tool/math', [], function () {
  18091. var _radians = Math.PI / 180;
  18092. function sin(angle, isDegrees) {
  18093. return Math.sin(isDegrees ? angle * _radians : angle);
  18094. }
  18095. function cos(angle, isDegrees) {
  18096. return Math.cos(isDegrees ? angle * _radians : angle);
  18097. }
  18098. function degreeToRadian(angle) {
  18099. return angle * _radians;
  18100. }
  18101. function radianToDegree(angle) {
  18102. return angle / _radians;
  18103. }
  18104. return {
  18105. sin: sin,
  18106. cos: cos,
  18107. degreeToRadian: degreeToRadian,
  18108. radianToDegree: radianToDegree
  18109. };
  18110. });define('zrender/shape/util/PathProxy', [
  18111. 'require',
  18112. '../../tool/vector'
  18113. ], function (require) {
  18114. var vector = require('../../tool/vector');
  18115. var PathSegment = function (command, points) {
  18116. this.command = command;
  18117. this.points = points || null;
  18118. };
  18119. var PathProxy = function () {
  18120. this.pathCommands = [];
  18121. this._ctx = null;
  18122. this._min = [];
  18123. this._max = [];
  18124. };
  18125. PathProxy.prototype.fastBoundingRect = function () {
  18126. var min = this._min;
  18127. var max = this._max;
  18128. min[0] = min[1] = Infinity;
  18129. max[0] = max[1] = -Infinity;
  18130. for (var i = 0; i < this.pathCommands.length; i++) {
  18131. var seg = this.pathCommands[i];
  18132. var p = seg.points;
  18133. switch (seg.command) {
  18134. case 'M':
  18135. vector.min(min, min, p);
  18136. vector.max(max, max, p);
  18137. break;
  18138. case 'L':
  18139. vector.min(min, min, p);
  18140. vector.max(max, max, p);
  18141. break;
  18142. case 'C':
  18143. for (var j = 0; j < 6; j += 2) {
  18144. min[0] = Math.min(min[0], min[0], p[j]);
  18145. min[1] = Math.min(min[1], min[1], p[j + 1]);
  18146. max[0] = Math.max(max[0], max[0], p[j]);
  18147. max[1] = Math.max(max[1], max[1], p[j + 1]);
  18148. }
  18149. break;
  18150. case 'Q':
  18151. for (var j = 0; j < 4; j += 2) {
  18152. min[0] = Math.min(min[0], min[0], p[j]);
  18153. min[1] = Math.min(min[1], min[1], p[j + 1]);
  18154. max[0] = Math.max(max[0], max[0], p[j]);
  18155. max[1] = Math.max(max[1], max[1], p[j + 1]);
  18156. }
  18157. break;
  18158. case 'A':
  18159. var cx = p[0];
  18160. var cy = p[1];
  18161. var rx = p[2];
  18162. var ry = p[3];
  18163. min[0] = Math.min(min[0], min[0], cx - rx);
  18164. min[1] = Math.min(min[1], min[1], cy - ry);
  18165. max[0] = Math.max(max[0], max[0], cx + rx);
  18166. max[1] = Math.max(max[1], max[1], cy + ry);
  18167. break;
  18168. }
  18169. }
  18170. return {
  18171. x: min[0],
  18172. y: min[1],
  18173. width: max[0] - min[0],
  18174. height: max[1] - min[1]
  18175. };
  18176. };
  18177. PathProxy.prototype.begin = function (ctx) {
  18178. this._ctx = ctx || null;
  18179. this.pathCommands.length = 0;
  18180. return this;
  18181. };
  18182. PathProxy.prototype.moveTo = function (x, y) {
  18183. this.pathCommands.push(new PathSegment('M', [
  18184. x,
  18185. y
  18186. ]));
  18187. if (this._ctx) {
  18188. this._ctx.moveTo(x, y);
  18189. }
  18190. return this;
  18191. };
  18192. PathProxy.prototype.lineTo = function (x, y) {
  18193. this.pathCommands.push(new PathSegment('L', [
  18194. x,
  18195. y
  18196. ]));
  18197. if (this._ctx) {
  18198. this._ctx.lineTo(x, y);
  18199. }
  18200. return this;
  18201. };
  18202. PathProxy.prototype.bezierCurveTo = function (x1, y1, x2, y2, x3, y3) {
  18203. this.pathCommands.push(new PathSegment('C', [
  18204. x1,
  18205. y1,
  18206. x2,
  18207. y2,
  18208. x3,
  18209. y3
  18210. ]));
  18211. if (this._ctx) {
  18212. this._ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  18213. }
  18214. return this;
  18215. };
  18216. PathProxy.prototype.quadraticCurveTo = function (x1, y1, x2, y2) {
  18217. this.pathCommands.push(new PathSegment('Q', [
  18218. x1,
  18219. y1,
  18220. x2,
  18221. y2
  18222. ]));
  18223. if (this._ctx) {
  18224. this._ctx.quadraticCurveTo(x1, y1, x2, y2);
  18225. }
  18226. return this;
  18227. };
  18228. PathProxy.prototype.arc = function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  18229. this.pathCommands.push(new PathSegment('A', [
  18230. cx,
  18231. cy,
  18232. r,
  18233. r,
  18234. startAngle,
  18235. endAngle - startAngle,
  18236. 0,
  18237. anticlockwise ? 0 : 1
  18238. ]));
  18239. if (this._ctx) {
  18240. this._ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  18241. }
  18242. return this;
  18243. };
  18244. PathProxy.prototype.arcTo = function (x1, y1, x2, y2, radius) {
  18245. if (this._ctx) {
  18246. this._ctx.arcTo(x1, y1, x2, y2, radius);
  18247. }
  18248. return this;
  18249. };
  18250. PathProxy.prototype.rect = function (x, y, w, h) {
  18251. if (this._ctx) {
  18252. this._ctx.rect(x, y, w, h);
  18253. }
  18254. return this;
  18255. };
  18256. PathProxy.prototype.closePath = function () {
  18257. this.pathCommands.push(new PathSegment('z'));
  18258. if (this._ctx) {
  18259. this._ctx.closePath();
  18260. }
  18261. return this;
  18262. };
  18263. PathProxy.prototype.isEmpty = function () {
  18264. return this.pathCommands.length === 0;
  18265. };
  18266. PathProxy.PathSegment = PathSegment;
  18267. return PathProxy;
  18268. });define('zrender/shape/Line', [
  18269. 'require',
  18270. './Base',
  18271. './util/dashedLineTo',
  18272. '../tool/util'
  18273. ], function (require) {
  18274. var Base = require('./Base');
  18275. var dashedLineTo = require('./util/dashedLineTo');
  18276. var Line = function (options) {
  18277. this.brushTypeOnly = 'stroke';
  18278. this.textPosition = 'end';
  18279. Base.call(this, options);
  18280. };
  18281. Line.prototype = {
  18282. type: 'line',
  18283. buildPath: function (ctx, style) {
  18284. if (!style.lineType || style.lineType == 'solid') {
  18285. ctx.moveTo(style.xStart, style.yStart);
  18286. ctx.lineTo(style.xEnd, style.yEnd);
  18287. } else if (style.lineType == 'dashed' || style.lineType == 'dotted') {
  18288. var dashLength = (style.lineWidth || 1) * (style.lineType == 'dashed' ? 5 : 1);
  18289. dashedLineTo(ctx, style.xStart, style.yStart, style.xEnd, style.yEnd, dashLength);
  18290. }
  18291. },
  18292. getRect: function (style) {
  18293. if (style.__rect) {
  18294. return style.__rect;
  18295. }
  18296. var lineWidth = style.lineWidth || 1;
  18297. style.__rect = {
  18298. x: Math.min(style.xStart, style.xEnd) - lineWidth,
  18299. y: Math.min(style.yStart, style.yEnd) - lineWidth,
  18300. width: Math.abs(style.xStart - style.xEnd) + lineWidth,
  18301. height: Math.abs(style.yStart - style.yEnd) + lineWidth
  18302. };
  18303. return style.__rect;
  18304. }
  18305. };
  18306. require('../tool/util').inherits(Line, Base);
  18307. return Line;
  18308. });define('zrender/shape/BezierCurve', [
  18309. 'require',
  18310. './Base',
  18311. '../tool/util'
  18312. ], function (require) {
  18313. 'use strict';
  18314. var Base = require('./Base');
  18315. var BezierCurve = function (options) {
  18316. this.brushTypeOnly = 'stroke';
  18317. this.textPosition = 'end';
  18318. Base.call(this, options);
  18319. };
  18320. BezierCurve.prototype = {
  18321. type: 'bezier-curve',
  18322. buildPath: function (ctx, style) {
  18323. ctx.moveTo(style.xStart, style.yStart);
  18324. if (typeof style.cpX2 != 'undefined' && typeof style.cpY2 != 'undefined') {
  18325. ctx.bezierCurveTo(style.cpX1, style.cpY1, style.cpX2, style.cpY2, style.xEnd, style.yEnd);
  18326. } else {
  18327. ctx.quadraticCurveTo(style.cpX1, style.cpY1, style.xEnd, style.yEnd);
  18328. }
  18329. },
  18330. getRect: function (style) {
  18331. if (style.__rect) {
  18332. return style.__rect;
  18333. }
  18334. var _minX = Math.min(style.xStart, style.xEnd, style.cpX1);
  18335. var _minY = Math.min(style.yStart, style.yEnd, style.cpY1);
  18336. var _maxX = Math.max(style.xStart, style.xEnd, style.cpX1);
  18337. var _maxY = Math.max(style.yStart, style.yEnd, style.cpY1);
  18338. var _x2 = style.cpX2;
  18339. var _y2 = style.cpY2;
  18340. if (typeof _x2 != 'undefined' && typeof _y2 != 'undefined') {
  18341. _minX = Math.min(_minX, _x2);
  18342. _minY = Math.min(_minY, _y2);
  18343. _maxX = Math.max(_maxX, _x2);
  18344. _maxY = Math.max(_maxY, _y2);
  18345. }
  18346. var lineWidth = style.lineWidth || 1;
  18347. style.__rect = {
  18348. x: _minX - lineWidth,
  18349. y: _minY - lineWidth,
  18350. width: _maxX - _minX + lineWidth,
  18351. height: _maxY - _minY + lineWidth
  18352. };
  18353. return style.__rect;
  18354. }
  18355. };
  18356. require('../tool/util').inherits(BezierCurve, Base);
  18357. return BezierCurve;
  18358. });define('zrender/shape/util/dashedLineTo', [], function () {
  18359. var dashPattern = [
  18360. 5,
  18361. 5
  18362. ];
  18363. return function (ctx, x1, y1, x2, y2, dashLength) {
  18364. if (ctx.setLineDash) {
  18365. dashPattern[0] = dashPattern[1] = dashLength;
  18366. ctx.setLineDash(dashPattern);
  18367. ctx.moveTo(x1, y1);
  18368. ctx.lineTo(x2, y2);
  18369. return;
  18370. }
  18371. dashLength = typeof dashLength != 'number' ? 5 : dashLength;
  18372. var dx = x2 - x1;
  18373. var dy = y2 - y1;
  18374. var numDashes = Math.floor(Math.sqrt(dx * dx + dy * dy) / dashLength);
  18375. dx = dx / numDashes;
  18376. dy = dy / numDashes;
  18377. var flag = true;
  18378. for (var i = 0; i < numDashes; ++i) {
  18379. if (flag) {
  18380. ctx.moveTo(x1, y1);
  18381. } else {
  18382. ctx.lineTo(x1, y1);
  18383. }
  18384. flag = !flag;
  18385. x1 += dx;
  18386. y1 += dy;
  18387. }
  18388. ctx.lineTo(x2, y2);
  18389. };
  18390. });define('zrender/shape/Polygon', [
  18391. 'require',
  18392. './Base',
  18393. './util/smoothSpline',
  18394. './util/smoothBezier',
  18395. './util/dashedLineTo',
  18396. '../tool/util'
  18397. ], function (require) {
  18398. var Base = require('./Base');
  18399. var smoothSpline = require('./util/smoothSpline');
  18400. var smoothBezier = require('./util/smoothBezier');
  18401. var dashedLineTo = require('./util/dashedLineTo');
  18402. var Polygon = function (options) {
  18403. Base.call(this, options);
  18404. };
  18405. Polygon.prototype = {
  18406. type: 'polygon',
  18407. buildPath: function (ctx, style) {
  18408. var pointList = style.pointList;
  18409. if (pointList.length < 2) {
  18410. return;
  18411. }
  18412. if (style.smooth && style.smooth !== 'spline') {
  18413. var controlPoints = smoothBezier(pointList, style.smooth, true, style.smoothConstraint);
  18414. ctx.moveTo(pointList[0][0], pointList[0][1]);
  18415. var cp1;
  18416. var cp2;
  18417. var p;
  18418. var len = pointList.length;
  18419. for (var i = 0; i < len; i++) {
  18420. cp1 = controlPoints[i * 2];
  18421. cp2 = controlPoints[i * 2 + 1];
  18422. p = pointList[(i + 1) % len];
  18423. ctx.bezierCurveTo(cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]);
  18424. }
  18425. } else {
  18426. if (style.smooth === 'spline') {
  18427. pointList = smoothSpline(pointList, true);
  18428. }
  18429. if (!style.lineType || style.lineType == 'solid') {
  18430. ctx.moveTo(pointList[0][0], pointList[0][1]);
  18431. for (var i = 1, l = pointList.length; i < l; i++) {
  18432. ctx.lineTo(pointList[i][0], pointList[i][1]);
  18433. }
  18434. ctx.lineTo(pointList[0][0], pointList[0][1]);
  18435. } else if (style.lineType == 'dashed' || style.lineType == 'dotted') {
  18436. var dashLength = style._dashLength || (style.lineWidth || 1) * (style.lineType == 'dashed' ? 5 : 1);
  18437. style._dashLength = dashLength;
  18438. ctx.moveTo(pointList[0][0], pointList[0][1]);
  18439. for (var i = 1, l = pointList.length; i < l; i++) {
  18440. dashedLineTo(ctx, pointList[i - 1][0], pointList[i - 1][1], pointList[i][0], pointList[i][1], dashLength);
  18441. }
  18442. dashedLineTo(ctx, pointList[pointList.length - 1][0], pointList[pointList.length - 1][1], pointList[0][0], pointList[0][1], dashLength);
  18443. }
  18444. }
  18445. ctx.closePath();
  18446. return;
  18447. },
  18448. getRect: function (style) {
  18449. if (style.__rect) {
  18450. return style.__rect;
  18451. }
  18452. var minX = Number.MAX_VALUE;
  18453. var maxX = Number.MIN_VALUE;
  18454. var minY = Number.MAX_VALUE;
  18455. var maxY = Number.MIN_VALUE;
  18456. var pointList = style.pointList;
  18457. for (var i = 0, l = pointList.length; i < l; i++) {
  18458. if (pointList[i][0] < minX) {
  18459. minX = pointList[i][0];
  18460. }
  18461. if (pointList[i][0] > maxX) {
  18462. maxX = pointList[i][0];
  18463. }
  18464. if (pointList[i][1] < minY) {
  18465. minY = pointList[i][1];
  18466. }
  18467. if (pointList[i][1] > maxY) {
  18468. maxY = pointList[i][1];
  18469. }
  18470. }
  18471. var lineWidth;
  18472. if (style.brushType == 'stroke' || style.brushType == 'fill') {
  18473. lineWidth = style.lineWidth || 1;
  18474. } else {
  18475. lineWidth = 0;
  18476. }
  18477. style.__rect = {
  18478. x: Math.round(minX - lineWidth / 2),
  18479. y: Math.round(minY - lineWidth / 2),
  18480. width: maxX - minX + lineWidth,
  18481. height: maxY - minY + lineWidth
  18482. };
  18483. return style.__rect;
  18484. }
  18485. };
  18486. require('../tool/util').inherits(Polygon, Base);
  18487. return Polygon;
  18488. });define('echarts/util/shape/normalIsCover', [], function () {
  18489. return function (x, y) {
  18490. var originPos = this.transformCoordToLocal(x, y);
  18491. x = originPos[0];
  18492. y = originPos[1];
  18493. return this.isCoverRect(x, y);
  18494. };
  18495. });define('zrender/shape/util/smoothSpline', [
  18496. 'require',
  18497. '../../tool/vector'
  18498. ], function (require) {
  18499. var vector = require('../../tool/vector');
  18500. function interpolate(p0, p1, p2, p3, t, t2, t3) {
  18501. var v0 = (p2 - p0) * 0.5;
  18502. var v1 = (p3 - p1) * 0.5;
  18503. return (2 * (p1 - p2) + v0 + v1) * t3 + (-3 * (p1 - p2) - 2 * v0 - v1) * t2 + v0 * t + p1;
  18504. }
  18505. return function (points, isLoop, constraint) {
  18506. var len = points.length;
  18507. var ret = [];
  18508. var distance = 0;
  18509. for (var i = 1; i < len; i++) {
  18510. distance += vector.distance(points[i - 1], points[i]);
  18511. }
  18512. var segs = distance / 5;
  18513. segs = segs < len ? len : segs;
  18514. for (var i = 0; i < segs; i++) {
  18515. var pos = i / (segs - 1) * (isLoop ? len : len - 1);
  18516. var idx = Math.floor(pos);
  18517. var w = pos - idx;
  18518. var p0;
  18519. var p1 = points[idx % len];
  18520. var p2;
  18521. var p3;
  18522. if (!isLoop) {
  18523. p0 = points[idx === 0 ? idx : idx - 1];
  18524. p2 = points[idx > len - 2 ? len - 1 : idx + 1];
  18525. p3 = points[idx > len - 3 ? len - 1 : idx + 2];
  18526. } else {
  18527. p0 = points[(idx - 1 + len) % len];
  18528. p2 = points[(idx + 1) % len];
  18529. p3 = points[(idx + 2) % len];
  18530. }
  18531. var w2 = w * w;
  18532. var w3 = w * w2;
  18533. ret.push([
  18534. interpolate(p0[0], p1[0], p2[0], p3[0], w, w2, w3),
  18535. interpolate(p0[1], p1[1], p2[1], p3[1], w, w2, w3)
  18536. ]);
  18537. }
  18538. return ret;
  18539. };
  18540. });define('zrender/shape/util/smoothBezier', [
  18541. 'require',
  18542. '../../tool/vector'
  18543. ], function (require) {
  18544. var vector = require('../../tool/vector');
  18545. return function (points, smooth, isLoop, constraint) {
  18546. var cps = [];
  18547. var v = [];
  18548. var v1 = [];
  18549. var v2 = [];
  18550. var prevPoint;
  18551. var nextPoint;
  18552. var hasConstraint = !!constraint;
  18553. var min, max;
  18554. if (hasConstraint) {
  18555. min = [
  18556. Infinity,
  18557. Infinity
  18558. ];
  18559. max = [
  18560. -Infinity,
  18561. -Infinity
  18562. ];
  18563. for (var i = 0, len = points.length; i < len; i++) {
  18564. vector.min(min, min, points[i]);
  18565. vector.max(max, max, points[i]);
  18566. }
  18567. vector.min(min, min, constraint[0]);
  18568. vector.max(max, max, constraint[1]);
  18569. }
  18570. for (var i = 0, len = points.length; i < len; i++) {
  18571. var point = points[i];
  18572. var prevPoint;
  18573. var nextPoint;
  18574. if (isLoop) {
  18575. prevPoint = points[i ? i - 1 : len - 1];
  18576. nextPoint = points[(i + 1) % len];
  18577. } else {
  18578. if (i === 0 || i === len - 1) {
  18579. cps.push(vector.clone(points[i]));
  18580. continue;
  18581. } else {
  18582. prevPoint = points[i - 1];
  18583. nextPoint = points[i + 1];
  18584. }
  18585. }
  18586. vector.sub(v, nextPoint, prevPoint);
  18587. vector.scale(v, v, smooth);
  18588. var d0 = vector.distance(point, prevPoint);
  18589. var d1 = vector.distance(point, nextPoint);
  18590. var sum = d0 + d1;
  18591. if (sum !== 0) {
  18592. d0 /= sum;
  18593. d1 /= sum;
  18594. }
  18595. vector.scale(v1, v, -d0);
  18596. vector.scale(v2, v, d1);
  18597. var cp0 = vector.add([], point, v1);
  18598. var cp1 = vector.add([], point, v2);
  18599. if (hasConstraint) {
  18600. vector.max(cp0, cp0, min);
  18601. vector.min(cp0, cp0, max);
  18602. vector.max(cp1, cp1, min);
  18603. vector.min(cp1, cp1, max);
  18604. }
  18605. cps.push(cp0);
  18606. cps.push(cp1);
  18607. }
  18608. if (isLoop) {
  18609. cps.push(vector.clone(cps.shift()));
  18610. }
  18611. return cps;
  18612. };
  18613. });define('echarts/util/ecQuery', [
  18614. 'require',
  18615. 'zrender/tool/util'
  18616. ], function (require) {
  18617. var zrUtil = require('zrender/tool/util');
  18618. function query(optionTarget, optionLocation) {
  18619. if (typeof optionTarget == 'undefined') {
  18620. return;
  18621. }
  18622. if (!optionLocation) {
  18623. return optionTarget;
  18624. }
  18625. optionLocation = optionLocation.split('.');
  18626. var length = optionLocation.length;
  18627. var curIdx = 0;
  18628. while (curIdx < length) {
  18629. optionTarget = optionTarget[optionLocation[curIdx]];
  18630. if (typeof optionTarget == 'undefined') {
  18631. return;
  18632. }
  18633. curIdx++;
  18634. }
  18635. return optionTarget;
  18636. }
  18637. function deepQuery(ctrList, optionLocation) {
  18638. var finalOption;
  18639. for (var i = 0, l = ctrList.length; i < l; i++) {
  18640. finalOption = query(ctrList[i], optionLocation);
  18641. if (typeof finalOption != 'undefined') {
  18642. return finalOption;
  18643. }
  18644. }
  18645. }
  18646. function deepMerge(ctrList, optionLocation) {
  18647. var finalOption;
  18648. var len = ctrList.length;
  18649. while (len--) {
  18650. var tempOption = query(ctrList[len], optionLocation);
  18651. if (typeof tempOption != 'undefined') {
  18652. if (typeof finalOption == 'undefined') {
  18653. finalOption = zrUtil.clone(tempOption);
  18654. } else {
  18655. zrUtil.merge(finalOption, tempOption, true);
  18656. }
  18657. }
  18658. }
  18659. return finalOption;
  18660. }
  18661. return {
  18662. query: query,
  18663. deepQuery: deepQuery,
  18664. deepMerge: deepMerge
  18665. };
  18666. });define('echarts/util/number', [], function () {
  18667. function _trim(str) {
  18668. return str.replace(/^\s+/, '').replace(/\s+$/, '');
  18669. }
  18670. function parsePercent(value, maxValue) {
  18671. if (typeof value === 'string') {
  18672. if (_trim(value).match(/%$/)) {
  18673. return parseFloat(value) / 100 * maxValue;
  18674. }
  18675. return parseFloat(value);
  18676. }
  18677. return value;
  18678. }
  18679. function parseCenter(zr, center) {
  18680. return [
  18681. parsePercent(center[0], zr.getWidth()),
  18682. parsePercent(center[1], zr.getHeight())
  18683. ];
  18684. }
  18685. function parseRadius(zr, radius) {
  18686. if (!(radius instanceof Array)) {
  18687. radius = [
  18688. 0,
  18689. radius
  18690. ];
  18691. }
  18692. var zrSize = Math.min(zr.getWidth(), zr.getHeight()) / 2;
  18693. return [
  18694. parsePercent(radius[0], zrSize),
  18695. parsePercent(radius[1], zrSize)
  18696. ];
  18697. }
  18698. function addCommas(x) {
  18699. if (isNaN(x)) {
  18700. return '-';
  18701. }
  18702. x = (x + '').split('.');
  18703. return x[0].replace(/(\d{1,3})(?=(?:\d{3})+(?!\d))/g, '$1,') + (x.length > 1 ? '.' + x[1] : '');
  18704. }
  18705. function getPrecision(val) {
  18706. var e = 1;
  18707. var count = 0;
  18708. while (Math.round(val * e) / e !== val) {
  18709. e *= 10;
  18710. count++;
  18711. }
  18712. return count;
  18713. }
  18714. return {
  18715. parsePercent: parsePercent,
  18716. parseCenter: parseCenter,
  18717. parseRadius: parseRadius,
  18718. addCommas: addCommas,
  18719. getPrecision: getPrecision
  18720. };
  18721. });define('echarts/data/KDTree', [
  18722. 'require',
  18723. './quickSelect'
  18724. ], function (require) {
  18725. var quickSelect = require('./quickSelect');
  18726. function Node(axis, data) {
  18727. this.left = null;
  18728. this.right = null;
  18729. this.axis = axis;
  18730. this.data = data;
  18731. }
  18732. var KDTree = function (points, dimension) {
  18733. if (!points.length) {
  18734. return;
  18735. }
  18736. if (!dimension) {
  18737. dimension = points[0].array.length;
  18738. }
  18739. this.dimension = dimension;
  18740. this.root = this._buildTree(points, 0, points.length - 1, 0);
  18741. this._stack = [];
  18742. this._nearstNList = [];
  18743. };
  18744. KDTree.prototype._buildTree = function (points, left, right, axis) {
  18745. if (right < left) {
  18746. return null;
  18747. }
  18748. var medianIndex = Math.floor((left + right) / 2);
  18749. medianIndex = quickSelect(points, left, right, medianIndex, function (a, b) {
  18750. return a.array[axis] - b.array[axis];
  18751. });
  18752. var median = points[medianIndex];
  18753. var node = new Node(axis, median);
  18754. axis = (axis + 1) % this.dimension;
  18755. if (right > left) {
  18756. node.left = this._buildTree(points, left, medianIndex - 1, axis);
  18757. node.right = this._buildTree(points, medianIndex + 1, right, axis);
  18758. }
  18759. return node;
  18760. };
  18761. KDTree.prototype.nearest = function (target, squaredDistance) {
  18762. var curr = this.root;
  18763. var stack = this._stack;
  18764. var idx = 0;
  18765. var minDist = Infinity;
  18766. var nearestNode = null;
  18767. if (curr.data !== target) {
  18768. minDist = squaredDistance(curr.data, target);
  18769. nearestNode = curr;
  18770. }
  18771. if (target.array[curr.axis] < curr.data.array[curr.axis]) {
  18772. curr.right && (stack[idx++] = curr.right);
  18773. curr.left && (stack[idx++] = curr.left);
  18774. } else {
  18775. curr.left && (stack[idx++] = curr.left);
  18776. curr.right && (stack[idx++] = curr.right);
  18777. }
  18778. while (idx--) {
  18779. curr = stack[idx];
  18780. var currDist = target.array[curr.axis] - curr.data.array[curr.axis];
  18781. var isLeft = currDist < 0;
  18782. var needsCheckOtherSide = false;
  18783. currDist = currDist * currDist;
  18784. if (currDist < minDist) {
  18785. currDist = squaredDistance(curr.data, target);
  18786. if (currDist < minDist && curr.data !== target) {
  18787. minDist = currDist;
  18788. nearestNode = curr;
  18789. }
  18790. needsCheckOtherSide = true;
  18791. }
  18792. if (isLeft) {
  18793. if (needsCheckOtherSide) {
  18794. curr.right && (stack[idx++] = curr.right);
  18795. }
  18796. curr.left && (stack[idx++] = curr.left);
  18797. } else {
  18798. if (needsCheckOtherSide) {
  18799. curr.left && (stack[idx++] = curr.left);
  18800. }
  18801. curr.right && (stack[idx++] = curr.right);
  18802. }
  18803. }
  18804. return nearestNode.data;
  18805. };
  18806. KDTree.prototype._addNearest = function (found, dist, node) {
  18807. var nearestNList = this._nearstNList;
  18808. for (var i = found - 1; i > 0; i--) {
  18809. if (dist >= nearestNList[i - 1].dist) {
  18810. break;
  18811. } else {
  18812. nearestNList[i].dist = nearestNList[i - 1].dist;
  18813. nearestNList[i].node = nearestNList[i - 1].node;
  18814. }
  18815. }
  18816. nearestNList[i].dist = dist;
  18817. nearestNList[i].node = node;
  18818. };
  18819. KDTree.prototype.nearestN = function (target, N, squaredDistance, output) {
  18820. if (N <= 0) {
  18821. output.length = 0;
  18822. return output;
  18823. }
  18824. var curr = this.root;
  18825. var stack = this._stack;
  18826. var idx = 0;
  18827. var nearestNList = this._nearstNList;
  18828. for (var i = 0; i < N; i++) {
  18829. if (!nearestNList[i]) {
  18830. nearestNList[i] = {};
  18831. }
  18832. nearestNList[i].dist = 0;
  18833. nearestNList[i].node = null;
  18834. }
  18835. var currDist = squaredDistance(curr.data, target);
  18836. var found = 0;
  18837. if (curr.data !== target) {
  18838. found++;
  18839. this._addNearest(found, currDist, curr);
  18840. }
  18841. if (target.array[curr.axis] < curr.data.array[curr.axis]) {
  18842. curr.right && (stack[idx++] = curr.right);
  18843. curr.left && (stack[idx++] = curr.left);
  18844. } else {
  18845. curr.left && (stack[idx++] = curr.left);
  18846. curr.right && (stack[idx++] = curr.right);
  18847. }
  18848. while (idx--) {
  18849. curr = stack[idx];
  18850. var currDist = target.array[curr.axis] - curr.data.array[curr.axis];
  18851. var isLeft = currDist < 0;
  18852. var needsCheckOtherSide = false;
  18853. currDist = currDist * currDist;
  18854. if (found < N || currDist < nearestNList[found - 1].dist) {
  18855. currDist = squaredDistance(curr.data, target);
  18856. if ((found < N || currDist < nearestNList[found - 1].dist) && curr.data !== target) {
  18857. if (found < N) {
  18858. found++;
  18859. }
  18860. this._addNearest(found, currDist, curr);
  18861. }
  18862. needsCheckOtherSide = true;
  18863. }
  18864. if (isLeft) {
  18865. if (needsCheckOtherSide) {
  18866. curr.right && (stack[idx++] = curr.right);
  18867. }
  18868. curr.left && (stack[idx++] = curr.left);
  18869. } else {
  18870. if (needsCheckOtherSide) {
  18871. curr.left && (stack[idx++] = curr.left);
  18872. }
  18873. curr.right && (stack[idx++] = curr.right);
  18874. }
  18875. }
  18876. for (var i = 0; i < found; i++) {
  18877. output[i] = nearestNList[i].node.data;
  18878. }
  18879. output.length = found;
  18880. return output;
  18881. };
  18882. return KDTree;
  18883. });define('echarts/data/quickSelect', ['require'], function (require) {
  18884. function defaultCompareFunc(a, b) {
  18885. return a - b;
  18886. }
  18887. function swapElement(list, idx0, idx1) {
  18888. var tmp = list[idx0];
  18889. list[idx0] = list[idx1];
  18890. list[idx1] = tmp;
  18891. }
  18892. function select(list, left, right, nth, compareFunc) {
  18893. var pivotIdx = left;
  18894. while (right > left) {
  18895. var pivotIdx = Math.round((right + left) / 2);
  18896. var pivotValue = list[pivotIdx];
  18897. swapElement(list, pivotIdx, right);
  18898. pivotIdx = left;
  18899. for (var i = left; i <= right - 1; i++) {
  18900. if (compareFunc(pivotValue, list[i]) >= 0) {
  18901. swapElement(list, i, pivotIdx);
  18902. pivotIdx++;
  18903. }
  18904. }
  18905. swapElement(list, right, pivotIdx);
  18906. if (pivotIdx === nth) {
  18907. return pivotIdx;
  18908. } else if (pivotIdx < nth) {
  18909. left = pivotIdx + 1;
  18910. } else {
  18911. right = pivotIdx - 1;
  18912. }
  18913. }
  18914. return left;
  18915. }
  18916. function quickSelect(list, left, right, nth, compareFunc) {
  18917. if (arguments.length <= 3) {
  18918. nth = left;
  18919. if (arguments.length == 2) {
  18920. compareFunc = defaultCompareFunc;
  18921. } else {
  18922. compareFunc = right;
  18923. }
  18924. left = 0;
  18925. right = list.length - 1;
  18926. }
  18927. return select(list, left, right, nth, compareFunc);
  18928. }
  18929. return quickSelect;
  18930. });define('echarts/component/dataView', [
  18931. 'require',
  18932. './base',
  18933. '../config',
  18934. 'zrender/tool/util',
  18935. '../component'
  18936. ], function (require) {
  18937. var Base = require('./base');
  18938. var ecConfig = require('../config');
  18939. var zrUtil = require('zrender/tool/util');
  18940. function DataView(ecTheme, messageCenter, zr, option, myChart) {
  18941. Base.call(this, ecTheme, messageCenter, zr, option, myChart);
  18942. this.dom = myChart.dom;
  18943. this._tDom = document.createElement('div');
  18944. this._textArea = document.createElement('textArea');
  18945. this._buttonRefresh = document.createElement('button');
  18946. this._buttonRefresh.setAttribute('type', 'button');
  18947. this._buttonClose = document.createElement('button');
  18948. this._buttonClose.setAttribute('type', 'button');
  18949. this._hasShow = false;
  18950. this._zrHeight = zr.getHeight();
  18951. this._zrWidth = zr.getWidth();
  18952. this._tDom.className = 'echarts-dataview';
  18953. this.hide();
  18954. this.dom.firstChild.appendChild(this._tDom);
  18955. if (window.addEventListener) {
  18956. this._tDom.addEventListener('click', this._stop);
  18957. this._tDom.addEventListener('mousewheel', this._stop);
  18958. this._tDom.addEventListener('mousemove', this._stop);
  18959. this._tDom.addEventListener('mousedown', this._stop);
  18960. this._tDom.addEventListener('mouseup', this._stop);
  18961. this._tDom.addEventListener('touchstart', this._stop);
  18962. this._tDom.addEventListener('touchmove', this._stop);
  18963. this._tDom.addEventListener('touchend', this._stop);
  18964. } else {
  18965. this._tDom.attachEvent('onclick', this._stop);
  18966. this._tDom.attachEvent('onmousewheel', this._stop);
  18967. this._tDom.attachEvent('onmousemove', this._stop);
  18968. this._tDom.attachEvent('onmousedown', this._stop);
  18969. this._tDom.attachEvent('onmouseup', this._stop);
  18970. }
  18971. }
  18972. DataView.prototype = {
  18973. type: ecConfig.COMPONENT_TYPE_DATAVIEW,
  18974. _lang: [
  18975. 'Data View',
  18976. 'close',
  18977. 'refresh'
  18978. ],
  18979. _gCssText: 'position:absolute;' + 'display:block;' + 'overflow:hidden;' + 'transition:height 0.8s,background-color 1s;' + '-moz-transition:height 0.8s,background-color 1s;' + '-webkit-transition:height 0.8s,background-color 1s;' + '-o-transition:height 0.8s,background-color 1s;' + 'z-index:1;' + 'left:0;' + 'top:0;',
  18980. hide: function () {
  18981. this._sizeCssText = 'width:' + this._zrWidth + 'px;' + 'height:' + 0 + 'px;' + 'background-color:#f0ffff;';
  18982. this._tDom.style.cssText = this._gCssText + this._sizeCssText;
  18983. },
  18984. show: function (newOption) {
  18985. this._hasShow = true;
  18986. var lang = this.query(this.option, 'toolbox.feature.dataView.lang') || this._lang;
  18987. this.option = newOption;
  18988. this._tDom.innerHTML = '<p style="padding:8px 0;margin:0 0 10px 0;' + 'border-bottom:1px solid #eee">' + (lang[0] || this._lang[0]) + '</p>';
  18989. var customContent = this.query(this.option, 'toolbox.feature.dataView.optionToContent');
  18990. if (typeof customContent != 'function') {
  18991. this._textArea.value = this._optionToContent();
  18992. } else {
  18993. this._textArea = document.createElement('div');
  18994. this._textArea.innerHTML = customContent(this.option);
  18995. }
  18996. this._textArea.style.cssText = 'display:block;margin:0 0 8px 0;padding:4px 6px;overflow:auto;' + 'width:100%;' + 'height:' + (this._zrHeight - 100) + 'px;';
  18997. this._tDom.appendChild(this._textArea);
  18998. this._buttonClose.style.cssText = 'float:right;padding:1px 6px;';
  18999. this._buttonClose.innerHTML = lang[1] || this._lang[1];
  19000. var self = this;
  19001. this._buttonClose.onclick = function () {
  19002. self.hide();
  19003. };
  19004. this._tDom.appendChild(this._buttonClose);
  19005. if (this.query(this.option, 'toolbox.feature.dataView.readOnly') === false) {
  19006. this._buttonRefresh.style.cssText = 'float:right;margin-right:10px;padding:1px 6px;';
  19007. this._buttonRefresh.innerHTML = lang[2] || this._lang[2];
  19008. this._buttonRefresh.onclick = function () {
  19009. self._save();
  19010. };
  19011. this._textArea.readOnly = false;
  19012. this._textArea.style.cursor = 'default';
  19013. } else {
  19014. this._buttonRefresh.style.cssText = 'display:none';
  19015. this._textArea.readOnly = true;
  19016. this._textArea.style.cursor = 'text';
  19017. }
  19018. this._tDom.appendChild(this._buttonRefresh);
  19019. this._sizeCssText = 'width:' + this._zrWidth + 'px;' + 'height:' + this._zrHeight + 'px;' + 'background-color:#fff;';
  19020. this._tDom.style.cssText = this._gCssText + this._sizeCssText;
  19021. },
  19022. _optionToContent: function () {
  19023. var i;
  19024. var j;
  19025. var k;
  19026. var len;
  19027. var data;
  19028. var valueList;
  19029. var axisList = [];
  19030. var content = '';
  19031. if (this.option.xAxis) {
  19032. if (this.option.xAxis instanceof Array) {
  19033. axisList = this.option.xAxis;
  19034. } else {
  19035. axisList = [this.option.xAxis];
  19036. }
  19037. for (i = 0, len = axisList.length; i < len; i++) {
  19038. if ((axisList[i].type || 'category') == 'category') {
  19039. valueList = [];
  19040. for (j = 0, k = axisList[i].data.length; j < k; j++) {
  19041. valueList.push(this.getDataFromOption(axisList[i].data[j]));
  19042. }
  19043. content += valueList.join(', ') + '\n\n';
  19044. }
  19045. }
  19046. }
  19047. if (this.option.yAxis) {
  19048. if (this.option.yAxis instanceof Array) {
  19049. axisList = this.option.yAxis;
  19050. } else {
  19051. axisList = [this.option.yAxis];
  19052. }
  19053. for (i = 0, len = axisList.length; i < len; i++) {
  19054. if (axisList[i].type == 'category') {
  19055. valueList = [];
  19056. for (j = 0, k = axisList[i].data.length; j < k; j++) {
  19057. valueList.push(this.getDataFromOption(axisList[i].data[j]));
  19058. }
  19059. content += valueList.join(', ') + '\n\n';
  19060. }
  19061. }
  19062. }
  19063. var series = this.option.series;
  19064. var itemName;
  19065. for (i = 0, len = series.length; i < len; i++) {
  19066. valueList = [];
  19067. for (j = 0, k = series[i].data.length; j < k; j++) {
  19068. data = series[i].data[j];
  19069. if (series[i].type == ecConfig.CHART_TYPE_PIE || series[i].type == ecConfig.CHART_TYPE_MAP) {
  19070. itemName = (data.name || '-') + ':';
  19071. } else {
  19072. itemName = '';
  19073. }
  19074. if (series[i].type == ecConfig.CHART_TYPE_SCATTER) {
  19075. data = this.getDataFromOption(data).join(', ');
  19076. }
  19077. valueList.push(itemName + this.getDataFromOption(data));
  19078. }
  19079. content += (series[i].name || '-') + ' : \n';
  19080. content += valueList.join(series[i].type == ecConfig.CHART_TYPE_SCATTER ? '\n' : ', ');
  19081. content += '\n\n';
  19082. }
  19083. return content;
  19084. },
  19085. _save: function () {
  19086. var customContent = this.query(this.option, 'toolbox.feature.dataView.contentToOption');
  19087. if (typeof customContent != 'function') {
  19088. var text = this._textArea.value.split('\n');
  19089. var content = [];
  19090. for (var i = 0, l = text.length; i < l; i++) {
  19091. text[i] = this._trim(text[i]);
  19092. if (text[i] !== '') {
  19093. content.push(text[i]);
  19094. }
  19095. }
  19096. this._contentToOption(content);
  19097. } else {
  19098. customContent(this._textArea, this.option);
  19099. }
  19100. this.hide();
  19101. var self = this;
  19102. setTimeout(function () {
  19103. self.messageCenter && self.messageCenter.dispatch(ecConfig.EVENT.DATA_VIEW_CHANGED, null, { option: self.option }, self.myChart);
  19104. }, self.canvasSupported ? 800 : 100);
  19105. },
  19106. _contentToOption: function (content) {
  19107. var i;
  19108. var j;
  19109. var k;
  19110. var len;
  19111. var data;
  19112. var axisList = [];
  19113. var contentIdx = 0;
  19114. var contentValueList;
  19115. var value;
  19116. if (this.option.xAxis) {
  19117. if (this.option.xAxis instanceof Array) {
  19118. axisList = this.option.xAxis;
  19119. } else {
  19120. axisList = [this.option.xAxis];
  19121. }
  19122. for (i = 0, len = axisList.length; i < len; i++) {
  19123. if ((axisList[i].type || 'category') == 'category') {
  19124. contentValueList = content[contentIdx].split(',');
  19125. for (j = 0, k = axisList[i].data.length; j < k; j++) {
  19126. value = this._trim(contentValueList[j] || '');
  19127. data = axisList[i].data[j];
  19128. if (typeof axisList[i].data[j].value != 'undefined') {
  19129. axisList[i].data[j].value = value;
  19130. } else {
  19131. axisList[i].data[j] = value;
  19132. }
  19133. }
  19134. contentIdx++;
  19135. }
  19136. }
  19137. }
  19138. if (this.option.yAxis) {
  19139. if (this.option.yAxis instanceof Array) {
  19140. axisList = this.option.yAxis;
  19141. } else {
  19142. axisList = [this.option.yAxis];
  19143. }
  19144. for (i = 0, len = axisList.length; i < len; i++) {
  19145. if (axisList[i].type == 'category') {
  19146. contentValueList = content[contentIdx].split(',');
  19147. for (j = 0, k = axisList[i].data.length; j < k; j++) {
  19148. value = this._trim(contentValueList[j] || '');
  19149. data = axisList[i].data[j];
  19150. if (typeof axisList[i].data[j].value != 'undefined') {
  19151. axisList[i].data[j].value = value;
  19152. } else {
  19153. axisList[i].data[j] = value;
  19154. }
  19155. }
  19156. contentIdx++;
  19157. }
  19158. }
  19159. }
  19160. var series = this.option.series;
  19161. for (i = 0, len = series.length; i < len; i++) {
  19162. contentIdx++;
  19163. if (series[i].type == ecConfig.CHART_TYPE_SCATTER) {
  19164. for (var j = 0, k = series[i].data.length; j < k; j++) {
  19165. contentValueList = content[contentIdx];
  19166. value = contentValueList.replace(' ', '').split(',');
  19167. if (typeof series[i].data[j].value != 'undefined') {
  19168. series[i].data[j].value = value;
  19169. } else {
  19170. series[i].data[j] = value;
  19171. }
  19172. contentIdx++;
  19173. }
  19174. } else {
  19175. contentValueList = content[contentIdx].split(',');
  19176. for (var j = 0, k = series[i].data.length; j < k; j++) {
  19177. value = (contentValueList[j] || '').replace(/.*:/, '');
  19178. value = this._trim(value);
  19179. value = value != '-' && value !== '' ? value - 0 : '-';
  19180. if (typeof series[i].data[j].value != 'undefined') {
  19181. series[i].data[j].value = value;
  19182. } else {
  19183. series[i].data[j] = value;
  19184. }
  19185. }
  19186. contentIdx++;
  19187. }
  19188. }
  19189. },
  19190. _trim: function (str) {
  19191. var trimer = new RegExp('(^[\\s\\t\\xa0\\u3000]+)|([\\u3000\\xa0\\s\\t]+$)', 'g');
  19192. return str.replace(trimer, '');
  19193. },
  19194. _stop: function (e) {
  19195. e = e || window.event;
  19196. if (e.stopPropagation) {
  19197. e.stopPropagation();
  19198. } else {
  19199. e.cancelBubble = true;
  19200. }
  19201. },
  19202. resize: function () {
  19203. this._zrHeight = this.zr.getHeight();
  19204. this._zrWidth = this.zr.getWidth();
  19205. if (this._tDom.offsetHeight > 10) {
  19206. this._sizeCssText = 'width:' + this._zrWidth + 'px;' + 'height:' + this._zrHeight + 'px;' + 'background-color:#fff;';
  19207. this._tDom.style.cssText = this._gCssText + this._sizeCssText;
  19208. this._textArea.style.cssText = 'display:block;margin:0 0 8px 0;' + 'padding:4px 6px;overflow:auto;' + 'width:100%;' + 'height:' + (this._zrHeight - 100) + 'px;';
  19209. }
  19210. },
  19211. dispose: function () {
  19212. if (window.removeEventListener) {
  19213. this._tDom.removeEventListener('click', this._stop);
  19214. this._tDom.removeEventListener('mousewheel', this._stop);
  19215. this._tDom.removeEventListener('mousemove', this._stop);
  19216. this._tDom.removeEventListener('mousedown', this._stop);
  19217. this._tDom.removeEventListener('mouseup', this._stop);
  19218. this._tDom.removeEventListener('touchstart', this._stop);
  19219. this._tDom.removeEventListener('touchmove', this._stop);
  19220. this._tDom.removeEventListener('touchend', this._stop);
  19221. } else {
  19222. this._tDom.detachEvent('onclick', this._stop);
  19223. this._tDom.detachEvent('onmousewheel', this._stop);
  19224. this._tDom.detachEvent('onmousemove', this._stop);
  19225. this._tDom.detachEvent('onmousedown', this._stop);
  19226. this._tDom.detachEvent('onmouseup', this._stop);
  19227. }
  19228. this._buttonRefresh.onclick = null;
  19229. this._buttonClose.onclick = null;
  19230. if (this._hasShow) {
  19231. this._tDom.removeChild(this._textArea);
  19232. this._tDom.removeChild(this._buttonRefresh);
  19233. this._tDom.removeChild(this._buttonClose);
  19234. }
  19235. this._textArea = null;
  19236. this._buttonRefresh = null;
  19237. this._buttonClose = null;
  19238. this.dom.firstChild.removeChild(this._tDom);
  19239. this._tDom = null;
  19240. }
  19241. };
  19242. zrUtil.inherits(DataView, Base);
  19243. require('../component').define('dataView', DataView);
  19244. return DataView;
  19245. });define('echarts/util/shape/Cross', [
  19246. 'require',
  19247. 'zrender/shape/Base',
  19248. 'zrender/shape/Line',
  19249. 'zrender/tool/util',
  19250. './normalIsCover'
  19251. ], function (require) {
  19252. var Base = require('zrender/shape/Base');
  19253. var LineShape = require('zrender/shape/Line');
  19254. var zrUtil = require('zrender/tool/util');
  19255. function Cross(options) {
  19256. Base.call(this, options);
  19257. }
  19258. Cross.prototype = {
  19259. type: 'cross',
  19260. buildPath: function (ctx, style) {
  19261. var rect = style.rect;
  19262. style.xStart = rect.x;
  19263. style.xEnd = rect.x + rect.width;
  19264. style.yStart = style.yEnd = style.y;
  19265. LineShape.prototype.buildPath(ctx, style);
  19266. style.xStart = style.xEnd = style.x;
  19267. style.yStart = rect.y;
  19268. style.yEnd = rect.y + rect.height;
  19269. LineShape.prototype.buildPath(ctx, style);
  19270. },
  19271. getRect: function (style) {
  19272. return style.rect;
  19273. },
  19274. isCover: require('./normalIsCover')
  19275. };
  19276. zrUtil.inherits(Cross, Base);
  19277. return Cross;
  19278. });define('zrender/shape/Sector', [
  19279. 'require',
  19280. '../tool/math',
  19281. '../tool/computeBoundingBox',
  19282. '../tool/vector',
  19283. './Base',
  19284. '../tool/util'
  19285. ], function (require) {
  19286. var math = require('../tool/math');
  19287. var computeBoundingBox = require('../tool/computeBoundingBox');
  19288. var vec2 = require('../tool/vector');
  19289. var Base = require('./Base');
  19290. var min0 = vec2.create();
  19291. var min1 = vec2.create();
  19292. var max0 = vec2.create();
  19293. var max1 = vec2.create();
  19294. var Sector = function (options) {
  19295. Base.call(this, options);
  19296. };
  19297. Sector.prototype = {
  19298. type: 'sector',
  19299. buildPath: function (ctx, style) {
  19300. var x = style.x;
  19301. var y = style.y;
  19302. var r0 = style.r0 || 0;
  19303. var r = style.r;
  19304. var startAngle = style.startAngle;
  19305. var endAngle = style.endAngle;
  19306. var clockWise = style.clockWise || false;
  19307. startAngle = math.degreeToRadian(startAngle);
  19308. endAngle = math.degreeToRadian(endAngle);
  19309. if (!clockWise) {
  19310. startAngle = -startAngle;
  19311. endAngle = -endAngle;
  19312. }
  19313. var unitX = math.cos(startAngle);
  19314. var unitY = math.sin(startAngle);
  19315. ctx.moveTo(unitX * r0 + x, unitY * r0 + y);
  19316. ctx.lineTo(unitX * r + x, unitY * r + y);
  19317. ctx.arc(x, y, r, startAngle, endAngle, !clockWise);
  19318. ctx.lineTo(math.cos(endAngle) * r0 + x, math.sin(endAngle) * r0 + y);
  19319. if (r0 !== 0) {
  19320. ctx.arc(x, y, r0, endAngle, startAngle, clockWise);
  19321. }
  19322. ctx.closePath();
  19323. return;
  19324. },
  19325. getRect: function (style) {
  19326. if (style.__rect) {
  19327. return style.__rect;
  19328. }
  19329. var x = style.x;
  19330. var y = style.y;
  19331. var r0 = style.r0 || 0;
  19332. var r = style.r;
  19333. var startAngle = math.degreeToRadian(style.startAngle);
  19334. var endAngle = math.degreeToRadian(style.endAngle);
  19335. var clockWise = style.clockWise;
  19336. if (!clockWise) {
  19337. startAngle = -startAngle;
  19338. endAngle = -endAngle;
  19339. }
  19340. if (r0 > 1) {
  19341. computeBoundingBox.arc(x, y, r0, startAngle, endAngle, !clockWise, min0, max0);
  19342. } else {
  19343. min0[0] = max0[0] = x;
  19344. min0[1] = max0[1] = y;
  19345. }
  19346. computeBoundingBox.arc(x, y, r, startAngle, endAngle, !clockWise, min1, max1);
  19347. vec2.min(min0, min0, min1);
  19348. vec2.max(max0, max0, max1);
  19349. style.__rect = {
  19350. x: min0[0],
  19351. y: min0[1],
  19352. width: max0[0] - min0[0],
  19353. height: max0[1] - min0[1]
  19354. };
  19355. return style.__rect;
  19356. }
  19357. };
  19358. require('../tool/util').inherits(Sector, Base);
  19359. return Sector;
  19360. });define('echarts/util/shape/Candle', [
  19361. 'require',
  19362. 'zrender/shape/Base',
  19363. 'zrender/tool/util',
  19364. './normalIsCover'
  19365. ], function (require) {
  19366. var Base = require('zrender/shape/Base');
  19367. var zrUtil = require('zrender/tool/util');
  19368. function Candle(options) {
  19369. Base.call(this, options);
  19370. }
  19371. Candle.prototype = {
  19372. type: 'candle',
  19373. _numberOrder: function (a, b) {
  19374. return b - a;
  19375. },
  19376. buildPath: function (ctx, style) {
  19377. var yList = zrUtil.clone(style.y).sort(this._numberOrder);
  19378. ctx.moveTo(style.x, yList[3]);
  19379. ctx.lineTo(style.x, yList[2]);
  19380. ctx.moveTo(style.x - style.width / 2, yList[2]);
  19381. ctx.rect(style.x - style.width / 2, yList[2], style.width, yList[1] - yList[2]);
  19382. ctx.moveTo(style.x, yList[1]);
  19383. ctx.lineTo(style.x, yList[0]);
  19384. },
  19385. getRect: function (style) {
  19386. if (!style.__rect) {
  19387. var lineWidth = 0;
  19388. if (style.brushType == 'stroke' || style.brushType == 'fill') {
  19389. lineWidth = style.lineWidth || 1;
  19390. }
  19391. var yList = zrUtil.clone(style.y).sort(this._numberOrder);
  19392. style.__rect = {
  19393. x: Math.round(style.x - style.width / 2 - lineWidth / 2),
  19394. y: Math.round(yList[3] - lineWidth / 2),
  19395. width: style.width + lineWidth,
  19396. height: yList[0] - yList[3] + lineWidth
  19397. };
  19398. }
  19399. return style.__rect;
  19400. },
  19401. isCover: require('./normalIsCover')
  19402. };
  19403. zrUtil.inherits(Candle, Base);
  19404. return Candle;
  19405. });define('zrender/tool/computeBoundingBox', [
  19406. 'require',
  19407. './vector',
  19408. './curve'
  19409. ], function (require) {
  19410. var vec2 = require('./vector');
  19411. var curve = require('./curve');
  19412. function computeBoundingBox(points, min, max) {
  19413. if (points.length === 0) {
  19414. return;
  19415. }
  19416. var left = points[0][0];
  19417. var right = points[0][0];
  19418. var top = points[0][1];
  19419. var bottom = points[0][1];
  19420. for (var i = 1; i < points.length; i++) {
  19421. var p = points[i];
  19422. if (p[0] < left) {
  19423. left = p[0];
  19424. }
  19425. if (p[0] > right) {
  19426. right = p[0];
  19427. }
  19428. if (p[1] < top) {
  19429. top = p[1];
  19430. }
  19431. if (p[1] > bottom) {
  19432. bottom = p[1];
  19433. }
  19434. }
  19435. min[0] = left;
  19436. min[1] = top;
  19437. max[0] = right;
  19438. max[1] = bottom;
  19439. }
  19440. function computeCubeBezierBoundingBox(p0, p1, p2, p3, min, max) {
  19441. var xDim = [];
  19442. curve.cubicExtrema(p0[0], p1[0], p2[0], p3[0], xDim);
  19443. for (var i = 0; i < xDim.length; i++) {
  19444. xDim[i] = curve.cubicAt(p0[0], p1[0], p2[0], p3[0], xDim[i]);
  19445. }
  19446. var yDim = [];
  19447. curve.cubicExtrema(p0[1], p1[1], p2[1], p3[1], yDim);
  19448. for (var i = 0; i < yDim.length; i++) {
  19449. yDim[i] = curve.cubicAt(p0[1], p1[1], p2[1], p3[1], yDim[i]);
  19450. }
  19451. xDim.push(p0[0], p3[0]);
  19452. yDim.push(p0[1], p3[1]);
  19453. var left = Math.min.apply(null, xDim);
  19454. var right = Math.max.apply(null, xDim);
  19455. var top = Math.min.apply(null, yDim);
  19456. var bottom = Math.max.apply(null, yDim);
  19457. min[0] = left;
  19458. min[1] = top;
  19459. max[0] = right;
  19460. max[1] = bottom;
  19461. }
  19462. function computeQuadraticBezierBoundingBox(p0, p1, p2, min, max) {
  19463. var t1 = curve.quadraticExtremum(p0[0], p1[0], p2[0]);
  19464. var t2 = curve.quadraticExtremum(p0[1], p1[1], p2[1]);
  19465. t1 = Math.max(Math.min(t1, 1), 0);
  19466. t2 = Math.max(Math.min(t2, 1), 0);
  19467. var ct1 = 1 - t1;
  19468. var ct2 = 1 - t2;
  19469. var x1 = ct1 * ct1 * p0[0] + 2 * ct1 * t1 * p1[0] + t1 * t1 * p2[0];
  19470. var y1 = ct1 * ct1 * p0[1] + 2 * ct1 * t1 * p1[1] + t1 * t1 * p2[1];
  19471. var x2 = ct2 * ct2 * p0[0] + 2 * ct2 * t2 * p1[0] + t2 * t2 * p2[0];
  19472. var y2 = ct2 * ct2 * p0[1] + 2 * ct2 * t2 * p1[1] + t2 * t2 * p2[1];
  19473. min[0] = Math.min(p0[0], p2[0], x1, x2);
  19474. min[1] = Math.min(p0[1], p2[1], y1, y2);
  19475. max[0] = Math.max(p0[0], p2[0], x1, x2);
  19476. max[1] = Math.max(p0[1], p2[1], y1, y2);
  19477. }
  19478. var start = vec2.create();
  19479. var end = vec2.create();
  19480. var extremity = vec2.create();
  19481. var computeArcBoundingBox = function (x, y, r, startAngle, endAngle, anticlockwise, min, max) {
  19482. if (Math.abs(startAngle - endAngle) >= Math.PI * 2) {
  19483. min[0] = x - r;
  19484. min[1] = y - r;
  19485. max[0] = x + r;
  19486. max[1] = y + r;
  19487. return;
  19488. }
  19489. start[0] = Math.cos(startAngle) * r + x;
  19490. start[1] = Math.sin(startAngle) * r + y;
  19491. end[0] = Math.cos(endAngle) * r + x;
  19492. end[1] = Math.sin(endAngle) * r + y;
  19493. vec2.min(min, start, end);
  19494. vec2.max(max, start, end);
  19495. startAngle = startAngle % (Math.PI * 2);
  19496. if (startAngle < 0) {
  19497. startAngle = startAngle + Math.PI * 2;
  19498. }
  19499. endAngle = endAngle % (Math.PI * 2);
  19500. if (endAngle < 0) {
  19501. endAngle = endAngle + Math.PI * 2;
  19502. }
  19503. if (startAngle > endAngle && !anticlockwise) {
  19504. endAngle += Math.PI * 2;
  19505. } else if (startAngle < endAngle && anticlockwise) {
  19506. startAngle += Math.PI * 2;
  19507. }
  19508. if (anticlockwise) {
  19509. var tmp = endAngle;
  19510. endAngle = startAngle;
  19511. startAngle = tmp;
  19512. }
  19513. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  19514. if (angle > startAngle) {
  19515. extremity[0] = Math.cos(angle) * r + x;
  19516. extremity[1] = Math.sin(angle) * r + y;
  19517. vec2.min(min, extremity, min);
  19518. vec2.max(max, extremity, max);
  19519. }
  19520. }
  19521. };
  19522. computeBoundingBox.cubeBezier = computeCubeBezierBoundingBox;
  19523. computeBoundingBox.quadraticBezier = computeQuadraticBezierBoundingBox;
  19524. computeBoundingBox.arc = computeArcBoundingBox;
  19525. return computeBoundingBox;
  19526. });define('echarts/util/shape/Chain', [
  19527. 'require',
  19528. 'zrender/shape/Base',
  19529. './Icon',
  19530. 'zrender/shape/util/dashedLineTo',
  19531. 'zrender/tool/util',
  19532. 'zrender/tool/matrix'
  19533. ], function (require) {
  19534. var Base = require('zrender/shape/Base');
  19535. var IconShape = require('./Icon');
  19536. var dashedLineTo = require('zrender/shape/util/dashedLineTo');
  19537. var zrUtil = require('zrender/tool/util');
  19538. var matrix = require('zrender/tool/matrix');
  19539. function Chain(options) {
  19540. Base.call(this, options);
  19541. }
  19542. Chain.prototype = {
  19543. type: 'chain',
  19544. brush: function (ctx, isHighlight) {
  19545. var style = this.style;
  19546. if (isHighlight) {
  19547. style = this.getHighlightStyle(style, this.highlightStyle || {});
  19548. }
  19549. ctx.save();
  19550. this.setContext(ctx, style);
  19551. this.setTransform(ctx);
  19552. ctx.save();
  19553. ctx.beginPath();
  19554. this.buildLinePath(ctx, style);
  19555. ctx.stroke();
  19556. ctx.restore();
  19557. this.brushSymbol(ctx, style);
  19558. ctx.restore();
  19559. return;
  19560. },
  19561. buildLinePath: function (ctx, style) {
  19562. var x = style.x;
  19563. var y = style.y + 5;
  19564. var width = style.width;
  19565. var height = style.height / 2 - 10;
  19566. ctx.moveTo(x, y);
  19567. ctx.lineTo(x, y + height);
  19568. ctx.moveTo(x + width, y);
  19569. ctx.lineTo(x + width, y + height);
  19570. ctx.moveTo(x, y + height / 2);
  19571. if (!style.lineType || style.lineType == 'solid') {
  19572. ctx.lineTo(x + width, y + height / 2);
  19573. } else if (style.lineType == 'dashed' || style.lineType == 'dotted') {
  19574. var dashLength = (style.lineWidth || 1) * (style.lineType == 'dashed' ? 5 : 1);
  19575. dashedLineTo(ctx, x, y + height / 2, x + width, y + height / 2, dashLength);
  19576. }
  19577. },
  19578. brushSymbol: function (ctx, style) {
  19579. var y = style.y + style.height / 4;
  19580. ctx.save();
  19581. var chainPoint = style.chainPoint;
  19582. var curPoint;
  19583. for (var idx = 0, l = chainPoint.length; idx < l; idx++) {
  19584. curPoint = chainPoint[idx];
  19585. if (curPoint.symbol != 'none') {
  19586. ctx.beginPath();
  19587. var symbolSize = curPoint.symbolSize;
  19588. IconShape.prototype.buildPath(ctx, {
  19589. iconType: curPoint.symbol,
  19590. x: curPoint.x - symbolSize,
  19591. y: y - symbolSize,
  19592. width: symbolSize * 2,
  19593. height: symbolSize * 2,
  19594. n: curPoint.n
  19595. });
  19596. ctx.fillStyle = curPoint.isEmpty ? '#fff' : style.strokeColor;
  19597. ctx.closePath();
  19598. ctx.fill();
  19599. ctx.stroke();
  19600. }
  19601. if (curPoint.showLabel) {
  19602. ctx.font = curPoint.textFont;
  19603. ctx.fillStyle = curPoint.textColor;
  19604. ctx.textAlign = curPoint.textAlign;
  19605. ctx.textBaseline = curPoint.textBaseline;
  19606. if (curPoint.rotation) {
  19607. ctx.save();
  19608. this._updateTextTransform(ctx, curPoint.rotation);
  19609. ctx.fillText(curPoint.name, curPoint.textX, curPoint.textY);
  19610. ctx.restore();
  19611. } else {
  19612. ctx.fillText(curPoint.name, curPoint.textX, curPoint.textY);
  19613. }
  19614. }
  19615. }
  19616. ctx.restore();
  19617. },
  19618. _updateTextTransform: function (ctx, rotation) {
  19619. var _transform = matrix.create();
  19620. matrix.identity(_transform);
  19621. if (rotation[0] !== 0) {
  19622. var originX = rotation[1] || 0;
  19623. var originY = rotation[2] || 0;
  19624. if (originX || originY) {
  19625. matrix.translate(_transform, _transform, [
  19626. -originX,
  19627. -originY
  19628. ]);
  19629. }
  19630. matrix.rotate(_transform, _transform, rotation[0]);
  19631. if (originX || originY) {
  19632. matrix.translate(_transform, _transform, [
  19633. originX,
  19634. originY
  19635. ]);
  19636. }
  19637. }
  19638. ctx.transform.apply(ctx, _transform);
  19639. },
  19640. isCover: function (x, y) {
  19641. var rect = this.style;
  19642. if (x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height) {
  19643. return true;
  19644. } else {
  19645. return false;
  19646. }
  19647. }
  19648. };
  19649. zrUtil.inherits(Chain, Base);
  19650. return Chain;
  19651. });define('zrender/shape/Ring', [
  19652. 'require',
  19653. './Base',
  19654. '../tool/util'
  19655. ], function (require) {
  19656. var Base = require('./Base');
  19657. var Ring = function (options) {
  19658. Base.call(this, options);
  19659. };
  19660. Ring.prototype = {
  19661. type: 'ring',
  19662. buildPath: function (ctx, style) {
  19663. ctx.arc(style.x, style.y, style.r, 0, Math.PI * 2, false);
  19664. ctx.moveTo(style.x + style.r0, style.y);
  19665. ctx.arc(style.x, style.y, style.r0, 0, Math.PI * 2, true);
  19666. return;
  19667. },
  19668. getRect: function (style) {
  19669. if (style.__rect) {
  19670. return style.__rect;
  19671. }
  19672. var lineWidth;
  19673. if (style.brushType == 'stroke' || style.brushType == 'fill') {
  19674. lineWidth = style.lineWidth || 1;
  19675. } else {
  19676. lineWidth = 0;
  19677. }
  19678. style.__rect = {
  19679. x: Math.round(style.x - style.r - lineWidth / 2),
  19680. y: Math.round(style.y - style.r - lineWidth / 2),
  19681. width: style.r * 2 + lineWidth,
  19682. height: style.r * 2 + lineWidth
  19683. };
  19684. return style.__rect;
  19685. }
  19686. };
  19687. require('../tool/util').inherits(Ring, Base);
  19688. return Ring;
  19689. });define('echarts/component/axis', [
  19690. 'require',
  19691. './base',
  19692. 'zrender/shape/Line',
  19693. '../config',
  19694. '../util/ecData',
  19695. 'zrender/tool/util',
  19696. 'zrender/tool/color',
  19697. './categoryAxis',
  19698. './valueAxis',
  19699. '../component'
  19700. ], function (require) {
  19701. var Base = require('./base');
  19702. var LineShape = require('zrender/shape/Line');
  19703. var ecConfig = require('../config');
  19704. var ecData = require('../util/ecData');
  19705. var zrUtil = require('zrender/tool/util');
  19706. var zrColor = require('zrender/tool/color');
  19707. function Axis(ecTheme, messageCenter, zr, option, myChart, axisType) {
  19708. Base.call(this, ecTheme, messageCenter, zr, option, myChart);
  19709. this.axisType = axisType;
  19710. this._axisList = [];
  19711. this.refresh(option);
  19712. }
  19713. Axis.prototype = {
  19714. type: ecConfig.COMPONENT_TYPE_AXIS,
  19715. axisBase: {
  19716. _buildAxisLine: function () {
  19717. var lineWidth = this.option.axisLine.lineStyle.width;
  19718. var halfLineWidth = lineWidth / 2;
  19719. var axShape = {
  19720. _axisShape: 'axisLine',
  19721. zlevel: this.getZlevelBase(),
  19722. z: this.getZBase() + 3,
  19723. hoverable: false
  19724. };
  19725. var grid = this.grid;
  19726. switch (this.option.position) {
  19727. case 'left':
  19728. axShape.style = {
  19729. xStart: grid.getX() - halfLineWidth,
  19730. yStart: grid.getYend(),
  19731. xEnd: grid.getX() - halfLineWidth,
  19732. yEnd: grid.getY(),
  19733. lineCap: 'round'
  19734. };
  19735. break;
  19736. case 'right':
  19737. axShape.style = {
  19738. xStart: grid.getXend() + halfLineWidth,
  19739. yStart: grid.getYend(),
  19740. xEnd: grid.getXend() + halfLineWidth,
  19741. yEnd: grid.getY(),
  19742. lineCap: 'round'
  19743. };
  19744. break;
  19745. case 'bottom':
  19746. axShape.style = {
  19747. xStart: grid.getX(),
  19748. yStart: grid.getYend() + halfLineWidth,
  19749. xEnd: grid.getXend(),
  19750. yEnd: grid.getYend() + halfLineWidth,
  19751. lineCap: 'round'
  19752. };
  19753. break;
  19754. case 'top':
  19755. axShape.style = {
  19756. xStart: grid.getX(),
  19757. yStart: grid.getY() - halfLineWidth,
  19758. xEnd: grid.getXend(),
  19759. yEnd: grid.getY() - halfLineWidth,
  19760. lineCap: 'round'
  19761. };
  19762. break;
  19763. }
  19764. var style = axShape.style;
  19765. if (this.option.name !== '') {
  19766. style.text = this.option.name;
  19767. style.textPosition = this.option.nameLocation;
  19768. style.textFont = this.getFont(this.option.nameTextStyle);
  19769. if (this.option.nameTextStyle.align) {
  19770. style.textAlign = this.option.nameTextStyle.align;
  19771. }
  19772. if (this.option.nameTextStyle.baseline) {
  19773. style.textBaseline = this.option.nameTextStyle.baseline;
  19774. }
  19775. if (this.option.nameTextStyle.color) {
  19776. style.textColor = this.option.nameTextStyle.color;
  19777. }
  19778. }
  19779. style.strokeColor = this.option.axisLine.lineStyle.color;
  19780. style.lineWidth = lineWidth;
  19781. if (this.isHorizontal()) {
  19782. style.yStart = style.yEnd = this.subPixelOptimize(style.yEnd, lineWidth);
  19783. } else {
  19784. style.xStart = style.xEnd = this.subPixelOptimize(style.xEnd, lineWidth);
  19785. }
  19786. style.lineType = this.option.axisLine.lineStyle.type;
  19787. axShape = new LineShape(axShape);
  19788. this.shapeList.push(axShape);
  19789. },
  19790. _axisLabelClickable: function (clickable, axShape) {
  19791. if (clickable) {
  19792. ecData.pack(axShape, undefined, -1, undefined, -1, axShape.style.text);
  19793. axShape.hoverable = true;
  19794. axShape.clickable = true;
  19795. axShape.highlightStyle = {
  19796. color: zrColor.lift(axShape.style.color, 1),
  19797. brushType: 'fill'
  19798. };
  19799. return axShape;
  19800. } else {
  19801. return axShape;
  19802. }
  19803. },
  19804. refixAxisShape: function (zeroX, zeroY) {
  19805. if (!this.option.axisLine.onZero) {
  19806. return;
  19807. }
  19808. var tickLength;
  19809. if (this.isHorizontal() && zeroY != null) {
  19810. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  19811. if (this.shapeList[i]._axisShape === 'axisLine') {
  19812. this.shapeList[i].style.yStart = this.shapeList[i].style.yEnd = this.subPixelOptimize(zeroY, this.shapeList[i].stylelineWidth);
  19813. this.zr.modShape(this.shapeList[i].id);
  19814. } else if (this.shapeList[i]._axisShape === 'axisTick') {
  19815. tickLength = this.shapeList[i].style.yEnd - this.shapeList[i].style.yStart;
  19816. this.shapeList[i].style.yStart = zeroY - tickLength;
  19817. this.shapeList[i].style.yEnd = zeroY;
  19818. this.zr.modShape(this.shapeList[i].id);
  19819. }
  19820. }
  19821. }
  19822. if (!this.isHorizontal() && zeroX != null) {
  19823. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  19824. if (this.shapeList[i]._axisShape === 'axisLine') {
  19825. this.shapeList[i].style.xStart = this.shapeList[i].style.xEnd = this.subPixelOptimize(zeroX, this.shapeList[i].stylelineWidth);
  19826. this.zr.modShape(this.shapeList[i].id);
  19827. } else if (this.shapeList[i]._axisShape === 'axisTick') {
  19828. tickLength = this.shapeList[i].style.xEnd - this.shapeList[i].style.xStart;
  19829. this.shapeList[i].style.xStart = zeroX;
  19830. this.shapeList[i].style.xEnd = zeroX + tickLength;
  19831. this.zr.modShape(this.shapeList[i].id);
  19832. }
  19833. }
  19834. }
  19835. },
  19836. getPosition: function () {
  19837. return this.option.position;
  19838. },
  19839. isHorizontal: function () {
  19840. return this.option.position === 'bottom' || this.option.position === 'top';
  19841. }
  19842. },
  19843. reformOption: function (opt) {
  19844. if (!opt || opt instanceof Array && opt.length === 0) {
  19845. opt = [{ type: ecConfig.COMPONENT_TYPE_AXIS_VALUE }];
  19846. } else if (!(opt instanceof Array)) {
  19847. opt = [opt];
  19848. }
  19849. if (opt.length > 2) {
  19850. opt = [
  19851. opt[0],
  19852. opt[1]
  19853. ];
  19854. }
  19855. if (this.axisType === 'xAxis') {
  19856. if (!opt[0].position || opt[0].position != 'bottom' && opt[0].position != 'top') {
  19857. opt[0].position = 'bottom';
  19858. }
  19859. if (opt.length > 1) {
  19860. opt[1].position = opt[0].position === 'bottom' ? 'top' : 'bottom';
  19861. }
  19862. for (var i = 0, l = opt.length; i < l; i++) {
  19863. opt[i].type = opt[i].type || 'category';
  19864. opt[i].xAxisIndex = i;
  19865. opt[i].yAxisIndex = -1;
  19866. }
  19867. } else {
  19868. if (!opt[0].position || opt[0].position != 'left' && opt[0].position != 'right') {
  19869. opt[0].position = 'left';
  19870. }
  19871. if (opt.length > 1) {
  19872. opt[1].position = opt[0].position === 'left' ? 'right' : 'left';
  19873. }
  19874. for (var i = 0, l = opt.length; i < l; i++) {
  19875. opt[i].type = opt[i].type || 'value';
  19876. opt[i].xAxisIndex = -1;
  19877. opt[i].yAxisIndex = i;
  19878. }
  19879. }
  19880. return opt;
  19881. },
  19882. refresh: function (newOption) {
  19883. var axisOption;
  19884. if (newOption) {
  19885. this.option = newOption;
  19886. if (this.axisType === 'xAxis') {
  19887. this.option.xAxis = this.reformOption(newOption.xAxis);
  19888. axisOption = this.option.xAxis;
  19889. } else {
  19890. this.option.yAxis = this.reformOption(newOption.yAxis);
  19891. axisOption = this.option.yAxis;
  19892. }
  19893. this.series = newOption.series;
  19894. }
  19895. var CategoryAxis = require('./categoryAxis');
  19896. var ValueAxis = require('./valueAxis');
  19897. var len = Math.max(axisOption && axisOption.length || 0, this._axisList.length);
  19898. for (var i = 0; i < len; i++) {
  19899. if (this._axisList[i] && newOption && (!axisOption[i] || this._axisList[i].type != axisOption[i].type)) {
  19900. this._axisList[i].dispose && this._axisList[i].dispose();
  19901. this._axisList[i] = false;
  19902. }
  19903. if (this._axisList[i]) {
  19904. this._axisList[i].refresh && this._axisList[i].refresh(axisOption ? axisOption[i] : false, this.series);
  19905. } else if (axisOption && axisOption[i]) {
  19906. this._axisList[i] = axisOption[i].type === 'category' ? new CategoryAxis(this.ecTheme, this.messageCenter, this.zr, axisOption[i], this.myChart, this.axisBase) : new ValueAxis(this.ecTheme, this.messageCenter, this.zr, axisOption[i], this.myChart, this.axisBase, this.series);
  19907. }
  19908. }
  19909. },
  19910. getAxis: function (idx) {
  19911. return this._axisList[idx];
  19912. },
  19913. getAxisCount: function () {
  19914. return this._axisList.length;
  19915. },
  19916. clear: function () {
  19917. for (var i = 0, l = this._axisList.length; i < l; i++) {
  19918. this._axisList[i].dispose && this._axisList[i].dispose();
  19919. }
  19920. this._axisList = [];
  19921. }
  19922. };
  19923. zrUtil.inherits(Axis, Base);
  19924. require('../component').define('axis', Axis);
  19925. return Axis;
  19926. });define('echarts/component/grid', [
  19927. 'require',
  19928. './base',
  19929. 'zrender/shape/Rectangle',
  19930. '../config',
  19931. 'zrender/tool/util',
  19932. '../component'
  19933. ], function (require) {
  19934. var Base = require('./base');
  19935. var RectangleShape = require('zrender/shape/Rectangle');
  19936. var ecConfig = require('../config');
  19937. ecConfig.grid = {
  19938. zlevel: 0,
  19939. z: 0,
  19940. x: 80,
  19941. y: 60,
  19942. x2: 80,
  19943. y2: 60,
  19944. backgroundColor: 'rgba(0,0,0,0)',
  19945. borderWidth: 1,
  19946. borderColor: '#ccc'
  19947. };
  19948. var zrUtil = require('zrender/tool/util');
  19949. function Grid(ecTheme, messageCenter, zr, option, myChart) {
  19950. Base.call(this, ecTheme, messageCenter, zr, option, myChart);
  19951. this.refresh(option);
  19952. }
  19953. Grid.prototype = {
  19954. type: ecConfig.COMPONENT_TYPE_GRID,
  19955. getX: function () {
  19956. return this._x;
  19957. },
  19958. getY: function () {
  19959. return this._y;
  19960. },
  19961. getWidth: function () {
  19962. return this._width;
  19963. },
  19964. getHeight: function () {
  19965. return this._height;
  19966. },
  19967. getXend: function () {
  19968. return this._x + this._width;
  19969. },
  19970. getYend: function () {
  19971. return this._y + this._height;
  19972. },
  19973. getArea: function () {
  19974. return {
  19975. x: this._x,
  19976. y: this._y,
  19977. width: this._width,
  19978. height: this._height
  19979. };
  19980. },
  19981. getBbox: function () {
  19982. return [
  19983. [
  19984. this._x,
  19985. this._y
  19986. ],
  19987. [
  19988. this.getXend(),
  19989. this.getYend()
  19990. ]
  19991. ];
  19992. },
  19993. refixAxisShape: function (component) {
  19994. var zeroX;
  19995. var zeroY;
  19996. var axisList = component.xAxis._axisList.concat(component.yAxis ? component.yAxis._axisList : []);
  19997. var len = axisList.length;
  19998. var axis;
  19999. while (len--) {
  20000. axis = axisList[len];
  20001. if (axis.type == ecConfig.COMPONENT_TYPE_AXIS_VALUE && axis._min < 0 && axis._max >= 0) {
  20002. axis.isHorizontal() ? zeroX = axis.getCoord(0) : zeroY = axis.getCoord(0);
  20003. }
  20004. }
  20005. if (typeof zeroX != 'undefined' || typeof zeroY != 'undefined') {
  20006. len = axisList.length;
  20007. while (len--) {
  20008. axisList[len].refixAxisShape(zeroX, zeroY);
  20009. }
  20010. }
  20011. },
  20012. refresh: function (newOption) {
  20013. if (newOption || this._zrWidth != this.zr.getWidth() || this._zrHeight != this.zr.getHeight()) {
  20014. this.clear();
  20015. this.option = newOption || this.option;
  20016. this.option.grid = this.reformOption(this.option.grid);
  20017. var gridOption = this.option.grid;
  20018. this._zrWidth = this.zr.getWidth();
  20019. this._zrHeight = this.zr.getHeight();
  20020. this._x = this.parsePercent(gridOption.x, this._zrWidth);
  20021. this._y = this.parsePercent(gridOption.y, this._zrHeight);
  20022. var x2 = this.parsePercent(gridOption.x2, this._zrWidth);
  20023. var y2 = this.parsePercent(gridOption.y2, this._zrHeight);
  20024. if (typeof gridOption.width == 'undefined') {
  20025. this._width = this._zrWidth - this._x - x2;
  20026. } else {
  20027. this._width = this.parsePercent(gridOption.width, this._zrWidth);
  20028. }
  20029. this._width = this._width <= 0 ? 10 : this._width;
  20030. if (typeof gridOption.height == 'undefined') {
  20031. this._height = this._zrHeight - this._y - y2;
  20032. } else {
  20033. this._height = this.parsePercent(gridOption.height, this._zrHeight);
  20034. }
  20035. this._height = this._height <= 0 ? 10 : this._height;
  20036. this._x = this.subPixelOptimize(this._x, gridOption.borderWidth);
  20037. this._y = this.subPixelOptimize(this._y, gridOption.borderWidth);
  20038. this.shapeList.push(new RectangleShape({
  20039. zlevel: this.getZlevelBase(),
  20040. z: this.getZBase(),
  20041. hoverable: false,
  20042. style: {
  20043. x: this._x,
  20044. y: this._y,
  20045. width: this._width,
  20046. height: this._height,
  20047. brushType: gridOption.borderWidth > 0 ? 'both' : 'fill',
  20048. color: gridOption.backgroundColor,
  20049. strokeColor: gridOption.borderColor,
  20050. lineWidth: gridOption.borderWidth
  20051. }
  20052. }));
  20053. this.zr.addShape(this.shapeList[0]);
  20054. }
  20055. }
  20056. };
  20057. zrUtil.inherits(Grid, Base);
  20058. require('../component').define('grid', Grid);
  20059. return Grid;
  20060. });define('echarts/component/dataZoom', [
  20061. 'require',
  20062. './base',
  20063. 'zrender/shape/Rectangle',
  20064. 'zrender/shape/Polygon',
  20065. '../util/shape/Icon',
  20066. '../config',
  20067. '../util/date',
  20068. 'zrender/tool/util',
  20069. '../component'
  20070. ], function (require) {
  20071. var Base = require('./base');
  20072. var RectangleShape = require('zrender/shape/Rectangle');
  20073. var PolygonShape = require('zrender/shape/Polygon');
  20074. var IconShape = require('../util/shape/Icon');
  20075. var ecConfig = require('../config');
  20076. ecConfig.dataZoom = {
  20077. zlevel: 0,
  20078. z: 4,
  20079. show: false,
  20080. orient: 'horizontal',
  20081. backgroundColor: 'rgba(0,0,0,0)',
  20082. dataBackgroundColor: '#eee',
  20083. fillerColor: 'rgba(144,197,237,0.2)',
  20084. handleColor: 'rgba(70,130,180,0.8)',
  20085. handleSize: 8,
  20086. showDetail: true,
  20087. realtime: true
  20088. };
  20089. var ecDate = require('../util/date');
  20090. var zrUtil = require('zrender/tool/util');
  20091. function DataZoom(ecTheme, messageCenter, zr, option, myChart) {
  20092. Base.call(this, ecTheme, messageCenter, zr, option, myChart);
  20093. var self = this;
  20094. self._ondrift = function (dx, dy) {
  20095. return self.__ondrift(this, dx, dy);
  20096. };
  20097. self._ondragend = function () {
  20098. return self.__ondragend();
  20099. };
  20100. this._fillerSize = 30;
  20101. this._isSilence = false;
  20102. this._zoom = {};
  20103. this.option.dataZoom = this.reformOption(this.option.dataZoom);
  20104. this.zoomOption = this.option.dataZoom;
  20105. this._handleSize = this.zoomOption.handleSize;
  20106. if (!this.myChart.canvasSupported) {
  20107. this.zoomOption.realtime = false;
  20108. }
  20109. this._location = this._getLocation();
  20110. this._zoom = this._getZoom();
  20111. this._backupData();
  20112. if (this.option.dataZoom.show) {
  20113. this._buildShape();
  20114. }
  20115. this._syncData();
  20116. }
  20117. DataZoom.prototype = {
  20118. type: ecConfig.COMPONENT_TYPE_DATAZOOM,
  20119. _buildShape: function () {
  20120. this._buildBackground();
  20121. this._buildFiller();
  20122. this._buildHandle();
  20123. this._buildFrame();
  20124. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  20125. this.zr.addShape(this.shapeList[i]);
  20126. }
  20127. this._syncFrameShape();
  20128. },
  20129. _getLocation: function () {
  20130. var x;
  20131. var y;
  20132. var width;
  20133. var height;
  20134. var grid = this.component.grid;
  20135. if (this.zoomOption.orient == 'horizontal') {
  20136. width = this.zoomOption.width || grid.getWidth();
  20137. height = this.zoomOption.height || this._fillerSize;
  20138. x = this.zoomOption.x != null ? this.zoomOption.x : grid.getX();
  20139. y = this.zoomOption.y != null ? this.zoomOption.y : this.zr.getHeight() - height - 2;
  20140. } else {
  20141. width = this.zoomOption.width || this._fillerSize;
  20142. height = this.zoomOption.height || grid.getHeight();
  20143. x = this.zoomOption.x != null ? this.zoomOption.x : 2;
  20144. y = this.zoomOption.y != null ? this.zoomOption.y : grid.getY();
  20145. }
  20146. return {
  20147. x: x,
  20148. y: y,
  20149. width: width,
  20150. height: height
  20151. };
  20152. },
  20153. _getZoom: function () {
  20154. var series = this.option.series;
  20155. var xAxis = this.option.xAxis;
  20156. if (xAxis && !(xAxis instanceof Array)) {
  20157. xAxis = [xAxis];
  20158. this.option.xAxis = xAxis;
  20159. }
  20160. var yAxis = this.option.yAxis;
  20161. if (yAxis && !(yAxis instanceof Array)) {
  20162. yAxis = [yAxis];
  20163. this.option.yAxis = yAxis;
  20164. }
  20165. var zoomSeriesIndex = [];
  20166. var xAxisIndex;
  20167. var yAxisIndex;
  20168. var zOptIdx = this.zoomOption.xAxisIndex;
  20169. if (xAxis && zOptIdx == null) {
  20170. xAxisIndex = [];
  20171. for (var i = 0, l = xAxis.length; i < l; i++) {
  20172. if (xAxis[i].type == 'category' || xAxis[i].type == null) {
  20173. xAxisIndex.push(i);
  20174. }
  20175. }
  20176. } else {
  20177. if (zOptIdx instanceof Array) {
  20178. xAxisIndex = zOptIdx;
  20179. } else if (zOptIdx != null) {
  20180. xAxisIndex = [zOptIdx];
  20181. } else {
  20182. xAxisIndex = [];
  20183. }
  20184. }
  20185. zOptIdx = this.zoomOption.yAxisIndex;
  20186. if (yAxis && zOptIdx == null) {
  20187. yAxisIndex = [];
  20188. for (var i = 0, l = yAxis.length; i < l; i++) {
  20189. if (yAxis[i].type == 'category') {
  20190. yAxisIndex.push(i);
  20191. }
  20192. }
  20193. } else {
  20194. if (zOptIdx instanceof Array) {
  20195. yAxisIndex = zOptIdx;
  20196. } else if (zOptIdx != null) {
  20197. yAxisIndex = [zOptIdx];
  20198. } else {
  20199. yAxisIndex = [];
  20200. }
  20201. }
  20202. var serie;
  20203. for (var i = 0, l = series.length; i < l; i++) {
  20204. serie = series[i];
  20205. if (serie.type != ecConfig.CHART_TYPE_LINE && serie.type != ecConfig.CHART_TYPE_BAR && serie.type != ecConfig.CHART_TYPE_SCATTER && serie.type != ecConfig.CHART_TYPE_K) {
  20206. continue;
  20207. }
  20208. for (var j = 0, k = xAxisIndex.length; j < k; j++) {
  20209. if (xAxisIndex[j] == (serie.xAxisIndex || 0)) {
  20210. zoomSeriesIndex.push(i);
  20211. break;
  20212. }
  20213. }
  20214. for (var j = 0, k = yAxisIndex.length; j < k; j++) {
  20215. if (yAxisIndex[j] == (serie.yAxisIndex || 0)) {
  20216. zoomSeriesIndex.push(i);
  20217. break;
  20218. }
  20219. }
  20220. if (this.zoomOption.xAxisIndex == null && this.zoomOption.yAxisIndex == null && serie.data && this.getDataFromOption(serie.data[0]) instanceof Array && (serie.type == ecConfig.CHART_TYPE_SCATTER || serie.type == ecConfig.CHART_TYPE_LINE || serie.type == ecConfig.CHART_TYPE_BAR)) {
  20221. zoomSeriesIndex.push(i);
  20222. }
  20223. }
  20224. var start = this._zoom.start != null ? this._zoom.start : this.zoomOption.start != null ? this.zoomOption.start : 0;
  20225. var end = this._zoom.end != null ? this._zoom.end : this.zoomOption.end != null ? this.zoomOption.end : 100;
  20226. if (start > end) {
  20227. start = start + end;
  20228. end = start - end;
  20229. start = start - end;
  20230. }
  20231. var size = Math.round((end - start) / 100 * (this.zoomOption.orient == 'horizontal' ? this._location.width : this._location.height));
  20232. return {
  20233. start: start,
  20234. end: end,
  20235. start2: 0,
  20236. end2: 100,
  20237. size: size,
  20238. xAxisIndex: xAxisIndex,
  20239. yAxisIndex: yAxisIndex,
  20240. seriesIndex: zoomSeriesIndex,
  20241. scatterMap: this._zoom.scatterMap || {}
  20242. };
  20243. },
  20244. _backupData: function () {
  20245. this._originalData = {
  20246. xAxis: {},
  20247. yAxis: {},
  20248. series: {}
  20249. };
  20250. var xAxis = this.option.xAxis;
  20251. var xAxisIndex = this._zoom.xAxisIndex;
  20252. for (var i = 0, l = xAxisIndex.length; i < l; i++) {
  20253. this._originalData.xAxis[xAxisIndex[i]] = xAxis[xAxisIndex[i]].data;
  20254. }
  20255. var yAxis = this.option.yAxis;
  20256. var yAxisIndex = this._zoom.yAxisIndex;
  20257. for (var i = 0, l = yAxisIndex.length; i < l; i++) {
  20258. this._originalData.yAxis[yAxisIndex[i]] = yAxis[yAxisIndex[i]].data;
  20259. }
  20260. var series = this.option.series;
  20261. var seriesIndex = this._zoom.seriesIndex;
  20262. var serie;
  20263. for (var i = 0, l = seriesIndex.length; i < l; i++) {
  20264. serie = series[seriesIndex[i]];
  20265. this._originalData.series[seriesIndex[i]] = serie.data;
  20266. if (serie.data && this.getDataFromOption(serie.data[0]) instanceof Array && (serie.type == ecConfig.CHART_TYPE_SCATTER || serie.type == ecConfig.CHART_TYPE_LINE || serie.type == ecConfig.CHART_TYPE_BAR)) {
  20267. this._backupScale();
  20268. this._calculScatterMap(seriesIndex[i]);
  20269. }
  20270. }
  20271. },
  20272. _calculScatterMap: function (seriesIndex) {
  20273. this._zoom.scatterMap = this._zoom.scatterMap || {};
  20274. this._zoom.scatterMap[seriesIndex] = this._zoom.scatterMap[seriesIndex] || {};
  20275. var componentLibrary = require('../component');
  20276. var Axis = componentLibrary.get('axis');
  20277. var axisOption = zrUtil.clone(this.option.xAxis);
  20278. if (axisOption[0].type == 'category') {
  20279. axisOption[0].type = 'value';
  20280. }
  20281. if (axisOption[1] && axisOption[1].type == 'category') {
  20282. axisOption[1].type = 'value';
  20283. }
  20284. var vAxis = new Axis(this.ecTheme, null, false, {
  20285. xAxis: axisOption,
  20286. series: this.option.series
  20287. }, this, 'xAxis');
  20288. var axisIndex = this.option.series[seriesIndex].xAxisIndex || 0;
  20289. this._zoom.scatterMap[seriesIndex].x = vAxis.getAxis(axisIndex).getExtremum();
  20290. vAxis.dispose();
  20291. axisOption = zrUtil.clone(this.option.yAxis);
  20292. if (axisOption[0].type == 'category') {
  20293. axisOption[0].type = 'value';
  20294. }
  20295. if (axisOption[1] && axisOption[1].type == 'category') {
  20296. axisOption[1].type = 'value';
  20297. }
  20298. vAxis = new Axis(this.ecTheme, null, false, {
  20299. yAxis: axisOption,
  20300. series: this.option.series
  20301. }, this, 'yAxis');
  20302. axisIndex = this.option.series[seriesIndex].yAxisIndex || 0;
  20303. this._zoom.scatterMap[seriesIndex].y = vAxis.getAxis(axisIndex).getExtremum();
  20304. vAxis.dispose();
  20305. },
  20306. _buildBackground: function () {
  20307. var width = this._location.width;
  20308. var height = this._location.height;
  20309. this.shapeList.push(new RectangleShape({
  20310. zlevel: this.getZlevelBase(),
  20311. z: this.getZBase(),
  20312. hoverable: false,
  20313. style: {
  20314. x: this._location.x,
  20315. y: this._location.y,
  20316. width: width,
  20317. height: height,
  20318. color: this.zoomOption.backgroundColor
  20319. }
  20320. }));
  20321. var maxLength = 0;
  20322. var xAxis = this._originalData.xAxis;
  20323. var xAxisIndex = this._zoom.xAxisIndex;
  20324. for (var i = 0, l = xAxisIndex.length; i < l; i++) {
  20325. maxLength = Math.max(maxLength, xAxis[xAxisIndex[i]].length);
  20326. }
  20327. var yAxis = this._originalData.yAxis;
  20328. var yAxisIndex = this._zoom.yAxisIndex;
  20329. for (var i = 0, l = yAxisIndex.length; i < l; i++) {
  20330. maxLength = Math.max(maxLength, yAxis[yAxisIndex[i]].length);
  20331. }
  20332. var seriesIndex = this._zoom.seriesIndex[0];
  20333. var data = this._originalData.series[seriesIndex];
  20334. var maxValue = Number.MIN_VALUE;
  20335. var minValue = Number.MAX_VALUE;
  20336. var value;
  20337. for (var i = 0, l = data.length; i < l; i++) {
  20338. value = this.getDataFromOption(data[i], 0);
  20339. if (this.option.series[seriesIndex].type == ecConfig.CHART_TYPE_K) {
  20340. value = value[1];
  20341. }
  20342. if (isNaN(value)) {
  20343. value = 0;
  20344. }
  20345. maxValue = Math.max(maxValue, value);
  20346. minValue = Math.min(minValue, value);
  20347. }
  20348. var valueRange = maxValue - minValue;
  20349. var pointList = [];
  20350. var x = width / (maxLength - (maxLength > 1 ? 1 : 0));
  20351. var y = height / (maxLength - (maxLength > 1 ? 1 : 0));
  20352. var step = 1;
  20353. if (this.zoomOption.orient == 'horizontal' && x < 1) {
  20354. step = Math.floor(maxLength * 3 / width);
  20355. } else if (this.zoomOption.orient == 'vertical' && y < 1) {
  20356. step = Math.floor(maxLength * 3 / height);
  20357. }
  20358. for (var i = 0, l = maxLength; i < l; i += step) {
  20359. value = this.getDataFromOption(data[i], 0);
  20360. if (this.option.series[seriesIndex].type == ecConfig.CHART_TYPE_K) {
  20361. value = value[1];
  20362. }
  20363. if (isNaN(value)) {
  20364. value = 0;
  20365. }
  20366. if (this.zoomOption.orient == 'horizontal') {
  20367. pointList.push([
  20368. this._location.x + x * i,
  20369. this._location.y + height - 1 - Math.round((value - minValue) / valueRange * (height - 10))
  20370. ]);
  20371. } else {
  20372. pointList.push([
  20373. this._location.x + 1 + Math.round((value - minValue) / valueRange * (width - 10)),
  20374. this._location.y + y * (l - i - 1)
  20375. ]);
  20376. }
  20377. }
  20378. if (this.zoomOption.orient == 'horizontal') {
  20379. pointList.push([
  20380. this._location.x + width,
  20381. this._location.y + height
  20382. ]);
  20383. pointList.push([
  20384. this._location.x,
  20385. this._location.y + height
  20386. ]);
  20387. } else {
  20388. pointList.push([
  20389. this._location.x,
  20390. this._location.y
  20391. ]);
  20392. pointList.push([
  20393. this._location.x,
  20394. this._location.y + height
  20395. ]);
  20396. }
  20397. this.shapeList.push(new PolygonShape({
  20398. zlevel: this.getZlevelBase(),
  20399. z: this.getZBase(),
  20400. style: {
  20401. pointList: pointList,
  20402. color: this.zoomOption.dataBackgroundColor
  20403. },
  20404. hoverable: false
  20405. }));
  20406. },
  20407. _buildFiller: function () {
  20408. this._fillerShae = {
  20409. zlevel: this.getZlevelBase(),
  20410. z: this.getZBase(),
  20411. draggable: true,
  20412. ondrift: this._ondrift,
  20413. ondragend: this._ondragend,
  20414. _type: 'filler'
  20415. };
  20416. if (this.zoomOption.orient == 'horizontal') {
  20417. this._fillerShae.style = {
  20418. x: this._location.x + Math.round(this._zoom.start / 100 * this._location.width) + this._handleSize,
  20419. y: this._location.y,
  20420. width: this._zoom.size - this._handleSize * 2,
  20421. height: this._location.height,
  20422. color: this.zoomOption.fillerColor,
  20423. text: ':::',
  20424. textPosition: 'inside'
  20425. };
  20426. } else {
  20427. this._fillerShae.style = {
  20428. x: this._location.x,
  20429. y: this._location.y + Math.round(this._zoom.start / 100 * this._location.height) + this._handleSize,
  20430. width: this._location.width,
  20431. height: this._zoom.size - this._handleSize * 2,
  20432. color: this.zoomOption.fillerColor,
  20433. text: '::',
  20434. textPosition: 'inside'
  20435. };
  20436. }
  20437. this._fillerShae.highlightStyle = {
  20438. brushType: 'fill',
  20439. color: 'rgba(0,0,0,0)'
  20440. };
  20441. this._fillerShae = new RectangleShape(this._fillerShae);
  20442. this.shapeList.push(this._fillerShae);
  20443. },
  20444. _buildHandle: function () {
  20445. var detail = this.zoomOption.showDetail ? this._getDetail() : {
  20446. start: '',
  20447. end: ''
  20448. };
  20449. this._startShape = {
  20450. zlevel: this.getZlevelBase(),
  20451. z: this.getZBase(),
  20452. draggable: true,
  20453. style: {
  20454. iconType: 'rectangle',
  20455. x: this._location.x,
  20456. y: this._location.y,
  20457. width: this._handleSize,
  20458. height: this._handleSize,
  20459. color: this.zoomOption.handleColor,
  20460. text: '=',
  20461. textPosition: 'inside'
  20462. },
  20463. highlightStyle: {
  20464. text: detail.start,
  20465. brushType: 'fill',
  20466. textPosition: 'left'
  20467. },
  20468. ondrift: this._ondrift,
  20469. ondragend: this._ondragend
  20470. };
  20471. if (this.zoomOption.orient == 'horizontal') {
  20472. this._startShape.style.height = this._location.height;
  20473. this._endShape = zrUtil.clone(this._startShape);
  20474. this._startShape.style.x = this._fillerShae.style.x - this._handleSize, this._endShape.style.x = this._fillerShae.style.x + this._fillerShae.style.width;
  20475. this._endShape.highlightStyle.text = detail.end;
  20476. this._endShape.highlightStyle.textPosition = 'right';
  20477. } else {
  20478. this._startShape.style.width = this._location.width;
  20479. this._endShape = zrUtil.clone(this._startShape);
  20480. this._startShape.style.y = this._fillerShae.style.y + this._fillerShae.style.height;
  20481. this._startShape.highlightStyle.textPosition = 'bottom';
  20482. this._endShape.style.y = this._fillerShae.style.y - this._handleSize;
  20483. this._endShape.highlightStyle.text = detail.end;
  20484. this._endShape.highlightStyle.textPosition = 'top';
  20485. }
  20486. this._startShape = new IconShape(this._startShape);
  20487. this._endShape = new IconShape(this._endShape);
  20488. this.shapeList.push(this._startShape);
  20489. this.shapeList.push(this._endShape);
  20490. },
  20491. _buildFrame: function () {
  20492. var x = this.subPixelOptimize(this._location.x, 1);
  20493. var y = this.subPixelOptimize(this._location.y, 1);
  20494. this._startFrameShape = {
  20495. zlevel: this.getZlevelBase(),
  20496. z: this.getZBase(),
  20497. hoverable: false,
  20498. style: {
  20499. x: x,
  20500. y: y,
  20501. width: this._location.width - (x > this._location.x ? 1 : 0),
  20502. height: this._location.height - (y > this._location.y ? 1 : 0),
  20503. lineWidth: 1,
  20504. brushType: 'stroke',
  20505. strokeColor: this.zoomOption.handleColor
  20506. }
  20507. };
  20508. this._endFrameShape = zrUtil.clone(this._startFrameShape);
  20509. this._startFrameShape = new RectangleShape(this._startFrameShape);
  20510. this._endFrameShape = new RectangleShape(this._endFrameShape);
  20511. this.shapeList.push(this._startFrameShape);
  20512. this.shapeList.push(this._endFrameShape);
  20513. return;
  20514. },
  20515. _syncHandleShape: function () {
  20516. if (this.zoomOption.orient == 'horizontal') {
  20517. this._startShape.style.x = this._fillerShae.style.x - this._handleSize;
  20518. this._endShape.style.x = this._fillerShae.style.x + this._fillerShae.style.width;
  20519. this._zoom.start = (this._startShape.style.x - this._location.x) / this._location.width * 100;
  20520. this._zoom.end = (this._endShape.style.x + this._handleSize - this._location.x) / this._location.width * 100;
  20521. } else {
  20522. this._startShape.style.y = this._fillerShae.style.y + this._fillerShae.style.height;
  20523. this._endShape.style.y = this._fillerShae.style.y - this._handleSize;
  20524. this._zoom.start = (this._location.y + this._location.height - this._startShape.style.y) / this._location.height * 100;
  20525. this._zoom.end = (this._location.y + this._location.height - this._endShape.style.y - this._handleSize) / this._location.height * 100;
  20526. }
  20527. this.zr.modShape(this._startShape.id);
  20528. this.zr.modShape(this._endShape.id);
  20529. this._syncFrameShape();
  20530. this.zr.refreshNextFrame();
  20531. },
  20532. _syncFillerShape: function () {
  20533. var a;
  20534. var b;
  20535. if (this.zoomOption.orient == 'horizontal') {
  20536. a = this._startShape.style.x;
  20537. b = this._endShape.style.x;
  20538. this._fillerShae.style.x = Math.min(a, b) + this._handleSize;
  20539. this._fillerShae.style.width = Math.abs(a - b) - this._handleSize;
  20540. this._zoom.start = (Math.min(a, b) - this._location.x) / this._location.width * 100;
  20541. this._zoom.end = (Math.max(a, b) + this._handleSize - this._location.x) / this._location.width * 100;
  20542. } else {
  20543. a = this._startShape.style.y;
  20544. b = this._endShape.style.y;
  20545. this._fillerShae.style.y = Math.min(a, b) + this._handleSize;
  20546. this._fillerShae.style.height = Math.abs(a - b) - this._handleSize;
  20547. this._zoom.start = (this._location.y + this._location.height - Math.max(a, b)) / this._location.height * 100;
  20548. this._zoom.end = (this._location.y + this._location.height - Math.min(a, b) - this._handleSize) / this._location.height * 100;
  20549. }
  20550. this.zr.modShape(this._fillerShae.id);
  20551. this._syncFrameShape();
  20552. this.zr.refreshNextFrame();
  20553. },
  20554. _syncFrameShape: function () {
  20555. if (this.zoomOption.orient == 'horizontal') {
  20556. this._startFrameShape.style.width = this._fillerShae.style.x - this._location.x;
  20557. this._endFrameShape.style.x = this._fillerShae.style.x + this._fillerShae.style.width;
  20558. this._endFrameShape.style.width = this._location.x + this._location.width - this._endFrameShape.style.x;
  20559. } else {
  20560. this._startFrameShape.style.y = this._fillerShae.style.y + this._fillerShae.style.height;
  20561. this._startFrameShape.style.height = this._location.y + this._location.height - this._startFrameShape.style.y;
  20562. this._endFrameShape.style.height = this._fillerShae.style.y - this._location.y;
  20563. }
  20564. this.zr.modShape(this._startFrameShape.id);
  20565. this.zr.modShape(this._endFrameShape.id);
  20566. },
  20567. _syncShape: function () {
  20568. if (!this.zoomOption.show) {
  20569. return;
  20570. }
  20571. if (this.zoomOption.orient == 'horizontal') {
  20572. this._startShape.style.x = this._location.x + this._zoom.start / 100 * this._location.width;
  20573. this._endShape.style.x = this._location.x + this._zoom.end / 100 * this._location.width - this._handleSize;
  20574. this._fillerShae.style.x = this._startShape.style.x + this._handleSize;
  20575. this._fillerShae.style.width = this._endShape.style.x - this._startShape.style.x - this._handleSize;
  20576. } else {
  20577. this._startShape.style.y = this._location.y + this._location.height - this._zoom.start / 100 * this._location.height;
  20578. this._endShape.style.y = this._location.y + this._location.height - this._zoom.end / 100 * this._location.height - this._handleSize;
  20579. this._fillerShae.style.y = this._endShape.style.y + this._handleSize;
  20580. this._fillerShae.style.height = this._startShape.style.y - this._endShape.style.y - this._handleSize;
  20581. }
  20582. this.zr.modShape(this._startShape.id);
  20583. this.zr.modShape(this._endShape.id);
  20584. this.zr.modShape(this._fillerShae.id);
  20585. this._syncFrameShape();
  20586. this.zr.refresh();
  20587. },
  20588. _syncData: function (dispatchNow) {
  20589. var target;
  20590. var start;
  20591. var end;
  20592. var length;
  20593. var data;
  20594. for (var key in this._originalData) {
  20595. target = this._originalData[key];
  20596. for (var idx in target) {
  20597. data = target[idx];
  20598. if (data == null) {
  20599. continue;
  20600. }
  20601. length = data.length;
  20602. start = Math.floor(this._zoom.start / 100 * length);
  20603. end = Math.ceil(this._zoom.end / 100 * length);
  20604. if (!(this.getDataFromOption(data[0]) instanceof Array) || this.option[key][idx].type == ecConfig.CHART_TYPE_K) {
  20605. this.option[key][idx].data = data.slice(start, end);
  20606. } else {
  20607. this._setScale();
  20608. this.option[key][idx].data = this._synScatterData(idx, data);
  20609. }
  20610. }
  20611. }
  20612. if (!this._isSilence && (this.zoomOption.realtime || dispatchNow)) {
  20613. this.messageCenter.dispatch(ecConfig.EVENT.DATA_ZOOM, null, { zoom: this._zoom }, this.myChart);
  20614. }
  20615. },
  20616. _synScatterData: function (seriesIndex, data) {
  20617. if (this._zoom.start === 0 && this._zoom.end == 100 && this._zoom.start2 === 0 && this._zoom.end2 == 100) {
  20618. return data;
  20619. }
  20620. var newData = [];
  20621. var scale = this._zoom.scatterMap[seriesIndex];
  20622. var total;
  20623. var xStart;
  20624. var xEnd;
  20625. var yStart;
  20626. var yEnd;
  20627. if (this.zoomOption.orient == 'horizontal') {
  20628. total = scale.x.max - scale.x.min;
  20629. xStart = this._zoom.start / 100 * total + scale.x.min;
  20630. xEnd = this._zoom.end / 100 * total + scale.x.min;
  20631. total = scale.y.max - scale.y.min;
  20632. yStart = this._zoom.start2 / 100 * total + scale.y.min;
  20633. yEnd = this._zoom.end2 / 100 * total + scale.y.min;
  20634. } else {
  20635. total = scale.x.max - scale.x.min;
  20636. xStart = this._zoom.start2 / 100 * total + scale.x.min;
  20637. xEnd = this._zoom.end2 / 100 * total + scale.x.min;
  20638. total = scale.y.max - scale.y.min;
  20639. yStart = this._zoom.start / 100 * total + scale.y.min;
  20640. yEnd = this._zoom.end / 100 * total + scale.y.min;
  20641. }
  20642. var dataMappingMethods;
  20643. if (dataMappingMethods = scale.x.dataMappingMethods) {
  20644. xStart = dataMappingMethods.coord2Value(xStart);
  20645. xEnd = dataMappingMethods.coord2Value(xEnd);
  20646. }
  20647. if (dataMappingMethods = scale.y.dataMappingMethods) {
  20648. yStart = dataMappingMethods.coord2Value(yStart);
  20649. yEnd = dataMappingMethods.coord2Value(yEnd);
  20650. }
  20651. var value;
  20652. for (var i = 0, l = data.length; i < l; i++) {
  20653. value = data[i].value || data[i];
  20654. if (value[0] >= xStart && value[0] <= xEnd && value[1] >= yStart && value[1] <= yEnd) {
  20655. newData.push(data[i]);
  20656. }
  20657. }
  20658. return newData;
  20659. },
  20660. _setScale: function () {
  20661. var needScale = this._zoom.start !== 0 || this._zoom.end !== 100 || this._zoom.start2 !== 0 || this._zoom.end2 !== 100;
  20662. var axis = {
  20663. xAxis: this.option.xAxis,
  20664. yAxis: this.option.yAxis
  20665. };
  20666. for (var key in axis) {
  20667. for (var i = 0, l = axis[key].length; i < l; i++) {
  20668. axis[key][i].scale = needScale || axis[key][i]._scale;
  20669. }
  20670. }
  20671. },
  20672. _backupScale: function () {
  20673. var axis = {
  20674. xAxis: this.option.xAxis,
  20675. yAxis: this.option.yAxis
  20676. };
  20677. for (var key in axis) {
  20678. for (var i = 0, l = axis[key].length; i < l; i++) {
  20679. axis[key][i]._scale = axis[key][i].scale;
  20680. }
  20681. }
  20682. },
  20683. _getDetail: function () {
  20684. var key = [
  20685. 'xAxis',
  20686. 'yAxis'
  20687. ];
  20688. for (var i = 0, l = key.length; i < l; i++) {
  20689. var target = this._originalData[key[i]];
  20690. for (var idx in target) {
  20691. var data = target[idx];
  20692. if (data == null) {
  20693. continue;
  20694. }
  20695. var length = data.length;
  20696. var start = Math.floor(this._zoom.start / 100 * length);
  20697. var end = Math.ceil(this._zoom.end / 100 * length);
  20698. end -= end > 0 ? 1 : 0;
  20699. return {
  20700. start: this.getDataFromOption(data[start]),
  20701. end: this.getDataFromOption(data[end])
  20702. };
  20703. }
  20704. }
  20705. key = this.zoomOption.orient == 'horizontal' ? 'xAxis' : 'yAxis';
  20706. var seriesIndex = this._zoom.seriesIndex[0];
  20707. var axisIndex = this.option.series[seriesIndex][key + 'Index'] || 0;
  20708. var axisType = this.option[key][axisIndex].type;
  20709. var min = this._zoom.scatterMap[seriesIndex][key.charAt(0)].min;
  20710. var max = this._zoom.scatterMap[seriesIndex][key.charAt(0)].max;
  20711. var gap = max - min;
  20712. if (axisType == 'value') {
  20713. return {
  20714. start: min + gap * this._zoom.start / 100,
  20715. end: min + gap * this._zoom.end / 100
  20716. };
  20717. } else if (axisType == 'time') {
  20718. max = min + gap * this._zoom.end / 100;
  20719. min = min + gap * this._zoom.start / 100;
  20720. var formatter = ecDate.getAutoFormatter(min, max).formatter;
  20721. return {
  20722. start: ecDate.format(formatter, min),
  20723. end: ecDate.format(formatter, max)
  20724. };
  20725. }
  20726. return {
  20727. start: '',
  20728. end: ''
  20729. };
  20730. },
  20731. __ondrift: function (shape, dx, dy) {
  20732. if (this.zoomOption.zoomLock) {
  20733. shape = this._fillerShae;
  20734. }
  20735. var detailSize = shape._type == 'filler' ? this._handleSize : 0;
  20736. if (this.zoomOption.orient == 'horizontal') {
  20737. if (shape.style.x + dx - detailSize <= this._location.x) {
  20738. shape.style.x = this._location.x + detailSize;
  20739. } else if (shape.style.x + dx + shape.style.width + detailSize >= this._location.x + this._location.width) {
  20740. shape.style.x = this._location.x + this._location.width - shape.style.width - detailSize;
  20741. } else {
  20742. shape.style.x += dx;
  20743. }
  20744. } else {
  20745. if (shape.style.y + dy - detailSize <= this._location.y) {
  20746. shape.style.y = this._location.y + detailSize;
  20747. } else if (shape.style.y + dy + shape.style.height + detailSize >= this._location.y + this._location.height) {
  20748. shape.style.y = this._location.y + this._location.height - shape.style.height - detailSize;
  20749. } else {
  20750. shape.style.y += dy;
  20751. }
  20752. }
  20753. if (shape._type == 'filler') {
  20754. this._syncHandleShape();
  20755. } else {
  20756. this._syncFillerShape();
  20757. }
  20758. if (this.zoomOption.realtime) {
  20759. this._syncData();
  20760. }
  20761. if (this.zoomOption.showDetail) {
  20762. var detail = this._getDetail();
  20763. this._startShape.style.text = this._startShape.highlightStyle.text = detail.start;
  20764. this._endShape.style.text = this._endShape.highlightStyle.text = detail.end;
  20765. this._startShape.style.textPosition = this._startShape.highlightStyle.textPosition;
  20766. this._endShape.style.textPosition = this._endShape.highlightStyle.textPosition;
  20767. }
  20768. return true;
  20769. },
  20770. __ondragend: function () {
  20771. if (this.zoomOption.showDetail) {
  20772. this._startShape.style.text = this._endShape.style.text = '=';
  20773. this._startShape.style.textPosition = this._endShape.style.textPosition = 'inside';
  20774. this.zr.modShape(this._startShape.id);
  20775. this.zr.modShape(this._endShape.id);
  20776. this.zr.refreshNextFrame();
  20777. }
  20778. this.isDragend = true;
  20779. },
  20780. ondragend: function (param, status) {
  20781. if (!this.isDragend || !param.target) {
  20782. return;
  20783. }
  20784. !this.zoomOption.realtime && this._syncData();
  20785. status.dragOut = true;
  20786. status.dragIn = true;
  20787. if (!this._isSilence && !this.zoomOption.realtime) {
  20788. this.messageCenter.dispatch(ecConfig.EVENT.DATA_ZOOM, null, { zoom: this._zoom }, this.myChart);
  20789. }
  20790. status.needRefresh = false;
  20791. this.isDragend = false;
  20792. return;
  20793. },
  20794. ondataZoom: function (param, status) {
  20795. status.needRefresh = true;
  20796. return;
  20797. },
  20798. absoluteZoom: function (param) {
  20799. this._zoom.start = param.start;
  20800. this._zoom.end = param.end;
  20801. this._zoom.start2 = param.start2;
  20802. this._zoom.end2 = param.end2;
  20803. this._syncShape();
  20804. this._syncData(true);
  20805. return;
  20806. },
  20807. rectZoom: function (param) {
  20808. if (!param) {
  20809. this._zoom.start = this._zoom.start2 = 0;
  20810. this._zoom.end = this._zoom.end2 = 100;
  20811. this._syncShape();
  20812. this._syncData(true);
  20813. return this._zoom;
  20814. }
  20815. var gridArea = this.component.grid.getArea();
  20816. var rect = {
  20817. x: param.x,
  20818. y: param.y,
  20819. width: param.width,
  20820. height: param.height
  20821. };
  20822. if (rect.width < 0) {
  20823. rect.x += rect.width;
  20824. rect.width = -rect.width;
  20825. }
  20826. if (rect.height < 0) {
  20827. rect.y += rect.height;
  20828. rect.height = -rect.height;
  20829. }
  20830. if (rect.x > gridArea.x + gridArea.width || rect.y > gridArea.y + gridArea.height) {
  20831. return false;
  20832. }
  20833. if (rect.x < gridArea.x) {
  20834. rect.x = gridArea.x;
  20835. }
  20836. if (rect.x + rect.width > gridArea.x + gridArea.width) {
  20837. rect.width = gridArea.x + gridArea.width - rect.x;
  20838. }
  20839. if (rect.y + rect.height > gridArea.y + gridArea.height) {
  20840. rect.height = gridArea.y + gridArea.height - rect.y;
  20841. }
  20842. var total;
  20843. var sdx = (rect.x - gridArea.x) / gridArea.width;
  20844. var edx = 1 - (rect.x + rect.width - gridArea.x) / gridArea.width;
  20845. var sdy = 1 - (rect.y + rect.height - gridArea.y) / gridArea.height;
  20846. var edy = (rect.y - gridArea.y) / gridArea.height;
  20847. if (this.zoomOption.orient == 'horizontal') {
  20848. total = this._zoom.end - this._zoom.start;
  20849. this._zoom.start += total * sdx;
  20850. this._zoom.end -= total * edx;
  20851. total = this._zoom.end2 - this._zoom.start2;
  20852. this._zoom.start2 += total * sdy;
  20853. this._zoom.end2 -= total * edy;
  20854. } else {
  20855. total = this._zoom.end - this._zoom.start;
  20856. this._zoom.start += total * sdy;
  20857. this._zoom.end -= total * edy;
  20858. total = this._zoom.end2 - this._zoom.start2;
  20859. this._zoom.start2 += total * sdx;
  20860. this._zoom.end2 -= total * edx;
  20861. }
  20862. this._syncShape();
  20863. this._syncData(true);
  20864. return this._zoom;
  20865. },
  20866. syncBackupData: function (curOption) {
  20867. var start;
  20868. var target = this._originalData['series'];
  20869. var curSeries = curOption.series;
  20870. var curData;
  20871. for (var i = 0, l = curSeries.length; i < l; i++) {
  20872. curData = curSeries[i].data || curSeries[i].eventList;
  20873. if (target[i]) {
  20874. start = Math.floor(this._zoom.start / 100 * target[i].length);
  20875. } else {
  20876. start = 0;
  20877. }
  20878. for (var j = 0, k = curData.length; j < k; j++) {
  20879. if (target[i]) {
  20880. target[i][j + start] = curData[j];
  20881. }
  20882. }
  20883. }
  20884. },
  20885. syncOption: function (magicOption) {
  20886. this.silence(true);
  20887. this.option = magicOption;
  20888. this.option.dataZoom = this.reformOption(this.option.dataZoom);
  20889. this.zoomOption = this.option.dataZoom;
  20890. if (!this.myChart.canvasSupported) {
  20891. this.zoomOption.realtime = false;
  20892. }
  20893. this.clear();
  20894. this._location = this._getLocation();
  20895. this._zoom = this._getZoom();
  20896. this._backupData();
  20897. if (this.option.dataZoom && this.option.dataZoom.show) {
  20898. this._buildShape();
  20899. }
  20900. this._syncData();
  20901. this.silence(false);
  20902. },
  20903. silence: function (s) {
  20904. this._isSilence = s;
  20905. },
  20906. getRealDataIndex: function (sIdx, dIdx) {
  20907. if (!this._originalData || this._zoom.start === 0 && this._zoom.end == 100) {
  20908. return dIdx;
  20909. }
  20910. var sreies = this._originalData.series;
  20911. if (sreies[sIdx]) {
  20912. return Math.floor(this._zoom.start / 100 * sreies[sIdx].length) + dIdx;
  20913. }
  20914. return -1;
  20915. },
  20916. resize: function () {
  20917. this.clear();
  20918. this._location = this._getLocation();
  20919. this._zoom = this._getZoom();
  20920. if (this.option.dataZoom.show) {
  20921. this._buildShape();
  20922. }
  20923. }
  20924. };
  20925. zrUtil.inherits(DataZoom, Base);
  20926. require('../component').define('dataZoom', DataZoom);
  20927. return DataZoom;
  20928. });define('echarts/component/categoryAxis', [
  20929. 'require',
  20930. './base',
  20931. 'zrender/shape/Text',
  20932. 'zrender/shape/Line',
  20933. 'zrender/shape/Rectangle',
  20934. '../config',
  20935. 'zrender/tool/util',
  20936. 'zrender/tool/area',
  20937. '../component'
  20938. ], function (require) {
  20939. var Base = require('./base');
  20940. var TextShape = require('zrender/shape/Text');
  20941. var LineShape = require('zrender/shape/Line');
  20942. var RectangleShape = require('zrender/shape/Rectangle');
  20943. var ecConfig = require('../config');
  20944. ecConfig.categoryAxis = {
  20945. zlevel: 0,
  20946. z: 0,
  20947. show: true,
  20948. position: 'bottom',
  20949. name: '',
  20950. nameLocation: 'end',
  20951. nameTextStyle: {},
  20952. boundaryGap: true,
  20953. axisLine: {
  20954. show: true,
  20955. onZero: true,
  20956. lineStyle: {
  20957. color: '#48b',
  20958. width: 2,
  20959. type: 'solid'
  20960. }
  20961. },
  20962. axisTick: {
  20963. show: true,
  20964. interval: 'auto',
  20965. inside: false,
  20966. length: 5,
  20967. lineStyle: {
  20968. color: '#333',
  20969. width: 1
  20970. }
  20971. },
  20972. axisLabel: {
  20973. show: true,
  20974. interval: 'auto',
  20975. rotate: 0,
  20976. margin: 8,
  20977. textStyle: { color: '#333' }
  20978. },
  20979. splitLine: {
  20980. show: true,
  20981. lineStyle: {
  20982. color: ['#ccc'],
  20983. width: 1,
  20984. type: 'solid'
  20985. }
  20986. },
  20987. splitArea: {
  20988. show: false,
  20989. areaStyle: {
  20990. color: [
  20991. 'rgba(250,250,250,0.3)',
  20992. 'rgba(200,200,200,0.3)'
  20993. ]
  20994. }
  20995. }
  20996. };
  20997. var zrUtil = require('zrender/tool/util');
  20998. var zrArea = require('zrender/tool/area');
  20999. function CategoryAxis(ecTheme, messageCenter, zr, option, myChart, axisBase) {
  21000. if (option.data.length < 1) {
  21001. console.error('option.data.length < 1.');
  21002. return;
  21003. }
  21004. Base.call(this, ecTheme, messageCenter, zr, option, myChart);
  21005. this.grid = this.component.grid;
  21006. for (var method in axisBase) {
  21007. this[method] = axisBase[method];
  21008. }
  21009. this.refresh(option);
  21010. }
  21011. CategoryAxis.prototype = {
  21012. type: ecConfig.COMPONENT_TYPE_AXIS_CATEGORY,
  21013. _getReformedLabel: function (idx) {
  21014. var data = this.getDataFromOption(this.option.data[idx]);
  21015. var formatter = this.option.data[idx].formatter || this.option.axisLabel.formatter;
  21016. if (formatter) {
  21017. if (typeof formatter == 'function') {
  21018. data = formatter.call(this.myChart, data);
  21019. } else if (typeof formatter == 'string') {
  21020. data = formatter.replace('{value}', data);
  21021. }
  21022. }
  21023. return data;
  21024. },
  21025. _getInterval: function () {
  21026. var interval = this.option.axisLabel.interval;
  21027. if (interval == 'auto') {
  21028. var fontSize = this.option.axisLabel.textStyle.fontSize;
  21029. var data = this.option.data;
  21030. var dataLength = this.option.data.length;
  21031. if (this.isHorizontal()) {
  21032. if (dataLength > 3) {
  21033. var gap = this.getGap();
  21034. var isEnough = false;
  21035. var labelSpace;
  21036. var labelSize;
  21037. var step = Math.floor(0.5 / gap);
  21038. step = step < 1 ? 1 : step;
  21039. interval = Math.floor(15 / gap);
  21040. while (!isEnough && interval < dataLength) {
  21041. interval += step;
  21042. isEnough = true;
  21043. labelSpace = Math.floor(gap * interval);
  21044. for (var i = Math.floor((dataLength - 1) / interval) * interval; i >= 0; i -= interval) {
  21045. if (this.option.axisLabel.rotate !== 0) {
  21046. labelSize = fontSize;
  21047. } else if (data[i].textStyle) {
  21048. labelSize = zrArea.getTextWidth(this._getReformedLabel(i), this.getFont(zrUtil.merge(data[i].textStyle, this.option.axisLabel.textStyle)));
  21049. } else {
  21050. var label = this._getReformedLabel(i) + '';
  21051. var wLen = (label.match(/\w/g) || '').length;
  21052. var oLen = label.length - wLen;
  21053. labelSize = wLen * fontSize * 2 / 3 + oLen * fontSize;
  21054. }
  21055. if (labelSpace < labelSize) {
  21056. isEnough = false;
  21057. break;
  21058. }
  21059. }
  21060. }
  21061. } else {
  21062. interval = 1;
  21063. }
  21064. } else {
  21065. if (dataLength > 3) {
  21066. var gap = this.getGap();
  21067. interval = Math.floor(11 / gap);
  21068. while (gap * interval - 6 < fontSize && interval < dataLength) {
  21069. interval++;
  21070. }
  21071. } else {
  21072. interval = 1;
  21073. }
  21074. }
  21075. } else {
  21076. interval = typeof interval == 'function' ? 1 : interval - 0 + 1;
  21077. }
  21078. return interval;
  21079. },
  21080. _buildShape: function () {
  21081. this._interval = this._getInterval();
  21082. if (!this.option.show) {
  21083. return;
  21084. }
  21085. this.option.splitArea.show && this._buildSplitArea();
  21086. this.option.splitLine.show && this._buildSplitLine();
  21087. this.option.axisLine.show && this._buildAxisLine();
  21088. this.option.axisTick.show && this._buildAxisTick();
  21089. this.option.axisLabel.show && this._buildAxisLabel();
  21090. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  21091. this.zr.addShape(this.shapeList[i]);
  21092. }
  21093. },
  21094. _buildAxisTick: function () {
  21095. var axShape;
  21096. var data = this.option.data;
  21097. var dataLength = this.option.data.length;
  21098. var tickOption = this.option.axisTick;
  21099. var length = tickOption.length;
  21100. var color = tickOption.lineStyle.color;
  21101. var lineWidth = tickOption.lineStyle.width;
  21102. var intervalFunction = typeof tickOption.interval == 'function' ? tickOption.interval : tickOption.interval == 'auto' ? typeof this.option.axisLabel.interval == 'function' ? this.option.axisLabel.interval : false : false;
  21103. var interval = intervalFunction ? 1 : tickOption.interval == 'auto' ? this._interval : tickOption.interval - 0 + 1;
  21104. var onGap = tickOption.onGap;
  21105. var optGap = onGap ? this.getGap() / 2 : typeof onGap == 'undefined' ? this.option.boundaryGap ? this.getGap() / 2 : 0 : 0;
  21106. var startIndex = optGap > 0 ? -interval : 0;
  21107. if (this.isHorizontal()) {
  21108. var yPosition = this.option.position == 'bottom' ? tickOption.inside ? this.grid.getYend() - length - 1 : this.grid.getYend() + 1 : tickOption.inside ? this.grid.getY() + 1 : this.grid.getY() - length - 1;
  21109. var x;
  21110. for (var i = startIndex; i < dataLength; i += interval) {
  21111. if (intervalFunction && !intervalFunction(i, data[i])) {
  21112. continue;
  21113. }
  21114. x = this.subPixelOptimize(this.getCoordByIndex(i) + (i >= 0 ? optGap : 0), lineWidth);
  21115. axShape = {
  21116. _axisShape: 'axisTick',
  21117. zlevel: this.getZlevelBase(),
  21118. z: this.getZBase(),
  21119. hoverable: false,
  21120. style: {
  21121. xStart: x,
  21122. yStart: yPosition,
  21123. xEnd: x,
  21124. yEnd: yPosition + length,
  21125. strokeColor: color,
  21126. lineWidth: lineWidth
  21127. }
  21128. };
  21129. this.shapeList.push(new LineShape(axShape));
  21130. }
  21131. } else {
  21132. var xPosition = this.option.position == 'left' ? tickOption.inside ? this.grid.getX() + 1 : this.grid.getX() - length - 1 : tickOption.inside ? this.grid.getXend() - length - 1 : this.grid.getXend() + 1;
  21133. var y;
  21134. for (var i = startIndex; i < dataLength; i += interval) {
  21135. if (intervalFunction && !intervalFunction(i, data[i])) {
  21136. continue;
  21137. }
  21138. y = this.subPixelOptimize(this.getCoordByIndex(i) - (i >= 0 ? optGap : 0), lineWidth);
  21139. axShape = {
  21140. _axisShape: 'axisTick',
  21141. zlevel: this.getZlevelBase(),
  21142. z: this.getZBase(),
  21143. hoverable: false,
  21144. style: {
  21145. xStart: xPosition,
  21146. yStart: y,
  21147. xEnd: xPosition + length,
  21148. yEnd: y,
  21149. strokeColor: color,
  21150. lineWidth: lineWidth
  21151. }
  21152. };
  21153. this.shapeList.push(new LineShape(axShape));
  21154. }
  21155. }
  21156. },
  21157. _buildAxisLabel: function () {
  21158. var axShape;
  21159. var data = this.option.data;
  21160. var dataLength = this.option.data.length;
  21161. var labelOption = this.option.axisLabel;
  21162. var rotate = labelOption.rotate;
  21163. var margin = labelOption.margin;
  21164. var clickable = labelOption.clickable;
  21165. var textStyle = labelOption.textStyle;
  21166. var intervalFunction = typeof labelOption.interval == 'function' ? labelOption.interval : false;
  21167. var dataTextStyle;
  21168. if (this.isHorizontal()) {
  21169. var yPosition;
  21170. var baseLine;
  21171. if (this.option.position == 'bottom') {
  21172. yPosition = this.grid.getYend() + margin;
  21173. baseLine = 'top';
  21174. } else {
  21175. yPosition = this.grid.getY() - margin;
  21176. baseLine = 'bottom';
  21177. }
  21178. for (var i = 0; i < dataLength; i += this._interval) {
  21179. if (intervalFunction && !intervalFunction(i, data[i]) || this._getReformedLabel(i) === '') {
  21180. continue;
  21181. }
  21182. dataTextStyle = zrUtil.merge(data[i].textStyle || {}, textStyle);
  21183. axShape = {
  21184. zlevel: this.getZlevelBase(),
  21185. z: this.getZBase() + 3,
  21186. hoverable: false,
  21187. style: {
  21188. x: this.getCoordByIndex(i),
  21189. y: yPosition,
  21190. color: dataTextStyle.color,
  21191. text: this._getReformedLabel(i),
  21192. textFont: this.getFont(dataTextStyle),
  21193. textAlign: dataTextStyle.align || 'center',
  21194. textBaseline: dataTextStyle.baseline || baseLine
  21195. }
  21196. };
  21197. if (rotate) {
  21198. axShape.style.textAlign = rotate > 0 ? this.option.position == 'bottom' ? 'right' : 'left' : this.option.position == 'bottom' ? 'left' : 'right';
  21199. axShape.rotation = [
  21200. rotate * Math.PI / 180,
  21201. axShape.style.x,
  21202. axShape.style.y
  21203. ];
  21204. }
  21205. this.shapeList.push(new TextShape(this._axisLabelClickable(clickable, axShape)));
  21206. }
  21207. } else {
  21208. var xPosition;
  21209. var align;
  21210. if (this.option.position == 'left') {
  21211. xPosition = this.grid.getX() - margin;
  21212. align = 'right';
  21213. } else {
  21214. xPosition = this.grid.getXend() + margin;
  21215. align = 'left';
  21216. }
  21217. for (var i = 0; i < dataLength; i += this._interval) {
  21218. if (intervalFunction && !intervalFunction(i, data[i]) || this._getReformedLabel(i) === '') {
  21219. continue;
  21220. }
  21221. dataTextStyle = zrUtil.merge(data[i].textStyle || {}, textStyle);
  21222. axShape = {
  21223. zlevel: this.getZlevelBase(),
  21224. z: this.getZBase() + 3,
  21225. hoverable: false,
  21226. style: {
  21227. x: xPosition,
  21228. y: this.getCoordByIndex(i),
  21229. color: dataTextStyle.color,
  21230. text: this._getReformedLabel(i),
  21231. textFont: this.getFont(dataTextStyle),
  21232. textAlign: dataTextStyle.align || align,
  21233. textBaseline: dataTextStyle.baseline || i === 0 && this.option.name !== '' ? 'bottom' : i == dataLength - 1 && this.option.name !== '' ? 'top' : 'middle'
  21234. }
  21235. };
  21236. if (rotate) {
  21237. axShape.rotation = [
  21238. rotate * Math.PI / 180,
  21239. axShape.style.x,
  21240. axShape.style.y
  21241. ];
  21242. }
  21243. this.shapeList.push(new TextShape(this._axisLabelClickable(clickable, axShape)));
  21244. }
  21245. }
  21246. },
  21247. _buildSplitLine: function () {
  21248. var axShape;
  21249. var data = this.option.data;
  21250. var dataLength = this.option.data.length;
  21251. var sLineOption = this.option.splitLine;
  21252. var lineType = sLineOption.lineStyle.type;
  21253. var lineWidth = sLineOption.lineStyle.width;
  21254. var color = sLineOption.lineStyle.color;
  21255. color = color instanceof Array ? color : [color];
  21256. var colorLength = color.length;
  21257. var intervalFunction = typeof this.option.axisLabel.interval == 'function' ? this.option.axisLabel.interval : false;
  21258. var onGap = sLineOption.onGap;
  21259. var optGap = onGap ? this.getGap() / 2 : typeof onGap == 'undefined' ? this.option.boundaryGap ? this.getGap() / 2 : 0 : 0;
  21260. dataLength -= onGap || typeof onGap == 'undefined' && this.option.boundaryGap ? 1 : 0;
  21261. if (this.isHorizontal()) {
  21262. var sy = this.grid.getY();
  21263. var ey = this.grid.getYend();
  21264. var x;
  21265. for (var i = 0; i < dataLength; i += this._interval) {
  21266. if (intervalFunction && !intervalFunction(i, data[i])) {
  21267. continue;
  21268. }
  21269. x = this.subPixelOptimize(this.getCoordByIndex(i) + optGap, lineWidth);
  21270. axShape = {
  21271. zlevel: this.getZlevelBase(),
  21272. z: this.getZBase(),
  21273. hoverable: false,
  21274. style: {
  21275. xStart: x,
  21276. yStart: sy,
  21277. xEnd: x,
  21278. yEnd: ey,
  21279. strokeColor: color[i / this._interval % colorLength],
  21280. lineType: lineType,
  21281. lineWidth: lineWidth
  21282. }
  21283. };
  21284. this.shapeList.push(new LineShape(axShape));
  21285. }
  21286. } else {
  21287. var sx = this.grid.getX();
  21288. var ex = this.grid.getXend();
  21289. var y;
  21290. for (var i = 0; i < dataLength; i += this._interval) {
  21291. if (intervalFunction && !intervalFunction(i, data[i])) {
  21292. continue;
  21293. }
  21294. y = this.subPixelOptimize(this.getCoordByIndex(i) - optGap, lineWidth);
  21295. axShape = {
  21296. zlevel: this.getZlevelBase(),
  21297. z: this.getZBase(),
  21298. hoverable: false,
  21299. style: {
  21300. xStart: sx,
  21301. yStart: y,
  21302. xEnd: ex,
  21303. yEnd: y,
  21304. strokeColor: color[i / this._interval % colorLength],
  21305. lineType: lineType,
  21306. lineWidth: lineWidth
  21307. }
  21308. };
  21309. this.shapeList.push(new LineShape(axShape));
  21310. }
  21311. }
  21312. },
  21313. _buildSplitArea: function () {
  21314. var axShape;
  21315. var data = this.option.data;
  21316. var sAreaOption = this.option.splitArea;
  21317. var color = sAreaOption.areaStyle.color;
  21318. if (!(color instanceof Array)) {
  21319. axShape = {
  21320. zlevel: this.getZlevelBase(),
  21321. z: this.getZBase(),
  21322. hoverable: false,
  21323. style: {
  21324. x: this.grid.getX(),
  21325. y: this.grid.getY(),
  21326. width: this.grid.getWidth(),
  21327. height: this.grid.getHeight(),
  21328. color: color
  21329. }
  21330. };
  21331. this.shapeList.push(new RectangleShape(axShape));
  21332. } else {
  21333. var colorLength = color.length;
  21334. var dataLength = this.option.data.length;
  21335. var intervalFunction = typeof this.option.axisLabel.interval == 'function' ? this.option.axisLabel.interval : false;
  21336. var onGap = sAreaOption.onGap;
  21337. var optGap = onGap ? this.getGap() / 2 : typeof onGap == 'undefined' ? this.option.boundaryGap ? this.getGap() / 2 : 0 : 0;
  21338. if (this.isHorizontal()) {
  21339. var y = this.grid.getY();
  21340. var height = this.grid.getHeight();
  21341. var lastX = this.grid.getX();
  21342. var curX;
  21343. for (var i = 0; i <= dataLength; i += this._interval) {
  21344. if (intervalFunction && !intervalFunction(i, data[i]) && i < dataLength) {
  21345. continue;
  21346. }
  21347. curX = i < dataLength ? this.getCoordByIndex(i) + optGap : this.grid.getXend();
  21348. axShape = {
  21349. zlevel: this.getZlevelBase(),
  21350. z: this.getZBase(),
  21351. hoverable: false,
  21352. style: {
  21353. x: lastX,
  21354. y: y,
  21355. width: curX - lastX,
  21356. height: height,
  21357. color: color[i / this._interval % colorLength]
  21358. }
  21359. };
  21360. this.shapeList.push(new RectangleShape(axShape));
  21361. lastX = curX;
  21362. }
  21363. } else {
  21364. var x = this.grid.getX();
  21365. var width = this.grid.getWidth();
  21366. var lastYend = this.grid.getYend();
  21367. var curY;
  21368. for (var i = 0; i <= dataLength; i += this._interval) {
  21369. if (intervalFunction && !intervalFunction(i, data[i]) && i < dataLength) {
  21370. continue;
  21371. }
  21372. curY = i < dataLength ? this.getCoordByIndex(i) - optGap : this.grid.getY();
  21373. axShape = {
  21374. zlevel: this.getZlevelBase(),
  21375. z: this.getZBase(),
  21376. hoverable: false,
  21377. style: {
  21378. x: x,
  21379. y: curY,
  21380. width: width,
  21381. height: lastYend - curY,
  21382. color: color[i / this._interval % colorLength]
  21383. }
  21384. };
  21385. this.shapeList.push(new RectangleShape(axShape));
  21386. lastYend = curY;
  21387. }
  21388. }
  21389. }
  21390. },
  21391. refresh: function (newOption) {
  21392. if (newOption) {
  21393. this.option = this.reformOption(newOption);
  21394. this.option.axisLabel.textStyle = this.getTextStyle(this.option.axisLabel.textStyle);
  21395. }
  21396. this.clear();
  21397. this._buildShape();
  21398. },
  21399. getGap: function () {
  21400. var dataLength = this.option.data.length;
  21401. var total = this.isHorizontal() ? this.grid.getWidth() : this.grid.getHeight();
  21402. if (this.option.boundaryGap) {
  21403. return total / dataLength;
  21404. } else {
  21405. return total / (dataLength > 1 ? dataLength - 1 : 1);
  21406. }
  21407. },
  21408. getCoord: function (value) {
  21409. var data = this.option.data;
  21410. var dataLength = data.length;
  21411. var gap = this.getGap();
  21412. var position = this.option.boundaryGap ? gap / 2 : 0;
  21413. for (var i = 0; i < dataLength; i++) {
  21414. if (this.getDataFromOption(data[i]) == value) {
  21415. if (this.isHorizontal()) {
  21416. position = this.grid.getX() + position;
  21417. } else {
  21418. position = this.grid.getYend() - position;
  21419. }
  21420. return position;
  21421. }
  21422. position += gap;
  21423. }
  21424. },
  21425. getCoordByIndex: function (dataIndex) {
  21426. if (dataIndex < 0) {
  21427. if (this.isHorizontal()) {
  21428. return this.grid.getX();
  21429. } else {
  21430. return this.grid.getYend();
  21431. }
  21432. } else if (dataIndex > this.option.data.length - 1) {
  21433. if (this.isHorizontal()) {
  21434. return this.grid.getXend();
  21435. } else {
  21436. return this.grid.getY();
  21437. }
  21438. } else {
  21439. var gap = this.getGap();
  21440. var position = this.option.boundaryGap ? gap / 2 : 0;
  21441. position += dataIndex * gap;
  21442. if (this.isHorizontal()) {
  21443. position = this.grid.getX() + position;
  21444. } else {
  21445. position = this.grid.getYend() - position;
  21446. }
  21447. return position;
  21448. }
  21449. },
  21450. getNameByIndex: function (dataIndex) {
  21451. return this.getDataFromOption(this.option.data[dataIndex]);
  21452. },
  21453. getIndexByName: function (name) {
  21454. var data = this.option.data;
  21455. var dataLength = data.length;
  21456. for (var i = 0; i < dataLength; i++) {
  21457. if (this.getDataFromOption(data[i]) == name) {
  21458. return i;
  21459. }
  21460. }
  21461. return -1;
  21462. },
  21463. getValueFromCoord: function () {
  21464. return '';
  21465. },
  21466. isMainAxis: function (dataIndex) {
  21467. return dataIndex % this._interval === 0;
  21468. }
  21469. };
  21470. zrUtil.inherits(CategoryAxis, Base);
  21471. require('../component').define('categoryAxis', CategoryAxis);
  21472. return CategoryAxis;
  21473. });define('echarts/component/valueAxis', [
  21474. 'require',
  21475. './base',
  21476. 'zrender/shape/Text',
  21477. 'zrender/shape/Line',
  21478. 'zrender/shape/Rectangle',
  21479. '../config',
  21480. '../util/date',
  21481. 'zrender/tool/util',
  21482. '../util/smartSteps',
  21483. '../util/accMath',
  21484. '../util/smartLogSteps',
  21485. '../component'
  21486. ], function (require) {
  21487. var Base = require('./base');
  21488. var TextShape = require('zrender/shape/Text');
  21489. var LineShape = require('zrender/shape/Line');
  21490. var RectangleShape = require('zrender/shape/Rectangle');
  21491. var ecConfig = require('../config');
  21492. ecConfig.valueAxis = {
  21493. zlevel: 0,
  21494. z: 0,
  21495. show: true,
  21496. position: 'left',
  21497. name: '',
  21498. nameLocation: 'end',
  21499. nameTextStyle: {},
  21500. boundaryGap: [
  21501. 0,
  21502. 0
  21503. ],
  21504. axisLine: {
  21505. show: true,
  21506. onZero: true,
  21507. lineStyle: {
  21508. color: '#48b',
  21509. width: 2,
  21510. type: 'solid'
  21511. }
  21512. },
  21513. axisTick: {
  21514. show: false,
  21515. inside: false,
  21516. length: 5,
  21517. lineStyle: {
  21518. color: '#333',
  21519. width: 1
  21520. }
  21521. },
  21522. axisLabel: {
  21523. show: true,
  21524. rotate: 0,
  21525. margin: 8,
  21526. textStyle: { color: '#333' }
  21527. },
  21528. splitLine: {
  21529. show: true,
  21530. lineStyle: {
  21531. color: ['#ccc'],
  21532. width: 1,
  21533. type: 'solid'
  21534. }
  21535. },
  21536. splitArea: {
  21537. show: false,
  21538. areaStyle: {
  21539. color: [
  21540. 'rgba(250,250,250,0.3)',
  21541. 'rgba(200,200,200,0.3)'
  21542. ]
  21543. }
  21544. }
  21545. };
  21546. var ecDate = require('../util/date');
  21547. var zrUtil = require('zrender/tool/util');
  21548. function ValueAxis(ecTheme, messageCenter, zr, option, myChart, axisBase, series) {
  21549. if (!series || series.length === 0) {
  21550. console.err('option.series.length == 0.');
  21551. return;
  21552. }
  21553. Base.call(this, ecTheme, messageCenter, zr, option, myChart);
  21554. this.series = series;
  21555. this.grid = this.component.grid;
  21556. for (var method in axisBase) {
  21557. this[method] = axisBase[method];
  21558. }
  21559. this.refresh(option, series);
  21560. }
  21561. ValueAxis.prototype = {
  21562. type: ecConfig.COMPONENT_TYPE_AXIS_VALUE,
  21563. _buildShape: function () {
  21564. this._hasData = false;
  21565. this._calculateValue();
  21566. if (!this._hasData || !this.option.show) {
  21567. return;
  21568. }
  21569. this.option.splitArea.show && this._buildSplitArea();
  21570. this.option.splitLine.show && this._buildSplitLine();
  21571. this.option.axisLine.show && this._buildAxisLine();
  21572. this.option.axisTick.show && this._buildAxisTick();
  21573. this.option.axisLabel.show && this._buildAxisLabel();
  21574. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  21575. this.zr.addShape(this.shapeList[i]);
  21576. }
  21577. },
  21578. _buildAxisTick: function () {
  21579. var axShape;
  21580. var data = this._valueList;
  21581. var dataLength = this._valueList.length;
  21582. var tickOption = this.option.axisTick;
  21583. var length = tickOption.length;
  21584. var color = tickOption.lineStyle.color;
  21585. var lineWidth = tickOption.lineStyle.width;
  21586. if (this.isHorizontal()) {
  21587. var yPosition = this.option.position === 'bottom' ? tickOption.inside ? this.grid.getYend() - length - 1 : this.grid.getYend() + 1 : tickOption.inside ? this.grid.getY() + 1 : this.grid.getY() - length - 1;
  21588. var x;
  21589. for (var i = 0; i < dataLength; i++) {
  21590. x = this.subPixelOptimize(this.getCoord(data[i]), lineWidth);
  21591. axShape = {
  21592. _axisShape: 'axisTick',
  21593. zlevel: this.getZlevelBase(),
  21594. z: this.getZBase(),
  21595. hoverable: false,
  21596. style: {
  21597. xStart: x,
  21598. yStart: yPosition,
  21599. xEnd: x,
  21600. yEnd: yPosition + length,
  21601. strokeColor: color,
  21602. lineWidth: lineWidth
  21603. }
  21604. };
  21605. this.shapeList.push(new LineShape(axShape));
  21606. }
  21607. } else {
  21608. var xPosition = this.option.position === 'left' ? tickOption.inside ? this.grid.getX() + 1 : this.grid.getX() - length - 1 : tickOption.inside ? this.grid.getXend() - length - 1 : this.grid.getXend() + 1;
  21609. var y;
  21610. for (var i = 0; i < dataLength; i++) {
  21611. y = this.subPixelOptimize(this.getCoord(data[i]), lineWidth);
  21612. axShape = {
  21613. _axisShape: 'axisTick',
  21614. zlevel: this.getZlevelBase(),
  21615. z: this.getZBase(),
  21616. hoverable: false,
  21617. style: {
  21618. xStart: xPosition,
  21619. yStart: y,
  21620. xEnd: xPosition + length,
  21621. yEnd: y,
  21622. strokeColor: color,
  21623. lineWidth: lineWidth
  21624. }
  21625. };
  21626. this.shapeList.push(new LineShape(axShape));
  21627. }
  21628. }
  21629. },
  21630. _buildAxisLabel: function () {
  21631. var axShape;
  21632. var data = this._valueList;
  21633. var dataLength = this._valueList.length;
  21634. var rotate = this.option.axisLabel.rotate;
  21635. var margin = this.option.axisLabel.margin;
  21636. var clickable = this.option.axisLabel.clickable;
  21637. var textStyle = this.option.axisLabel.textStyle;
  21638. if (this.isHorizontal()) {
  21639. var yPosition;
  21640. var baseLine;
  21641. if (this.option.position === 'bottom') {
  21642. yPosition = this.grid.getYend() + margin;
  21643. baseLine = 'top';
  21644. } else {
  21645. yPosition = this.grid.getY() - margin;
  21646. baseLine = 'bottom';
  21647. }
  21648. for (var i = 0; i < dataLength; i++) {
  21649. axShape = {
  21650. zlevel: this.getZlevelBase(),
  21651. z: this.getZBase() + 3,
  21652. hoverable: false,
  21653. style: {
  21654. x: this.getCoord(data[i]),
  21655. y: yPosition,
  21656. color: typeof textStyle.color === 'function' ? textStyle.color(data[i]) : textStyle.color,
  21657. text: this._valueLabel[i],
  21658. textFont: this.getFont(textStyle),
  21659. textAlign: textStyle.align || 'center',
  21660. textBaseline: textStyle.baseline || baseLine
  21661. }
  21662. };
  21663. if (rotate) {
  21664. axShape.style.textAlign = rotate > 0 ? this.option.position === 'bottom' ? 'right' : 'left' : this.option.position === 'bottom' ? 'left' : 'right';
  21665. axShape.rotation = [
  21666. rotate * Math.PI / 180,
  21667. axShape.style.x,
  21668. axShape.style.y
  21669. ];
  21670. }
  21671. this.shapeList.push(new TextShape(this._axisLabelClickable(clickable, axShape)));
  21672. }
  21673. } else {
  21674. var xPosition;
  21675. var align;
  21676. if (this.option.position === 'left') {
  21677. xPosition = this.grid.getX() - margin;
  21678. align = 'right';
  21679. } else {
  21680. xPosition = this.grid.getXend() + margin;
  21681. align = 'left';
  21682. }
  21683. for (var i = 0; i < dataLength; i++) {
  21684. axShape = {
  21685. zlevel: this.getZlevelBase(),
  21686. z: this.getZBase() + 3,
  21687. hoverable: false,
  21688. style: {
  21689. x: xPosition,
  21690. y: this.getCoord(data[i]),
  21691. color: typeof textStyle.color === 'function' ? textStyle.color(data[i]) : textStyle.color,
  21692. text: this._valueLabel[i],
  21693. textFont: this.getFont(textStyle),
  21694. textAlign: textStyle.align || align,
  21695. textBaseline: textStyle.baseline || (i === 0 && this.option.name !== '' ? 'bottom' : i === dataLength - 1 && this.option.name !== '' ? 'top' : 'middle')
  21696. }
  21697. };
  21698. if (rotate) {
  21699. axShape.rotation = [
  21700. rotate * Math.PI / 180,
  21701. axShape.style.x,
  21702. axShape.style.y
  21703. ];
  21704. }
  21705. this.shapeList.push(new TextShape(this._axisLabelClickable(clickable, axShape)));
  21706. }
  21707. }
  21708. },
  21709. _buildSplitLine: function () {
  21710. var axShape;
  21711. var data = this._valueList;
  21712. var dataLength = this._valueList.length;
  21713. var sLineOption = this.option.splitLine;
  21714. var lineType = sLineOption.lineStyle.type;
  21715. var lineWidth = sLineOption.lineStyle.width;
  21716. var color = sLineOption.lineStyle.color;
  21717. color = color instanceof Array ? color : [color];
  21718. var colorLength = color.length;
  21719. if (this.isHorizontal()) {
  21720. var sy = this.grid.getY();
  21721. var ey = this.grid.getYend();
  21722. var x;
  21723. for (var i = 0; i < dataLength; i++) {
  21724. x = this.subPixelOptimize(this.getCoord(data[i]), lineWidth);
  21725. axShape = {
  21726. zlevel: this.getZlevelBase(),
  21727. z: this.getZBase(),
  21728. hoverable: false,
  21729. style: {
  21730. xStart: x,
  21731. yStart: sy,
  21732. xEnd: x,
  21733. yEnd: ey,
  21734. strokeColor: color[i % colorLength],
  21735. lineType: lineType,
  21736. lineWidth: lineWidth
  21737. }
  21738. };
  21739. this.shapeList.push(new LineShape(axShape));
  21740. }
  21741. } else {
  21742. var sx = this.grid.getX();
  21743. var ex = this.grid.getXend();
  21744. var y;
  21745. for (var i = 0; i < dataLength; i++) {
  21746. y = this.subPixelOptimize(this.getCoord(data[i]), lineWidth);
  21747. axShape = {
  21748. zlevel: this.getZlevelBase(),
  21749. z: this.getZBase(),
  21750. hoverable: false,
  21751. style: {
  21752. xStart: sx,
  21753. yStart: y,
  21754. xEnd: ex,
  21755. yEnd: y,
  21756. strokeColor: color[i % colorLength],
  21757. lineType: lineType,
  21758. lineWidth: lineWidth
  21759. }
  21760. };
  21761. this.shapeList.push(new LineShape(axShape));
  21762. }
  21763. }
  21764. },
  21765. _buildSplitArea: function () {
  21766. var axShape;
  21767. var color = this.option.splitArea.areaStyle.color;
  21768. if (!(color instanceof Array)) {
  21769. axShape = {
  21770. zlevel: this.getZlevelBase(),
  21771. z: this.getZBase(),
  21772. hoverable: false,
  21773. style: {
  21774. x: this.grid.getX(),
  21775. y: this.grid.getY(),
  21776. width: this.grid.getWidth(),
  21777. height: this.grid.getHeight(),
  21778. color: color
  21779. }
  21780. };
  21781. this.shapeList.push(new RectangleShape(axShape));
  21782. } else {
  21783. var colorLength = color.length;
  21784. var data = this._valueList;
  21785. var dataLength = this._valueList.length;
  21786. if (this.isHorizontal()) {
  21787. var y = this.grid.getY();
  21788. var height = this.grid.getHeight();
  21789. var lastX = this.grid.getX();
  21790. var curX;
  21791. for (var i = 0; i <= dataLength; i++) {
  21792. curX = i < dataLength ? this.getCoord(data[i]) : this.grid.getXend();
  21793. axShape = {
  21794. zlevel: this.getZlevelBase(),
  21795. z: this.getZBase(),
  21796. hoverable: false,
  21797. style: {
  21798. x: lastX,
  21799. y: y,
  21800. width: curX - lastX,
  21801. height: height,
  21802. color: color[i % colorLength]
  21803. }
  21804. };
  21805. this.shapeList.push(new RectangleShape(axShape));
  21806. lastX = curX;
  21807. }
  21808. } else {
  21809. var x = this.grid.getX();
  21810. var width = this.grid.getWidth();
  21811. var lastYend = this.grid.getYend();
  21812. var curY;
  21813. for (var i = 0; i <= dataLength; i++) {
  21814. curY = i < dataLength ? this.getCoord(data[i]) : this.grid.getY();
  21815. axShape = {
  21816. zlevel: this.getZlevelBase(),
  21817. z: this.getZBase(),
  21818. hoverable: false,
  21819. style: {
  21820. x: x,
  21821. y: curY,
  21822. width: width,
  21823. height: lastYend - curY,
  21824. color: color[i % colorLength]
  21825. }
  21826. };
  21827. this.shapeList.push(new RectangleShape(axShape));
  21828. lastYend = curY;
  21829. }
  21830. }
  21831. }
  21832. },
  21833. _calculateValue: function () {
  21834. if (isNaN(this.option.min - 0) || isNaN(this.option.max - 0)) {
  21835. var data = {};
  21836. var xIdx;
  21837. var yIdx;
  21838. var legend = this.component.legend;
  21839. for (var i = 0, l = this.series.length; i < l; i++) {
  21840. if (this.series[i].type != ecConfig.CHART_TYPE_LINE && this.series[i].type != ecConfig.CHART_TYPE_BAR && this.series[i].type != ecConfig.CHART_TYPE_SCATTER && this.series[i].type != ecConfig.CHART_TYPE_K && this.series[i].type != ecConfig.CHART_TYPE_EVENTRIVER) {
  21841. continue;
  21842. }
  21843. if (legend && !legend.isSelected(this.series[i].name)) {
  21844. continue;
  21845. }
  21846. xIdx = this.series[i].xAxisIndex || 0;
  21847. yIdx = this.series[i].yAxisIndex || 0;
  21848. if (this.option.xAxisIndex != xIdx && this.option.yAxisIndex != yIdx) {
  21849. continue;
  21850. }
  21851. this._calculSum(data, i);
  21852. }
  21853. var oriData;
  21854. for (var i in data) {
  21855. oriData = data[i];
  21856. for (var j = 0, k = oriData.length; j < k; j++) {
  21857. if (!isNaN(oriData[j])) {
  21858. this._hasData = true;
  21859. this._min = oriData[j];
  21860. this._max = oriData[j];
  21861. break;
  21862. }
  21863. }
  21864. if (this._hasData) {
  21865. break;
  21866. }
  21867. }
  21868. for (var i in data) {
  21869. oriData = data[i];
  21870. for (var j = 0, k = oriData.length; j < k; j++) {
  21871. if (!isNaN(oriData[j])) {
  21872. this._min = Math.min(this._min, oriData[j]);
  21873. this._max = Math.max(this._max, oriData[j]);
  21874. }
  21875. }
  21876. }
  21877. var boundaryGap = this.option.type !== 'log' ? this.option.boundaryGap : [
  21878. 0,
  21879. 0
  21880. ];
  21881. var gap = Math.abs(this._max - this._min);
  21882. this._min = isNaN(this.option.min - 0) ? this._min - Math.abs(gap * boundaryGap[0]) : this.option.min - 0;
  21883. this._max = isNaN(this.option.max - 0) ? this._max + Math.abs(gap * boundaryGap[1]) : this.option.max - 0;
  21884. if (this._min === this._max) {
  21885. if (this._max === 0) {
  21886. this._max = 1;
  21887. } else if (this._max > 0) {
  21888. this._min = this._max / this.option.splitNumber != null ? this.option.splitNumber : 5;
  21889. } else {
  21890. this._max = this._max / this.option.splitNumber != null ? this.option.splitNumber : 5;
  21891. }
  21892. }
  21893. if (this.option.type === 'time') {
  21894. this._reformTimeValue();
  21895. } else if (this.option.type === 'log') {
  21896. this._reformLogValue();
  21897. } else {
  21898. this._reformValue(this.option.scale);
  21899. }
  21900. } else {
  21901. this._hasData = true;
  21902. this._min = this.option.min - 0;
  21903. this._max = this.option.max - 0;
  21904. if (this.option.type === 'time') {
  21905. this._reformTimeValue();
  21906. } else if (this.option.type === 'log') {
  21907. this._reformLogValue();
  21908. } else {
  21909. this._customerValue();
  21910. }
  21911. }
  21912. },
  21913. _calculSum: function (data, i) {
  21914. var key = this.series[i].name || 'kener';
  21915. var value;
  21916. var oriData;
  21917. if (!this.series[i].stack) {
  21918. data[key] = data[key] || [];
  21919. if (this.series[i].type != ecConfig.CHART_TYPE_EVENTRIVER) {
  21920. oriData = this.series[i].data;
  21921. for (var j = 0, k = oriData.length; j < k; j++) {
  21922. value = this.getDataFromOption(oriData[j]);
  21923. if (this.series[i].type === ecConfig.CHART_TYPE_K) {
  21924. data[key].push(value[0]);
  21925. data[key].push(value[1]);
  21926. data[key].push(value[2]);
  21927. data[key].push(value[3]);
  21928. } else if (value instanceof Array) {
  21929. if (this.option.xAxisIndex != -1) {
  21930. data[key].push(this.option.type != 'time' ? value[0] : ecDate.getNewDate(value[0]));
  21931. }
  21932. if (this.option.yAxisIndex != -1) {
  21933. data[key].push(this.option.type != 'time' ? value[1] : ecDate.getNewDate(value[1]));
  21934. }
  21935. } else {
  21936. data[key].push(value);
  21937. }
  21938. }
  21939. } else {
  21940. oriData = this.series[i].data;
  21941. for (var j = 0, k = oriData.length; j < k; j++) {
  21942. var evolution = oriData[j].evolution;
  21943. for (var m = 0, n = evolution.length; m < n; m++) {
  21944. data[key].push(ecDate.getNewDate(evolution[m].time));
  21945. }
  21946. }
  21947. }
  21948. } else {
  21949. var keyP = '__Magic_Key_Positive__' + this.series[i].stack;
  21950. var keyN = '__Magic_Key_Negative__' + this.series[i].stack;
  21951. data[keyP] = data[keyP] || [];
  21952. data[keyN] = data[keyN] || [];
  21953. data[key] = data[key] || [];
  21954. oriData = this.series[i].data;
  21955. for (var j = 0, k = oriData.length; j < k; j++) {
  21956. value = this.getDataFromOption(oriData[j]);
  21957. if (value === '-') {
  21958. continue;
  21959. }
  21960. value = value - 0;
  21961. if (value >= 0) {
  21962. if (data[keyP][j] != null) {
  21963. data[keyP][j] += value;
  21964. } else {
  21965. data[keyP][j] = value;
  21966. }
  21967. } else {
  21968. if (data[keyN][j] != null) {
  21969. data[keyN][j] += value;
  21970. } else {
  21971. data[keyN][j] = value;
  21972. }
  21973. }
  21974. if (this.option.scale) {
  21975. data[key].push(value);
  21976. }
  21977. }
  21978. }
  21979. },
  21980. _reformValue: function (scale) {
  21981. var smartSteps = require('../util/smartSteps');
  21982. var splitNumber = this.option.splitNumber;
  21983. if (!scale && this._min >= 0 && this._max >= 0) {
  21984. this._min = 0;
  21985. }
  21986. if (!scale && this._min <= 0 && this._max <= 0) {
  21987. this._max = 0;
  21988. }
  21989. var stepOpt = smartSteps(this._min, this._max, splitNumber);
  21990. splitNumber = splitNumber != null ? splitNumber : stepOpt.secs;
  21991. this._min = stepOpt.min;
  21992. this._max = stepOpt.max;
  21993. this._valueList = stepOpt.pnts;
  21994. this._reformLabelData();
  21995. },
  21996. _reformTimeValue: function () {
  21997. var splitNumber = this.option.splitNumber != null ? this.option.splitNumber : 5;
  21998. var curValue = ecDate.getAutoFormatter(this._min, this._max, splitNumber);
  21999. var formatter = curValue.formatter;
  22000. var gapValue = curValue.gapValue;
  22001. this._valueList = [ecDate.getNewDate(this._min)];
  22002. var startGap;
  22003. switch (formatter) {
  22004. case 'week':
  22005. startGap = ecDate.nextMonday(this._min);
  22006. break;
  22007. case 'month':
  22008. startGap = ecDate.nextNthOnMonth(this._min, 1);
  22009. break;
  22010. case 'quarter':
  22011. startGap = ecDate.nextNthOnQuarterYear(this._min, 1);
  22012. break;
  22013. case 'half-year':
  22014. startGap = ecDate.nextNthOnHalfYear(this._min, 1);
  22015. break;
  22016. case 'year':
  22017. startGap = ecDate.nextNthOnYear(this._min, 1);
  22018. break;
  22019. default:
  22020. if (gapValue <= 3600000 * 2) {
  22021. startGap = (Math.floor(this._min / gapValue) + 1) * gapValue;
  22022. } else {
  22023. startGap = ecDate.getNewDate(this._min - -gapValue);
  22024. startGap.setHours(Math.round(startGap.getHours() / 6) * 6);
  22025. startGap.setMinutes(0);
  22026. startGap.setSeconds(0);
  22027. }
  22028. break;
  22029. }
  22030. if (startGap - this._min < gapValue / 2) {
  22031. startGap -= -gapValue;
  22032. }
  22033. curValue = ecDate.getNewDate(startGap);
  22034. splitNumber *= 1.5;
  22035. while (splitNumber-- >= 0) {
  22036. if (formatter == 'month' || formatter == 'quarter' || formatter == 'half-year' || formatter == 'year') {
  22037. curValue.setDate(1);
  22038. }
  22039. if (this._max - curValue < gapValue / 2) {
  22040. break;
  22041. }
  22042. this._valueList.push(curValue);
  22043. curValue = ecDate.getNewDate(curValue - -gapValue);
  22044. }
  22045. this._valueList.push(ecDate.getNewDate(this._max));
  22046. this._reformLabelData(function (formatterStr) {
  22047. return function (value) {
  22048. return ecDate.format(formatterStr, value);
  22049. };
  22050. }(formatter));
  22051. },
  22052. _customerValue: function () {
  22053. var accMath = require('../util/accMath');
  22054. var splitNumber = this.option.splitNumber != null ? this.option.splitNumber : 5;
  22055. var splitGap = (this._max - this._min) / splitNumber;
  22056. this._valueList = [];
  22057. for (var i = 0; i <= splitNumber; i++) {
  22058. this._valueList.push(accMath.accAdd(this._min, accMath.accMul(splitGap, i)));
  22059. }
  22060. this._reformLabelData();
  22061. },
  22062. _reformLogValue: function () {
  22063. var thisOption = this.option;
  22064. var result = require('../util/smartLogSteps')({
  22065. dataMin: this._min,
  22066. dataMax: this._max,
  22067. logPositive: thisOption.logPositive,
  22068. logLabelBase: thisOption.logLabelBase,
  22069. splitNumber: thisOption.splitNumber
  22070. });
  22071. this._min = result.dataMin;
  22072. this._max = result.dataMax;
  22073. this._valueList = result.tickList;
  22074. this._dataMappingMethods = result.dataMappingMethods;
  22075. this._reformLabelData(result.labelFormatter);
  22076. },
  22077. _reformLabelData: function (innerFormatter) {
  22078. this._valueLabel = [];
  22079. var formatter = this.option.axisLabel.formatter;
  22080. if (formatter) {
  22081. for (var i = 0, l = this._valueList.length; i < l; i++) {
  22082. if (typeof formatter === 'function') {
  22083. this._valueLabel.push(innerFormatter ? formatter.call(this.myChart, this._valueList[i], innerFormatter) : formatter.call(this.myChart, this._valueList[i]));
  22084. } else if (typeof formatter === 'string') {
  22085. this._valueLabel.push(innerFormatter ? ecDate.format(formatter, this._valueList[i]) : formatter.replace('{value}', this._valueList[i]));
  22086. }
  22087. }
  22088. } else {
  22089. for (var i = 0, l = this._valueList.length; i < l; i++) {
  22090. this._valueLabel.push(innerFormatter ? innerFormatter(this._valueList[i]) : this.numAddCommas(this._valueList[i]));
  22091. }
  22092. }
  22093. },
  22094. getExtremum: function () {
  22095. this._calculateValue();
  22096. var dataMappingMethods = this._dataMappingMethods;
  22097. return {
  22098. min: this._min,
  22099. max: this._max,
  22100. dataMappingMethods: dataMappingMethods ? zrUtil.merge({}, dataMappingMethods) : null
  22101. };
  22102. },
  22103. refresh: function (newOption, newSeries) {
  22104. if (newOption) {
  22105. this.option = this.reformOption(newOption);
  22106. this.option.axisLabel.textStyle = zrUtil.merge(this.option.axisLabel.textStyle || {}, this.ecTheme.textStyle);
  22107. this.series = newSeries;
  22108. }
  22109. if (this.zr) {
  22110. this.clear();
  22111. this._buildShape();
  22112. }
  22113. },
  22114. getCoord: function (value) {
  22115. if (this._dataMappingMethods) {
  22116. value = this._dataMappingMethods.value2Coord(value);
  22117. }
  22118. value = value < this._min ? this._min : value;
  22119. value = value > this._max ? this._max : value;
  22120. var result;
  22121. if (!this.isHorizontal()) {
  22122. result = this.grid.getYend() - (value - this._min) / (this._max - this._min) * this.grid.getHeight();
  22123. } else {
  22124. result = this.grid.getX() + (value - this._min) / (this._max - this._min) * this.grid.getWidth();
  22125. }
  22126. return result;
  22127. },
  22128. getCoordSize: function (value) {
  22129. if (!this.isHorizontal()) {
  22130. return Math.abs(value / (this._max - this._min) * this.grid.getHeight());
  22131. } else {
  22132. return Math.abs(value / (this._max - this._min) * this.grid.getWidth());
  22133. }
  22134. },
  22135. getValueFromCoord: function (coord) {
  22136. var result;
  22137. if (!this.isHorizontal()) {
  22138. coord = coord < this.grid.getY() ? this.grid.getY() : coord;
  22139. coord = coord > this.grid.getYend() ? this.grid.getYend() : coord;
  22140. result = this._max - (coord - this.grid.getY()) / this.grid.getHeight() * (this._max - this._min);
  22141. } else {
  22142. coord = coord < this.grid.getX() ? this.grid.getX() : coord;
  22143. coord = coord > this.grid.getXend() ? this.grid.getXend() : coord;
  22144. result = this._min + (coord - this.grid.getX()) / this.grid.getWidth() * (this._max - this._min);
  22145. }
  22146. if (this._dataMappingMethods) {
  22147. result = this._dataMappingMethods.coord2Value(result);
  22148. }
  22149. return result.toFixed(2) - 0;
  22150. },
  22151. isMaindAxis: function (value) {
  22152. for (var i = 0, l = this._valueList.length; i < l; i++) {
  22153. if (this._valueList[i] === value) {
  22154. return true;
  22155. }
  22156. }
  22157. return false;
  22158. }
  22159. };
  22160. zrUtil.inherits(ValueAxis, Base);
  22161. require('../component').define('valueAxis', ValueAxis);
  22162. return ValueAxis;
  22163. });define('echarts/util/date', [], function () {
  22164. var _timeGap = [
  22165. {
  22166. formatter: 'hh : mm : ss',
  22167. value: 1000
  22168. },
  22169. {
  22170. formatter: 'hh : mm : ss',
  22171. value: 1000 * 5
  22172. },
  22173. {
  22174. formatter: 'hh : mm : ss',
  22175. value: 1000 * 10
  22176. },
  22177. {
  22178. formatter: 'hh : mm : ss',
  22179. value: 1000 * 15
  22180. },
  22181. {
  22182. formatter: 'hh : mm : ss',
  22183. value: 1000 * 30
  22184. },
  22185. {
  22186. formatter: 'hh : mm\nMM - dd',
  22187. value: 60000
  22188. },
  22189. {
  22190. formatter: 'hh : mm\nMM - dd',
  22191. value: 60000 * 5
  22192. },
  22193. {
  22194. formatter: 'hh : mm\nMM - dd',
  22195. value: 60000 * 10
  22196. },
  22197. {
  22198. formatter: 'hh : mm\nMM - dd',
  22199. value: 60000 * 15
  22200. },
  22201. {
  22202. formatter: 'hh : mm\nMM - dd',
  22203. value: 60000 * 30
  22204. },
  22205. {
  22206. formatter: 'hh : mm\nMM - dd',
  22207. value: 3600000
  22208. },
  22209. {
  22210. formatter: 'hh : mm\nMM - dd',
  22211. value: 3600000 * 2
  22212. },
  22213. {
  22214. formatter: 'hh : mm\nMM - dd',
  22215. value: 3600000 * 6
  22216. },
  22217. {
  22218. formatter: 'hh : mm\nMM - dd',
  22219. value: 3600000 * 12
  22220. },
  22221. {
  22222. formatter: 'MM - dd\nyyyy',
  22223. value: 3600000 * 24
  22224. },
  22225. {
  22226. formatter: 'week',
  22227. value: 3600000 * 24 * 7
  22228. },
  22229. {
  22230. formatter: 'month',
  22231. value: 3600000 * 24 * 31
  22232. },
  22233. {
  22234. formatter: 'quarter',
  22235. value: 3600000 * 24 * 380 / 4
  22236. },
  22237. {
  22238. formatter: 'half-year',
  22239. value: 3600000 * 24 * 380 / 2
  22240. },
  22241. {
  22242. formatter: 'year',
  22243. value: 3600000 * 24 * 380
  22244. }
  22245. ];
  22246. function getAutoFormatter(min, max, splitNumber) {
  22247. splitNumber = splitNumber > 1 ? splitNumber : 2;
  22248. var curValue;
  22249. var totalGap;
  22250. var formatter;
  22251. var gapValue;
  22252. for (var i = 0, l = _timeGap.length; i < l; i++) {
  22253. curValue = _timeGap[i].value;
  22254. totalGap = Math.ceil(max / curValue) * curValue - Math.floor(min / curValue) * curValue;
  22255. if (Math.round(totalGap / curValue) <= splitNumber * 1.2) {
  22256. formatter = _timeGap[i].formatter;
  22257. gapValue = _timeGap[i].value;
  22258. break;
  22259. }
  22260. }
  22261. if (formatter == null) {
  22262. formatter = 'year';
  22263. curValue = 3600000 * 24 * 367;
  22264. totalGap = Math.ceil(max / curValue) * curValue - Math.floor(min / curValue) * curValue;
  22265. gapValue = Math.round(totalGap / (splitNumber - 1) / curValue) * curValue;
  22266. }
  22267. return {
  22268. formatter: formatter,
  22269. gapValue: gapValue
  22270. };
  22271. }
  22272. function s2d(v) {
  22273. return v < 10 ? '0' + v : v;
  22274. }
  22275. function format(formatter, value) {
  22276. if (formatter == 'week' || formatter == 'month' || formatter == 'quarter' || formatter == 'half-year' || formatter == 'year') {
  22277. formatter = 'MM - dd\nyyyy';
  22278. }
  22279. var date = getNewDate(value);
  22280. var y = date.getFullYear();
  22281. var M = date.getMonth() + 1;
  22282. var d = date.getDate();
  22283. var h = date.getHours();
  22284. var m = date.getMinutes();
  22285. var s = date.getSeconds();
  22286. formatter = formatter.replace('MM', s2d(M));
  22287. formatter = formatter.toLowerCase();
  22288. formatter = formatter.replace('yyyy', y);
  22289. formatter = formatter.replace('yy', y % 100);
  22290. formatter = formatter.replace('dd', s2d(d));
  22291. formatter = formatter.replace('d', d);
  22292. formatter = formatter.replace('hh', s2d(h));
  22293. formatter = formatter.replace('h', h);
  22294. formatter = formatter.replace('mm', s2d(m));
  22295. formatter = formatter.replace('m', m);
  22296. formatter = formatter.replace('ss', s2d(s));
  22297. formatter = formatter.replace('s', s);
  22298. return formatter;
  22299. }
  22300. function nextMonday(value) {
  22301. value = getNewDate(value);
  22302. value.setDate(value.getDate() + 8 - value.getDay());
  22303. return value;
  22304. }
  22305. function nextNthPerNmonth(value, nth, nmon) {
  22306. value = getNewDate(value);
  22307. value.setMonth(Math.ceil((value.getMonth() + 1) / nmon) * nmon);
  22308. value.setDate(nth);
  22309. return value;
  22310. }
  22311. function nextNthOnMonth(value, nth) {
  22312. return nextNthPerNmonth(value, nth, 1);
  22313. }
  22314. function nextNthOnQuarterYear(value, nth) {
  22315. return nextNthPerNmonth(value, nth, 3);
  22316. }
  22317. function nextNthOnHalfYear(value, nth) {
  22318. return nextNthPerNmonth(value, nth, 6);
  22319. }
  22320. function nextNthOnYear(value, nth) {
  22321. return nextNthPerNmonth(value, nth, 12);
  22322. }
  22323. function getNewDate(value) {
  22324. return value instanceof Date ? value : new Date(typeof value == 'string' ? value.replace(/-/g, '/') : value);
  22325. }
  22326. return {
  22327. getAutoFormatter: getAutoFormatter,
  22328. getNewDate: getNewDate,
  22329. format: format,
  22330. nextMonday: nextMonday,
  22331. nextNthPerNmonth: nextNthPerNmonth,
  22332. nextNthOnMonth: nextNthOnMonth,
  22333. nextNthOnQuarterYear: nextNthOnQuarterYear,
  22334. nextNthOnHalfYear: nextNthOnHalfYear,
  22335. nextNthOnYear: nextNthOnYear
  22336. };
  22337. });define('echarts/util/smartSteps', [], function () {
  22338. var mySteps = [
  22339. 10,
  22340. 20,
  22341. 25,
  22342. 50
  22343. ];
  22344. var mySections = [
  22345. 4,
  22346. 5,
  22347. 6
  22348. ];
  22349. var custOpts;
  22350. var custSteps;
  22351. var custSecs;
  22352. var minLocked;
  22353. var maxLocked;
  22354. var MT = Math;
  22355. var MATH_ROUND = MT.round;
  22356. var MATH_FLOOR = MT.floor;
  22357. var MATH_CEIL = MT.ceil;
  22358. var MATH_ABS = MT.abs;
  22359. function MATH_LOG(n) {
  22360. return MT.log(MATH_ABS(n)) / MT.LN10;
  22361. }
  22362. function MATH_POW(n) {
  22363. return MT.pow(10, n);
  22364. }
  22365. function MATH_ISINT(n) {
  22366. return n === MATH_FLOOR(n);
  22367. }
  22368. function smartSteps(min, max, section, opts) {
  22369. custOpts = opts || {};
  22370. custSteps = custOpts.steps || mySteps;
  22371. custSecs = custOpts.secs || mySections;
  22372. section = MATH_ROUND(+section || 0) % 99;
  22373. min = +min || 0;
  22374. max = +max || 0;
  22375. minLocked = maxLocked = 0;
  22376. if ('min' in custOpts) {
  22377. min = +custOpts.min || 0;
  22378. minLocked = 1;
  22379. }
  22380. if ('max' in custOpts) {
  22381. max = +custOpts.max || 0;
  22382. maxLocked = 1;
  22383. }
  22384. if (min > max) {
  22385. max = [
  22386. min,
  22387. min = max
  22388. ][0];
  22389. }
  22390. var span = max - min;
  22391. if (minLocked && maxLocked) {
  22392. return bothLocked(min, max, section);
  22393. }
  22394. if (span < (section || 5)) {
  22395. if (MATH_ISINT(min) && MATH_ISINT(max)) {
  22396. return forInteger(min, max, section);
  22397. } else if (span === 0) {
  22398. return forSpan0(min, max, section);
  22399. }
  22400. }
  22401. return coreCalc(min, max, section);
  22402. }
  22403. function makeResult(newMin, newMax, section, expon) {
  22404. expon = expon || 0;
  22405. var expStep = expNum((newMax - newMin) / section, -1);
  22406. var expMin = expNum(newMin, -1, 1);
  22407. var expMax = expNum(newMax, -1);
  22408. var minExp = MT.min(expStep.e, expMin.e, expMax.e);
  22409. if (expMin.c === 0) {
  22410. minExp = MT.min(expStep.e, expMax.e);
  22411. } else if (expMax.c === 0) {
  22412. minExp = MT.min(expStep.e, expMin.e);
  22413. }
  22414. expFixTo(expStep, {
  22415. c: 0,
  22416. e: minExp
  22417. });
  22418. expFixTo(expMin, expStep, 1);
  22419. expFixTo(expMax, expStep);
  22420. expon += minExp;
  22421. newMin = expMin.c;
  22422. newMax = expMax.c;
  22423. var step = (newMax - newMin) / section;
  22424. var zoom = MATH_POW(expon);
  22425. var fixTo = 0;
  22426. var points = [];
  22427. for (var i = section + 1; i--;) {
  22428. points[i] = (newMin + step * i) * zoom;
  22429. }
  22430. if (expon < 0) {
  22431. fixTo = decimals(zoom);
  22432. step = +(step * zoom).toFixed(fixTo);
  22433. newMin = +(newMin * zoom).toFixed(fixTo);
  22434. newMax = +(newMax * zoom).toFixed(fixTo);
  22435. for (var i = points.length; i--;) {
  22436. points[i] = points[i].toFixed(fixTo);
  22437. +points[i] === 0 && (points[i] = '0');
  22438. }
  22439. } else {
  22440. newMin *= zoom;
  22441. newMax *= zoom;
  22442. step *= zoom;
  22443. }
  22444. custSecs = 0;
  22445. custSteps = 0;
  22446. custOpts = 0;
  22447. return {
  22448. min: newMin,
  22449. max: newMax,
  22450. secs: section,
  22451. step: step,
  22452. fix: fixTo,
  22453. exp: expon,
  22454. pnts: points
  22455. };
  22456. }
  22457. function expNum(num, digit, byFloor) {
  22458. digit = MATH_ROUND(digit % 10) || 2;
  22459. if (digit < 0) {
  22460. if (MATH_ISINT(num)) {
  22461. digit = ('' + MATH_ABS(num)).replace(/0+$/, '').length || 1;
  22462. } else {
  22463. num = num.toFixed(15).replace(/0+$/, '');
  22464. digit = num.replace('.', '').replace(/^[-0]+/, '').length;
  22465. num = +num;
  22466. }
  22467. }
  22468. var expon = MATH_FLOOR(MATH_LOG(num)) - digit + 1;
  22469. var cNum = +(num * MATH_POW(-expon)).toFixed(15) || 0;
  22470. cNum = byFloor ? MATH_FLOOR(cNum) : MATH_CEIL(cNum);
  22471. !cNum && (expon = 0);
  22472. if (('' + MATH_ABS(cNum)).length > digit) {
  22473. expon += 1;
  22474. cNum /= 10;
  22475. }
  22476. return {
  22477. c: cNum,
  22478. e: expon
  22479. };
  22480. }
  22481. function expFixTo(expnum1, expnum2, byFloor) {
  22482. var deltaExp = expnum2.e - expnum1.e;
  22483. if (deltaExp) {
  22484. expnum1.e += deltaExp;
  22485. expnum1.c *= MATH_POW(-deltaExp);
  22486. expnum1.c = byFloor ? MATH_FLOOR(expnum1.c) : MATH_CEIL(expnum1.c);
  22487. }
  22488. }
  22489. function expFixMin(expnum1, expnum2, byFloor) {
  22490. if (expnum1.e < expnum2.e) {
  22491. expFixTo(expnum2, expnum1, byFloor);
  22492. } else {
  22493. expFixTo(expnum1, expnum2, byFloor);
  22494. }
  22495. }
  22496. function getCeil(num, rounds) {
  22497. rounds = rounds || mySteps;
  22498. num = expNum(num);
  22499. var cNum = num.c;
  22500. var i = 0;
  22501. while (cNum > rounds[i]) {
  22502. i++;
  22503. }
  22504. if (!rounds[i]) {
  22505. cNum /= 10;
  22506. num.e += 1;
  22507. i = 0;
  22508. while (cNum > rounds[i]) {
  22509. i++;
  22510. }
  22511. }
  22512. num.c = rounds[i];
  22513. return num;
  22514. }
  22515. function coreCalc(min, max, section) {
  22516. var step;
  22517. var secs = section || +custSecs.slice(-1);
  22518. var expStep = getCeil((max - min) / secs, custSteps);
  22519. var expSpan = expNum(max - min);
  22520. var expMin = expNum(min, -1, 1);
  22521. var expMax = expNum(max, -1);
  22522. expFixTo(expSpan, expStep);
  22523. expFixTo(expMin, expStep, 1);
  22524. expFixTo(expMax, expStep);
  22525. if (!section) {
  22526. secs = look4sections(expMin, expMax);
  22527. } else {
  22528. step = look4step(expMin, expMax, secs);
  22529. }
  22530. if (MATH_ISINT(min) && MATH_ISINT(max) && min * max >= 0) {
  22531. if (max - min < secs) {
  22532. return forInteger(min, max, secs);
  22533. }
  22534. secs = tryForInt(min, max, section, expMin, expMax, secs);
  22535. }
  22536. var arrMM = cross0(min, max, expMin.c, expMax.c);
  22537. expMin.c = arrMM[0];
  22538. expMax.c = arrMM[1];
  22539. if (minLocked || maxLocked) {
  22540. singleLocked(min, max, expMin, expMax);
  22541. }
  22542. return makeResult(expMin.c, expMax.c, secs, expMax.e);
  22543. }
  22544. function look4sections(expMin, expMax) {
  22545. var section;
  22546. var tmpStep, tmpMin, tmpMax;
  22547. var reference = [];
  22548. for (var i = custSecs.length; i--;) {
  22549. section = custSecs[i];
  22550. tmpStep = getCeil((expMax.c - expMin.c) / section, custSteps);
  22551. tmpStep = tmpStep.c * MATH_POW(tmpStep.e);
  22552. tmpMin = MATH_FLOOR(expMin.c / tmpStep) * tmpStep;
  22553. tmpMax = MATH_CEIL(expMax.c / tmpStep) * tmpStep;
  22554. reference[i] = {
  22555. min: tmpMin,
  22556. max: tmpMax,
  22557. step: tmpStep,
  22558. span: tmpMax - tmpMin
  22559. };
  22560. }
  22561. reference.sort(function (a, b) {
  22562. var delta = a.span - b.span;
  22563. if (delta === 0) {
  22564. delta = a.step - b.step;
  22565. }
  22566. return delta;
  22567. });
  22568. reference = reference[0];
  22569. section = reference.span / reference.step;
  22570. expMin.c = reference.min;
  22571. expMax.c = reference.max;
  22572. return section < 3 ? section * 2 : section;
  22573. }
  22574. function look4step(expMin, expMax, secs) {
  22575. var span;
  22576. var tmpMax;
  22577. var tmpMin = expMax.c;
  22578. var tmpStep = (expMax.c - expMin.c) / secs - 1;
  22579. while (tmpMin > expMin.c) {
  22580. tmpStep = getCeil(tmpStep + 1, custSteps);
  22581. tmpStep = tmpStep.c * MATH_POW(tmpStep.e);
  22582. span = tmpStep * secs;
  22583. tmpMax = MATH_CEIL(expMax.c / tmpStep) * tmpStep;
  22584. tmpMin = tmpMax - span;
  22585. }
  22586. var deltaMin = expMin.c - tmpMin;
  22587. var deltaMax = tmpMax - expMax.c;
  22588. var deltaDelta = deltaMin - deltaMax;
  22589. if (deltaDelta > tmpStep * 1.1) {
  22590. deltaDelta = MATH_ROUND(deltaDelta / tmpStep / 2) * tmpStep;
  22591. tmpMin += deltaDelta;
  22592. tmpMax += deltaDelta;
  22593. }
  22594. expMin.c = tmpMin;
  22595. expMax.c = tmpMax;
  22596. return tmpStep;
  22597. }
  22598. function tryForInt(min, max, section, expMin, expMax, secs) {
  22599. var span = expMax.c - expMin.c;
  22600. var step = span / secs * MATH_POW(expMax.e);
  22601. if (!MATH_ISINT(step)) {
  22602. step = MATH_FLOOR(step);
  22603. span = step * secs;
  22604. if (span < max - min) {
  22605. step += 1;
  22606. span = step * secs;
  22607. if (!section && step * (secs - 1) >= max - min) {
  22608. secs -= 1;
  22609. span = step * secs;
  22610. }
  22611. }
  22612. if (span >= max - min) {
  22613. var delta = span - (max - min);
  22614. expMin.c = MATH_ROUND(min - delta / 2);
  22615. expMax.c = MATH_ROUND(max + delta / 2);
  22616. expMin.e = 0;
  22617. expMax.e = 0;
  22618. }
  22619. }
  22620. return secs;
  22621. }
  22622. function forInteger(min, max, section) {
  22623. section = section || 5;
  22624. if (minLocked) {
  22625. max = min + section;
  22626. } else if (maxLocked) {
  22627. min = max - section;
  22628. } else {
  22629. var delta = section - (max - min);
  22630. var newMin = MATH_ROUND(min - delta / 2);
  22631. var newMax = MATH_ROUND(max + delta / 2);
  22632. var arrMM = cross0(min, max, newMin, newMax);
  22633. min = arrMM[0];
  22634. max = arrMM[1];
  22635. }
  22636. return makeResult(min, max, section);
  22637. }
  22638. function forSpan0(min, max, section) {
  22639. section = section || 5;
  22640. var delta = MT.min(MATH_ABS(max / section), section) / 2.1;
  22641. if (minLocked) {
  22642. max = min + delta;
  22643. } else if (maxLocked) {
  22644. min = max - delta;
  22645. } else {
  22646. min = min - delta;
  22647. max = max + delta;
  22648. }
  22649. return coreCalc(min, max, section);
  22650. }
  22651. function cross0(min, max, newMin, newMax) {
  22652. if (min >= 0 && newMin < 0) {
  22653. newMax -= newMin;
  22654. newMin = 0;
  22655. } else if (max <= 0 && newMax > 0) {
  22656. newMin -= newMax;
  22657. newMax = 0;
  22658. }
  22659. return [
  22660. newMin,
  22661. newMax
  22662. ];
  22663. }
  22664. function decimals(num) {
  22665. num = (+num).toFixed(15).split('.');
  22666. return num.pop().replace(/0+$/, '').length;
  22667. }
  22668. function singleLocked(min, max, emin, emax) {
  22669. if (minLocked) {
  22670. var expMin = expNum(min, 4, 1);
  22671. if (emin.e - expMin.e > 6) {
  22672. expMin = {
  22673. c: 0,
  22674. e: emin.e
  22675. };
  22676. }
  22677. expFixMin(emin, expMin);
  22678. expFixMin(emax, expMin);
  22679. emax.c += expMin.c - emin.c;
  22680. emin.c = expMin.c;
  22681. } else if (maxLocked) {
  22682. var expMax = expNum(max, 4);
  22683. if (emax.e - expMax.e > 6) {
  22684. expMax = {
  22685. c: 0,
  22686. e: emax.e
  22687. };
  22688. }
  22689. expFixMin(emin, expMax);
  22690. expFixMin(emax, expMax);
  22691. emin.c += expMax.c - emax.c;
  22692. emax.c = expMax.c;
  22693. }
  22694. }
  22695. function bothLocked(min, max, section) {
  22696. var trySecs = section ? [section] : custSecs;
  22697. var span = max - min;
  22698. if (span === 0) {
  22699. max = expNum(max, 3);
  22700. section = trySecs[0];
  22701. max.c = MATH_ROUND(max.c + section / 2);
  22702. return makeResult(max.c - section, max.c, section, max.e);
  22703. }
  22704. if (MATH_ABS(max / span) < 0.000001) {
  22705. max = 0;
  22706. }
  22707. if (MATH_ABS(min / span) < 0.000001) {
  22708. min = 0;
  22709. }
  22710. var step, deltaSpan, score;
  22711. var scoreS = [
  22712. [
  22713. 5,
  22714. 10
  22715. ],
  22716. [
  22717. 10,
  22718. 2
  22719. ],
  22720. [
  22721. 50,
  22722. 10
  22723. ],
  22724. [
  22725. 100,
  22726. 2
  22727. ]
  22728. ];
  22729. var reference = [];
  22730. var debugLog = [];
  22731. var expSpan = expNum(max - min, 3);
  22732. var expMin = expNum(min, -1, 1);
  22733. var expMax = expNum(max, -1);
  22734. expFixTo(expMin, expSpan, 1);
  22735. expFixTo(expMax, expSpan);
  22736. span = expMax.c - expMin.c;
  22737. expSpan.c = span;
  22738. for (var i = trySecs.length; i--;) {
  22739. section = trySecs[i];
  22740. step = MATH_CEIL(span / section);
  22741. deltaSpan = step * section - span;
  22742. score = (deltaSpan + 3) * 3;
  22743. score += (section - trySecs[0] + 2) * 2;
  22744. if (section % 5 === 0) {
  22745. score -= 10;
  22746. }
  22747. for (var j = scoreS.length; j--;) {
  22748. if (step % scoreS[j][0] === 0) {
  22749. score /= scoreS[j][1];
  22750. }
  22751. }
  22752. debugLog[i] = [
  22753. section,
  22754. step,
  22755. deltaSpan,
  22756. score
  22757. ].join();
  22758. reference[i] = {
  22759. secs: section,
  22760. step: step,
  22761. delta: deltaSpan,
  22762. score: score
  22763. };
  22764. }
  22765. reference.sort(function (a, b) {
  22766. return a.score - b.score;
  22767. });
  22768. reference = reference[0];
  22769. expMin.c = MATH_ROUND(expMin.c - reference.delta / 2);
  22770. expMax.c = MATH_ROUND(expMax.c + reference.delta / 2);
  22771. return makeResult(expMin.c, expMax.c, reference.secs, expSpan.e);
  22772. }
  22773. return smartSteps;
  22774. });define('echarts/util/smartLogSteps', [
  22775. 'require',
  22776. './number'
  22777. ], function (require) {
  22778. var number = require('./number');
  22779. var Mt = Math;
  22780. var mathLog = Mt.log;
  22781. var mathPow = Mt.pow;
  22782. var mathAbs = Mt.abs;
  22783. var mathCeil = Mt.ceil;
  22784. var mathFloor = Mt.floor;
  22785. var LOG_BASE = Mt.E;
  22786. var LN10 = Mt.LN10;
  22787. var LN2 = Mt.LN2;
  22788. var LN2D10 = LN2 / LN10;
  22789. var EPSILON = 1e-9;
  22790. var DEFAULT_SPLIT_NUMBER = 5;
  22791. var MIN_BASE_10_SPLIT_NUMBER = 2;
  22792. var SUPERSCRIPTS = {
  22793. '0': '⁰',
  22794. '1': '¹',
  22795. '2': '²',
  22796. '3': '³',
  22797. '4': '⁴',
  22798. '5': '⁵',
  22799. '6': '⁶',
  22800. '7': '⁷',
  22801. '8': '⁸',
  22802. '9': '⁹',
  22803. '-': '⁻'
  22804. };
  22805. var logPositive;
  22806. var logLabelBase;
  22807. var logLabelMode;
  22808. var lnBase;
  22809. var custOpts;
  22810. var splitNumber;
  22811. var logMappingOffset;
  22812. var absMin;
  22813. var absMax;
  22814. var tickList;
  22815. function smartLogSteps(opts) {
  22816. clearStaticVariables();
  22817. custOpts = opts || {};
  22818. reformSetting();
  22819. makeTicksList();
  22820. return [
  22821. makeResult(),
  22822. clearStaticVariables()
  22823. ][0];
  22824. }
  22825. function clearStaticVariables() {
  22826. logPositive = custOpts = logMappingOffset = lnBase = absMin = absMax = splitNumber = tickList = logLabelBase = logLabelMode = null;
  22827. }
  22828. function reformSetting() {
  22829. logLabelBase = custOpts.logLabelBase;
  22830. if (logLabelBase == null) {
  22831. logLabelMode = 'plain';
  22832. logLabelBase = 10;
  22833. lnBase = LN10;
  22834. } else {
  22835. logLabelBase = +logLabelBase;
  22836. if (logLabelBase < 1) {
  22837. logLabelBase = 10;
  22838. }
  22839. logLabelMode = 'exponent';
  22840. lnBase = mathLog(logLabelBase);
  22841. }
  22842. splitNumber = custOpts.splitNumber;
  22843. splitNumber == null && (splitNumber = DEFAULT_SPLIT_NUMBER);
  22844. var dataMin = parseFloat(custOpts.dataMin);
  22845. var dataMax = parseFloat(custOpts.dataMax);
  22846. if (!isFinite(dataMin) && !isFinite(dataMax)) {
  22847. dataMin = dataMax = 1;
  22848. } else if (!isFinite(dataMin)) {
  22849. dataMin = dataMax;
  22850. } else if (!isFinite(dataMax)) {
  22851. dataMax = dataMin;
  22852. } else if (dataMin > dataMax) {
  22853. dataMax = [
  22854. dataMin,
  22855. dataMin = dataMax
  22856. ][0];
  22857. }
  22858. logPositive = custOpts.logPositive;
  22859. if (logPositive == null) {
  22860. logPositive = dataMax > 0 || dataMin === 0;
  22861. }
  22862. absMin = logPositive ? dataMin : -dataMax;
  22863. absMax = logPositive ? dataMax : -dataMin;
  22864. absMin < EPSILON && (absMin = EPSILON);
  22865. absMax < EPSILON && (absMax = EPSILON);
  22866. }
  22867. function makeTicksList() {
  22868. tickList = [];
  22869. var maxDataLog = fixAccurate(mathLog(absMax) / lnBase);
  22870. var minDataLog = fixAccurate(mathLog(absMin) / lnBase);
  22871. var maxExpon = mathCeil(maxDataLog);
  22872. var minExpon = mathFloor(minDataLog);
  22873. var spanExpon = maxExpon - minExpon;
  22874. var spanDataLog = maxDataLog - minDataLog;
  22875. if (logLabelMode === 'exponent') {
  22876. baseAnalysis();
  22877. } else {
  22878. !(spanExpon <= MIN_BASE_10_SPLIT_NUMBER && splitNumber > MIN_BASE_10_SPLIT_NUMBER) ? baseAnalysis() : detailAnalysis();
  22879. }
  22880. function baseAnalysis() {
  22881. if (spanExpon < splitNumber) {
  22882. splitNumber = spanExpon;
  22883. }
  22884. var stepExpon = mathFloor(fixAccurate(spanExpon / splitNumber));
  22885. var splitNumberAdjust = mathCeil(fixAccurate(spanExpon / stepExpon));
  22886. var spanExponAdjust = stepExpon * splitNumberAdjust;
  22887. var halfDiff = (spanExponAdjust - spanDataLog) / 2;
  22888. var minExponAdjust = mathFloor(fixAccurate(minDataLog - halfDiff));
  22889. if (aroundZero(minExponAdjust - minDataLog)) {
  22890. minExponAdjust -= 1;
  22891. }
  22892. logMappingOffset = -minExponAdjust * lnBase;
  22893. for (var n = minExponAdjust; n - stepExpon <= maxDataLog; n += stepExpon) {
  22894. tickList.push(mathPow(logLabelBase, n));
  22895. }
  22896. }
  22897. function detailAnalysis() {
  22898. var minDecimal = toDecimalFrom4Hex(minExpon, 0);
  22899. var endDecimal = minDecimal + 2;
  22900. while (minDecimal < endDecimal && toH(minDecimal + 1) + toK(minDecimal + 1) * LN2D10 < minDataLog) {
  22901. minDecimal++;
  22902. }
  22903. var maxDecimal = toDecimalFrom4Hex(maxExpon, 0);
  22904. var endDecimal = maxDecimal - 2;
  22905. while (maxDecimal > endDecimal && toH(maxDecimal - 1) + toK(maxDecimal - 1) * LN2D10 > maxDataLog) {
  22906. maxDecimal--;
  22907. }
  22908. logMappingOffset = -(toH(minDecimal) * LN10 + toK(minDecimal) * LN2);
  22909. for (var i = minDecimal; i <= maxDecimal; i++) {
  22910. var h = toH(i);
  22911. var k = toK(i);
  22912. tickList.push(mathPow(10, h) * mathPow(2, k));
  22913. }
  22914. }
  22915. function toDecimalFrom4Hex(h, k) {
  22916. return h * 3 + k;
  22917. }
  22918. function toK(decimal) {
  22919. return decimal - toH(decimal) * 3;
  22920. }
  22921. function toH(decimal) {
  22922. return mathFloor(fixAccurate(decimal / 3));
  22923. }
  22924. }
  22925. function makeResult() {
  22926. var resultTickList = [];
  22927. for (var i = 0, len = tickList.length; i < len; i++) {
  22928. resultTickList[i] = (logPositive ? 1 : -1) * tickList[i];
  22929. }
  22930. !logPositive && resultTickList.reverse();
  22931. var dataMappingMethods = makeDataMappingMethods();
  22932. var value2Coord = dataMappingMethods.value2Coord;
  22933. var newDataMin = value2Coord(resultTickList[0]);
  22934. var newDataMax = value2Coord(resultTickList[resultTickList.length - 1]);
  22935. if (newDataMin === newDataMax) {
  22936. newDataMin -= 1;
  22937. newDataMax += 1;
  22938. }
  22939. return {
  22940. dataMin: newDataMin,
  22941. dataMax: newDataMax,
  22942. tickList: resultTickList,
  22943. logPositive: logPositive,
  22944. labelFormatter: makeLabelFormatter(),
  22945. dataMappingMethods: dataMappingMethods
  22946. };
  22947. }
  22948. function makeLabelFormatter() {
  22949. if (logLabelMode === 'exponent') {
  22950. var myLogLabelBase = logLabelBase;
  22951. var myLnBase = lnBase;
  22952. return function (value) {
  22953. if (!isFinite(parseFloat(value))) {
  22954. return '';
  22955. }
  22956. var sign = '';
  22957. if (value < 0) {
  22958. value = -value;
  22959. sign = '-';
  22960. }
  22961. return sign + myLogLabelBase + makeSuperscriptExponent(mathLog(value) / myLnBase);
  22962. };
  22963. } else {
  22964. return function (value) {
  22965. if (!isFinite(parseFloat(value))) {
  22966. return '';
  22967. }
  22968. return number.addCommas(formatNumber(value));
  22969. };
  22970. }
  22971. }
  22972. function makeDataMappingMethods() {
  22973. var myLogPositive = logPositive;
  22974. var myLogMappingOffset = logMappingOffset;
  22975. return {
  22976. value2Coord: function (x) {
  22977. if (x == null || isNaN(x) || !isFinite(x)) {
  22978. return x;
  22979. }
  22980. x = parseFloat(x);
  22981. if (!isFinite(x)) {
  22982. x = EPSILON;
  22983. } else if (myLogPositive && x < EPSILON) {
  22984. x = EPSILON;
  22985. } else if (!myLogPositive && x > -EPSILON) {
  22986. x = -EPSILON;
  22987. }
  22988. x = mathAbs(x);
  22989. return (myLogPositive ? 1 : -1) * (mathLog(x) + myLogMappingOffset);
  22990. },
  22991. coord2Value: function (x) {
  22992. if (x == null || isNaN(x) || !isFinite(x)) {
  22993. return x;
  22994. }
  22995. x = parseFloat(x);
  22996. if (!isFinite(x)) {
  22997. x = EPSILON;
  22998. }
  22999. return myLogPositive ? mathPow(LOG_BASE, x - myLogMappingOffset) : -mathPow(LOG_BASE, -x + myLogMappingOffset);
  23000. }
  23001. };
  23002. }
  23003. function fixAccurate(result) {
  23004. return +Number(+result).toFixed(14);
  23005. }
  23006. function formatNumber(num) {
  23007. return Number(num).toFixed(15).replace(/\.?0*$/, '');
  23008. }
  23009. function makeSuperscriptExponent(exponent) {
  23010. exponent = formatNumber(Math.round(exponent));
  23011. var result = [];
  23012. for (var i = 0, len = exponent.length; i < len; i++) {
  23013. var cha = exponent.charAt(i);
  23014. result.push(SUPERSCRIPTS[cha] || '');
  23015. }
  23016. return result.join('');
  23017. }
  23018. function aroundZero(val) {
  23019. return val > -EPSILON && val < EPSILON;
  23020. }
  23021. return smartLogSteps;
  23022. });