echarts.js 863 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864
  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.1';
  1479. self.dependencies = { zrender: '2.0.8' };
  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. if (type != 'HOVER' && type != 'MOUSEOUT') {
  1558. setTimeout(function () {
  1559. self._messageCenterOutSide.dispatchWithContext(type, eventPackage, that);
  1560. }, 50);
  1561. } else {
  1562. self._messageCenterOutSide.dispatchWithContext(type, eventPackage, that);
  1563. }
  1564. };
  1565. this._onevent = function (param) {
  1566. return self.__onevent(param);
  1567. };
  1568. for (var e in ecConfig.EVENT) {
  1569. if (e != 'CLICK' && e != 'DBLCLICK' && e != 'HOVER' && e != 'MOUSEOUT' && e != 'MAP_ROAM') {
  1570. this._messageCenter.bind(ecConfig.EVENT[e], this._onevent, this);
  1571. }
  1572. }
  1573. var eventBehaviors = {};
  1574. this._onzrevent = function (param) {
  1575. return self[eventBehaviors[param.type]](param);
  1576. };
  1577. for (var i = 0, len = ZR_EVENT_LISTENS.length; i < len; i++) {
  1578. var eventName = ZR_EVENT_LISTENS[i];
  1579. var eventValue = ZR_EVENT[eventName];
  1580. eventBehaviors[eventValue] = '_on' + eventName.toLowerCase();
  1581. _zr.on(eventValue, this._onzrevent);
  1582. }
  1583. this.chart = {};
  1584. this.component = {};
  1585. var Island = require('./chart/island');
  1586. this._island = new Island(this._themeConfig, this._messageCenter, _zr, {}, this);
  1587. this.chart.island = this._island;
  1588. var Toolbox = require('./component/toolbox');
  1589. this._toolbox = new Toolbox(this._themeConfig, this._messageCenter, _zr, {}, this);
  1590. this.component.toolbox = this._toolbox;
  1591. var componentLibrary = require('./component');
  1592. componentLibrary.define('title', require('./component/title'));
  1593. componentLibrary.define('tooltip', require('./component/tooltip'));
  1594. componentLibrary.define('legend', require('./component/legend'));
  1595. if (_zr.getWidth() === 0 || _zr.getHeight() === 0) {
  1596. console.error('Dom’s width & height should be ready before init.');
  1597. }
  1598. },
  1599. __onevent: function (param) {
  1600. param.__echartsId = param.__echartsId || this.id;
  1601. var fromMyself = param.__echartsId === this.id;
  1602. if (!this._curEventType) {
  1603. this._curEventType = param.type;
  1604. }
  1605. switch (param.type) {
  1606. case ecConfig.EVENT.LEGEND_SELECTED:
  1607. this._onlegendSelected(param);
  1608. break;
  1609. case ecConfig.EVENT.DATA_ZOOM:
  1610. if (!fromMyself) {
  1611. var dz = this.component.dataZoom;
  1612. if (dz) {
  1613. dz.silence(true);
  1614. dz.absoluteZoom(param.zoom);
  1615. dz.silence(false);
  1616. }
  1617. }
  1618. this._ondataZoom(param);
  1619. break;
  1620. case ecConfig.EVENT.DATA_RANGE:
  1621. fromMyself && this._ondataRange(param);
  1622. break;
  1623. case ecConfig.EVENT.MAGIC_TYPE_CHANGED:
  1624. if (!fromMyself) {
  1625. var tb = this.component.toolbox;
  1626. if (tb) {
  1627. tb.silence(true);
  1628. tb.setMagicType(param.magicType);
  1629. tb.silence(false);
  1630. }
  1631. }
  1632. this._onmagicTypeChanged(param);
  1633. break;
  1634. case ecConfig.EVENT.DATA_VIEW_CHANGED:
  1635. fromMyself && this._ondataViewChanged(param);
  1636. break;
  1637. case ecConfig.EVENT.TOOLTIP_HOVER:
  1638. fromMyself && this._tooltipHover(param);
  1639. break;
  1640. case ecConfig.EVENT.RESTORE:
  1641. this._onrestore();
  1642. break;
  1643. case ecConfig.EVENT.REFRESH:
  1644. fromMyself && this._onrefresh(param);
  1645. break;
  1646. case ecConfig.EVENT.TOOLTIP_IN_GRID:
  1647. case ecConfig.EVENT.TOOLTIP_OUT_GRID:
  1648. if (!fromMyself) {
  1649. var grid = this.component.grid;
  1650. if (grid) {
  1651. this._zr.trigger('mousemove', {
  1652. connectTrigger: true,
  1653. zrenderX: grid.getX() + param.x * grid.getWidth(),
  1654. zrenderY: grid.getY() + param.y * grid.getHeight()
  1655. });
  1656. }
  1657. } else if (this._connected) {
  1658. var grid = this.component.grid;
  1659. if (grid) {
  1660. param.x = (param.event.zrenderX - grid.getX()) / grid.getWidth();
  1661. param.y = (param.event.zrenderY - grid.getY()) / grid.getHeight();
  1662. }
  1663. }
  1664. break;
  1665. }
  1666. if (this._connected && fromMyself && this._curEventType === param.type) {
  1667. for (var c in this._connected) {
  1668. this._connected[c].connectedEventHandler(param);
  1669. }
  1670. this._curEventType = null;
  1671. }
  1672. if (!fromMyself || !this._connected && fromMyself) {
  1673. this._curEventType = null;
  1674. }
  1675. },
  1676. _onclick: function (param) {
  1677. callChartListMethodReverse(this, 'onclick', param);
  1678. if (param.target) {
  1679. var ecData = this._eventPackage(param.target);
  1680. if (ecData && ecData.seriesIndex != null) {
  1681. this._messageCenter.dispatch(ecConfig.EVENT.CLICK, param.event, ecData, this);
  1682. }
  1683. }
  1684. },
  1685. _ondblclick: function (param) {
  1686. callChartListMethodReverse(this, 'ondblclick', param);
  1687. if (param.target) {
  1688. var ecData = this._eventPackage(param.target);
  1689. if (ecData && ecData.seriesIndex != null) {
  1690. this._messageCenter.dispatch(ecConfig.EVENT.DBLCLICK, param.event, ecData, this);
  1691. }
  1692. }
  1693. },
  1694. _onmouseover: function (param) {
  1695. if (param.target) {
  1696. var ecData = this._eventPackage(param.target);
  1697. if (ecData && ecData.seriesIndex != null) {
  1698. this._messageCenter.dispatch(ecConfig.EVENT.HOVER, param.event, ecData, this);
  1699. }
  1700. }
  1701. },
  1702. _onmouseout: function (param) {
  1703. if (param.target) {
  1704. var ecData = this._eventPackage(param.target);
  1705. if (ecData && ecData.seriesIndex != null) {
  1706. this._messageCenter.dispatch(ecConfig.EVENT.MOUSEOUT, param.event, ecData, this);
  1707. }
  1708. }
  1709. },
  1710. _ondragstart: function (param) {
  1711. this._status = {
  1712. dragIn: false,
  1713. dragOut: false,
  1714. needRefresh: false
  1715. };
  1716. callChartListMethodReverse(this, 'ondragstart', param);
  1717. },
  1718. _ondragenter: function (param) {
  1719. callChartListMethodReverse(this, 'ondragenter', param);
  1720. },
  1721. _ondragover: function (param) {
  1722. callChartListMethodReverse(this, 'ondragover', param);
  1723. },
  1724. _ondragleave: function (param) {
  1725. callChartListMethodReverse(this, 'ondragleave', param);
  1726. },
  1727. _ondrop: function (param) {
  1728. callChartListMethodReverse(this, 'ondrop', param, this._status);
  1729. this._island.ondrop(param, this._status);
  1730. },
  1731. _ondragend: function (param) {
  1732. callChartListMethodReverse(this, 'ondragend', param, this._status);
  1733. this._timeline && this._timeline.ondragend(param, this._status);
  1734. this._island.ondragend(param, this._status);
  1735. if (this._status.needRefresh) {
  1736. this._syncBackupData(this._option);
  1737. var messageCenter = this._messageCenter;
  1738. messageCenter.dispatch(ecConfig.EVENT.DATA_CHANGED, param.event, this._eventPackage(param.target), this);
  1739. messageCenter.dispatch(ecConfig.EVENT.REFRESH, null, null, this);
  1740. }
  1741. },
  1742. _onlegendSelected: function (param) {
  1743. this._status.needRefresh = false;
  1744. callChartListMethodReverse(this, 'onlegendSelected', param, this._status);
  1745. if (this._status.needRefresh) {
  1746. this._messageCenter.dispatch(ecConfig.EVENT.REFRESH, null, null, this);
  1747. }
  1748. },
  1749. _ondataZoom: function (param) {
  1750. this._status.needRefresh = false;
  1751. callChartListMethodReverse(this, 'ondataZoom', param, this._status);
  1752. if (this._status.needRefresh) {
  1753. this._messageCenter.dispatch(ecConfig.EVENT.REFRESH, null, null, this);
  1754. }
  1755. },
  1756. _ondataRange: function (param) {
  1757. this._clearEffect();
  1758. this._status.needRefresh = false;
  1759. callChartListMethodReverse(this, 'ondataRange', param, this._status);
  1760. if (this._status.needRefresh) {
  1761. this._zr.refreshNextFrame();
  1762. }
  1763. },
  1764. _onmagicTypeChanged: function () {
  1765. this._clearEffect();
  1766. this._render(this._toolbox.getMagicOption());
  1767. },
  1768. _ondataViewChanged: function (param) {
  1769. this._syncBackupData(param.option);
  1770. this._messageCenter.dispatch(ecConfig.EVENT.DATA_CHANGED, null, param, this);
  1771. this._messageCenter.dispatch(ecConfig.EVENT.REFRESH, null, null, this);
  1772. },
  1773. _tooltipHover: function (param) {
  1774. var tipShape = [];
  1775. callChartListMethodReverse(this, 'ontooltipHover', param, tipShape);
  1776. },
  1777. _onrestore: function () {
  1778. this.restore();
  1779. },
  1780. _onrefresh: function (param) {
  1781. this._refreshInside = true;
  1782. this.refresh(param);
  1783. this._refreshInside = false;
  1784. },
  1785. _syncBackupData: function (curOption) {
  1786. this.component.dataZoom && this.component.dataZoom.syncBackupData(curOption);
  1787. },
  1788. _eventPackage: function (target) {
  1789. if (target) {
  1790. var ecData = require('./util/ecData');
  1791. var seriesIndex = ecData.get(target, 'seriesIndex');
  1792. var dataIndex = ecData.get(target, 'dataIndex');
  1793. dataIndex = seriesIndex != -1 && this.component.dataZoom ? this.component.dataZoom.getRealDataIndex(seriesIndex, dataIndex) : dataIndex;
  1794. return {
  1795. seriesIndex: seriesIndex,
  1796. seriesName: (ecData.get(target, 'series') || {}).name,
  1797. dataIndex: dataIndex,
  1798. data: ecData.get(target, 'data'),
  1799. name: ecData.get(target, 'name'),
  1800. value: ecData.get(target, 'value'),
  1801. special: ecData.get(target, 'special')
  1802. };
  1803. }
  1804. return;
  1805. },
  1806. _noDataCheck: function (magicOption) {
  1807. var series = magicOption.series;
  1808. for (var i = 0, l = series.length; i < l; i++) {
  1809. 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) {
  1810. return false;
  1811. }
  1812. }
  1813. var loadOption = this._option && this._option.noDataLoadingOption || this._themeConfig.noDataLoadingOption || ecConfig.noDataLoadingOption || {
  1814. text: this._option && this._option.noDataText || this._themeConfig.noDataText || ecConfig.noDataText,
  1815. effect: this._option && this._option.noDataEffect || this._themeConfig.noDataEffect || ecConfig.noDataEffect
  1816. };
  1817. this.clear();
  1818. this.showLoading(loadOption);
  1819. return true;
  1820. },
  1821. _render: function (magicOption) {
  1822. this._mergeGlobalConifg(magicOption);
  1823. if (this._noDataCheck(magicOption)) {
  1824. return;
  1825. }
  1826. var bgColor = magicOption.backgroundColor;
  1827. if (bgColor) {
  1828. if (!_canvasSupported && bgColor.indexOf('rgba') != -1) {
  1829. var cList = bgColor.split(',');
  1830. this.dom.style.filter = 'alpha(opacity=' + cList[3].substring(0, cList[3].lastIndexOf(')')) * 100 + ')';
  1831. cList.length = 3;
  1832. cList[0] = cList[0].replace('a', '');
  1833. this.dom.style.backgroundColor = cList.join(',') + ')';
  1834. } else {
  1835. this.dom.style.backgroundColor = bgColor;
  1836. }
  1837. }
  1838. this._zr.clearAnimation();
  1839. this._chartList = [];
  1840. var chartLibrary = require('./chart');
  1841. var componentLibrary = require('./component');
  1842. if (magicOption.xAxis || magicOption.yAxis) {
  1843. magicOption.grid = magicOption.grid || {};
  1844. magicOption.dataZoom = magicOption.dataZoom || {};
  1845. }
  1846. var componentList = [
  1847. 'title',
  1848. 'legend',
  1849. 'tooltip',
  1850. 'dataRange',
  1851. 'roamController',
  1852. 'grid',
  1853. 'dataZoom',
  1854. 'xAxis',
  1855. 'yAxis',
  1856. 'polar'
  1857. ];
  1858. var ComponentClass;
  1859. var componentType;
  1860. var component;
  1861. for (var i = 0, l = componentList.length; i < l; i++) {
  1862. componentType = componentList[i];
  1863. component = this.component[componentType];
  1864. if (magicOption[componentType]) {
  1865. if (component) {
  1866. component.refresh && component.refresh(magicOption);
  1867. } else {
  1868. ComponentClass = componentLibrary.get(/^[xy]Axis$/.test(componentType) ? 'axis' : componentType);
  1869. component = new ComponentClass(this._themeConfig, this._messageCenter, this._zr, magicOption, this, componentType);
  1870. this.component[componentType] = component;
  1871. }
  1872. this._chartList.push(component);
  1873. } else if (component) {
  1874. component.dispose();
  1875. this.component[componentType] = null;
  1876. delete this.component[componentType];
  1877. }
  1878. }
  1879. var ChartClass;
  1880. var chartType;
  1881. var chart;
  1882. var chartMap = {};
  1883. for (var i = 0, l = magicOption.series.length; i < l; i++) {
  1884. chartType = magicOption.series[i].type;
  1885. if (!chartType) {
  1886. console.error('series[' + i + '] chart type has not been defined.');
  1887. continue;
  1888. }
  1889. if (!chartMap[chartType]) {
  1890. chartMap[chartType] = true;
  1891. ChartClass = chartLibrary.get(chartType);
  1892. if (ChartClass) {
  1893. if (this.chart[chartType]) {
  1894. chart = this.chart[chartType];
  1895. chart.refresh(magicOption);
  1896. } else {
  1897. chart = new ChartClass(this._themeConfig, this._messageCenter, this._zr, magicOption, this);
  1898. }
  1899. this._chartList.push(chart);
  1900. this.chart[chartType] = chart;
  1901. } else {
  1902. console.error(chartType + ' has not been required.');
  1903. }
  1904. }
  1905. }
  1906. for (chartType in this.chart) {
  1907. if (chartType != ecConfig.CHART_TYPE_ISLAND && !chartMap[chartType]) {
  1908. this.chart[chartType].dispose();
  1909. this.chart[chartType] = null;
  1910. delete this.chart[chartType];
  1911. }
  1912. }
  1913. this.component.grid && this.component.grid.refixAxisShape(this.component);
  1914. this._island.refresh(magicOption);
  1915. this._toolbox.refresh(magicOption);
  1916. magicOption.animation && !magicOption.renderAsImage ? this._zr.refresh() : this._zr.render();
  1917. var imgId = 'IMG' + this.id;
  1918. var img = document.getElementById(imgId);
  1919. if (magicOption.renderAsImage && _canvasSupported) {
  1920. if (img) {
  1921. img.src = this.getDataURL(magicOption.renderAsImage);
  1922. } else {
  1923. img = this.getImage(magicOption.renderAsImage);
  1924. img.id = imgId;
  1925. img.style.position = 'absolute';
  1926. img.style.left = 0;
  1927. img.style.top = 0;
  1928. this.dom.firstChild.appendChild(img);
  1929. }
  1930. this.un();
  1931. this._zr.un();
  1932. this._disposeChartList();
  1933. this._zr.clear();
  1934. } else if (img) {
  1935. img.parentNode.removeChild(img);
  1936. }
  1937. img = null;
  1938. this._option = magicOption;
  1939. },
  1940. restore: function () {
  1941. this._clearEffect();
  1942. this._option = zrUtil.clone(this._optionRestore);
  1943. this._disposeChartList();
  1944. this._island.clear();
  1945. this._toolbox.reset(this._option, true);
  1946. this._render(this._option);
  1947. },
  1948. refresh: function (param) {
  1949. this._clearEffect();
  1950. param = param || {};
  1951. var magicOption = param.option;
  1952. if (!this._refreshInside && magicOption) {
  1953. magicOption = this.getOption();
  1954. zrUtil.merge(magicOption, param.option, true);
  1955. zrUtil.merge(this._optionRestore, param.option, true);
  1956. this._toolbox.reset(magicOption);
  1957. }
  1958. this._island.refresh(magicOption);
  1959. this._toolbox.refresh(magicOption);
  1960. this._zr.clearAnimation();
  1961. for (var i = 0, l = this._chartList.length; i < l; i++) {
  1962. this._chartList[i].refresh && this._chartList[i].refresh(magicOption);
  1963. }
  1964. this.component.grid && this.component.grid.refixAxisShape(this.component);
  1965. this._zr.refresh();
  1966. },
  1967. _disposeChartList: function () {
  1968. this._clearEffect();
  1969. this._zr.clearAnimation();
  1970. var len = this._chartList.length;
  1971. while (len--) {
  1972. var chart = this._chartList[len];
  1973. if (chart) {
  1974. var chartType = chart.type;
  1975. this.chart[chartType] && delete this.chart[chartType];
  1976. this.component[chartType] && delete this.component[chartType];
  1977. chart.dispose && chart.dispose();
  1978. }
  1979. }
  1980. this._chartList = [];
  1981. },
  1982. _mergeGlobalConifg: function (magicOption) {
  1983. var mergeList = [
  1984. 'backgroundColor',
  1985. 'calculable',
  1986. 'calculableColor',
  1987. 'calculableHolderColor',
  1988. 'nameConnector',
  1989. 'valueConnector',
  1990. 'animation',
  1991. 'animationThreshold',
  1992. 'animationDuration',
  1993. 'animationDurationUpdate',
  1994. 'animationEasing',
  1995. 'addDataAnimation',
  1996. 'symbolList',
  1997. 'DRAG_ENABLE_TIME'
  1998. ];
  1999. var len = mergeList.length;
  2000. while (len--) {
  2001. var mergeItem = mergeList[len];
  2002. if (magicOption[mergeItem] == null) {
  2003. magicOption[mergeItem] = this._themeConfig[mergeItem] != null ? this._themeConfig[mergeItem] : ecConfig[mergeItem];
  2004. }
  2005. }
  2006. var themeColor = magicOption.color;
  2007. if (!(themeColor && themeColor.length)) {
  2008. themeColor = this._themeConfig.color || ecConfig.color;
  2009. }
  2010. this._zr.getColor = function (idx) {
  2011. var zrColor = require('zrender/tool/color');
  2012. return zrColor.getColor(idx, themeColor);
  2013. };
  2014. if (!_canvasSupported) {
  2015. magicOption.animation = false;
  2016. magicOption.addDataAnimation = false;
  2017. }
  2018. },
  2019. setOption: function (option, notMerge) {
  2020. if (!option.timeline) {
  2021. return this._setOption(option, notMerge);
  2022. } else {
  2023. return this._setTimelineOption(option);
  2024. }
  2025. },
  2026. _setOption: function (option, notMerge) {
  2027. if (!notMerge && this._option) {
  2028. this._option = zrUtil.merge(this.getOption(), zrUtil.clone(option), true);
  2029. } else {
  2030. this._option = zrUtil.clone(option);
  2031. }
  2032. this._optionRestore = zrUtil.clone(this._option);
  2033. if (!this._option.series || this._option.series.length === 0) {
  2034. this._zr.clear();
  2035. return;
  2036. }
  2037. 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)) {
  2038. this.component.dataZoom.syncOption(this._option);
  2039. }
  2040. this._toolbox.reset(this._option);
  2041. this._render(this._option);
  2042. return this;
  2043. },
  2044. getOption: function () {
  2045. var magicOption = zrUtil.clone(this._option);
  2046. var self = this;
  2047. function restoreOption(prop) {
  2048. var restoreSource = self._optionRestore[prop];
  2049. if (restoreSource) {
  2050. if (restoreSource instanceof Array) {
  2051. var len = restoreSource.length;
  2052. while (len--) {
  2053. magicOption[prop][len].data = zrUtil.clone(restoreSource[len].data);
  2054. }
  2055. } else {
  2056. magicOption[prop].data = zrUtil.clone(restoreSource.data);
  2057. }
  2058. }
  2059. }
  2060. restoreOption('xAxis');
  2061. restoreOption('yAxis');
  2062. restoreOption('series');
  2063. return magicOption;
  2064. },
  2065. setSeries: function (series, notMerge) {
  2066. if (!notMerge) {
  2067. this.setOption({ series: series });
  2068. } else {
  2069. this._option.series = series;
  2070. this.setOption(this._option, notMerge);
  2071. }
  2072. return this;
  2073. },
  2074. getSeries: function () {
  2075. return this.getOption().series;
  2076. },
  2077. _setTimelineOption: function (option) {
  2078. this._timeline && this._timeline.dispose();
  2079. var Timeline = require('./component/timeline');
  2080. var timeline = new Timeline(this._themeConfig, this._messageCenter, this._zr, option, this);
  2081. this._timeline = timeline;
  2082. this.component.timeline = this._timeline;
  2083. return this;
  2084. },
  2085. addData: function (seriesIdx, data, isHead, dataGrow, additionData) {
  2086. var params = seriesIdx instanceof Array ? seriesIdx : [[
  2087. seriesIdx,
  2088. data,
  2089. isHead,
  2090. dataGrow,
  2091. additionData
  2092. ]];
  2093. var magicOption = this.getOption();
  2094. var optionRestore = this._optionRestore;
  2095. for (var i = 0, l = params.length; i < l; i++) {
  2096. seriesIdx = params[i][0];
  2097. data = params[i][1];
  2098. isHead = params[i][2];
  2099. dataGrow = params[i][3];
  2100. additionData = params[i][4];
  2101. var seriesItem = optionRestore.series[seriesIdx];
  2102. var inMethod = isHead ? 'unshift' : 'push';
  2103. var outMethod = isHead ? 'pop' : 'shift';
  2104. if (seriesItem) {
  2105. var seriesItemData = seriesItem.data;
  2106. var mSeriesItemData = magicOption.series[seriesIdx].data;
  2107. seriesItemData[inMethod](data);
  2108. mSeriesItemData[inMethod](data);
  2109. if (!dataGrow) {
  2110. seriesItemData[outMethod]();
  2111. data = mSeriesItemData[outMethod]();
  2112. }
  2113. if (additionData != null) {
  2114. var legend;
  2115. var legendData;
  2116. if (seriesItem.type === ecConfig.CHART_TYPE_PIE && (legend = optionRestore.legend) && (legendData = legend.data)) {
  2117. var mLegendData = magicOption.legend.data;
  2118. legendData[inMethod](additionData);
  2119. mLegendData[inMethod](additionData);
  2120. if (!dataGrow) {
  2121. var legendDataIdx = zrUtil.indexOf(legendData, data.name);
  2122. legendDataIdx != -1 && legendData.splice(legendDataIdx, 1);
  2123. legendDataIdx = zrUtil.indexOf(mLegendData, data.name);
  2124. legendDataIdx != -1 && mLegendData.splice(legendDataIdx, 1);
  2125. }
  2126. } else if (optionRestore.xAxis != null && optionRestore.yAxis != null) {
  2127. var axisData;
  2128. var mAxisData;
  2129. var axisIdx = seriesItem.xAxisIndex || 0;
  2130. if (optionRestore.xAxis[axisIdx].type == null || optionRestore.xAxis[axisIdx].type === 'category') {
  2131. axisData = optionRestore.xAxis[axisIdx].data;
  2132. mAxisData = magicOption.xAxis[axisIdx].data;
  2133. axisData[inMethod](additionData);
  2134. mAxisData[inMethod](additionData);
  2135. if (!dataGrow) {
  2136. axisData[outMethod]();
  2137. mAxisData[outMethod]();
  2138. }
  2139. }
  2140. axisIdx = seriesItem.yAxisIndex || 0;
  2141. if (optionRestore.yAxis[axisIdx].type === 'category') {
  2142. axisData = optionRestore.yAxis[axisIdx].data;
  2143. mAxisData = magicOption.yAxis[axisIdx].data;
  2144. axisData[inMethod](additionData);
  2145. mAxisData[inMethod](additionData);
  2146. if (!dataGrow) {
  2147. axisData[outMethod]();
  2148. mAxisData[outMethod]();
  2149. }
  2150. }
  2151. }
  2152. }
  2153. this._option.series[seriesIdx].data = magicOption.series[seriesIdx].data;
  2154. }
  2155. }
  2156. this._zr.clearAnimation();
  2157. var chartList = this._chartList;
  2158. var chartAnimationCount = 0;
  2159. var chartAnimationDone = function () {
  2160. chartAnimationCount--;
  2161. if (chartAnimationCount === 0) {
  2162. animationDone();
  2163. }
  2164. };
  2165. for (var i = 0, l = chartList.length; i < l; i++) {
  2166. if (magicOption.addDataAnimation && chartList[i].addDataAnimation) {
  2167. chartAnimationCount++;
  2168. chartList[i].addDataAnimation(params, chartAnimationDone);
  2169. }
  2170. }
  2171. this.component.dataZoom && this.component.dataZoom.syncOption(magicOption);
  2172. this._option = magicOption;
  2173. var self = this;
  2174. function animationDone() {
  2175. if (!self._zr) {
  2176. return;
  2177. }
  2178. self._zr.clearAnimation();
  2179. for (var i = 0, l = chartList.length; i < l; i++) {
  2180. chartList[i].motionlessOnce = magicOption.addDataAnimation && chartList[i].addDataAnimation;
  2181. }
  2182. self._messageCenter.dispatch(ecConfig.EVENT.REFRESH, null, { option: magicOption }, self);
  2183. }
  2184. if (!magicOption.addDataAnimation) {
  2185. setTimeout(animationDone, 0);
  2186. }
  2187. return this;
  2188. },
  2189. addMarkPoint: function (seriesIdx, markData) {
  2190. return this._addMark(seriesIdx, markData, 'markPoint');
  2191. },
  2192. addMarkLine: function (seriesIdx, markData) {
  2193. return this._addMark(seriesIdx, markData, 'markLine');
  2194. },
  2195. _addMark: function (seriesIdx, markData, markType) {
  2196. var series = this._option.series;
  2197. var seriesItem;
  2198. if (series && (seriesItem = series[seriesIdx])) {
  2199. var seriesR = this._optionRestore.series;
  2200. var seriesRItem = seriesR[seriesIdx];
  2201. var markOpt = seriesItem[markType];
  2202. var markOptR = seriesRItem[markType];
  2203. markOpt = seriesItem[markType] = markOpt || { data: [] };
  2204. markOptR = seriesRItem[markType] = markOptR || { data: [] };
  2205. for (var key in markData) {
  2206. if (key === 'data') {
  2207. markOpt.data = markOpt.data.concat(markData.data);
  2208. markOptR.data = markOptR.data.concat(markData.data);
  2209. } else if (typeof markData[key] != 'object' || markOpt[key] == null) {
  2210. markOpt[key] = markOptR[key] = markData[key];
  2211. } else {
  2212. zrUtil.merge(markOpt[key], markData[key], true);
  2213. zrUtil.merge(markOptR[key], markData[key], true);
  2214. }
  2215. }
  2216. var chart = this.chart[seriesItem.type];
  2217. chart && chart.addMark(seriesIdx, markData, markType);
  2218. }
  2219. return this;
  2220. },
  2221. delMarkPoint: function (seriesIdx, markName) {
  2222. return this._delMark(seriesIdx, markName, 'markPoint');
  2223. },
  2224. delMarkLine: function (seriesIdx, markName) {
  2225. return this._delMark(seriesIdx, markName, 'markLine');
  2226. },
  2227. _delMark: function (seriesIdx, markName, markType) {
  2228. var series = this._option.series;
  2229. var seriesItem;
  2230. var mark;
  2231. var dataArray;
  2232. if (!(series && (seriesItem = series[seriesIdx]) && (mark = seriesItem[markType]) && (dataArray = mark.data))) {
  2233. return this;
  2234. }
  2235. markName = markName.split(' > ');
  2236. var targetIndex = -1;
  2237. for (var i = 0, l = dataArray.length; i < l; i++) {
  2238. var dataItem = dataArray[i];
  2239. if (dataItem instanceof Array) {
  2240. if (dataItem[0].name === markName[0] && dataItem[1].name === markName[1]) {
  2241. targetIndex = i;
  2242. break;
  2243. }
  2244. } else if (dataItem.name === markName[0]) {
  2245. targetIndex = i;
  2246. break;
  2247. }
  2248. }
  2249. if (targetIndex > -1) {
  2250. dataArray.splice(targetIndex, 1);
  2251. this._optionRestore.series[seriesIdx][markType].data.splice(targetIndex, 1);
  2252. var chart = this.chart[seriesItem.type];
  2253. chart && chart.delMark(seriesIdx, markName.join(' > '), markType);
  2254. }
  2255. return this;
  2256. },
  2257. getDom: function () {
  2258. return this.dom;
  2259. },
  2260. getZrender: function () {
  2261. return this._zr;
  2262. },
  2263. getDataURL: function (imgType) {
  2264. if (!_canvasSupported) {
  2265. return '';
  2266. }
  2267. if (this._chartList.length === 0) {
  2268. var imgId = 'IMG' + this.id;
  2269. var img = document.getElementById(imgId);
  2270. if (img) {
  2271. return img.src;
  2272. }
  2273. }
  2274. var tooltip = this.component.tooltip;
  2275. tooltip && tooltip.hideTip();
  2276. switch (imgType) {
  2277. case 'jpeg':
  2278. break;
  2279. default:
  2280. imgType = 'png';
  2281. }
  2282. var bgColor = this._option.backgroundColor;
  2283. if (bgColor && bgColor.replace(' ', '') === 'rgba(0,0,0,0)') {
  2284. bgColor = '#fff';
  2285. }
  2286. return this._zr.toDataURL('image/' + imgType, bgColor);
  2287. },
  2288. getImage: function (imgType) {
  2289. var title = this._optionRestore.title;
  2290. var imgDom = document.createElement('img');
  2291. imgDom.src = this.getDataURL(imgType);
  2292. imgDom.title = title && title.text || 'ECharts';
  2293. return imgDom;
  2294. },
  2295. getConnectedDataURL: function (imgType) {
  2296. if (!this.isConnected()) {
  2297. return this.getDataURL(imgType);
  2298. }
  2299. var tempDom = this.dom;
  2300. var imgList = {
  2301. 'self': {
  2302. img: this.getDataURL(imgType),
  2303. left: tempDom.offsetLeft,
  2304. top: tempDom.offsetTop,
  2305. right: tempDom.offsetLeft + tempDom.offsetWidth,
  2306. bottom: tempDom.offsetTop + tempDom.offsetHeight
  2307. }
  2308. };
  2309. var minLeft = imgList.self.left;
  2310. var minTop = imgList.self.top;
  2311. var maxRight = imgList.self.right;
  2312. var maxBottom = imgList.self.bottom;
  2313. for (var c in this._connected) {
  2314. tempDom = this._connected[c].getDom();
  2315. imgList[c] = {
  2316. img: this._connected[c].getDataURL(imgType),
  2317. left: tempDom.offsetLeft,
  2318. top: tempDom.offsetTop,
  2319. right: tempDom.offsetLeft + tempDom.offsetWidth,
  2320. bottom: tempDom.offsetTop + tempDom.offsetHeight
  2321. };
  2322. minLeft = Math.min(minLeft, imgList[c].left);
  2323. minTop = Math.min(minTop, imgList[c].top);
  2324. maxRight = Math.max(maxRight, imgList[c].right);
  2325. maxBottom = Math.max(maxBottom, imgList[c].bottom);
  2326. }
  2327. var zrDom = document.createElement('div');
  2328. zrDom.style.position = 'absolute';
  2329. zrDom.style.left = '-4000px';
  2330. zrDom.style.width = maxRight - minLeft + 'px';
  2331. zrDom.style.height = maxBottom - minTop + 'px';
  2332. document.body.appendChild(zrDom);
  2333. var zrImg = require('zrender').init(zrDom);
  2334. var ImageShape = require('zrender/shape/Image');
  2335. for (var c in imgList) {
  2336. zrImg.addShape(new ImageShape({
  2337. style: {
  2338. x: imgList[c].left - minLeft,
  2339. y: imgList[c].top - minTop,
  2340. image: imgList[c].img
  2341. }
  2342. }));
  2343. }
  2344. zrImg.render();
  2345. var bgColor = this._option.backgroundColor;
  2346. if (bgColor && bgColor.replace(/ /g, '') === 'rgba(0,0,0,0)') {
  2347. bgColor = '#fff';
  2348. }
  2349. var image = zrImg.toDataURL('image/png', bgColor);
  2350. setTimeout(function () {
  2351. zrImg.dispose();
  2352. zrDom.parentNode.removeChild(zrDom);
  2353. zrDom = null;
  2354. }, 100);
  2355. return image;
  2356. },
  2357. getConnectedImage: function (imgType) {
  2358. var title = this._optionRestore.title;
  2359. var imgDom = document.createElement('img');
  2360. imgDom.src = this.getConnectedDataURL(imgType);
  2361. imgDom.title = title && title.text || 'ECharts';
  2362. return imgDom;
  2363. },
  2364. on: function (eventName, eventListener) {
  2365. this._messageCenterOutSide.bind(eventName, eventListener, this);
  2366. return this;
  2367. },
  2368. un: function (eventName, eventListener) {
  2369. this._messageCenterOutSide.unbind(eventName, eventListener);
  2370. return this;
  2371. },
  2372. connect: function (connectTarget) {
  2373. if (!connectTarget) {
  2374. return this;
  2375. }
  2376. if (!this._connected) {
  2377. this._connected = {};
  2378. }
  2379. if (connectTarget instanceof Array) {
  2380. for (var i = 0, l = connectTarget.length; i < l; i++) {
  2381. this._connected[connectTarget[i].id] = connectTarget[i];
  2382. }
  2383. } else {
  2384. this._connected[connectTarget.id] = connectTarget;
  2385. }
  2386. return this;
  2387. },
  2388. disConnect: function (connectTarget) {
  2389. if (!connectTarget || !this._connected) {
  2390. return this;
  2391. }
  2392. if (connectTarget instanceof Array) {
  2393. for (var i = 0, l = connectTarget.length; i < l; i++) {
  2394. delete this._connected[connectTarget[i].id];
  2395. }
  2396. } else {
  2397. delete this._connected[connectTarget.id];
  2398. }
  2399. for (var k in this._connected) {
  2400. return k, this;
  2401. }
  2402. this._connected = false;
  2403. return this;
  2404. },
  2405. connectedEventHandler: function (param) {
  2406. if (param.__echartsId != this.id) {
  2407. this._onevent(param);
  2408. }
  2409. },
  2410. isConnected: function () {
  2411. return !!this._connected;
  2412. },
  2413. showLoading: function (loadingOption) {
  2414. var effectList = {
  2415. bar: require('zrender/loadingEffect/Bar'),
  2416. bubble: require('zrender/loadingEffect/Bubble'),
  2417. dynamicLine: require('zrender/loadingEffect/DynamicLine'),
  2418. ring: require('zrender/loadingEffect/Ring'),
  2419. spin: require('zrender/loadingEffect/Spin'),
  2420. whirling: require('zrender/loadingEffect/Whirling')
  2421. };
  2422. this._toolbox.hideDataView();
  2423. loadingOption = loadingOption || {};
  2424. var textStyle = loadingOption.textStyle || {};
  2425. loadingOption.textStyle = textStyle;
  2426. var finalTextStyle = zrUtil.merge(zrUtil.merge(zrUtil.clone(textStyle), this._themeConfig.textStyle), ecConfig.textStyle);
  2427. textStyle.textFont = finalTextStyle.fontStyle + ' ' + finalTextStyle.fontWeight + ' ' + finalTextStyle.fontSize + 'px ' + finalTextStyle.fontFamily;
  2428. textStyle.text = loadingOption.text || this._option && this._option.loadingText || this._themeConfig.loadingText || ecConfig.loadingText;
  2429. if (loadingOption.x != null) {
  2430. textStyle.x = loadingOption.x;
  2431. }
  2432. if (loadingOption.y != null) {
  2433. textStyle.y = loadingOption.y;
  2434. }
  2435. loadingOption.effectOption = loadingOption.effectOption || {};
  2436. loadingOption.effectOption.textStyle = textStyle;
  2437. var Effect = loadingOption.effect;
  2438. if (typeof Effect === 'string' || Effect == null) {
  2439. Effect = effectList[loadingOption.effect || this._option && this._option.loadingEffect || this._themeConfig.loadingEffect || ecConfig.loadingEffect] || effectList.spin;
  2440. }
  2441. this._zr.showLoading(new Effect(loadingOption.effectOption));
  2442. return this;
  2443. },
  2444. hideLoading: function () {
  2445. this._zr.hideLoading();
  2446. return this;
  2447. },
  2448. setTheme: function (theme) {
  2449. if (theme) {
  2450. if (typeof theme === 'string') {
  2451. switch (theme) {
  2452. case 'macarons':
  2453. theme = require('./theme/macarons');
  2454. break;
  2455. case 'infographic':
  2456. theme = require('./theme/infographic');
  2457. break;
  2458. default:
  2459. theme = {};
  2460. }
  2461. } else {
  2462. theme = theme || {};
  2463. }
  2464. this._themeConfig = theme;
  2465. }
  2466. if (!_canvasSupported) {
  2467. var textStyle = this._themeConfig.textStyle;
  2468. textStyle && textStyle.fontFamily && textStyle.fontFamily2 && (textStyle.fontFamily = textStyle.fontFamily2);
  2469. textStyle = ecConfig.textStyle;
  2470. textStyle.fontFamily = textStyle.fontFamily2;
  2471. }
  2472. this._timeline && this._timeline.setTheme(true);
  2473. this._optionRestore && this.restore();
  2474. },
  2475. resize: function () {
  2476. var self = this;
  2477. return function () {
  2478. self._clearEffect();
  2479. self._zr.resize();
  2480. if (self._option && self._option.renderAsImage && _canvasSupported) {
  2481. self._render(self._option);
  2482. return self;
  2483. }
  2484. self._zr.clearAnimation();
  2485. self._island.resize();
  2486. self._toolbox.resize();
  2487. self._timeline && self._timeline.resize();
  2488. for (var i = 0, l = self._chartList.length; i < l; i++) {
  2489. self._chartList[i].resize && self._chartList[i].resize();
  2490. }
  2491. self.component.grid && self.component.grid.refixAxisShape(self.component);
  2492. self._zr.refresh();
  2493. self._messageCenter.dispatch(ecConfig.EVENT.RESIZE, null, null, self);
  2494. return self;
  2495. };
  2496. },
  2497. _clearEffect: function () {
  2498. this._zr.modLayer(ecConfig.EFFECT_ZLEVEL, { motionBlur: false });
  2499. this._zr.painter.clearLayer(ecConfig.EFFECT_ZLEVEL);
  2500. },
  2501. clear: function () {
  2502. this._disposeChartList();
  2503. this._zr.clear();
  2504. this._option = {};
  2505. this._optionRestore = {};
  2506. this.dom.style.backgroundColor = null;
  2507. return this;
  2508. },
  2509. dispose: function () {
  2510. var key = this.dom.getAttribute(DOM_ATTRIBUTE_KEY);
  2511. key && delete _instances[key];
  2512. this._island.dispose();
  2513. this._toolbox.dispose();
  2514. this._timeline && this._timeline.dispose();
  2515. this._messageCenter.unbind();
  2516. this.clear();
  2517. this._zr.dispose();
  2518. this._zr = null;
  2519. }
  2520. };
  2521. return self;
  2522. });define('echarts/config', [], function () {
  2523. var config = {
  2524. CHART_TYPE_LINE: 'line',
  2525. CHART_TYPE_BAR: 'bar',
  2526. CHART_TYPE_SCATTER: 'scatter',
  2527. CHART_TYPE_PIE: 'pie',
  2528. CHART_TYPE_RADAR: 'radar',
  2529. CHART_TYPE_MAP: 'map',
  2530. CHART_TYPE_K: 'k',
  2531. CHART_TYPE_ISLAND: 'island',
  2532. CHART_TYPE_FORCE: 'force',
  2533. CHART_TYPE_CHORD: 'chord',
  2534. CHART_TYPE_GAUGE: 'gauge',
  2535. CHART_TYPE_FUNNEL: 'funnel',
  2536. CHART_TYPE_EVENTRIVER: 'eventRiver',
  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. symbolList: [
  2675. 'circle',
  2676. 'rectangle',
  2677. 'triangle',
  2678. 'diamond',
  2679. 'emptyCircle',
  2680. 'emptyRectangle',
  2681. 'emptyTriangle',
  2682. 'emptyDiamond'
  2683. ],
  2684. loadingEffect: 'spin',
  2685. loadingText: '数据读取中...',
  2686. noDataEffect: 'bubble',
  2687. noDataText: '暂无数据',
  2688. calculable: false,
  2689. calculableColor: 'rgba(255,165,0,0.6)',
  2690. calculableHolderColor: '#ccc',
  2691. nameConnector: ' & ',
  2692. valueConnector: ': ',
  2693. animation: true,
  2694. addDataAnimation: true,
  2695. animationThreshold: 2000,
  2696. animationDuration: 2000,
  2697. animationDurationUpdate: 500,
  2698. animationEasing: 'ExponentialOut'
  2699. };
  2700. return config;
  2701. });define('zrender/tool/util', [
  2702. 'require',
  2703. '../dep/excanvas'
  2704. ], function (require) {
  2705. var BUILTIN_OBJECT = {
  2706. '[object Function]': 1,
  2707. '[object RegExp]': 1,
  2708. '[object Date]': 1,
  2709. '[object Error]': 1,
  2710. '[object CanvasGradient]': 1
  2711. };
  2712. var objToString = Object.prototype.toString;
  2713. function isDom(obj) {
  2714. return obj && obj.nodeType === 1 && typeof obj.nodeName == 'string';
  2715. }
  2716. function clone(source) {
  2717. if (typeof source == 'object' && source !== null) {
  2718. var result = source;
  2719. if (source instanceof Array) {
  2720. result = [];
  2721. for (var i = 0, len = source.length; i < len; i++) {
  2722. result[i] = clone(source[i]);
  2723. }
  2724. } else if (!BUILTIN_OBJECT[objToString.call(source)] && !isDom(source)) {
  2725. result = {};
  2726. for (var key in source) {
  2727. if (source.hasOwnProperty(key)) {
  2728. result[key] = clone(source[key]);
  2729. }
  2730. }
  2731. }
  2732. return result;
  2733. }
  2734. return source;
  2735. }
  2736. function mergeItem(target, source, key, overwrite) {
  2737. if (source.hasOwnProperty(key)) {
  2738. var targetProp = target[key];
  2739. if (typeof targetProp == 'object' && !BUILTIN_OBJECT[objToString.call(targetProp)] && !isDom(targetProp)) {
  2740. merge(target[key], source[key], overwrite);
  2741. } else if (overwrite || !(key in target)) {
  2742. target[key] = source[key];
  2743. }
  2744. }
  2745. }
  2746. function merge(target, source, overwrite) {
  2747. for (var i in source) {
  2748. mergeItem(target, source, i, overwrite);
  2749. }
  2750. return target;
  2751. }
  2752. var _ctx;
  2753. function getContext() {
  2754. if (!_ctx) {
  2755. require('../dep/excanvas');
  2756. if (window['G_vmlCanvasManager']) {
  2757. var _div = document.createElement('div');
  2758. _div.style.position = 'absolute';
  2759. _div.style.top = '-1000px';
  2760. document.body.appendChild(_div);
  2761. _ctx = G_vmlCanvasManager.initElement(_div).getContext('2d');
  2762. } else {
  2763. _ctx = document.createElement('canvas').getContext('2d');
  2764. }
  2765. }
  2766. return _ctx;
  2767. }
  2768. var _canvas;
  2769. var _pixelCtx;
  2770. var _width;
  2771. var _height;
  2772. var _offsetX = 0;
  2773. var _offsetY = 0;
  2774. function getPixelContext() {
  2775. if (!_pixelCtx) {
  2776. _canvas = document.createElement('canvas');
  2777. _width = _canvas.width;
  2778. _height = _canvas.height;
  2779. _pixelCtx = _canvas.getContext('2d');
  2780. }
  2781. return _pixelCtx;
  2782. }
  2783. function adjustCanvasSize(x, y) {
  2784. var _v = 100;
  2785. var _flag;
  2786. if (x + _offsetX > _width) {
  2787. _width = x + _offsetX + _v;
  2788. _canvas.width = _width;
  2789. _flag = true;
  2790. }
  2791. if (y + _offsetY > _height) {
  2792. _height = y + _offsetY + _v;
  2793. _canvas.height = _height;
  2794. _flag = true;
  2795. }
  2796. if (x < -_offsetX) {
  2797. _offsetX = Math.ceil(-x / _v) * _v;
  2798. _width += _offsetX;
  2799. _canvas.width = _width;
  2800. _flag = true;
  2801. }
  2802. if (y < -_offsetY) {
  2803. _offsetY = Math.ceil(-y / _v) * _v;
  2804. _height += _offsetY;
  2805. _canvas.height = _height;
  2806. _flag = true;
  2807. }
  2808. if (_flag) {
  2809. _pixelCtx.translate(_offsetX, _offsetY);
  2810. }
  2811. }
  2812. function getPixelOffset() {
  2813. return {
  2814. x: _offsetX,
  2815. y: _offsetY
  2816. };
  2817. }
  2818. function indexOf(array, value) {
  2819. if (array.indexOf) {
  2820. return array.indexOf(value);
  2821. }
  2822. for (var i = 0, len = array.length; i < len; i++) {
  2823. if (array[i] === value) {
  2824. return i;
  2825. }
  2826. }
  2827. return -1;
  2828. }
  2829. function inherits(clazz, baseClazz) {
  2830. var clazzPrototype = clazz.prototype;
  2831. function F() {
  2832. }
  2833. F.prototype = baseClazz.prototype;
  2834. clazz.prototype = new F();
  2835. for (var prop in clazzPrototype) {
  2836. clazz.prototype[prop] = clazzPrototype[prop];
  2837. }
  2838. clazz.constructor = clazz;
  2839. }
  2840. return {
  2841. inherits: inherits,
  2842. clone: clone,
  2843. merge: merge,
  2844. getContext: getContext,
  2845. getPixelContext: getPixelContext,
  2846. getPixelOffset: getPixelOffset,
  2847. adjustCanvasSize: adjustCanvasSize,
  2848. indexOf: indexOf
  2849. };
  2850. });define('zrender/tool/event', [
  2851. 'require',
  2852. '../mixin/Eventful'
  2853. ], function (require) {
  2854. 'use strict';
  2855. var Eventful = require('../mixin/Eventful');
  2856. function getX(e) {
  2857. 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;
  2858. }
  2859. function getY(e) {
  2860. 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;
  2861. }
  2862. function getDelta(e) {
  2863. return typeof e.zrenderDelta != 'undefined' && e.zrenderDelta || typeof e.wheelDelta != 'undefined' && e.wheelDelta || typeof e.detail != 'undefined' && -e.detail;
  2864. }
  2865. var stop = typeof window.addEventListener === 'function' ? function (e) {
  2866. e.preventDefault();
  2867. e.stopPropagation();
  2868. e.cancelBubble = true;
  2869. } : function (e) {
  2870. e.returnValue = false;
  2871. e.cancelBubble = true;
  2872. };
  2873. return {
  2874. getX: getX,
  2875. getY: getY,
  2876. getDelta: getDelta,
  2877. stop: stop,
  2878. Dispatcher: Eventful
  2879. };
  2880. });define('zrender/tool/env', [], function () {
  2881. function detect(ua) {
  2882. var os = this.os = {};
  2883. var browser = this.browser = {};
  2884. var webkit = ua.match(/Web[kK]it[\/]{0,1}([\d.]+)/);
  2885. var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
  2886. var ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
  2887. var ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
  2888. var iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/);
  2889. var webos = ua.match(/(webOS|hpwOS)[\s\/]([\d.]+)/);
  2890. var touchpad = webos && ua.match(/TouchPad/);
  2891. var kindle = ua.match(/Kindle\/([\d.]+)/);
  2892. var silk = ua.match(/Silk\/([\d._]+)/);
  2893. var blackberry = ua.match(/(BlackBerry).*Version\/([\d.]+)/);
  2894. var bb10 = ua.match(/(BB10).*Version\/([\d.]+)/);
  2895. var rimtabletos = ua.match(/(RIM\sTablet\sOS)\s([\d.]+)/);
  2896. var playbook = ua.match(/PlayBook/);
  2897. var chrome = ua.match(/Chrome\/([\d.]+)/) || ua.match(/CriOS\/([\d.]+)/);
  2898. var firefox = ua.match(/Firefox\/([\d.]+)/);
  2899. var ie = ua.match(/MSIE ([\d.]+)/);
  2900. var safari = webkit && ua.match(/Mobile\//) && !chrome;
  2901. var webview = ua.match(/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/) && !chrome;
  2902. var ie = ua.match(/MSIE\s([\d.]+)/);
  2903. if (browser.webkit = !!webkit)
  2904. browser.version = webkit[1];
  2905. if (android)
  2906. os.android = true, os.version = android[2];
  2907. if (iphone && !ipod)
  2908. os.ios = os.iphone = true, os.version = iphone[2].replace(/_/g, '.');
  2909. if (ipad)
  2910. os.ios = os.ipad = true, os.version = ipad[2].replace(/_/g, '.');
  2911. if (ipod)
  2912. os.ios = os.ipod = true, os.version = ipod[3] ? ipod[3].replace(/_/g, '.') : null;
  2913. if (webos)
  2914. os.webos = true, os.version = webos[2];
  2915. if (touchpad)
  2916. os.touchpad = true;
  2917. if (blackberry)
  2918. os.blackberry = true, os.version = blackberry[2];
  2919. if (bb10)
  2920. os.bb10 = true, os.version = bb10[2];
  2921. if (rimtabletos)
  2922. os.rimtabletos = true, os.version = rimtabletos[2];
  2923. if (playbook)
  2924. browser.playbook = true;
  2925. if (kindle)
  2926. os.kindle = true, os.version = kindle[1];
  2927. if (silk)
  2928. browser.silk = true, browser.version = silk[1];
  2929. if (!silk && os.android && ua.match(/Kindle Fire/))
  2930. browser.silk = true;
  2931. if (chrome)
  2932. browser.chrome = true, browser.version = chrome[1];
  2933. if (firefox)
  2934. browser.firefox = true, browser.version = firefox[1];
  2935. if (ie)
  2936. browser.ie = true, browser.version = ie[1];
  2937. if (safari && (ua.match(/Safari/) || !!os.ios))
  2938. browser.safari = true;
  2939. if (webview)
  2940. browser.webview = true;
  2941. if (ie)
  2942. browser.ie = true, browser.version = ie[1];
  2943. os.tablet = !!(ipad || playbook || android && !ua.match(/Mobile/) || firefox && ua.match(/Tablet/) || ie && !ua.match(/Phone/) && ua.match(/Touch/));
  2944. 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/)));
  2945. return {
  2946. browser: browser,
  2947. os: os,
  2948. canvasSupported: document.createElement('canvas').getContext ? true : false
  2949. };
  2950. }
  2951. return detect(navigator.userAgent);
  2952. });define('zrender', ['zrender/zrender'], function (main) {return main;});
  2953. define('zrender/zrender', [
  2954. 'require',
  2955. './dep/excanvas',
  2956. './tool/util',
  2957. './tool/log',
  2958. './tool/guid',
  2959. './Handler',
  2960. './Painter',
  2961. './Storage',
  2962. './animation/Animation',
  2963. './tool/env'
  2964. ], function (require) {
  2965. require('./dep/excanvas');
  2966. var util = require('./tool/util');
  2967. var log = require('./tool/log');
  2968. var guid = require('./tool/guid');
  2969. var Handler = require('./Handler');
  2970. var Painter = require('./Painter');
  2971. var Storage = require('./Storage');
  2972. var Animation = require('./animation/Animation');
  2973. var _instances = {};
  2974. var zrender = {};
  2975. zrender.version = '2.0.8';
  2976. zrender.init = function (dom) {
  2977. var zr = new ZRender(guid(), dom);
  2978. _instances[zr.id] = zr;
  2979. return zr;
  2980. };
  2981. zrender.dispose = function (zr) {
  2982. if (zr) {
  2983. zr.dispose();
  2984. } else {
  2985. for (var key in _instances) {
  2986. _instances[key].dispose();
  2987. }
  2988. _instances = {};
  2989. }
  2990. return zrender;
  2991. };
  2992. zrender.getInstance = function (id) {
  2993. return _instances[id];
  2994. };
  2995. zrender.delInstance = function (id) {
  2996. delete _instances[id];
  2997. return zrender;
  2998. };
  2999. function getFrameCallback(zrInstance) {
  3000. return function () {
  3001. var animatingElements = zrInstance.animatingElements;
  3002. for (var i = 0, l = animatingElements.length; i < l; i++) {
  3003. zrInstance.storage.mod(animatingElements[i].id);
  3004. }
  3005. if (animatingElements.length || zrInstance._needsRefreshNextFrame) {
  3006. zrInstance.refresh();
  3007. }
  3008. };
  3009. }
  3010. var ZRender = function (id, dom) {
  3011. this.id = id;
  3012. this.env = require('./tool/env');
  3013. this.storage = new Storage();
  3014. this.painter = new Painter(dom, this.storage);
  3015. this.handler = new Handler(dom, this.storage, this.painter);
  3016. this.animatingElements = [];
  3017. this.animation = new Animation({ stage: { update: getFrameCallback(this) } });
  3018. this.animation.start();
  3019. var self = this;
  3020. this.painter.refreshNextFrame = function () {
  3021. self.refreshNextFrame();
  3022. };
  3023. this._needsRefreshNextFrame = false;
  3024. var self = this;
  3025. var storage = this.storage;
  3026. var oldDelFromMap = storage.delFromMap;
  3027. storage.delFromMap = function (elId) {
  3028. var el = storage.get(elId);
  3029. self.stopAnimation(el);
  3030. oldDelFromMap.call(storage, elId);
  3031. };
  3032. };
  3033. ZRender.prototype.getId = function () {
  3034. return this.id;
  3035. };
  3036. ZRender.prototype.addShape = function (shape) {
  3037. this.addElement(shape);
  3038. return this;
  3039. };
  3040. ZRender.prototype.addGroup = function (group) {
  3041. this.addElement(group);
  3042. return this;
  3043. };
  3044. ZRender.prototype.delShape = function (shapeId) {
  3045. this.delElement(shapeId);
  3046. return this;
  3047. };
  3048. ZRender.prototype.delGroup = function (groupId) {
  3049. this.delElement(groupId);
  3050. return this;
  3051. };
  3052. ZRender.prototype.modShape = function (shapeId, shape) {
  3053. this.modElement(shapeId, shape);
  3054. return this;
  3055. };
  3056. ZRender.prototype.modGroup = function (groupId, group) {
  3057. this.modElement(groupId, group);
  3058. return this;
  3059. };
  3060. ZRender.prototype.addElement = function (el) {
  3061. this.storage.addRoot(el);
  3062. this._needsRefreshNextFrame = true;
  3063. return this;
  3064. };
  3065. ZRender.prototype.delElement = function (el) {
  3066. this.storage.delRoot(el);
  3067. this._needsRefreshNextFrame = true;
  3068. return this;
  3069. };
  3070. ZRender.prototype.modElement = function (el, params) {
  3071. this.storage.mod(el, params);
  3072. this._needsRefreshNextFrame = true;
  3073. return this;
  3074. };
  3075. ZRender.prototype.modLayer = function (zLevel, config) {
  3076. this.painter.modLayer(zLevel, config);
  3077. this._needsRefreshNextFrame = true;
  3078. return this;
  3079. };
  3080. ZRender.prototype.addHoverShape = function (shape) {
  3081. this.storage.addHover(shape);
  3082. return this;
  3083. };
  3084. ZRender.prototype.render = function (callback) {
  3085. this.painter.render(callback);
  3086. this._needsRefreshNextFrame = false;
  3087. return this;
  3088. };
  3089. ZRender.prototype.refresh = function (callback) {
  3090. this.painter.refresh(callback);
  3091. this._needsRefreshNextFrame = false;
  3092. return this;
  3093. };
  3094. ZRender.prototype.refreshNextFrame = function () {
  3095. this._needsRefreshNextFrame = true;
  3096. return this;
  3097. };
  3098. ZRender.prototype.refreshHover = function (callback) {
  3099. this.painter.refreshHover(callback);
  3100. return this;
  3101. };
  3102. ZRender.prototype.refreshShapes = function (shapeList, callback) {
  3103. this.painter.refreshShapes(shapeList, callback);
  3104. return this;
  3105. };
  3106. ZRender.prototype.resize = function () {
  3107. this.painter.resize();
  3108. return this;
  3109. };
  3110. ZRender.prototype.animate = function (el, path, loop) {
  3111. if (typeof el === 'string') {
  3112. el = this.storage.get(el);
  3113. }
  3114. if (el) {
  3115. var target;
  3116. if (path) {
  3117. var pathSplitted = path.split('.');
  3118. var prop = el;
  3119. for (var i = 0, l = pathSplitted.length; i < l; i++) {
  3120. if (!prop) {
  3121. continue;
  3122. }
  3123. prop = prop[pathSplitted[i]];
  3124. }
  3125. if (prop) {
  3126. target = prop;
  3127. }
  3128. } else {
  3129. target = el;
  3130. }
  3131. if (!target) {
  3132. log('Property "' + path + '" is not existed in element ' + el.id);
  3133. return;
  3134. }
  3135. var animatingElements = this.animatingElements;
  3136. if (el.__animators == null) {
  3137. el.__animators = [];
  3138. }
  3139. var animators = el.__animators;
  3140. if (animators.length === 0) {
  3141. animatingElements.push(el);
  3142. }
  3143. var animator = this.animation.animate(target, { loop: loop }).done(function () {
  3144. var idx = util.indexOf(el.__animators, animator);
  3145. if (idx >= 0) {
  3146. animators.splice(idx, 1);
  3147. }
  3148. if (animators.length === 0) {
  3149. var idx = util.indexOf(animatingElements, el);
  3150. animatingElements.splice(idx, 1);
  3151. }
  3152. });
  3153. animators.push(animator);
  3154. return animator;
  3155. } else {
  3156. log('Element not existed');
  3157. }
  3158. };
  3159. ZRender.prototype.stopAnimation = function (el) {
  3160. if (el.__animators) {
  3161. var animators = el.__animators;
  3162. var len = animators.length;
  3163. for (var i = 0; i < len; i++) {
  3164. animators[i].stop();
  3165. }
  3166. if (len > 0) {
  3167. var animatingElements = this.animatingElements;
  3168. var idx = util.indexOf(animatingElements, el);
  3169. if (idx >= 0) {
  3170. animatingElements.splice(idx, 1);
  3171. }
  3172. }
  3173. animators.length = 0;
  3174. }
  3175. return this;
  3176. };
  3177. ZRender.prototype.clearAnimation = function () {
  3178. this.animation.clear();
  3179. this.animatingElements.length = 0;
  3180. return this;
  3181. };
  3182. ZRender.prototype.showLoading = function (loadingEffect) {
  3183. this.painter.showLoading(loadingEffect);
  3184. return this;
  3185. };
  3186. ZRender.prototype.hideLoading = function () {
  3187. this.painter.hideLoading();
  3188. return this;
  3189. };
  3190. ZRender.prototype.getWidth = function () {
  3191. return this.painter.getWidth();
  3192. };
  3193. ZRender.prototype.getHeight = function () {
  3194. return this.painter.getHeight();
  3195. };
  3196. ZRender.prototype.toDataURL = function (type, backgroundColor, args) {
  3197. return this.painter.toDataURL(type, backgroundColor, args);
  3198. };
  3199. ZRender.prototype.shapeToImage = function (e, width, height) {
  3200. var id = guid();
  3201. return this.painter.shapeToImage(id, e, width, height);
  3202. };
  3203. ZRender.prototype.on = function (eventName, eventHandler, context) {
  3204. this.handler.on(eventName, eventHandler, context);
  3205. return this;
  3206. };
  3207. ZRender.prototype.un = function (eventName, eventHandler) {
  3208. this.handler.un(eventName, eventHandler);
  3209. return this;
  3210. };
  3211. ZRender.prototype.trigger = function (eventName, event) {
  3212. this.handler.trigger(eventName, event);
  3213. return this;
  3214. };
  3215. ZRender.prototype.clear = function () {
  3216. this.storage.delRoot();
  3217. this.painter.clear();
  3218. return this;
  3219. };
  3220. ZRender.prototype.dispose = function () {
  3221. this.animation.stop();
  3222. this.clear();
  3223. this.storage.dispose();
  3224. this.painter.dispose();
  3225. this.handler.dispose();
  3226. this.animation = this.animatingElements = this.storage = this.painter = this.handler = null;
  3227. zrender.delInstance(this.id);
  3228. };
  3229. return zrender;
  3230. });define('zrender/config', [], function () {
  3231. var config = {
  3232. EVENT: {
  3233. RESIZE: 'resize',
  3234. CLICK: 'click',
  3235. DBLCLICK: 'dblclick',
  3236. MOUSEWHEEL: 'mousewheel',
  3237. MOUSEMOVE: 'mousemove',
  3238. MOUSEOVER: 'mouseover',
  3239. MOUSEOUT: 'mouseout',
  3240. MOUSEDOWN: 'mousedown',
  3241. MOUSEUP: 'mouseup',
  3242. GLOBALOUT: 'globalout',
  3243. DRAGSTART: 'dragstart',
  3244. DRAGEND: 'dragend',
  3245. DRAGENTER: 'dragenter',
  3246. DRAGOVER: 'dragover',
  3247. DRAGLEAVE: 'dragleave',
  3248. DROP: 'drop',
  3249. touchClickDelay: 300
  3250. },
  3251. catchBrushException: false,
  3252. debugMode: 0,
  3253. devicePixelRatio: Math.max(window.devicePixelRatio || 1, 1)
  3254. };
  3255. return config;
  3256. });define('echarts/chart/island', [
  3257. 'require',
  3258. './base',
  3259. 'zrender/shape/Circle',
  3260. '../config',
  3261. '../util/ecData',
  3262. 'zrender/tool/util',
  3263. 'zrender/tool/event',
  3264. 'zrender/tool/color',
  3265. '../util/accMath',
  3266. '../chart'
  3267. ], function (require) {
  3268. var ChartBase = require('./base');
  3269. var CircleShape = require('zrender/shape/Circle');
  3270. var ecConfig = require('../config');
  3271. ecConfig.island = {
  3272. zlevel: 0,
  3273. z: 5,
  3274. r: 15,
  3275. calculateStep: 0.1
  3276. };
  3277. var ecData = require('../util/ecData');
  3278. var zrUtil = require('zrender/tool/util');
  3279. var zrEvent = require('zrender/tool/event');
  3280. function Island(ecTheme, messageCenter, zr, option, myChart) {
  3281. ChartBase.call(this, ecTheme, messageCenter, zr, option, myChart);
  3282. this._nameConnector;
  3283. this._valueConnector;
  3284. this._zrHeight = this.zr.getHeight();
  3285. this._zrWidth = this.zr.getWidth();
  3286. var self = this;
  3287. self.shapeHandler.onmousewheel = function (param) {
  3288. var shape = param.target;
  3289. var event = param.event;
  3290. var delta = zrEvent.getDelta(event);
  3291. delta = delta > 0 ? -1 : 1;
  3292. shape.style.r -= delta;
  3293. shape.style.r = shape.style.r < 5 ? 5 : shape.style.r;
  3294. var value = ecData.get(shape, 'value');
  3295. var dvalue = value * self.option.island.calculateStep;
  3296. value = dvalue > 1 ? Math.round(value - dvalue * delta) : +(value - dvalue * delta).toFixed(2);
  3297. var name = ecData.get(shape, 'name');
  3298. shape.style.text = name + ':' + value;
  3299. ecData.set(shape, 'value', value);
  3300. ecData.set(shape, 'name', name);
  3301. self.zr.modShape(shape.id);
  3302. self.zr.refreshNextFrame();
  3303. zrEvent.stop(event);
  3304. };
  3305. }
  3306. Island.prototype = {
  3307. type: ecConfig.CHART_TYPE_ISLAND,
  3308. _combine: function (tarShape, srcShape) {
  3309. var zrColor = require('zrender/tool/color');
  3310. var accMath = require('../util/accMath');
  3311. var value = accMath.accAdd(ecData.get(tarShape, 'value'), ecData.get(srcShape, 'value'));
  3312. var name = ecData.get(tarShape, 'name') + this._nameConnector + ecData.get(srcShape, 'name');
  3313. tarShape.style.text = name + this._valueConnector + value;
  3314. ecData.set(tarShape, 'value', value);
  3315. ecData.set(tarShape, 'name', name);
  3316. tarShape.style.r = this.option.island.r;
  3317. tarShape.style.color = zrColor.mix(tarShape.style.color, srcShape.style.color);
  3318. },
  3319. refresh: function (newOption) {
  3320. if (newOption) {
  3321. newOption.island = this.reformOption(newOption.island);
  3322. this.option = newOption;
  3323. this._nameConnector = this.option.nameConnector;
  3324. this._valueConnector = this.option.valueConnector;
  3325. }
  3326. },
  3327. getOption: function () {
  3328. return this.option;
  3329. },
  3330. resize: function () {
  3331. var newWidth = this.zr.getWidth();
  3332. var newHieght = this.zr.getHeight();
  3333. var xScale = newWidth / (this._zrWidth || newWidth);
  3334. var yScale = newHieght / (this._zrHeight || newHieght);
  3335. if (xScale === 1 && yScale === 1) {
  3336. return;
  3337. }
  3338. this._zrWidth = newWidth;
  3339. this._zrHeight = newHieght;
  3340. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  3341. this.zr.modShape(this.shapeList[i].id, {
  3342. style: {
  3343. x: Math.round(this.shapeList[i].style.x * xScale),
  3344. y: Math.round(this.shapeList[i].style.y * yScale)
  3345. }
  3346. });
  3347. }
  3348. },
  3349. add: function (shape) {
  3350. var name = ecData.get(shape, 'name');
  3351. var value = ecData.get(shape, 'value');
  3352. var seriesName = ecData.get(shape, 'series') != null ? ecData.get(shape, 'series').name : '';
  3353. var font = this.getFont(this.option.island.textStyle);
  3354. var islandShape = {
  3355. zlevel: this.getZlevelBase(),
  3356. z: this.getZBase(),
  3357. style: {
  3358. x: shape.style.x,
  3359. y: shape.style.y,
  3360. r: this.option.island.r,
  3361. color: shape.style.color || shape.style.strokeColor,
  3362. text: name + this._valueConnector + value,
  3363. textFont: font
  3364. },
  3365. draggable: true,
  3366. hoverable: true,
  3367. onmousewheel: this.shapeHandler.onmousewheel,
  3368. _type: 'island'
  3369. };
  3370. if (islandShape.style.color === '#fff') {
  3371. islandShape.style.color = shape.style.strokeColor;
  3372. }
  3373. this.setCalculable(islandShape);
  3374. islandShape.dragEnableTime = 0;
  3375. ecData.pack(islandShape, { name: seriesName }, -1, value, -1, name);
  3376. islandShape = new CircleShape(islandShape);
  3377. this.shapeList.push(islandShape);
  3378. this.zr.addShape(islandShape);
  3379. },
  3380. del: function (shape) {
  3381. this.zr.delShape(shape.id);
  3382. var newShapeList = [];
  3383. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  3384. if (this.shapeList[i].id != shape.id) {
  3385. newShapeList.push(this.shapeList[i]);
  3386. }
  3387. }
  3388. this.shapeList = newShapeList;
  3389. },
  3390. ondrop: function (param, status) {
  3391. if (!this.isDrop || !param.target) {
  3392. return;
  3393. }
  3394. var target = param.target;
  3395. var dragged = param.dragged;
  3396. this._combine(target, dragged);
  3397. this.zr.modShape(target.id);
  3398. status.dragIn = true;
  3399. this.isDrop = false;
  3400. return;
  3401. },
  3402. ondragend: function (param, status) {
  3403. var target = param.target;
  3404. if (!this.isDragend) {
  3405. if (!status.dragIn) {
  3406. target.style.x = zrEvent.getX(param.event);
  3407. target.style.y = zrEvent.getY(param.event);
  3408. this.add(target);
  3409. status.needRefresh = true;
  3410. }
  3411. } else {
  3412. if (status.dragIn) {
  3413. this.del(target);
  3414. status.needRefresh = true;
  3415. }
  3416. }
  3417. this.isDragend = false;
  3418. return;
  3419. }
  3420. };
  3421. zrUtil.inherits(Island, ChartBase);
  3422. require('../chart').define('island', Island);
  3423. return Island;
  3424. });define('echarts/component/toolbox', [
  3425. 'require',
  3426. './base',
  3427. 'zrender/shape/Line',
  3428. 'zrender/shape/Image',
  3429. 'zrender/shape/Rectangle',
  3430. '../util/shape/Icon',
  3431. '../config',
  3432. 'zrender/tool/util',
  3433. 'zrender/config',
  3434. 'zrender/tool/event',
  3435. './dataView',
  3436. '../component'
  3437. ], function (require) {
  3438. var Base = require('./base');
  3439. var LineShape = require('zrender/shape/Line');
  3440. var ImageShape = require('zrender/shape/Image');
  3441. var RectangleShape = require('zrender/shape/Rectangle');
  3442. var IconShape = require('../util/shape/Icon');
  3443. var ecConfig = require('../config');
  3444. ecConfig.toolbox = {
  3445. zlevel: 0,
  3446. z: 6,
  3447. show: false,
  3448. orient: 'horizontal',
  3449. x: 'right',
  3450. y: 'top',
  3451. color: [
  3452. '#1e90ff',
  3453. '#22bb22',
  3454. '#4b0082',
  3455. '#d2691e'
  3456. ],
  3457. disableColor: '#ddd',
  3458. effectiveColor: 'red',
  3459. backgroundColor: 'rgba(0,0,0,0)',
  3460. borderColor: '#ccc',
  3461. borderWidth: 0,
  3462. padding: 5,
  3463. itemGap: 10,
  3464. itemSize: 16,
  3465. showTitle: true,
  3466. feature: {
  3467. mark: {
  3468. show: false,
  3469. title: {
  3470. mark: '辅助线开关',
  3471. markUndo: '删除辅助线',
  3472. markClear: '清空辅助线'
  3473. },
  3474. lineStyle: {
  3475. width: 1,
  3476. color: '#1e90ff',
  3477. type: 'dashed'
  3478. }
  3479. },
  3480. dataZoom: {
  3481. show: false,
  3482. title: {
  3483. dataZoom: '区域缩放',
  3484. dataZoomReset: '区域缩放后退'
  3485. }
  3486. },
  3487. dataView: {
  3488. show: false,
  3489. title: '数据视图',
  3490. readOnly: false,
  3491. lang: [
  3492. '数据视图',
  3493. '关闭',
  3494. '刷新'
  3495. ]
  3496. },
  3497. magicType: {
  3498. show: false,
  3499. title: {
  3500. line: '折线图切换',
  3501. bar: '柱形图切换',
  3502. stack: '堆积',
  3503. tiled: '平铺',
  3504. force: '力导向布局图切换',
  3505. chord: '和弦图切换',
  3506. pie: '饼图切换',
  3507. funnel: '漏斗图切换'
  3508. },
  3509. type: []
  3510. },
  3511. restore: {
  3512. show: false,
  3513. title: '还原'
  3514. },
  3515. saveAsImage: {
  3516. show: false,
  3517. title: '保存为图片',
  3518. type: 'png',
  3519. lang: ['点击保存']
  3520. }
  3521. }
  3522. };
  3523. var zrUtil = require('zrender/tool/util');
  3524. var zrConfig = require('zrender/config');
  3525. var zrEvent = require('zrender/tool/event');
  3526. var _MAGICTYPE_STACK = 'stack';
  3527. var _MAGICTYPE_TILED = 'tiled';
  3528. function Toolbox(ecTheme, messageCenter, zr, option, myChart) {
  3529. Base.call(this, ecTheme, messageCenter, zr, option, myChart);
  3530. this.dom = myChart.dom;
  3531. this._magicType = {};
  3532. this._magicMap = {};
  3533. this._isSilence = false;
  3534. this._iconList;
  3535. this._iconShapeMap = {};
  3536. this._featureTitle = {};
  3537. this._featureIcon = {};
  3538. this._featureColor = {};
  3539. this._featureOption = {};
  3540. this._enableColor = 'red';
  3541. this._disableColor = '#ccc';
  3542. this._markShapeList = [];
  3543. var self = this;
  3544. self._onMark = function (param) {
  3545. self.__onMark(param);
  3546. };
  3547. self._onMarkUndo = function (param) {
  3548. self.__onMarkUndo(param);
  3549. };
  3550. self._onMarkClear = function (param) {
  3551. self.__onMarkClear(param);
  3552. };
  3553. self._onDataZoom = function (param) {
  3554. self.__onDataZoom(param);
  3555. };
  3556. self._onDataZoomReset = function (param) {
  3557. self.__onDataZoomReset(param);
  3558. };
  3559. self._onDataView = function (param) {
  3560. self.__onDataView(param);
  3561. };
  3562. self._onRestore = function (param) {
  3563. self.__onRestore(param);
  3564. };
  3565. self._onSaveAsImage = function (param) {
  3566. self.__onSaveAsImage(param);
  3567. };
  3568. self._onMagicType = function (param) {
  3569. self.__onMagicType(param);
  3570. };
  3571. self._onCustomHandler = function (param) {
  3572. self.__onCustomHandler(param);
  3573. };
  3574. self._onmousemove = function (param) {
  3575. return self.__onmousemove(param);
  3576. };
  3577. self._onmousedown = function (param) {
  3578. return self.__onmousedown(param);
  3579. };
  3580. self._onmouseup = function (param) {
  3581. return self.__onmouseup(param);
  3582. };
  3583. self._onclick = function (param) {
  3584. return self.__onclick(param);
  3585. };
  3586. }
  3587. Toolbox.prototype = {
  3588. type: ecConfig.COMPONENT_TYPE_TOOLBOX,
  3589. _buildShape: function () {
  3590. this._iconList = [];
  3591. var toolboxOption = this.option.toolbox;
  3592. this._enableColor = toolboxOption.effectiveColor;
  3593. this._disableColor = toolboxOption.disableColor;
  3594. var feature = toolboxOption.feature;
  3595. var iconName = [];
  3596. for (var key in feature) {
  3597. if (feature[key].show) {
  3598. switch (key) {
  3599. case 'mark':
  3600. iconName.push({
  3601. key: key,
  3602. name: 'mark'
  3603. });
  3604. iconName.push({
  3605. key: key,
  3606. name: 'markUndo'
  3607. });
  3608. iconName.push({
  3609. key: key,
  3610. name: 'markClear'
  3611. });
  3612. break;
  3613. case 'magicType':
  3614. for (var i = 0, l = feature[key].type.length; i < l; i++) {
  3615. feature[key].title[feature[key].type[i] + 'Chart'] = feature[key].title[feature[key].type[i]];
  3616. if (feature[key].option) {
  3617. feature[key].option[feature[key].type[i] + 'Chart'] = feature[key].option[feature[key].type[i]];
  3618. }
  3619. iconName.push({
  3620. key: key,
  3621. name: feature[key].type[i] + 'Chart'
  3622. });
  3623. }
  3624. break;
  3625. case 'dataZoom':
  3626. iconName.push({
  3627. key: key,
  3628. name: 'dataZoom'
  3629. });
  3630. iconName.push({
  3631. key: key,
  3632. name: 'dataZoomReset'
  3633. });
  3634. break;
  3635. case 'saveAsImage':
  3636. if (this.canvasSupported) {
  3637. iconName.push({
  3638. key: key,
  3639. name: 'saveAsImage'
  3640. });
  3641. }
  3642. break;
  3643. default:
  3644. iconName.push({
  3645. key: key,
  3646. name: key
  3647. });
  3648. break;
  3649. }
  3650. }
  3651. }
  3652. if (iconName.length > 0) {
  3653. var name;
  3654. var key;
  3655. for (var i = 0, l = iconName.length; i < l; i++) {
  3656. name = iconName[i].name;
  3657. key = iconName[i].key;
  3658. this._iconList.push(name);
  3659. this._featureTitle[name] = feature[key].title[name] || feature[key].title;
  3660. if (feature[key].icon) {
  3661. this._featureIcon[name] = feature[key].icon[name] || feature[key].icon;
  3662. }
  3663. if (feature[key].color) {
  3664. this._featureColor[name] = feature[key].color[name] || feature[key].color;
  3665. }
  3666. if (feature[key].option) {
  3667. this._featureOption[name] = feature[key].option[name] || feature[key].option;
  3668. }
  3669. }
  3670. this._itemGroupLocation = this._getItemGroupLocation();
  3671. this._buildBackground();
  3672. this._buildItem();
  3673. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  3674. this.zr.addShape(this.shapeList[i]);
  3675. }
  3676. if (this._iconShapeMap['mark']) {
  3677. this._iconDisable(this._iconShapeMap['markUndo']);
  3678. this._iconDisable(this._iconShapeMap['markClear']);
  3679. }
  3680. if (this._iconShapeMap['dataZoomReset'] && this._zoomQueue.length === 0) {
  3681. this._iconDisable(this._iconShapeMap['dataZoomReset']);
  3682. }
  3683. }
  3684. },
  3685. _buildItem: function () {
  3686. var toolboxOption = this.option.toolbox;
  3687. var iconLength = this._iconList.length;
  3688. var lastX = this._itemGroupLocation.x;
  3689. var lastY = this._itemGroupLocation.y;
  3690. var itemSize = toolboxOption.itemSize;
  3691. var itemGap = toolboxOption.itemGap;
  3692. var itemShape;
  3693. var color = toolboxOption.color instanceof Array ? toolboxOption.color : [toolboxOption.color];
  3694. var textFont = this.getFont(toolboxOption.textStyle);
  3695. var textPosition;
  3696. var textAlign;
  3697. var textBaseline;
  3698. if (toolboxOption.orient === 'horizontal') {
  3699. textPosition = this._itemGroupLocation.y / this.zr.getHeight() < 0.5 ? 'bottom' : 'top';
  3700. textAlign = this._itemGroupLocation.x / this.zr.getWidth() < 0.5 ? 'left' : 'right';
  3701. textBaseline = this._itemGroupLocation.y / this.zr.getHeight() < 0.5 ? 'top' : 'bottom';
  3702. } else {
  3703. textPosition = this._itemGroupLocation.x / this.zr.getWidth() < 0.5 ? 'right' : 'left';
  3704. }
  3705. this._iconShapeMap = {};
  3706. var self = this;
  3707. for (var i = 0; i < iconLength; i++) {
  3708. itemShape = {
  3709. type: 'icon',
  3710. zlevel: this.getZlevelBase(),
  3711. z: this.getZBase(),
  3712. style: {
  3713. x: lastX,
  3714. y: lastY,
  3715. width: itemSize,
  3716. height: itemSize,
  3717. iconType: this._iconList[i],
  3718. lineWidth: 1,
  3719. strokeColor: this._featureColor[this._iconList[i]] || color[i % color.length],
  3720. brushType: 'stroke'
  3721. },
  3722. highlightStyle: {
  3723. lineWidth: 1,
  3724. text: toolboxOption.showTitle ? this._featureTitle[this._iconList[i]] : undefined,
  3725. textFont: textFont,
  3726. textPosition: textPosition,
  3727. strokeColor: this._featureColor[this._iconList[i]] || color[i % color.length]
  3728. },
  3729. hoverable: true,
  3730. clickable: true
  3731. };
  3732. if (this._featureIcon[this._iconList[i]]) {
  3733. itemShape.style.image = this._featureIcon[this._iconList[i]].replace(new RegExp('^image:\\/\\/'), '');
  3734. itemShape.style.opacity = 0.8;
  3735. itemShape.highlightStyle.opacity = 1;
  3736. itemShape.type = 'image';
  3737. }
  3738. if (toolboxOption.orient === 'horizontal') {
  3739. if (i === 0 && textAlign === 'left') {
  3740. itemShape.highlightStyle.textPosition = 'specific';
  3741. itemShape.highlightStyle.textAlign = textAlign;
  3742. itemShape.highlightStyle.textBaseline = textBaseline;
  3743. itemShape.highlightStyle.textX = lastX;
  3744. itemShape.highlightStyle.textY = textBaseline === 'top' ? lastY + itemSize + 10 : lastY - 10;
  3745. }
  3746. if (i === iconLength - 1 && textAlign === 'right') {
  3747. itemShape.highlightStyle.textPosition = 'specific';
  3748. itemShape.highlightStyle.textAlign = textAlign;
  3749. itemShape.highlightStyle.textBaseline = textBaseline;
  3750. itemShape.highlightStyle.textX = lastX + itemSize;
  3751. itemShape.highlightStyle.textY = textBaseline === 'top' ? lastY + itemSize + 10 : lastY - 10;
  3752. }
  3753. }
  3754. switch (this._iconList[i]) {
  3755. case 'mark':
  3756. itemShape.onclick = self._onMark;
  3757. break;
  3758. case 'markUndo':
  3759. itemShape.onclick = self._onMarkUndo;
  3760. break;
  3761. case 'markClear':
  3762. itemShape.onclick = self._onMarkClear;
  3763. break;
  3764. case 'dataZoom':
  3765. itemShape.onclick = self._onDataZoom;
  3766. break;
  3767. case 'dataZoomReset':
  3768. itemShape.onclick = self._onDataZoomReset;
  3769. break;
  3770. case 'dataView':
  3771. if (!this._dataView) {
  3772. var DataView = require('./dataView');
  3773. this._dataView = new DataView(this.ecTheme, this.messageCenter, this.zr, this.option, this.myChart);
  3774. }
  3775. itemShape.onclick = self._onDataView;
  3776. break;
  3777. case 'restore':
  3778. itemShape.onclick = self._onRestore;
  3779. break;
  3780. case 'saveAsImage':
  3781. itemShape.onclick = self._onSaveAsImage;
  3782. break;
  3783. default:
  3784. if (this._iconList[i].match('Chart')) {
  3785. itemShape._name = this._iconList[i].replace('Chart', '');
  3786. itemShape.onclick = self._onMagicType;
  3787. } else {
  3788. itemShape.onclick = self._onCustomHandler;
  3789. }
  3790. break;
  3791. }
  3792. if (itemShape.type === 'icon') {
  3793. itemShape = new IconShape(itemShape);
  3794. } else if (itemShape.type === 'image') {
  3795. itemShape = new ImageShape(itemShape);
  3796. }
  3797. this.shapeList.push(itemShape);
  3798. this._iconShapeMap[this._iconList[i]] = itemShape;
  3799. if (toolboxOption.orient === 'horizontal') {
  3800. lastX += itemSize + itemGap;
  3801. } else {
  3802. lastY += itemSize + itemGap;
  3803. }
  3804. }
  3805. },
  3806. _buildBackground: function () {
  3807. var toolboxOption = this.option.toolbox;
  3808. var padding = this.reformCssArray(this.option.toolbox.padding);
  3809. this.shapeList.push(new RectangleShape({
  3810. zlevel: this.getZlevelBase(),
  3811. z: this.getZBase(),
  3812. hoverable: false,
  3813. style: {
  3814. x: this._itemGroupLocation.x - padding[3],
  3815. y: this._itemGroupLocation.y - padding[0],
  3816. width: this._itemGroupLocation.width + padding[3] + padding[1],
  3817. height: this._itemGroupLocation.height + padding[0] + padding[2],
  3818. brushType: toolboxOption.borderWidth === 0 ? 'fill' : 'both',
  3819. color: toolboxOption.backgroundColor,
  3820. strokeColor: toolboxOption.borderColor,
  3821. lineWidth: toolboxOption.borderWidth
  3822. }
  3823. }));
  3824. },
  3825. _getItemGroupLocation: function () {
  3826. var toolboxOption = this.option.toolbox;
  3827. var padding = this.reformCssArray(this.option.toolbox.padding);
  3828. var iconLength = this._iconList.length;
  3829. var itemGap = toolboxOption.itemGap;
  3830. var itemSize = toolboxOption.itemSize;
  3831. var totalWidth = 0;
  3832. var totalHeight = 0;
  3833. if (toolboxOption.orient === 'horizontal') {
  3834. totalWidth = (itemSize + itemGap) * iconLength - itemGap;
  3835. totalHeight = itemSize;
  3836. } else {
  3837. totalHeight = (itemSize + itemGap) * iconLength - itemGap;
  3838. totalWidth = itemSize;
  3839. }
  3840. var x;
  3841. var zrWidth = this.zr.getWidth();
  3842. switch (toolboxOption.x) {
  3843. case 'center':
  3844. x = Math.floor((zrWidth - totalWidth) / 2);
  3845. break;
  3846. case 'left':
  3847. x = padding[3] + toolboxOption.borderWidth;
  3848. break;
  3849. case 'right':
  3850. x = zrWidth - totalWidth - padding[1] - toolboxOption.borderWidth;
  3851. break;
  3852. default:
  3853. x = toolboxOption.x - 0;
  3854. x = isNaN(x) ? 0 : x;
  3855. break;
  3856. }
  3857. var y;
  3858. var zrHeight = this.zr.getHeight();
  3859. switch (toolboxOption.y) {
  3860. case 'top':
  3861. y = padding[0] + toolboxOption.borderWidth;
  3862. break;
  3863. case 'bottom':
  3864. y = zrHeight - totalHeight - padding[2] - toolboxOption.borderWidth;
  3865. break;
  3866. case 'center':
  3867. y = Math.floor((zrHeight - totalHeight) / 2);
  3868. break;
  3869. default:
  3870. y = toolboxOption.y - 0;
  3871. y = isNaN(y) ? 0 : y;
  3872. break;
  3873. }
  3874. return {
  3875. x: x,
  3876. y: y,
  3877. width: totalWidth,
  3878. height: totalHeight
  3879. };
  3880. },
  3881. __onmousemove: function (param) {
  3882. if (this._marking) {
  3883. this._markShape.style.xEnd = zrEvent.getX(param.event);
  3884. this._markShape.style.yEnd = zrEvent.getY(param.event);
  3885. this.zr.addHoverShape(this._markShape);
  3886. }
  3887. if (this._zooming) {
  3888. this._zoomShape.style.width = zrEvent.getX(param.event) - this._zoomShape.style.x;
  3889. this._zoomShape.style.height = zrEvent.getY(param.event) - this._zoomShape.style.y;
  3890. this.zr.addHoverShape(this._zoomShape);
  3891. this.dom.style.cursor = 'crosshair';
  3892. zrEvent.stop(param.event);
  3893. }
  3894. if (this._zoomStart && (this.dom.style.cursor != 'pointer' && this.dom.style.cursor != 'move')) {
  3895. this.dom.style.cursor = 'crosshair';
  3896. }
  3897. },
  3898. __onmousedown: function (param) {
  3899. if (param.target) {
  3900. return;
  3901. }
  3902. this._zooming = true;
  3903. var x = zrEvent.getX(param.event);
  3904. var y = zrEvent.getY(param.event);
  3905. var zoomOption = this.option.dataZoom || {};
  3906. this._zoomShape = new RectangleShape({
  3907. zlevel: this.getZlevelBase(),
  3908. z: this.getZBase(),
  3909. style: {
  3910. x: x,
  3911. y: y,
  3912. width: 1,
  3913. height: 1,
  3914. brushType: 'both'
  3915. },
  3916. highlightStyle: {
  3917. lineWidth: 2,
  3918. color: zoomOption.fillerColor || ecConfig.dataZoom.fillerColor,
  3919. strokeColor: zoomOption.handleColor || ecConfig.dataZoom.handleColor,
  3920. brushType: 'both'
  3921. }
  3922. });
  3923. this.zr.addHoverShape(this._zoomShape);
  3924. return true;
  3925. },
  3926. __onmouseup: function () {
  3927. if (!this._zoomShape || Math.abs(this._zoomShape.style.width) < 10 || Math.abs(this._zoomShape.style.height) < 10) {
  3928. this._zooming = false;
  3929. return true;
  3930. }
  3931. if (this._zooming && this.component.dataZoom) {
  3932. this._zooming = false;
  3933. var zoom = this.component.dataZoom.rectZoom(this._zoomShape.style);
  3934. if (zoom) {
  3935. this._zoomQueue.push({
  3936. start: zoom.start,
  3937. end: zoom.end,
  3938. start2: zoom.start2,
  3939. end2: zoom.end2
  3940. });
  3941. this._iconEnable(this._iconShapeMap['dataZoomReset']);
  3942. this.zr.refreshNextFrame();
  3943. }
  3944. }
  3945. return true;
  3946. },
  3947. __onclick: function (param) {
  3948. if (param.target) {
  3949. return;
  3950. }
  3951. if (this._marking) {
  3952. this._marking = false;
  3953. this._markShapeList.push(this._markShape);
  3954. this._iconEnable(this._iconShapeMap['markUndo']);
  3955. this._iconEnable(this._iconShapeMap['markClear']);
  3956. this.zr.addShape(this._markShape);
  3957. this.zr.refreshNextFrame();
  3958. } else if (this._markStart) {
  3959. this._marking = true;
  3960. var x = zrEvent.getX(param.event);
  3961. var y = zrEvent.getY(param.event);
  3962. this._markShape = new LineShape({
  3963. zlevel: this.getZlevelBase(),
  3964. z: this.getZBase(),
  3965. style: {
  3966. xStart: x,
  3967. yStart: y,
  3968. xEnd: x,
  3969. yEnd: y,
  3970. lineWidth: this.query(this.option, 'toolbox.feature.mark.lineStyle.width'),
  3971. strokeColor: this.query(this.option, 'toolbox.feature.mark.lineStyle.color'),
  3972. lineType: this.query(this.option, 'toolbox.feature.mark.lineStyle.type')
  3973. }
  3974. });
  3975. this.zr.addHoverShape(this._markShape);
  3976. }
  3977. },
  3978. __onMark: function (param) {
  3979. var target = param.target;
  3980. if (this._marking || this._markStart) {
  3981. this._resetMark();
  3982. this.zr.refreshNextFrame();
  3983. } else {
  3984. this._resetZoom();
  3985. this.zr.modShape(target.id, { style: { strokeColor: this._enableColor } });
  3986. this.zr.refreshNextFrame();
  3987. this._markStart = true;
  3988. var self = this;
  3989. setTimeout(function () {
  3990. self.zr && self.zr.on(zrConfig.EVENT.CLICK, self._onclick) && self.zr.on(zrConfig.EVENT.MOUSEMOVE, self._onmousemove);
  3991. }, 10);
  3992. }
  3993. return true;
  3994. },
  3995. __onMarkUndo: function () {
  3996. if (this._marking) {
  3997. this._marking = false;
  3998. } else {
  3999. var len = this._markShapeList.length;
  4000. if (len >= 1) {
  4001. var target = this._markShapeList[len - 1];
  4002. this.zr.delShape(target.id);
  4003. this.zr.refreshNextFrame();
  4004. this._markShapeList.pop();
  4005. if (len === 1) {
  4006. this._iconDisable(this._iconShapeMap['markUndo']);
  4007. this._iconDisable(this._iconShapeMap['markClear']);
  4008. }
  4009. }
  4010. }
  4011. return true;
  4012. },
  4013. __onMarkClear: function () {
  4014. if (this._marking) {
  4015. this._marking = false;
  4016. }
  4017. var len = this._markShapeList.length;
  4018. if (len > 0) {
  4019. while (len--) {
  4020. this.zr.delShape(this._markShapeList.pop().id);
  4021. }
  4022. this._iconDisable(this._iconShapeMap['markUndo']);
  4023. this._iconDisable(this._iconShapeMap['markClear']);
  4024. this.zr.refreshNextFrame();
  4025. }
  4026. return true;
  4027. },
  4028. __onDataZoom: function (param) {
  4029. var target = param.target;
  4030. if (this._zooming || this._zoomStart) {
  4031. this._resetZoom();
  4032. this.zr.refreshNextFrame();
  4033. this.dom.style.cursor = 'default';
  4034. } else {
  4035. this._resetMark();
  4036. this.zr.modShape(target.id, { style: { strokeColor: this._enableColor } });
  4037. this.zr.refreshNextFrame();
  4038. this._zoomStart = true;
  4039. var self = this;
  4040. setTimeout(function () {
  4041. 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);
  4042. }, 10);
  4043. this.dom.style.cursor = 'crosshair';
  4044. }
  4045. return true;
  4046. },
  4047. __onDataZoomReset: function () {
  4048. if (this._zooming) {
  4049. this._zooming = false;
  4050. }
  4051. this._zoomQueue.pop();
  4052. if (this._zoomQueue.length > 0) {
  4053. this.component.dataZoom.absoluteZoom(this._zoomQueue[this._zoomQueue.length - 1]);
  4054. } else {
  4055. this.component.dataZoom.rectZoom();
  4056. this._iconDisable(this._iconShapeMap['dataZoomReset']);
  4057. this.zr.refreshNextFrame();
  4058. }
  4059. return true;
  4060. },
  4061. _resetMark: function () {
  4062. this._marking = false;
  4063. if (this._markStart) {
  4064. this._markStart = false;
  4065. if (this._iconShapeMap['mark']) {
  4066. this.zr.modShape(this._iconShapeMap['mark'].id, { style: { strokeColor: this._iconShapeMap['mark'].highlightStyle.strokeColor } });
  4067. }
  4068. this.zr.un(zrConfig.EVENT.CLICK, this._onclick);
  4069. this.zr.un(zrConfig.EVENT.MOUSEMOVE, this._onmousemove);
  4070. }
  4071. },
  4072. _resetZoom: function () {
  4073. this._zooming = false;
  4074. if (this._zoomStart) {
  4075. this._zoomStart = false;
  4076. if (this._iconShapeMap['dataZoom']) {
  4077. this.zr.modShape(this._iconShapeMap['dataZoom'].id, { style: { strokeColor: this._iconShapeMap['dataZoom'].highlightStyle.strokeColor } });
  4078. }
  4079. this.zr.un(zrConfig.EVENT.MOUSEDOWN, this._onmousedown);
  4080. this.zr.un(zrConfig.EVENT.MOUSEUP, this._onmouseup);
  4081. this.zr.un(zrConfig.EVENT.MOUSEMOVE, this._onmousemove);
  4082. }
  4083. },
  4084. _iconDisable: function (target) {
  4085. if (target.type != 'image') {
  4086. this.zr.modShape(target.id, {
  4087. hoverable: false,
  4088. clickable: false,
  4089. style: { strokeColor: this._disableColor }
  4090. });
  4091. } else {
  4092. this.zr.modShape(target.id, {
  4093. hoverable: false,
  4094. clickable: false,
  4095. style: { opacity: 0.3 }
  4096. });
  4097. }
  4098. },
  4099. _iconEnable: function (target) {
  4100. if (target.type != 'image') {
  4101. this.zr.modShape(target.id, {
  4102. hoverable: true,
  4103. clickable: true,
  4104. style: { strokeColor: target.highlightStyle.strokeColor }
  4105. });
  4106. } else {
  4107. this.zr.modShape(target.id, {
  4108. hoverable: true,
  4109. clickable: true,
  4110. style: { opacity: 0.8 }
  4111. });
  4112. }
  4113. },
  4114. __onDataView: function () {
  4115. this._dataView.show(this.option);
  4116. return true;
  4117. },
  4118. __onRestore: function () {
  4119. this._resetMark();
  4120. this._resetZoom();
  4121. this.messageCenter.dispatch(ecConfig.EVENT.RESTORE, null, null, this.myChart);
  4122. return true;
  4123. },
  4124. __onSaveAsImage: function () {
  4125. var saveOption = this.option.toolbox.feature.saveAsImage;
  4126. var imgType = saveOption.type || 'png';
  4127. if (imgType != 'png' && imgType != 'jpeg') {
  4128. imgType = 'png';
  4129. }
  4130. var image;
  4131. if (!this.myChart.isConnected()) {
  4132. image = this.zr.toDataURL('image/' + imgType, this.option.backgroundColor && this.option.backgroundColor.replace(' ', '') === 'rgba(0,0,0,0)' ? '#fff' : this.option.backgroundColor);
  4133. } else {
  4134. image = this.myChart.getConnectedDataURL(imgType);
  4135. }
  4136. var downloadDiv = document.createElement('div');
  4137. downloadDiv.id = '__echarts_download_wrap__';
  4138. 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;';
  4139. var downloadLink = document.createElement('a');
  4140. downloadLink.href = image;
  4141. 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);
  4142. downloadLink.innerHTML = '<img style="vertical-align:middle" src="' + image + '" title="' + (!!window.ActiveXObject || 'ActiveXObject' in window ? '右键->图片另存为' : saveOption.lang ? saveOption.lang[0] : '点击保存') + '"/>';
  4143. downloadDiv.appendChild(downloadLink);
  4144. document.body.appendChild(downloadDiv);
  4145. downloadLink = null;
  4146. downloadDiv = null;
  4147. setTimeout(function () {
  4148. var _d = document.getElementById('__echarts_download_wrap__');
  4149. if (_d) {
  4150. _d.onclick = function () {
  4151. var d = document.getElementById('__echarts_download_wrap__');
  4152. d.onclick = null;
  4153. d.innerHTML = '';
  4154. document.body.removeChild(d);
  4155. d = null;
  4156. };
  4157. _d = null;
  4158. }
  4159. }, 500);
  4160. return;
  4161. },
  4162. __onMagicType: function (param) {
  4163. this._resetMark();
  4164. var itemName = param.target._name;
  4165. if (!this._magicType[itemName]) {
  4166. this._magicType[itemName] = true;
  4167. if (itemName === ecConfig.CHART_TYPE_LINE) {
  4168. this._magicType[ecConfig.CHART_TYPE_BAR] = false;
  4169. } else if (itemName === ecConfig.CHART_TYPE_BAR) {
  4170. this._magicType[ecConfig.CHART_TYPE_LINE] = false;
  4171. }
  4172. if (itemName === ecConfig.CHART_TYPE_PIE) {
  4173. this._magicType[ecConfig.CHART_TYPE_FUNNEL] = false;
  4174. } else if (itemName === ecConfig.CHART_TYPE_FUNNEL) {
  4175. this._magicType[ecConfig.CHART_TYPE_PIE] = false;
  4176. }
  4177. if (itemName === ecConfig.CHART_TYPE_FORCE) {
  4178. this._magicType[ecConfig.CHART_TYPE_CHORD] = false;
  4179. } else if (itemName === ecConfig.CHART_TYPE_CHORD) {
  4180. this._magicType[ecConfig.CHART_TYPE_FORCE] = false;
  4181. }
  4182. if (itemName === _MAGICTYPE_STACK) {
  4183. this._magicType[_MAGICTYPE_TILED] = false;
  4184. } else if (itemName === _MAGICTYPE_TILED) {
  4185. this._magicType[_MAGICTYPE_STACK] = false;
  4186. }
  4187. this.messageCenter.dispatch(ecConfig.EVENT.MAGIC_TYPE_CHANGED, param.event, { magicType: this._magicType }, this.myChart);
  4188. }
  4189. return true;
  4190. },
  4191. setMagicType: function (magicType) {
  4192. this._resetMark();
  4193. this._magicType = magicType;
  4194. !this._isSilence && this.messageCenter.dispatch(ecConfig.EVENT.MAGIC_TYPE_CHANGED, null, { magicType: this._magicType }, this.myChart);
  4195. },
  4196. __onCustomHandler: function (param) {
  4197. var target = param.target.style.iconType;
  4198. var featureHandler = this.option.toolbox.feature[target].onclick;
  4199. if (typeof featureHandler === 'function') {
  4200. featureHandler.call(this, this.option);
  4201. }
  4202. },
  4203. reset: function (newOption, isRestore) {
  4204. isRestore && this.clear();
  4205. if (this.query(newOption, 'toolbox.show') && this.query(newOption, 'toolbox.feature.magicType.show')) {
  4206. var magicType = newOption.toolbox.feature.magicType.type;
  4207. var len = magicType.length;
  4208. this._magicMap = {};
  4209. while (len--) {
  4210. this._magicMap[magicType[len]] = true;
  4211. }
  4212. len = newOption.series.length;
  4213. var oriType;
  4214. var axis;
  4215. while (len--) {
  4216. oriType = newOption.series[len].type;
  4217. if (this._magicMap[oriType]) {
  4218. axis = newOption.xAxis instanceof Array ? newOption.xAxis[newOption.series[len].xAxisIndex || 0] : newOption.xAxis;
  4219. if (axis && (axis.type || 'category') === 'category') {
  4220. axis.__boundaryGap = axis.boundaryGap != null ? axis.boundaryGap : true;
  4221. }
  4222. axis = newOption.yAxis instanceof Array ? newOption.yAxis[newOption.series[len].yAxisIndex || 0] : newOption.yAxis;
  4223. if (axis && axis.type === 'category') {
  4224. axis.__boundaryGap = axis.boundaryGap != null ? axis.boundaryGap : true;
  4225. }
  4226. newOption.series[len].__type = oriType;
  4227. newOption.series[len].__itemStyle = zrUtil.clone(newOption.series[len].itemStyle || {});
  4228. }
  4229. if (this._magicMap[_MAGICTYPE_STACK] || this._magicMap[_MAGICTYPE_TILED]) {
  4230. newOption.series[len].__stack = newOption.series[len].stack;
  4231. }
  4232. }
  4233. }
  4234. this._magicType = isRestore ? {} : this._magicType || {};
  4235. for (var itemName in this._magicType) {
  4236. if (this._magicType[itemName]) {
  4237. this.option = newOption;
  4238. this.getMagicOption();
  4239. break;
  4240. }
  4241. }
  4242. var zoomOption = newOption.dataZoom;
  4243. if (zoomOption && zoomOption.show) {
  4244. var start = zoomOption.start != null && zoomOption.start >= 0 && zoomOption.start <= 100 ? zoomOption.start : 0;
  4245. var end = zoomOption.end != null && zoomOption.end >= 0 && zoomOption.end <= 100 ? zoomOption.end : 100;
  4246. if (start > end) {
  4247. start = start + end;
  4248. end = start - end;
  4249. start = start - end;
  4250. }
  4251. this._zoomQueue = [{
  4252. start: start,
  4253. end: end,
  4254. start2: 0,
  4255. end2: 100
  4256. }];
  4257. } else {
  4258. this._zoomQueue = [];
  4259. }
  4260. },
  4261. getMagicOption: function () {
  4262. var axis;
  4263. var chartType;
  4264. if (this._magicType[ecConfig.CHART_TYPE_LINE] || this._magicType[ecConfig.CHART_TYPE_BAR]) {
  4265. var boundaryGap = this._magicType[ecConfig.CHART_TYPE_LINE] ? false : true;
  4266. for (var i = 0, l = this.option.series.length; i < l; i++) {
  4267. chartType = this.option.series[i].type;
  4268. if (chartType == ecConfig.CHART_TYPE_LINE || chartType == ecConfig.CHART_TYPE_BAR) {
  4269. axis = this.option.xAxis instanceof Array ? this.option.xAxis[this.option.series[i].xAxisIndex || 0] : this.option.xAxis;
  4270. if (axis && (axis.type || 'category') === 'category') {
  4271. axis.boundaryGap = boundaryGap ? true : axis.__boundaryGap;
  4272. }
  4273. axis = this.option.yAxis instanceof Array ? this.option.yAxis[this.option.series[i].yAxisIndex || 0] : this.option.yAxis;
  4274. if (axis && axis.type === 'category') {
  4275. axis.boundaryGap = boundaryGap ? true : axis.__boundaryGap;
  4276. }
  4277. }
  4278. }
  4279. this._defaultMagic(ecConfig.CHART_TYPE_LINE, ecConfig.CHART_TYPE_BAR);
  4280. }
  4281. this._defaultMagic(ecConfig.CHART_TYPE_CHORD, ecConfig.CHART_TYPE_FORCE);
  4282. this._defaultMagic(ecConfig.CHART_TYPE_PIE, ecConfig.CHART_TYPE_FUNNEL);
  4283. if (this._magicType[_MAGICTYPE_STACK] || this._magicType[_MAGICTYPE_TILED]) {
  4284. for (var i = 0, l = this.option.series.length; i < l; i++) {
  4285. if (this._magicType[_MAGICTYPE_STACK]) {
  4286. this.option.series[i].stack = '_ECHARTS_STACK_KENER_2014_';
  4287. chartType = _MAGICTYPE_STACK;
  4288. } else if (this._magicType[_MAGICTYPE_TILED]) {
  4289. this.option.series[i].stack = null;
  4290. chartType = _MAGICTYPE_TILED;
  4291. }
  4292. if (this._featureOption[chartType + 'Chart']) {
  4293. zrUtil.merge(this.option.series[i], this._featureOption[chartType + 'Chart'] || {}, true);
  4294. }
  4295. }
  4296. }
  4297. return this.option;
  4298. },
  4299. _defaultMagic: function (cType1, cType2) {
  4300. if (this._magicType[cType1] || this._magicType[cType2]) {
  4301. for (var i = 0, l = this.option.series.length; i < l; i++) {
  4302. var chartType = this.option.series[i].type;
  4303. if (chartType == cType1 || chartType == cType2) {
  4304. this.option.series[i].type = this._magicType[cType1] ? cType1 : cType2;
  4305. this.option.series[i].itemStyle = zrUtil.clone(this.option.series[i].__itemStyle);
  4306. chartType = this.option.series[i].type;
  4307. if (this._featureOption[chartType + 'Chart']) {
  4308. zrUtil.merge(this.option.series[i], this._featureOption[chartType + 'Chart'] || {}, true);
  4309. }
  4310. }
  4311. }
  4312. }
  4313. },
  4314. silence: function (s) {
  4315. this._isSilence = s;
  4316. },
  4317. resize: function () {
  4318. this._resetMark();
  4319. this.clear();
  4320. if (this.option && this.option.toolbox && this.option.toolbox.show) {
  4321. this._buildShape();
  4322. }
  4323. if (this._dataView) {
  4324. this._dataView.resize();
  4325. }
  4326. },
  4327. hideDataView: function () {
  4328. if (this._dataView) {
  4329. this._dataView.hide();
  4330. }
  4331. },
  4332. clear: function (notMark) {
  4333. if (this.zr) {
  4334. this.zr.delShape(this.shapeList);
  4335. this.shapeList = [];
  4336. if (!notMark) {
  4337. this.zr.delShape(this._markShapeList);
  4338. this._markShapeList = [];
  4339. }
  4340. }
  4341. },
  4342. onbeforDispose: function () {
  4343. if (this._dataView) {
  4344. this._dataView.dispose();
  4345. this._dataView = null;
  4346. }
  4347. this._markShapeList = null;
  4348. },
  4349. refresh: function (newOption) {
  4350. if (newOption) {
  4351. this._resetMark();
  4352. this._resetZoom();
  4353. newOption.toolbox = this.reformOption(newOption.toolbox);
  4354. this.option = newOption;
  4355. this.clear(true);
  4356. if (newOption.toolbox.show) {
  4357. this._buildShape();
  4358. }
  4359. this.hideDataView();
  4360. }
  4361. }
  4362. };
  4363. zrUtil.inherits(Toolbox, Base);
  4364. require('../component').define('toolbox', Toolbox);
  4365. return Toolbox;
  4366. });define('echarts/component', [], function () {
  4367. var self = {};
  4368. var _componentLibrary = {};
  4369. self.define = function (name, clazz) {
  4370. _componentLibrary[name] = clazz;
  4371. return self;
  4372. };
  4373. self.get = function (name) {
  4374. return _componentLibrary[name];
  4375. };
  4376. return self;
  4377. });define('echarts/component/title', [
  4378. 'require',
  4379. './base',
  4380. 'zrender/shape/Text',
  4381. 'zrender/shape/Rectangle',
  4382. '../config',
  4383. 'zrender/tool/util',
  4384. 'zrender/tool/area',
  4385. 'zrender/tool/color',
  4386. '../component'
  4387. ], function (require) {
  4388. var Base = require('./base');
  4389. var TextShape = require('zrender/shape/Text');
  4390. var RectangleShape = require('zrender/shape/Rectangle');
  4391. var ecConfig = require('../config');
  4392. ecConfig.title = {
  4393. zlevel: 0,
  4394. z: 6,
  4395. show: true,
  4396. text: '',
  4397. subtext: '',
  4398. x: 'left',
  4399. y: 'top',
  4400. backgroundColor: 'rgba(0,0,0,0)',
  4401. borderColor: '#ccc',
  4402. borderWidth: 0,
  4403. padding: 5,
  4404. itemGap: 5,
  4405. textStyle: {
  4406. fontSize: 18,
  4407. fontWeight: 'bolder',
  4408. color: '#333'
  4409. },
  4410. subtextStyle: { color: '#aaa' }
  4411. };
  4412. var zrUtil = require('zrender/tool/util');
  4413. var zrArea = require('zrender/tool/area');
  4414. var zrColor = require('zrender/tool/color');
  4415. function Title(ecTheme, messageCenter, zr, option, myChart) {
  4416. Base.call(this, ecTheme, messageCenter, zr, option, myChart);
  4417. this.refresh(option);
  4418. }
  4419. Title.prototype = {
  4420. type: ecConfig.COMPONENT_TYPE_TITLE,
  4421. _buildShape: function () {
  4422. if (!this.titleOption.show) {
  4423. return;
  4424. }
  4425. this._itemGroupLocation = this._getItemGroupLocation();
  4426. this._buildBackground();
  4427. this._buildItem();
  4428. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  4429. this.zr.addShape(this.shapeList[i]);
  4430. }
  4431. },
  4432. _buildItem: function () {
  4433. var text = this.titleOption.text;
  4434. var link = this.titleOption.link;
  4435. var target = this.titleOption.target;
  4436. var subtext = this.titleOption.subtext;
  4437. var sublink = this.titleOption.sublink;
  4438. var subtarget = this.titleOption.subtarget;
  4439. var font = this.getFont(this.titleOption.textStyle);
  4440. var subfont = this.getFont(this.titleOption.subtextStyle);
  4441. var x = this._itemGroupLocation.x;
  4442. var y = this._itemGroupLocation.y;
  4443. var width = this._itemGroupLocation.width;
  4444. var height = this._itemGroupLocation.height;
  4445. var textShape = {
  4446. zlevel: this.getZlevelBase(),
  4447. z: this.getZBase(),
  4448. style: {
  4449. y: y,
  4450. color: this.titleOption.textStyle.color,
  4451. text: text,
  4452. textFont: font,
  4453. textBaseline: 'top'
  4454. },
  4455. highlightStyle: {
  4456. color: zrColor.lift(this.titleOption.textStyle.color, 1),
  4457. brushType: 'fill'
  4458. },
  4459. hoverable: false
  4460. };
  4461. if (link) {
  4462. textShape.hoverable = true;
  4463. textShape.clickable = true;
  4464. textShape.onclick = function () {
  4465. if (!target || target != 'self') {
  4466. window.open(link);
  4467. } else {
  4468. window.location = link;
  4469. }
  4470. };
  4471. }
  4472. var subtextShape = {
  4473. zlevel: this.getZlevelBase(),
  4474. z: this.getZBase(),
  4475. style: {
  4476. y: y + height,
  4477. color: this.titleOption.subtextStyle.color,
  4478. text: subtext,
  4479. textFont: subfont,
  4480. textBaseline: 'bottom'
  4481. },
  4482. highlightStyle: {
  4483. color: zrColor.lift(this.titleOption.subtextStyle.color, 1),
  4484. brushType: 'fill'
  4485. },
  4486. hoverable: false
  4487. };
  4488. if (sublink) {
  4489. subtextShape.hoverable = true;
  4490. subtextShape.clickable = true;
  4491. subtextShape.onclick = function () {
  4492. if (!subtarget || subtarget != 'self') {
  4493. window.open(sublink);
  4494. } else {
  4495. window.location = sublink;
  4496. }
  4497. };
  4498. }
  4499. switch (this.titleOption.x) {
  4500. case 'center':
  4501. textShape.style.x = subtextShape.style.x = x + width / 2;
  4502. textShape.style.textAlign = subtextShape.style.textAlign = 'center';
  4503. break;
  4504. case 'left':
  4505. textShape.style.x = subtextShape.style.x = x;
  4506. textShape.style.textAlign = subtextShape.style.textAlign = 'left';
  4507. break;
  4508. case 'right':
  4509. textShape.style.x = subtextShape.style.x = x + width;
  4510. textShape.style.textAlign = subtextShape.style.textAlign = 'right';
  4511. break;
  4512. default:
  4513. x = this.titleOption.x - 0;
  4514. x = isNaN(x) ? 0 : x;
  4515. textShape.style.x = subtextShape.style.x = x;
  4516. break;
  4517. }
  4518. if (this.titleOption.textAlign) {
  4519. textShape.style.textAlign = subtextShape.style.textAlign = this.titleOption.textAlign;
  4520. }
  4521. this.shapeList.push(new TextShape(textShape));
  4522. subtext !== '' && this.shapeList.push(new TextShape(subtextShape));
  4523. },
  4524. _buildBackground: function () {
  4525. var padding = this.reformCssArray(this.titleOption.padding);
  4526. this.shapeList.push(new RectangleShape({
  4527. zlevel: this.getZlevelBase(),
  4528. z: this.getZBase(),
  4529. hoverable: false,
  4530. style: {
  4531. x: this._itemGroupLocation.x - padding[3],
  4532. y: this._itemGroupLocation.y - padding[0],
  4533. width: this._itemGroupLocation.width + padding[3] + padding[1],
  4534. height: this._itemGroupLocation.height + padding[0] + padding[2],
  4535. brushType: this.titleOption.borderWidth === 0 ? 'fill' : 'both',
  4536. color: this.titleOption.backgroundColor,
  4537. strokeColor: this.titleOption.borderColor,
  4538. lineWidth: this.titleOption.borderWidth
  4539. }
  4540. }));
  4541. },
  4542. _getItemGroupLocation: function () {
  4543. var padding = this.reformCssArray(this.titleOption.padding);
  4544. var text = this.titleOption.text;
  4545. var subtext = this.titleOption.subtext;
  4546. var font = this.getFont(this.titleOption.textStyle);
  4547. var subfont = this.getFont(this.titleOption.subtextStyle);
  4548. var totalWidth = Math.max(zrArea.getTextWidth(text, font), zrArea.getTextWidth(subtext, subfont));
  4549. var totalHeight = zrArea.getTextHeight(text, font) + (subtext === '' ? 0 : this.titleOption.itemGap + zrArea.getTextHeight(subtext, subfont));
  4550. var x;
  4551. var zrWidth = this.zr.getWidth();
  4552. switch (this.titleOption.x) {
  4553. case 'center':
  4554. x = Math.floor((zrWidth - totalWidth) / 2);
  4555. break;
  4556. case 'left':
  4557. x = padding[3] + this.titleOption.borderWidth;
  4558. break;
  4559. case 'right':
  4560. x = zrWidth - totalWidth - padding[1] - this.titleOption.borderWidth;
  4561. break;
  4562. default:
  4563. x = this.titleOption.x - 0;
  4564. x = isNaN(x) ? 0 : x;
  4565. break;
  4566. }
  4567. var y;
  4568. var zrHeight = this.zr.getHeight();
  4569. switch (this.titleOption.y) {
  4570. case 'top':
  4571. y = padding[0] + this.titleOption.borderWidth;
  4572. break;
  4573. case 'bottom':
  4574. y = zrHeight - totalHeight - padding[2] - this.titleOption.borderWidth;
  4575. break;
  4576. case 'center':
  4577. y = Math.floor((zrHeight - totalHeight) / 2);
  4578. break;
  4579. default:
  4580. y = this.titleOption.y - 0;
  4581. y = isNaN(y) ? 0 : y;
  4582. break;
  4583. }
  4584. return {
  4585. x: x,
  4586. y: y,
  4587. width: totalWidth,
  4588. height: totalHeight
  4589. };
  4590. },
  4591. refresh: function (newOption) {
  4592. if (newOption) {
  4593. this.option = newOption;
  4594. this.option.title = this.reformOption(this.option.title);
  4595. this.titleOption = this.option.title;
  4596. this.titleOption.textStyle = this.getTextStyle(this.titleOption.textStyle);
  4597. this.titleOption.subtextStyle = this.getTextStyle(this.titleOption.subtextStyle);
  4598. }
  4599. this.clear();
  4600. this._buildShape();
  4601. }
  4602. };
  4603. zrUtil.inherits(Title, Base);
  4604. require('../component').define('title', Title);
  4605. return Title;
  4606. });define('echarts/component/tooltip', [
  4607. 'require',
  4608. './base',
  4609. '../util/shape/Cross',
  4610. 'zrender/shape/Line',
  4611. 'zrender/shape/Rectangle',
  4612. '../config',
  4613. '../util/ecData',
  4614. 'zrender/config',
  4615. 'zrender/tool/event',
  4616. 'zrender/tool/area',
  4617. 'zrender/tool/color',
  4618. 'zrender/tool/util',
  4619. 'zrender/shape/Base',
  4620. '../component'
  4621. ], function (require) {
  4622. var Base = require('./base');
  4623. var CrossShape = require('../util/shape/Cross');
  4624. var LineShape = require('zrender/shape/Line');
  4625. var RectangleShape = require('zrender/shape/Rectangle');
  4626. var rectangleInstance = new RectangleShape({});
  4627. var ecConfig = require('../config');
  4628. ecConfig.tooltip = {
  4629. zlevel: 1,
  4630. z: 8,
  4631. show: true,
  4632. showContent: true,
  4633. trigger: 'item',
  4634. islandFormatter: '{a} <br/>{b} : {c}',
  4635. showDelay: 20,
  4636. hideDelay: 100,
  4637. transitionDuration: 0.4,
  4638. enterable: false,
  4639. backgroundColor: 'rgba(0,0,0,0.7)',
  4640. borderColor: '#333',
  4641. borderRadius: 4,
  4642. borderWidth: 0,
  4643. padding: 5,
  4644. axisPointer: {
  4645. type: 'line',
  4646. lineStyle: {
  4647. color: '#48b',
  4648. width: 2,
  4649. type: 'solid'
  4650. },
  4651. crossStyle: {
  4652. color: '#1e90ff',
  4653. width: 1,
  4654. type: 'dashed'
  4655. },
  4656. shadowStyle: {
  4657. color: 'rgba(150,150,150,0.3)',
  4658. width: 'auto',
  4659. type: 'default'
  4660. }
  4661. },
  4662. textStyle: { color: '#fff' }
  4663. };
  4664. var ecData = require('../util/ecData');
  4665. var zrConfig = require('zrender/config');
  4666. var zrEvent = require('zrender/tool/event');
  4667. var zrArea = require('zrender/tool/area');
  4668. var zrColor = require('zrender/tool/color');
  4669. var zrUtil = require('zrender/tool/util');
  4670. var zrShapeBase = require('zrender/shape/Base');
  4671. function Tooltip(ecTheme, messageCenter, zr, option, myChart) {
  4672. Base.call(this, ecTheme, messageCenter, zr, option, myChart);
  4673. this.dom = myChart.dom;
  4674. var self = this;
  4675. self._onmousemove = function (param) {
  4676. return self.__onmousemove(param);
  4677. };
  4678. self._onglobalout = function (param) {
  4679. return self.__onglobalout(param);
  4680. };
  4681. this.zr.on(zrConfig.EVENT.MOUSEMOVE, self._onmousemove);
  4682. this.zr.on(zrConfig.EVENT.GLOBALOUT, self._onglobalout);
  4683. self._hide = function (param) {
  4684. return self.__hide(param);
  4685. };
  4686. self._tryShow = function (param) {
  4687. return self.__tryShow(param);
  4688. };
  4689. self._refixed = function (param) {
  4690. return self.__refixed(param);
  4691. };
  4692. self._setContent = function (ticket, res) {
  4693. return self.__setContent(ticket, res);
  4694. };
  4695. this._tDom = this._tDom || document.createElement('div');
  4696. this._tDom.onselectstart = function () {
  4697. return false;
  4698. };
  4699. this._tDom.onmouseover = function () {
  4700. self._mousein = true;
  4701. };
  4702. this._tDom.onmouseout = function () {
  4703. self._mousein = false;
  4704. };
  4705. this._tDom.className = 'echarts-tooltip';
  4706. this._tDom.style.position = 'absolute';
  4707. this.hasAppend = false;
  4708. this._axisLineShape && this.zr.delShape(this._axisLineShape.id);
  4709. this._axisLineShape = new LineShape({
  4710. zlevel: this.getZlevelBase(),
  4711. z: this.getZBase(),
  4712. invisible: true,
  4713. hoverable: false
  4714. });
  4715. this.shapeList.push(this._axisLineShape);
  4716. this.zr.addShape(this._axisLineShape);
  4717. this._axisShadowShape && this.zr.delShape(this._axisShadowShape.id);
  4718. this._axisShadowShape = new LineShape({
  4719. zlevel: this.getZlevelBase(),
  4720. z: 1,
  4721. invisible: true,
  4722. hoverable: false
  4723. });
  4724. this.shapeList.push(this._axisShadowShape);
  4725. this.zr.addShape(this._axisShadowShape);
  4726. this._axisCrossShape && this.zr.delShape(this._axisCrossShape.id);
  4727. this._axisCrossShape = new CrossShape({
  4728. zlevel: this.getZlevelBase(),
  4729. z: this.getZBase(),
  4730. invisible: true,
  4731. hoverable: false
  4732. });
  4733. this.shapeList.push(this._axisCrossShape);
  4734. this.zr.addShape(this._axisCrossShape);
  4735. this.showing = false;
  4736. this.refresh(option);
  4737. }
  4738. Tooltip.prototype = {
  4739. type: ecConfig.COMPONENT_TYPE_TOOLTIP,
  4740. _gCssText: 'position:absolute;display:block;border-style:solid;white-space:nowrap;',
  4741. _style: function (opt) {
  4742. if (!opt) {
  4743. return '';
  4744. }
  4745. var cssText = [];
  4746. if (opt.transitionDuration) {
  4747. var transitionText = 'left ' + opt.transitionDuration + 's,' + 'top ' + opt.transitionDuration + 's';
  4748. cssText.push('transition:' + transitionText);
  4749. cssText.push('-moz-transition:' + transitionText);
  4750. cssText.push('-webkit-transition:' + transitionText);
  4751. cssText.push('-o-transition:' + transitionText);
  4752. }
  4753. if (opt.backgroundColor) {
  4754. cssText.push('background-Color:' + zrColor.toHex(opt.backgroundColor));
  4755. cssText.push('filter:alpha(opacity=70)');
  4756. cssText.push('background-Color:' + opt.backgroundColor);
  4757. }
  4758. if (opt.borderWidth != null) {
  4759. cssText.push('border-width:' + opt.borderWidth + 'px');
  4760. }
  4761. if (opt.borderColor != null) {
  4762. cssText.push('border-color:' + opt.borderColor);
  4763. }
  4764. if (opt.borderRadius != null) {
  4765. cssText.push('border-radius:' + opt.borderRadius + 'px');
  4766. cssText.push('-moz-border-radius:' + opt.borderRadius + 'px');
  4767. cssText.push('-webkit-border-radius:' + opt.borderRadius + 'px');
  4768. cssText.push('-o-border-radius:' + opt.borderRadius + 'px');
  4769. }
  4770. var textStyle = opt.textStyle;
  4771. if (textStyle) {
  4772. textStyle.color && cssText.push('color:' + textStyle.color);
  4773. textStyle.decoration && cssText.push('text-decoration:' + textStyle.decoration);
  4774. textStyle.align && cssText.push('text-align:' + textStyle.align);
  4775. textStyle.fontFamily && cssText.push('font-family:' + textStyle.fontFamily);
  4776. textStyle.fontSize && cssText.push('font-size:' + textStyle.fontSize + 'px');
  4777. textStyle.fontSize && cssText.push('line-height:' + Math.round(textStyle.fontSize * 3 / 2) + 'px');
  4778. textStyle.fontStyle && cssText.push('font-style:' + textStyle.fontStyle);
  4779. textStyle.fontWeight && cssText.push('font-weight:' + textStyle.fontWeight);
  4780. }
  4781. var padding = opt.padding;
  4782. if (padding != null) {
  4783. padding = this.reformCssArray(padding);
  4784. cssText.push('padding:' + padding[0] + 'px ' + padding[1] + 'px ' + padding[2] + 'px ' + padding[3] + 'px');
  4785. }
  4786. cssText = cssText.join(';') + ';';
  4787. return cssText;
  4788. },
  4789. __hide: function () {
  4790. this._lastDataIndex = -1;
  4791. this._lastSeriesIndex = -1;
  4792. this._lastItemTriggerId = -1;
  4793. if (this._tDom) {
  4794. this._tDom.style.display = 'none';
  4795. }
  4796. var needRefresh = false;
  4797. if (!this._axisLineShape.invisible) {
  4798. this._axisLineShape.invisible = true;
  4799. this.zr.modShape(this._axisLineShape.id);
  4800. needRefresh = true;
  4801. }
  4802. if (!this._axisShadowShape.invisible) {
  4803. this._axisShadowShape.invisible = true;
  4804. this.zr.modShape(this._axisShadowShape.id);
  4805. needRefresh = true;
  4806. }
  4807. if (!this._axisCrossShape.invisible) {
  4808. this._axisCrossShape.invisible = true;
  4809. this.zr.modShape(this._axisCrossShape.id);
  4810. needRefresh = true;
  4811. }
  4812. if (this._lastTipShape && this._lastTipShape.tipShape.length > 0) {
  4813. this.zr.delShape(this._lastTipShape.tipShape);
  4814. this._lastTipShape = false;
  4815. this.shapeList.length = 2;
  4816. }
  4817. needRefresh && this.zr.refreshNextFrame();
  4818. this.showing = false;
  4819. },
  4820. _show: function (position, x, y, specialCssText) {
  4821. var domHeight = this._tDom.offsetHeight;
  4822. var domWidth = this._tDom.offsetWidth;
  4823. if (position) {
  4824. if (typeof position === 'function') {
  4825. position = position([
  4826. x,
  4827. y
  4828. ]);
  4829. }
  4830. if (position instanceof Array) {
  4831. x = position[0];
  4832. y = position[1];
  4833. }
  4834. }
  4835. if (x + domWidth > this._zrWidth) {
  4836. x -= domWidth + 40;
  4837. }
  4838. if (y + domHeight > this._zrHeight) {
  4839. y -= domHeight - 20;
  4840. }
  4841. if (y < 20) {
  4842. y = 0;
  4843. }
  4844. this._tDom.style.cssText = this._gCssText + this._defaultCssText + (specialCssText ? specialCssText : '') + 'left:' + x + 'px;top:' + y + 'px;';
  4845. if (domHeight < 10 || domWidth < 10) {
  4846. setTimeout(this._refixed, 20);
  4847. }
  4848. this.showing = true;
  4849. },
  4850. __refixed: function () {
  4851. if (this._tDom) {
  4852. var cssText = '';
  4853. var domHeight = this._tDom.offsetHeight;
  4854. var domWidth = this._tDom.offsetWidth;
  4855. if (this._tDom.offsetLeft + domWidth > this._zrWidth) {
  4856. cssText += 'left:' + (this._zrWidth - domWidth - 20) + 'px;';
  4857. }
  4858. if (this._tDom.offsetTop + domHeight > this._zrHeight) {
  4859. cssText += 'top:' + (this._zrHeight - domHeight - 10) + 'px;';
  4860. }
  4861. if (cssText !== '') {
  4862. this._tDom.style.cssText += cssText;
  4863. }
  4864. }
  4865. },
  4866. __tryShow: function () {
  4867. var needShow;
  4868. var trigger;
  4869. if (!this._curTarget) {
  4870. this._findPolarTrigger() || this._findAxisTrigger();
  4871. } else {
  4872. if (this._curTarget._type === 'island' && this.option.tooltip.show) {
  4873. this._showItemTrigger();
  4874. return;
  4875. }
  4876. var serie = ecData.get(this._curTarget, 'series');
  4877. var data = ecData.get(this._curTarget, 'data');
  4878. needShow = this.deepQuery([
  4879. data,
  4880. serie,
  4881. this.option
  4882. ], 'tooltip.show');
  4883. if (serie == null || data == null || !needShow) {
  4884. clearTimeout(this._hidingTicket);
  4885. clearTimeout(this._showingTicket);
  4886. this._hidingTicket = setTimeout(this._hide, this._hideDelay);
  4887. } else {
  4888. trigger = this.deepQuery([
  4889. data,
  4890. serie,
  4891. this.option
  4892. ], 'tooltip.trigger');
  4893. trigger === 'axis' ? this._showAxisTrigger(serie.xAxisIndex, serie.yAxisIndex, ecData.get(this._curTarget, 'dataIndex')) : this._showItemTrigger();
  4894. }
  4895. }
  4896. },
  4897. _findAxisTrigger: function () {
  4898. if (!this.component.xAxis || !this.component.yAxis) {
  4899. this._hidingTicket = setTimeout(this._hide, this._hideDelay);
  4900. return;
  4901. }
  4902. var series = this.option.series;
  4903. var xAxisIndex;
  4904. var yAxisIndex;
  4905. for (var i = 0, l = series.length; i < l; i++) {
  4906. if (this.deepQuery([
  4907. series[i],
  4908. this.option
  4909. ], 'tooltip.trigger') === 'axis') {
  4910. xAxisIndex = series[i].xAxisIndex || 0;
  4911. yAxisIndex = series[i].yAxisIndex || 0;
  4912. if (this.component.xAxis.getAxis(xAxisIndex) && this.component.xAxis.getAxis(xAxisIndex).type === ecConfig.COMPONENT_TYPE_AXIS_CATEGORY) {
  4913. this._showAxisTrigger(xAxisIndex, yAxisIndex, this._getNearestDataIndex('x', this.component.xAxis.getAxis(xAxisIndex)));
  4914. return;
  4915. } else if (this.component.yAxis.getAxis(yAxisIndex) && this.component.yAxis.getAxis(yAxisIndex).type === ecConfig.COMPONENT_TYPE_AXIS_CATEGORY) {
  4916. this._showAxisTrigger(xAxisIndex, yAxisIndex, this._getNearestDataIndex('y', this.component.yAxis.getAxis(yAxisIndex)));
  4917. return;
  4918. } else {
  4919. this._showAxisTrigger(xAxisIndex, yAxisIndex, -1);
  4920. return;
  4921. }
  4922. }
  4923. }
  4924. if (this.option.tooltip.axisPointer.type === 'cross') {
  4925. this._showAxisTrigger(-1, -1, -1);
  4926. }
  4927. },
  4928. _findPolarTrigger: function () {
  4929. if (!this.component.polar) {
  4930. return false;
  4931. }
  4932. var x = zrEvent.getX(this._event);
  4933. var y = zrEvent.getY(this._event);
  4934. var polarIndex = this.component.polar.getNearestIndex([
  4935. x,
  4936. y
  4937. ]);
  4938. var valueIndex;
  4939. if (polarIndex) {
  4940. valueIndex = polarIndex.valueIndex;
  4941. polarIndex = polarIndex.polarIndex;
  4942. } else {
  4943. polarIndex = -1;
  4944. }
  4945. if (polarIndex != -1) {
  4946. return this._showPolarTrigger(polarIndex, valueIndex);
  4947. }
  4948. return false;
  4949. },
  4950. _getNearestDataIndex: function (direction, categoryAxis) {
  4951. var dataIndex = -1;
  4952. var x = zrEvent.getX(this._event);
  4953. var y = zrEvent.getY(this._event);
  4954. if (direction === 'x') {
  4955. var left;
  4956. var right;
  4957. var xEnd = this.component.grid.getXend();
  4958. var curCoord = categoryAxis.getCoordByIndex(dataIndex);
  4959. while (curCoord < xEnd) {
  4960. right = curCoord;
  4961. if (curCoord <= x) {
  4962. left = curCoord;
  4963. } else {
  4964. break;
  4965. }
  4966. curCoord = categoryAxis.getCoordByIndex(++dataIndex);
  4967. }
  4968. if (dataIndex <= 0) {
  4969. dataIndex = 0;
  4970. } else if (x - left <= right - x) {
  4971. dataIndex -= 1;
  4972. } else {
  4973. if (categoryAxis.getNameByIndex(dataIndex) == null) {
  4974. dataIndex -= 1;
  4975. }
  4976. }
  4977. return dataIndex;
  4978. } else {
  4979. var top;
  4980. var bottom;
  4981. var yStart = this.component.grid.getY();
  4982. var curCoord = categoryAxis.getCoordByIndex(dataIndex);
  4983. while (curCoord > yStart) {
  4984. top = curCoord;
  4985. if (curCoord >= y) {
  4986. bottom = curCoord;
  4987. } else {
  4988. break;
  4989. }
  4990. curCoord = categoryAxis.getCoordByIndex(++dataIndex);
  4991. }
  4992. if (dataIndex <= 0) {
  4993. dataIndex = 0;
  4994. } else if (y - top >= bottom - y) {
  4995. dataIndex -= 1;
  4996. } else {
  4997. if (categoryAxis.getNameByIndex(dataIndex) == null) {
  4998. dataIndex -= 1;
  4999. }
  5000. }
  5001. return dataIndex;
  5002. }
  5003. return -1;
  5004. },
  5005. _showAxisTrigger: function (xAxisIndex, yAxisIndex, dataIndex) {
  5006. !this._event.connectTrigger && this.messageCenter.dispatch(ecConfig.EVENT.TOOLTIP_IN_GRID, this._event, null, this.myChart);
  5007. if (this.component.xAxis == null || this.component.yAxis == null || xAxisIndex == null || yAxisIndex == null) {
  5008. clearTimeout(this._hidingTicket);
  5009. clearTimeout(this._showingTicket);
  5010. this._hidingTicket = setTimeout(this._hide, this._hideDelay);
  5011. return;
  5012. }
  5013. var series = this.option.series;
  5014. var seriesArray = [];
  5015. var seriesIndex = [];
  5016. var categoryAxis;
  5017. var formatter;
  5018. var position;
  5019. var showContent;
  5020. var specialCssText = '';
  5021. if (this.option.tooltip.trigger === 'axis') {
  5022. if (!this.option.tooltip.show) {
  5023. return;
  5024. }
  5025. formatter = this.option.tooltip.formatter;
  5026. position = this.option.tooltip.position;
  5027. }
  5028. 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;
  5029. var x;
  5030. var y;
  5031. if (axisLayout) {
  5032. var axisIndex = axisLayout == 'xAxis' ? xAxisIndex : yAxisIndex;
  5033. categoryAxis = this.component[axisLayout].getAxis(axisIndex);
  5034. for (var i = 0, l = series.length; i < l; i++) {
  5035. if (!this._isSelected(series[i].name)) {
  5036. continue;
  5037. }
  5038. if (series[i][axisLayout + 'Index'] === axisIndex && this.deepQuery([
  5039. series[i],
  5040. this.option
  5041. ], 'tooltip.trigger') === 'axis') {
  5042. showContent = this.query(series[i], 'tooltip.showContent') || showContent;
  5043. formatter = this.query(series[i], 'tooltip.formatter') || formatter;
  5044. position = this.query(series[i], 'tooltip.position') || position;
  5045. specialCssText += this._style(this.query(series[i], 'tooltip'));
  5046. if (series[i].stack != null && axisLayout == 'xAxis') {
  5047. seriesArray.unshift(series[i]);
  5048. seriesIndex.unshift(i);
  5049. } else {
  5050. seriesArray.push(series[i]);
  5051. seriesIndex.push(i);
  5052. }
  5053. }
  5054. }
  5055. this.messageCenter.dispatch(ecConfig.EVENT.TOOLTIP_HOVER, this._event, {
  5056. seriesIndex: seriesIndex,
  5057. dataIndex: dataIndex
  5058. }, this.myChart);
  5059. var rect;
  5060. if (axisLayout == 'xAxis') {
  5061. x = this.subPixelOptimize(categoryAxis.getCoordByIndex(dataIndex), this._axisLineWidth);
  5062. y = zrEvent.getY(this._event);
  5063. rect = [
  5064. x,
  5065. this.component.grid.getY(),
  5066. x,
  5067. this.component.grid.getYend()
  5068. ];
  5069. } else {
  5070. x = zrEvent.getX(this._event);
  5071. y = this.subPixelOptimize(categoryAxis.getCoordByIndex(dataIndex), this._axisLineWidth);
  5072. rect = [
  5073. this.component.grid.getX(),
  5074. y,
  5075. this.component.grid.getXend(),
  5076. y
  5077. ];
  5078. }
  5079. this._styleAxisPointer(seriesArray, rect[0], rect[1], rect[2], rect[3], categoryAxis.getGap(), x, y);
  5080. } else {
  5081. x = zrEvent.getX(this._event);
  5082. y = zrEvent.getY(this._event);
  5083. this._styleAxisPointer(series, this.component.grid.getX(), y, this.component.grid.getXend(), y, 0, x, y);
  5084. if (dataIndex >= 0) {
  5085. this._showItemTrigger(true);
  5086. } else {
  5087. clearTimeout(this._hidingTicket);
  5088. clearTimeout(this._showingTicket);
  5089. this._tDom.style.display = 'none';
  5090. }
  5091. }
  5092. if (seriesArray.length > 0) {
  5093. this._lastItemTriggerId = -1;
  5094. if (this._lastDataIndex != dataIndex || this._lastSeriesIndex != seriesIndex[0]) {
  5095. this._lastDataIndex = dataIndex;
  5096. this._lastSeriesIndex = seriesIndex[0];
  5097. var data;
  5098. var value;
  5099. if (typeof formatter === 'function') {
  5100. var params = [];
  5101. for (var i = 0, l = seriesArray.length; i < l; i++) {
  5102. data = seriesArray[i].data[dataIndex];
  5103. value = this.getDataFromOption(data, '-');
  5104. params.push({
  5105. seriesIndex: seriesIndex[i],
  5106. seriesName: seriesArray[i].name || '',
  5107. series: seriesArray[i],
  5108. dataIndex: dataIndex,
  5109. data: data,
  5110. name: categoryAxis.getNameByIndex(dataIndex),
  5111. value: value,
  5112. 0: seriesArray[i].name || '',
  5113. 1: categoryAxis.getNameByIndex(dataIndex),
  5114. 2: value,
  5115. 3: data
  5116. });
  5117. }
  5118. this._curTicket = 'axis:' + dataIndex;
  5119. this._tDom.innerHTML = formatter.call(this.myChart, params, this._curTicket, this._setContent);
  5120. } else if (typeof formatter === 'string') {
  5121. this._curTicket = NaN;
  5122. formatter = formatter.replace('{a}', '{a0}').replace('{b}', '{b0}').replace('{c}', '{c0}');
  5123. for (var i = 0, l = seriesArray.length; i < l; i++) {
  5124. formatter = formatter.replace('{a' + i + '}', this._encodeHTML(seriesArray[i].name || ''));
  5125. formatter = formatter.replace('{b' + i + '}', this._encodeHTML(categoryAxis.getNameByIndex(dataIndex)));
  5126. data = seriesArray[i].data[dataIndex];
  5127. data = this.getDataFromOption(data, '-');
  5128. formatter = formatter.replace('{c' + i + '}', data instanceof Array ? data : this.numAddCommas(data));
  5129. }
  5130. this._tDom.innerHTML = formatter;
  5131. } else {
  5132. this._curTicket = NaN;
  5133. formatter = this._encodeHTML(categoryAxis.getNameByIndex(dataIndex));
  5134. for (var i = 0, l = seriesArray.length; i < l; i++) {
  5135. formatter += '<br/>' + this._encodeHTML(seriesArray[i].name || '') + ' : ';
  5136. data = seriesArray[i].data[dataIndex];
  5137. data = this.getDataFromOption(data, '-');
  5138. formatter += data instanceof Array ? data : this.numAddCommas(data);
  5139. }
  5140. this._tDom.innerHTML = formatter;
  5141. }
  5142. }
  5143. if (showContent === false || !this.option.tooltip.showContent) {
  5144. return;
  5145. }
  5146. if (!this.hasAppend) {
  5147. this._tDom.style.left = this._zrWidth / 2 + 'px';
  5148. this._tDom.style.top = this._zrHeight / 2 + 'px';
  5149. this.dom.firstChild.appendChild(this._tDom);
  5150. this.hasAppend = true;
  5151. }
  5152. this._show(position, x + 10, y + 10, specialCssText);
  5153. }
  5154. },
  5155. _showPolarTrigger: function (polarIndex, dataIndex) {
  5156. if (this.component.polar == null || polarIndex == null || dataIndex == null || dataIndex < 0) {
  5157. return false;
  5158. }
  5159. var series = this.option.series;
  5160. var seriesArray = [];
  5161. var seriesIndex = [];
  5162. var formatter;
  5163. var position;
  5164. var showContent;
  5165. var specialCssText = '';
  5166. if (this.option.tooltip.trigger === 'axis') {
  5167. if (!this.option.tooltip.show) {
  5168. return false;
  5169. }
  5170. formatter = this.option.tooltip.formatter;
  5171. position = this.option.tooltip.position;
  5172. }
  5173. var indicatorName = this.option.polar[polarIndex].indicator[dataIndex].text;
  5174. for (var i = 0, l = series.length; i < l; i++) {
  5175. if (!this._isSelected(series[i].name)) {
  5176. continue;
  5177. }
  5178. if (series[i].polarIndex === polarIndex && this.deepQuery([
  5179. series[i],
  5180. this.option
  5181. ], 'tooltip.trigger') === 'axis') {
  5182. showContent = this.query(series[i], 'tooltip.showContent') || showContent;
  5183. formatter = this.query(series[i], 'tooltip.formatter') || formatter;
  5184. position = this.query(series[i], 'tooltip.position') || position;
  5185. specialCssText += this._style(this.query(series[i], 'tooltip'));
  5186. seriesArray.push(series[i]);
  5187. seriesIndex.push(i);
  5188. }
  5189. }
  5190. if (seriesArray.length > 0) {
  5191. var polarData;
  5192. var data;
  5193. var value;
  5194. var params = [];
  5195. for (var i = 0, l = seriesArray.length; i < l; i++) {
  5196. polarData = seriesArray[i].data;
  5197. for (var j = 0, k = polarData.length; j < k; j++) {
  5198. data = polarData[j];
  5199. if (!this._isSelected(data.name)) {
  5200. continue;
  5201. }
  5202. data = data != null ? data : {
  5203. name: '',
  5204. value: { dataIndex: '-' }
  5205. };
  5206. value = this.getDataFromOption(data.value[dataIndex]);
  5207. params.push({
  5208. seriesIndex: seriesIndex[i],
  5209. seriesName: seriesArray[i].name || '',
  5210. series: seriesArray[i],
  5211. dataIndex: dataIndex,
  5212. data: data,
  5213. name: data.name,
  5214. indicator: indicatorName,
  5215. value: value,
  5216. 0: seriesArray[i].name || '',
  5217. 1: data.name,
  5218. 2: value,
  5219. 3: indicatorName
  5220. });
  5221. }
  5222. }
  5223. if (params.length <= 0) {
  5224. return;
  5225. }
  5226. this._lastItemTriggerId = -1;
  5227. if (this._lastDataIndex != dataIndex || this._lastSeriesIndex != seriesIndex[0]) {
  5228. this._lastDataIndex = dataIndex;
  5229. this._lastSeriesIndex = seriesIndex[0];
  5230. if (typeof formatter === 'function') {
  5231. this._curTicket = 'axis:' + dataIndex;
  5232. this._tDom.innerHTML = formatter.call(this.myChart, params, this._curTicket, this._setContent);
  5233. } else if (typeof formatter === 'string') {
  5234. formatter = formatter.replace('{a}', '{a0}').replace('{b}', '{b0}').replace('{c}', '{c0}').replace('{d}', '{d0}');
  5235. for (var i = 0, l = params.length; i < l; i++) {
  5236. formatter = formatter.replace('{a' + i + '}', this._encodeHTML(params[i].seriesName));
  5237. formatter = formatter.replace('{b' + i + '}', this._encodeHTML(params[i].name));
  5238. formatter = formatter.replace('{c' + i + '}', this.numAddCommas(params[i].value));
  5239. formatter = formatter.replace('{d' + i + '}', this._encodeHTML(params[i].indicator));
  5240. }
  5241. this._tDom.innerHTML = formatter;
  5242. } else {
  5243. formatter = this._encodeHTML(params[0].name) + '<br/>' + this._encodeHTML(params[0].indicator) + ' : ' + this.numAddCommas(params[0].value);
  5244. for (var i = 1, l = params.length; i < l; i++) {
  5245. formatter += '<br/>' + this._encodeHTML(params[i].name) + '<br/>';
  5246. formatter += this._encodeHTML(params[i].indicator) + ' : ' + this.numAddCommas(params[i].value);
  5247. }
  5248. this._tDom.innerHTML = formatter;
  5249. }
  5250. }
  5251. if (showContent === false || !this.option.tooltip.showContent) {
  5252. return;
  5253. }
  5254. if (!this.hasAppend) {
  5255. this._tDom.style.left = this._zrWidth / 2 + 'px';
  5256. this._tDom.style.top = this._zrHeight / 2 + 'px';
  5257. this.dom.firstChild.appendChild(this._tDom);
  5258. this.hasAppend = true;
  5259. }
  5260. this._show(position, zrEvent.getX(this._event), zrEvent.getY(this._event), specialCssText);
  5261. return true;
  5262. }
  5263. },
  5264. _showItemTrigger: function (axisTrigger) {
  5265. if (!this._curTarget) {
  5266. return;
  5267. }
  5268. var serie = ecData.get(this._curTarget, 'series');
  5269. var seriesIndex = ecData.get(this._curTarget, 'seriesIndex');
  5270. var data = ecData.get(this._curTarget, 'data');
  5271. var dataIndex = ecData.get(this._curTarget, 'dataIndex');
  5272. var name = ecData.get(this._curTarget, 'name');
  5273. var value = ecData.get(this._curTarget, 'value');
  5274. var special = ecData.get(this._curTarget, 'special');
  5275. var special2 = ecData.get(this._curTarget, 'special2');
  5276. var queryTarget = [
  5277. data,
  5278. serie,
  5279. this.option
  5280. ];
  5281. var formatter;
  5282. var position;
  5283. var showContent;
  5284. var specialCssText = '';
  5285. if (this._curTarget._type != 'island') {
  5286. var trigger = axisTrigger ? 'axis' : 'item';
  5287. if (this.option.tooltip.trigger === trigger) {
  5288. formatter = this.option.tooltip.formatter;
  5289. position = this.option.tooltip.position;
  5290. }
  5291. if (this.query(serie, 'tooltip.trigger') === trigger) {
  5292. showContent = this.query(serie, 'tooltip.showContent') || showContent;
  5293. formatter = this.query(serie, 'tooltip.formatter') || formatter;
  5294. position = this.query(serie, 'tooltip.position') || position;
  5295. specialCssText += this._style(this.query(serie, 'tooltip'));
  5296. }
  5297. showContent = this.query(data, 'tooltip.showContent') || showContent;
  5298. formatter = this.query(data, 'tooltip.formatter') || formatter;
  5299. position = this.query(data, 'tooltip.position') || position;
  5300. specialCssText += this._style(this.query(data, 'tooltip'));
  5301. } else {
  5302. this._lastItemTriggerId = NaN;
  5303. showContent = this.deepQuery(queryTarget, 'tooltip.showContent');
  5304. formatter = this.deepQuery(queryTarget, 'tooltip.islandFormatter');
  5305. position = this.deepQuery(queryTarget, 'tooltip.islandPosition');
  5306. }
  5307. this._lastDataIndex = -1;
  5308. this._lastSeriesIndex = -1;
  5309. if (this._lastItemTriggerId !== this._curTarget.id) {
  5310. this._lastItemTriggerId = this._curTarget.id;
  5311. if (typeof formatter === 'function') {
  5312. this._curTicket = (serie.name || '') + ':' + dataIndex;
  5313. this._tDom.innerHTML = formatter.call(this.myChart, {
  5314. seriesIndex: seriesIndex,
  5315. seriesName: serie.name || '',
  5316. series: serie,
  5317. dataIndex: dataIndex,
  5318. data: data,
  5319. name: name,
  5320. value: value,
  5321. percent: special,
  5322. indicator: special,
  5323. value2: special2,
  5324. indicator2: special2,
  5325. 0: serie.name || '',
  5326. 1: name,
  5327. 2: value,
  5328. 3: special,
  5329. 4: special2,
  5330. 5: data,
  5331. 6: seriesIndex,
  5332. 7: dataIndex
  5333. }, this._curTicket, this._setContent);
  5334. } else if (typeof formatter === 'string') {
  5335. this._curTicket = NaN;
  5336. formatter = formatter.replace('{a}', '{a0}').replace('{b}', '{b0}').replace('{c}', '{c0}');
  5337. formatter = formatter.replace('{a0}', this._encodeHTML(serie.name || '')).replace('{b0}', this._encodeHTML(name)).replace('{c0}', value instanceof Array ? value : this.numAddCommas(value));
  5338. formatter = formatter.replace('{d}', '{d0}').replace('{d0}', special || '');
  5339. formatter = formatter.replace('{e}', '{e0}').replace('{e0}', ecData.get(this._curTarget, 'special2') || '');
  5340. this._tDom.innerHTML = formatter;
  5341. } else {
  5342. this._curTicket = NaN;
  5343. if (serie.type === ecConfig.CHART_TYPE_RADAR && special) {
  5344. this._tDom.innerHTML = this._itemFormatter.radar.call(this, serie, name, value, special);
  5345. } else if (serie.type === ecConfig.CHART_TYPE_EVENTRIVER) {
  5346. this._tDom.innerHTML = this._itemFormatter.eventRiver.call(this, serie, name, value, data);
  5347. } else {
  5348. this._tDom.innerHTML = '' + (serie.name != null ? this._encodeHTML(serie.name) + '<br/>' : '') + (name === '' ? '' : this._encodeHTML(name) + ' : ') + (value instanceof Array ? value : this.numAddCommas(value));
  5349. }
  5350. }
  5351. }
  5352. var x = zrEvent.getX(this._event);
  5353. var y = zrEvent.getY(this._event);
  5354. if (this.deepQuery(queryTarget, 'tooltip.axisPointer.show') && this.component.grid) {
  5355. this._styleAxisPointer([serie], this.component.grid.getX(), y, this.component.grid.getXend(), y, 0, x, y);
  5356. } else {
  5357. this._hide();
  5358. }
  5359. if (showContent === false || !this.option.tooltip.showContent) {
  5360. return;
  5361. }
  5362. if (!this.hasAppend) {
  5363. this._tDom.style.left = this._zrWidth / 2 + 'px';
  5364. this._tDom.style.top = this._zrHeight / 2 + 'px';
  5365. this.dom.firstChild.appendChild(this._tDom);
  5366. this.hasAppend = true;
  5367. }
  5368. this._show(position, x + 20, y - 20, specialCssText);
  5369. },
  5370. _itemFormatter: {
  5371. radar: function (serie, name, value, indicator) {
  5372. var html = '';
  5373. html += this._encodeHTML(name === '' ? serie.name || '' : name);
  5374. html += html === '' ? '' : '<br />';
  5375. for (var i = 0; i < indicator.length; i++) {
  5376. html += this._encodeHTML(indicator[i].text) + ' : ' + this.numAddCommas(value[i]) + '<br />';
  5377. }
  5378. return html;
  5379. },
  5380. chord: function (serie, name, value, special, special2) {
  5381. if (special2 == null) {
  5382. return this._encodeHTML(name) + ' (' + this.numAddCommas(value) + ')';
  5383. } else {
  5384. var name1 = this._encodeHTML(name);
  5385. var name2 = this._encodeHTML(special);
  5386. return '' + (serie.name != null ? this._encodeHTML(serie.name) + '<br/>' : '') + name1 + ' -> ' + name2 + ' (' + this.numAddCommas(value) + ')' + '<br />' + name2 + ' -> ' + name1 + ' (' + this.numAddCommas(special2) + ')';
  5387. }
  5388. },
  5389. eventRiver: function (serie, name, value, data) {
  5390. var html = '';
  5391. html += this._encodeHTML(serie.name === '' ? '' : serie.name + ' : ');
  5392. html += this._encodeHTML(name);
  5393. html += html === '' ? '' : '<br />';
  5394. data = data.evolution;
  5395. for (var i = 0, l = data.length; i < l; i++) {
  5396. html += '<div style="padding-top:5px;">';
  5397. if (!data[i].detail) {
  5398. continue;
  5399. }
  5400. if (data[i].detail.img) {
  5401. html += '<img src="' + data[i].detail.img + '" style="float:left;width:40px;height:40px;">';
  5402. }
  5403. html += '<div style="margin-left:45px;">' + data[i].time + '<br/>';
  5404. html += '<a href="' + data[i].detail.link + '" target="_blank">';
  5405. html += data[i].detail.text + '</a></div>';
  5406. html += '</div>';
  5407. }
  5408. return html;
  5409. }
  5410. },
  5411. _styleAxisPointer: function (seriesArray, xStart, yStart, xEnd, yEnd, gap, x, y) {
  5412. if (seriesArray.length > 0) {
  5413. var queryTarget;
  5414. var curType;
  5415. var axisPointer = this.option.tooltip.axisPointer;
  5416. var pointType = axisPointer.type;
  5417. var style = {
  5418. line: {},
  5419. cross: {},
  5420. shadow: {}
  5421. };
  5422. for (var pType in style) {
  5423. style[pType].color = axisPointer[pType + 'Style'].color;
  5424. style[pType].width = axisPointer[pType + 'Style'].width;
  5425. style[pType].type = axisPointer[pType + 'Style'].type;
  5426. }
  5427. for (var i = 0, l = seriesArray.length; i < l; i++) {
  5428. queryTarget = seriesArray[i];
  5429. curType = this.query(queryTarget, 'tooltip.axisPointer.type');
  5430. pointType = curType || pointType;
  5431. if (curType) {
  5432. style[curType].color = this.query(queryTarget, 'tooltip.axisPointer.' + curType + 'Style.color') || style[curType].color;
  5433. style[curType].width = this.query(queryTarget, 'tooltip.axisPointer.' + curType + 'Style.width') || style[curType].width;
  5434. style[curType].type = this.query(queryTarget, 'tooltip.axisPointer.' + curType + 'Style.type') || style[curType].type;
  5435. }
  5436. }
  5437. if (pointType === 'line') {
  5438. var lineWidth = style.line.width;
  5439. var isVertical = xStart == xEnd;
  5440. this._axisLineShape.style = {
  5441. xStart: isVertical ? this.subPixelOptimize(xStart, lineWidth) : xStart,
  5442. yStart: isVertical ? yStart : this.subPixelOptimize(yStart, lineWidth),
  5443. xEnd: isVertical ? this.subPixelOptimize(xEnd, lineWidth) : xEnd,
  5444. yEnd: isVertical ? yEnd : this.subPixelOptimize(yEnd, lineWidth),
  5445. strokeColor: style.line.color,
  5446. lineWidth: lineWidth,
  5447. lineType: style.line.type
  5448. };
  5449. this._axisLineShape.invisible = false;
  5450. this.zr.modShape(this._axisLineShape.id);
  5451. } else if (pointType === 'cross') {
  5452. var crossWidth = style.cross.width;
  5453. this._axisCrossShape.style = {
  5454. brushType: 'stroke',
  5455. rect: this.component.grid.getArea(),
  5456. x: this.subPixelOptimize(x, crossWidth),
  5457. y: this.subPixelOptimize(y, crossWidth),
  5458. text: ('( ' + this.component.xAxis.getAxis(0).getValueFromCoord(x) + ' , ' + this.component.yAxis.getAxis(0).getValueFromCoord(y) + ' )').replace(' , ', ' ').replace(' , ', ' '),
  5459. textPosition: 'specific',
  5460. strokeColor: style.cross.color,
  5461. lineWidth: crossWidth,
  5462. lineType: style.cross.type
  5463. };
  5464. if (this.component.grid.getXend() - x > 100) {
  5465. this._axisCrossShape.style.textAlign = 'left';
  5466. this._axisCrossShape.style.textX = x + 10;
  5467. } else {
  5468. this._axisCrossShape.style.textAlign = 'right';
  5469. this._axisCrossShape.style.textX = x - 10;
  5470. }
  5471. if (y - this.component.grid.getY() > 50) {
  5472. this._axisCrossShape.style.textBaseline = 'bottom';
  5473. this._axisCrossShape.style.textY = y - 10;
  5474. } else {
  5475. this._axisCrossShape.style.textBaseline = 'top';
  5476. this._axisCrossShape.style.textY = y + 10;
  5477. }
  5478. this._axisCrossShape.invisible = false;
  5479. this.zr.modShape(this._axisCrossShape.id);
  5480. } else if (pointType === 'shadow') {
  5481. if (style.shadow.width == null || style.shadow.width === 'auto' || isNaN(style.shadow.width)) {
  5482. style.shadow.width = gap;
  5483. }
  5484. if (xStart === xEnd) {
  5485. if (Math.abs(this.component.grid.getX() - xStart) < 2) {
  5486. style.shadow.width /= 2;
  5487. xStart = xEnd = xEnd + style.shadow.width / 2;
  5488. } else if (Math.abs(this.component.grid.getXend() - xStart) < 2) {
  5489. style.shadow.width /= 2;
  5490. xStart = xEnd = xEnd - style.shadow.width / 2;
  5491. }
  5492. } else if (yStart === yEnd) {
  5493. if (Math.abs(this.component.grid.getY() - yStart) < 2) {
  5494. style.shadow.width /= 2;
  5495. yStart = yEnd = yEnd + style.shadow.width / 2;
  5496. } else if (Math.abs(this.component.grid.getYend() - yStart) < 2) {
  5497. style.shadow.width /= 2;
  5498. yStart = yEnd = yEnd - style.shadow.width / 2;
  5499. }
  5500. }
  5501. this._axisShadowShape.style = {
  5502. xStart: xStart,
  5503. yStart: yStart,
  5504. xEnd: xEnd,
  5505. yEnd: yEnd,
  5506. strokeColor: style.shadow.color,
  5507. lineWidth: style.shadow.width
  5508. };
  5509. this._axisShadowShape.invisible = false;
  5510. this.zr.modShape(this._axisShadowShape.id);
  5511. }
  5512. this.zr.refreshNextFrame();
  5513. }
  5514. },
  5515. __onmousemove: function (param) {
  5516. clearTimeout(this._hidingTicket);
  5517. clearTimeout(this._showingTicket);
  5518. if (this._mousein && this._enterable) {
  5519. return;
  5520. }
  5521. var target = param.target;
  5522. var mx = zrEvent.getX(param.event);
  5523. var my = zrEvent.getY(param.event);
  5524. if (!target) {
  5525. this._curTarget = false;
  5526. this._event = param.event;
  5527. this._event.zrenderX = mx;
  5528. this._event.zrenderY = my;
  5529. if (this._needAxisTrigger && this.component.grid && zrArea.isInside(rectangleInstance, this.component.grid.getArea(), mx, my)) {
  5530. this._showingTicket = setTimeout(this._tryShow, this._showDelay);
  5531. } else if (this._needAxisTrigger && this.component.polar && this.component.polar.isInside([
  5532. mx,
  5533. my
  5534. ]) != -1) {
  5535. this._showingTicket = setTimeout(this._tryShow, this._showDelay);
  5536. } else {
  5537. !this._event.connectTrigger && this.messageCenter.dispatch(ecConfig.EVENT.TOOLTIP_OUT_GRID, this._event, null, this.myChart);
  5538. this._hidingTicket = setTimeout(this._hide, this._hideDelay);
  5539. }
  5540. } else {
  5541. this._curTarget = target;
  5542. this._event = param.event;
  5543. this._event.zrenderX = mx;
  5544. this._event.zrenderY = my;
  5545. var polarIndex;
  5546. if (this._needAxisTrigger && this.component.polar && (polarIndex = this.component.polar.isInside([
  5547. mx,
  5548. my
  5549. ])) != -1) {
  5550. var series = this.option.series;
  5551. for (var i = 0, l = series.length; i < l; i++) {
  5552. if (series[i].polarIndex === polarIndex && this.deepQuery([
  5553. series[i],
  5554. this.option
  5555. ], 'tooltip.trigger') === 'axis') {
  5556. this._curTarget = null;
  5557. break;
  5558. }
  5559. }
  5560. }
  5561. this._showingTicket = setTimeout(this._tryShow, this._showDelay);
  5562. }
  5563. },
  5564. __onglobalout: function () {
  5565. clearTimeout(this._hidingTicket);
  5566. clearTimeout(this._showingTicket);
  5567. this._hidingTicket = setTimeout(this._hide, this._hideDelay);
  5568. },
  5569. __setContent: function (ticket, content) {
  5570. if (!this._tDom) {
  5571. return;
  5572. }
  5573. if (ticket === this._curTicket) {
  5574. this._tDom.innerHTML = content;
  5575. }
  5576. setTimeout(this._refixed, 20);
  5577. },
  5578. ontooltipHover: function (param, tipShape) {
  5579. if (!this._lastTipShape || this._lastTipShape && this._lastTipShape.dataIndex != param.dataIndex) {
  5580. if (this._lastTipShape && this._lastTipShape.tipShape.length > 0) {
  5581. this.zr.delShape(this._lastTipShape.tipShape);
  5582. this.shapeList.length = 2;
  5583. }
  5584. for (var i = 0, l = tipShape.length; i < l; i++) {
  5585. tipShape[i].zlevel = this.getZlevelBase();
  5586. tipShape[i].z = this.getZBase();
  5587. tipShape[i].style = zrShapeBase.prototype.getHighlightStyle(tipShape[i].style, tipShape[i].highlightStyle);
  5588. tipShape[i].draggable = false;
  5589. tipShape[i].hoverable = false;
  5590. tipShape[i].clickable = false;
  5591. tipShape[i].ondragend = null;
  5592. tipShape[i].ondragover = null;
  5593. tipShape[i].ondrop = null;
  5594. this.shapeList.push(tipShape[i]);
  5595. this.zr.addShape(tipShape[i]);
  5596. }
  5597. this._lastTipShape = {
  5598. dataIndex: param.dataIndex,
  5599. tipShape: tipShape
  5600. };
  5601. }
  5602. },
  5603. ondragend: function () {
  5604. this._hide();
  5605. },
  5606. onlegendSelected: function (param) {
  5607. this._selectedMap = param.selected;
  5608. },
  5609. _setSelectedMap: function () {
  5610. if (this.component.legend) {
  5611. this._selectedMap = zrUtil.clone(this.component.legend.getSelectedMap());
  5612. } else {
  5613. this._selectedMap = {};
  5614. }
  5615. },
  5616. _isSelected: function (itemName) {
  5617. if (this._selectedMap[itemName] != null) {
  5618. return this._selectedMap[itemName];
  5619. } else {
  5620. return true;
  5621. }
  5622. },
  5623. showTip: function (params) {
  5624. if (!params) {
  5625. return;
  5626. }
  5627. var seriesIndex;
  5628. var series = this.option.series;
  5629. if (params.seriesIndex != null) {
  5630. seriesIndex = params.seriesIndex;
  5631. } else {
  5632. var seriesName = params.seriesName;
  5633. for (var i = 0, l = series.length; i < l; i++) {
  5634. if (series[i].name === seriesName) {
  5635. seriesIndex = i;
  5636. break;
  5637. }
  5638. }
  5639. }
  5640. var serie = series[seriesIndex];
  5641. if (serie == null) {
  5642. return;
  5643. }
  5644. var chart = this.myChart.chart[serie.type];
  5645. var isAxisTrigger = this.deepQuery([
  5646. serie,
  5647. this.option
  5648. ], 'tooltip.trigger') === 'axis';
  5649. if (!chart) {
  5650. return;
  5651. }
  5652. if (isAxisTrigger) {
  5653. var dataIndex = params.dataIndex;
  5654. switch (chart.type) {
  5655. case ecConfig.CHART_TYPE_LINE:
  5656. case ecConfig.CHART_TYPE_BAR:
  5657. case ecConfig.CHART_TYPE_K:
  5658. if (this.component.xAxis == null || this.component.yAxis == null || serie.data.length <= dataIndex) {
  5659. return;
  5660. }
  5661. var xAxisIndex = serie.xAxisIndex || 0;
  5662. var yAxisIndex = serie.yAxisIndex || 0;
  5663. if (this.component.xAxis.getAxis(xAxisIndex).type === ecConfig.COMPONENT_TYPE_AXIS_CATEGORY) {
  5664. this._event = {
  5665. zrenderX: this.component.xAxis.getAxis(xAxisIndex).getCoordByIndex(dataIndex),
  5666. zrenderY: this.component.grid.getY() + (this.component.grid.getYend() - this.component.grid.getY()) / 4
  5667. };
  5668. } else {
  5669. this._event = {
  5670. zrenderX: this.component.grid.getX() + (this.component.grid.getXend() - this.component.grid.getX()) / 4,
  5671. zrenderY: this.component.yAxis.getAxis(yAxisIndex).getCoordByIndex(dataIndex)
  5672. };
  5673. }
  5674. this._showAxisTrigger(xAxisIndex, yAxisIndex, dataIndex);
  5675. break;
  5676. case ecConfig.CHART_TYPE_RADAR:
  5677. if (this.component.polar == null || serie.data[0].value.length <= dataIndex) {
  5678. return;
  5679. }
  5680. var polarIndex = serie.polarIndex || 0;
  5681. var vector = this.component.polar.getVector(polarIndex, dataIndex, 'max');
  5682. this._event = {
  5683. zrenderX: vector[0],
  5684. zrenderY: vector[1]
  5685. };
  5686. this._showPolarTrigger(polarIndex, dataIndex);
  5687. break;
  5688. }
  5689. } else {
  5690. var shapeList = chart.shapeList;
  5691. var x;
  5692. var y;
  5693. switch (chart.type) {
  5694. case ecConfig.CHART_TYPE_LINE:
  5695. case ecConfig.CHART_TYPE_BAR:
  5696. case ecConfig.CHART_TYPE_K:
  5697. case ecConfig.CHART_TYPE_SCATTER:
  5698. var dataIndex = params.dataIndex;
  5699. for (var i = 0, l = shapeList.length; i < l; i++) {
  5700. if (shapeList[i]._mark == null && ecData.get(shapeList[i], 'seriesIndex') == seriesIndex && ecData.get(shapeList[i], 'dataIndex') == dataIndex) {
  5701. this._curTarget = shapeList[i];
  5702. x = shapeList[i].style.x;
  5703. y = chart.type != ecConfig.CHART_TYPE_K ? shapeList[i].style.y : shapeList[i].style.y[0];
  5704. break;
  5705. }
  5706. }
  5707. break;
  5708. case ecConfig.CHART_TYPE_RADAR:
  5709. var dataIndex = params.dataIndex;
  5710. for (var i = 0, l = shapeList.length; i < l; i++) {
  5711. if (shapeList[i].type === 'polygon' && ecData.get(shapeList[i], 'seriesIndex') == seriesIndex && ecData.get(shapeList[i], 'dataIndex') == dataIndex) {
  5712. this._curTarget = shapeList[i];
  5713. var vector = this.component.polar.getCenter(serie.polarIndex || 0);
  5714. x = vector[0];
  5715. y = vector[1];
  5716. break;
  5717. }
  5718. }
  5719. break;
  5720. case ecConfig.CHART_TYPE_PIE:
  5721. var name = params.name;
  5722. for (var i = 0, l = shapeList.length; i < l; i++) {
  5723. if (shapeList[i].type === 'sector' && ecData.get(shapeList[i], 'seriesIndex') == seriesIndex && ecData.get(shapeList[i], 'name') == name) {
  5724. this._curTarget = shapeList[i];
  5725. var style = this._curTarget.style;
  5726. var midAngle = (style.startAngle + style.endAngle) / 2 * Math.PI / 180;
  5727. x = this._curTarget.style.x + Math.cos(midAngle) * style.r / 1.5;
  5728. y = this._curTarget.style.y - Math.sin(midAngle) * style.r / 1.5;
  5729. break;
  5730. }
  5731. }
  5732. break;
  5733. case ecConfig.CHART_TYPE_MAP:
  5734. var name = params.name;
  5735. var mapType = serie.mapType;
  5736. for (var i = 0, l = shapeList.length; i < l; i++) {
  5737. if (shapeList[i].type === 'text' && shapeList[i]._mapType === mapType && shapeList[i].style._name === name) {
  5738. this._curTarget = shapeList[i];
  5739. x = this._curTarget.style.x + this._curTarget.position[0];
  5740. y = this._curTarget.style.y + this._curTarget.position[1];
  5741. break;
  5742. }
  5743. }
  5744. break;
  5745. case ecConfig.CHART_TYPE_CHORD:
  5746. var name = params.name;
  5747. for (var i = 0, l = shapeList.length; i < l; i++) {
  5748. if (shapeList[i].type === 'sector' && ecData.get(shapeList[i], 'name') == name) {
  5749. this._curTarget = shapeList[i];
  5750. var style = this._curTarget.style;
  5751. var midAngle = (style.startAngle + style.endAngle) / 2 * Math.PI / 180;
  5752. x = this._curTarget.style.x + Math.cos(midAngle) * (style.r - 2);
  5753. y = this._curTarget.style.y - Math.sin(midAngle) * (style.r - 2);
  5754. this.zr.trigger(zrConfig.EVENT.MOUSEMOVE, {
  5755. zrenderX: x,
  5756. zrenderY: y
  5757. });
  5758. return;
  5759. }
  5760. }
  5761. break;
  5762. case ecConfig.CHART_TYPE_FORCE:
  5763. var name = params.name;
  5764. for (var i = 0, l = shapeList.length; i < l; i++) {
  5765. if (shapeList[i].type === 'circle' && ecData.get(shapeList[i], 'name') == name) {
  5766. this._curTarget = shapeList[i];
  5767. x = this._curTarget.position[0];
  5768. y = this._curTarget.position[1];
  5769. break;
  5770. }
  5771. }
  5772. break;
  5773. }
  5774. if (x != null && y != null) {
  5775. this._event = {
  5776. zrenderX: x,
  5777. zrenderY: y
  5778. };
  5779. this.zr.addHoverShape(this._curTarget);
  5780. this.zr.refreshHover();
  5781. this._showItemTrigger();
  5782. }
  5783. }
  5784. },
  5785. hideTip: function () {
  5786. this._hide();
  5787. },
  5788. refresh: function (newOption) {
  5789. this._zrHeight = this.zr.getHeight();
  5790. this._zrWidth = this.zr.getWidth();
  5791. if (this._lastTipShape && this._lastTipShape.tipShape.length > 0) {
  5792. this.zr.delShape(this._lastTipShape.tipShape);
  5793. }
  5794. this._lastTipShape = false;
  5795. this.shapeList.length = 2;
  5796. this._lastDataIndex = -1;
  5797. this._lastSeriesIndex = -1;
  5798. this._lastItemTriggerId = -1;
  5799. if (newOption) {
  5800. this.option = newOption;
  5801. this.option.tooltip = this.reformOption(this.option.tooltip);
  5802. this.option.tooltip.textStyle = zrUtil.merge(this.option.tooltip.textStyle, this.ecTheme.textStyle);
  5803. this._needAxisTrigger = false;
  5804. if (this.option.tooltip.trigger === 'axis') {
  5805. this._needAxisTrigger = true;
  5806. }
  5807. var series = this.option.series;
  5808. for (var i = 0, l = series.length; i < l; i++) {
  5809. if (this.query(series[i], 'tooltip.trigger') === 'axis') {
  5810. this._needAxisTrigger = true;
  5811. break;
  5812. }
  5813. }
  5814. this._showDelay = this.option.tooltip.showDelay;
  5815. this._hideDelay = this.option.tooltip.hideDelay;
  5816. this._defaultCssText = this._style(this.option.tooltip);
  5817. this._setSelectedMap();
  5818. this._axisLineWidth = this.option.tooltip.axisPointer.lineStyle.width;
  5819. this._enterable = this.option.tooltip.enterable;
  5820. }
  5821. if (this.showing) {
  5822. var self = this;
  5823. setTimeout(function () {
  5824. self.zr.trigger(zrConfig.EVENT.MOUSEMOVE, self.zr.handler._event);
  5825. }, 50);
  5826. }
  5827. },
  5828. onbeforDispose: function () {
  5829. if (this._lastTipShape && this._lastTipShape.tipShape.length > 0) {
  5830. this.zr.delShape(this._lastTipShape.tipShape);
  5831. }
  5832. clearTimeout(this._hidingTicket);
  5833. clearTimeout(this._showingTicket);
  5834. this.zr.un(zrConfig.EVENT.MOUSEMOVE, this._onmousemove);
  5835. this.zr.un(zrConfig.EVENT.GLOBALOUT, this._onglobalout);
  5836. if (this.hasAppend && !!this.dom.firstChild) {
  5837. this.dom.firstChild.removeChild(this._tDom);
  5838. }
  5839. this._tDom = null;
  5840. },
  5841. _encodeHTML: function (source) {
  5842. return String(source).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
  5843. }
  5844. };
  5845. zrUtil.inherits(Tooltip, Base);
  5846. require('../component').define('tooltip', Tooltip);
  5847. return Tooltip;
  5848. });define('echarts/component/legend', [
  5849. 'require',
  5850. './base',
  5851. 'zrender/shape/Text',
  5852. 'zrender/shape/Rectangle',
  5853. 'zrender/shape/Sector',
  5854. '../util/shape/Icon',
  5855. '../util/shape/Candle',
  5856. '../config',
  5857. 'zrender/tool/util',
  5858. 'zrender/tool/area',
  5859. '../component'
  5860. ], function (require) {
  5861. var Base = require('./base');
  5862. var TextShape = require('zrender/shape/Text');
  5863. var RectangleShape = require('zrender/shape/Rectangle');
  5864. var SectorShape = require('zrender/shape/Sector');
  5865. var IconShape = require('../util/shape/Icon');
  5866. var CandleShape = require('../util/shape/Candle');
  5867. var ecConfig = require('../config');
  5868. ecConfig.legend = {
  5869. zlevel: 0,
  5870. z: 4,
  5871. show: true,
  5872. orient: 'horizontal',
  5873. x: 'center',
  5874. y: 'top',
  5875. backgroundColor: 'rgba(0,0,0,0)',
  5876. borderColor: '#ccc',
  5877. borderWidth: 0,
  5878. padding: 5,
  5879. itemGap: 10,
  5880. itemWidth: 20,
  5881. itemHeight: 14,
  5882. textStyle: { color: '#333' },
  5883. selectedMode: true
  5884. };
  5885. var zrUtil = require('zrender/tool/util');
  5886. var zrArea = require('zrender/tool/area');
  5887. function Legend(ecTheme, messageCenter, zr, option, myChart) {
  5888. if (!this.query(option, 'legend.data')) {
  5889. console.error('option.legend.data has not been defined.');
  5890. return;
  5891. }
  5892. Base.call(this, ecTheme, messageCenter, zr, option, myChart);
  5893. var self = this;
  5894. self._legendSelected = function (param) {
  5895. self.__legendSelected(param);
  5896. };
  5897. self._dispatchHoverLink = function (param) {
  5898. return self.__dispatchHoverLink(param);
  5899. };
  5900. this._colorIndex = 0;
  5901. this._colorMap = {};
  5902. this._selectedMap = {};
  5903. this._hasDataMap = {};
  5904. this.refresh(option);
  5905. }
  5906. Legend.prototype = {
  5907. type: ecConfig.COMPONENT_TYPE_LEGEND,
  5908. _buildShape: function () {
  5909. if (!this.legendOption.show) {
  5910. return;
  5911. }
  5912. this._itemGroupLocation = this._getItemGroupLocation();
  5913. this._buildBackground();
  5914. this._buildItem();
  5915. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  5916. this.zr.addShape(this.shapeList[i]);
  5917. }
  5918. },
  5919. _buildItem: function () {
  5920. var data = this.legendOption.data;
  5921. var dataLength = data.length;
  5922. var itemName;
  5923. var itemType;
  5924. var itemShape;
  5925. var textShape;
  5926. var textStyle = this.legendOption.textStyle;
  5927. var dataTextStyle;
  5928. var dataFont;
  5929. var formattedName;
  5930. var zrWidth = this.zr.getWidth();
  5931. var zrHeight = this.zr.getHeight();
  5932. var lastX = this._itemGroupLocation.x;
  5933. var lastY = this._itemGroupLocation.y;
  5934. var itemWidth = this.legendOption.itemWidth;
  5935. var itemHeight = this.legendOption.itemHeight;
  5936. var itemGap = this.legendOption.itemGap;
  5937. var color;
  5938. if (this.legendOption.orient === 'vertical' && this.legendOption.x === 'right') {
  5939. lastX = this._itemGroupLocation.x + this._itemGroupLocation.width - itemWidth;
  5940. }
  5941. for (var i = 0; i < dataLength; i++) {
  5942. dataTextStyle = zrUtil.merge(data[i].textStyle || {}, textStyle);
  5943. dataFont = this.getFont(dataTextStyle);
  5944. itemName = this._getName(data[i]);
  5945. formattedName = this._getFormatterName(itemName);
  5946. if (itemName === '') {
  5947. if (this.legendOption.orient === 'horizontal') {
  5948. lastX = this._itemGroupLocation.x;
  5949. lastY += itemHeight + itemGap;
  5950. } else {
  5951. this.legendOption.x === 'right' ? lastX -= this._itemGroupLocation.maxWidth + itemGap : lastX += this._itemGroupLocation.maxWidth + itemGap;
  5952. lastY = this._itemGroupLocation.y;
  5953. }
  5954. continue;
  5955. }
  5956. itemType = data[i].icon || this._getSomethingByName(itemName).type;
  5957. color = this.getColor(itemName);
  5958. if (this.legendOption.orient === 'horizontal') {
  5959. if (zrWidth - lastX < 200 && itemWidth + 5 + zrArea.getTextWidth(formattedName, dataFont) + (i === dataLength - 1 || data[i + 1] === '' ? 0 : itemGap) >= zrWidth - lastX) {
  5960. lastX = this._itemGroupLocation.x;
  5961. lastY += itemHeight + itemGap;
  5962. }
  5963. } else {
  5964. if (zrHeight - lastY < 200 && itemHeight + (i === dataLength - 1 || data[i + 1] === '' ? 0 : itemGap) >= zrHeight - lastY) {
  5965. this.legendOption.x === 'right' ? lastX -= this._itemGroupLocation.maxWidth + itemGap : lastX += this._itemGroupLocation.maxWidth + itemGap;
  5966. lastY = this._itemGroupLocation.y;
  5967. }
  5968. }
  5969. itemShape = this._getItemShapeByType(lastX, lastY, itemWidth, itemHeight, this._selectedMap[itemName] && this._hasDataMap[itemName] ? color : '#ccc', itemType, color);
  5970. itemShape._name = itemName;
  5971. itemShape = new IconShape(itemShape);
  5972. textShape = {
  5973. zlevel: this.getZlevelBase(),
  5974. z: this.getZBase(),
  5975. style: {
  5976. x: lastX + itemWidth + 5,
  5977. y: lastY + itemHeight / 2,
  5978. color: this._selectedMap[itemName] ? dataTextStyle.color === 'auto' ? color : dataTextStyle.color : '#ccc',
  5979. text: formattedName,
  5980. textFont: dataFont,
  5981. textBaseline: 'middle'
  5982. },
  5983. highlightStyle: {
  5984. color: color,
  5985. brushType: 'fill'
  5986. },
  5987. hoverable: !!this.legendOption.selectedMode,
  5988. clickable: !!this.legendOption.selectedMode
  5989. };
  5990. if (this.legendOption.orient === 'vertical' && this.legendOption.x === 'right') {
  5991. textShape.style.x -= itemWidth + 10;
  5992. textShape.style.textAlign = 'right';
  5993. }
  5994. textShape._name = itemName;
  5995. textShape = new TextShape(textShape);
  5996. if (this.legendOption.selectedMode) {
  5997. itemShape.onclick = textShape.onclick = this._legendSelected;
  5998. itemShape.onmouseover = textShape.onmouseover = this._dispatchHoverLink;
  5999. itemShape.hoverConnect = textShape.id;
  6000. textShape.hoverConnect = itemShape.id;
  6001. }
  6002. this.shapeList.push(itemShape);
  6003. this.shapeList.push(textShape);
  6004. if (this.legendOption.orient === 'horizontal') {
  6005. lastX += itemWidth + 5 + zrArea.getTextWidth(formattedName, dataFont) + itemGap;
  6006. } else {
  6007. lastY += itemHeight + itemGap;
  6008. }
  6009. }
  6010. if (this.legendOption.orient === 'horizontal' && this.legendOption.x === 'center' && lastY != this._itemGroupLocation.y) {
  6011. this._mLineOptimize();
  6012. }
  6013. },
  6014. _getName: function (data) {
  6015. return typeof data.name != 'undefined' ? data.name : data;
  6016. },
  6017. _getFormatterName: function (itemName) {
  6018. var formatter = this.legendOption.formatter;
  6019. var formattedName;
  6020. if (typeof formatter === 'function') {
  6021. formattedName = formatter.call(this.myChart, itemName);
  6022. } else if (typeof formatter === 'string') {
  6023. formattedName = formatter.replace('{name}', itemName);
  6024. } else {
  6025. formattedName = itemName;
  6026. }
  6027. return formattedName;
  6028. },
  6029. _getFormatterNameFromData: function (data) {
  6030. var itemName = this._getName(data);
  6031. return this._getFormatterName(itemName);
  6032. },
  6033. _mLineOptimize: function () {
  6034. var lineOffsetArray = [];
  6035. var lastX = this._itemGroupLocation.x;
  6036. for (var i = 2, l = this.shapeList.length; i < l; i++) {
  6037. if (this.shapeList[i].style.x === lastX) {
  6038. 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);
  6039. } else if (i === l - 1) {
  6040. lineOffsetArray.push((this._itemGroupLocation.width - (this.shapeList[i].style.x + zrArea.getTextWidth(this.shapeList[i].style.text, this.shapeList[i].style.textFont) - lastX)) / 2);
  6041. }
  6042. }
  6043. var curLineIndex = -1;
  6044. for (var i = 1, l = this.shapeList.length; i < l; i++) {
  6045. if (this.shapeList[i].style.x === lastX) {
  6046. curLineIndex++;
  6047. }
  6048. if (lineOffsetArray[curLineIndex] === 0) {
  6049. continue;
  6050. } else {
  6051. this.shapeList[i].style.x += lineOffsetArray[curLineIndex];
  6052. }
  6053. }
  6054. },
  6055. _buildBackground: function () {
  6056. var padding = this.reformCssArray(this.legendOption.padding);
  6057. this.shapeList.push(new RectangleShape({
  6058. zlevel: this.getZlevelBase(),
  6059. z: this.getZBase(),
  6060. hoverable: false,
  6061. style: {
  6062. x: this._itemGroupLocation.x - padding[3],
  6063. y: this._itemGroupLocation.y - padding[0],
  6064. width: this._itemGroupLocation.width + padding[3] + padding[1],
  6065. height: this._itemGroupLocation.height + padding[0] + padding[2],
  6066. brushType: this.legendOption.borderWidth === 0 ? 'fill' : 'both',
  6067. color: this.legendOption.backgroundColor,
  6068. strokeColor: this.legendOption.borderColor,
  6069. lineWidth: this.legendOption.borderWidth
  6070. }
  6071. }));
  6072. },
  6073. _getItemGroupLocation: function () {
  6074. var data = this.legendOption.data;
  6075. var dataLength = data.length;
  6076. var itemGap = this.legendOption.itemGap;
  6077. var itemWidth = this.legendOption.itemWidth + 5;
  6078. var itemHeight = this.legendOption.itemHeight;
  6079. var textStyle = this.legendOption.textStyle;
  6080. var font = this.getFont(textStyle);
  6081. var totalWidth = 0;
  6082. var totalHeight = 0;
  6083. var padding = this.reformCssArray(this.legendOption.padding);
  6084. var zrWidth = this.zr.getWidth() - padding[1] - padding[3];
  6085. var zrHeight = this.zr.getHeight() - padding[0] - padding[2];
  6086. var temp = 0;
  6087. var maxWidth = 0;
  6088. if (this.legendOption.orient === 'horizontal') {
  6089. totalHeight = itemHeight;
  6090. for (var i = 0; i < dataLength; i++) {
  6091. if (this._getName(data[i]) === '') {
  6092. temp -= itemGap;
  6093. totalWidth = Math.max(totalWidth, temp);
  6094. totalHeight += itemHeight + itemGap;
  6095. temp = 0;
  6096. continue;
  6097. }
  6098. var tempTextWidth = zrArea.getTextWidth(this._getFormatterNameFromData(data[i]), data[i].textStyle ? this.getFont(zrUtil.merge(data[i].textStyle || {}, textStyle)) : font);
  6099. if (temp + itemWidth + tempTextWidth + itemGap > zrWidth) {
  6100. temp -= itemGap;
  6101. totalWidth = Math.max(totalWidth, temp);
  6102. totalHeight += itemHeight + itemGap;
  6103. temp = 0;
  6104. } else {
  6105. temp += itemWidth + tempTextWidth + itemGap;
  6106. totalWidth = Math.max(totalWidth, temp - itemGap);
  6107. }
  6108. }
  6109. } else {
  6110. for (var i = 0; i < dataLength; i++) {
  6111. maxWidth = Math.max(maxWidth, zrArea.getTextWidth(this._getFormatterNameFromData(data[i]), data[i].textStyle ? this.getFont(zrUtil.merge(data[i].textStyle || {}, textStyle)) : font));
  6112. }
  6113. maxWidth += itemWidth;
  6114. totalWidth = maxWidth;
  6115. for (var i = 0; i < dataLength; i++) {
  6116. if (this._getName(data[i]) === '') {
  6117. totalWidth += maxWidth + itemGap;
  6118. temp -= itemGap;
  6119. totalHeight = Math.max(totalHeight, temp);
  6120. temp = 0;
  6121. continue;
  6122. }
  6123. if (temp + itemHeight + itemGap > zrHeight) {
  6124. totalWidth += maxWidth + itemGap;
  6125. temp -= itemGap;
  6126. totalHeight = Math.max(totalHeight, temp);
  6127. temp = 0;
  6128. } else {
  6129. temp += itemHeight + itemGap;
  6130. totalHeight = Math.max(totalHeight, temp - itemGap);
  6131. }
  6132. }
  6133. }
  6134. zrWidth = this.zr.getWidth();
  6135. zrHeight = this.zr.getHeight();
  6136. var x;
  6137. switch (this.legendOption.x) {
  6138. case 'center':
  6139. x = Math.floor((zrWidth - totalWidth) / 2);
  6140. break;
  6141. case 'left':
  6142. x = padding[3] + this.legendOption.borderWidth;
  6143. break;
  6144. case 'right':
  6145. x = zrWidth - totalWidth - padding[1] - padding[3] - this.legendOption.borderWidth * 2;
  6146. break;
  6147. default:
  6148. x = this.parsePercent(this.legendOption.x, zrWidth);
  6149. break;
  6150. }
  6151. var y;
  6152. switch (this.legendOption.y) {
  6153. case 'top':
  6154. y = padding[0] + this.legendOption.borderWidth;
  6155. break;
  6156. case 'bottom':
  6157. y = zrHeight - totalHeight - padding[0] - padding[2] - this.legendOption.borderWidth * 2;
  6158. break;
  6159. case 'center':
  6160. y = Math.floor((zrHeight - totalHeight) / 2);
  6161. break;
  6162. default:
  6163. y = this.parsePercent(this.legendOption.y, zrHeight);
  6164. break;
  6165. }
  6166. return {
  6167. x: x,
  6168. y: y,
  6169. width: totalWidth,
  6170. height: totalHeight,
  6171. maxWidth: maxWidth
  6172. };
  6173. },
  6174. _getSomethingByName: function (name) {
  6175. var series = this.option.series;
  6176. var data;
  6177. for (var i = 0, l = series.length; i < l; i++) {
  6178. if (series[i].name === name) {
  6179. return {
  6180. type: series[i].type,
  6181. series: series[i],
  6182. seriesIndex: i,
  6183. data: null,
  6184. dataIndex: -1
  6185. };
  6186. }
  6187. 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) {
  6188. data = series[i].categories || series[i].data || series[i].nodes;
  6189. for (var j = 0, k = data.length; j < k; j++) {
  6190. if (data[j].name === name) {
  6191. return {
  6192. type: series[i].type,
  6193. series: series[i],
  6194. seriesIndex: i,
  6195. data: data[j],
  6196. dataIndex: j
  6197. };
  6198. }
  6199. }
  6200. }
  6201. }
  6202. return {
  6203. type: 'bar',
  6204. series: null,
  6205. seriesIndex: -1,
  6206. data: null,
  6207. dataIndex: -1
  6208. };
  6209. },
  6210. _getItemShapeByType: function (x, y, width, height, color, itemType, defaultColor) {
  6211. var highlightColor = color === '#ccc' ? defaultColor : color;
  6212. var itemShape = {
  6213. zlevel: this.getZlevelBase(),
  6214. z: this.getZBase(),
  6215. style: {
  6216. iconType: 'legendicon' + itemType,
  6217. x: x,
  6218. y: y,
  6219. width: width,
  6220. height: height,
  6221. color: color,
  6222. strokeColor: color,
  6223. lineWidth: 2
  6224. },
  6225. highlightStyle: {
  6226. color: highlightColor,
  6227. strokeColor: highlightColor,
  6228. lineWidth: 1
  6229. },
  6230. hoverable: this.legendOption.selectedMode,
  6231. clickable: this.legendOption.selectedMode
  6232. };
  6233. var imageLocation;
  6234. if (itemType.match('image')) {
  6235. var imageLocation = itemType.replace(new RegExp('^image:\\/\\/'), '');
  6236. itemType = 'image';
  6237. }
  6238. switch (itemType) {
  6239. case 'line':
  6240. itemShape.style.brushType = 'stroke';
  6241. itemShape.highlightStyle.lineWidth = 3;
  6242. break;
  6243. case 'radar':
  6244. case 'scatter':
  6245. itemShape.highlightStyle.lineWidth = 3;
  6246. break;
  6247. case 'k':
  6248. itemShape.style.brushType = 'both';
  6249. itemShape.highlightStyle.lineWidth = 3;
  6250. itemShape.highlightStyle.color = itemShape.style.color = this.deepQuery([
  6251. this.ecTheme,
  6252. ecConfig
  6253. ], 'k.itemStyle.normal.color') || '#fff';
  6254. itemShape.style.strokeColor = color != '#ccc' ? this.deepQuery([
  6255. this.ecTheme,
  6256. ecConfig
  6257. ], 'k.itemStyle.normal.lineStyle.color') || '#ff3200' : color;
  6258. break;
  6259. case 'image':
  6260. itemShape.style.iconType = 'image';
  6261. itemShape.style.image = imageLocation;
  6262. if (color === '#ccc') {
  6263. itemShape.style.opacity = 0.5;
  6264. }
  6265. break;
  6266. }
  6267. return itemShape;
  6268. },
  6269. __legendSelected: function (param) {
  6270. var itemName = param.target._name;
  6271. if (this.legendOption.selectedMode === 'single') {
  6272. for (var k in this._selectedMap) {
  6273. this._selectedMap[k] = false;
  6274. }
  6275. }
  6276. this._selectedMap[itemName] = !this._selectedMap[itemName];
  6277. this.messageCenter.dispatch(ecConfig.EVENT.LEGEND_SELECTED, param.event, {
  6278. selected: this._selectedMap,
  6279. target: itemName
  6280. }, this.myChart);
  6281. },
  6282. __dispatchHoverLink: function (param) {
  6283. this.messageCenter.dispatch(ecConfig.EVENT.LEGEND_HOVERLINK, param.event, { target: param.target._name }, this.myChart);
  6284. return;
  6285. },
  6286. refresh: function (newOption) {
  6287. if (newOption) {
  6288. this.option = newOption || this.option;
  6289. this.option.legend = this.reformOption(this.option.legend);
  6290. this.legendOption = this.option.legend;
  6291. var data = this.legendOption.data || [];
  6292. var itemName;
  6293. var something;
  6294. var color;
  6295. var queryTarget;
  6296. if (this.legendOption.selected) {
  6297. for (var k in this.legendOption.selected) {
  6298. this._selectedMap[k] = typeof this._selectedMap[k] != 'undefined' ? this._selectedMap[k] : this.legendOption.selected[k];
  6299. }
  6300. }
  6301. for (var i = 0, dataLength = data.length; i < dataLength; i++) {
  6302. itemName = this._getName(data[i]);
  6303. if (itemName === '') {
  6304. continue;
  6305. }
  6306. something = this._getSomethingByName(itemName);
  6307. if (!something.series) {
  6308. this._hasDataMap[itemName] = false;
  6309. } else {
  6310. this._hasDataMap[itemName] = true;
  6311. if (something.data && (something.type === ecConfig.CHART_TYPE_PIE || something.type === ecConfig.CHART_TYPE_FORCE || something.type === ecConfig.CHART_TYPE_FUNNEL)) {
  6312. queryTarget = [
  6313. something.data,
  6314. something.series
  6315. ];
  6316. } else {
  6317. queryTarget = [something.series];
  6318. }
  6319. color = this.getItemStyleColor(this.deepQuery(queryTarget, 'itemStyle.normal.color'), something.seriesIndex, something.dataIndex, something.data);
  6320. if (color && something.type != ecConfig.CHART_TYPE_K) {
  6321. this.setColor(itemName, color);
  6322. }
  6323. this._selectedMap[itemName] = this._selectedMap[itemName] != null ? this._selectedMap[itemName] : true;
  6324. }
  6325. }
  6326. }
  6327. this.clear();
  6328. this._buildShape();
  6329. },
  6330. getRelatedAmount: function (name) {
  6331. var amount = 0;
  6332. var series = this.option.series;
  6333. var data;
  6334. for (var i = 0, l = series.length; i < l; i++) {
  6335. if (series[i].name === name) {
  6336. amount++;
  6337. }
  6338. 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) {
  6339. data = series[i].type != ecConfig.CHART_TYPE_FORCE ? series[i].data : series[i].categories;
  6340. for (var j = 0, k = data.length; j < k; j++) {
  6341. if (data[j].name === name && data[j].value != '-') {
  6342. amount++;
  6343. }
  6344. }
  6345. }
  6346. }
  6347. return amount;
  6348. },
  6349. setColor: function (legendName, color) {
  6350. this._colorMap[legendName] = color;
  6351. },
  6352. getColor: function (legendName) {
  6353. if (!this._colorMap[legendName]) {
  6354. this._colorMap[legendName] = this.zr.getColor(this._colorIndex++);
  6355. }
  6356. return this._colorMap[legendName];
  6357. },
  6358. hasColor: function (legendName) {
  6359. return this._colorMap[legendName] ? this._colorMap[legendName] : false;
  6360. },
  6361. add: function (name, color) {
  6362. var data = this.legendOption.data;
  6363. for (var i = 0, dataLength = data.length; i < dataLength; i++) {
  6364. if (this._getName(data[i]) === name) {
  6365. return;
  6366. }
  6367. }
  6368. this.legendOption.data.push(name);
  6369. this.setColor(name, color);
  6370. this._selectedMap[name] = true;
  6371. this._hasDataMap[name] = true;
  6372. },
  6373. del: function (name) {
  6374. var data = this.legendOption.data;
  6375. for (var i = 0, dataLength = data.length; i < dataLength; i++) {
  6376. if (this._getName(data[i]) === name) {
  6377. return this.legendOption.data.splice(i, 1);
  6378. }
  6379. }
  6380. },
  6381. getItemShape: function (name) {
  6382. if (name == null) {
  6383. return;
  6384. }
  6385. var shape;
  6386. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  6387. shape = this.shapeList[i];
  6388. if (shape._name === name && shape.type != 'text') {
  6389. return shape;
  6390. }
  6391. }
  6392. },
  6393. setItemShape: function (name, itemShape) {
  6394. var shape;
  6395. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  6396. shape = this.shapeList[i];
  6397. if (shape._name === name && shape.type != 'text') {
  6398. if (!this._selectedMap[name]) {
  6399. itemShape.style.color = '#ccc';
  6400. itemShape.style.strokeColor = '#ccc';
  6401. }
  6402. this.zr.modShape(shape.id, itemShape);
  6403. }
  6404. }
  6405. },
  6406. isSelected: function (itemName) {
  6407. if (typeof this._selectedMap[itemName] != 'undefined') {
  6408. return this._selectedMap[itemName];
  6409. } else {
  6410. return true;
  6411. }
  6412. },
  6413. getSelectedMap: function () {
  6414. return this._selectedMap;
  6415. },
  6416. setSelected: function (itemName, selectStatus) {
  6417. if (this.legendOption.selectedMode === 'single') {
  6418. for (var k in this._selectedMap) {
  6419. this._selectedMap[k] = false;
  6420. }
  6421. }
  6422. this._selectedMap[itemName] = selectStatus;
  6423. this.messageCenter.dispatch(ecConfig.EVENT.LEGEND_SELECTED, null, {
  6424. selected: this._selectedMap,
  6425. target: itemName
  6426. }, this.myChart);
  6427. },
  6428. onlegendSelected: function (param, status) {
  6429. var legendSelected = param.selected;
  6430. for (var itemName in legendSelected) {
  6431. if (this._selectedMap[itemName] != legendSelected[itemName]) {
  6432. status.needRefresh = true;
  6433. }
  6434. this._selectedMap[itemName] = legendSelected[itemName];
  6435. }
  6436. return;
  6437. }
  6438. };
  6439. var legendIcon = {
  6440. line: function (ctx, style) {
  6441. var dy = style.height / 2;
  6442. ctx.moveTo(style.x, style.y + dy);
  6443. ctx.lineTo(style.x + style.width, style.y + dy);
  6444. },
  6445. pie: function (ctx, style) {
  6446. var x = style.x;
  6447. var y = style.y;
  6448. var width = style.width;
  6449. var height = style.height;
  6450. SectorShape.prototype.buildPath(ctx, {
  6451. x: x + width / 2,
  6452. y: y + height + 2,
  6453. r: height,
  6454. r0: 6,
  6455. startAngle: 45,
  6456. endAngle: 135
  6457. });
  6458. },
  6459. eventRiver: function (ctx, style) {
  6460. var x = style.x;
  6461. var y = style.y;
  6462. var width = style.width;
  6463. var height = style.height;
  6464. ctx.moveTo(x, y + height);
  6465. ctx.bezierCurveTo(x + width, y + height, x, y + 4, x + width, y + 4);
  6466. ctx.lineTo(x + width, y);
  6467. ctx.bezierCurveTo(x, y, x + width, y + height - 4, x, y + height - 4);
  6468. ctx.lineTo(x, y + height);
  6469. },
  6470. k: function (ctx, style) {
  6471. var x = style.x;
  6472. var y = style.y;
  6473. var width = style.width;
  6474. var height = style.height;
  6475. CandleShape.prototype.buildPath(ctx, {
  6476. x: x + width / 2,
  6477. y: [
  6478. y + 1,
  6479. y + 1,
  6480. y + height - 6,
  6481. y + height
  6482. ],
  6483. width: width - 6
  6484. });
  6485. },
  6486. bar: function (ctx, style) {
  6487. var x = style.x;
  6488. var y = style.y + 1;
  6489. var width = style.width;
  6490. var height = style.height - 2;
  6491. var r = 3;
  6492. ctx.moveTo(x + r, y);
  6493. ctx.lineTo(x + width - r, y);
  6494. ctx.quadraticCurveTo(x + width, y, x + width, y + r);
  6495. ctx.lineTo(x + width, y + height - r);
  6496. ctx.quadraticCurveTo(x + width, y + height, x + width - r, y + height);
  6497. ctx.lineTo(x + r, y + height);
  6498. ctx.quadraticCurveTo(x, y + height, x, y + height - r);
  6499. ctx.lineTo(x, y + r);
  6500. ctx.quadraticCurveTo(x, y, x + r, y);
  6501. },
  6502. force: function (ctx, style) {
  6503. IconShape.prototype.iconLibrary.circle(ctx, style);
  6504. },
  6505. radar: function (ctx, style) {
  6506. var n = 6;
  6507. var x = style.x + style.width / 2;
  6508. var y = style.y + style.height / 2;
  6509. var r = style.height / 2;
  6510. var dStep = 2 * Math.PI / n;
  6511. var deg = -Math.PI / 2;
  6512. var xStart = x + r * Math.cos(deg);
  6513. var yStart = y + r * Math.sin(deg);
  6514. ctx.moveTo(xStart, yStart);
  6515. deg += dStep;
  6516. for (var i = 0, end = n - 1; i < end; i++) {
  6517. ctx.lineTo(x + r * Math.cos(deg), y + r * Math.sin(deg));
  6518. deg += dStep;
  6519. }
  6520. ctx.lineTo(xStart, yStart);
  6521. }
  6522. };
  6523. legendIcon.chord = legendIcon.pie;
  6524. legendIcon.map = legendIcon.bar;
  6525. for (var k in legendIcon) {
  6526. IconShape.prototype.iconLibrary['legendicon' + k] = legendIcon[k];
  6527. }
  6528. zrUtil.inherits(Legend, Base);
  6529. require('../component').define('legend', Legend);
  6530. return Legend;
  6531. });define('echarts/util/ecData', [], function () {
  6532. function pack(shape, series, seriesIndex, data, dataIndex, name, special, special2) {
  6533. var value;
  6534. if (typeof data != 'undefined') {
  6535. value = data.value == null ? data : data.value;
  6536. }
  6537. shape._echartsData = {
  6538. '_series': series,
  6539. '_seriesIndex': seriesIndex,
  6540. '_data': data,
  6541. '_dataIndex': dataIndex,
  6542. '_name': name,
  6543. '_value': value,
  6544. '_special': special,
  6545. '_special2': special2
  6546. };
  6547. return shape._echartsData;
  6548. }
  6549. function get(shape, key) {
  6550. var data = shape._echartsData;
  6551. if (!key) {
  6552. return data;
  6553. }
  6554. switch (key) {
  6555. case 'series':
  6556. case 'seriesIndex':
  6557. case 'data':
  6558. case 'dataIndex':
  6559. case 'name':
  6560. case 'value':
  6561. case 'special':
  6562. case 'special2':
  6563. return data && data['_' + key];
  6564. }
  6565. return null;
  6566. }
  6567. function set(shape, key, value) {
  6568. shape._echartsData = shape._echartsData || {};
  6569. switch (key) {
  6570. case 'series':
  6571. case 'seriesIndex':
  6572. case 'data':
  6573. case 'dataIndex':
  6574. case 'name':
  6575. case 'value':
  6576. case 'special':
  6577. case 'special2':
  6578. shape._echartsData['_' + key] = value;
  6579. break;
  6580. }
  6581. }
  6582. function clone(source, target) {
  6583. target._echartsData = {
  6584. '_series': source._echartsData._series,
  6585. '_seriesIndex': source._echartsData._seriesIndex,
  6586. '_data': source._echartsData._data,
  6587. '_dataIndex': source._echartsData._dataIndex,
  6588. '_name': source._echartsData._name,
  6589. '_value': source._echartsData._value,
  6590. '_special': source._echartsData._special,
  6591. '_special2': source._echartsData._special2
  6592. };
  6593. }
  6594. return {
  6595. pack: pack,
  6596. set: set,
  6597. get: get,
  6598. clone: clone
  6599. };
  6600. });define('echarts/chart', [], function () {
  6601. var self = {};
  6602. var _chartLibrary = {};
  6603. self.define = function (name, clazz) {
  6604. _chartLibrary[name] = clazz;
  6605. return self;
  6606. };
  6607. self.get = function (name) {
  6608. return _chartLibrary[name];
  6609. };
  6610. return self;
  6611. });define('zrender/tool/color', [
  6612. 'require',
  6613. '../tool/util'
  6614. ], function (require) {
  6615. var util = require('../tool/util');
  6616. var _ctx;
  6617. var palette = [
  6618. '#ff9277',
  6619. ' #dddd00',
  6620. ' #ffc877',
  6621. ' #bbe3ff',
  6622. ' #d5ffbb',
  6623. '#bbbbff',
  6624. ' #ddb000',
  6625. ' #b0dd00',
  6626. ' #e2bbff',
  6627. ' #ffbbe3',
  6628. '#ff7777',
  6629. ' #ff9900',
  6630. ' #83dd00',
  6631. ' #77e3ff',
  6632. ' #778fff',
  6633. '#c877ff',
  6634. ' #ff77ab',
  6635. ' #ff6600',
  6636. ' #aa8800',
  6637. ' #77c7ff',
  6638. '#ad77ff',
  6639. ' #ff77ff',
  6640. ' #dd0083',
  6641. ' #777700',
  6642. ' #00aa00',
  6643. '#0088aa',
  6644. ' #8400dd',
  6645. ' #aa0088',
  6646. ' #dd0000',
  6647. ' #772e00'
  6648. ];
  6649. var _palette = palette;
  6650. var highlightColor = 'rgba(255,255,0,0.5)';
  6651. var _highlightColor = highlightColor;
  6652. 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;
  6653. var _nameColors = {
  6654. aliceblue: '#f0f8ff',
  6655. antiquewhite: '#faebd7',
  6656. aqua: '#0ff',
  6657. aquamarine: '#7fffd4',
  6658. azure: '#f0ffff',
  6659. beige: '#f5f5dc',
  6660. bisque: '#ffe4c4',
  6661. black: '#000',
  6662. blanchedalmond: '#ffebcd',
  6663. blue: '#00f',
  6664. blueviolet: '#8a2be2',
  6665. brown: '#a52a2a',
  6666. burlywood: '#deb887',
  6667. cadetblue: '#5f9ea0',
  6668. chartreuse: '#7fff00',
  6669. chocolate: '#d2691e',
  6670. coral: '#ff7f50',
  6671. cornflowerblue: '#6495ed',
  6672. cornsilk: '#fff8dc',
  6673. crimson: '#dc143c',
  6674. cyan: '#0ff',
  6675. darkblue: '#00008b',
  6676. darkcyan: '#008b8b',
  6677. darkgoldenrod: '#b8860b',
  6678. darkgray: '#a9a9a9',
  6679. darkgrey: '#a9a9a9',
  6680. darkgreen: '#006400',
  6681. darkkhaki: '#bdb76b',
  6682. darkmagenta: '#8b008b',
  6683. darkolivegreen: '#556b2f',
  6684. darkorange: '#ff8c00',
  6685. darkorchid: '#9932cc',
  6686. darkred: '#8b0000',
  6687. darksalmon: '#e9967a',
  6688. darkseagreen: '#8fbc8f',
  6689. darkslateblue: '#483d8b',
  6690. darkslategray: '#2f4f4f',
  6691. darkslategrey: '#2f4f4f',
  6692. darkturquoise: '#00ced1',
  6693. darkviolet: '#9400d3',
  6694. deeppink: '#ff1493',
  6695. deepskyblue: '#00bfff',
  6696. dimgray: '#696969',
  6697. dimgrey: '#696969',
  6698. dodgerblue: '#1e90ff',
  6699. firebrick: '#b22222',
  6700. floralwhite: '#fffaf0',
  6701. forestgreen: '#228b22',
  6702. fuchsia: '#f0f',
  6703. gainsboro: '#dcdcdc',
  6704. ghostwhite: '#f8f8ff',
  6705. gold: '#ffd700',
  6706. goldenrod: '#daa520',
  6707. gray: '#808080',
  6708. grey: '#808080',
  6709. green: '#008000',
  6710. greenyellow: '#adff2f',
  6711. honeydew: '#f0fff0',
  6712. hotpink: '#ff69b4',
  6713. indianred: '#cd5c5c',
  6714. indigo: '#4b0082',
  6715. ivory: '#fffff0',
  6716. khaki: '#f0e68c',
  6717. lavender: '#e6e6fa',
  6718. lavenderblush: '#fff0f5',
  6719. lawngreen: '#7cfc00',
  6720. lemonchiffon: '#fffacd',
  6721. lightblue: '#add8e6',
  6722. lightcoral: '#f08080',
  6723. lightcyan: '#e0ffff',
  6724. lightgoldenrodyellow: '#fafad2',
  6725. lightgray: '#d3d3d3',
  6726. lightgrey: '#d3d3d3',
  6727. lightgreen: '#90ee90',
  6728. lightpink: '#ffb6c1',
  6729. lightsalmon: '#ffa07a',
  6730. lightseagreen: '#20b2aa',
  6731. lightskyblue: '#87cefa',
  6732. lightslategray: '#789',
  6733. lightslategrey: '#789',
  6734. lightsteelblue: '#b0c4de',
  6735. lightyellow: '#ffffe0',
  6736. lime: '#0f0',
  6737. limegreen: '#32cd32',
  6738. linen: '#faf0e6',
  6739. magenta: '#f0f',
  6740. maroon: '#800000',
  6741. mediumaquamarine: '#66cdaa',
  6742. mediumblue: '#0000cd',
  6743. mediumorchid: '#ba55d3',
  6744. mediumpurple: '#9370d8',
  6745. mediumseagreen: '#3cb371',
  6746. mediumslateblue: '#7b68ee',
  6747. mediumspringgreen: '#00fa9a',
  6748. mediumturquoise: '#48d1cc',
  6749. mediumvioletred: '#c71585',
  6750. midnightblue: '#191970',
  6751. mintcream: '#f5fffa',
  6752. mistyrose: '#ffe4e1',
  6753. moccasin: '#ffe4b5',
  6754. navajowhite: '#ffdead',
  6755. navy: '#000080',
  6756. oldlace: '#fdf5e6',
  6757. olive: '#808000',
  6758. olivedrab: '#6b8e23',
  6759. orange: '#ffa500',
  6760. orangered: '#ff4500',
  6761. orchid: '#da70d6',
  6762. palegoldenrod: '#eee8aa',
  6763. palegreen: '#98fb98',
  6764. paleturquoise: '#afeeee',
  6765. palevioletred: '#d87093',
  6766. papayawhip: '#ffefd5',
  6767. peachpuff: '#ffdab9',
  6768. peru: '#cd853f',
  6769. pink: '#ffc0cb',
  6770. plum: '#dda0dd',
  6771. powderblue: '#b0e0e6',
  6772. purple: '#800080',
  6773. red: '#f00',
  6774. rosybrown: '#bc8f8f',
  6775. royalblue: '#4169e1',
  6776. saddlebrown: '#8b4513',
  6777. salmon: '#fa8072',
  6778. sandybrown: '#f4a460',
  6779. seagreen: '#2e8b57',
  6780. seashell: '#fff5ee',
  6781. sienna: '#a0522d',
  6782. silver: '#c0c0c0',
  6783. skyblue: '#87ceeb',
  6784. slateblue: '#6a5acd',
  6785. slategray: '#708090',
  6786. slategrey: '#708090',
  6787. snow: '#fffafa',
  6788. springgreen: '#00ff7f',
  6789. steelblue: '#4682b4',
  6790. tan: '#d2b48c',
  6791. teal: '#008080',
  6792. thistle: '#d8bfd8',
  6793. tomato: '#ff6347',
  6794. turquoise: '#40e0d0',
  6795. violet: '#ee82ee',
  6796. wheat: '#f5deb3',
  6797. white: '#fff',
  6798. whitesmoke: '#f5f5f5',
  6799. yellow: '#ff0',
  6800. yellowgreen: '#9acd32'
  6801. };
  6802. function customPalette(userPalete) {
  6803. palette = userPalete;
  6804. }
  6805. function resetPalette() {
  6806. palette = _palette;
  6807. }
  6808. function getColor(idx, userPalete) {
  6809. idx = idx | 0;
  6810. userPalete = userPalete || palette;
  6811. return userPalete[idx % userPalete.length];
  6812. }
  6813. function customHighlight(userHighlightColor) {
  6814. highlightColor = userHighlightColor;
  6815. }
  6816. function resetHighlight() {
  6817. _highlightColor = highlightColor;
  6818. }
  6819. function getHighlightColor() {
  6820. return highlightColor;
  6821. }
  6822. function getRadialGradient(x0, y0, r0, x1, y1, r1, colorList) {
  6823. if (!_ctx) {
  6824. _ctx = util.getContext();
  6825. }
  6826. var gradient = _ctx.createRadialGradient(x0, y0, r0, x1, y1, r1);
  6827. for (var i = 0, l = colorList.length; i < l; i++) {
  6828. gradient.addColorStop(colorList[i][0], colorList[i][1]);
  6829. }
  6830. gradient.__nonRecursion = true;
  6831. return gradient;
  6832. }
  6833. function getLinearGradient(x0, y0, x1, y1, colorList) {
  6834. if (!_ctx) {
  6835. _ctx = util.getContext();
  6836. }
  6837. var gradient = _ctx.createLinearGradient(x0, y0, x1, y1);
  6838. for (var i = 0, l = colorList.length; i < l; i++) {
  6839. gradient.addColorStop(colorList[i][0], colorList[i][1]);
  6840. }
  6841. gradient.__nonRecursion = true;
  6842. return gradient;
  6843. }
  6844. function getStepColors(start, end, step) {
  6845. start = toRGBA(start);
  6846. end = toRGBA(end);
  6847. start = getData(start);
  6848. end = getData(end);
  6849. var colors = [];
  6850. var stepR = (end[0] - start[0]) / step;
  6851. var stepG = (end[1] - start[1]) / step;
  6852. var stepB = (end[2] - start[2]) / step;
  6853. var stepA = (end[3] - start[3]) / step;
  6854. for (var i = 0, r = start[0], g = start[1], b = start[2], a = start[3]; i < step; i++) {
  6855. colors[i] = toColor([
  6856. adjust(Math.floor(r), [
  6857. 0,
  6858. 255
  6859. ]),
  6860. adjust(Math.floor(g), [
  6861. 0,
  6862. 255
  6863. ]),
  6864. adjust(Math.floor(b), [
  6865. 0,
  6866. 255
  6867. ]),
  6868. a.toFixed(4) - 0
  6869. ], 'rgba');
  6870. r += stepR;
  6871. g += stepG;
  6872. b += stepB;
  6873. a += stepA;
  6874. }
  6875. r = end[0];
  6876. g = end[1];
  6877. b = end[2];
  6878. a = end[3];
  6879. colors[i] = toColor([
  6880. r,
  6881. g,
  6882. b,
  6883. a
  6884. ], 'rgba');
  6885. return colors;
  6886. }
  6887. function getGradientColors(colors, step) {
  6888. var ret = [];
  6889. var len = colors.length;
  6890. if (step === undefined) {
  6891. step = 20;
  6892. }
  6893. if (len === 1) {
  6894. ret = getStepColors(colors[0], colors[0], step);
  6895. } else if (len > 1) {
  6896. for (var i = 0, n = len - 1; i < n; i++) {
  6897. var steps = getStepColors(colors[i], colors[i + 1], step);
  6898. if (i < n - 1) {
  6899. steps.pop();
  6900. }
  6901. ret = ret.concat(steps);
  6902. }
  6903. }
  6904. return ret;
  6905. }
  6906. function toColor(data, format) {
  6907. format = format || 'rgb';
  6908. if (data && (data.length === 3 || data.length === 4)) {
  6909. data = map(data, function (c) {
  6910. return c > 1 ? Math.ceil(c) : c;
  6911. });
  6912. if (format.indexOf('hex') > -1) {
  6913. return '#' + ((1 << 24) + (data[0] << 16) + (data[1] << 8) + +data[2]).toString(16).slice(1);
  6914. } else if (format.indexOf('hs') > -1) {
  6915. var sx = map(data.slice(1, 3), function (c) {
  6916. return c + '%';
  6917. });
  6918. data[1] = sx[0];
  6919. data[2] = sx[1];
  6920. }
  6921. if (format.indexOf('a') > -1) {
  6922. if (data.length === 3) {
  6923. data.push(1);
  6924. }
  6925. data[3] = adjust(data[3], [
  6926. 0,
  6927. 1
  6928. ]);
  6929. return format + '(' + data.slice(0, 4).join(',') + ')';
  6930. }
  6931. return format + '(' + data.slice(0, 3).join(',') + ')';
  6932. }
  6933. }
  6934. function toArray(color) {
  6935. color = trim(color);
  6936. if (color.indexOf('rgba') < 0) {
  6937. color = toRGBA(color);
  6938. }
  6939. var data = [];
  6940. var i = 0;
  6941. color.replace(/[\d.]+/g, function (n) {
  6942. if (i < 3) {
  6943. n = n | 0;
  6944. } else {
  6945. n = +n;
  6946. }
  6947. data[i++] = n;
  6948. });
  6949. return data;
  6950. }
  6951. function convert(color, format) {
  6952. if (!isCalculableColor(color)) {
  6953. return color;
  6954. }
  6955. var data = getData(color);
  6956. var alpha = data[3];
  6957. if (typeof alpha === 'undefined') {
  6958. alpha = 1;
  6959. }
  6960. if (color.indexOf('hsb') > -1) {
  6961. data = _HSV_2_RGB(data);
  6962. } else if (color.indexOf('hsl') > -1) {
  6963. data = _HSL_2_RGB(data);
  6964. }
  6965. if (format.indexOf('hsb') > -1 || format.indexOf('hsv') > -1) {
  6966. data = _RGB_2_HSB(data);
  6967. } else if (format.indexOf('hsl') > -1) {
  6968. data = _RGB_2_HSL(data);
  6969. }
  6970. data[3] = alpha;
  6971. return toColor(data, format);
  6972. }
  6973. function toRGBA(color) {
  6974. return convert(color, 'rgba');
  6975. }
  6976. function toRGB(color) {
  6977. return convert(color, 'rgb');
  6978. }
  6979. function toHex(color) {
  6980. return convert(color, 'hex');
  6981. }
  6982. function toHSVA(color) {
  6983. return convert(color, 'hsva');
  6984. }
  6985. function toHSV(color) {
  6986. return convert(color, 'hsv');
  6987. }
  6988. function toHSBA(color) {
  6989. return convert(color, 'hsba');
  6990. }
  6991. function toHSB(color) {
  6992. return convert(color, 'hsb');
  6993. }
  6994. function toHSLA(color) {
  6995. return convert(color, 'hsla');
  6996. }
  6997. function toHSL(color) {
  6998. return convert(color, 'hsl');
  6999. }
  7000. function toName(color) {
  7001. for (var key in _nameColors) {
  7002. if (toHex(_nameColors[key]) === toHex(color)) {
  7003. return key;
  7004. }
  7005. }
  7006. return null;
  7007. }
  7008. function trim(color) {
  7009. return String(color).replace(/\s+/g, '');
  7010. }
  7011. function normalize(color) {
  7012. if (_nameColors[color]) {
  7013. color = _nameColors[color];
  7014. }
  7015. color = trim(color);
  7016. color = color.replace(/hsv/i, 'hsb');
  7017. if (/^#[\da-f]{3}$/i.test(color)) {
  7018. color = parseInt(color.slice(1), 16);
  7019. var r = (color & 3840) << 8;
  7020. var g = (color & 240) << 4;
  7021. var b = color & 15;
  7022. color = '#' + ((1 << 24) + (r << 4) + r + (g << 4) + g + (b << 4) + b).toString(16).slice(1);
  7023. }
  7024. return color;
  7025. }
  7026. function lift(color, level) {
  7027. if (!isCalculableColor(color)) {
  7028. return color;
  7029. }
  7030. var direct = level > 0 ? 1 : -1;
  7031. if (typeof level === 'undefined') {
  7032. level = 0;
  7033. }
  7034. level = Math.abs(level) > 1 ? 1 : Math.abs(level);
  7035. color = toRGB(color);
  7036. var data = getData(color);
  7037. for (var i = 0; i < 3; i++) {
  7038. if (direct === 1) {
  7039. data[i] = data[i] * (1 - level) | 0;
  7040. } else {
  7041. data[i] = (255 - data[i]) * level + data[i] | 0;
  7042. }
  7043. }
  7044. return 'rgb(' + data.join(',') + ')';
  7045. }
  7046. function reverse(color) {
  7047. if (!isCalculableColor(color)) {
  7048. return color;
  7049. }
  7050. var data = getData(toRGBA(color));
  7051. data = map(data, function (c) {
  7052. return 255 - c;
  7053. });
  7054. return toColor(data, 'rgb');
  7055. }
  7056. function mix(color1, color2, weight) {
  7057. if (!isCalculableColor(color1) || !isCalculableColor(color2)) {
  7058. return color1;
  7059. }
  7060. if (typeof weight === 'undefined') {
  7061. weight = 0.5;
  7062. }
  7063. weight = 1 - adjust(weight, [
  7064. 0,
  7065. 1
  7066. ]);
  7067. var w = weight * 2 - 1;
  7068. var data1 = getData(toRGBA(color1));
  7069. var data2 = getData(toRGBA(color2));
  7070. var d = data1[3] - data2[3];
  7071. var weight1 = ((w * d === -1 ? w : (w + d) / (1 + w * d)) + 1) / 2;
  7072. var weight2 = 1 - weight1;
  7073. var data = [];
  7074. for (var i = 0; i < 3; i++) {
  7075. data[i] = data1[i] * weight1 + data2[i] * weight2;
  7076. }
  7077. var alpha = data1[3] * weight + data2[3] * (1 - weight);
  7078. alpha = Math.max(0, Math.min(1, alpha));
  7079. if (data1[3] === 1 && data2[3] === 1) {
  7080. return toColor(data, 'rgb');
  7081. }
  7082. data[3] = alpha;
  7083. return toColor(data, 'rgba');
  7084. }
  7085. function random() {
  7086. return '#' + (Math.random().toString(16) + '0000').slice(2, 8);
  7087. }
  7088. function getData(color) {
  7089. color = normalize(color);
  7090. var r = color.match(colorRegExp);
  7091. if (r === null) {
  7092. throw new Error('The color format error');
  7093. }
  7094. var d;
  7095. var a;
  7096. var data = [];
  7097. var rgb;
  7098. if (r[2]) {
  7099. d = r[2].replace('#', '').split('');
  7100. rgb = [
  7101. d[0] + d[1],
  7102. d[2] + d[3],
  7103. d[4] + d[5]
  7104. ];
  7105. data = map(rgb, function (c) {
  7106. return adjust(parseInt(c, 16), [
  7107. 0,
  7108. 255
  7109. ]);
  7110. });
  7111. } else if (r[4]) {
  7112. var rgba = r[4].split(',');
  7113. a = rgba[3];
  7114. rgb = rgba.slice(0, 3);
  7115. data = map(rgb, function (c) {
  7116. c = Math.floor(c.indexOf('%') > 0 ? parseInt(c, 0) * 2.55 : c);
  7117. return adjust(c, [
  7118. 0,
  7119. 255
  7120. ]);
  7121. });
  7122. if (typeof a !== 'undefined') {
  7123. data.push(adjust(parseFloat(a), [
  7124. 0,
  7125. 1
  7126. ]));
  7127. }
  7128. } else if (r[5] || r[6]) {
  7129. var hsxa = (r[5] || r[6]).split(',');
  7130. var h = parseInt(hsxa[0], 0) / 360;
  7131. var s = hsxa[1];
  7132. var x = hsxa[2];
  7133. a = hsxa[3];
  7134. data = map([
  7135. s,
  7136. x
  7137. ], function (c) {
  7138. return adjust(parseFloat(c) / 100, [
  7139. 0,
  7140. 1
  7141. ]);
  7142. });
  7143. data.unshift(h);
  7144. if (typeof a !== 'undefined') {
  7145. data.push(adjust(parseFloat(a), [
  7146. 0,
  7147. 1
  7148. ]));
  7149. }
  7150. }
  7151. return data;
  7152. }
  7153. function alpha(color, a) {
  7154. if (!isCalculableColor(color)) {
  7155. return color;
  7156. }
  7157. if (a === null) {
  7158. a = 1;
  7159. }
  7160. var data = getData(toRGBA(color));
  7161. data[3] = adjust(Number(a).toFixed(4), [
  7162. 0,
  7163. 1
  7164. ]);
  7165. return toColor(data, 'rgba');
  7166. }
  7167. function map(array, fun) {
  7168. if (typeof fun !== 'function') {
  7169. throw new TypeError();
  7170. }
  7171. var len = array ? array.length : 0;
  7172. for (var i = 0; i < len; i++) {
  7173. array[i] = fun(array[i]);
  7174. }
  7175. return array;
  7176. }
  7177. function adjust(value, region) {
  7178. if (value <= region[0]) {
  7179. value = region[0];
  7180. } else if (value >= region[1]) {
  7181. value = region[1];
  7182. }
  7183. return value;
  7184. }
  7185. function isCalculableColor(color) {
  7186. return color instanceof Array || typeof color === 'string';
  7187. }
  7188. function _HSV_2_RGB(data) {
  7189. var H = data[0];
  7190. var S = data[1];
  7191. var V = data[2];
  7192. var R;
  7193. var G;
  7194. var B;
  7195. if (S === 0) {
  7196. R = V * 255;
  7197. G = V * 255;
  7198. B = V * 255;
  7199. } else {
  7200. var h = H * 6;
  7201. if (h === 6) {
  7202. h = 0;
  7203. }
  7204. var i = h | 0;
  7205. var v1 = V * (1 - S);
  7206. var v2 = V * (1 - S * (h - i));
  7207. var v3 = V * (1 - S * (1 - (h - i)));
  7208. var r = 0;
  7209. var g = 0;
  7210. var b = 0;
  7211. if (i === 0) {
  7212. r = V;
  7213. g = v3;
  7214. b = v1;
  7215. } else if (i === 1) {
  7216. r = v2;
  7217. g = V;
  7218. b = v1;
  7219. } else if (i === 2) {
  7220. r = v1;
  7221. g = V;
  7222. b = v3;
  7223. } else if (i === 3) {
  7224. r = v1;
  7225. g = v2;
  7226. b = V;
  7227. } else if (i === 4) {
  7228. r = v3;
  7229. g = v1;
  7230. b = V;
  7231. } else {
  7232. r = V;
  7233. g = v1;
  7234. b = v2;
  7235. }
  7236. R = r * 255;
  7237. G = g * 255;
  7238. B = b * 255;
  7239. }
  7240. return [
  7241. R,
  7242. G,
  7243. B
  7244. ];
  7245. }
  7246. function _HSL_2_RGB(data) {
  7247. var H = data[0];
  7248. var S = data[1];
  7249. var L = data[2];
  7250. var R;
  7251. var G;
  7252. var B;
  7253. if (S === 0) {
  7254. R = L * 255;
  7255. G = L * 255;
  7256. B = L * 255;
  7257. } else {
  7258. var v2;
  7259. if (L < 0.5) {
  7260. v2 = L * (1 + S);
  7261. } else {
  7262. v2 = L + S - S * L;
  7263. }
  7264. var v1 = 2 * L - v2;
  7265. R = 255 * _HUE_2_RGB(v1, v2, H + 1 / 3);
  7266. G = 255 * _HUE_2_RGB(v1, v2, H);
  7267. B = 255 * _HUE_2_RGB(v1, v2, H - 1 / 3);
  7268. }
  7269. return [
  7270. R,
  7271. G,
  7272. B
  7273. ];
  7274. }
  7275. function _HUE_2_RGB(v1, v2, vH) {
  7276. if (vH < 0) {
  7277. vH += 1;
  7278. }
  7279. if (vH > 1) {
  7280. vH -= 1;
  7281. }
  7282. if (6 * vH < 1) {
  7283. return v1 + (v2 - v1) * 6 * vH;
  7284. }
  7285. if (2 * vH < 1) {
  7286. return v2;
  7287. }
  7288. if (3 * vH < 2) {
  7289. return v1 + (v2 - v1) * (2 / 3 - vH) * 6;
  7290. }
  7291. return v1;
  7292. }
  7293. function _RGB_2_HSB(data) {
  7294. var R = data[0] / 255;
  7295. var G = data[1] / 255;
  7296. var B = data[2] / 255;
  7297. var vMin = Math.min(R, G, B);
  7298. var vMax = Math.max(R, G, B);
  7299. var delta = vMax - vMin;
  7300. var V = vMax;
  7301. var H;
  7302. var S;
  7303. if (delta === 0) {
  7304. H = 0;
  7305. S = 0;
  7306. } else {
  7307. S = delta / vMax;
  7308. var deltaR = ((vMax - R) / 6 + delta / 2) / delta;
  7309. var deltaG = ((vMax - G) / 6 + delta / 2) / delta;
  7310. var deltaB = ((vMax - B) / 6 + delta / 2) / delta;
  7311. if (R === vMax) {
  7312. H = deltaB - deltaG;
  7313. } else if (G === vMax) {
  7314. H = 1 / 3 + deltaR - deltaB;
  7315. } else if (B === vMax) {
  7316. H = 2 / 3 + deltaG - deltaR;
  7317. }
  7318. if (H < 0) {
  7319. H += 1;
  7320. }
  7321. if (H > 1) {
  7322. H -= 1;
  7323. }
  7324. }
  7325. H = H * 360;
  7326. S = S * 100;
  7327. V = V * 100;
  7328. return [
  7329. H,
  7330. S,
  7331. V
  7332. ];
  7333. }
  7334. function _RGB_2_HSL(data) {
  7335. var R = data[0] / 255;
  7336. var G = data[1] / 255;
  7337. var B = data[2] / 255;
  7338. var vMin = Math.min(R, G, B);
  7339. var vMax = Math.max(R, G, B);
  7340. var delta = vMax - vMin;
  7341. var L = (vMax + vMin) / 2;
  7342. var H;
  7343. var S;
  7344. if (delta === 0) {
  7345. H = 0;
  7346. S = 0;
  7347. } else {
  7348. if (L < 0.5) {
  7349. S = delta / (vMax + vMin);
  7350. } else {
  7351. S = delta / (2 - vMax - vMin);
  7352. }
  7353. var deltaR = ((vMax - R) / 6 + delta / 2) / delta;
  7354. var deltaG = ((vMax - G) / 6 + delta / 2) / delta;
  7355. var deltaB = ((vMax - B) / 6 + delta / 2) / delta;
  7356. if (R === vMax) {
  7357. H = deltaB - deltaG;
  7358. } else if (G === vMax) {
  7359. H = 1 / 3 + deltaR - deltaB;
  7360. } else if (B === vMax) {
  7361. H = 2 / 3 + deltaG - deltaR;
  7362. }
  7363. if (H < 0) {
  7364. H += 1;
  7365. }
  7366. if (H > 1) {
  7367. H -= 1;
  7368. }
  7369. }
  7370. H = H * 360;
  7371. S = S * 100;
  7372. L = L * 100;
  7373. return [
  7374. H,
  7375. S,
  7376. L
  7377. ];
  7378. }
  7379. return {
  7380. customPalette: customPalette,
  7381. resetPalette: resetPalette,
  7382. getColor: getColor,
  7383. getHighlightColor: getHighlightColor,
  7384. customHighlight: customHighlight,
  7385. resetHighlight: resetHighlight,
  7386. getRadialGradient: getRadialGradient,
  7387. getLinearGradient: getLinearGradient,
  7388. getGradientColors: getGradientColors,
  7389. getStepColors: getStepColors,
  7390. reverse: reverse,
  7391. mix: mix,
  7392. lift: lift,
  7393. trim: trim,
  7394. random: random,
  7395. toRGB: toRGB,
  7396. toRGBA: toRGBA,
  7397. toHex: toHex,
  7398. toHSL: toHSL,
  7399. toHSLA: toHSLA,
  7400. toHSB: toHSB,
  7401. toHSBA: toHSBA,
  7402. toHSV: toHSV,
  7403. toHSVA: toHSVA,
  7404. toName: toName,
  7405. toColor: toColor,
  7406. toArray: toArray,
  7407. alpha: alpha,
  7408. getData: getData
  7409. };
  7410. });define('echarts/component/timeline', [
  7411. 'require',
  7412. './base',
  7413. 'zrender/shape/Rectangle',
  7414. '../util/shape/Icon',
  7415. '../util/shape/Chain',
  7416. '../config',
  7417. 'zrender/tool/util',
  7418. 'zrender/tool/area',
  7419. 'zrender/tool/event',
  7420. '../component'
  7421. ], function (require) {
  7422. var Base = require('./base');
  7423. var RectangleShape = require('zrender/shape/Rectangle');
  7424. var IconShape = require('../util/shape/Icon');
  7425. var ChainShape = require('../util/shape/Chain');
  7426. var ecConfig = require('../config');
  7427. ecConfig.timeline = {
  7428. zlevel: 0,
  7429. z: 4,
  7430. show: true,
  7431. type: 'time',
  7432. notMerge: false,
  7433. realtime: true,
  7434. x: 80,
  7435. x2: 80,
  7436. y2: 0,
  7437. height: 50,
  7438. backgroundColor: 'rgba(0,0,0,0)',
  7439. borderColor: '#ccc',
  7440. borderWidth: 0,
  7441. padding: 5,
  7442. controlPosition: 'left',
  7443. autoPlay: false,
  7444. loop: true,
  7445. playInterval: 2000,
  7446. lineStyle: {
  7447. width: 1,
  7448. color: '#666',
  7449. type: 'dashed'
  7450. },
  7451. label: {
  7452. show: true,
  7453. interval: 'auto',
  7454. rotate: 0,
  7455. textStyle: { color: '#333' }
  7456. },
  7457. checkpointStyle: {
  7458. symbol: 'auto',
  7459. symbolSize: 'auto',
  7460. color: 'auto',
  7461. borderColor: 'auto',
  7462. borderWidth: 'auto',
  7463. label: {
  7464. show: false,
  7465. textStyle: { color: 'auto' }
  7466. }
  7467. },
  7468. controlStyle: {
  7469. itemSize: 15,
  7470. itemGap: 5,
  7471. normal: { color: '#333' },
  7472. emphasis: { color: '#1e90ff' }
  7473. },
  7474. symbol: 'emptyDiamond',
  7475. symbolSize: 4,
  7476. currentIndex: 0
  7477. };
  7478. var zrUtil = require('zrender/tool/util');
  7479. var zrArea = require('zrender/tool/area');
  7480. var zrEvent = require('zrender/tool/event');
  7481. function Timeline(ecTheme, messageCenter, zr, option, myChart) {
  7482. Base.call(this, ecTheme, messageCenter, zr, option, myChart);
  7483. var self = this;
  7484. self._onclick = function (param) {
  7485. return self.__onclick(param);
  7486. };
  7487. self._ondrift = function (dx, dy) {
  7488. return self.__ondrift(this, dx, dy);
  7489. };
  7490. self._ondragend = function () {
  7491. return self.__ondragend();
  7492. };
  7493. self._setCurrentOption = function () {
  7494. var timelineOption = self.timelineOption;
  7495. self.currentIndex %= timelineOption.data.length;
  7496. var curOption = self.options[self.currentIndex] || {};
  7497. self.myChart.setOption(curOption, timelineOption.notMerge);
  7498. self.messageCenter.dispatch(ecConfig.EVENT.TIMELINE_CHANGED, null, {
  7499. currentIndex: self.currentIndex,
  7500. data: timelineOption.data[self.currentIndex].name != null ? timelineOption.data[self.currentIndex].name : timelineOption.data[self.currentIndex]
  7501. }, self.myChart);
  7502. };
  7503. self._onFrame = function () {
  7504. self._setCurrentOption();
  7505. self._syncHandleShape();
  7506. if (self.timelineOption.autoPlay) {
  7507. self.playTicket = setTimeout(function () {
  7508. self.currentIndex += 1;
  7509. if (!self.timelineOption.loop && self.currentIndex >= self.timelineOption.data.length) {
  7510. self.currentIndex = self.timelineOption.data.length - 1;
  7511. self.stop();
  7512. return;
  7513. }
  7514. self._onFrame();
  7515. }, self.timelineOption.playInterval);
  7516. }
  7517. };
  7518. this.setTheme(false);
  7519. this.options = this.option.options;
  7520. this.currentIndex = this.timelineOption.currentIndex % this.timelineOption.data.length;
  7521. if (!this.timelineOption.notMerge && this.currentIndex !== 0) {
  7522. this.options[this.currentIndex] = zrUtil.merge(this.options[this.currentIndex], this.options[0]);
  7523. }
  7524. if (this.timelineOption.show) {
  7525. this._buildShape();
  7526. this._syncHandleShape();
  7527. }
  7528. this._setCurrentOption();
  7529. if (this.timelineOption.autoPlay) {
  7530. var self = this;
  7531. this.playTicket = setTimeout(function () {
  7532. self.play();
  7533. }, this.ecTheme.animationDuration != null ? this.ecTheme.animationDuration : ecConfig.animationDuration);
  7534. }
  7535. }
  7536. Timeline.prototype = {
  7537. type: ecConfig.COMPONENT_TYPE_TIMELINE,
  7538. _buildShape: function () {
  7539. this._location = this._getLocation();
  7540. this._buildBackground();
  7541. this._buildControl();
  7542. this._chainPoint = this._getChainPoint();
  7543. if (this.timelineOption.label.show) {
  7544. var interval = this._getInterval();
  7545. for (var i = 0, len = this._chainPoint.length; i < len; i += interval) {
  7546. this._chainPoint[i].showLabel = true;
  7547. }
  7548. }
  7549. this._buildChain();
  7550. this._buildHandle();
  7551. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  7552. this.zr.addShape(this.shapeList[i]);
  7553. }
  7554. },
  7555. _getLocation: function () {
  7556. var timelineOption = this.timelineOption;
  7557. var padding = this.reformCssArray(this.timelineOption.padding);
  7558. var zrWidth = this.zr.getWidth();
  7559. var x = this.parsePercent(timelineOption.x, zrWidth);
  7560. var x2 = this.parsePercent(timelineOption.x2, zrWidth);
  7561. var width;
  7562. if (timelineOption.width == null) {
  7563. width = zrWidth - x - x2;
  7564. x2 = zrWidth - x2;
  7565. } else {
  7566. width = this.parsePercent(timelineOption.width, zrWidth);
  7567. x2 = x + width;
  7568. }
  7569. var zrHeight = this.zr.getHeight();
  7570. var height = this.parsePercent(timelineOption.height, zrHeight);
  7571. var y;
  7572. var y2;
  7573. if (timelineOption.y != null) {
  7574. y = this.parsePercent(timelineOption.y, zrHeight);
  7575. y2 = y + height;
  7576. } else {
  7577. y2 = zrHeight - this.parsePercent(timelineOption.y2, zrHeight);
  7578. y = y2 - height;
  7579. }
  7580. return {
  7581. x: x + padding[3],
  7582. y: y + padding[0],
  7583. x2: x2 - padding[1],
  7584. y2: y2 - padding[2],
  7585. width: width - padding[1] - padding[3],
  7586. height: height - padding[0] - padding[2]
  7587. };
  7588. },
  7589. _getReformedLabel: function (idx) {
  7590. var timelineOption = this.timelineOption;
  7591. var data = timelineOption.data[idx].name != null ? timelineOption.data[idx].name : timelineOption.data[idx];
  7592. var formatter = timelineOption.data[idx].formatter || timelineOption.label.formatter;
  7593. if (formatter) {
  7594. if (typeof formatter === 'function') {
  7595. data = formatter.call(this.myChart, data);
  7596. } else if (typeof formatter === 'string') {
  7597. data = formatter.replace('{value}', data);
  7598. }
  7599. }
  7600. return data;
  7601. },
  7602. _getInterval: function () {
  7603. var chainPoint = this._chainPoint;
  7604. var timelineOption = this.timelineOption;
  7605. var interval = timelineOption.label.interval;
  7606. if (interval === 'auto') {
  7607. var fontSize = timelineOption.label.textStyle.fontSize;
  7608. var data = timelineOption.data;
  7609. var dataLength = timelineOption.data.length;
  7610. if (dataLength > 3) {
  7611. var isEnough = false;
  7612. var labelSpace;
  7613. var labelSize;
  7614. interval = 0;
  7615. while (!isEnough && interval < dataLength) {
  7616. interval++;
  7617. isEnough = true;
  7618. for (var i = interval; i < dataLength; i += interval) {
  7619. labelSpace = chainPoint[i].x - chainPoint[i - interval].x;
  7620. if (timelineOption.label.rotate !== 0) {
  7621. labelSize = fontSize;
  7622. } else if (data[i].textStyle) {
  7623. labelSize = zrArea.getTextWidth(chainPoint[i].name, chainPoint[i].textFont);
  7624. } else {
  7625. var label = chainPoint[i].name + '';
  7626. var wLen = (label.match(/\w/g) || '').length;
  7627. var oLen = label.length - wLen;
  7628. labelSize = wLen * fontSize * 2 / 3 + oLen * fontSize;
  7629. }
  7630. if (labelSpace < labelSize) {
  7631. isEnough = false;
  7632. break;
  7633. }
  7634. }
  7635. }
  7636. } else {
  7637. interval = 1;
  7638. }
  7639. } else {
  7640. interval = interval - 0 + 1;
  7641. }
  7642. return interval;
  7643. },
  7644. _getChainPoint: function () {
  7645. var timelineOption = this.timelineOption;
  7646. var symbol = timelineOption.symbol.toLowerCase();
  7647. var symbolSize = timelineOption.symbolSize;
  7648. var rotate = timelineOption.label.rotate;
  7649. var textStyle = timelineOption.label.textStyle;
  7650. var textFont = this.getFont(textStyle);
  7651. var dataTextStyle;
  7652. var data = timelineOption.data;
  7653. var x = this._location.x;
  7654. var y = this._location.y + this._location.height / 4 * 3;
  7655. var width = this._location.x2 - this._location.x;
  7656. var len = data.length;
  7657. function _getName(i) {
  7658. return data[i].name != null ? data[i].name : data[i] + '';
  7659. }
  7660. var xList = [];
  7661. if (len > 1) {
  7662. var boundaryGap = width / len;
  7663. boundaryGap = boundaryGap > 50 ? 50 : boundaryGap < 20 ? 5 : boundaryGap;
  7664. width -= boundaryGap * 2;
  7665. if (timelineOption.type === 'number') {
  7666. for (var i = 0; i < len; i++) {
  7667. xList.push(x + boundaryGap + width / (len - 1) * i);
  7668. }
  7669. } else {
  7670. xList[0] = new Date(_getName(0).replace(/-/g, '/'));
  7671. xList[len - 1] = new Date(_getName(len - 1).replace(/-/g, '/')) - xList[0];
  7672. for (var i = 1; i < len; i++) {
  7673. xList[i] = x + boundaryGap + width * (new Date(_getName(i).replace(/-/g, '/')) - xList[0]) / xList[len - 1];
  7674. }
  7675. xList[0] = x + boundaryGap;
  7676. }
  7677. } else {
  7678. xList.push(x + width / 2);
  7679. }
  7680. var list = [];
  7681. var curSymbol;
  7682. var n;
  7683. var isEmpty;
  7684. var textAlign;
  7685. var rotation;
  7686. for (var i = 0; i < len; i++) {
  7687. x = xList[i];
  7688. curSymbol = data[i].symbol && data[i].symbol.toLowerCase() || symbol;
  7689. if (curSymbol.match('empty')) {
  7690. curSymbol = curSymbol.replace('empty', '');
  7691. isEmpty = true;
  7692. } else {
  7693. isEmpty = false;
  7694. }
  7695. if (curSymbol.match('star')) {
  7696. n = curSymbol.replace('star', '') - 0 || 5;
  7697. curSymbol = 'star';
  7698. }
  7699. dataTextStyle = data[i].textStyle ? zrUtil.merge(data[i].textStyle || {}, textStyle) : textStyle;
  7700. textAlign = dataTextStyle.align || 'center';
  7701. if (rotate) {
  7702. textAlign = rotate > 0 ? 'right' : 'left';
  7703. rotation = [
  7704. rotate * Math.PI / 180,
  7705. x,
  7706. y - 5
  7707. ];
  7708. } else {
  7709. rotation = false;
  7710. }
  7711. list.push({
  7712. x: x,
  7713. n: n,
  7714. isEmpty: isEmpty,
  7715. symbol: curSymbol,
  7716. symbolSize: data[i].symbolSize || symbolSize,
  7717. color: data[i].color,
  7718. borderColor: data[i].borderColor,
  7719. borderWidth: data[i].borderWidth,
  7720. name: this._getReformedLabel(i),
  7721. textColor: dataTextStyle.color,
  7722. textAlign: textAlign,
  7723. textBaseline: dataTextStyle.baseline || 'middle',
  7724. textX: x,
  7725. textY: y - (rotate ? 5 : 0),
  7726. textFont: data[i].textStyle ? this.getFont(dataTextStyle) : textFont,
  7727. rotation: rotation,
  7728. showLabel: false
  7729. });
  7730. }
  7731. return list;
  7732. },
  7733. _buildBackground: function () {
  7734. var timelineOption = this.timelineOption;
  7735. var padding = this.reformCssArray(this.timelineOption.padding);
  7736. var width = this._location.width;
  7737. var height = this._location.height;
  7738. if (timelineOption.borderWidth !== 0 || timelineOption.backgroundColor.replace(/\s/g, '') != 'rgba(0,0,0,0)') {
  7739. this.shapeList.push(new RectangleShape({
  7740. zlevel: this.getZlevelBase(),
  7741. z: this.getZBase(),
  7742. hoverable: false,
  7743. style: {
  7744. x: this._location.x - padding[3],
  7745. y: this._location.y - padding[0],
  7746. width: width + padding[1] + padding[3],
  7747. height: height + padding[0] + padding[2],
  7748. brushType: timelineOption.borderWidth === 0 ? 'fill' : 'both',
  7749. color: timelineOption.backgroundColor,
  7750. strokeColor: timelineOption.borderColor,
  7751. lineWidth: timelineOption.borderWidth
  7752. }
  7753. }));
  7754. }
  7755. },
  7756. _buildControl: function () {
  7757. var self = this;
  7758. var timelineOption = this.timelineOption;
  7759. var lineStyle = timelineOption.lineStyle;
  7760. var controlStyle = timelineOption.controlStyle;
  7761. if (timelineOption.controlPosition === 'none') {
  7762. return;
  7763. }
  7764. var iconSize = controlStyle.itemSize;
  7765. var iconGap = controlStyle.itemGap;
  7766. var x;
  7767. if (timelineOption.controlPosition === 'left') {
  7768. x = this._location.x;
  7769. this._location.x += (iconSize + iconGap) * 3;
  7770. } else {
  7771. x = this._location.x2 - ((iconSize + iconGap) * 3 - iconGap);
  7772. this._location.x2 -= (iconSize + iconGap) * 3;
  7773. }
  7774. var y = this._location.y;
  7775. var iconStyle = {
  7776. zlevel: this.getZlevelBase(),
  7777. z: this.getZBase() + 1,
  7778. style: {
  7779. iconType: 'timelineControl',
  7780. symbol: 'last',
  7781. x: x,
  7782. y: y,
  7783. width: iconSize,
  7784. height: iconSize,
  7785. brushType: 'stroke',
  7786. color: controlStyle.normal.color,
  7787. strokeColor: controlStyle.normal.color,
  7788. lineWidth: lineStyle.width
  7789. },
  7790. highlightStyle: {
  7791. color: controlStyle.emphasis.color,
  7792. strokeColor: controlStyle.emphasis.color,
  7793. lineWidth: lineStyle.width + 1
  7794. },
  7795. clickable: true
  7796. };
  7797. this._ctrLastShape = new IconShape(iconStyle);
  7798. this._ctrLastShape.onclick = function () {
  7799. self.last();
  7800. };
  7801. this.shapeList.push(this._ctrLastShape);
  7802. x += iconSize + iconGap;
  7803. this._ctrPlayShape = new IconShape(zrUtil.clone(iconStyle));
  7804. this._ctrPlayShape.style.brushType = 'fill';
  7805. this._ctrPlayShape.style.symbol = 'play';
  7806. this._ctrPlayShape.style.status = this.timelineOption.autoPlay ? 'playing' : 'stop';
  7807. this._ctrPlayShape.style.x = x;
  7808. this._ctrPlayShape.onclick = function () {
  7809. if (self._ctrPlayShape.style.status === 'stop') {
  7810. self.play();
  7811. } else {
  7812. self.stop();
  7813. }
  7814. };
  7815. this.shapeList.push(this._ctrPlayShape);
  7816. x += iconSize + iconGap;
  7817. this._ctrNextShape = new IconShape(zrUtil.clone(iconStyle));
  7818. this._ctrNextShape.style.symbol = 'next';
  7819. this._ctrNextShape.style.x = x;
  7820. this._ctrNextShape.onclick = function () {
  7821. self.next();
  7822. };
  7823. this.shapeList.push(this._ctrNextShape);
  7824. },
  7825. _buildChain: function () {
  7826. var timelineOption = this.timelineOption;
  7827. var lineStyle = timelineOption.lineStyle;
  7828. this._timelineShae = {
  7829. zlevel: this.getZlevelBase(),
  7830. z: this.getZBase(),
  7831. style: {
  7832. x: this._location.x,
  7833. y: this.subPixelOptimize(this._location.y, lineStyle.width),
  7834. width: this._location.x2 - this._location.x,
  7835. height: this._location.height,
  7836. chainPoint: this._chainPoint,
  7837. brushType: 'both',
  7838. strokeColor: lineStyle.color,
  7839. lineWidth: lineStyle.width,
  7840. lineType: lineStyle.type
  7841. },
  7842. hoverable: false,
  7843. clickable: true,
  7844. onclick: this._onclick
  7845. };
  7846. this._timelineShae = new ChainShape(this._timelineShae);
  7847. this.shapeList.push(this._timelineShae);
  7848. },
  7849. _buildHandle: function () {
  7850. var curPoint = this._chainPoint[this.currentIndex];
  7851. var symbolSize = curPoint.symbolSize + 1;
  7852. symbolSize = symbolSize < 5 ? 5 : symbolSize;
  7853. this._handleShape = {
  7854. zlevel: this.getZlevelBase(),
  7855. z: this.getZBase() + 1,
  7856. hoverable: false,
  7857. draggable: true,
  7858. style: {
  7859. iconType: 'diamond',
  7860. n: curPoint.n,
  7861. x: curPoint.x - symbolSize,
  7862. y: this._location.y + this._location.height / 4 - symbolSize,
  7863. width: symbolSize * 2,
  7864. height: symbolSize * 2,
  7865. brushType: 'both',
  7866. textPosition: 'specific',
  7867. textX: curPoint.x,
  7868. textY: this._location.y - this._location.height / 4,
  7869. textAlign: 'center',
  7870. textBaseline: 'middle'
  7871. },
  7872. highlightStyle: {},
  7873. ondrift: this._ondrift,
  7874. ondragend: this._ondragend
  7875. };
  7876. this._handleShape = new IconShape(this._handleShape);
  7877. this.shapeList.push(this._handleShape);
  7878. },
  7879. _syncHandleShape: function () {
  7880. if (!this.timelineOption.show) {
  7881. return;
  7882. }
  7883. var timelineOption = this.timelineOption;
  7884. var cpStyle = timelineOption.checkpointStyle;
  7885. var curPoint = this._chainPoint[this.currentIndex];
  7886. this._handleShape.style.text = cpStyle.label.show ? curPoint.name : '';
  7887. this._handleShape.style.textFont = curPoint.textFont;
  7888. this._handleShape.style.n = curPoint.n;
  7889. if (cpStyle.symbol === 'auto') {
  7890. this._handleShape.style.iconType = curPoint.symbol != 'none' ? curPoint.symbol : 'diamond';
  7891. } else {
  7892. this._handleShape.style.iconType = cpStyle.symbol;
  7893. if (cpStyle.symbol.match('star')) {
  7894. this._handleShape.style.n = cpStyle.symbol.replace('star', '') - 0 || 5;
  7895. this._handleShape.style.iconType = 'star';
  7896. }
  7897. }
  7898. var symbolSize;
  7899. if (cpStyle.symbolSize === 'auto') {
  7900. symbolSize = curPoint.symbolSize + 2;
  7901. symbolSize = symbolSize < 5 ? 5 : symbolSize;
  7902. } else {
  7903. symbolSize = cpStyle.symbolSize - 0;
  7904. }
  7905. this._handleShape.style.color = cpStyle.color === 'auto' ? curPoint.color ? curPoint.color : timelineOption.controlStyle.emphasis.color : cpStyle.color;
  7906. this._handleShape.style.textColor = cpStyle.label.textStyle.color === 'auto' ? this._handleShape.style.color : cpStyle.label.textStyle.color;
  7907. this._handleShape.highlightStyle.strokeColor = this._handleShape.style.strokeColor = cpStyle.borderColor === 'auto' ? curPoint.borderColor ? curPoint.borderColor : '#fff' : cpStyle.borderColor;
  7908. this._handleShape.style.lineWidth = cpStyle.borderWidth === 'auto' ? curPoint.borderWidth ? curPoint.borderWidth : 0 : cpStyle.borderWidth - 0;
  7909. this._handleShape.highlightStyle.lineWidth = this._handleShape.style.lineWidth + 1;
  7910. this.zr.animate(this._handleShape.id, 'style').when(500, {
  7911. x: curPoint.x - symbolSize,
  7912. textX: curPoint.x,
  7913. y: this._location.y + this._location.height / 4 - symbolSize,
  7914. width: symbolSize * 2,
  7915. height: symbolSize * 2
  7916. }).start('ExponentialOut');
  7917. },
  7918. _findChainIndex: function (x) {
  7919. var chainPoint = this._chainPoint;
  7920. var len = chainPoint.length;
  7921. if (x <= chainPoint[0].x) {
  7922. return 0;
  7923. } else if (x >= chainPoint[len - 1].x) {
  7924. return len - 1;
  7925. }
  7926. for (var i = 0; i < len - 1; i++) {
  7927. if (x >= chainPoint[i].x && x <= chainPoint[i + 1].x) {
  7928. return Math.abs(x - chainPoint[i].x) < Math.abs(x - chainPoint[i + 1].x) ? i : i + 1;
  7929. }
  7930. }
  7931. },
  7932. __onclick: function (param) {
  7933. var x = zrEvent.getX(param.event);
  7934. var newIndex = this._findChainIndex(x);
  7935. if (newIndex === this.currentIndex) {
  7936. return true;
  7937. }
  7938. this.currentIndex = newIndex;
  7939. this.timelineOption.autoPlay && this.stop();
  7940. clearTimeout(this.playTicket);
  7941. this._onFrame();
  7942. },
  7943. __ondrift: function (shape, dx) {
  7944. this.timelineOption.autoPlay && this.stop();
  7945. var chainPoint = this._chainPoint;
  7946. var len = chainPoint.length;
  7947. var newIndex;
  7948. if (shape.style.x + dx <= chainPoint[0].x - chainPoint[0].symbolSize) {
  7949. shape.style.x = chainPoint[0].x - chainPoint[0].symbolSize;
  7950. newIndex = 0;
  7951. } else if (shape.style.x + dx >= chainPoint[len - 1].x - chainPoint[len - 1].symbolSize) {
  7952. shape.style.x = chainPoint[len - 1].x - chainPoint[len - 1].symbolSize;
  7953. newIndex = len - 1;
  7954. } else {
  7955. shape.style.x += dx;
  7956. newIndex = this._findChainIndex(shape.style.x);
  7957. }
  7958. var curPoint = chainPoint[newIndex];
  7959. var symbolSize = curPoint.symbolSize + 2;
  7960. shape.style.iconType = curPoint.symbol;
  7961. shape.style.n = curPoint.n;
  7962. shape.style.textX = shape.style.x + symbolSize / 2;
  7963. shape.style.y = this._location.y + this._location.height / 4 - symbolSize;
  7964. shape.style.width = symbolSize * 2;
  7965. shape.style.height = symbolSize * 2;
  7966. shape.style.text = curPoint.name;
  7967. if (newIndex === this.currentIndex) {
  7968. return true;
  7969. }
  7970. this.currentIndex = newIndex;
  7971. if (this.timelineOption.realtime) {
  7972. clearTimeout(this.playTicket);
  7973. var self = this;
  7974. this.playTicket = setTimeout(function () {
  7975. self._setCurrentOption();
  7976. }, 200);
  7977. }
  7978. return true;
  7979. },
  7980. __ondragend: function () {
  7981. this.isDragend = true;
  7982. },
  7983. ondragend: function (param, status) {
  7984. if (!this.isDragend || !param.target) {
  7985. return;
  7986. }
  7987. !this.timelineOption.realtime && this._setCurrentOption();
  7988. status.dragOut = true;
  7989. status.dragIn = true;
  7990. status.needRefresh = false;
  7991. this.isDragend = false;
  7992. this._syncHandleShape();
  7993. return;
  7994. },
  7995. last: function () {
  7996. this.timelineOption.autoPlay && this.stop();
  7997. this.currentIndex -= 1;
  7998. if (this.currentIndex < 0) {
  7999. this.currentIndex = this.timelineOption.data.length - 1;
  8000. }
  8001. this._onFrame();
  8002. return this.currentIndex;
  8003. },
  8004. next: function () {
  8005. this.timelineOption.autoPlay && this.stop();
  8006. this.currentIndex += 1;
  8007. if (this.currentIndex >= this.timelineOption.data.length) {
  8008. this.currentIndex = 0;
  8009. }
  8010. this._onFrame();
  8011. return this.currentIndex;
  8012. },
  8013. play: function (targetIndex, autoPlay) {
  8014. if (this._ctrPlayShape && this._ctrPlayShape.style.status != 'playing') {
  8015. this._ctrPlayShape.style.status = 'playing';
  8016. this.zr.modShape(this._ctrPlayShape.id);
  8017. this.zr.refreshNextFrame();
  8018. }
  8019. this.timelineOption.autoPlay = autoPlay != null ? autoPlay : true;
  8020. if (!this.timelineOption.autoPlay) {
  8021. clearTimeout(this.playTicket);
  8022. }
  8023. this.currentIndex = targetIndex != null ? targetIndex : this.currentIndex + 1;
  8024. if (this.currentIndex >= this.timelineOption.data.length) {
  8025. this.currentIndex = 0;
  8026. }
  8027. this._onFrame();
  8028. return this.currentIndex;
  8029. },
  8030. stop: function () {
  8031. if (this._ctrPlayShape && this._ctrPlayShape.style.status != 'stop') {
  8032. this._ctrPlayShape.style.status = 'stop';
  8033. this.zr.modShape(this._ctrPlayShape.id);
  8034. this.zr.refreshNextFrame();
  8035. }
  8036. this.timelineOption.autoPlay = false;
  8037. clearTimeout(this.playTicket);
  8038. return this.currentIndex;
  8039. },
  8040. resize: function () {
  8041. if (this.timelineOption.show) {
  8042. this.clear();
  8043. this._buildShape();
  8044. this._syncHandleShape();
  8045. }
  8046. },
  8047. setTheme: function (needRefresh) {
  8048. this.timelineOption = this.reformOption(zrUtil.clone(this.option.timeline));
  8049. this.timelineOption.label.textStyle = this.getTextStyle(this.timelineOption.label.textStyle);
  8050. this.timelineOption.checkpointStyle.label.textStyle = this.getTextStyle(this.timelineOption.checkpointStyle.label.textStyle);
  8051. if (!this.myChart.canvasSupported) {
  8052. this.timelineOption.realtime = false;
  8053. }
  8054. if (this.timelineOption.show && needRefresh) {
  8055. this.clear();
  8056. this._buildShape();
  8057. this._syncHandleShape();
  8058. }
  8059. },
  8060. onbeforDispose: function () {
  8061. clearTimeout(this.playTicket);
  8062. }
  8063. };
  8064. function timelineControl(ctx, style) {
  8065. var lineWidth = 2;
  8066. var x = style.x + lineWidth;
  8067. var y = style.y + lineWidth + 2;
  8068. var width = style.width - lineWidth;
  8069. var height = style.height - lineWidth;
  8070. var symbol = style.symbol;
  8071. if (symbol === 'last') {
  8072. ctx.moveTo(x + width - 2, y + height / 3);
  8073. ctx.lineTo(x + width - 2, y);
  8074. ctx.lineTo(x + 2, y + height / 2);
  8075. ctx.lineTo(x + width - 2, y + height);
  8076. ctx.lineTo(x + width - 2, y + height / 3 * 2);
  8077. ctx.moveTo(x, y);
  8078. ctx.lineTo(x, y);
  8079. } else if (symbol === 'next') {
  8080. ctx.moveTo(x + 2, y + height / 3);
  8081. ctx.lineTo(x + 2, y);
  8082. ctx.lineTo(x + width - 2, y + height / 2);
  8083. ctx.lineTo(x + 2, y + height);
  8084. ctx.lineTo(x + 2, y + height / 3 * 2);
  8085. ctx.moveTo(x, y);
  8086. ctx.lineTo(x, y);
  8087. } else if (symbol === 'play') {
  8088. if (style.status === 'stop') {
  8089. ctx.moveTo(x + 2, y);
  8090. ctx.lineTo(x + width - 2, y + height / 2);
  8091. ctx.lineTo(x + 2, y + height);
  8092. ctx.lineTo(x + 2, y);
  8093. } else {
  8094. var delta = style.brushType === 'both' ? 2 : 3;
  8095. ctx.rect(x + 2, y, delta, height);
  8096. ctx.rect(x + width - delta - 2, y, delta, height);
  8097. }
  8098. } else if (symbol.match('image')) {
  8099. var imageLocation = '';
  8100. imageLocation = symbol.replace(new RegExp('^image:\\/\\/'), '');
  8101. symbol = IconShape.prototype.iconLibrary.image;
  8102. symbol(ctx, {
  8103. x: x,
  8104. y: y,
  8105. width: width,
  8106. height: height,
  8107. image: imageLocation
  8108. });
  8109. }
  8110. }
  8111. IconShape.prototype.iconLibrary['timelineControl'] = timelineControl;
  8112. zrUtil.inherits(Timeline, Base);
  8113. require('../component').define('timeline', Timeline);
  8114. return Timeline;
  8115. });define('zrender/shape/Image', [
  8116. 'require',
  8117. './Base',
  8118. '../tool/util'
  8119. ], function (require) {
  8120. var Base = require('./Base');
  8121. var ZImage = function (options) {
  8122. Base.call(this, options);
  8123. };
  8124. ZImage.prototype = {
  8125. type: 'image',
  8126. brush: function (ctx, isHighlight, refreshNextFrame) {
  8127. var style = this.style || {};
  8128. if (isHighlight) {
  8129. style = this.getHighlightStyle(style, this.highlightStyle || {});
  8130. }
  8131. var image = style.image;
  8132. var self = this;
  8133. if (!this._imageCache) {
  8134. this._imageCache = {};
  8135. }
  8136. if (typeof image === 'string') {
  8137. var src = image;
  8138. if (this._imageCache[src]) {
  8139. image = this._imageCache[src];
  8140. } else {
  8141. image = new Image();
  8142. image.onload = function () {
  8143. image.onload = null;
  8144. self.modSelf();
  8145. refreshNextFrame();
  8146. };
  8147. image.src = src;
  8148. this._imageCache[src] = image;
  8149. }
  8150. }
  8151. if (image) {
  8152. if (image.nodeName.toUpperCase() == 'IMG') {
  8153. if (window.ActiveXObject) {
  8154. if (image.readyState != 'complete') {
  8155. return;
  8156. }
  8157. } else {
  8158. if (!image.complete) {
  8159. return;
  8160. }
  8161. }
  8162. }
  8163. var width = style.width || image.width;
  8164. var height = style.height || image.height;
  8165. var x = style.x;
  8166. var y = style.y;
  8167. if (!image.width || !image.height) {
  8168. return;
  8169. }
  8170. ctx.save();
  8171. this.doClip(ctx);
  8172. this.setContext(ctx, style);
  8173. this.setTransform(ctx);
  8174. if (style.sWidth && style.sHeight) {
  8175. var sx = style.sx || 0;
  8176. var sy = style.sy || 0;
  8177. ctx.drawImage(image, sx, sy, style.sWidth, style.sHeight, x, y, width, height);
  8178. } else if (style.sx && style.sy) {
  8179. var sx = style.sx;
  8180. var sy = style.sy;
  8181. var sWidth = width - sx;
  8182. var sHeight = height - sy;
  8183. ctx.drawImage(image, sx, sy, sWidth, sHeight, x, y, width, height);
  8184. } else {
  8185. ctx.drawImage(image, x, y, width, height);
  8186. }
  8187. if (!style.width) {
  8188. style.width = width;
  8189. }
  8190. if (!style.height) {
  8191. style.height = height;
  8192. }
  8193. if (!this.style.width) {
  8194. this.style.width = width;
  8195. }
  8196. if (!this.style.height) {
  8197. this.style.height = height;
  8198. }
  8199. this.drawText(ctx, style, this.style);
  8200. ctx.restore();
  8201. }
  8202. },
  8203. getRect: function (style) {
  8204. return {
  8205. x: style.x,
  8206. y: style.y,
  8207. width: style.width,
  8208. height: style.height
  8209. };
  8210. },
  8211. clearCache: function () {
  8212. this._imageCache = {};
  8213. }
  8214. };
  8215. require('../tool/util').inherits(ZImage, Base);
  8216. return ZImage;
  8217. });define('zrender/loadingEffect/Bar', [
  8218. 'require',
  8219. './Base',
  8220. '../tool/util',
  8221. '../tool/color',
  8222. '../shape/Rectangle'
  8223. ], function (require) {
  8224. var Base = require('./Base');
  8225. var util = require('../tool/util');
  8226. var zrColor = require('../tool/color');
  8227. var RectangleShape = require('../shape/Rectangle');
  8228. function Bar(options) {
  8229. Base.call(this, options);
  8230. }
  8231. util.inherits(Bar, Base);
  8232. Bar.prototype._start = function (addShapeHandle, refreshHandle) {
  8233. var options = util.merge(this.options, {
  8234. textStyle: { color: '#888' },
  8235. backgroundColor: 'rgba(250, 250, 250, 0.8)',
  8236. effectOption: {
  8237. x: 0,
  8238. y: this.canvasHeight / 2 - 30,
  8239. width: this.canvasWidth,
  8240. height: 5,
  8241. brushType: 'fill',
  8242. timeInterval: 100
  8243. }
  8244. });
  8245. var textShape = this.createTextShape(options.textStyle);
  8246. var background = this.createBackgroundShape(options.backgroundColor);
  8247. var effectOption = options.effectOption;
  8248. var barShape = new RectangleShape({ highlightStyle: util.clone(effectOption) });
  8249. barShape.highlightStyle.color = effectOption.color || zrColor.getLinearGradient(effectOption.x, effectOption.y, effectOption.x + effectOption.width, effectOption.y + effectOption.height, [
  8250. [
  8251. 0,
  8252. '#ff6400'
  8253. ],
  8254. [
  8255. 0.5,
  8256. '#ffe100'
  8257. ],
  8258. [
  8259. 1,
  8260. '#b1ff00'
  8261. ]
  8262. ]);
  8263. if (options.progress != null) {
  8264. addShapeHandle(background);
  8265. barShape.highlightStyle.width = this.adjust(options.progress, [
  8266. 0,
  8267. 1
  8268. ]) * options.effectOption.width;
  8269. addShapeHandle(barShape);
  8270. addShapeHandle(textShape);
  8271. refreshHandle();
  8272. return;
  8273. } else {
  8274. barShape.highlightStyle.width = 0;
  8275. return setInterval(function () {
  8276. addShapeHandle(background);
  8277. if (barShape.highlightStyle.width < effectOption.width) {
  8278. barShape.highlightStyle.width += 8;
  8279. } else {
  8280. barShape.highlightStyle.width = 0;
  8281. }
  8282. addShapeHandle(barShape);
  8283. addShapeHandle(textShape);
  8284. refreshHandle();
  8285. }, effectOption.timeInterval);
  8286. }
  8287. };
  8288. return Bar;
  8289. });define('zrender/loadingEffect/Bubble', [
  8290. 'require',
  8291. './Base',
  8292. '../tool/util',
  8293. '../tool/color',
  8294. '../shape/Circle'
  8295. ], function (require) {
  8296. var Base = require('./Base');
  8297. var util = require('../tool/util');
  8298. var zrColor = require('../tool/color');
  8299. var CircleShape = require('../shape/Circle');
  8300. function Bubble(options) {
  8301. Base.call(this, options);
  8302. }
  8303. util.inherits(Bubble, Base);
  8304. Bubble.prototype._start = function (addShapeHandle, refreshHandle) {
  8305. var options = util.merge(this.options, {
  8306. textStyle: { color: '#888' },
  8307. backgroundColor: 'rgba(250, 250, 250, 0.8)',
  8308. effect: {
  8309. n: 50,
  8310. lineWidth: 2,
  8311. brushType: 'stroke',
  8312. color: 'random',
  8313. timeInterval: 100
  8314. }
  8315. });
  8316. var textShape = this.createTextShape(options.textStyle);
  8317. var background = this.createBackgroundShape(options.backgroundColor);
  8318. var effectOption = options.effect;
  8319. var n = effectOption.n;
  8320. var brushType = effectOption.brushType;
  8321. var lineWidth = effectOption.lineWidth;
  8322. var shapeList = [];
  8323. var canvasWidth = this.canvasWidth;
  8324. var canvasHeight = this.canvasHeight;
  8325. for (var i = 0; i < n; i++) {
  8326. var color = effectOption.color == 'random' ? zrColor.alpha(zrColor.random(), 0.3) : effectOption.color;
  8327. shapeList[i] = new CircleShape({
  8328. highlightStyle: {
  8329. x: Math.ceil(Math.random() * canvasWidth),
  8330. y: Math.ceil(Math.random() * canvasHeight),
  8331. r: Math.ceil(Math.random() * 40),
  8332. brushType: brushType,
  8333. color: color,
  8334. strokeColor: color,
  8335. lineWidth: lineWidth
  8336. },
  8337. animationY: Math.ceil(Math.random() * 20)
  8338. });
  8339. }
  8340. return setInterval(function () {
  8341. addShapeHandle(background);
  8342. for (var i = 0; i < n; i++) {
  8343. var style = shapeList[i].highlightStyle;
  8344. if (style.y - shapeList[i].animationY + style.r <= 0) {
  8345. shapeList[i].highlightStyle.y = canvasHeight + style.r;
  8346. shapeList[i].highlightStyle.x = Math.ceil(Math.random() * canvasWidth);
  8347. }
  8348. shapeList[i].highlightStyle.y -= shapeList[i].animationY;
  8349. addShapeHandle(shapeList[i]);
  8350. }
  8351. addShapeHandle(textShape);
  8352. refreshHandle();
  8353. }, effectOption.timeInterval);
  8354. };
  8355. return Bubble;
  8356. });define('zrender/loadingEffect/DynamicLine', [
  8357. 'require',
  8358. './Base',
  8359. '../tool/util',
  8360. '../tool/color',
  8361. '../shape/Line'
  8362. ], function (require) {
  8363. var Base = require('./Base');
  8364. var util = require('../tool/util');
  8365. var zrColor = require('../tool/color');
  8366. var LineShape = require('../shape/Line');
  8367. function DynamicLine(options) {
  8368. Base.call(this, options);
  8369. }
  8370. util.inherits(DynamicLine, Base);
  8371. DynamicLine.prototype._start = function (addShapeHandle, refreshHandle) {
  8372. var options = util.merge(this.options, {
  8373. textStyle: { color: '#fff' },
  8374. backgroundColor: 'rgba(0, 0, 0, 0.8)',
  8375. effectOption: {
  8376. n: 30,
  8377. lineWidth: 1,
  8378. color: 'random',
  8379. timeInterval: 100
  8380. }
  8381. });
  8382. var textShape = this.createTextShape(options.textStyle);
  8383. var background = this.createBackgroundShape(options.backgroundColor);
  8384. var effectOption = options.effectOption;
  8385. var n = effectOption.n;
  8386. var lineWidth = effectOption.lineWidth;
  8387. var shapeList = [];
  8388. var canvasWidth = this.canvasWidth;
  8389. var canvasHeight = this.canvasHeight;
  8390. for (var i = 0; i < n; i++) {
  8391. var xStart = -Math.ceil(Math.random() * 1000);
  8392. var len = Math.ceil(Math.random() * 400);
  8393. var pos = Math.ceil(Math.random() * canvasHeight);
  8394. var color = effectOption.color == 'random' ? zrColor.random() : effectOption.color;
  8395. shapeList[i] = new LineShape({
  8396. highlightStyle: {
  8397. xStart: xStart,
  8398. yStart: pos,
  8399. xEnd: xStart + len,
  8400. yEnd: pos,
  8401. strokeColor: color,
  8402. lineWidth: lineWidth
  8403. },
  8404. animationX: Math.ceil(Math.random() * 100),
  8405. len: len
  8406. });
  8407. }
  8408. return setInterval(function () {
  8409. addShapeHandle(background);
  8410. for (var i = 0; i < n; i++) {
  8411. var style = shapeList[i].highlightStyle;
  8412. if (style.xStart >= canvasWidth) {
  8413. shapeList[i].len = Math.ceil(Math.random() * 400);
  8414. style.xStart = -400;
  8415. style.xEnd = -400 + shapeList[i].len;
  8416. style.yStart = Math.ceil(Math.random() * canvasHeight);
  8417. style.yEnd = style.yStart;
  8418. }
  8419. style.xStart += shapeList[i].animationX;
  8420. style.xEnd += shapeList[i].animationX;
  8421. addShapeHandle(shapeList[i]);
  8422. }
  8423. addShapeHandle(textShape);
  8424. refreshHandle();
  8425. }, effectOption.timeInterval);
  8426. };
  8427. return DynamicLine;
  8428. });define('zrender/loadingEffect/Ring', [
  8429. 'require',
  8430. './Base',
  8431. '../tool/util',
  8432. '../tool/color',
  8433. '../shape/Ring',
  8434. '../shape/Sector'
  8435. ], function (require) {
  8436. var Base = require('./Base');
  8437. var util = require('../tool/util');
  8438. var zrColor = require('../tool/color');
  8439. var RingShape = require('../shape/Ring');
  8440. var SectorShape = require('../shape/Sector');
  8441. function Ring(options) {
  8442. Base.call(this, options);
  8443. }
  8444. util.inherits(Ring, Base);
  8445. Ring.prototype._start = function (addShapeHandle, refreshHandle) {
  8446. var options = util.merge(this.options, {
  8447. textStyle: { color: '#07a' },
  8448. backgroundColor: 'rgba(250, 250, 250, 0.8)',
  8449. effect: {
  8450. x: this.canvasWidth / 2,
  8451. y: this.canvasHeight / 2,
  8452. r0: 60,
  8453. r: 100,
  8454. color: '#bbdcff',
  8455. brushType: 'fill',
  8456. textPosition: 'inside',
  8457. textFont: 'normal 30px verdana',
  8458. textColor: 'rgba(30, 144, 255, 0.6)',
  8459. timeInterval: 100
  8460. }
  8461. });
  8462. var effectOption = options.effect;
  8463. var textStyle = options.textStyle;
  8464. if (textStyle.x == null) {
  8465. textStyle.x = effectOption.x;
  8466. }
  8467. if (textStyle.y == null) {
  8468. textStyle.y = effectOption.y + (effectOption.r0 + effectOption.r) / 2 - 5;
  8469. }
  8470. var textShape = this.createTextShape(options.textStyle);
  8471. var background = this.createBackgroundShape(options.backgroundColor);
  8472. var x = effectOption.x;
  8473. var y = effectOption.y;
  8474. var r0 = effectOption.r0 + 6;
  8475. var r = effectOption.r - 6;
  8476. var color = effectOption.color;
  8477. var darkColor = zrColor.lift(color, 0.1);
  8478. var shapeRing = new RingShape({ highlightStyle: util.clone(effectOption) });
  8479. var shapeList = [];
  8480. var clolrList = zrColor.getGradientColors([
  8481. '#ff6400',
  8482. '#ffe100',
  8483. '#97ff00'
  8484. ], 25);
  8485. var preAngle = 15;
  8486. var endAngle = 240;
  8487. for (var i = 0; i < 16; i++) {
  8488. shapeList.push(new SectorShape({
  8489. highlightStyle: {
  8490. x: x,
  8491. y: y,
  8492. r0: r0,
  8493. r: r,
  8494. startAngle: endAngle - preAngle,
  8495. endAngle: endAngle,
  8496. brushType: 'fill',
  8497. color: darkColor
  8498. },
  8499. _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), [
  8500. [
  8501. 0,
  8502. clolrList[i * 2]
  8503. ],
  8504. [
  8505. 1,
  8506. clolrList[i * 2 + 1]
  8507. ]
  8508. ])
  8509. }));
  8510. endAngle -= preAngle;
  8511. }
  8512. endAngle = 360;
  8513. for (var i = 0; i < 4; i++) {
  8514. shapeList.push(new SectorShape({
  8515. highlightStyle: {
  8516. x: x,
  8517. y: y,
  8518. r0: r0,
  8519. r: r,
  8520. startAngle: endAngle - preAngle,
  8521. endAngle: endAngle,
  8522. brushType: 'fill',
  8523. color: darkColor
  8524. },
  8525. _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), [
  8526. [
  8527. 0,
  8528. clolrList[i * 2 + 32]
  8529. ],
  8530. [
  8531. 1,
  8532. clolrList[i * 2 + 33]
  8533. ]
  8534. ])
  8535. }));
  8536. endAngle -= preAngle;
  8537. }
  8538. var n = 0;
  8539. if (options.progress != null) {
  8540. addShapeHandle(background);
  8541. n = this.adjust(options.progress, [
  8542. 0,
  8543. 1
  8544. ]).toFixed(2) * 100 / 5;
  8545. shapeRing.highlightStyle.text = n * 5 + '%';
  8546. addShapeHandle(shapeRing);
  8547. for (var i = 0; i < 20; i++) {
  8548. shapeList[i].highlightStyle.color = i < n ? shapeList[i]._color : darkColor;
  8549. addShapeHandle(shapeList[i]);
  8550. }
  8551. addShapeHandle(textShape);
  8552. refreshHandle();
  8553. return;
  8554. }
  8555. return setInterval(function () {
  8556. addShapeHandle(background);
  8557. n += n >= 20 ? -20 : 1;
  8558. addShapeHandle(shapeRing);
  8559. for (var i = 0; i < 20; i++) {
  8560. shapeList[i].highlightStyle.color = i < n ? shapeList[i]._color : darkColor;
  8561. addShapeHandle(shapeList[i]);
  8562. }
  8563. addShapeHandle(textShape);
  8564. refreshHandle();
  8565. }, effectOption.timeInterval);
  8566. };
  8567. return Ring;
  8568. });define('zrender/loadingEffect/Spin', [
  8569. 'require',
  8570. './Base',
  8571. '../tool/util',
  8572. '../tool/color',
  8573. '../tool/area',
  8574. '../shape/Sector'
  8575. ], function (require) {
  8576. var Base = require('./Base');
  8577. var util = require('../tool/util');
  8578. var zrColor = require('../tool/color');
  8579. var zrArea = require('../tool/area');
  8580. var SectorShape = require('../shape/Sector');
  8581. function Spin(options) {
  8582. Base.call(this, options);
  8583. }
  8584. util.inherits(Spin, Base);
  8585. Spin.prototype._start = function (addShapeHandle, refreshHandle) {
  8586. var options = util.merge(this.options, {
  8587. textStyle: {
  8588. color: '#fff',
  8589. textAlign: 'start'
  8590. },
  8591. backgroundColor: 'rgba(0, 0, 0, 0.8)'
  8592. });
  8593. var textShape = this.createTextShape(options.textStyle);
  8594. var textGap = 10;
  8595. var textWidth = zrArea.getTextWidth(textShape.highlightStyle.text, textShape.highlightStyle.textFont);
  8596. var textHeight = zrArea.getTextHeight(textShape.highlightStyle.text, textShape.highlightStyle.textFont);
  8597. var effectOption = util.merge(this.options.effect || {}, {
  8598. r0: 9,
  8599. r: 15,
  8600. n: 18,
  8601. color: '#fff',
  8602. timeInterval: 100
  8603. });
  8604. var location = this.getLocation(this.options.textStyle, textWidth + textGap + effectOption.r * 2, Math.max(effectOption.r * 2, textHeight));
  8605. effectOption.x = location.x + effectOption.r;
  8606. effectOption.y = textShape.highlightStyle.y = location.y + location.height / 2;
  8607. textShape.highlightStyle.x = effectOption.x + effectOption.r + textGap;
  8608. var background = this.createBackgroundShape(options.backgroundColor);
  8609. var n = effectOption.n;
  8610. var x = effectOption.x;
  8611. var y = effectOption.y;
  8612. var r0 = effectOption.r0;
  8613. var r = effectOption.r;
  8614. var color = effectOption.color;
  8615. var shapeList = [];
  8616. var preAngle = Math.round(180 / n);
  8617. for (var i = 0; i < n; i++) {
  8618. shapeList[i] = new SectorShape({
  8619. highlightStyle: {
  8620. x: x,
  8621. y: y,
  8622. r0: r0,
  8623. r: r,
  8624. startAngle: preAngle * i * 2,
  8625. endAngle: preAngle * i * 2 + preAngle,
  8626. color: zrColor.alpha(color, (i + 1) / n),
  8627. brushType: 'fill'
  8628. }
  8629. });
  8630. }
  8631. var pos = [
  8632. 0,
  8633. x,
  8634. y
  8635. ];
  8636. return setInterval(function () {
  8637. addShapeHandle(background);
  8638. pos[0] -= 0.3;
  8639. for (var i = 0; i < n; i++) {
  8640. shapeList[i].rotation = pos;
  8641. addShapeHandle(shapeList[i]);
  8642. }
  8643. addShapeHandle(textShape);
  8644. refreshHandle();
  8645. }, effectOption.timeInterval);
  8646. };
  8647. return Spin;
  8648. });define('zrender/loadingEffect/Whirling', [
  8649. 'require',
  8650. './Base',
  8651. '../tool/util',
  8652. '../tool/area',
  8653. '../shape/Ring',
  8654. '../shape/Droplet',
  8655. '../shape/Circle'
  8656. ], function (require) {
  8657. var Base = require('./Base');
  8658. var util = require('../tool/util');
  8659. var zrArea = require('../tool/area');
  8660. var RingShape = require('../shape/Ring');
  8661. var DropletShape = require('../shape/Droplet');
  8662. var CircleShape = require('../shape/Circle');
  8663. function Whirling(options) {
  8664. Base.call(this, options);
  8665. }
  8666. util.inherits(Whirling, Base);
  8667. Whirling.prototype._start = function (addShapeHandle, refreshHandle) {
  8668. var options = util.merge(this.options, {
  8669. textStyle: {
  8670. color: '#888',
  8671. textAlign: 'start'
  8672. },
  8673. backgroundColor: 'rgba(250, 250, 250, 0.8)'
  8674. });
  8675. var textShape = this.createTextShape(options.textStyle);
  8676. var textGap = 10;
  8677. var textWidth = zrArea.getTextWidth(textShape.highlightStyle.text, textShape.highlightStyle.textFont);
  8678. var textHeight = zrArea.getTextHeight(textShape.highlightStyle.text, textShape.highlightStyle.textFont);
  8679. var effectOption = util.merge(this.options.effect || {}, {
  8680. r: 18,
  8681. colorIn: '#fff',
  8682. colorOut: '#555',
  8683. colorWhirl: '#6cf',
  8684. timeInterval: 50
  8685. });
  8686. var location = this.getLocation(this.options.textStyle, textWidth + textGap + effectOption.r * 2, Math.max(effectOption.r * 2, textHeight));
  8687. effectOption.x = location.x + effectOption.r;
  8688. effectOption.y = textShape.highlightStyle.y = location.y + location.height / 2;
  8689. textShape.highlightStyle.x = effectOption.x + effectOption.r + textGap;
  8690. var background = this.createBackgroundShape(options.backgroundColor);
  8691. var droplet = new DropletShape({
  8692. highlightStyle: {
  8693. a: Math.round(effectOption.r / 2),
  8694. b: Math.round(effectOption.r - effectOption.r / 6),
  8695. brushType: 'fill',
  8696. color: effectOption.colorWhirl
  8697. }
  8698. });
  8699. var circleIn = new CircleShape({
  8700. highlightStyle: {
  8701. r: Math.round(effectOption.r / 6),
  8702. brushType: 'fill',
  8703. color: effectOption.colorIn
  8704. }
  8705. });
  8706. var circleOut = new RingShape({
  8707. highlightStyle: {
  8708. r0: Math.round(effectOption.r - effectOption.r / 3),
  8709. r: effectOption.r,
  8710. brushType: 'fill',
  8711. color: effectOption.colorOut
  8712. }
  8713. });
  8714. var pos = [
  8715. 0,
  8716. effectOption.x,
  8717. effectOption.y
  8718. ];
  8719. droplet.highlightStyle.x = circleIn.highlightStyle.x = circleOut.highlightStyle.x = pos[1];
  8720. droplet.highlightStyle.y = circleIn.highlightStyle.y = circleOut.highlightStyle.y = pos[2];
  8721. return setInterval(function () {
  8722. addShapeHandle(background);
  8723. addShapeHandle(circleOut);
  8724. pos[0] -= 0.3;
  8725. droplet.rotation = pos;
  8726. addShapeHandle(droplet);
  8727. addShapeHandle(circleIn);
  8728. addShapeHandle(textShape);
  8729. refreshHandle();
  8730. }, effectOption.timeInterval);
  8731. };
  8732. return Whirling;
  8733. });define('echarts/theme/macarons', [], function () {
  8734. var theme = {
  8735. color: [
  8736. '#2ec7c9',
  8737. '#b6a2de',
  8738. '#5ab1ef',
  8739. '#ffb980',
  8740. '#d87a80',
  8741. '#8d98b3',
  8742. '#e5cf0d',
  8743. '#97b552',
  8744. '#95706d',
  8745. '#dc69aa',
  8746. '#07a2a4',
  8747. '#9a7fd1',
  8748. '#588dd5',
  8749. '#f5994e',
  8750. '#c05050',
  8751. '#59678c',
  8752. '#c9ab00',
  8753. '#7eb00a',
  8754. '#6f5553',
  8755. '#c14089'
  8756. ],
  8757. title: {
  8758. textStyle: {
  8759. fontWeight: 'normal',
  8760. color: '#008acd'
  8761. }
  8762. },
  8763. dataRange: {
  8764. itemWidth: 15,
  8765. color: [
  8766. '#5ab1ef',
  8767. '#e0ffff'
  8768. ]
  8769. },
  8770. toolbox: {
  8771. color: [
  8772. '#1e90ff',
  8773. '#1e90ff',
  8774. '#1e90ff',
  8775. '#1e90ff'
  8776. ],
  8777. effectiveColor: '#ff4500'
  8778. },
  8779. tooltip: {
  8780. backgroundColor: 'rgba(50,50,50,0.5)',
  8781. axisPointer: {
  8782. type: 'line',
  8783. lineStyle: { color: '#008acd' },
  8784. crossStyle: { color: '#008acd' },
  8785. shadowStyle: { color: 'rgba(200,200,200,0.2)' }
  8786. }
  8787. },
  8788. dataZoom: {
  8789. dataBackgroundColor: '#efefff',
  8790. fillerColor: 'rgba(182,162,222,0.2)',
  8791. handleColor: '#008acd'
  8792. },
  8793. grid: { borderColor: '#eee' },
  8794. categoryAxis: {
  8795. axisLine: { lineStyle: { color: '#008acd' } },
  8796. splitLine: { lineStyle: { color: ['#eee'] } }
  8797. },
  8798. valueAxis: {
  8799. axisLine: { lineStyle: { color: '#008acd' } },
  8800. splitArea: {
  8801. show: true,
  8802. areaStyle: {
  8803. color: [
  8804. 'rgba(250,250,250,0.1)',
  8805. 'rgba(200,200,200,0.1)'
  8806. ]
  8807. }
  8808. },
  8809. splitLine: { lineStyle: { color: ['#eee'] } }
  8810. },
  8811. polar: {
  8812. axisLine: { lineStyle: { color: '#ddd' } },
  8813. splitArea: {
  8814. show: true,
  8815. areaStyle: {
  8816. color: [
  8817. 'rgba(250,250,250,0.2)',
  8818. 'rgba(200,200,200,0.2)'
  8819. ]
  8820. }
  8821. },
  8822. splitLine: { lineStyle: { color: '#ddd' } }
  8823. },
  8824. timeline: {
  8825. lineStyle: { color: '#008acd' },
  8826. controlStyle: {
  8827. normal: { color: '#008acd' },
  8828. emphasis: { color: '#008acd' }
  8829. },
  8830. symbol: 'emptyCircle',
  8831. symbolSize: 3
  8832. },
  8833. bar: {
  8834. itemStyle: {
  8835. normal: { barBorderRadius: 5 },
  8836. emphasis: { barBorderRadius: 5 }
  8837. }
  8838. },
  8839. line: {
  8840. smooth: true,
  8841. symbol: 'emptyCircle',
  8842. symbolSize: 3
  8843. },
  8844. k: {
  8845. itemStyle: {
  8846. normal: {
  8847. color: '#d87a80',
  8848. color0: '#2ec7c9',
  8849. lineStyle: {
  8850. color: '#d87a80',
  8851. color0: '#2ec7c9'
  8852. }
  8853. }
  8854. }
  8855. },
  8856. scatter: {
  8857. symbol: 'circle',
  8858. symbolSize: 4
  8859. },
  8860. radar: {
  8861. symbol: 'emptyCircle',
  8862. symbolSize: 3
  8863. },
  8864. map: {
  8865. itemStyle: {
  8866. normal: {
  8867. areaStyle: { color: '#ddd' },
  8868. label: { textStyle: { color: '#d87a80' } }
  8869. },
  8870. emphasis: { areaStyle: { color: '#fe994e' } }
  8871. }
  8872. },
  8873. force: { itemStyle: { normal: { linkStyle: { color: '#1e90ff' } } } },
  8874. chord: {
  8875. itemStyle: {
  8876. normal: {
  8877. borderWidth: 1,
  8878. borderColor: 'rgba(128, 128, 128, 0.5)',
  8879. chordStyle: { lineStyle: { color: 'rgba(128, 128, 128, 0.5)' } }
  8880. },
  8881. emphasis: {
  8882. borderWidth: 1,
  8883. borderColor: 'rgba(128, 128, 128, 0.5)',
  8884. chordStyle: { lineStyle: { color: 'rgba(128, 128, 128, 0.5)' } }
  8885. }
  8886. }
  8887. },
  8888. gauge: {
  8889. axisLine: {
  8890. lineStyle: {
  8891. color: [
  8892. [
  8893. 0.2,
  8894. '#2ec7c9'
  8895. ],
  8896. [
  8897. 0.8,
  8898. '#5ab1ef'
  8899. ],
  8900. [
  8901. 1,
  8902. '#d87a80'
  8903. ]
  8904. ],
  8905. width: 10
  8906. }
  8907. },
  8908. axisTick: {
  8909. splitNumber: 10,
  8910. length: 15,
  8911. lineStyle: { color: 'auto' }
  8912. },
  8913. splitLine: {
  8914. length: 22,
  8915. lineStyle: { color: 'auto' }
  8916. },
  8917. pointer: { width: 5 }
  8918. },
  8919. textStyle: { fontFamily: '微软雅黑, Arial, Verdana, sans-serif' }
  8920. };
  8921. return theme;
  8922. });define('echarts/theme/infographic', [], function () {
  8923. var theme = {
  8924. color: [
  8925. '#C1232B',
  8926. '#B5C334',
  8927. '#FCCE10',
  8928. '#E87C25',
  8929. '#27727B',
  8930. '#FE8463',
  8931. '#9BCA63',
  8932. '#FAD860',
  8933. '#F3A43B',
  8934. '#60C0DD',
  8935. '#D7504B',
  8936. '#C6E579',
  8937. '#F4E001',
  8938. '#F0805A',
  8939. '#26C0C0'
  8940. ],
  8941. title: {
  8942. textStyle: {
  8943. fontWeight: 'normal',
  8944. color: '#27727B'
  8945. }
  8946. },
  8947. dataRange: {
  8948. x: 'right',
  8949. y: 'center',
  8950. itemWidth: 5,
  8951. itemHeight: 25,
  8952. color: [
  8953. '#C1232B',
  8954. '#FCCE10'
  8955. ]
  8956. },
  8957. toolbox: {
  8958. color: [
  8959. '#C1232B',
  8960. '#B5C334',
  8961. '#FCCE10',
  8962. '#E87C25',
  8963. '#27727B',
  8964. '#FE8463',
  8965. '#9BCA63',
  8966. '#FAD860',
  8967. '#F3A43B',
  8968. '#60C0DD'
  8969. ],
  8970. effectiveColor: '#ff4500'
  8971. },
  8972. tooltip: {
  8973. backgroundColor: 'rgba(50,50,50,0.5)',
  8974. axisPointer: {
  8975. type: 'line',
  8976. lineStyle: {
  8977. color: '#27727B',
  8978. type: 'dashed'
  8979. },
  8980. crossStyle: { color: '#27727B' },
  8981. shadowStyle: { color: 'rgba(200,200,200,0.3)' }
  8982. }
  8983. },
  8984. dataZoom: {
  8985. dataBackgroundColor: 'rgba(181,195,52,0.3)',
  8986. fillerColor: 'rgba(181,195,52,0.2)',
  8987. handleColor: '#27727B'
  8988. },
  8989. grid: { borderWidth: 0 },
  8990. categoryAxis: {
  8991. axisLine: { lineStyle: { color: '#27727B' } },
  8992. splitLine: { show: false }
  8993. },
  8994. valueAxis: {
  8995. axisLine: { show: false },
  8996. splitArea: { show: false },
  8997. splitLine: {
  8998. lineStyle: {
  8999. color: ['#ccc'],
  9000. type: 'dashed'
  9001. }
  9002. }
  9003. },
  9004. polar: {
  9005. axisLine: { lineStyle: { color: '#ddd' } },
  9006. splitArea: {
  9007. show: true,
  9008. areaStyle: {
  9009. color: [
  9010. 'rgba(250,250,250,0.2)',
  9011. 'rgba(200,200,200,0.2)'
  9012. ]
  9013. }
  9014. },
  9015. splitLine: { lineStyle: { color: '#ddd' } }
  9016. },
  9017. timeline: {
  9018. lineStyle: { color: '#27727B' },
  9019. controlStyle: {
  9020. normal: { color: '#27727B' },
  9021. emphasis: { color: '#27727B' }
  9022. },
  9023. symbol: 'emptyCircle',
  9024. symbolSize: 3
  9025. },
  9026. line: {
  9027. itemStyle: {
  9028. normal: {
  9029. borderWidth: 2,
  9030. borderColor: '#fff',
  9031. lineStyle: { width: 3 }
  9032. },
  9033. emphasis: { borderWidth: 0 }
  9034. },
  9035. symbol: 'circle',
  9036. symbolSize: 3.5
  9037. },
  9038. k: {
  9039. itemStyle: {
  9040. normal: {
  9041. color: '#C1232B',
  9042. color0: '#B5C334',
  9043. lineStyle: {
  9044. width: 1,
  9045. color: '#C1232B',
  9046. color0: '#B5C334'
  9047. }
  9048. }
  9049. }
  9050. },
  9051. scatter: {
  9052. itemStyle: {
  9053. normal: {
  9054. borderWidth: 1,
  9055. borderColor: 'rgba(200,200,200,0.5)'
  9056. },
  9057. emphasis: { borderWidth: 0 }
  9058. },
  9059. symbol: 'star4',
  9060. symbolSize: 4
  9061. },
  9062. radar: {
  9063. symbol: 'emptyCircle',
  9064. symbolSize: 3
  9065. },
  9066. map: {
  9067. itemStyle: {
  9068. normal: {
  9069. areaStyle: { color: '#ddd' },
  9070. label: { textStyle: { color: '#C1232B' } }
  9071. },
  9072. emphasis: {
  9073. areaStyle: { color: '#fe994e' },
  9074. label: { textStyle: { color: 'rgb(100,0,0)' } }
  9075. }
  9076. }
  9077. },
  9078. force: { itemStyle: { normal: { linkStyle: { color: '#27727B' } } } },
  9079. chord: {
  9080. itemStyle: {
  9081. normal: {
  9082. borderWidth: 1,
  9083. borderColor: 'rgba(128, 128, 128, 0.5)',
  9084. chordStyle: { lineStyle: { color: 'rgba(128, 128, 128, 0.5)' } }
  9085. },
  9086. emphasis: {
  9087. borderWidth: 1,
  9088. borderColor: 'rgba(128, 128, 128, 0.5)',
  9089. chordStyle: { lineStyle: { color: 'rgba(128, 128, 128, 0.5)' } }
  9090. }
  9091. }
  9092. },
  9093. gauge: {
  9094. center: [
  9095. '50%',
  9096. '80%'
  9097. ],
  9098. radius: '100%',
  9099. startAngle: 180,
  9100. endAngle: 0,
  9101. axisLine: {
  9102. show: true,
  9103. lineStyle: {
  9104. color: [
  9105. [
  9106. 0.2,
  9107. '#B5C334'
  9108. ],
  9109. [
  9110. 0.8,
  9111. '#27727B'
  9112. ],
  9113. [
  9114. 1,
  9115. '#C1232B'
  9116. ]
  9117. ],
  9118. width: '40%'
  9119. }
  9120. },
  9121. axisTick: {
  9122. splitNumber: 2,
  9123. length: 5,
  9124. lineStyle: { color: '#fff' }
  9125. },
  9126. axisLabel: {
  9127. textStyle: {
  9128. color: '#fff',
  9129. fontWeight: 'bolder'
  9130. }
  9131. },
  9132. splitLine: {
  9133. length: '5%',
  9134. lineStyle: { color: '#fff' }
  9135. },
  9136. pointer: {
  9137. width: '40%',
  9138. length: '80%',
  9139. color: '#fff'
  9140. },
  9141. title: {
  9142. offsetCenter: [
  9143. 0,
  9144. -20
  9145. ],
  9146. textStyle: {
  9147. color: 'auto',
  9148. fontSize: 20
  9149. }
  9150. },
  9151. detail: {
  9152. offsetCenter: [
  9153. 0,
  9154. 0
  9155. ],
  9156. textStyle: {
  9157. color: 'auto',
  9158. fontSize: 40
  9159. }
  9160. }
  9161. },
  9162. textStyle: { fontFamily: '微软雅黑, Arial, Verdana, sans-serif' }
  9163. };
  9164. return theme;
  9165. });define('zrender/dep/excanvas', ['require'], function (require) {
  9166. if (!document.createElement('canvas').getContext) {
  9167. (function () {
  9168. var m = Math;
  9169. var mr = m.round;
  9170. var ms = m.sin;
  9171. var mc = m.cos;
  9172. var abs = m.abs;
  9173. var sqrt = m.sqrt;
  9174. var Z = 10;
  9175. var Z2 = Z / 2;
  9176. var IE_VERSION = +navigator.userAgent.match(/MSIE ([\d.]+)?/)[1];
  9177. function getContext() {
  9178. return this.context_ || (this.context_ = new CanvasRenderingContext2D_(this));
  9179. }
  9180. var slice = Array.prototype.slice;
  9181. function bind(f, obj, var_args) {
  9182. var a = slice.call(arguments, 2);
  9183. return function () {
  9184. return f.apply(obj, a.concat(slice.call(arguments)));
  9185. };
  9186. }
  9187. function encodeHtmlAttribute(s) {
  9188. return String(s).replace(/&/g, '&amp;').replace(/"/g, '&quot;');
  9189. }
  9190. function addNamespace(doc, prefix, urn) {
  9191. if (!doc.namespaces[prefix]) {
  9192. doc.namespaces.add(prefix, urn, '#default#VML');
  9193. }
  9194. }
  9195. function addNamespacesAndStylesheet(doc) {
  9196. addNamespace(doc, 'g_vml_', 'urn:schemas-microsoft-com:vml');
  9197. addNamespace(doc, 'g_o_', 'urn:schemas-microsoft-com:office:office');
  9198. if (!doc.styleSheets['ex_canvas_']) {
  9199. var ss = doc.createStyleSheet();
  9200. ss.owningElement.id = 'ex_canvas_';
  9201. ss.cssText = 'canvas{display:inline-block;overflow:hidden;' + 'text-align:left;width:300px;height:150px}';
  9202. }
  9203. }
  9204. addNamespacesAndStylesheet(document);
  9205. var G_vmlCanvasManager_ = {
  9206. init: function (opt_doc) {
  9207. var doc = opt_doc || document;
  9208. doc.createElement('canvas');
  9209. doc.attachEvent('onreadystatechange', bind(this.init_, this, doc));
  9210. },
  9211. init_: function (doc) {
  9212. var els = doc.getElementsByTagName('canvas');
  9213. for (var i = 0; i < els.length; i++) {
  9214. this.initElement(els[i]);
  9215. }
  9216. },
  9217. initElement: function (el) {
  9218. if (!el.getContext) {
  9219. el.getContext = getContext;
  9220. addNamespacesAndStylesheet(el.ownerDocument);
  9221. el.innerHTML = '';
  9222. el.attachEvent('onpropertychange', onPropertyChange);
  9223. el.attachEvent('onresize', onResize);
  9224. var attrs = el.attributes;
  9225. if (attrs.width && attrs.width.specified) {
  9226. el.style.width = attrs.width.nodeValue + 'px';
  9227. } else {
  9228. el.width = el.clientWidth;
  9229. }
  9230. if (attrs.height && attrs.height.specified) {
  9231. el.style.height = attrs.height.nodeValue + 'px';
  9232. } else {
  9233. el.height = el.clientHeight;
  9234. }
  9235. }
  9236. return el;
  9237. }
  9238. };
  9239. function onPropertyChange(e) {
  9240. var el = e.srcElement;
  9241. switch (e.propertyName) {
  9242. case 'width':
  9243. el.getContext().clearRect();
  9244. el.style.width = el.attributes.width.nodeValue + 'px';
  9245. el.firstChild.style.width = el.clientWidth + 'px';
  9246. break;
  9247. case 'height':
  9248. el.getContext().clearRect();
  9249. el.style.height = el.attributes.height.nodeValue + 'px';
  9250. el.firstChild.style.height = el.clientHeight + 'px';
  9251. break;
  9252. }
  9253. }
  9254. function onResize(e) {
  9255. var el = e.srcElement;
  9256. if (el.firstChild) {
  9257. el.firstChild.style.width = el.clientWidth + 'px';
  9258. el.firstChild.style.height = el.clientHeight + 'px';
  9259. }
  9260. }
  9261. G_vmlCanvasManager_.init();
  9262. var decToHex = [];
  9263. for (var i = 0; i < 16; i++) {
  9264. for (var j = 0; j < 16; j++) {
  9265. decToHex[i * 16 + j] = i.toString(16) + j.toString(16);
  9266. }
  9267. }
  9268. function createMatrixIdentity() {
  9269. return [
  9270. [
  9271. 1,
  9272. 0,
  9273. 0
  9274. ],
  9275. [
  9276. 0,
  9277. 1,
  9278. 0
  9279. ],
  9280. [
  9281. 0,
  9282. 0,
  9283. 1
  9284. ]
  9285. ];
  9286. }
  9287. function matrixMultiply(m1, m2) {
  9288. var result = createMatrixIdentity();
  9289. for (var x = 0; x < 3; x++) {
  9290. for (var y = 0; y < 3; y++) {
  9291. var sum = 0;
  9292. for (var z = 0; z < 3; z++) {
  9293. sum += m1[x][z] * m2[z][y];
  9294. }
  9295. result[x][y] = sum;
  9296. }
  9297. }
  9298. return result;
  9299. }
  9300. function copyState(o1, o2) {
  9301. o2.fillStyle = o1.fillStyle;
  9302. o2.lineCap = o1.lineCap;
  9303. o2.lineJoin = o1.lineJoin;
  9304. o2.lineWidth = o1.lineWidth;
  9305. o2.miterLimit = o1.miterLimit;
  9306. o2.shadowBlur = o1.shadowBlur;
  9307. o2.shadowColor = o1.shadowColor;
  9308. o2.shadowOffsetX = o1.shadowOffsetX;
  9309. o2.shadowOffsetY = o1.shadowOffsetY;
  9310. o2.strokeStyle = o1.strokeStyle;
  9311. o2.globalAlpha = o1.globalAlpha;
  9312. o2.font = o1.font;
  9313. o2.textAlign = o1.textAlign;
  9314. o2.textBaseline = o1.textBaseline;
  9315. o2.scaleX_ = o1.scaleX_;
  9316. o2.scaleY_ = o1.scaleY_;
  9317. o2.lineScale_ = o1.lineScale_;
  9318. }
  9319. var colorData = {
  9320. aliceblue: '#F0F8FF',
  9321. antiquewhite: '#FAEBD7',
  9322. aquamarine: '#7FFFD4',
  9323. azure: '#F0FFFF',
  9324. beige: '#F5F5DC',
  9325. bisque: '#FFE4C4',
  9326. black: '#000000',
  9327. blanchedalmond: '#FFEBCD',
  9328. blueviolet: '#8A2BE2',
  9329. brown: '#A52A2A',
  9330. burlywood: '#DEB887',
  9331. cadetblue: '#5F9EA0',
  9332. chartreuse: '#7FFF00',
  9333. chocolate: '#D2691E',
  9334. coral: '#FF7F50',
  9335. cornflowerblue: '#6495ED',
  9336. cornsilk: '#FFF8DC',
  9337. crimson: '#DC143C',
  9338. cyan: '#00FFFF',
  9339. darkblue: '#00008B',
  9340. darkcyan: '#008B8B',
  9341. darkgoldenrod: '#B8860B',
  9342. darkgray: '#A9A9A9',
  9343. darkgreen: '#006400',
  9344. darkgrey: '#A9A9A9',
  9345. darkkhaki: '#BDB76B',
  9346. darkmagenta: '#8B008B',
  9347. darkolivegreen: '#556B2F',
  9348. darkorange: '#FF8C00',
  9349. darkorchid: '#9932CC',
  9350. darkred: '#8B0000',
  9351. darksalmon: '#E9967A',
  9352. darkseagreen: '#8FBC8F',
  9353. darkslateblue: '#483D8B',
  9354. darkslategray: '#2F4F4F',
  9355. darkslategrey: '#2F4F4F',
  9356. darkturquoise: '#00CED1',
  9357. darkviolet: '#9400D3',
  9358. deeppink: '#FF1493',
  9359. deepskyblue: '#00BFFF',
  9360. dimgray: '#696969',
  9361. dimgrey: '#696969',
  9362. dodgerblue: '#1E90FF',
  9363. firebrick: '#B22222',
  9364. floralwhite: '#FFFAF0',
  9365. forestgreen: '#228B22',
  9366. gainsboro: '#DCDCDC',
  9367. ghostwhite: '#F8F8FF',
  9368. gold: '#FFD700',
  9369. goldenrod: '#DAA520',
  9370. grey: '#808080',
  9371. greenyellow: '#ADFF2F',
  9372. honeydew: '#F0FFF0',
  9373. hotpink: '#FF69B4',
  9374. indianred: '#CD5C5C',
  9375. indigo: '#4B0082',
  9376. ivory: '#FFFFF0',
  9377. khaki: '#F0E68C',
  9378. lavender: '#E6E6FA',
  9379. lavenderblush: '#FFF0F5',
  9380. lawngreen: '#7CFC00',
  9381. lemonchiffon: '#FFFACD',
  9382. lightblue: '#ADD8E6',
  9383. lightcoral: '#F08080',
  9384. lightcyan: '#E0FFFF',
  9385. lightgoldenrodyellow: '#FAFAD2',
  9386. lightgreen: '#90EE90',
  9387. lightgrey: '#D3D3D3',
  9388. lightpink: '#FFB6C1',
  9389. lightsalmon: '#FFA07A',
  9390. lightseagreen: '#20B2AA',
  9391. lightskyblue: '#87CEFA',
  9392. lightslategray: '#778899',
  9393. lightslategrey: '#778899',
  9394. lightsteelblue: '#B0C4DE',
  9395. lightyellow: '#FFFFE0',
  9396. limegreen: '#32CD32',
  9397. linen: '#FAF0E6',
  9398. magenta: '#FF00FF',
  9399. mediumaquamarine: '#66CDAA',
  9400. mediumblue: '#0000CD',
  9401. mediumorchid: '#BA55D3',
  9402. mediumpurple: '#9370DB',
  9403. mediumseagreen: '#3CB371',
  9404. mediumslateblue: '#7B68EE',
  9405. mediumspringgreen: '#00FA9A',
  9406. mediumturquoise: '#48D1CC',
  9407. mediumvioletred: '#C71585',
  9408. midnightblue: '#191970',
  9409. mintcream: '#F5FFFA',
  9410. mistyrose: '#FFE4E1',
  9411. moccasin: '#FFE4B5',
  9412. navajowhite: '#FFDEAD',
  9413. oldlace: '#FDF5E6',
  9414. olivedrab: '#6B8E23',
  9415. orange: '#FFA500',
  9416. orangered: '#FF4500',
  9417. orchid: '#DA70D6',
  9418. palegoldenrod: '#EEE8AA',
  9419. palegreen: '#98FB98',
  9420. paleturquoise: '#AFEEEE',
  9421. palevioletred: '#DB7093',
  9422. papayawhip: '#FFEFD5',
  9423. peachpuff: '#FFDAB9',
  9424. peru: '#CD853F',
  9425. pink: '#FFC0CB',
  9426. plum: '#DDA0DD',
  9427. powderblue: '#B0E0E6',
  9428. rosybrown: '#BC8F8F',
  9429. royalblue: '#4169E1',
  9430. saddlebrown: '#8B4513',
  9431. salmon: '#FA8072',
  9432. sandybrown: '#F4A460',
  9433. seagreen: '#2E8B57',
  9434. seashell: '#FFF5EE',
  9435. sienna: '#A0522D',
  9436. skyblue: '#87CEEB',
  9437. slateblue: '#6A5ACD',
  9438. slategray: '#708090',
  9439. slategrey: '#708090',
  9440. snow: '#FFFAFA',
  9441. springgreen: '#00FF7F',
  9442. steelblue: '#4682B4',
  9443. tan: '#D2B48C',
  9444. thistle: '#D8BFD8',
  9445. tomato: '#FF6347',
  9446. turquoise: '#40E0D0',
  9447. violet: '#EE82EE',
  9448. wheat: '#F5DEB3',
  9449. whitesmoke: '#F5F5F5',
  9450. yellowgreen: '#9ACD32'
  9451. };
  9452. function getRgbHslContent(styleString) {
  9453. var start = styleString.indexOf('(', 3);
  9454. var end = styleString.indexOf(')', start + 1);
  9455. var parts = styleString.substring(start + 1, end).split(',');
  9456. if (parts.length != 4 || styleString.charAt(3) != 'a') {
  9457. parts[3] = 1;
  9458. }
  9459. return parts;
  9460. }
  9461. function percent(s) {
  9462. return parseFloat(s) / 100;
  9463. }
  9464. function clamp(v, min, max) {
  9465. return Math.min(max, Math.max(min, v));
  9466. }
  9467. function hslToRgb(parts) {
  9468. var r, g, b, h, s, l;
  9469. h = parseFloat(parts[0]) / 360 % 360;
  9470. if (h < 0)
  9471. h++;
  9472. s = clamp(percent(parts[1]), 0, 1);
  9473. l = clamp(percent(parts[2]), 0, 1);
  9474. if (s == 0) {
  9475. r = g = b = l;
  9476. } else {
  9477. var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
  9478. var p = 2 * l - q;
  9479. r = hueToRgb(p, q, h + 1 / 3);
  9480. g = hueToRgb(p, q, h);
  9481. b = hueToRgb(p, q, h - 1 / 3);
  9482. }
  9483. return '#' + decToHex[Math.floor(r * 255)] + decToHex[Math.floor(g * 255)] + decToHex[Math.floor(b * 255)];
  9484. }
  9485. function hueToRgb(m1, m2, h) {
  9486. if (h < 0)
  9487. h++;
  9488. if (h > 1)
  9489. h--;
  9490. if (6 * h < 1)
  9491. return m1 + (m2 - m1) * 6 * h;
  9492. else if (2 * h < 1)
  9493. return m2;
  9494. else if (3 * h < 2)
  9495. return m1 + (m2 - m1) * (2 / 3 - h) * 6;
  9496. else
  9497. return m1;
  9498. }
  9499. var processStyleCache = {};
  9500. function processStyle(styleString) {
  9501. if (styleString in processStyleCache) {
  9502. return processStyleCache[styleString];
  9503. }
  9504. var str, alpha = 1;
  9505. styleString = String(styleString);
  9506. if (styleString.charAt(0) == '#') {
  9507. str = styleString;
  9508. } else if (/^rgb/.test(styleString)) {
  9509. var parts = getRgbHslContent(styleString);
  9510. var str = '#', n;
  9511. for (var i = 0; i < 3; i++) {
  9512. if (parts[i].indexOf('%') != -1) {
  9513. n = Math.floor(percent(parts[i]) * 255);
  9514. } else {
  9515. n = +parts[i];
  9516. }
  9517. str += decToHex[clamp(n, 0, 255)];
  9518. }
  9519. alpha = +parts[3];
  9520. } else if (/^hsl/.test(styleString)) {
  9521. var parts = getRgbHslContent(styleString);
  9522. str = hslToRgb(parts);
  9523. alpha = parts[3];
  9524. } else {
  9525. str = colorData[styleString] || styleString;
  9526. }
  9527. return processStyleCache[styleString] = {
  9528. color: str,
  9529. alpha: alpha
  9530. };
  9531. }
  9532. var DEFAULT_STYLE = {
  9533. style: 'normal',
  9534. variant: 'normal',
  9535. weight: 'normal',
  9536. size: 12,
  9537. family: '微软雅黑'
  9538. };
  9539. var fontStyleCache = {};
  9540. function processFontStyle(styleString) {
  9541. if (fontStyleCache[styleString]) {
  9542. return fontStyleCache[styleString];
  9543. }
  9544. var el = document.createElement('div');
  9545. var style = el.style;
  9546. var fontFamily;
  9547. try {
  9548. style.font = styleString;
  9549. fontFamily = style.fontFamily.split(',')[0];
  9550. } catch (ex) {
  9551. }
  9552. return fontStyleCache[styleString] = {
  9553. style: style.fontStyle || DEFAULT_STYLE.style,
  9554. variant: style.fontVariant || DEFAULT_STYLE.variant,
  9555. weight: style.fontWeight || DEFAULT_STYLE.weight,
  9556. size: style.fontSize || DEFAULT_STYLE.size,
  9557. family: fontFamily || DEFAULT_STYLE.family
  9558. };
  9559. }
  9560. function getComputedStyle(style, element) {
  9561. var computedStyle = {};
  9562. for (var p in style) {
  9563. computedStyle[p] = style[p];
  9564. }
  9565. var canvasFontSize = parseFloat(element.currentStyle.fontSize), fontSize = parseFloat(style.size);
  9566. if (typeof style.size == 'number') {
  9567. computedStyle.size = style.size;
  9568. } else if (style.size.indexOf('px') != -1) {
  9569. computedStyle.size = fontSize;
  9570. } else if (style.size.indexOf('em') != -1) {
  9571. computedStyle.size = canvasFontSize * fontSize;
  9572. } else if (style.size.indexOf('%') != -1) {
  9573. computedStyle.size = canvasFontSize / 100 * fontSize;
  9574. } else if (style.size.indexOf('pt') != -1) {
  9575. computedStyle.size = fontSize / 0.75;
  9576. } else {
  9577. computedStyle.size = canvasFontSize;
  9578. }
  9579. return computedStyle;
  9580. }
  9581. function buildStyle(style) {
  9582. return style.style + ' ' + style.variant + ' ' + style.weight + ' ' + style.size + 'px \'' + style.family + '\'';
  9583. }
  9584. var lineCapMap = {
  9585. 'butt': 'flat',
  9586. 'round': 'round'
  9587. };
  9588. function processLineCap(lineCap) {
  9589. return lineCapMap[lineCap] || 'square';
  9590. }
  9591. function CanvasRenderingContext2D_(canvasElement) {
  9592. this.m_ = createMatrixIdentity();
  9593. this.mStack_ = [];
  9594. this.aStack_ = [];
  9595. this.currentPath_ = [];
  9596. this.strokeStyle = '#000';
  9597. this.fillStyle = '#000';
  9598. this.lineWidth = 1;
  9599. this.lineJoin = 'miter';
  9600. this.lineCap = 'butt';
  9601. this.miterLimit = Z * 1;
  9602. this.globalAlpha = 1;
  9603. this.font = '12px 微软雅黑';
  9604. this.textAlign = 'left';
  9605. this.textBaseline = 'alphabetic';
  9606. this.canvas = canvasElement;
  9607. var cssText = 'width:' + canvasElement.clientWidth + 'px;height:' + canvasElement.clientHeight + 'px;overflow:hidden;position:absolute';
  9608. var el = canvasElement.ownerDocument.createElement('div');
  9609. el.style.cssText = cssText;
  9610. canvasElement.appendChild(el);
  9611. var overlayEl = el.cloneNode(false);
  9612. overlayEl.style.backgroundColor = '#fff';
  9613. overlayEl.style.filter = 'alpha(opacity=0)';
  9614. canvasElement.appendChild(overlayEl);
  9615. this.element_ = el;
  9616. this.scaleX_ = 1;
  9617. this.scaleY_ = 1;
  9618. this.lineScale_ = 1;
  9619. }
  9620. var contextPrototype = CanvasRenderingContext2D_.prototype;
  9621. contextPrototype.clearRect = function () {
  9622. if (this.textMeasureEl_) {
  9623. this.textMeasureEl_.removeNode(true);
  9624. this.textMeasureEl_ = null;
  9625. }
  9626. this.element_.innerHTML = '';
  9627. };
  9628. contextPrototype.beginPath = function () {
  9629. this.currentPath_ = [];
  9630. };
  9631. contextPrototype.moveTo = function (aX, aY) {
  9632. var p = getCoords(this, aX, aY);
  9633. this.currentPath_.push({
  9634. type: 'moveTo',
  9635. x: p.x,
  9636. y: p.y
  9637. });
  9638. this.currentX_ = p.x;
  9639. this.currentY_ = p.y;
  9640. };
  9641. contextPrototype.lineTo = function (aX, aY) {
  9642. var p = getCoords(this, aX, aY);
  9643. this.currentPath_.push({
  9644. type: 'lineTo',
  9645. x: p.x,
  9646. y: p.y
  9647. });
  9648. this.currentX_ = p.x;
  9649. this.currentY_ = p.y;
  9650. };
  9651. contextPrototype.bezierCurveTo = function (aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  9652. var p = getCoords(this, aX, aY);
  9653. var cp1 = getCoords(this, aCP1x, aCP1y);
  9654. var cp2 = getCoords(this, aCP2x, aCP2y);
  9655. bezierCurveTo(this, cp1, cp2, p);
  9656. };
  9657. function bezierCurveTo(self, cp1, cp2, p) {
  9658. self.currentPath_.push({
  9659. type: 'bezierCurveTo',
  9660. cp1x: cp1.x,
  9661. cp1y: cp1.y,
  9662. cp2x: cp2.x,
  9663. cp2y: cp2.y,
  9664. x: p.x,
  9665. y: p.y
  9666. });
  9667. self.currentX_ = p.x;
  9668. self.currentY_ = p.y;
  9669. }
  9670. contextPrototype.quadraticCurveTo = function (aCPx, aCPy, aX, aY) {
  9671. var cp = getCoords(this, aCPx, aCPy);
  9672. var p = getCoords(this, aX, aY);
  9673. var cp1 = {
  9674. x: this.currentX_ + 2 / 3 * (cp.x - this.currentX_),
  9675. y: this.currentY_ + 2 / 3 * (cp.y - this.currentY_)
  9676. };
  9677. var cp2 = {
  9678. x: cp1.x + (p.x - this.currentX_) / 3,
  9679. y: cp1.y + (p.y - this.currentY_) / 3
  9680. };
  9681. bezierCurveTo(this, cp1, cp2, p);
  9682. };
  9683. contextPrototype.arc = function (aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  9684. aRadius *= Z;
  9685. var arcType = aClockwise ? 'at' : 'wa';
  9686. var xStart = aX + mc(aStartAngle) * aRadius - Z2;
  9687. var yStart = aY + ms(aStartAngle) * aRadius - Z2;
  9688. var xEnd = aX + mc(aEndAngle) * aRadius - Z2;
  9689. var yEnd = aY + ms(aEndAngle) * aRadius - Z2;
  9690. if (xStart == xEnd && !aClockwise) {
  9691. xStart += 0.125;
  9692. }
  9693. var p = getCoords(this, aX, aY);
  9694. var pStart = getCoords(this, xStart, yStart);
  9695. var pEnd = getCoords(this, xEnd, yEnd);
  9696. this.currentPath_.push({
  9697. type: arcType,
  9698. x: p.x,
  9699. y: p.y,
  9700. radius: aRadius,
  9701. xStart: pStart.x,
  9702. yStart: pStart.y,
  9703. xEnd: pEnd.x,
  9704. yEnd: pEnd.y
  9705. });
  9706. };
  9707. contextPrototype.rect = function (aX, aY, aWidth, aHeight) {
  9708. this.moveTo(aX, aY);
  9709. this.lineTo(aX + aWidth, aY);
  9710. this.lineTo(aX + aWidth, aY + aHeight);
  9711. this.lineTo(aX, aY + aHeight);
  9712. this.closePath();
  9713. };
  9714. contextPrototype.strokeRect = function (aX, aY, aWidth, aHeight) {
  9715. var oldPath = this.currentPath_;
  9716. this.beginPath();
  9717. this.moveTo(aX, aY);
  9718. this.lineTo(aX + aWidth, aY);
  9719. this.lineTo(aX + aWidth, aY + aHeight);
  9720. this.lineTo(aX, aY + aHeight);
  9721. this.closePath();
  9722. this.stroke();
  9723. this.currentPath_ = oldPath;
  9724. };
  9725. contextPrototype.fillRect = function (aX, aY, aWidth, aHeight) {
  9726. var oldPath = this.currentPath_;
  9727. this.beginPath();
  9728. this.moveTo(aX, aY);
  9729. this.lineTo(aX + aWidth, aY);
  9730. this.lineTo(aX + aWidth, aY + aHeight);
  9731. this.lineTo(aX, aY + aHeight);
  9732. this.closePath();
  9733. this.fill();
  9734. this.currentPath_ = oldPath;
  9735. };
  9736. contextPrototype.createLinearGradient = function (aX0, aY0, aX1, aY1) {
  9737. var gradient = new CanvasGradient_('gradient');
  9738. gradient.x0_ = aX0;
  9739. gradient.y0_ = aY0;
  9740. gradient.x1_ = aX1;
  9741. gradient.y1_ = aY1;
  9742. return gradient;
  9743. };
  9744. contextPrototype.createRadialGradient = function (aX0, aY0, aR0, aX1, aY1, aR1) {
  9745. var gradient = new CanvasGradient_('gradientradial');
  9746. gradient.x0_ = aX0;
  9747. gradient.y0_ = aY0;
  9748. gradient.r0_ = aR0;
  9749. gradient.x1_ = aX1;
  9750. gradient.y1_ = aY1;
  9751. gradient.r1_ = aR1;
  9752. return gradient;
  9753. };
  9754. contextPrototype.drawImage = function (image, var_args) {
  9755. var dx, dy, dw, dh, sx, sy, sw, sh;
  9756. var oldRuntimeWidth = image.runtimeStyle.width;
  9757. var oldRuntimeHeight = image.runtimeStyle.height;
  9758. image.runtimeStyle.width = 'auto';
  9759. image.runtimeStyle.height = 'auto';
  9760. var w = image.width;
  9761. var h = image.height;
  9762. image.runtimeStyle.width = oldRuntimeWidth;
  9763. image.runtimeStyle.height = oldRuntimeHeight;
  9764. if (arguments.length == 3) {
  9765. dx = arguments[1];
  9766. dy = arguments[2];
  9767. sx = sy = 0;
  9768. sw = dw = w;
  9769. sh = dh = h;
  9770. } else if (arguments.length == 5) {
  9771. dx = arguments[1];
  9772. dy = arguments[2];
  9773. dw = arguments[3];
  9774. dh = arguments[4];
  9775. sx = sy = 0;
  9776. sw = w;
  9777. sh = h;
  9778. } else if (arguments.length == 9) {
  9779. sx = arguments[1];
  9780. sy = arguments[2];
  9781. sw = arguments[3];
  9782. sh = arguments[4];
  9783. dx = arguments[5];
  9784. dy = arguments[6];
  9785. dw = arguments[7];
  9786. dh = arguments[8];
  9787. } else {
  9788. throw Error('Invalid number of arguments');
  9789. }
  9790. var d = getCoords(this, dx, dy);
  9791. var w2 = sw / 2;
  9792. var h2 = sh / 2;
  9793. var vmlStr = [];
  9794. var W = 10;
  9795. var H = 10;
  9796. var scaleX = scaleY = 1;
  9797. vmlStr.push(' <g_vml_:group', ' coordsize="', Z * W, ',', Z * H, '"', ' coordorigin="0,0"', ' style="width:', W, 'px;height:', H, 'px;position:absolute;');
  9798. if (this.m_[0][0] != 1 || this.m_[0][1] || this.m_[1][1] != 1 || this.m_[1][0]) {
  9799. var filter = [];
  9800. var scaleX = this.scaleX_;
  9801. var scaleY = this.scaleY_;
  9802. 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), '');
  9803. var max = d;
  9804. var c2 = getCoords(this, dx + dw, dy);
  9805. var c3 = getCoords(this, dx, dy + dh);
  9806. var c4 = getCoords(this, dx + dw, dy + dh);
  9807. max.x = m.max(max.x, c2.x, c3.x, c4.x);
  9808. max.y = m.max(max.y, c2.y, c3.y, c4.y);
  9809. vmlStr.push('padding:0 ', mr(max.x / Z), 'px ', mr(max.y / Z), 'px 0;filter:progid:DXImageTransform.Microsoft.Matrix(', filter.join(''), ', SizingMethod=\'clip\');');
  9810. } else {
  9811. vmlStr.push('top:', mr(d.y / Z), 'px;left:', mr(d.x / Z), 'px;');
  9812. }
  9813. vmlStr.push(' ">');
  9814. if (sx || sy) {
  9815. 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, ');">');
  9816. }
  9817. vmlStr.push('<div style="width:', Math.round(scaleX * w * dw / sw), 'px;', ' height:', Math.round(scaleY * h * dh / sh), 'px;', ' filter:');
  9818. if (this.globalAlpha < 1) {
  9819. vmlStr.push(' progid:DXImageTransform.Microsoft.Alpha(opacity=' + this.globalAlpha * 100 + ')');
  9820. }
  9821. vmlStr.push(' progid:DXImageTransform.Microsoft.AlphaImageLoader(src=', image.src, ',sizingMethod=scale)">');
  9822. if (sx || sy)
  9823. vmlStr.push('</div>');
  9824. vmlStr.push('</div></div>');
  9825. this.element_.insertAdjacentHTML('BeforeEnd', vmlStr.join(''));
  9826. };
  9827. contextPrototype.stroke = function (aFill) {
  9828. var lineStr = [];
  9829. var lineOpen = false;
  9830. var W = 10;
  9831. var H = 10;
  9832. 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="');
  9833. var newSeq = false;
  9834. var min = {
  9835. x: null,
  9836. y: null
  9837. };
  9838. var max = {
  9839. x: null,
  9840. y: null
  9841. };
  9842. for (var i = 0; i < this.currentPath_.length; i++) {
  9843. var p = this.currentPath_[i];
  9844. var c;
  9845. switch (p.type) {
  9846. case 'moveTo':
  9847. c = p;
  9848. lineStr.push(' m ', mr(p.x), ',', mr(p.y));
  9849. break;
  9850. case 'lineTo':
  9851. lineStr.push(' l ', mr(p.x), ',', mr(p.y));
  9852. break;
  9853. case 'close':
  9854. lineStr.push(' x ');
  9855. p = null;
  9856. break;
  9857. case 'bezierCurveTo':
  9858. lineStr.push(' c ', mr(p.cp1x), ',', mr(p.cp1y), ',', mr(p.cp2x), ',', mr(p.cp2y), ',', mr(p.x), ',', mr(p.y));
  9859. break;
  9860. case 'at':
  9861. case 'wa':
  9862. 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));
  9863. break;
  9864. }
  9865. if (p) {
  9866. if (min.x == null || p.x < min.x) {
  9867. min.x = p.x;
  9868. }
  9869. if (max.x == null || p.x > max.x) {
  9870. max.x = p.x;
  9871. }
  9872. if (min.y == null || p.y < min.y) {
  9873. min.y = p.y;
  9874. }
  9875. if (max.y == null || p.y > max.y) {
  9876. max.y = p.y;
  9877. }
  9878. }
  9879. }
  9880. lineStr.push(' ">');
  9881. if (!aFill) {
  9882. appendStroke(this, lineStr);
  9883. } else {
  9884. appendFill(this, lineStr, min, max);
  9885. }
  9886. lineStr.push('</g_vml_:shape>');
  9887. this.element_.insertAdjacentHTML('beforeEnd', lineStr.join(''));
  9888. };
  9889. function appendStroke(ctx, lineStr) {
  9890. var a = processStyle(ctx.strokeStyle);
  9891. var color = a.color;
  9892. var opacity = a.alpha * ctx.globalAlpha;
  9893. var lineWidth = ctx.lineScale_ * ctx.lineWidth;
  9894. if (lineWidth < 1) {
  9895. opacity *= lineWidth;
  9896. }
  9897. lineStr.push('<g_vml_:stroke', ' opacity="', opacity, '"', ' joinstyle="', ctx.lineJoin, '"', ' miterlimit="', ctx.miterLimit, '"', ' endcap="', processLineCap(ctx.lineCap), '"', ' weight="', lineWidth, 'px"', ' color="', color, '" />');
  9898. }
  9899. function appendFill(ctx, lineStr, min, max) {
  9900. var fillStyle = ctx.fillStyle;
  9901. var arcScaleX = ctx.scaleX_;
  9902. var arcScaleY = ctx.scaleY_;
  9903. var width = max.x - min.x;
  9904. var height = max.y - min.y;
  9905. if (fillStyle instanceof CanvasGradient_) {
  9906. var angle = 0;
  9907. var focus = {
  9908. x: 0,
  9909. y: 0
  9910. };
  9911. var shift = 0;
  9912. var expansion = 1;
  9913. if (fillStyle.type_ == 'gradient') {
  9914. var x0 = fillStyle.x0_ / arcScaleX;
  9915. var y0 = fillStyle.y0_ / arcScaleY;
  9916. var x1 = fillStyle.x1_ / arcScaleX;
  9917. var y1 = fillStyle.y1_ / arcScaleY;
  9918. var p0 = getCoords(ctx, x0, y0);
  9919. var p1 = getCoords(ctx, x1, y1);
  9920. var dx = p1.x - p0.x;
  9921. var dy = p1.y - p0.y;
  9922. angle = Math.atan2(dx, dy) * 180 / Math.PI;
  9923. if (angle < 0) {
  9924. angle += 360;
  9925. }
  9926. if (angle < 0.000001) {
  9927. angle = 0;
  9928. }
  9929. } else {
  9930. var p0 = getCoords(ctx, fillStyle.x0_, fillStyle.y0_);
  9931. focus = {
  9932. x: (p0.x - min.x) / width,
  9933. y: (p0.y - min.y) / height
  9934. };
  9935. width /= arcScaleX * Z;
  9936. height /= arcScaleY * Z;
  9937. var dimension = m.max(width, height);
  9938. shift = 2 * fillStyle.r0_ / dimension;
  9939. expansion = 2 * fillStyle.r1_ / dimension - shift;
  9940. }
  9941. var stops = fillStyle.colors_;
  9942. stops.sort(function (cs1, cs2) {
  9943. return cs1.offset - cs2.offset;
  9944. });
  9945. var length = stops.length;
  9946. var color1 = stops[0].color;
  9947. var color2 = stops[length - 1].color;
  9948. var opacity1 = stops[0].alpha * ctx.globalAlpha;
  9949. var opacity2 = stops[length - 1].alpha * ctx.globalAlpha;
  9950. var colors = [];
  9951. for (var i = 0; i < length; i++) {
  9952. var stop = stops[i];
  9953. colors.push(stop.offset * expansion + shift + ' ' + stop.color);
  9954. }
  9955. 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, '" />');
  9956. } else if (fillStyle instanceof CanvasPattern_) {
  9957. if (width && height) {
  9958. var deltaLeft = -min.x;
  9959. var deltaTop = -min.y;
  9960. lineStr.push('<g_vml_:fill', ' position="', deltaLeft / width * arcScaleX * arcScaleX, ',', deltaTop / height * arcScaleY * arcScaleY, '"', ' type="tile"', ' src="', fillStyle.src_, '" />');
  9961. }
  9962. } else {
  9963. var a = processStyle(ctx.fillStyle);
  9964. var color = a.color;
  9965. var opacity = a.alpha * ctx.globalAlpha;
  9966. lineStr.push('<g_vml_:fill color="', color, '" opacity="', opacity, '" />');
  9967. }
  9968. }
  9969. contextPrototype.fill = function () {
  9970. this.stroke(true);
  9971. };
  9972. contextPrototype.closePath = function () {
  9973. this.currentPath_.push({ type: 'close' });
  9974. };
  9975. function getCoords(ctx, aX, aY) {
  9976. var m = ctx.m_;
  9977. return {
  9978. x: Z * (aX * m[0][0] + aY * m[1][0] + m[2][0]) - Z2,
  9979. y: Z * (aX * m[0][1] + aY * m[1][1] + m[2][1]) - Z2
  9980. };
  9981. }
  9982. ;
  9983. contextPrototype.save = function () {
  9984. var o = {};
  9985. copyState(this, o);
  9986. this.aStack_.push(o);
  9987. this.mStack_.push(this.m_);
  9988. this.m_ = matrixMultiply(createMatrixIdentity(), this.m_);
  9989. };
  9990. contextPrototype.restore = function () {
  9991. if (this.aStack_.length) {
  9992. copyState(this.aStack_.pop(), this);
  9993. this.m_ = this.mStack_.pop();
  9994. }
  9995. };
  9996. function matrixIsFinite(m) {
  9997. 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]);
  9998. }
  9999. function setM(ctx, m, updateLineScale) {
  10000. if (!matrixIsFinite(m)) {
  10001. return;
  10002. }
  10003. ctx.m_ = m;
  10004. ctx.scaleX_ = Math.sqrt(m[0][0] * m[0][0] + m[0][1] * m[0][1]);
  10005. ctx.scaleY_ = Math.sqrt(m[1][0] * m[1][0] + m[1][1] * m[1][1]);
  10006. if (updateLineScale) {
  10007. var det = m[0][0] * m[1][1] - m[0][1] * m[1][0];
  10008. ctx.lineScale_ = sqrt(abs(det));
  10009. }
  10010. }
  10011. contextPrototype.translate = function (aX, aY) {
  10012. var m1 = [
  10013. [
  10014. 1,
  10015. 0,
  10016. 0
  10017. ],
  10018. [
  10019. 0,
  10020. 1,
  10021. 0
  10022. ],
  10023. [
  10024. aX,
  10025. aY,
  10026. 1
  10027. ]
  10028. ];
  10029. setM(this, matrixMultiply(m1, this.m_), false);
  10030. };
  10031. contextPrototype.rotate = function (aRot) {
  10032. var c = mc(aRot);
  10033. var s = ms(aRot);
  10034. var m1 = [
  10035. [
  10036. c,
  10037. s,
  10038. 0
  10039. ],
  10040. [
  10041. -s,
  10042. c,
  10043. 0
  10044. ],
  10045. [
  10046. 0,
  10047. 0,
  10048. 1
  10049. ]
  10050. ];
  10051. setM(this, matrixMultiply(m1, this.m_), false);
  10052. };
  10053. contextPrototype.scale = function (aX, aY) {
  10054. var m1 = [
  10055. [
  10056. aX,
  10057. 0,
  10058. 0
  10059. ],
  10060. [
  10061. 0,
  10062. aY,
  10063. 0
  10064. ],
  10065. [
  10066. 0,
  10067. 0,
  10068. 1
  10069. ]
  10070. ];
  10071. setM(this, matrixMultiply(m1, this.m_), true);
  10072. };
  10073. contextPrototype.transform = function (m11, m12, m21, m22, dx, dy) {
  10074. var m1 = [
  10075. [
  10076. m11,
  10077. m12,
  10078. 0
  10079. ],
  10080. [
  10081. m21,
  10082. m22,
  10083. 0
  10084. ],
  10085. [
  10086. dx,
  10087. dy,
  10088. 1
  10089. ]
  10090. ];
  10091. setM(this, matrixMultiply(m1, this.m_), true);
  10092. };
  10093. contextPrototype.setTransform = function (m11, m12, m21, m22, dx, dy) {
  10094. var m = [
  10095. [
  10096. m11,
  10097. m12,
  10098. 0
  10099. ],
  10100. [
  10101. m21,
  10102. m22,
  10103. 0
  10104. ],
  10105. [
  10106. dx,
  10107. dy,
  10108. 1
  10109. ]
  10110. ];
  10111. setM(this, m, true);
  10112. };
  10113. contextPrototype.drawText_ = function (text, x, y, maxWidth, stroke) {
  10114. var m = this.m_, delta = 1000, left = 0, right = delta, offset = {
  10115. x: 0,
  10116. y: 0
  10117. }, lineStr = [];
  10118. var fontStyle = getComputedStyle(processFontStyle(this.font), this.element_);
  10119. var fontStyleString = buildStyle(fontStyle);
  10120. var elementStyle = this.element_.currentStyle;
  10121. var textAlign = this.textAlign.toLowerCase();
  10122. switch (textAlign) {
  10123. case 'left':
  10124. case 'center':
  10125. case 'right':
  10126. break;
  10127. case 'end':
  10128. textAlign = elementStyle.direction == 'ltr' ? 'right' : 'left';
  10129. break;
  10130. case 'start':
  10131. textAlign = elementStyle.direction == 'rtl' ? 'right' : 'left';
  10132. break;
  10133. default:
  10134. textAlign = 'left';
  10135. }
  10136. switch (this.textBaseline) {
  10137. case 'hanging':
  10138. case 'top':
  10139. offset.y = fontStyle.size / 1.75;
  10140. break;
  10141. case 'middle':
  10142. break;
  10143. default:
  10144. case null:
  10145. case 'alphabetic':
  10146. case 'ideographic':
  10147. case 'bottom':
  10148. offset.y = -fontStyle.size / 2.25;
  10149. break;
  10150. }
  10151. switch (textAlign) {
  10152. case 'right':
  10153. left = delta;
  10154. right = 0.05;
  10155. break;
  10156. case 'center':
  10157. left = right = delta / 2;
  10158. break;
  10159. }
  10160. var d = getCoords(this, x + offset.x, y + offset.y);
  10161. 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;">');
  10162. if (stroke) {
  10163. appendStroke(this, lineStr);
  10164. } else {
  10165. appendFill(this, lineStr, {
  10166. x: -left,
  10167. y: 0
  10168. }, {
  10169. x: right,
  10170. y: fontStyle.size
  10171. });
  10172. }
  10173. var skewM = m[0][0].toFixed(3) + ',' + m[1][0].toFixed(3) + ',' + m[0][1].toFixed(3) + ',' + m[1][1].toFixed(3) + ',0,0';
  10174. var skewOffset = mr(d.x / Z) + ',' + mr(d.y / Z);
  10175. 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>');
  10176. this.element_.insertAdjacentHTML('beforeEnd', lineStr.join(''));
  10177. };
  10178. contextPrototype.fillText = function (text, x, y, maxWidth) {
  10179. this.drawText_(text, x, y, maxWidth, false);
  10180. };
  10181. contextPrototype.strokeText = function (text, x, y, maxWidth) {
  10182. this.drawText_(text, x, y, maxWidth, true);
  10183. };
  10184. contextPrototype.measureText = function (text) {
  10185. if (!this.textMeasureEl_) {
  10186. var s = '<span style="position:absolute;' + 'top:-20000px;left:0;padding:0;margin:0;border:none;' + 'white-space:pre;"></span>';
  10187. this.element_.insertAdjacentHTML('beforeEnd', s);
  10188. this.textMeasureEl_ = this.element_.lastChild;
  10189. }
  10190. var doc = this.element_.ownerDocument;
  10191. this.textMeasureEl_.innerHTML = '';
  10192. try {
  10193. this.textMeasureEl_.style.font = this.font;
  10194. } catch (ex) {
  10195. }
  10196. this.textMeasureEl_.appendChild(doc.createTextNode(text));
  10197. return { width: this.textMeasureEl_.offsetWidth };
  10198. };
  10199. contextPrototype.clip = function () {
  10200. };
  10201. contextPrototype.arcTo = function () {
  10202. };
  10203. contextPrototype.createPattern = function (image, repetition) {
  10204. return new CanvasPattern_(image, repetition);
  10205. };
  10206. function CanvasGradient_(aType) {
  10207. this.type_ = aType;
  10208. this.x0_ = 0;
  10209. this.y0_ = 0;
  10210. this.r0_ = 0;
  10211. this.x1_ = 0;
  10212. this.y1_ = 0;
  10213. this.r1_ = 0;
  10214. this.colors_ = [];
  10215. }
  10216. CanvasGradient_.prototype.addColorStop = function (aOffset, aColor) {
  10217. aColor = processStyle(aColor);
  10218. this.colors_.push({
  10219. offset: aOffset,
  10220. color: aColor.color,
  10221. alpha: aColor.alpha
  10222. });
  10223. };
  10224. function CanvasPattern_(image, repetition) {
  10225. assertImageIsValid(image);
  10226. switch (repetition) {
  10227. case 'repeat':
  10228. case null:
  10229. case '':
  10230. this.repetition_ = 'repeat';
  10231. break;
  10232. case 'repeat-x':
  10233. case 'repeat-y':
  10234. case 'no-repeat':
  10235. this.repetition_ = repetition;
  10236. break;
  10237. default:
  10238. throwException('SYNTAX_ERR');
  10239. }
  10240. this.src_ = image.src;
  10241. this.width_ = image.width;
  10242. this.height_ = image.height;
  10243. }
  10244. function throwException(s) {
  10245. throw new DOMException_(s);
  10246. }
  10247. function assertImageIsValid(img) {
  10248. if (!img || img.nodeType != 1 || img.tagName != 'IMG') {
  10249. throwException('TYPE_MISMATCH_ERR');
  10250. }
  10251. if (img.readyState != 'complete') {
  10252. throwException('INVALID_STATE_ERR');
  10253. }
  10254. }
  10255. function DOMException_(s) {
  10256. this.code = this[s];
  10257. this.message = s + ': DOM Exception ' + this.code;
  10258. }
  10259. var p = DOMException_.prototype = new Error();
  10260. p.INDEX_SIZE_ERR = 1;
  10261. p.DOMSTRING_SIZE_ERR = 2;
  10262. p.HIERARCHY_REQUEST_ERR = 3;
  10263. p.WRONG_DOCUMENT_ERR = 4;
  10264. p.INVALID_CHARACTER_ERR = 5;
  10265. p.NO_DATA_ALLOWED_ERR = 6;
  10266. p.NO_MODIFICATION_ALLOWED_ERR = 7;
  10267. p.NOT_FOUND_ERR = 8;
  10268. p.NOT_SUPPORTED_ERR = 9;
  10269. p.INUSE_ATTRIBUTE_ERR = 10;
  10270. p.INVALID_STATE_ERR = 11;
  10271. p.SYNTAX_ERR = 12;
  10272. p.INVALID_MODIFICATION_ERR = 13;
  10273. p.NAMESPACE_ERR = 14;
  10274. p.INVALID_ACCESS_ERR = 15;
  10275. p.VALIDATION_ERR = 16;
  10276. p.TYPE_MISMATCH_ERR = 17;
  10277. G_vmlCanvasManager = G_vmlCanvasManager_;
  10278. CanvasRenderingContext2D = CanvasRenderingContext2D_;
  10279. CanvasGradient = CanvasGradient_;
  10280. CanvasPattern = CanvasPattern_;
  10281. DOMException = DOMException_;
  10282. }());
  10283. } else {
  10284. G_vmlCanvasManager = false;
  10285. }
  10286. return G_vmlCanvasManager;
  10287. });define('zrender/mixin/Eventful', ['require'], function (require) {
  10288. var Eventful = function () {
  10289. this._handlers = {};
  10290. };
  10291. Eventful.prototype.one = function (event, handler, context) {
  10292. var _h = this._handlers;
  10293. if (!handler || !event) {
  10294. return this;
  10295. }
  10296. if (!_h[event]) {
  10297. _h[event] = [];
  10298. }
  10299. _h[event].push({
  10300. h: handler,
  10301. one: true,
  10302. ctx: context || this
  10303. });
  10304. return this;
  10305. };
  10306. Eventful.prototype.bind = function (event, handler, context) {
  10307. var _h = this._handlers;
  10308. if (!handler || !event) {
  10309. return this;
  10310. }
  10311. if (!_h[event]) {
  10312. _h[event] = [];
  10313. }
  10314. _h[event].push({
  10315. h: handler,
  10316. one: false,
  10317. ctx: context || this
  10318. });
  10319. return this;
  10320. };
  10321. Eventful.prototype.unbind = function (event, handler) {
  10322. var _h = this._handlers;
  10323. if (!event) {
  10324. this._handlers = {};
  10325. return this;
  10326. }
  10327. if (handler) {
  10328. if (_h[event]) {
  10329. var newList = [];
  10330. for (var i = 0, l = _h[event].length; i < l; i++) {
  10331. if (_h[event][i]['h'] != handler) {
  10332. newList.push(_h[event][i]);
  10333. }
  10334. }
  10335. _h[event] = newList;
  10336. }
  10337. if (_h[event] && _h[event].length === 0) {
  10338. delete _h[event];
  10339. }
  10340. } else {
  10341. delete _h[event];
  10342. }
  10343. return this;
  10344. };
  10345. Eventful.prototype.dispatch = function (type) {
  10346. if (this._handlers[type]) {
  10347. var args = arguments;
  10348. var argLen = args.length;
  10349. if (argLen > 3) {
  10350. args = Array.prototype.slice.call(args, 1);
  10351. }
  10352. var _h = this._handlers[type];
  10353. var len = _h.length;
  10354. for (var i = 0; i < len;) {
  10355. switch (argLen) {
  10356. case 1:
  10357. _h[i]['h'].call(_h[i]['ctx']);
  10358. break;
  10359. case 2:
  10360. _h[i]['h'].call(_h[i]['ctx'], args[1]);
  10361. break;
  10362. case 3:
  10363. _h[i]['h'].call(_h[i]['ctx'], args[1], args[2]);
  10364. break;
  10365. default:
  10366. _h[i]['h'].apply(_h[i]['ctx'], args);
  10367. break;
  10368. }
  10369. if (_h[i]['one']) {
  10370. _h.splice(i, 1);
  10371. len--;
  10372. } else {
  10373. i++;
  10374. }
  10375. }
  10376. }
  10377. return this;
  10378. };
  10379. Eventful.prototype.dispatchWithContext = function (type) {
  10380. if (this._handlers[type]) {
  10381. var args = arguments;
  10382. var argLen = args.length;
  10383. if (argLen > 4) {
  10384. args = Array.prototype.slice.call(args, 1, args.length - 1);
  10385. }
  10386. var ctx = args[args.length - 1];
  10387. var _h = this._handlers[type];
  10388. var len = _h.length;
  10389. for (var i = 0; i < len;) {
  10390. switch (argLen) {
  10391. case 1:
  10392. _h[i]['h'].call(ctx);
  10393. break;
  10394. case 2:
  10395. _h[i]['h'].call(ctx, args[1]);
  10396. break;
  10397. case 3:
  10398. _h[i]['h'].call(ctx, args[1], args[2]);
  10399. break;
  10400. default:
  10401. _h[i]['h'].apply(ctx, args);
  10402. break;
  10403. }
  10404. if (_h[i]['one']) {
  10405. _h.splice(i, 1);
  10406. len--;
  10407. } else {
  10408. i++;
  10409. }
  10410. }
  10411. }
  10412. return this;
  10413. };
  10414. return Eventful;
  10415. });define('zrender/tool/log', [
  10416. 'require',
  10417. '../config'
  10418. ], function (require) {
  10419. var config = require('../config');
  10420. return function () {
  10421. if (config.debugMode === 0) {
  10422. return;
  10423. } else if (config.debugMode == 1) {
  10424. for (var k in arguments) {
  10425. throw new Error(arguments[k]);
  10426. }
  10427. } else if (config.debugMode > 1) {
  10428. for (var k in arguments) {
  10429. console.log(arguments[k]);
  10430. }
  10431. }
  10432. };
  10433. });define('zrender/tool/guid', [], function () {
  10434. var idStart = 2311;
  10435. return function () {
  10436. return 'zrender__' + idStart++;
  10437. };
  10438. });define('zrender/Handler', [
  10439. 'require',
  10440. './config',
  10441. './tool/env',
  10442. './tool/event',
  10443. './tool/util',
  10444. './tool/vector',
  10445. './tool/matrix',
  10446. './mixin/Eventful'
  10447. ], function (require) {
  10448. 'use strict';
  10449. var config = require('./config');
  10450. var env = require('./tool/env');
  10451. var eventTool = require('./tool/event');
  10452. var util = require('./tool/util');
  10453. var vec2 = require('./tool/vector');
  10454. var mat2d = require('./tool/matrix');
  10455. var EVENT = config.EVENT;
  10456. var Eventful = require('./mixin/Eventful');
  10457. var domHandlerNames = [
  10458. 'resize',
  10459. 'click',
  10460. 'dblclick',
  10461. 'mousewheel',
  10462. 'mousemove',
  10463. 'mouseout',
  10464. 'mouseup',
  10465. 'mousedown',
  10466. 'touchstart',
  10467. 'touchend',
  10468. 'touchmove'
  10469. ];
  10470. var domHandlers = {
  10471. resize: function (event) {
  10472. event = event || window.event;
  10473. this._lastHover = null;
  10474. this._isMouseDown = 0;
  10475. this.dispatch(EVENT.RESIZE, event);
  10476. },
  10477. click: function (event) {
  10478. event = this._zrenderEventFixed(event);
  10479. var _lastHover = this._lastHover;
  10480. if (_lastHover && _lastHover.clickable || !_lastHover) {
  10481. if (this._clickThreshold < 5) {
  10482. this._dispatchAgency(_lastHover, EVENT.CLICK, event);
  10483. }
  10484. }
  10485. this._mousemoveHandler(event);
  10486. },
  10487. dblclick: function (event) {
  10488. event = event || window.event;
  10489. event = this._zrenderEventFixed(event);
  10490. var _lastHover = this._lastHover;
  10491. if (_lastHover && _lastHover.clickable || !_lastHover) {
  10492. if (this._clickThreshold < 5) {
  10493. this._dispatchAgency(_lastHover, EVENT.DBLCLICK, event);
  10494. }
  10495. }
  10496. this._mousemoveHandler(event);
  10497. },
  10498. mousewheel: function (event) {
  10499. event = this._zrenderEventFixed(event);
  10500. var delta = event.wheelDelta || -event.detail;
  10501. var scale = delta > 0 ? 1.1 : 1 / 1.1;
  10502. var needsRefresh = false;
  10503. var mouseX = this._mouseX;
  10504. var mouseY = this._mouseY;
  10505. this.painter.eachBuildinLayer(function (layer) {
  10506. var pos = layer.position;
  10507. if (layer.zoomable) {
  10508. layer.__zoom = layer.__zoom || 1;
  10509. var newZoom = layer.__zoom;
  10510. newZoom *= scale;
  10511. newZoom = Math.max(Math.min(layer.maxZoom, newZoom), layer.minZoom);
  10512. scale = newZoom / layer.__zoom;
  10513. layer.__zoom = newZoom;
  10514. pos[0] -= (mouseX - pos[0]) * (scale - 1);
  10515. pos[1] -= (mouseY - pos[1]) * (scale - 1);
  10516. layer.scale[0] *= scale;
  10517. layer.scale[1] *= scale;
  10518. layer.dirty = true;
  10519. needsRefresh = true;
  10520. eventTool.stop(event);
  10521. }
  10522. });
  10523. if (needsRefresh) {
  10524. this.painter.refresh();
  10525. }
  10526. this._dispatchAgency(this._lastHover, EVENT.MOUSEWHEEL, event);
  10527. this._mousemoveHandler(event);
  10528. },
  10529. mousemove: function (event) {
  10530. if (this.painter.isLoading()) {
  10531. return;
  10532. }
  10533. event = this._zrenderEventFixed(event);
  10534. this._lastX = this._mouseX;
  10535. this._lastY = this._mouseY;
  10536. this._mouseX = eventTool.getX(event);
  10537. this._mouseY = eventTool.getY(event);
  10538. var dx = this._mouseX - this._lastX;
  10539. var dy = this._mouseY - this._lastY;
  10540. this._processDragStart(event);
  10541. this._hasfound = 0;
  10542. this._event = event;
  10543. this._iterateAndFindHover();
  10544. if (!this._hasfound) {
  10545. if (!this._draggingTarget || this._lastHover && this._lastHover != this._draggingTarget) {
  10546. this._processOutShape(event);
  10547. this._processDragLeave(event);
  10548. }
  10549. this._lastHover = null;
  10550. this.storage.delHover();
  10551. this.painter.clearHover();
  10552. }
  10553. var cursor = 'default';
  10554. if (this._draggingTarget) {
  10555. this.storage.drift(this._draggingTarget.id, dx, dy);
  10556. this._draggingTarget.modSelf();
  10557. this.storage.addHover(this._draggingTarget);
  10558. this._clickThreshold++;
  10559. } else if (this._isMouseDown) {
  10560. var needsRefresh = false;
  10561. this.painter.eachBuildinLayer(function (layer) {
  10562. if (layer.panable) {
  10563. cursor = 'move';
  10564. layer.position[0] += dx;
  10565. layer.position[1] += dy;
  10566. needsRefresh = true;
  10567. layer.dirty = true;
  10568. }
  10569. });
  10570. if (needsRefresh) {
  10571. this.painter.refresh();
  10572. }
  10573. }
  10574. if (this._draggingTarget || this._hasfound && this._lastHover.draggable) {
  10575. cursor = 'move';
  10576. } else if (this._hasfound && this._lastHover.clickable) {
  10577. cursor = 'pointer';
  10578. }
  10579. this.root.style.cursor = cursor;
  10580. this._dispatchAgency(this._lastHover, EVENT.MOUSEMOVE, event);
  10581. if (this._draggingTarget || this._hasfound || this.storage.hasHoverShape()) {
  10582. this.painter.refreshHover();
  10583. }
  10584. },
  10585. mouseout: function (event) {
  10586. event = this._zrenderEventFixed(event);
  10587. var element = event.toElement || event.relatedTarget;
  10588. if (element != this.root) {
  10589. while (element && element.nodeType != 9) {
  10590. if (element == this.root) {
  10591. this._mousemoveHandler(event);
  10592. return;
  10593. }
  10594. element = element.parentNode;
  10595. }
  10596. }
  10597. event.zrenderX = this._lastX;
  10598. event.zrenderY = this._lastY;
  10599. this.root.style.cursor = 'default';
  10600. this._isMouseDown = 0;
  10601. this._processOutShape(event);
  10602. this._processDrop(event);
  10603. this._processDragEnd(event);
  10604. if (!this.painter.isLoading()) {
  10605. this.painter.refreshHover();
  10606. }
  10607. this.dispatch(EVENT.GLOBALOUT, event);
  10608. },
  10609. mousedown: function (event) {
  10610. this._clickThreshold = 0;
  10611. if (this._lastDownButton == 2) {
  10612. this._lastDownButton = event.button;
  10613. this._mouseDownTarget = null;
  10614. return;
  10615. }
  10616. this._lastMouseDownMoment = new Date();
  10617. event = this._zrenderEventFixed(event);
  10618. this._isMouseDown = 1;
  10619. this._mouseDownTarget = this._lastHover;
  10620. this._dispatchAgency(this._lastHover, EVENT.MOUSEDOWN, event);
  10621. this._lastDownButton = event.button;
  10622. },
  10623. mouseup: function (event) {
  10624. event = this._zrenderEventFixed(event);
  10625. this.root.style.cursor = 'default';
  10626. this._isMouseDown = 0;
  10627. this._mouseDownTarget = null;
  10628. this._dispatchAgency(this._lastHover, EVENT.MOUSEUP, event);
  10629. this._processDrop(event);
  10630. this._processDragEnd(event);
  10631. },
  10632. touchstart: function (event) {
  10633. event = this._zrenderEventFixed(event, true);
  10634. this._lastTouchMoment = new Date();
  10635. this._mobileFindFixed(event);
  10636. this._mousedownHandler(event);
  10637. },
  10638. touchmove: function (event) {
  10639. event = this._zrenderEventFixed(event, true);
  10640. this._mousemoveHandler(event);
  10641. if (this._isDragging) {
  10642. eventTool.stop(event);
  10643. }
  10644. },
  10645. touchend: function (event) {
  10646. event = this._zrenderEventFixed(event, true);
  10647. this._mouseupHandler(event);
  10648. var now = new Date();
  10649. if (now - this._lastTouchMoment < EVENT.touchClickDelay) {
  10650. this._mobileFindFixed(event);
  10651. this._clickHandler(event);
  10652. if (now - this._lastClickMoment < EVENT.touchClickDelay / 2) {
  10653. this._dblclickHandler(event);
  10654. if (this._lastHover && this._lastHover.clickable) {
  10655. eventTool.stop(event);
  10656. }
  10657. }
  10658. this._lastClickMoment = now;
  10659. }
  10660. this.painter.clearHover();
  10661. }
  10662. };
  10663. function bind1Arg(handler, context) {
  10664. return function (e) {
  10665. return handler.call(context, e);
  10666. };
  10667. }
  10668. function bind3Arg(handler, context) {
  10669. return function (arg1, arg2, arg3) {
  10670. return handler.call(context, arg1, arg2, arg3);
  10671. };
  10672. }
  10673. function initDomHandler(instance) {
  10674. var len = domHandlerNames.length;
  10675. while (len--) {
  10676. var name = domHandlerNames[len];
  10677. instance['_' + name + 'Handler'] = bind1Arg(domHandlers[name], instance);
  10678. }
  10679. }
  10680. var Handler = function (root, storage, painter) {
  10681. Eventful.call(this);
  10682. this.root = root;
  10683. this.storage = storage;
  10684. this.painter = painter;
  10685. this._lastX = this._lastY = this._mouseX = this._mouseY = 0;
  10686. this._findHover = bind3Arg(findHover, this);
  10687. this._domHover = painter.getDomHover();
  10688. initDomHandler(this);
  10689. if (window.addEventListener) {
  10690. window.addEventListener('resize', this._resizeHandler);
  10691. if (env.os.tablet || env.os.phone) {
  10692. root.addEventListener('touchstart', this._touchstartHandler);
  10693. root.addEventListener('touchmove', this._touchmoveHandler);
  10694. root.addEventListener('touchend', this._touchendHandler);
  10695. } else {
  10696. root.addEventListener('click', this._clickHandler);
  10697. root.addEventListener('dblclick', this._dblclickHandler);
  10698. root.addEventListener('mousewheel', this._mousewheelHandler);
  10699. root.addEventListener('mousemove', this._mousemoveHandler);
  10700. root.addEventListener('mousedown', this._mousedownHandler);
  10701. root.addEventListener('mouseup', this._mouseupHandler);
  10702. }
  10703. root.addEventListener('DOMMouseScroll', this._mousewheelHandler);
  10704. root.addEventListener('mouseout', this._mouseoutHandler);
  10705. } else {
  10706. window.attachEvent('onresize', this._resizeHandler);
  10707. root.attachEvent('onclick', this._clickHandler);
  10708. root.ondblclick = this._dblclickHandler;
  10709. root.attachEvent('onmousewheel', this._mousewheelHandler);
  10710. root.attachEvent('onmousemove', this._mousemoveHandler);
  10711. root.attachEvent('onmouseout', this._mouseoutHandler);
  10712. root.attachEvent('onmousedown', this._mousedownHandler);
  10713. root.attachEvent('onmouseup', this._mouseupHandler);
  10714. }
  10715. };
  10716. Handler.prototype.on = function (eventName, handler, context) {
  10717. this.bind(eventName, handler, context);
  10718. return this;
  10719. };
  10720. Handler.prototype.un = function (eventName, handler) {
  10721. this.unbind(eventName, handler);
  10722. return this;
  10723. };
  10724. Handler.prototype.trigger = function (eventName, eventArgs) {
  10725. switch (eventName) {
  10726. case EVENT.RESIZE:
  10727. case EVENT.CLICK:
  10728. case EVENT.DBLCLICK:
  10729. case EVENT.MOUSEWHEEL:
  10730. case EVENT.MOUSEMOVE:
  10731. case EVENT.MOUSEDOWN:
  10732. case EVENT.MOUSEUP:
  10733. case EVENT.MOUSEOUT:
  10734. this['_' + eventName + 'Handler'](eventArgs);
  10735. break;
  10736. }
  10737. };
  10738. Handler.prototype.dispose = function () {
  10739. var root = this.root;
  10740. if (window.removeEventListener) {
  10741. window.removeEventListener('resize', this._resizeHandler);
  10742. if (env.os.tablet || env.os.phone) {
  10743. root.removeEventListener('touchstart', this._touchstartHandler);
  10744. root.removeEventListener('touchmove', this._touchmoveHandler);
  10745. root.removeEventListener('touchend', this._touchendHandler);
  10746. } else {
  10747. root.removeEventListener('click', this._clickHandler);
  10748. root.removeEventListener('dblclick', this._dblclickHandler);
  10749. root.removeEventListener('mousewheel', this._mousewheelHandler);
  10750. root.removeEventListener('mousemove', this._mousemoveHandler);
  10751. root.removeEventListener('mousedown', this._mousedownHandler);
  10752. root.removeEventListener('mouseup', this._mouseupHandler);
  10753. }
  10754. root.removeEventListener('DOMMouseScroll', this._mousewheelHandler);
  10755. root.removeEventListener('mouseout', this._mouseoutHandler);
  10756. } else {
  10757. window.detachEvent('onresize', this._resizeHandler);
  10758. root.detachEvent('onclick', this._clickHandler);
  10759. root.detachEvent('dblclick', this._dblclickHandler);
  10760. root.detachEvent('onmousewheel', this._mousewheelHandler);
  10761. root.detachEvent('onmousemove', this._mousemoveHandler);
  10762. root.detachEvent('onmouseout', this._mouseoutHandler);
  10763. root.detachEvent('onmousedown', this._mousedownHandler);
  10764. root.detachEvent('onmouseup', this._mouseupHandler);
  10765. }
  10766. this.root = this._domHover = this.storage = this.painter = null;
  10767. this.un();
  10768. };
  10769. Handler.prototype._processDragStart = function (event) {
  10770. var _lastHover = this._lastHover;
  10771. if (this._isMouseDown && _lastHover && _lastHover.draggable && !this._draggingTarget && this._mouseDownTarget == _lastHover) {
  10772. if (_lastHover.dragEnableTime && new Date() - this._lastMouseDownMoment < _lastHover.dragEnableTime) {
  10773. return;
  10774. }
  10775. var _draggingTarget = _lastHover;
  10776. this._draggingTarget = _draggingTarget;
  10777. this._isDragging = 1;
  10778. _draggingTarget.invisible = true;
  10779. this.storage.mod(_draggingTarget.id);
  10780. this._dispatchAgency(_draggingTarget, EVENT.DRAGSTART, event);
  10781. this.painter.refresh();
  10782. }
  10783. };
  10784. Handler.prototype._processDragEnter = function (event) {
  10785. if (this._draggingTarget) {
  10786. this._dispatchAgency(this._lastHover, EVENT.DRAGENTER, event, this._draggingTarget);
  10787. }
  10788. };
  10789. Handler.prototype._processDragOver = function (event) {
  10790. if (this._draggingTarget) {
  10791. this._dispatchAgency(this._lastHover, EVENT.DRAGOVER, event, this._draggingTarget);
  10792. }
  10793. };
  10794. Handler.prototype._processDragLeave = function (event) {
  10795. if (this._draggingTarget) {
  10796. this._dispatchAgency(this._lastHover, EVENT.DRAGLEAVE, event, this._draggingTarget);
  10797. }
  10798. };
  10799. Handler.prototype._processDrop = function (event) {
  10800. if (this._draggingTarget) {
  10801. this._draggingTarget.invisible = false;
  10802. this.storage.mod(this._draggingTarget.id);
  10803. this.painter.refresh();
  10804. this._dispatchAgency(this._lastHover, EVENT.DROP, event, this._draggingTarget);
  10805. }
  10806. };
  10807. Handler.prototype._processDragEnd = function (event) {
  10808. if (this._draggingTarget) {
  10809. this._dispatchAgency(this._draggingTarget, EVENT.DRAGEND, event);
  10810. this._lastHover = null;
  10811. }
  10812. this._isDragging = 0;
  10813. this._draggingTarget = null;
  10814. };
  10815. Handler.prototype._processOverShape = function (event) {
  10816. this._dispatchAgency(this._lastHover, EVENT.MOUSEOVER, event);
  10817. };
  10818. Handler.prototype._processOutShape = function (event) {
  10819. this._dispatchAgency(this._lastHover, EVENT.MOUSEOUT, event);
  10820. };
  10821. Handler.prototype._dispatchAgency = function (targetShape, eventName, event, draggedShape) {
  10822. var eventHandler = 'on' + eventName;
  10823. var eventPacket = {
  10824. type: eventName,
  10825. event: event,
  10826. target: targetShape,
  10827. cancelBubble: false
  10828. };
  10829. var el = targetShape;
  10830. if (draggedShape) {
  10831. eventPacket.dragged = draggedShape;
  10832. }
  10833. while (el) {
  10834. el[eventHandler] && (eventPacket.cancelBubble = el[eventHandler](eventPacket));
  10835. el.dispatch(eventName, eventPacket);
  10836. el = el.parent;
  10837. if (eventPacket.cancelBubble) {
  10838. break;
  10839. }
  10840. }
  10841. if (targetShape) {
  10842. if (!eventPacket.cancelBubble) {
  10843. this.dispatch(eventName, eventPacket);
  10844. }
  10845. } else if (!draggedShape) {
  10846. var eveObj = {
  10847. type: eventName,
  10848. event: event
  10849. };
  10850. this.dispatch(eventName, eveObj);
  10851. this.painter.eachOtherLayer(function (layer) {
  10852. if (typeof layer[eventHandler] == 'function') {
  10853. layer[eventHandler](eveObj);
  10854. }
  10855. if (layer.dispatch) {
  10856. layer.dispatch(eventName, eveObj);
  10857. }
  10858. });
  10859. }
  10860. };
  10861. Handler.prototype._iterateAndFindHover = function () {
  10862. var invTransform = mat2d.create();
  10863. return function () {
  10864. var list = this.storage.getShapeList();
  10865. var currentZLevel;
  10866. var currentLayer;
  10867. var tmp = [
  10868. 0,
  10869. 0
  10870. ];
  10871. for (var i = list.length - 1; i >= 0; i--) {
  10872. var shape = list[i];
  10873. if (currentZLevel !== shape.zlevel) {
  10874. currentLayer = this.painter.getLayer(shape.zlevel, currentLayer);
  10875. tmp[0] = this._mouseX;
  10876. tmp[1] = this._mouseY;
  10877. if (currentLayer.needTransform) {
  10878. mat2d.invert(invTransform, currentLayer.transform);
  10879. vec2.applyTransform(tmp, tmp, invTransform);
  10880. }
  10881. }
  10882. if (this._findHover(shape, tmp[0], tmp[1])) {
  10883. break;
  10884. }
  10885. }
  10886. };
  10887. }();
  10888. var MOBILE_TOUCH_OFFSETS = [
  10889. { x: 10 },
  10890. { x: -20 },
  10891. {
  10892. x: 10,
  10893. y: 10
  10894. },
  10895. { y: -20 }
  10896. ];
  10897. Handler.prototype._mobileFindFixed = function (event) {
  10898. this._lastHover = null;
  10899. this._mouseX = event.zrenderX;
  10900. this._mouseY = event.zrenderY;
  10901. this._event = event;
  10902. this._iterateAndFindHover();
  10903. for (var i = 0; !this._lastHover && i < MOBILE_TOUCH_OFFSETS.length; i++) {
  10904. var offset = MOBILE_TOUCH_OFFSETS[i];
  10905. offset.x && (this._mouseX += offset.x);
  10906. offset.y && (this._mouseY += offset.y);
  10907. this._iterateAndFindHover();
  10908. }
  10909. if (this._lastHover) {
  10910. event.zrenderX = this._mouseX;
  10911. event.zrenderY = this._mouseY;
  10912. }
  10913. };
  10914. function findHover(shape, x, y) {
  10915. if (this._draggingTarget && this._draggingTarget.id == shape.id || shape.isSilent()) {
  10916. return false;
  10917. }
  10918. var event = this._event;
  10919. if (shape.isCover(x, y)) {
  10920. if (shape.hoverable) {
  10921. this.storage.addHover(shape);
  10922. }
  10923. var p = shape.parent;
  10924. while (p) {
  10925. if (p.clipShape && !p.clipShape.isCover(this._mouseX, this._mouseY)) {
  10926. return false;
  10927. }
  10928. p = p.parent;
  10929. }
  10930. if (this._lastHover != shape) {
  10931. this._processOutShape(event);
  10932. this._processDragLeave(event);
  10933. this._lastHover = shape;
  10934. this._processDragEnter(event);
  10935. }
  10936. this._processOverShape(event);
  10937. this._processDragOver(event);
  10938. this._hasfound = 1;
  10939. return true;
  10940. }
  10941. return false;
  10942. }
  10943. Handler.prototype._zrenderEventFixed = function (event, isTouch) {
  10944. if (event.zrenderFixed) {
  10945. return event;
  10946. }
  10947. if (!isTouch) {
  10948. event = event || window.event;
  10949. var target = event.toElement || event.relatedTarget || event.srcElement || event.target;
  10950. if (target && target != this._domHover) {
  10951. event.zrenderX = (typeof event.offsetX != 'undefined' ? event.offsetX : event.layerX) + target.offsetLeft;
  10952. event.zrenderY = (typeof event.offsetY != 'undefined' ? event.offsetY : event.layerY) + target.offsetTop;
  10953. }
  10954. } else {
  10955. var touch = event.type != 'touchend' ? event.targetTouches[0] : event.changedTouches[0];
  10956. if (touch) {
  10957. var rBounding = this.painter._domRoot.getBoundingClientRect();
  10958. event.zrenderX = touch.clientX - rBounding.left;
  10959. event.zrenderY = touch.clientY - rBounding.top;
  10960. }
  10961. }
  10962. event.zrenderFixed = 1;
  10963. return event;
  10964. };
  10965. util.merge(Handler.prototype, Eventful.prototype, true);
  10966. return Handler;
  10967. });define('zrender/Painter', [
  10968. 'require',
  10969. './config',
  10970. './tool/util',
  10971. './tool/log',
  10972. './loadingEffect/Base',
  10973. './Layer',
  10974. './shape/Image'
  10975. ], function (require) {
  10976. 'use strict';
  10977. var config = require('./config');
  10978. var util = require('./tool/util');
  10979. var log = require('./tool/log');
  10980. var BaseLoadingEffect = require('./loadingEffect/Base');
  10981. var Layer = require('./Layer');
  10982. function returnFalse() {
  10983. return false;
  10984. }
  10985. function doNothing() {
  10986. }
  10987. function isLayerValid(layer) {
  10988. if (!layer) {
  10989. return false;
  10990. }
  10991. if (layer.isBuildin) {
  10992. return true;
  10993. }
  10994. if (typeof layer.resize !== 'function' || typeof layer.refresh !== 'function') {
  10995. return false;
  10996. }
  10997. return true;
  10998. }
  10999. var Painter = function (root, storage) {
  11000. this.root = root;
  11001. root.style['-webkit-tap-highlight-color'] = 'transparent';
  11002. root.style['-webkit-user-select'] = 'none';
  11003. root.style['user-select'] = 'none';
  11004. root.style['-webkit-touch-callout'] = 'none';
  11005. this.storage = storage;
  11006. root.innerHTML = '';
  11007. this._width = this._getWidth();
  11008. this._height = this._getHeight();
  11009. var domRoot = document.createElement('div');
  11010. this._domRoot = domRoot;
  11011. domRoot.style.position = 'relative';
  11012. domRoot.style.overflow = 'hidden';
  11013. domRoot.style.width = this._width + 'px';
  11014. domRoot.style.height = this._height + 'px';
  11015. root.appendChild(domRoot);
  11016. this._layers = {};
  11017. this._zlevelList = [];
  11018. this._layerConfig = {};
  11019. this._loadingEffect = new BaseLoadingEffect({});
  11020. this.shapeToImage = this._createShapeToImageProcessor();
  11021. this._bgDom = document.createElement('div');
  11022. this._bgDom.style.cssText = [
  11023. 'position:absolute;left:0px;top:0px;width:',
  11024. this._width,
  11025. 'px;height:',
  11026. this._height + 'px;',
  11027. '-webkit-user-select:none;user-select;none;',
  11028. '-webkit-touch-callout:none;'
  11029. ].join('');
  11030. this._bgDom.setAttribute('data-zr-dom-id', 'bg');
  11031. domRoot.appendChild(this._bgDom);
  11032. this._bgDom.onselectstart = returnFalse;
  11033. var hoverLayer = new Layer('_zrender_hover_', this);
  11034. this._layers['hover'] = hoverLayer;
  11035. domRoot.appendChild(hoverLayer.dom);
  11036. hoverLayer.initContext();
  11037. hoverLayer.dom.onselectstart = returnFalse;
  11038. hoverLayer.dom.style['-webkit-user-select'] = 'none';
  11039. hoverLayer.dom.style['user-select'] = 'none';
  11040. hoverLayer.dom.style['-webkit-touch-callout'] = 'none';
  11041. this.refreshNextFrame = null;
  11042. };
  11043. Painter.prototype.render = function (callback) {
  11044. if (this.isLoading()) {
  11045. this.hideLoading();
  11046. }
  11047. this.refresh(callback, true);
  11048. return this;
  11049. };
  11050. Painter.prototype.refresh = function (callback, paintAll) {
  11051. var list = this.storage.getShapeList(true);
  11052. this._paintList(list, paintAll);
  11053. for (var i = 0; i < this._zlevelList.length; i++) {
  11054. var z = this._zlevelList[i];
  11055. var layer = this._layers[z];
  11056. if (!layer.isBuildin && layer.refresh) {
  11057. layer.refresh();
  11058. }
  11059. }
  11060. if (typeof callback == 'function') {
  11061. callback();
  11062. }
  11063. return this;
  11064. };
  11065. Painter.prototype._preProcessLayer = function (layer) {
  11066. layer.unusedCount++;
  11067. layer.updateTransform();
  11068. };
  11069. Painter.prototype._postProcessLayer = function (layer) {
  11070. layer.dirty = false;
  11071. if (layer.unusedCount == 1) {
  11072. layer.clear();
  11073. }
  11074. };
  11075. Painter.prototype._paintList = function (list, paintAll) {
  11076. if (typeof paintAll == 'undefined') {
  11077. paintAll = false;
  11078. }
  11079. this._updateLayerStatus(list);
  11080. var currentLayer;
  11081. var currentZLevel;
  11082. var ctx;
  11083. this.eachBuildinLayer(this._preProcessLayer);
  11084. for (var i = 0, l = list.length; i < l; i++) {
  11085. var shape = list[i];
  11086. if (currentZLevel !== shape.zlevel) {
  11087. if (currentLayer) {
  11088. if (currentLayer.needTransform) {
  11089. ctx.restore();
  11090. }
  11091. ctx.flush && ctx.flush();
  11092. }
  11093. currentZLevel = shape.zlevel;
  11094. currentLayer = this.getLayer(currentZLevel);
  11095. if (!currentLayer.isBuildin) {
  11096. log('ZLevel ' + currentZLevel + ' has been used by unkown layer ' + currentLayer.id);
  11097. }
  11098. ctx = currentLayer.ctx;
  11099. currentLayer.unusedCount = 0;
  11100. if (currentLayer.dirty || paintAll) {
  11101. currentLayer.clear();
  11102. }
  11103. if (currentLayer.needTransform) {
  11104. ctx.save();
  11105. currentLayer.setTransform(ctx);
  11106. }
  11107. }
  11108. if ((currentLayer.dirty || paintAll) && !shape.invisible) {
  11109. if (!shape.onbrush || shape.onbrush && !shape.onbrush(ctx, false)) {
  11110. if (config.catchBrushException) {
  11111. try {
  11112. shape.brush(ctx, false, this.refreshNextFrame);
  11113. } catch (error) {
  11114. log(error, 'brush error of ' + shape.type, shape);
  11115. }
  11116. } else {
  11117. shape.brush(ctx, false, this.refreshNextFrame);
  11118. }
  11119. }
  11120. }
  11121. shape.__dirty = false;
  11122. }
  11123. if (currentLayer) {
  11124. if (currentLayer.needTransform) {
  11125. ctx.restore();
  11126. }
  11127. ctx.flush && ctx.flush();
  11128. }
  11129. this.eachBuildinLayer(this._postProcessLayer);
  11130. };
  11131. Painter.prototype.getLayer = function (zlevel) {
  11132. var layer = this._layers[zlevel];
  11133. if (!layer) {
  11134. layer = new Layer(zlevel, this);
  11135. layer.isBuildin = true;
  11136. if (this._layerConfig[zlevel]) {
  11137. util.merge(layer, this._layerConfig[zlevel], true);
  11138. }
  11139. layer.updateTransform();
  11140. this.insertLayer(zlevel, layer);
  11141. layer.initContext();
  11142. }
  11143. return layer;
  11144. };
  11145. Painter.prototype.insertLayer = function (zlevel, layer) {
  11146. if (this._layers[zlevel]) {
  11147. log('ZLevel ' + zlevel + ' has been used already');
  11148. return;
  11149. }
  11150. if (!isLayerValid(layer)) {
  11151. log('Layer of zlevel ' + zlevel + ' is not valid');
  11152. return;
  11153. }
  11154. var len = this._zlevelList.length;
  11155. var prevLayer = null;
  11156. var i = -1;
  11157. if (len > 0 && zlevel > this._zlevelList[0]) {
  11158. for (i = 0; i < len - 1; i++) {
  11159. if (this._zlevelList[i] < zlevel && this._zlevelList[i + 1] > zlevel) {
  11160. break;
  11161. }
  11162. }
  11163. prevLayer = this._layers[this._zlevelList[i]];
  11164. }
  11165. this._zlevelList.splice(i + 1, 0, zlevel);
  11166. var prevDom = prevLayer ? prevLayer.dom : this._bgDom;
  11167. if (prevDom.nextSibling) {
  11168. prevDom.parentNode.insertBefore(layer.dom, prevDom.nextSibling);
  11169. } else {
  11170. prevDom.parentNode.appendChild(layer.dom);
  11171. }
  11172. this._layers[zlevel] = layer;
  11173. };
  11174. Painter.prototype.eachLayer = function (cb, context) {
  11175. for (var i = 0; i < this._zlevelList.length; i++) {
  11176. var z = this._zlevelList[i];
  11177. cb.call(context, this._layers[z], z);
  11178. }
  11179. };
  11180. Painter.prototype.eachBuildinLayer = function (cb, context) {
  11181. for (var i = 0; i < this._zlevelList.length; i++) {
  11182. var z = this._zlevelList[i];
  11183. var layer = this._layers[z];
  11184. if (layer.isBuildin) {
  11185. cb.call(context, layer, z);
  11186. }
  11187. }
  11188. };
  11189. Painter.prototype.eachOtherLayer = function (cb, context) {
  11190. for (var i = 0; i < this._zlevelList.length; i++) {
  11191. var z = this._zlevelList[i];
  11192. var layer = this._layers[z];
  11193. if (!layer.isBuildin) {
  11194. cb.call(context, layer, z);
  11195. }
  11196. }
  11197. };
  11198. Painter.prototype.getLayers = function () {
  11199. return this._layers;
  11200. };
  11201. Painter.prototype._updateLayerStatus = function (list) {
  11202. var layers = this._layers;
  11203. var elCounts = {};
  11204. this.eachBuildinLayer(function (layer, z) {
  11205. elCounts[z] = layer.elCount;
  11206. layer.elCount = 0;
  11207. });
  11208. for (var i = 0, l = list.length; i < l; i++) {
  11209. var shape = list[i];
  11210. var zlevel = shape.zlevel;
  11211. var layer = layers[zlevel];
  11212. if (layer) {
  11213. layer.elCount++;
  11214. if (layer.dirty) {
  11215. continue;
  11216. }
  11217. layer.dirty = shape.__dirty;
  11218. }
  11219. }
  11220. this.eachBuildinLayer(function (layer, z) {
  11221. if (elCounts[z] !== layer.elCount) {
  11222. layer.dirty = true;
  11223. }
  11224. });
  11225. };
  11226. Painter.prototype.refreshShapes = function (shapeList, callback) {
  11227. for (var i = 0, l = shapeList.length; i < l; i++) {
  11228. var shape = shapeList[i];
  11229. shape.modSelf();
  11230. }
  11231. this.refresh(callback);
  11232. return this;
  11233. };
  11234. Painter.prototype.setLoadingEffect = function (loadingEffect) {
  11235. this._loadingEffect = loadingEffect;
  11236. return this;
  11237. };
  11238. Painter.prototype.clear = function () {
  11239. this.eachBuildinLayer(this._clearLayer);
  11240. return this;
  11241. };
  11242. Painter.prototype._clearLayer = function (layer) {
  11243. layer.clear();
  11244. };
  11245. Painter.prototype.modLayer = function (zlevel, config) {
  11246. if (config) {
  11247. if (!this._layerConfig[zlevel]) {
  11248. this._layerConfig[zlevel] = config;
  11249. } else {
  11250. util.merge(this._layerConfig[zlevel], config, true);
  11251. }
  11252. var layer = this._layers[zlevel];
  11253. if (layer) {
  11254. util.merge(layer, this._layerConfig[zlevel], true);
  11255. }
  11256. }
  11257. };
  11258. Painter.prototype.delLayer = function (zlevel) {
  11259. var layer = this._layers[zlevel];
  11260. if (!layer) {
  11261. return;
  11262. }
  11263. this.modLayer(zlevel, {
  11264. position: layer.position,
  11265. rotation: layer.rotation,
  11266. scale: layer.scale
  11267. });
  11268. layer.dom.parentNode.removeChild(layer.dom);
  11269. delete this._layers[zlevel];
  11270. this._zlevelList.splice(util.indexOf(this._zlevelList, zlevel), 1);
  11271. };
  11272. Painter.prototype.refreshHover = function () {
  11273. this.clearHover();
  11274. var list = this.storage.getHoverShapes(true);
  11275. for (var i = 0, l = list.length; i < l; i++) {
  11276. this._brushHover(list[i]);
  11277. }
  11278. var ctx = this._layers.hover.ctx;
  11279. ctx.flush && ctx.flush();
  11280. this.storage.delHover();
  11281. return this;
  11282. };
  11283. Painter.prototype.clearHover = function () {
  11284. var hover = this._layers.hover;
  11285. hover && hover.clear();
  11286. return this;
  11287. };
  11288. Painter.prototype.showLoading = function (loadingEffect) {
  11289. this._loadingEffect && this._loadingEffect.stop();
  11290. loadingEffect && this.setLoadingEffect(loadingEffect);
  11291. this._loadingEffect.start(this);
  11292. this.loading = true;
  11293. return this;
  11294. };
  11295. Painter.prototype.hideLoading = function () {
  11296. this._loadingEffect.stop();
  11297. this.clearHover();
  11298. this.loading = false;
  11299. return this;
  11300. };
  11301. Painter.prototype.isLoading = function () {
  11302. return this.loading;
  11303. };
  11304. Painter.prototype.resize = function () {
  11305. var domRoot = this._domRoot;
  11306. domRoot.style.display = 'none';
  11307. var width = this._getWidth();
  11308. var height = this._getHeight();
  11309. domRoot.style.display = '';
  11310. if (this._width != width || height != this._height) {
  11311. this._width = width;
  11312. this._height = height;
  11313. domRoot.style.width = width + 'px';
  11314. domRoot.style.height = height + 'px';
  11315. for (var id in this._layers) {
  11316. this._layers[id].resize(width, height);
  11317. }
  11318. this.refresh(null, true);
  11319. }
  11320. return this;
  11321. };
  11322. Painter.prototype.clearLayer = function (zLevel) {
  11323. var layer = this._layers[zLevel];
  11324. if (layer) {
  11325. layer.clear();
  11326. }
  11327. };
  11328. Painter.prototype.dispose = function () {
  11329. if (this.isLoading()) {
  11330. this.hideLoading();
  11331. }
  11332. this.root.innerHTML = '';
  11333. this.root = this.storage = this._domRoot = this._layers = null;
  11334. };
  11335. Painter.prototype.getDomHover = function () {
  11336. return this._layers.hover.dom;
  11337. };
  11338. Painter.prototype.toDataURL = function (type, backgroundColor, args) {
  11339. if (window['G_vmlCanvasManager']) {
  11340. return null;
  11341. }
  11342. var imageLayer = new Layer('image', this);
  11343. this._bgDom.appendChild(imageLayer.dom);
  11344. imageLayer.initContext();
  11345. var ctx = imageLayer.ctx;
  11346. imageLayer.clearColor = backgroundColor || '#fff';
  11347. imageLayer.clear();
  11348. var self = this;
  11349. this.storage.iterShape(function (shape) {
  11350. if (!shape.invisible) {
  11351. if (!shape.onbrush || shape.onbrush && !shape.onbrush(ctx, false)) {
  11352. if (config.catchBrushException) {
  11353. try {
  11354. shape.brush(ctx, false, self.refreshNextFrame);
  11355. } catch (error) {
  11356. log(error, 'brush error of ' + shape.type, shape);
  11357. }
  11358. } else {
  11359. shape.brush(ctx, false, self.refreshNextFrame);
  11360. }
  11361. }
  11362. }
  11363. }, {
  11364. normal: 'up',
  11365. update: true
  11366. });
  11367. var image = imageLayer.dom.toDataURL(type, args);
  11368. ctx = null;
  11369. this._bgDom.removeChild(imageLayer.dom);
  11370. return image;
  11371. };
  11372. Painter.prototype.getWidth = function () {
  11373. return this._width;
  11374. };
  11375. Painter.prototype.getHeight = function () {
  11376. return this._height;
  11377. };
  11378. Painter.prototype._getWidth = function () {
  11379. var root = this.root;
  11380. var stl = root.currentStyle || document.defaultView.getComputedStyle(root);
  11381. return ((root.clientWidth || parseInt(stl.width, 10)) - parseInt(stl.paddingLeft, 10) - parseInt(stl.paddingRight, 10)).toFixed(0) - 0;
  11382. };
  11383. Painter.prototype._getHeight = function () {
  11384. var root = this.root;
  11385. var stl = root.currentStyle || document.defaultView.getComputedStyle(root);
  11386. return ((root.clientHeight || parseInt(stl.height, 10)) - parseInt(stl.paddingTop, 10) - parseInt(stl.paddingBottom, 10)).toFixed(0) - 0;
  11387. };
  11388. Painter.prototype._brushHover = function (shape) {
  11389. var ctx = this._layers.hover.ctx;
  11390. if (!shape.onbrush || shape.onbrush && !shape.onbrush(ctx, true)) {
  11391. var layer = this.getLayer(shape.zlevel);
  11392. if (layer.needTransform) {
  11393. ctx.save();
  11394. layer.setTransform(ctx);
  11395. }
  11396. if (config.catchBrushException) {
  11397. try {
  11398. shape.brush(ctx, true, this.refreshNextFrame);
  11399. } catch (error) {
  11400. log(error, 'hoverBrush error of ' + shape.type, shape);
  11401. }
  11402. } else {
  11403. shape.brush(ctx, true, this.refreshNextFrame);
  11404. }
  11405. if (layer.needTransform) {
  11406. ctx.restore();
  11407. }
  11408. }
  11409. };
  11410. Painter.prototype._shapeToImage = function (id, shape, width, height, devicePixelRatio) {
  11411. var canvas = document.createElement('canvas');
  11412. var ctx = canvas.getContext('2d');
  11413. canvas.style.width = width + 'px';
  11414. canvas.style.height = height + 'px';
  11415. canvas.setAttribute('width', width * devicePixelRatio);
  11416. canvas.setAttribute('height', height * devicePixelRatio);
  11417. ctx.clearRect(0, 0, width * devicePixelRatio, height * devicePixelRatio);
  11418. var shapeTransform = {
  11419. position: shape.position,
  11420. rotation: shape.rotation,
  11421. scale: shape.scale
  11422. };
  11423. shape.position = [
  11424. 0,
  11425. 0,
  11426. 0
  11427. ];
  11428. shape.rotation = 0;
  11429. shape.scale = [
  11430. 1,
  11431. 1
  11432. ];
  11433. if (shape) {
  11434. shape.brush(ctx, false);
  11435. }
  11436. var ImageShape = require('./shape/Image');
  11437. var imgShape = new ImageShape({
  11438. id: id,
  11439. style: {
  11440. x: 0,
  11441. y: 0,
  11442. image: canvas
  11443. }
  11444. });
  11445. if (shapeTransform.position != null) {
  11446. imgShape.position = shape.position = shapeTransform.position;
  11447. }
  11448. if (shapeTransform.rotation != null) {
  11449. imgShape.rotation = shape.rotation = shapeTransform.rotation;
  11450. }
  11451. if (shapeTransform.scale != null) {
  11452. imgShape.scale = shape.scale = shapeTransform.scale;
  11453. }
  11454. return imgShape;
  11455. };
  11456. Painter.prototype._createShapeToImageProcessor = function () {
  11457. if (window['G_vmlCanvasManager']) {
  11458. return doNothing;
  11459. }
  11460. var me = this;
  11461. return function (id, e, width, height) {
  11462. return me._shapeToImage(id, e, width, height, config.devicePixelRatio);
  11463. };
  11464. };
  11465. return Painter;
  11466. });define('zrender/Storage', [
  11467. 'require',
  11468. './tool/util',
  11469. './Group'
  11470. ], function (require) {
  11471. 'use strict';
  11472. var util = require('./tool/util');
  11473. var Group = require('./Group');
  11474. var defaultIterateOption = {
  11475. hover: false,
  11476. normal: 'down',
  11477. update: false
  11478. };
  11479. function shapeCompareFunc(a, b) {
  11480. if (a.zlevel == b.zlevel) {
  11481. if (a.z == b.z) {
  11482. return a.__renderidx - b.__renderidx;
  11483. }
  11484. return a.z - b.z;
  11485. }
  11486. return a.zlevel - b.zlevel;
  11487. }
  11488. var Storage = function () {
  11489. this._elements = {};
  11490. this._hoverElements = [];
  11491. this._roots = [];
  11492. this._shapeList = [];
  11493. this._shapeListOffset = 0;
  11494. };
  11495. Storage.prototype.iterShape = function (fun, option) {
  11496. if (!option) {
  11497. option = defaultIterateOption;
  11498. }
  11499. if (option.hover) {
  11500. for (var i = 0, l = this._hoverElements.length; i < l; i++) {
  11501. var el = this._hoverElements[i];
  11502. el.updateTransform();
  11503. if (fun(el)) {
  11504. return this;
  11505. }
  11506. }
  11507. }
  11508. if (option.update) {
  11509. this.updateShapeList();
  11510. }
  11511. switch (option.normal) {
  11512. case 'down':
  11513. var l = this._shapeList.length;
  11514. while (l--) {
  11515. if (fun(this._shapeList[l])) {
  11516. return this;
  11517. }
  11518. }
  11519. break;
  11520. default:
  11521. for (var i = 0, l = this._shapeList.length; i < l; i++) {
  11522. if (fun(this._shapeList[i])) {
  11523. return this;
  11524. }
  11525. }
  11526. break;
  11527. }
  11528. return this;
  11529. };
  11530. Storage.prototype.getHoverShapes = function (update) {
  11531. var hoverElements = [];
  11532. for (var i = 0, l = this._hoverElements.length; i < l; i++) {
  11533. hoverElements.push(this._hoverElements[i]);
  11534. var target = this._hoverElements[i].hoverConnect;
  11535. if (target) {
  11536. var shape;
  11537. target = target instanceof Array ? target : [target];
  11538. for (var j = 0, k = target.length; j < k; j++) {
  11539. shape = target[j].id ? target[j] : this.get(target[j]);
  11540. if (shape) {
  11541. hoverElements.push(shape);
  11542. }
  11543. }
  11544. }
  11545. }
  11546. hoverElements.sort(shapeCompareFunc);
  11547. if (update) {
  11548. for (var i = 0, l = hoverElements.length; i < l; i++) {
  11549. hoverElements[i].updateTransform();
  11550. }
  11551. }
  11552. return hoverElements;
  11553. };
  11554. Storage.prototype.getShapeList = function (update) {
  11555. if (update) {
  11556. this.updateShapeList();
  11557. }
  11558. return this._shapeList;
  11559. };
  11560. Storage.prototype.updateShapeList = function () {
  11561. this._shapeListOffset = 0;
  11562. for (var i = 0, len = this._roots.length; i < len; i++) {
  11563. var root = this._roots[i];
  11564. this._updateAndAddShape(root);
  11565. }
  11566. this._shapeList.length = this._shapeListOffset;
  11567. for (var i = 0, len = this._shapeList.length; i < len; i++) {
  11568. this._shapeList[i].__renderidx = i;
  11569. }
  11570. this._shapeList.sort(shapeCompareFunc);
  11571. };
  11572. Storage.prototype._updateAndAddShape = function (el, clipShapes) {
  11573. if (el.ignore) {
  11574. return;
  11575. }
  11576. el.updateTransform();
  11577. if (el.type == 'group') {
  11578. if (el.clipShape) {
  11579. el.clipShape.parent = el;
  11580. el.clipShape.updateTransform();
  11581. if (clipShapes) {
  11582. clipShapes = clipShapes.slice();
  11583. clipShapes.push(el.clipShape);
  11584. } else {
  11585. clipShapes = [el.clipShape];
  11586. }
  11587. }
  11588. for (var i = 0; i < el._children.length; i++) {
  11589. var child = el._children[i];
  11590. child.__dirty = el.__dirty || child.__dirty;
  11591. this._updateAndAddShape(child, clipShapes);
  11592. }
  11593. el.__dirty = false;
  11594. } else {
  11595. el.__clipShapes = clipShapes;
  11596. this._shapeList[this._shapeListOffset++] = el;
  11597. }
  11598. };
  11599. Storage.prototype.mod = function (el, params) {
  11600. if (typeof el === 'string') {
  11601. el = this._elements[el];
  11602. }
  11603. if (el) {
  11604. el.modSelf();
  11605. if (params) {
  11606. if (params.parent || params._storage || params.__clipShapes) {
  11607. var target = {};
  11608. for (var name in params) {
  11609. if (name === 'parent' || name === '_storage' || name === '__clipShapes') {
  11610. continue;
  11611. }
  11612. if (params.hasOwnProperty(name)) {
  11613. target[name] = params[name];
  11614. }
  11615. }
  11616. util.merge(el, target, true);
  11617. } else {
  11618. util.merge(el, params, true);
  11619. }
  11620. }
  11621. }
  11622. return this;
  11623. };
  11624. Storage.prototype.drift = function (shapeId, dx, dy) {
  11625. var shape = this._elements[shapeId];
  11626. if (shape) {
  11627. shape.needTransform = true;
  11628. if (shape.draggable === 'horizontal') {
  11629. dy = 0;
  11630. } else if (shape.draggable === 'vertical') {
  11631. dx = 0;
  11632. }
  11633. if (!shape.ondrift || shape.ondrift && !shape.ondrift(dx, dy)) {
  11634. shape.drift(dx, dy);
  11635. }
  11636. }
  11637. return this;
  11638. };
  11639. Storage.prototype.addHover = function (shape) {
  11640. shape.updateNeedTransform();
  11641. this._hoverElements.push(shape);
  11642. return this;
  11643. };
  11644. Storage.prototype.delHover = function () {
  11645. this._hoverElements = [];
  11646. return this;
  11647. };
  11648. Storage.prototype.hasHoverShape = function () {
  11649. return this._hoverElements.length > 0;
  11650. };
  11651. Storage.prototype.addRoot = function (el) {
  11652. if (this._elements[el.id]) {
  11653. return;
  11654. }
  11655. if (el instanceof Group) {
  11656. el.addChildrenToStorage(this);
  11657. }
  11658. this.addToMap(el);
  11659. this._roots.push(el);
  11660. };
  11661. Storage.prototype.delRoot = function (elId) {
  11662. if (typeof elId == 'undefined') {
  11663. for (var i = 0; i < this._roots.length; i++) {
  11664. var root = this._roots[i];
  11665. if (root instanceof Group) {
  11666. root.delChildrenFromStorage(this);
  11667. }
  11668. }
  11669. this._elements = {};
  11670. this._hoverElements = [];
  11671. this._roots = [];
  11672. this._shapeList = [];
  11673. this._shapeListOffset = 0;
  11674. return;
  11675. }
  11676. if (elId instanceof Array) {
  11677. for (var i = 0, l = elId.length; i < l; i++) {
  11678. this.delRoot(elId[i]);
  11679. }
  11680. return;
  11681. }
  11682. var el;
  11683. if (typeof elId == 'string') {
  11684. el = this._elements[elId];
  11685. } else {
  11686. el = elId;
  11687. }
  11688. var idx = util.indexOf(this._roots, el);
  11689. if (idx >= 0) {
  11690. this.delFromMap(el.id);
  11691. this._roots.splice(idx, 1);
  11692. if (el instanceof Group) {
  11693. el.delChildrenFromStorage(this);
  11694. }
  11695. }
  11696. };
  11697. Storage.prototype.addToMap = function (el) {
  11698. if (el instanceof Group) {
  11699. el._storage = this;
  11700. }
  11701. el.modSelf();
  11702. this._elements[el.id] = el;
  11703. return this;
  11704. };
  11705. Storage.prototype.get = function (elId) {
  11706. return this._elements[elId];
  11707. };
  11708. Storage.prototype.delFromMap = function (elId) {
  11709. var el = this._elements[elId];
  11710. if (el) {
  11711. delete this._elements[elId];
  11712. if (el instanceof Group) {
  11713. el._storage = null;
  11714. }
  11715. }
  11716. return this;
  11717. };
  11718. Storage.prototype.dispose = function () {
  11719. this._elements = this._renderList = this._roots = this._hoverElements = null;
  11720. };
  11721. return Storage;
  11722. });define('zrender/animation/Animation', [
  11723. 'require',
  11724. './Clip',
  11725. '../tool/color',
  11726. '../tool/util',
  11727. '../tool/event'
  11728. ], function (require) {
  11729. 'use strict';
  11730. var Clip = require('./Clip');
  11731. var color = require('../tool/color');
  11732. var util = require('../tool/util');
  11733. var Dispatcher = require('../tool/event').Dispatcher;
  11734. var requestAnimationFrame = window.requestAnimationFrame || window.msRequestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || function (func) {
  11735. setTimeout(func, 16);
  11736. };
  11737. var arraySlice = Array.prototype.slice;
  11738. var Animation = function (options) {
  11739. options = options || {};
  11740. this.stage = options.stage || {};
  11741. this.onframe = options.onframe || function () {
  11742. };
  11743. this._clips = [];
  11744. this._running = false;
  11745. this._time = 0;
  11746. Dispatcher.call(this);
  11747. };
  11748. Animation.prototype = {
  11749. add: function (clip) {
  11750. this._clips.push(clip);
  11751. },
  11752. remove: function (clip) {
  11753. var idx = util.indexOf(this._clips, clip);
  11754. if (idx >= 0) {
  11755. this._clips.splice(idx, 1);
  11756. }
  11757. },
  11758. _update: function () {
  11759. var time = new Date().getTime();
  11760. var delta = time - this._time;
  11761. var clips = this._clips;
  11762. var len = clips.length;
  11763. var deferredEvents = [];
  11764. var deferredClips = [];
  11765. for (var i = 0; i < len; i++) {
  11766. var clip = clips[i];
  11767. var e = clip.step(time);
  11768. if (e) {
  11769. deferredEvents.push(e);
  11770. deferredClips.push(clip);
  11771. }
  11772. }
  11773. for (var i = 0; i < len;) {
  11774. if (clips[i]._needsRemove) {
  11775. clips[i] = clips[len - 1];
  11776. clips.pop();
  11777. len--;
  11778. } else {
  11779. i++;
  11780. }
  11781. }
  11782. len = deferredEvents.length;
  11783. for (var i = 0; i < len; i++) {
  11784. deferredClips[i].fire(deferredEvents[i]);
  11785. }
  11786. this._time = time;
  11787. this.onframe(delta);
  11788. this.dispatch('frame', delta);
  11789. if (this.stage.update) {
  11790. this.stage.update();
  11791. }
  11792. },
  11793. start: function () {
  11794. var self = this;
  11795. this._running = true;
  11796. function step() {
  11797. if (self._running) {
  11798. requestAnimationFrame(step);
  11799. self._update();
  11800. }
  11801. }
  11802. this._time = new Date().getTime();
  11803. requestAnimationFrame(step);
  11804. },
  11805. stop: function () {
  11806. this._running = false;
  11807. },
  11808. clear: function () {
  11809. this._clips = [];
  11810. },
  11811. animate: function (target, options) {
  11812. options = options || {};
  11813. var deferred = new Animator(target, options.loop, options.getter, options.setter);
  11814. deferred.animation = this;
  11815. return deferred;
  11816. },
  11817. constructor: Animation
  11818. };
  11819. util.merge(Animation.prototype, Dispatcher.prototype, true);
  11820. function _defaultGetter(target, key) {
  11821. return target[key];
  11822. }
  11823. function _defaultSetter(target, key, value) {
  11824. target[key] = value;
  11825. }
  11826. function _interpolateNumber(p0, p1, percent) {
  11827. return (p1 - p0) * percent + p0;
  11828. }
  11829. function _interpolateArray(p0, p1, percent, out, arrDim) {
  11830. var len = p0.length;
  11831. if (arrDim == 1) {
  11832. for (var i = 0; i < len; i++) {
  11833. out[i] = _interpolateNumber(p0[i], p1[i], percent);
  11834. }
  11835. } else {
  11836. var len2 = p0[0].length;
  11837. for (var i = 0; i < len; i++) {
  11838. for (var j = 0; j < len2; j++) {
  11839. out[i][j] = _interpolateNumber(p0[i][j], p1[i][j], percent);
  11840. }
  11841. }
  11842. }
  11843. }
  11844. function _isArrayLike(data) {
  11845. switch (typeof data) {
  11846. case 'undefined':
  11847. case 'string':
  11848. return false;
  11849. }
  11850. return typeof data.length !== 'undefined';
  11851. }
  11852. function _catmullRomInterpolateArray(p0, p1, p2, p3, t, t2, t3, out, arrDim) {
  11853. var len = p0.length;
  11854. if (arrDim == 1) {
  11855. for (var i = 0; i < len; i++) {
  11856. out[i] = _catmullRomInterpolate(p0[i], p1[i], p2[i], p3[i], t, t2, t3);
  11857. }
  11858. } else {
  11859. var len2 = p0[0].length;
  11860. for (var i = 0; i < len; i++) {
  11861. for (var j = 0; j < len2; j++) {
  11862. out[i][j] = _catmullRomInterpolate(p0[i][j], p1[i][j], p2[i][j], p3[i][j], t, t2, t3);
  11863. }
  11864. }
  11865. }
  11866. }
  11867. function _catmullRomInterpolate(p0, p1, p2, p3, t, t2, t3) {
  11868. var v0 = (p2 - p0) * 0.5;
  11869. var v1 = (p3 - p1) * 0.5;
  11870. return (2 * (p1 - p2) + v0 + v1) * t3 + (-3 * (p1 - p2) - 2 * v0 - v1) * t2 + v0 * t + p1;
  11871. }
  11872. function _cloneValue(value) {
  11873. if (_isArrayLike(value)) {
  11874. var len = value.length;
  11875. if (_isArrayLike(value[0])) {
  11876. var ret = [];
  11877. for (var i = 0; i < len; i++) {
  11878. ret.push(arraySlice.call(value[i]));
  11879. }
  11880. return ret;
  11881. } else {
  11882. return arraySlice.call(value);
  11883. }
  11884. } else {
  11885. return value;
  11886. }
  11887. }
  11888. function rgba2String(rgba) {
  11889. rgba[0] = Math.floor(rgba[0]);
  11890. rgba[1] = Math.floor(rgba[1]);
  11891. rgba[2] = Math.floor(rgba[2]);
  11892. return 'rgba(' + rgba.join(',') + ')';
  11893. }
  11894. var Animator = function (target, loop, getter, setter) {
  11895. this._tracks = {};
  11896. this._target = target;
  11897. this._loop = loop || false;
  11898. this._getter = getter || _defaultGetter;
  11899. this._setter = setter || _defaultSetter;
  11900. this._clipCount = 0;
  11901. this._delay = 0;
  11902. this._doneList = [];
  11903. this._onframeList = [];
  11904. this._clipList = [];
  11905. };
  11906. Animator.prototype = {
  11907. when: function (time, props) {
  11908. for (var propName in props) {
  11909. if (!this._tracks[propName]) {
  11910. this._tracks[propName] = [];
  11911. if (time !== 0) {
  11912. this._tracks[propName].push({
  11913. time: 0,
  11914. value: _cloneValue(this._getter(this._target, propName))
  11915. });
  11916. }
  11917. }
  11918. this._tracks[propName].push({
  11919. time: parseInt(time, 10),
  11920. value: props[propName]
  11921. });
  11922. }
  11923. return this;
  11924. },
  11925. during: function (callback) {
  11926. this._onframeList.push(callback);
  11927. return this;
  11928. },
  11929. start: function (easing) {
  11930. var self = this;
  11931. var setter = this._setter;
  11932. var getter = this._getter;
  11933. var useSpline = easing === 'spline';
  11934. var ondestroy = function () {
  11935. self._clipCount--;
  11936. if (self._clipCount === 0) {
  11937. self._tracks = {};
  11938. var len = self._doneList.length;
  11939. for (var i = 0; i < len; i++) {
  11940. self._doneList[i].call(self);
  11941. }
  11942. }
  11943. };
  11944. var createTrackClip = function (keyframes, propName) {
  11945. var trackLen = keyframes.length;
  11946. if (!trackLen) {
  11947. return;
  11948. }
  11949. var firstVal = keyframes[0].value;
  11950. var isValueArray = _isArrayLike(firstVal);
  11951. var isValueColor = false;
  11952. var arrDim = isValueArray && _isArrayLike(firstVal[0]) ? 2 : 1;
  11953. keyframes.sort(function (a, b) {
  11954. return a.time - b.time;
  11955. });
  11956. var trackMaxTime;
  11957. if (trackLen) {
  11958. trackMaxTime = keyframes[trackLen - 1].time;
  11959. } else {
  11960. return;
  11961. }
  11962. var kfPercents = [];
  11963. var kfValues = [];
  11964. for (var i = 0; i < trackLen; i++) {
  11965. kfPercents.push(keyframes[i].time / trackMaxTime);
  11966. var value = keyframes[i].value;
  11967. if (typeof value == 'string') {
  11968. value = color.toArray(value);
  11969. if (value.length === 0) {
  11970. value[0] = value[1] = value[2] = 0;
  11971. value[3] = 1;
  11972. }
  11973. isValueColor = true;
  11974. }
  11975. kfValues.push(value);
  11976. }
  11977. var cacheKey = 0;
  11978. var cachePercent = 0;
  11979. var start;
  11980. var i;
  11981. var w;
  11982. var p0;
  11983. var p1;
  11984. var p2;
  11985. var p3;
  11986. if (isValueColor) {
  11987. var rgba = [
  11988. 0,
  11989. 0,
  11990. 0,
  11991. 0
  11992. ];
  11993. }
  11994. var onframe = function (target, percent) {
  11995. if (percent < cachePercent) {
  11996. start = Math.min(cacheKey + 1, trackLen - 1);
  11997. for (i = start; i >= 0; i--) {
  11998. if (kfPercents[i] <= percent) {
  11999. break;
  12000. }
  12001. }
  12002. i = Math.min(i, trackLen - 2);
  12003. } else {
  12004. for (i = cacheKey; i < trackLen; i++) {
  12005. if (kfPercents[i] > percent) {
  12006. break;
  12007. }
  12008. }
  12009. i = Math.min(i - 1, trackLen - 2);
  12010. }
  12011. cacheKey = i;
  12012. cachePercent = percent;
  12013. var range = kfPercents[i + 1] - kfPercents[i];
  12014. if (range === 0) {
  12015. return;
  12016. } else {
  12017. w = (percent - kfPercents[i]) / range;
  12018. }
  12019. if (useSpline) {
  12020. p1 = kfValues[i];
  12021. p0 = kfValues[i === 0 ? i : i - 1];
  12022. p2 = kfValues[i > trackLen - 2 ? trackLen - 1 : i + 1];
  12023. p3 = kfValues[i > trackLen - 3 ? trackLen - 1 : i + 2];
  12024. if (isValueArray) {
  12025. _catmullRomInterpolateArray(p0, p1, p2, p3, w, w * w, w * w * w, getter(target, propName), arrDim);
  12026. } else {
  12027. var value;
  12028. if (isValueColor) {
  12029. value = _catmullRomInterpolateArray(p0, p1, p2, p3, w, w * w, w * w * w, rgba, 1);
  12030. value = rgba2String(rgba);
  12031. } else {
  12032. value = _catmullRomInterpolate(p0, p1, p2, p3, w, w * w, w * w * w);
  12033. }
  12034. setter(target, propName, value);
  12035. }
  12036. } else {
  12037. if (isValueArray) {
  12038. _interpolateArray(kfValues[i], kfValues[i + 1], w, getter(target, propName), arrDim);
  12039. } else {
  12040. var value;
  12041. if (isValueColor) {
  12042. _interpolateArray(kfValues[i], kfValues[i + 1], w, rgba, 1);
  12043. value = rgba2String(rgba);
  12044. } else {
  12045. value = _interpolateNumber(kfValues[i], kfValues[i + 1], w);
  12046. }
  12047. setter(target, propName, value);
  12048. }
  12049. }
  12050. for (i = 0; i < self._onframeList.length; i++) {
  12051. self._onframeList[i](target, percent);
  12052. }
  12053. };
  12054. var clip = new Clip({
  12055. target: self._target,
  12056. life: trackMaxTime,
  12057. loop: self._loop,
  12058. delay: self._delay,
  12059. onframe: onframe,
  12060. ondestroy: ondestroy
  12061. });
  12062. if (easing && easing !== 'spline') {
  12063. clip.easing = easing;
  12064. }
  12065. self._clipList.push(clip);
  12066. self._clipCount++;
  12067. self.animation.add(clip);
  12068. };
  12069. for (var propName in this._tracks) {
  12070. createTrackClip(this._tracks[propName], propName);
  12071. }
  12072. return this;
  12073. },
  12074. stop: function () {
  12075. for (var i = 0; i < this._clipList.length; i++) {
  12076. var clip = this._clipList[i];
  12077. this.animation.remove(clip);
  12078. }
  12079. this._clipList = [];
  12080. },
  12081. delay: function (time) {
  12082. this._delay = time;
  12083. return this;
  12084. },
  12085. done: function (cb) {
  12086. if (cb) {
  12087. this._doneList.push(cb);
  12088. }
  12089. return this;
  12090. }
  12091. };
  12092. return Animation;
  12093. });define('zrender/tool/vector', [], function () {
  12094. var ArrayCtor = typeof Float32Array === 'undefined' ? Array : Float32Array;
  12095. var vector = {
  12096. create: function (x, y) {
  12097. var out = new ArrayCtor(2);
  12098. out[0] = x || 0;
  12099. out[1] = y || 0;
  12100. return out;
  12101. },
  12102. copy: function (out, v) {
  12103. out[0] = v[0];
  12104. out[1] = v[1];
  12105. return out;
  12106. },
  12107. clone: function (v) {
  12108. var out = new ArrayCtor(2);
  12109. out[0] = v[0];
  12110. out[1] = v[1];
  12111. return out;
  12112. },
  12113. set: function (out, a, b) {
  12114. out[0] = a;
  12115. out[1] = b;
  12116. return out;
  12117. },
  12118. add: function (out, v1, v2) {
  12119. out[0] = v1[0] + v2[0];
  12120. out[1] = v1[1] + v2[1];
  12121. return out;
  12122. },
  12123. scaleAndAdd: function (out, v1, v2, a) {
  12124. out[0] = v1[0] + v2[0] * a;
  12125. out[1] = v1[1] + v2[1] * a;
  12126. return out;
  12127. },
  12128. sub: function (out, v1, v2) {
  12129. out[0] = v1[0] - v2[0];
  12130. out[1] = v1[1] - v2[1];
  12131. return out;
  12132. },
  12133. len: function (v) {
  12134. return Math.sqrt(this.lenSquare(v));
  12135. },
  12136. lenSquare: function (v) {
  12137. return v[0] * v[0] + v[1] * v[1];
  12138. },
  12139. mul: function (out, v1, v2) {
  12140. out[0] = v1[0] * v2[0];
  12141. out[1] = v1[1] * v2[1];
  12142. return out;
  12143. },
  12144. div: function (out, v1, v2) {
  12145. out[0] = v1[0] / v2[0];
  12146. out[1] = v1[1] / v2[1];
  12147. return out;
  12148. },
  12149. dot: function (v1, v2) {
  12150. return v1[0] * v2[0] + v1[1] * v2[1];
  12151. },
  12152. scale: function (out, v, s) {
  12153. out[0] = v[0] * s;
  12154. out[1] = v[1] * s;
  12155. return out;
  12156. },
  12157. normalize: function (out, v) {
  12158. var d = vector.len(v);
  12159. if (d === 0) {
  12160. out[0] = 0;
  12161. out[1] = 0;
  12162. } else {
  12163. out[0] = v[0] / d;
  12164. out[1] = v[1] / d;
  12165. }
  12166. return out;
  12167. },
  12168. distance: function (v1, v2) {
  12169. return Math.sqrt((v1[0] - v2[0]) * (v1[0] - v2[0]) + (v1[1] - v2[1]) * (v1[1] - v2[1]));
  12170. },
  12171. distanceSquare: function (v1, v2) {
  12172. return (v1[0] - v2[0]) * (v1[0] - v2[0]) + (v1[1] - v2[1]) * (v1[1] - v2[1]);
  12173. },
  12174. negate: function (out, v) {
  12175. out[0] = -v[0];
  12176. out[1] = -v[1];
  12177. return out;
  12178. },
  12179. lerp: function (out, v1, v2, t) {
  12180. out[0] = v1[0] + t * (v2[0] - v1[0]);
  12181. out[1] = v1[1] + t * (v2[1] - v1[1]);
  12182. return out;
  12183. },
  12184. applyTransform: function (out, v, m) {
  12185. var x = v[0];
  12186. var y = v[1];
  12187. out[0] = m[0] * x + m[2] * y + m[4];
  12188. out[1] = m[1] * x + m[3] * y + m[5];
  12189. return out;
  12190. },
  12191. min: function (out, v1, v2) {
  12192. out[0] = Math.min(v1[0], v2[0]);
  12193. out[1] = Math.min(v1[1], v2[1]);
  12194. return out;
  12195. },
  12196. max: function (out, v1, v2) {
  12197. out[0] = Math.max(v1[0], v2[0]);
  12198. out[1] = Math.max(v1[1], v2[1]);
  12199. return out;
  12200. }
  12201. };
  12202. vector.length = vector.len;
  12203. vector.lengthSquare = vector.lenSquare;
  12204. vector.dist = vector.distance;
  12205. vector.distSquare = vector.distanceSquare;
  12206. return vector;
  12207. });define('zrender/tool/matrix', [], function () {
  12208. var ArrayCtor = typeof Float32Array === 'undefined' ? Array : Float32Array;
  12209. var matrix = {
  12210. create: function () {
  12211. var out = new ArrayCtor(6);
  12212. matrix.identity(out);
  12213. return out;
  12214. },
  12215. identity: function (out) {
  12216. out[0] = 1;
  12217. out[1] = 0;
  12218. out[2] = 0;
  12219. out[3] = 1;
  12220. out[4] = 0;
  12221. out[5] = 0;
  12222. return out;
  12223. },
  12224. copy: function (out, m) {
  12225. out[0] = m[0];
  12226. out[1] = m[1];
  12227. out[2] = m[2];
  12228. out[3] = m[3];
  12229. out[4] = m[4];
  12230. out[5] = m[5];
  12231. return out;
  12232. },
  12233. mul: function (out, m1, m2) {
  12234. out[0] = m1[0] * m2[0] + m1[2] * m2[1];
  12235. out[1] = m1[1] * m2[0] + m1[3] * m2[1];
  12236. out[2] = m1[0] * m2[2] + m1[2] * m2[3];
  12237. out[3] = m1[1] * m2[2] + m1[3] * m2[3];
  12238. out[4] = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  12239. out[5] = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  12240. return out;
  12241. },
  12242. translate: function (out, a, v) {
  12243. out[0] = a[0];
  12244. out[1] = a[1];
  12245. out[2] = a[2];
  12246. out[3] = a[3];
  12247. out[4] = a[4] + v[0];
  12248. out[5] = a[5] + v[1];
  12249. return out;
  12250. },
  12251. rotate: function (out, a, rad) {
  12252. var aa = a[0];
  12253. var ac = a[2];
  12254. var atx = a[4];
  12255. var ab = a[1];
  12256. var ad = a[3];
  12257. var aty = a[5];
  12258. var st = Math.sin(rad);
  12259. var ct = Math.cos(rad);
  12260. out[0] = aa * ct + ab * st;
  12261. out[1] = -aa * st + ab * ct;
  12262. out[2] = ac * ct + ad * st;
  12263. out[3] = -ac * st + ct * ad;
  12264. out[4] = ct * atx + st * aty;
  12265. out[5] = ct * aty - st * atx;
  12266. return out;
  12267. },
  12268. scale: function (out, a, v) {
  12269. var vx = v[0];
  12270. var vy = v[1];
  12271. out[0] = a[0] * vx;
  12272. out[1] = a[1] * vy;
  12273. out[2] = a[2] * vx;
  12274. out[3] = a[3] * vy;
  12275. out[4] = a[4] * vx;
  12276. out[5] = a[5] * vy;
  12277. return out;
  12278. },
  12279. invert: function (out, a) {
  12280. var aa = a[0];
  12281. var ac = a[2];
  12282. var atx = a[4];
  12283. var ab = a[1];
  12284. var ad = a[3];
  12285. var aty = a[5];
  12286. var det = aa * ad - ab * ac;
  12287. if (!det) {
  12288. return null;
  12289. }
  12290. det = 1 / det;
  12291. out[0] = ad * det;
  12292. out[1] = -ab * det;
  12293. out[2] = -ac * det;
  12294. out[3] = aa * det;
  12295. out[4] = (ac * aty - ad * atx) * det;
  12296. out[5] = (ab * atx - aa * aty) * det;
  12297. return out;
  12298. },
  12299. mulVector: function (out, a, v) {
  12300. var aa = a[0];
  12301. var ac = a[2];
  12302. var atx = a[4];
  12303. var ab = a[1];
  12304. var ad = a[3];
  12305. var aty = a[5];
  12306. out[0] = v[0] * aa + v[1] * ac + atx;
  12307. out[1] = v[0] * ab + v[1] * ad + aty;
  12308. return out;
  12309. }
  12310. };
  12311. return matrix;
  12312. });define('zrender/loadingEffect/Base', [
  12313. 'require',
  12314. '../tool/util',
  12315. '../shape/Text',
  12316. '../shape/Rectangle'
  12317. ], function (require) {
  12318. var util = require('../tool/util');
  12319. var TextShape = require('../shape/Text');
  12320. var RectangleShape = require('../shape/Rectangle');
  12321. var DEFAULT_TEXT = 'Loading...';
  12322. var DEFAULT_TEXT_FONT = 'normal 16px Arial';
  12323. function Base(options) {
  12324. this.setOptions(options);
  12325. }
  12326. Base.prototype.createTextShape = function (textStyle) {
  12327. return new TextShape({
  12328. highlightStyle: util.merge({
  12329. x: this.canvasWidth / 2,
  12330. y: this.canvasHeight / 2,
  12331. text: DEFAULT_TEXT,
  12332. textAlign: 'center',
  12333. textBaseline: 'middle',
  12334. textFont: DEFAULT_TEXT_FONT,
  12335. color: '#333',
  12336. brushType: 'fill'
  12337. }, textStyle, true)
  12338. });
  12339. };
  12340. Base.prototype.createBackgroundShape = function (color) {
  12341. return new RectangleShape({
  12342. highlightStyle: {
  12343. x: 0,
  12344. y: 0,
  12345. width: this.canvasWidth,
  12346. height: this.canvasHeight,
  12347. brushType: 'fill',
  12348. color: color
  12349. }
  12350. });
  12351. };
  12352. Base.prototype.start = function (painter) {
  12353. this.canvasWidth = painter._width;
  12354. this.canvasHeight = painter._height;
  12355. function addShapeHandle(param) {
  12356. painter.storage.addHover(param);
  12357. }
  12358. function refreshHandle() {
  12359. painter.refreshHover();
  12360. }
  12361. this.loadingTimer = this._start(addShapeHandle, refreshHandle);
  12362. };
  12363. Base.prototype._start = function () {
  12364. return setInterval(function () {
  12365. }, 10000);
  12366. };
  12367. Base.prototype.stop = function () {
  12368. clearInterval(this.loadingTimer);
  12369. };
  12370. Base.prototype.setOptions = function (options) {
  12371. this.options = options || {};
  12372. };
  12373. Base.prototype.adjust = function (value, region) {
  12374. if (value <= region[0]) {
  12375. value = region[0];
  12376. } else if (value >= region[1]) {
  12377. value = region[1];
  12378. }
  12379. return value;
  12380. };
  12381. Base.prototype.getLocation = function (loc, totalWidth, totalHeight) {
  12382. var x = loc.x != null ? loc.x : 'center';
  12383. switch (x) {
  12384. case 'center':
  12385. x = Math.floor((this.canvasWidth - totalWidth) / 2);
  12386. break;
  12387. case 'left':
  12388. x = 0;
  12389. break;
  12390. case 'right':
  12391. x = this.canvasWidth - totalWidth;
  12392. break;
  12393. }
  12394. var y = loc.y != null ? loc.y : 'center';
  12395. switch (y) {
  12396. case 'center':
  12397. y = Math.floor((this.canvasHeight - totalHeight) / 2);
  12398. break;
  12399. case 'top':
  12400. y = 0;
  12401. break;
  12402. case 'bottom':
  12403. y = this.canvasHeight - totalHeight;
  12404. break;
  12405. }
  12406. return {
  12407. x: x,
  12408. y: y,
  12409. width: totalWidth,
  12410. height: totalHeight
  12411. };
  12412. };
  12413. return Base;
  12414. });define('zrender/Layer', [
  12415. 'require',
  12416. './mixin/Transformable',
  12417. './tool/util',
  12418. './config'
  12419. ], function (require) {
  12420. var Transformable = require('./mixin/Transformable');
  12421. var util = require('./tool/util');
  12422. var vmlCanvasManager = window['G_vmlCanvasManager'];
  12423. var config = require('./config');
  12424. function returnFalse() {
  12425. return false;
  12426. }
  12427. function createDom(id, type, painter) {
  12428. var newDom = document.createElement(type);
  12429. var width = painter.getWidth();
  12430. var height = painter.getHeight();
  12431. newDom.style.position = 'absolute';
  12432. newDom.style.left = 0;
  12433. newDom.style.top = 0;
  12434. newDom.style.width = width + 'px';
  12435. newDom.style.height = height + 'px';
  12436. newDom.width = width * config.devicePixelRatio;
  12437. newDom.height = height * config.devicePixelRatio;
  12438. newDom.setAttribute('data-zr-dom-id', id);
  12439. return newDom;
  12440. }
  12441. var Layer = function (id, painter) {
  12442. this.id = id;
  12443. this.dom = createDom(id, 'canvas', painter);
  12444. this.dom.onselectstart = returnFalse;
  12445. this.dom.style['-webkit-user-select'] = 'none';
  12446. this.dom.style['user-select'] = 'none';
  12447. this.dom.style['-webkit-touch-callout'] = 'none';
  12448. this.dom.style['-webkit-tap-highlight-color'] = 'rgba(0,0,0,0)';
  12449. vmlCanvasManager && vmlCanvasManager.initElement(this.dom);
  12450. this.domBack = null;
  12451. this.ctxBack = null;
  12452. this.painter = painter;
  12453. this.unusedCount = 0;
  12454. this.config = null;
  12455. this.dirty = true;
  12456. this.elCount = 0;
  12457. this.clearColor = 0;
  12458. this.motionBlur = false;
  12459. this.lastFrameAlpha = 0.7;
  12460. this.zoomable = false;
  12461. this.panable = false;
  12462. this.maxZoom = Infinity;
  12463. this.minZoom = 0;
  12464. Transformable.call(this);
  12465. };
  12466. Layer.prototype.initContext = function () {
  12467. this.ctx = this.dom.getContext('2d');
  12468. var dpr = config.devicePixelRatio;
  12469. if (dpr != 1) {
  12470. this.ctx.scale(dpr, dpr);
  12471. }
  12472. };
  12473. Layer.prototype.createBackBuffer = function () {
  12474. if (vmlCanvasManager) {
  12475. return;
  12476. }
  12477. this.domBack = createDom('back-' + this.id, 'canvas', this.painter);
  12478. this.ctxBack = this.domBack.getContext('2d');
  12479. var dpr = config.devicePixelRatio;
  12480. if (dpr != 1) {
  12481. this.ctxBack.scale(dpr, dpr);
  12482. }
  12483. };
  12484. Layer.prototype.resize = function (width, height) {
  12485. var dpr = config.devicePixelRatio;
  12486. this.dom.style.width = width + 'px';
  12487. this.dom.style.height = height + 'px';
  12488. this.dom.setAttribute('width', width * dpr);
  12489. this.dom.setAttribute('height', height * dpr);
  12490. if (dpr != 1) {
  12491. this.ctx.scale(dpr, dpr);
  12492. }
  12493. if (this.domBack) {
  12494. this.domBack.setAttribute('width', width * dpr);
  12495. this.domBack.setAttribute('height', height * dpr);
  12496. if (dpr != 1) {
  12497. this.ctxBack.scale(dpr, dpr);
  12498. }
  12499. }
  12500. };
  12501. Layer.prototype.clear = function () {
  12502. var dom = this.dom;
  12503. var ctx = this.ctx;
  12504. var width = dom.width;
  12505. var height = dom.height;
  12506. var haveClearColor = this.clearColor && !vmlCanvasManager;
  12507. var haveMotionBLur = this.motionBlur && !vmlCanvasManager;
  12508. var lastFrameAlpha = this.lastFrameAlpha;
  12509. var dpr = config.devicePixelRatio;
  12510. if (haveMotionBLur) {
  12511. if (!this.domBack) {
  12512. this.createBackBuffer();
  12513. }
  12514. this.ctxBack.globalCompositeOperation = 'copy';
  12515. this.ctxBack.drawImage(dom, 0, 0, width / dpr, height / dpr);
  12516. }
  12517. ctx.clearRect(0, 0, width / dpr, height / dpr);
  12518. if (haveClearColor) {
  12519. ctx.save();
  12520. ctx.fillStyle = this.clearColor;
  12521. ctx.fillRect(0, 0, width / dpr, height / dpr);
  12522. ctx.restore();
  12523. }
  12524. if (haveMotionBLur) {
  12525. var domBack = this.domBack;
  12526. ctx.save();
  12527. ctx.globalAlpha = lastFrameAlpha;
  12528. ctx.drawImage(domBack, 0, 0, width / dpr, height / dpr);
  12529. ctx.restore();
  12530. }
  12531. };
  12532. util.merge(Layer.prototype, Transformable.prototype);
  12533. return Layer;
  12534. });define('zrender/shape/Text', [
  12535. 'require',
  12536. '../tool/area',
  12537. './Base',
  12538. '../tool/util'
  12539. ], function (require) {
  12540. var area = require('../tool/area');
  12541. var Base = require('./Base');
  12542. var Text = function (options) {
  12543. Base.call(this, options);
  12544. };
  12545. Text.prototype = {
  12546. type: 'text',
  12547. brush: function (ctx, isHighlight) {
  12548. var style = this.style;
  12549. if (isHighlight) {
  12550. style = this.getHighlightStyle(style, this.highlightStyle || {});
  12551. }
  12552. if (typeof style.text == 'undefined' || style.text === false) {
  12553. return;
  12554. }
  12555. ctx.save();
  12556. this.doClip(ctx);
  12557. this.setContext(ctx, style);
  12558. this.setTransform(ctx);
  12559. if (style.textFont) {
  12560. ctx.font = style.textFont;
  12561. }
  12562. ctx.textAlign = style.textAlign || 'start';
  12563. ctx.textBaseline = style.textBaseline || 'middle';
  12564. var text = (style.text + '').split('\n');
  12565. var lineHeight = area.getTextHeight('国', style.textFont);
  12566. var rect = this.getRect(style);
  12567. var x = style.x;
  12568. var y;
  12569. if (style.textBaseline == 'top') {
  12570. y = rect.y;
  12571. } else if (style.textBaseline == 'bottom') {
  12572. y = rect.y + lineHeight;
  12573. } else {
  12574. y = rect.y + lineHeight / 2;
  12575. }
  12576. for (var i = 0, l = text.length; i < l; i++) {
  12577. if (style.maxWidth) {
  12578. switch (style.brushType) {
  12579. case 'fill':
  12580. ctx.fillText(text[i], x, y, style.maxWidth);
  12581. break;
  12582. case 'stroke':
  12583. ctx.strokeText(text[i], x, y, style.maxWidth);
  12584. break;
  12585. case 'both':
  12586. ctx.fillText(text[i], x, y, style.maxWidth);
  12587. ctx.strokeText(text[i], x, y, style.maxWidth);
  12588. break;
  12589. default:
  12590. ctx.fillText(text[i], x, y, style.maxWidth);
  12591. }
  12592. } else {
  12593. switch (style.brushType) {
  12594. case 'fill':
  12595. ctx.fillText(text[i], x, y);
  12596. break;
  12597. case 'stroke':
  12598. ctx.strokeText(text[i], x, y);
  12599. break;
  12600. case 'both':
  12601. ctx.fillText(text[i], x, y);
  12602. ctx.strokeText(text[i], x, y);
  12603. break;
  12604. default:
  12605. ctx.fillText(text[i], x, y);
  12606. }
  12607. }
  12608. y += lineHeight;
  12609. }
  12610. ctx.restore();
  12611. return;
  12612. },
  12613. getRect: function (style) {
  12614. if (style.__rect) {
  12615. return style.__rect;
  12616. }
  12617. var width = area.getTextWidth(style.text, style.textFont);
  12618. var height = area.getTextHeight(style.text, style.textFont);
  12619. var textX = style.x;
  12620. if (style.textAlign == 'end' || style.textAlign == 'right') {
  12621. textX -= width;
  12622. } else if (style.textAlign == 'center') {
  12623. textX -= width / 2;
  12624. }
  12625. var textY;
  12626. if (style.textBaseline == 'top') {
  12627. textY = style.y;
  12628. } else if (style.textBaseline == 'bottom') {
  12629. textY = style.y - height;
  12630. } else {
  12631. textY = style.y - height / 2;
  12632. }
  12633. style.__rect = {
  12634. x: textX,
  12635. y: textY,
  12636. width: width,
  12637. height: height
  12638. };
  12639. return style.__rect;
  12640. }
  12641. };
  12642. require('../tool/util').inherits(Text, Base);
  12643. return Text;
  12644. });define('zrender/shape/Rectangle', [
  12645. 'require',
  12646. './Base',
  12647. '../tool/util'
  12648. ], function (require) {
  12649. var Base = require('./Base');
  12650. var Rectangle = function (options) {
  12651. Base.call(this, options);
  12652. };
  12653. Rectangle.prototype = {
  12654. type: 'rectangle',
  12655. _buildRadiusPath: function (ctx, style) {
  12656. var x = style.x;
  12657. var y = style.y;
  12658. var width = style.width;
  12659. var height = style.height;
  12660. var r = style.radius;
  12661. var r1;
  12662. var r2;
  12663. var r3;
  12664. var r4;
  12665. if (typeof r === 'number') {
  12666. r1 = r2 = r3 = r4 = r;
  12667. } else if (r instanceof Array) {
  12668. if (r.length === 1) {
  12669. r1 = r2 = r3 = r4 = r[0];
  12670. } else if (r.length === 2) {
  12671. r1 = r3 = r[0];
  12672. r2 = r4 = r[1];
  12673. } else if (r.length === 3) {
  12674. r1 = r[0];
  12675. r2 = r4 = r[1];
  12676. r3 = r[2];
  12677. } else {
  12678. r1 = r[0];
  12679. r2 = r[1];
  12680. r3 = r[2];
  12681. r4 = r[3];
  12682. }
  12683. } else {
  12684. r1 = r2 = r3 = r4 = 0;
  12685. }
  12686. var total;
  12687. if (r1 + r2 > width) {
  12688. total = r1 + r2;
  12689. r1 *= width / total;
  12690. r2 *= width / total;
  12691. }
  12692. if (r3 + r4 > width) {
  12693. total = r3 + r4;
  12694. r3 *= width / total;
  12695. r4 *= width / total;
  12696. }
  12697. if (r2 + r3 > height) {
  12698. total = r2 + r3;
  12699. r2 *= height / total;
  12700. r3 *= height / total;
  12701. }
  12702. if (r1 + r4 > height) {
  12703. total = r1 + r4;
  12704. r1 *= height / total;
  12705. r4 *= height / total;
  12706. }
  12707. ctx.moveTo(x + r1, y);
  12708. ctx.lineTo(x + width - r2, y);
  12709. r2 !== 0 && ctx.quadraticCurveTo(x + width, y, x + width, y + r2);
  12710. ctx.lineTo(x + width, y + height - r3);
  12711. r3 !== 0 && ctx.quadraticCurveTo(x + width, y + height, x + width - r3, y + height);
  12712. ctx.lineTo(x + r4, y + height);
  12713. r4 !== 0 && ctx.quadraticCurveTo(x, y + height, x, y + height - r4);
  12714. ctx.lineTo(x, y + r1);
  12715. r1 !== 0 && ctx.quadraticCurveTo(x, y, x + r1, y);
  12716. },
  12717. buildPath: function (ctx, style) {
  12718. if (!style.radius) {
  12719. ctx.moveTo(style.x, style.y);
  12720. ctx.lineTo(style.x + style.width, style.y);
  12721. ctx.lineTo(style.x + style.width, style.y + style.height);
  12722. ctx.lineTo(style.x, style.y + style.height);
  12723. ctx.lineTo(style.x, style.y);
  12724. } else {
  12725. this._buildRadiusPath(ctx, style);
  12726. }
  12727. ctx.closePath();
  12728. return;
  12729. },
  12730. getRect: function (style) {
  12731. if (style.__rect) {
  12732. return style.__rect;
  12733. }
  12734. var lineWidth;
  12735. if (style.brushType == 'stroke' || style.brushType == 'fill') {
  12736. lineWidth = style.lineWidth || 1;
  12737. } else {
  12738. lineWidth = 0;
  12739. }
  12740. style.__rect = {
  12741. x: Math.round(style.x - lineWidth / 2),
  12742. y: Math.round(style.y - lineWidth / 2),
  12743. width: style.width + lineWidth,
  12744. height: style.height + lineWidth
  12745. };
  12746. return style.__rect;
  12747. }
  12748. };
  12749. require('../tool/util').inherits(Rectangle, Base);
  12750. return Rectangle;
  12751. });define('zrender/tool/area', [
  12752. 'require',
  12753. './util',
  12754. './curve'
  12755. ], function (require) {
  12756. 'use strict';
  12757. var util = require('./util');
  12758. var curve = require('./curve');
  12759. var _ctx;
  12760. var _textWidthCache = {};
  12761. var _textHeightCache = {};
  12762. var _textWidthCacheCounter = 0;
  12763. var _textHeightCacheCounter = 0;
  12764. var TEXT_CACHE_MAX = 5000;
  12765. var PI2 = Math.PI * 2;
  12766. function normalizeRadian(angle) {
  12767. angle %= PI2;
  12768. if (angle < 0) {
  12769. angle += PI2;
  12770. }
  12771. return angle;
  12772. }
  12773. function isInside(shape, area, x, y) {
  12774. if (!area || !shape) {
  12775. return false;
  12776. }
  12777. var zoneType = shape.type;
  12778. _ctx = _ctx || util.getContext();
  12779. var _mathReturn = _mathMethod(shape, area, x, y);
  12780. if (typeof _mathReturn != 'undefined') {
  12781. return _mathReturn;
  12782. }
  12783. if (shape.buildPath && _ctx.isPointInPath) {
  12784. return _buildPathMethod(shape, _ctx, area, x, y);
  12785. }
  12786. switch (zoneType) {
  12787. case 'ellipse':
  12788. return true;
  12789. case 'trochoid':
  12790. var _r = area.location == 'out' ? area.r1 + area.r2 + area.d : area.r1 - area.r2 + area.d;
  12791. return isInsideCircle(area, x, y, _r);
  12792. case 'rose':
  12793. return isInsideCircle(area, x, y, area.maxr);
  12794. default:
  12795. return false;
  12796. }
  12797. }
  12798. function _mathMethod(shape, area, x, y) {
  12799. var zoneType = shape.type;
  12800. switch (zoneType) {
  12801. case 'bezier-curve':
  12802. if (typeof area.cpX2 === 'undefined') {
  12803. return isInsideQuadraticStroke(area.xStart, area.yStart, area.cpX1, area.cpY1, area.xEnd, area.yEnd, area.lineWidth, x, y);
  12804. }
  12805. return isInsideCubicStroke(area.xStart, area.yStart, area.cpX1, area.cpY1, area.cpX2, area.cpY2, area.xEnd, area.yEnd, area.lineWidth, x, y);
  12806. case 'line':
  12807. return isInsideLine(area.xStart, area.yStart, area.xEnd, area.yEnd, area.lineWidth, x, y);
  12808. case 'polyline':
  12809. return isInsidePolyline(area.pointList, area.lineWidth, x, y);
  12810. case 'ring':
  12811. return isInsideRing(area.x, area.y, area.r0, area.r, x, y);
  12812. case 'circle':
  12813. return isInsideCircle(area.x, area.y, area.r, x, y);
  12814. case 'sector':
  12815. var startAngle = area.startAngle * Math.PI / 180;
  12816. var endAngle = area.endAngle * Math.PI / 180;
  12817. if (!area.clockWise) {
  12818. startAngle = -startAngle;
  12819. endAngle = -endAngle;
  12820. }
  12821. return isInsideSector(area.x, area.y, area.r0, area.r, startAngle, endAngle, !area.clockWise, x, y);
  12822. case 'path':
  12823. return area.pathArray && isInsidePath(area.pathArray, Math.max(area.lineWidth, 5), area.brushType, x, y);
  12824. case 'polygon':
  12825. case 'star':
  12826. case 'isogon':
  12827. return isInsidePolygon(area.pointList, x, y);
  12828. case 'text':
  12829. var rect = area.__rect || shape.getRect(area);
  12830. return isInsideRect(rect.x, rect.y, rect.width, rect.height, x, y);
  12831. case 'rectangle':
  12832. case 'image':
  12833. return isInsideRect(area.x, area.y, area.width, area.height, x, y);
  12834. }
  12835. }
  12836. function _buildPathMethod(shape, context, area, x, y) {
  12837. context.beginPath();
  12838. shape.buildPath(context, area);
  12839. context.closePath();
  12840. return context.isPointInPath(x, y);
  12841. }
  12842. function isOutside(shape, area, x, y) {
  12843. return !isInside(shape, area, x, y);
  12844. }
  12845. function isInsideLine(x0, y0, x1, y1, lineWidth, x, y) {
  12846. if (lineWidth === 0) {
  12847. return false;
  12848. }
  12849. var _l = Math.max(lineWidth, 5);
  12850. var _a = 0;
  12851. var _b = x0;
  12852. 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) {
  12853. return false;
  12854. }
  12855. if (x0 !== x1) {
  12856. _a = (y0 - y1) / (x0 - x1);
  12857. _b = (x0 * y1 - x1 * y0) / (x0 - x1);
  12858. } else {
  12859. return Math.abs(x - x0) <= _l / 2;
  12860. }
  12861. var tmp = _a * x - y + _b;
  12862. var _s = tmp * tmp / (_a * _a + 1);
  12863. return _s <= _l / 2 * _l / 2;
  12864. }
  12865. function isInsideCubicStroke(x0, y0, x1, y1, x2, y2, x3, y3, lineWidth, x, y) {
  12866. if (lineWidth === 0) {
  12867. return false;
  12868. }
  12869. var _l = Math.max(lineWidth, 5);
  12870. 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) {
  12871. return false;
  12872. }
  12873. var d = curve.cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, null);
  12874. return d <= _l / 2;
  12875. }
  12876. function isInsideQuadraticStroke(x0, y0, x1, y1, x2, y2, lineWidth, x, y) {
  12877. if (lineWidth === 0) {
  12878. return false;
  12879. }
  12880. var _l = Math.max(lineWidth, 5);
  12881. 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) {
  12882. return false;
  12883. }
  12884. var d = curve.quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, null);
  12885. return d <= _l / 2;
  12886. }
  12887. function isInsideArcStroke(cx, cy, r, startAngle, endAngle, anticlockwise, lineWidth, x, y) {
  12888. if (lineWidth === 0) {
  12889. return false;
  12890. }
  12891. var _l = Math.max(lineWidth, 5);
  12892. x -= cx;
  12893. y -= cy;
  12894. var d = Math.sqrt(x * x + y * y);
  12895. if (d - _l > r || d + _l < r) {
  12896. return false;
  12897. }
  12898. if (Math.abs(startAngle - endAngle) >= PI2) {
  12899. return true;
  12900. }
  12901. if (anticlockwise) {
  12902. var tmp = startAngle;
  12903. startAngle = normalizeRadian(endAngle);
  12904. endAngle = normalizeRadian(tmp);
  12905. } else {
  12906. startAngle = normalizeRadian(startAngle);
  12907. endAngle = normalizeRadian(endAngle);
  12908. }
  12909. if (startAngle > endAngle) {
  12910. endAngle += PI2;
  12911. }
  12912. var angle = Math.atan2(y, x);
  12913. if (angle < 0) {
  12914. angle += PI2;
  12915. }
  12916. return angle >= startAngle && angle <= endAngle || angle + PI2 >= startAngle && angle + PI2 <= endAngle;
  12917. }
  12918. function isInsidePolyline(points, lineWidth, x, y) {
  12919. var lineWidth = Math.max(lineWidth, 10);
  12920. for (var i = 0, l = points.length - 1; i < l; i++) {
  12921. var x0 = points[i][0];
  12922. var y0 = points[i][1];
  12923. var x1 = points[i + 1][0];
  12924. var y1 = points[i + 1][1];
  12925. if (isInsideLine(x0, y0, x1, y1, lineWidth, x, y)) {
  12926. return true;
  12927. }
  12928. }
  12929. return false;
  12930. }
  12931. function isInsideRing(cx, cy, r0, r, x, y) {
  12932. var d = (x - cx) * (x - cx) + (y - cy) * (y - cy);
  12933. return d < r * r && d > r0 * r0;
  12934. }
  12935. function isInsideRect(x0, y0, width, height, x, y) {
  12936. return x >= x0 && x <= x0 + width && y >= y0 && y <= y0 + height;
  12937. }
  12938. function isInsideCircle(x0, y0, r, x, y) {
  12939. return (x - x0) * (x - x0) + (y - y0) * (y - y0) < r * r;
  12940. }
  12941. function isInsideSector(cx, cy, r0, r, startAngle, endAngle, anticlockwise, x, y) {
  12942. return isInsideArcStroke(cx, cy, (r0 + r) / 2, startAngle, endAngle, anticlockwise, r - r0, x, y);
  12943. }
  12944. function isInsidePolygon(points, x, y) {
  12945. var N = points.length;
  12946. var w = 0;
  12947. for (var i = 0, j = N - 1; i < N; i++) {
  12948. var x0 = points[j][0];
  12949. var y0 = points[j][1];
  12950. var x1 = points[i][0];
  12951. var y1 = points[i][1];
  12952. w += windingLine(x0, y0, x1, y1, x, y);
  12953. j = i;
  12954. }
  12955. return w !== 0;
  12956. }
  12957. function windingLine(x0, y0, x1, y1, x, y) {
  12958. if (y > y0 && y > y1 || y < y0 && y < y1) {
  12959. return 0;
  12960. }
  12961. if (y1 == y0) {
  12962. return 0;
  12963. }
  12964. var dir = y1 < y0 ? 1 : -1;
  12965. var t = (y - y0) / (y1 - y0);
  12966. var x_ = t * (x1 - x0) + x0;
  12967. return x_ > x ? dir : 0;
  12968. }
  12969. var roots = [
  12970. -1,
  12971. -1,
  12972. -1
  12973. ];
  12974. var extrema = [
  12975. -1,
  12976. -1
  12977. ];
  12978. function swapExtrema() {
  12979. var tmp = extrema[0];
  12980. extrema[0] = extrema[1];
  12981. extrema[1] = tmp;
  12982. }
  12983. function windingCubic(x0, y0, x1, y1, x2, y2, x3, y3, x, y) {
  12984. if (y > y0 && y > y1 && y > y2 && y > y3 || y < y0 && y < y1 && y < y2 && y < y3) {
  12985. return 0;
  12986. }
  12987. var nRoots = curve.cubicRootAt(y0, y1, y2, y3, y, roots);
  12988. if (nRoots === 0) {
  12989. return 0;
  12990. } else {
  12991. var w = 0;
  12992. var nExtrema = -1;
  12993. var y0_, y1_;
  12994. for (var i = 0; i < nRoots; i++) {
  12995. var t = roots[i];
  12996. var x_ = curve.cubicAt(x0, x1, x2, x3, t);
  12997. if (x_ < x) {
  12998. continue;
  12999. }
  13000. if (nExtrema < 0) {
  13001. nExtrema = curve.cubicExtrema(y0, y1, y2, y3, extrema);
  13002. if (extrema[1] < extrema[0] && nExtrema > 1) {
  13003. swapExtrema();
  13004. }
  13005. y0_ = curve.cubicAt(y0, y1, y2, y3, extrema[0]);
  13006. if (nExtrema > 1) {
  13007. y1_ = curve.cubicAt(y0, y1, y2, y3, extrema[1]);
  13008. }
  13009. }
  13010. if (nExtrema == 2) {
  13011. if (t < extrema[0]) {
  13012. w += y0_ < y0 ? 1 : -1;
  13013. } else if (t < extrema[1]) {
  13014. w += y1_ < y0_ ? 1 : -1;
  13015. } else {
  13016. w += y3 < y1_ ? 1 : -1;
  13017. }
  13018. } else {
  13019. if (t < extrema[0]) {
  13020. w += y0_ < y0 ? 1 : -1;
  13021. } else {
  13022. w += y3 < y0_ ? 1 : -1;
  13023. }
  13024. }
  13025. }
  13026. return w;
  13027. }
  13028. }
  13029. function windingQuadratic(x0, y0, x1, y1, x2, y2, x, y) {
  13030. if (y > y0 && y > y1 && y > y2 || y < y0 && y < y1 && y < y2) {
  13031. return 0;
  13032. }
  13033. var nRoots = curve.quadraticRootAt(y0, y1, y2, y, roots);
  13034. if (nRoots === 0) {
  13035. return 0;
  13036. } else {
  13037. var t = curve.quadraticExtremum(y0, y1, y2);
  13038. if (t >= 0 && t <= 1) {
  13039. var w = 0;
  13040. var y_ = curve.quadraticAt(y0, y1, y2, t);
  13041. for (var i = 0; i < nRoots; i++) {
  13042. var x_ = curve.quadraticAt(x0, x1, x2, roots[i]);
  13043. if (x_ < x) {
  13044. continue;
  13045. }
  13046. if (roots[i] < t) {
  13047. w += y_ < y0 ? 1 : -1;
  13048. } else {
  13049. w += y2 < y_ ? 1 : -1;
  13050. }
  13051. }
  13052. return w;
  13053. } else {
  13054. var x_ = curve.quadraticAt(x0, x1, x2, roots[0]);
  13055. if (x_ < x) {
  13056. return 0;
  13057. }
  13058. return y2 < y0 ? 1 : -1;
  13059. }
  13060. }
  13061. }
  13062. function windingArc(cx, cy, r, startAngle, endAngle, anticlockwise, x, y) {
  13063. y -= cy;
  13064. if (y > r || y < -r) {
  13065. return 0;
  13066. }
  13067. var tmp = Math.sqrt(r * r - y * y);
  13068. roots[0] = -tmp;
  13069. roots[1] = tmp;
  13070. if (Math.abs(startAngle - endAngle) >= PI2) {
  13071. startAngle = 0;
  13072. endAngle = PI2;
  13073. var dir = anticlockwise ? 1 : -1;
  13074. if (x >= roots[0] + cx && x <= roots[1] + cx) {
  13075. return dir;
  13076. } else {
  13077. return 0;
  13078. }
  13079. }
  13080. if (anticlockwise) {
  13081. var tmp = startAngle;
  13082. startAngle = normalizeRadian(endAngle);
  13083. endAngle = normalizeRadian(tmp);
  13084. } else {
  13085. startAngle = normalizeRadian(startAngle);
  13086. endAngle = normalizeRadian(endAngle);
  13087. }
  13088. if (startAngle > endAngle) {
  13089. endAngle += PI2;
  13090. }
  13091. var w = 0;
  13092. for (var i = 0; i < 2; i++) {
  13093. var x_ = roots[i];
  13094. if (x_ + cx > x) {
  13095. var angle = Math.atan2(y, x_);
  13096. var dir = anticlockwise ? 1 : -1;
  13097. if (angle < 0) {
  13098. angle = PI2 + angle;
  13099. }
  13100. if (angle >= startAngle && angle <= endAngle || angle + PI2 >= startAngle && angle + PI2 <= endAngle) {
  13101. if (angle > Math.PI / 2 && angle < Math.PI * 1.5) {
  13102. dir = -dir;
  13103. }
  13104. w += dir;
  13105. }
  13106. }
  13107. }
  13108. return w;
  13109. }
  13110. function isInsidePath(pathArray, lineWidth, brushType, x, y) {
  13111. var w = 0;
  13112. var xi = 0;
  13113. var yi = 0;
  13114. var x0 = 0;
  13115. var y0 = 0;
  13116. var beginSubpath = true;
  13117. var firstCmd = true;
  13118. brushType = brushType || 'fill';
  13119. var hasStroke = brushType === 'stroke' || brushType === 'both';
  13120. var hasFill = brushType === 'fill' || brushType === 'both';
  13121. for (var i = 0; i < pathArray.length; i++) {
  13122. var seg = pathArray[i];
  13123. var p = seg.points;
  13124. if (beginSubpath || seg.command === 'M') {
  13125. if (i > 0) {
  13126. if (hasFill) {
  13127. w += windingLine(xi, yi, x0, y0, x, y);
  13128. }
  13129. if (w !== 0) {
  13130. return true;
  13131. }
  13132. }
  13133. x0 = p[p.length - 2];
  13134. y0 = p[p.length - 1];
  13135. beginSubpath = false;
  13136. if (firstCmd && seg.command !== 'A') {
  13137. firstCmd = false;
  13138. xi = x0;
  13139. yi = y0;
  13140. }
  13141. }
  13142. switch (seg.command) {
  13143. case 'M':
  13144. xi = p[0];
  13145. yi = p[1];
  13146. break;
  13147. case 'L':
  13148. if (hasStroke) {
  13149. if (isInsideLine(xi, yi, p[0], p[1], lineWidth, x, y)) {
  13150. return true;
  13151. }
  13152. }
  13153. if (hasFill) {
  13154. w += windingLine(xi, yi, p[0], p[1], x, y);
  13155. }
  13156. xi = p[0];
  13157. yi = p[1];
  13158. break;
  13159. case 'C':
  13160. if (hasStroke) {
  13161. if (isInsideCubicStroke(xi, yi, p[0], p[1], p[2], p[3], p[4], p[5], lineWidth, x, y)) {
  13162. return true;
  13163. }
  13164. }
  13165. if (hasFill) {
  13166. w += windingCubic(xi, yi, p[0], p[1], p[2], p[3], p[4], p[5], x, y);
  13167. }
  13168. xi = p[4];
  13169. yi = p[5];
  13170. break;
  13171. case 'Q':
  13172. if (hasStroke) {
  13173. if (isInsideQuadraticStroke(xi, yi, p[0], p[1], p[2], p[3], lineWidth, x, y)) {
  13174. return true;
  13175. }
  13176. }
  13177. if (hasFill) {
  13178. w += windingQuadratic(xi, yi, p[0], p[1], p[2], p[3], x, y);
  13179. }
  13180. xi = p[2];
  13181. yi = p[3];
  13182. break;
  13183. case 'A':
  13184. var cx = p[0];
  13185. var cy = p[1];
  13186. var rx = p[2];
  13187. var ry = p[3];
  13188. var theta = p[4];
  13189. var dTheta = p[5];
  13190. var x1 = Math.cos(theta) * rx + cx;
  13191. var y1 = Math.sin(theta) * ry + cy;
  13192. if (!firstCmd) {
  13193. w += windingLine(xi, yi, x1, y1);
  13194. } else {
  13195. firstCmd = false;
  13196. x0 = x1;
  13197. y0 = y1;
  13198. }
  13199. var _x = (x - cx) * ry / rx + cx;
  13200. if (hasStroke) {
  13201. if (isInsideArcStroke(cx, cy, ry, theta, theta + dTheta, 1 - p[7], lineWidth, _x, y)) {
  13202. return true;
  13203. }
  13204. }
  13205. if (hasFill) {
  13206. w += windingArc(cx, cy, ry, theta, theta + dTheta, 1 - p[7], _x, y);
  13207. }
  13208. xi = Math.cos(theta + dTheta) * rx + cx;
  13209. yi = Math.sin(theta + dTheta) * ry + cy;
  13210. break;
  13211. case 'z':
  13212. if (hasStroke) {
  13213. if (isInsideLine(xi, yi, x0, y0, lineWidth, x, y)) {
  13214. return true;
  13215. }
  13216. }
  13217. beginSubpath = true;
  13218. break;
  13219. }
  13220. }
  13221. if (hasFill) {
  13222. w += windingLine(xi, yi, x0, y0, x, y);
  13223. }
  13224. return w !== 0;
  13225. }
  13226. function getTextWidth(text, textFont) {
  13227. var key = text + ':' + textFont;
  13228. if (_textWidthCache[key]) {
  13229. return _textWidthCache[key];
  13230. }
  13231. _ctx = _ctx || util.getContext();
  13232. _ctx.save();
  13233. if (textFont) {
  13234. _ctx.font = textFont;
  13235. }
  13236. text = (text + '').split('\n');
  13237. var width = 0;
  13238. for (var i = 0, l = text.length; i < l; i++) {
  13239. width = Math.max(_ctx.measureText(text[i]).width, width);
  13240. }
  13241. _ctx.restore();
  13242. _textWidthCache[key] = width;
  13243. if (++_textWidthCacheCounter > TEXT_CACHE_MAX) {
  13244. _textWidthCacheCounter = 0;
  13245. _textWidthCache = {};
  13246. }
  13247. return width;
  13248. }
  13249. function getTextHeight(text, textFont) {
  13250. var key = text + ':' + textFont;
  13251. if (_textHeightCache[key]) {
  13252. return _textHeightCache[key];
  13253. }
  13254. _ctx = _ctx || util.getContext();
  13255. _ctx.save();
  13256. if (textFont) {
  13257. _ctx.font = textFont;
  13258. }
  13259. text = (text + '').split('\n');
  13260. var height = (_ctx.measureText('国').width + 2) * text.length;
  13261. _ctx.restore();
  13262. _textHeightCache[key] = height;
  13263. if (++_textHeightCacheCounter > TEXT_CACHE_MAX) {
  13264. _textHeightCacheCounter = 0;
  13265. _textHeightCache = {};
  13266. }
  13267. return height;
  13268. }
  13269. return {
  13270. isInside: isInside,
  13271. isOutside: isOutside,
  13272. getTextWidth: getTextWidth,
  13273. getTextHeight: getTextHeight,
  13274. isInsidePath: isInsidePath,
  13275. isInsidePolygon: isInsidePolygon,
  13276. isInsideSector: isInsideSector,
  13277. isInsideCircle: isInsideCircle,
  13278. isInsideLine: isInsideLine,
  13279. isInsideRect: isInsideRect,
  13280. isInsidePolyline: isInsidePolyline,
  13281. isInsideCubicStroke: isInsideCubicStroke,
  13282. isInsideQuadraticStroke: isInsideQuadraticStroke
  13283. };
  13284. });define('zrender/shape/Base', [
  13285. 'require',
  13286. '../tool/matrix',
  13287. '../tool/guid',
  13288. '../tool/util',
  13289. '../tool/log',
  13290. '../mixin/Transformable',
  13291. '../mixin/Eventful',
  13292. '../tool/area',
  13293. '../tool/color'
  13294. ], function (require) {
  13295. var vmlCanvasManager = window['G_vmlCanvasManager'];
  13296. var matrix = require('../tool/matrix');
  13297. var guid = require('../tool/guid');
  13298. var util = require('../tool/util');
  13299. var log = require('../tool/log');
  13300. var Transformable = require('../mixin/Transformable');
  13301. var Eventful = require('../mixin/Eventful');
  13302. function _fillText(ctx, text, x, y, textFont, textAlign, textBaseline) {
  13303. if (textFont) {
  13304. ctx.font = textFont;
  13305. }
  13306. ctx.textAlign = textAlign;
  13307. ctx.textBaseline = textBaseline;
  13308. var rect = _getTextRect(text, x, y, textFont, textAlign, textBaseline);
  13309. text = (text + '').split('\n');
  13310. var lineHeight = require('../tool/area').getTextHeight('国', textFont);
  13311. switch (textBaseline) {
  13312. case 'top':
  13313. y = rect.y;
  13314. break;
  13315. case 'bottom':
  13316. y = rect.y + lineHeight;
  13317. break;
  13318. default:
  13319. y = rect.y + lineHeight / 2;
  13320. }
  13321. for (var i = 0, l = text.length; i < l; i++) {
  13322. ctx.fillText(text[i], x, y);
  13323. y += lineHeight;
  13324. }
  13325. }
  13326. function _getTextRect(text, x, y, textFont, textAlign, textBaseline) {
  13327. var area = require('../tool/area');
  13328. var width = area.getTextWidth(text, textFont);
  13329. var lineHeight = area.getTextHeight('国', textFont);
  13330. text = (text + '').split('\n');
  13331. switch (textAlign) {
  13332. case 'end':
  13333. case 'right':
  13334. x -= width;
  13335. break;
  13336. case 'center':
  13337. x -= width / 2;
  13338. break;
  13339. }
  13340. switch (textBaseline) {
  13341. case 'top':
  13342. break;
  13343. case 'bottom':
  13344. y -= lineHeight * text.length;
  13345. break;
  13346. default:
  13347. y -= lineHeight * text.length / 2;
  13348. }
  13349. return {
  13350. x: x,
  13351. y: y,
  13352. width: width,
  13353. height: lineHeight * text.length
  13354. };
  13355. }
  13356. var Base = function (options) {
  13357. options = options || {};
  13358. this.id = options.id || guid();
  13359. for (var key in options) {
  13360. this[key] = options[key];
  13361. }
  13362. this.style = this.style || {};
  13363. this.highlightStyle = this.highlightStyle || null;
  13364. this.parent = null;
  13365. this.__dirty = true;
  13366. this.__clipShapes = [];
  13367. Transformable.call(this);
  13368. Eventful.call(this);
  13369. };
  13370. Base.prototype.invisible = false;
  13371. Base.prototype.ignore = false;
  13372. Base.prototype.zlevel = 0;
  13373. Base.prototype.draggable = false;
  13374. Base.prototype.clickable = false;
  13375. Base.prototype.hoverable = true;
  13376. Base.prototype.z = 0;
  13377. Base.prototype.brush = function (ctx, isHighlight) {
  13378. var style = this.beforeBrush(ctx, isHighlight);
  13379. ctx.beginPath();
  13380. this.buildPath(ctx, style);
  13381. switch (style.brushType) {
  13382. case 'both':
  13383. ctx.fill();
  13384. case 'stroke':
  13385. style.lineWidth > 0 && ctx.stroke();
  13386. break;
  13387. default:
  13388. ctx.fill();
  13389. }
  13390. this.drawText(ctx, style, this.style);
  13391. this.afterBrush(ctx);
  13392. };
  13393. Base.prototype.beforeBrush = function (ctx, isHighlight) {
  13394. var style = this.style;
  13395. if (this.brushTypeOnly) {
  13396. style.brushType = this.brushTypeOnly;
  13397. }
  13398. if (isHighlight) {
  13399. style = this.getHighlightStyle(style, this.highlightStyle || {}, this.brushTypeOnly);
  13400. }
  13401. if (this.brushTypeOnly == 'stroke') {
  13402. style.strokeColor = style.strokeColor || style.color;
  13403. }
  13404. ctx.save();
  13405. this.doClip(ctx);
  13406. this.setContext(ctx, style);
  13407. this.setTransform(ctx);
  13408. return style;
  13409. };
  13410. Base.prototype.afterBrush = function (ctx) {
  13411. ctx.restore();
  13412. };
  13413. var STYLE_CTX_MAP = [
  13414. [
  13415. 'color',
  13416. 'fillStyle'
  13417. ],
  13418. [
  13419. 'strokeColor',
  13420. 'strokeStyle'
  13421. ],
  13422. [
  13423. 'opacity',
  13424. 'globalAlpha'
  13425. ],
  13426. [
  13427. 'lineCap',
  13428. 'lineCap'
  13429. ],
  13430. [
  13431. 'lineJoin',
  13432. 'lineJoin'
  13433. ],
  13434. [
  13435. 'miterLimit',
  13436. 'miterLimit'
  13437. ],
  13438. [
  13439. 'lineWidth',
  13440. 'lineWidth'
  13441. ],
  13442. [
  13443. 'shadowBlur',
  13444. 'shadowBlur'
  13445. ],
  13446. [
  13447. 'shadowColor',
  13448. 'shadowColor'
  13449. ],
  13450. [
  13451. 'shadowOffsetX',
  13452. 'shadowOffsetX'
  13453. ],
  13454. [
  13455. 'shadowOffsetY',
  13456. 'shadowOffsetY'
  13457. ]
  13458. ];
  13459. Base.prototype.setContext = function (ctx, style) {
  13460. for (var i = 0, len = STYLE_CTX_MAP.length; i < len; i++) {
  13461. var styleProp = STYLE_CTX_MAP[i][0];
  13462. var styleValue = style[styleProp];
  13463. var ctxProp = STYLE_CTX_MAP[i][1];
  13464. if (typeof styleValue != 'undefined') {
  13465. ctx[ctxProp] = styleValue;
  13466. }
  13467. }
  13468. };
  13469. var clipShapeInvTransform = matrix.create();
  13470. Base.prototype.doClip = function (ctx) {
  13471. if (this.__clipShapes && !vmlCanvasManager) {
  13472. for (var i = 0; i < this.__clipShapes.length; i++) {
  13473. var clipShape = this.__clipShapes[i];
  13474. if (clipShape.needTransform) {
  13475. var m = clipShape.transform;
  13476. matrix.invert(clipShapeInvTransform, m);
  13477. ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
  13478. }
  13479. ctx.beginPath();
  13480. clipShape.buildPath(ctx, clipShape.style);
  13481. ctx.clip();
  13482. if (clipShape.needTransform) {
  13483. var m = clipShapeInvTransform;
  13484. ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
  13485. }
  13486. }
  13487. }
  13488. };
  13489. Base.prototype.getHighlightStyle = function (style, highlightStyle, brushTypeOnly) {
  13490. var newStyle = {};
  13491. for (var k in style) {
  13492. newStyle[k] = style[k];
  13493. }
  13494. var color = require('../tool/color');
  13495. var highlightColor = color.getHighlightColor();
  13496. if (style.brushType != 'stroke') {
  13497. newStyle.strokeColor = highlightColor;
  13498. newStyle.lineWidth = (style.lineWidth || 1) + this.getHighlightZoom();
  13499. newStyle.brushType = 'both';
  13500. } else {
  13501. if (brushTypeOnly != 'stroke') {
  13502. newStyle.strokeColor = highlightColor;
  13503. newStyle.lineWidth = (style.lineWidth || 1) + this.getHighlightZoom();
  13504. } else {
  13505. newStyle.strokeColor = highlightStyle.strokeColor || color.mix(style.strokeColor, color.toRGB(highlightColor));
  13506. }
  13507. }
  13508. for (var k in highlightStyle) {
  13509. if (typeof highlightStyle[k] != 'undefined') {
  13510. newStyle[k] = highlightStyle[k];
  13511. }
  13512. }
  13513. return newStyle;
  13514. };
  13515. Base.prototype.getHighlightZoom = function () {
  13516. return this.type != 'text' ? 6 : 2;
  13517. };
  13518. Base.prototype.drift = function (dx, dy) {
  13519. this.position[0] += dx;
  13520. this.position[1] += dy;
  13521. };
  13522. Base.prototype.buildPath = function (ctx, style) {
  13523. log('buildPath not implemented in ' + this.type);
  13524. };
  13525. Base.prototype.getRect = function (style) {
  13526. log('getRect not implemented in ' + this.type);
  13527. };
  13528. Base.prototype.isCover = function (x, y) {
  13529. var originPos = this.transformCoordToLocal(x, y);
  13530. x = originPos[0];
  13531. y = originPos[1];
  13532. if (this.isCoverRect(x, y)) {
  13533. return require('../tool/area').isInside(this, this.style, x, y);
  13534. }
  13535. return false;
  13536. };
  13537. Base.prototype.isCoverRect = function (x, y) {
  13538. var rect = this.style.__rect;
  13539. if (!rect) {
  13540. rect = this.style.__rect = this.getRect(this.style);
  13541. }
  13542. return x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height;
  13543. };
  13544. Base.prototype.drawText = function (ctx, style, normalStyle) {
  13545. if (typeof style.text == 'undefined' || style.text === false) {
  13546. return;
  13547. }
  13548. var textColor = style.textColor || style.color || style.strokeColor;
  13549. ctx.fillStyle = textColor;
  13550. var dd = 10;
  13551. var al;
  13552. var bl;
  13553. var tx;
  13554. var ty;
  13555. var textPosition = style.textPosition || this.textPosition || 'top';
  13556. switch (textPosition) {
  13557. case 'inside':
  13558. case 'top':
  13559. case 'bottom':
  13560. case 'left':
  13561. case 'right':
  13562. if (this.getRect) {
  13563. var rect = (normalStyle || style).__rect || this.getRect(normalStyle || style);
  13564. switch (textPosition) {
  13565. case 'inside':
  13566. tx = rect.x + rect.width / 2;
  13567. ty = rect.y + rect.height / 2;
  13568. al = 'center';
  13569. bl = 'middle';
  13570. if (style.brushType != 'stroke' && textColor == style.color) {
  13571. ctx.fillStyle = '#fff';
  13572. }
  13573. break;
  13574. case 'left':
  13575. tx = rect.x - dd;
  13576. ty = rect.y + rect.height / 2;
  13577. al = 'end';
  13578. bl = 'middle';
  13579. break;
  13580. case 'right':
  13581. tx = rect.x + rect.width + dd;
  13582. ty = rect.y + rect.height / 2;
  13583. al = 'start';
  13584. bl = 'middle';
  13585. break;
  13586. case 'top':
  13587. tx = rect.x + rect.width / 2;
  13588. ty = rect.y - dd;
  13589. al = 'center';
  13590. bl = 'bottom';
  13591. break;
  13592. case 'bottom':
  13593. tx = rect.x + rect.width / 2;
  13594. ty = rect.y + rect.height + dd;
  13595. al = 'center';
  13596. bl = 'top';
  13597. break;
  13598. }
  13599. }
  13600. break;
  13601. case 'start':
  13602. case 'end':
  13603. var pointList = style.pointList || [
  13604. [
  13605. style.xStart || 0,
  13606. style.yStart || 0
  13607. ],
  13608. [
  13609. style.xEnd || 0,
  13610. style.yEnd || 0
  13611. ]
  13612. ];
  13613. var length = pointList.length;
  13614. if (length < 2) {
  13615. return;
  13616. }
  13617. var xStart;
  13618. var xEnd;
  13619. var yStart;
  13620. var yEnd;
  13621. switch (textPosition) {
  13622. case 'start':
  13623. xStart = pointList[1][0];
  13624. xEnd = pointList[0][0];
  13625. yStart = pointList[1][1];
  13626. yEnd = pointList[0][1];
  13627. break;
  13628. case 'end':
  13629. xStart = pointList[length - 2][0];
  13630. xEnd = pointList[length - 1][0];
  13631. yStart = pointList[length - 2][1];
  13632. yEnd = pointList[length - 1][1];
  13633. break;
  13634. }
  13635. tx = xEnd;
  13636. ty = yEnd;
  13637. var angle = Math.atan((yStart - yEnd) / (xEnd - xStart)) / Math.PI * 180;
  13638. if (xEnd - xStart < 0) {
  13639. angle += 180;
  13640. } else if (yStart - yEnd < 0) {
  13641. angle += 360;
  13642. }
  13643. dd = 5;
  13644. if (angle >= 30 && angle <= 150) {
  13645. al = 'center';
  13646. bl = 'bottom';
  13647. ty -= dd;
  13648. } else if (angle > 150 && angle < 210) {
  13649. al = 'right';
  13650. bl = 'middle';
  13651. tx -= dd;
  13652. } else if (angle >= 210 && angle <= 330) {
  13653. al = 'center';
  13654. bl = 'top';
  13655. ty += dd;
  13656. } else {
  13657. al = 'left';
  13658. bl = 'middle';
  13659. tx += dd;
  13660. }
  13661. break;
  13662. case 'specific':
  13663. tx = style.textX || 0;
  13664. ty = style.textY || 0;
  13665. al = 'start';
  13666. bl = 'middle';
  13667. break;
  13668. }
  13669. if (tx != null && ty != null) {
  13670. _fillText(ctx, style.text, tx, ty, style.textFont, style.textAlign || al, style.textBaseline || bl);
  13671. }
  13672. };
  13673. Base.prototype.modSelf = function () {
  13674. this.__dirty = true;
  13675. if (this.style) {
  13676. this.style.__rect = null;
  13677. }
  13678. if (this.highlightStyle) {
  13679. this.highlightStyle.__rect = null;
  13680. }
  13681. };
  13682. Base.prototype.isSilent = function () {
  13683. 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);
  13684. };
  13685. util.merge(Base.prototype, Transformable.prototype, true);
  13686. util.merge(Base.prototype, Eventful.prototype, true);
  13687. return Base;
  13688. });define('zrender/tool/curve', [
  13689. 'require',
  13690. './vector'
  13691. ], function (require) {
  13692. var vector = require('./vector');
  13693. 'use strict';
  13694. var EPSILON = 0.0001;
  13695. var THREE_SQRT = Math.sqrt(3);
  13696. var ONE_THIRD = 1 / 3;
  13697. var _v0 = vector.create();
  13698. var _v1 = vector.create();
  13699. var _v2 = vector.create();
  13700. function isAroundZero(val) {
  13701. return val > -EPSILON && val < EPSILON;
  13702. }
  13703. function isNotAroundZero(val) {
  13704. return val > EPSILON || val < -EPSILON;
  13705. }
  13706. function cubicAt(p0, p1, p2, p3, t) {
  13707. var onet = 1 - t;
  13708. return onet * onet * (onet * p0 + 3 * t * p1) + t * t * (t * p3 + 3 * onet * p2);
  13709. }
  13710. function cubicDerivativeAt(p0, p1, p2, p3, t) {
  13711. var onet = 1 - t;
  13712. return 3 * (((p1 - p0) * onet + 2 * (p2 - p1) * t) * onet + (p3 - p2) * t * t);
  13713. }
  13714. function cubicRootAt(p0, p1, p2, p3, val, roots) {
  13715. var a = p3 + 3 * (p1 - p2) - p0;
  13716. var b = 3 * (p2 - p1 * 2 + p0);
  13717. var c = 3 * (p1 - p0);
  13718. var d = p0 - val;
  13719. var A = b * b - 3 * a * c;
  13720. var B = b * c - 9 * a * d;
  13721. var C = c * c - 3 * b * d;
  13722. var n = 0;
  13723. if (isAroundZero(A) && isAroundZero(B)) {
  13724. if (isAroundZero(b)) {
  13725. roots[0] = 0;
  13726. } else {
  13727. var t1 = -c / b;
  13728. if (t1 >= 0 && t1 <= 1) {
  13729. roots[n++] = t1;
  13730. }
  13731. }
  13732. } else {
  13733. var disc = B * B - 4 * A * C;
  13734. if (isAroundZero(disc)) {
  13735. var K = B / A;
  13736. var t1 = -b / a + K;
  13737. var t2 = -K / 2;
  13738. if (t1 >= 0 && t1 <= 1) {
  13739. roots[n++] = t1;
  13740. }
  13741. if (t2 >= 0 && t2 <= 1) {
  13742. roots[n++] = t2;
  13743. }
  13744. } else if (disc > 0) {
  13745. var discSqrt = Math.sqrt(disc);
  13746. var Y1 = A * b + 1.5 * a * (-B + discSqrt);
  13747. var Y2 = A * b + 1.5 * a * (-B - discSqrt);
  13748. if (Y1 < 0) {
  13749. Y1 = -Math.pow(-Y1, ONE_THIRD);
  13750. } else {
  13751. Y1 = Math.pow(Y1, ONE_THIRD);
  13752. }
  13753. if (Y2 < 0) {
  13754. Y2 = -Math.pow(-Y2, ONE_THIRD);
  13755. } else {
  13756. Y2 = Math.pow(Y2, ONE_THIRD);
  13757. }
  13758. var t1 = (-b - (Y1 + Y2)) / (3 * a);
  13759. if (t1 >= 0 && t1 <= 1) {
  13760. roots[n++] = t1;
  13761. }
  13762. } else {
  13763. var T = (2 * A * b - 3 * a * B) / (2 * Math.sqrt(A * A * A));
  13764. var theta = Math.acos(T) / 3;
  13765. var ASqrt = Math.sqrt(A);
  13766. var tmp = Math.cos(theta);
  13767. var t1 = (-b - 2 * ASqrt * tmp) / (3 * a);
  13768. var t2 = (-b + ASqrt * (tmp + THREE_SQRT * Math.sin(theta))) / (3 * a);
  13769. var t3 = (-b + ASqrt * (tmp - THREE_SQRT * Math.sin(theta))) / (3 * a);
  13770. if (t1 >= 0 && t1 <= 1) {
  13771. roots[n++] = t1;
  13772. }
  13773. if (t2 >= 0 && t2 <= 1) {
  13774. roots[n++] = t2;
  13775. }
  13776. if (t3 >= 0 && t3 <= 1) {
  13777. roots[n++] = t3;
  13778. }
  13779. }
  13780. }
  13781. return n;
  13782. }
  13783. function cubicExtrema(p0, p1, p2, p3, extrema) {
  13784. var b = 6 * p2 - 12 * p1 + 6 * p0;
  13785. var a = 9 * p1 + 3 * p3 - 3 * p0 - 9 * p2;
  13786. var c = 3 * p1 - 3 * p0;
  13787. var n = 0;
  13788. if (isAroundZero(a)) {
  13789. if (isNotAroundZero(b)) {
  13790. var t1 = -c / b;
  13791. if (t1 >= 0 && t1 <= 1) {
  13792. extrema[n++] = t1;
  13793. }
  13794. }
  13795. } else {
  13796. var disc = b * b - 4 * a * c;
  13797. if (isAroundZero(disc)) {
  13798. extrema[0] = -b / (2 * a);
  13799. } else if (disc > 0) {
  13800. var discSqrt = Math.sqrt(disc);
  13801. var t1 = (-b + discSqrt) / (2 * a);
  13802. var t2 = (-b - discSqrt) / (2 * a);
  13803. if (t1 >= 0 && t1 <= 1) {
  13804. extrema[n++] = t1;
  13805. }
  13806. if (t2 >= 0 && t2 <= 1) {
  13807. extrema[n++] = t2;
  13808. }
  13809. }
  13810. }
  13811. return n;
  13812. }
  13813. function cubicSubdivide(p0, p1, p2, p3, t, out) {
  13814. var p01 = (p1 - p0) * t + p0;
  13815. var p12 = (p2 - p1) * t + p1;
  13816. var p23 = (p3 - p2) * t + p2;
  13817. var p012 = (p12 - p01) * t + p01;
  13818. var p123 = (p23 - p12) * t + p12;
  13819. var p0123 = (p123 - p012) * t + p012;
  13820. out[0] = p0;
  13821. out[1] = p01;
  13822. out[2] = p012;
  13823. out[3] = p0123;
  13824. out[4] = p0123;
  13825. out[5] = p123;
  13826. out[6] = p23;
  13827. out[7] = p3;
  13828. }
  13829. function cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, out) {
  13830. var t;
  13831. var interval = 0.005;
  13832. var d = Infinity;
  13833. _v0[0] = x;
  13834. _v0[1] = y;
  13835. for (var _t = 0; _t < 1; _t += 0.05) {
  13836. _v1[0] = cubicAt(x0, x1, x2, x3, _t);
  13837. _v1[1] = cubicAt(y0, y1, y2, y3, _t);
  13838. var d1 = vector.distSquare(_v0, _v1);
  13839. if (d1 < d) {
  13840. t = _t;
  13841. d = d1;
  13842. }
  13843. }
  13844. d = Infinity;
  13845. for (var i = 0; i < 32; i++) {
  13846. if (interval < EPSILON) {
  13847. break;
  13848. }
  13849. var prev = t - interval;
  13850. var next = t + interval;
  13851. _v1[0] = cubicAt(x0, x1, x2, x3, prev);
  13852. _v1[1] = cubicAt(y0, y1, y2, y3, prev);
  13853. var d1 = vector.distSquare(_v1, _v0);
  13854. if (prev >= 0 && d1 < d) {
  13855. t = prev;
  13856. d = d1;
  13857. } else {
  13858. _v2[0] = cubicAt(x0, x1, x2, x3, next);
  13859. _v2[1] = cubicAt(y0, y1, y2, y3, next);
  13860. var d2 = vector.distSquare(_v2, _v0);
  13861. if (next <= 1 && d2 < d) {
  13862. t = next;
  13863. d = d2;
  13864. } else {
  13865. interval *= 0.5;
  13866. }
  13867. }
  13868. }
  13869. if (out) {
  13870. out[0] = cubicAt(x0, x1, x2, x3, t);
  13871. out[1] = cubicAt(y0, y1, y2, y3, t);
  13872. }
  13873. return Math.sqrt(d);
  13874. }
  13875. function quadraticAt(p0, p1, p2, t) {
  13876. var onet = 1 - t;
  13877. return onet * (onet * p0 + 2 * t * p1) + t * t * p2;
  13878. }
  13879. function quadraticDerivativeAt(p0, p1, p2, t) {
  13880. return 2 * ((1 - t) * (p1 - p0) + t * (p2 - p1));
  13881. }
  13882. function quadraticRootAt(p0, p1, p2, val, roots) {
  13883. var a = p0 - 2 * p1 + p2;
  13884. var b = 2 * (p1 - p0);
  13885. var c = p0 - val;
  13886. var n = 0;
  13887. if (isAroundZero(a)) {
  13888. if (isNotAroundZero(b)) {
  13889. var t1 = -c / b;
  13890. if (t1 >= 0 && t1 <= 1) {
  13891. roots[n++] = t1;
  13892. }
  13893. }
  13894. } else {
  13895. var disc = b * b - 4 * a * c;
  13896. if (isAroundZero(disc)) {
  13897. var t1 = -b / (2 * a);
  13898. if (t1 >= 0 && t1 <= 1) {
  13899. roots[n++] = t1;
  13900. }
  13901. } else if (disc > 0) {
  13902. var discSqrt = Math.sqrt(disc);
  13903. var t1 = (-b + discSqrt) / (2 * a);
  13904. var t2 = (-b - discSqrt) / (2 * a);
  13905. if (t1 >= 0 && t1 <= 1) {
  13906. roots[n++] = t1;
  13907. }
  13908. if (t2 >= 0 && t2 <= 1) {
  13909. roots[n++] = t2;
  13910. }
  13911. }
  13912. }
  13913. return n;
  13914. }
  13915. function quadraticExtremum(p0, p1, p2) {
  13916. var divider = p0 + p2 - 2 * p1;
  13917. if (divider === 0) {
  13918. return 0.5;
  13919. } else {
  13920. return (p0 - p1) / divider;
  13921. }
  13922. }
  13923. function quadraticSubdivide(p0, p1, p2, t, out) {
  13924. var p01 = (p1 - p0) * t + p0;
  13925. var p12 = (p2 - p1) * t + p1;
  13926. var p012 = (p12 - p01) * t + p01;
  13927. out[0] = p0;
  13928. out[1] = p01;
  13929. out[2] = p012;
  13930. out[3] = p012;
  13931. out[4] = p12;
  13932. out[5] = p2;
  13933. }
  13934. function quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, out) {
  13935. var t;
  13936. var interval = 0.005;
  13937. var d = Infinity;
  13938. _v0[0] = x;
  13939. _v0[1] = y;
  13940. for (var _t = 0; _t < 1; _t += 0.05) {
  13941. _v1[0] = quadraticAt(x0, x1, x2, _t);
  13942. _v1[1] = quadraticAt(y0, y1, y2, _t);
  13943. var d1 = vector.distSquare(_v0, _v1);
  13944. if (d1 < d) {
  13945. t = _t;
  13946. d = d1;
  13947. }
  13948. }
  13949. d = Infinity;
  13950. for (var i = 0; i < 32; i++) {
  13951. if (interval < EPSILON) {
  13952. break;
  13953. }
  13954. var prev = t - interval;
  13955. var next = t + interval;
  13956. _v1[0] = quadraticAt(x0, x1, x2, prev);
  13957. _v1[1] = quadraticAt(y0, y1, y2, prev);
  13958. var d1 = vector.distSquare(_v1, _v0);
  13959. if (prev >= 0 && d1 < d) {
  13960. t = prev;
  13961. d = d1;
  13962. } else {
  13963. _v2[0] = quadraticAt(x0, x1, x2, next);
  13964. _v2[1] = quadraticAt(y0, y1, y2, next);
  13965. var d2 = vector.distSquare(_v2, _v0);
  13966. if (next <= 1 && d2 < d) {
  13967. t = next;
  13968. d = d2;
  13969. } else {
  13970. interval *= 0.5;
  13971. }
  13972. }
  13973. }
  13974. if (out) {
  13975. out[0] = quadraticAt(x0, x1, x2, t);
  13976. out[1] = quadraticAt(y0, y1, y2, t);
  13977. }
  13978. return Math.sqrt(d);
  13979. }
  13980. return {
  13981. cubicAt: cubicAt,
  13982. cubicDerivativeAt: cubicDerivativeAt,
  13983. cubicRootAt: cubicRootAt,
  13984. cubicExtrema: cubicExtrema,
  13985. cubicSubdivide: cubicSubdivide,
  13986. cubicProjectPoint: cubicProjectPoint,
  13987. quadraticAt: quadraticAt,
  13988. quadraticDerivativeAt: quadraticDerivativeAt,
  13989. quadraticRootAt: quadraticRootAt,
  13990. quadraticExtremum: quadraticExtremum,
  13991. quadraticSubdivide: quadraticSubdivide,
  13992. quadraticProjectPoint: quadraticProjectPoint
  13993. };
  13994. });define('zrender/mixin/Transformable', [
  13995. 'require',
  13996. '../tool/matrix',
  13997. '../tool/vector'
  13998. ], function (require) {
  13999. 'use strict';
  14000. var matrix = require('../tool/matrix');
  14001. var vector = require('../tool/vector');
  14002. var origin = [
  14003. 0,
  14004. 0
  14005. ];
  14006. var mTranslate = matrix.translate;
  14007. var EPSILON = 0.00005;
  14008. function isAroundZero(val) {
  14009. return val > -EPSILON && val < EPSILON;
  14010. }
  14011. function isNotAroundZero(val) {
  14012. return val > EPSILON || val < -EPSILON;
  14013. }
  14014. var Transformable = function () {
  14015. if (!this.position) {
  14016. this.position = [
  14017. 0,
  14018. 0
  14019. ];
  14020. }
  14021. if (typeof this.rotation == 'undefined') {
  14022. this.rotation = [
  14023. 0,
  14024. 0,
  14025. 0
  14026. ];
  14027. }
  14028. if (!this.scale) {
  14029. this.scale = [
  14030. 1,
  14031. 1,
  14032. 0,
  14033. 0
  14034. ];
  14035. }
  14036. this.needLocalTransform = false;
  14037. this.needTransform = false;
  14038. };
  14039. Transformable.prototype = {
  14040. constructor: Transformable,
  14041. updateNeedTransform: function () {
  14042. this.needLocalTransform = isNotAroundZero(this.rotation[0]) || isNotAroundZero(this.position[0]) || isNotAroundZero(this.position[1]) || isNotAroundZero(this.scale[0] - 1) || isNotAroundZero(this.scale[1] - 1);
  14043. },
  14044. updateTransform: function () {
  14045. this.updateNeedTransform();
  14046. var parentHasTransform = this.parent && this.parent.needTransform;
  14047. this.needTransform = this.needLocalTransform || parentHasTransform;
  14048. if (!this.needTransform) {
  14049. return;
  14050. }
  14051. var m = this.transform || matrix.create();
  14052. matrix.identity(m);
  14053. if (this.needLocalTransform) {
  14054. var scale = this.scale;
  14055. if (isNotAroundZero(scale[0]) || isNotAroundZero(scale[1])) {
  14056. origin[0] = -scale[2] || 0;
  14057. origin[1] = -scale[3] || 0;
  14058. var haveOrigin = isNotAroundZero(origin[0]) || isNotAroundZero(origin[1]);
  14059. if (haveOrigin) {
  14060. mTranslate(m, m, origin);
  14061. }
  14062. matrix.scale(m, m, scale);
  14063. if (haveOrigin) {
  14064. origin[0] = -origin[0];
  14065. origin[1] = -origin[1];
  14066. mTranslate(m, m, origin);
  14067. }
  14068. }
  14069. if (this.rotation instanceof Array) {
  14070. if (this.rotation[0] !== 0) {
  14071. origin[0] = -this.rotation[1] || 0;
  14072. origin[1] = -this.rotation[2] || 0;
  14073. var haveOrigin = isNotAroundZero(origin[0]) || isNotAroundZero(origin[1]);
  14074. if (haveOrigin) {
  14075. mTranslate(m, m, origin);
  14076. }
  14077. matrix.rotate(m, m, this.rotation[0]);
  14078. if (haveOrigin) {
  14079. origin[0] = -origin[0];
  14080. origin[1] = -origin[1];
  14081. mTranslate(m, m, origin);
  14082. }
  14083. }
  14084. } else {
  14085. if (this.rotation !== 0) {
  14086. matrix.rotate(m, m, this.rotation);
  14087. }
  14088. }
  14089. if (isNotAroundZero(this.position[0]) || isNotAroundZero(this.position[1])) {
  14090. mTranslate(m, m, this.position);
  14091. }
  14092. }
  14093. if (parentHasTransform) {
  14094. if (this.needLocalTransform) {
  14095. matrix.mul(m, this.parent.transform, m);
  14096. } else {
  14097. matrix.copy(m, this.parent.transform);
  14098. }
  14099. }
  14100. this.transform = m;
  14101. this.invTransform = this.invTransform || matrix.create();
  14102. matrix.invert(this.invTransform, m);
  14103. },
  14104. setTransform: function (ctx) {
  14105. if (this.needTransform) {
  14106. var m = this.transform;
  14107. ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
  14108. }
  14109. },
  14110. lookAt: function () {
  14111. var v = vector.create();
  14112. return function (target) {
  14113. if (!this.transform) {
  14114. this.transform = matrix.create();
  14115. }
  14116. var m = this.transform;
  14117. vector.sub(v, target, this.position);
  14118. if (isAroundZero(v[0]) && isAroundZero(v[1])) {
  14119. return;
  14120. }
  14121. vector.normalize(v, v);
  14122. var scale = this.scale;
  14123. m[2] = v[0] * scale[1];
  14124. m[3] = v[1] * scale[1];
  14125. m[0] = v[1] * scale[0];
  14126. m[1] = -v[0] * scale[0];
  14127. m[4] = this.position[0];
  14128. m[5] = this.position[1];
  14129. this.decomposeTransform();
  14130. };
  14131. }(),
  14132. decomposeTransform: function () {
  14133. if (!this.transform) {
  14134. return;
  14135. }
  14136. var m = this.transform;
  14137. var sx = m[0] * m[0] + m[1] * m[1];
  14138. var position = this.position;
  14139. var scale = this.scale;
  14140. var rotation = this.rotation;
  14141. if (isNotAroundZero(sx - 1)) {
  14142. sx = Math.sqrt(sx);
  14143. }
  14144. var sy = m[2] * m[2] + m[3] * m[3];
  14145. if (isNotAroundZero(sy - 1)) {
  14146. sy = Math.sqrt(sy);
  14147. }
  14148. position[0] = m[4];
  14149. position[1] = m[5];
  14150. scale[0] = sx;
  14151. scale[1] = sy;
  14152. scale[2] = scale[3] = 0;
  14153. rotation[0] = Math.atan2(-m[1] / sy, m[0] / sx);
  14154. rotation[1] = rotation[2] = 0;
  14155. },
  14156. transformCoordToLocal: function (x, y) {
  14157. var v2 = [
  14158. x,
  14159. y
  14160. ];
  14161. if (this.needTransform && this.invTransform) {
  14162. matrix.mulVector(v2, this.invTransform, v2);
  14163. }
  14164. return v2;
  14165. }
  14166. };
  14167. return Transformable;
  14168. });define('zrender/Group', [
  14169. 'require',
  14170. './tool/guid',
  14171. './tool/util',
  14172. './mixin/Transformable',
  14173. './mixin/Eventful'
  14174. ], function (require) {
  14175. var guid = require('./tool/guid');
  14176. var util = require('./tool/util');
  14177. var Transformable = require('./mixin/Transformable');
  14178. var Eventful = require('./mixin/Eventful');
  14179. var Group = function (options) {
  14180. options = options || {};
  14181. this.id = options.id || guid();
  14182. for (var key in options) {
  14183. this[key] = options[key];
  14184. }
  14185. this.type = 'group';
  14186. this.clipShape = null;
  14187. this._children = [];
  14188. this._storage = null;
  14189. this.__dirty = true;
  14190. Transformable.call(this);
  14191. Eventful.call(this);
  14192. };
  14193. Group.prototype.ignore = false;
  14194. Group.prototype.children = function () {
  14195. return this._children.slice();
  14196. };
  14197. Group.prototype.childAt = function (idx) {
  14198. return this._children[idx];
  14199. };
  14200. Group.prototype.addChild = function (child) {
  14201. if (child == this) {
  14202. return;
  14203. }
  14204. if (child.parent == this) {
  14205. return;
  14206. }
  14207. if (child.parent) {
  14208. child.parent.removeChild(child);
  14209. }
  14210. this._children.push(child);
  14211. child.parent = this;
  14212. if (this._storage && this._storage !== child._storage) {
  14213. this._storage.addToMap(child);
  14214. if (child instanceof Group) {
  14215. child.addChildrenToStorage(this._storage);
  14216. }
  14217. }
  14218. };
  14219. Group.prototype.removeChild = function (child) {
  14220. var idx = util.indexOf(this._children, child);
  14221. if (idx >= 0) {
  14222. this._children.splice(idx, 1);
  14223. }
  14224. child.parent = null;
  14225. if (this._storage) {
  14226. this._storage.delFromMap(child.id);
  14227. if (child instanceof Group) {
  14228. child.delChildrenFromStorage(this._storage);
  14229. }
  14230. }
  14231. };
  14232. Group.prototype.clearChildren = function () {
  14233. for (var i = 0; i < this._children.length; i++) {
  14234. var child = this._children[i];
  14235. if (this._storage) {
  14236. this._storage.delFromMap(child.id);
  14237. if (child instanceof Group) {
  14238. child.delChildrenFromStorage(this._storage);
  14239. }
  14240. }
  14241. }
  14242. this._children.length = 0;
  14243. };
  14244. Group.prototype.eachChild = function (cb, context) {
  14245. var haveContext = !!context;
  14246. for (var i = 0; i < this._children.length; i++) {
  14247. var child = this._children[i];
  14248. if (haveContext) {
  14249. cb.call(context, child);
  14250. } else {
  14251. cb(child);
  14252. }
  14253. }
  14254. };
  14255. Group.prototype.traverse = function (cb, context) {
  14256. var haveContext = !!context;
  14257. for (var i = 0; i < this._children.length; i++) {
  14258. var child = this._children[i];
  14259. if (haveContext) {
  14260. cb.call(context, child);
  14261. } else {
  14262. cb(child);
  14263. }
  14264. if (child.type === 'group') {
  14265. child.traverse(cb, context);
  14266. }
  14267. }
  14268. };
  14269. Group.prototype.addChildrenToStorage = function (storage) {
  14270. for (var i = 0; i < this._children.length; i++) {
  14271. var child = this._children[i];
  14272. storage.addToMap(child);
  14273. if (child instanceof Group) {
  14274. child.addChildrenToStorage(storage);
  14275. }
  14276. }
  14277. };
  14278. Group.prototype.delChildrenFromStorage = function (storage) {
  14279. for (var i = 0; i < this._children.length; i++) {
  14280. var child = this._children[i];
  14281. storage.delFromMap(child.id);
  14282. if (child instanceof Group) {
  14283. child.delChildrenFromStorage(storage);
  14284. }
  14285. }
  14286. };
  14287. Group.prototype.modSelf = function () {
  14288. this.__dirty = true;
  14289. };
  14290. util.merge(Group.prototype, Transformable.prototype, true);
  14291. util.merge(Group.prototype, Eventful.prototype, true);
  14292. return Group;
  14293. });define('zrender/animation/Clip', [
  14294. 'require',
  14295. './easing'
  14296. ], function (require) {
  14297. var Easing = require('./easing');
  14298. function Clip(options) {
  14299. this._targetPool = options.target || {};
  14300. if (!(this._targetPool instanceof Array)) {
  14301. this._targetPool = [this._targetPool];
  14302. }
  14303. this._life = options.life || 1000;
  14304. this._delay = options.delay || 0;
  14305. this._startTime = new Date().getTime() + this._delay;
  14306. this._endTime = this._startTime + this._life * 1000;
  14307. this.loop = typeof options.loop == 'undefined' ? false : options.loop;
  14308. this.gap = options.gap || 0;
  14309. this.easing = options.easing || 'Linear';
  14310. this.onframe = options.onframe;
  14311. this.ondestroy = options.ondestroy;
  14312. this.onrestart = options.onrestart;
  14313. }
  14314. Clip.prototype = {
  14315. step: function (time) {
  14316. var percent = (time - this._startTime) / this._life;
  14317. if (percent < 0) {
  14318. return;
  14319. }
  14320. percent = Math.min(percent, 1);
  14321. var easingFunc = typeof this.easing == 'string' ? Easing[this.easing] : this.easing;
  14322. var schedule = typeof easingFunc === 'function' ? easingFunc(percent) : percent;
  14323. this.fire('frame', schedule);
  14324. if (percent == 1) {
  14325. if (this.loop) {
  14326. this.restart();
  14327. return 'restart';
  14328. }
  14329. this._needsRemove = true;
  14330. return 'destroy';
  14331. }
  14332. return null;
  14333. },
  14334. restart: function () {
  14335. var time = new Date().getTime();
  14336. var remainder = (time - this._startTime) % this._life;
  14337. this._startTime = new Date().getTime() - remainder + this.gap;
  14338. this._needsRemove = false;
  14339. },
  14340. fire: function (eventType, arg) {
  14341. for (var i = 0, len = this._targetPool.length; i < len; i++) {
  14342. if (this['on' + eventType]) {
  14343. this['on' + eventType](this._targetPool[i], arg);
  14344. }
  14345. }
  14346. },
  14347. constructor: Clip
  14348. };
  14349. return Clip;
  14350. });define('zrender/animation/easing', [], function () {
  14351. var easing = {
  14352. Linear: function (k) {
  14353. return k;
  14354. },
  14355. QuadraticIn: function (k) {
  14356. return k * k;
  14357. },
  14358. QuadraticOut: function (k) {
  14359. return k * (2 - k);
  14360. },
  14361. QuadraticInOut: function (k) {
  14362. if ((k *= 2) < 1) {
  14363. return 0.5 * k * k;
  14364. }
  14365. return -0.5 * (--k * (k - 2) - 1);
  14366. },
  14367. CubicIn: function (k) {
  14368. return k * k * k;
  14369. },
  14370. CubicOut: function (k) {
  14371. return --k * k * k + 1;
  14372. },
  14373. CubicInOut: function (k) {
  14374. if ((k *= 2) < 1) {
  14375. return 0.5 * k * k * k;
  14376. }
  14377. return 0.5 * ((k -= 2) * k * k + 2);
  14378. },
  14379. QuarticIn: function (k) {
  14380. return k * k * k * k;
  14381. },
  14382. QuarticOut: function (k) {
  14383. return 1 - --k * k * k * k;
  14384. },
  14385. QuarticInOut: function (k) {
  14386. if ((k *= 2) < 1) {
  14387. return 0.5 * k * k * k * k;
  14388. }
  14389. return -0.5 * ((k -= 2) * k * k * k - 2);
  14390. },
  14391. QuinticIn: function (k) {
  14392. return k * k * k * k * k;
  14393. },
  14394. QuinticOut: function (k) {
  14395. return --k * k * k * k * k + 1;
  14396. },
  14397. QuinticInOut: function (k) {
  14398. if ((k *= 2) < 1) {
  14399. return 0.5 * k * k * k * k * k;
  14400. }
  14401. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  14402. },
  14403. SinusoidalIn: function (k) {
  14404. return 1 - Math.cos(k * Math.PI / 2);
  14405. },
  14406. SinusoidalOut: function (k) {
  14407. return Math.sin(k * Math.PI / 2);
  14408. },
  14409. SinusoidalInOut: function (k) {
  14410. return 0.5 * (1 - Math.cos(Math.PI * k));
  14411. },
  14412. ExponentialIn: function (k) {
  14413. return k === 0 ? 0 : Math.pow(1024, k - 1);
  14414. },
  14415. ExponentialOut: function (k) {
  14416. return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
  14417. },
  14418. ExponentialInOut: function (k) {
  14419. if (k === 0) {
  14420. return 0;
  14421. }
  14422. if (k === 1) {
  14423. return 1;
  14424. }
  14425. if ((k *= 2) < 1) {
  14426. return 0.5 * Math.pow(1024, k - 1);
  14427. }
  14428. return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
  14429. },
  14430. CircularIn: function (k) {
  14431. return 1 - Math.sqrt(1 - k * k);
  14432. },
  14433. CircularOut: function (k) {
  14434. return Math.sqrt(1 - --k * k);
  14435. },
  14436. CircularInOut: function (k) {
  14437. if ((k *= 2) < 1) {
  14438. return -0.5 * (Math.sqrt(1 - k * k) - 1);
  14439. }
  14440. return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
  14441. },
  14442. ElasticIn: function (k) {
  14443. var s;
  14444. var a = 0.1;
  14445. var p = 0.4;
  14446. if (k === 0) {
  14447. return 0;
  14448. }
  14449. if (k === 1) {
  14450. return 1;
  14451. }
  14452. if (!a || a < 1) {
  14453. a = 1;
  14454. s = p / 4;
  14455. } else {
  14456. s = p * Math.asin(1 / a) / (2 * Math.PI);
  14457. }
  14458. return -(a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
  14459. },
  14460. ElasticOut: function (k) {
  14461. var s;
  14462. var a = 0.1;
  14463. var p = 0.4;
  14464. if (k === 0) {
  14465. return 0;
  14466. }
  14467. if (k === 1) {
  14468. return 1;
  14469. }
  14470. if (!a || a < 1) {
  14471. a = 1;
  14472. s = p / 4;
  14473. } else {
  14474. s = p * Math.asin(1 / a) / (2 * Math.PI);
  14475. }
  14476. return a * Math.pow(2, -10 * k) * Math.sin((k - s) * (2 * Math.PI) / p) + 1;
  14477. },
  14478. ElasticInOut: function (k) {
  14479. var s;
  14480. var a = 0.1;
  14481. var p = 0.4;
  14482. if (k === 0) {
  14483. return 0;
  14484. }
  14485. if (k === 1) {
  14486. return 1;
  14487. }
  14488. if (!a || a < 1) {
  14489. a = 1;
  14490. s = p / 4;
  14491. } else {
  14492. s = p * Math.asin(1 / a) / (2 * Math.PI);
  14493. }
  14494. if ((k *= 2) < 1) {
  14495. return -0.5 * (a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
  14496. }
  14497. return a * Math.pow(2, -10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
  14498. },
  14499. BackIn: function (k) {
  14500. var s = 1.70158;
  14501. return k * k * ((s + 1) * k - s);
  14502. },
  14503. BackOut: function (k) {
  14504. var s = 1.70158;
  14505. return --k * k * ((s + 1) * k + s) + 1;
  14506. },
  14507. BackInOut: function (k) {
  14508. var s = 1.70158 * 1.525;
  14509. if ((k *= 2) < 1) {
  14510. return 0.5 * (k * k * ((s + 1) * k - s));
  14511. }
  14512. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  14513. },
  14514. BounceIn: function (k) {
  14515. return 1 - easing.BounceOut(1 - k);
  14516. },
  14517. BounceOut: function (k) {
  14518. if (k < 1 / 2.75) {
  14519. return 7.5625 * k * k;
  14520. } else if (k < 2 / 2.75) {
  14521. return 7.5625 * (k -= 1.5 / 2.75) * k + 0.75;
  14522. } else if (k < 2.5 / 2.75) {
  14523. return 7.5625 * (k -= 2.25 / 2.75) * k + 0.9375;
  14524. } else {
  14525. return 7.5625 * (k -= 2.625 / 2.75) * k + 0.984375;
  14526. }
  14527. },
  14528. BounceInOut: function (k) {
  14529. if (k < 0.5) {
  14530. return easing.BounceIn(k * 2) * 0.5;
  14531. }
  14532. return easing.BounceOut(k * 2 - 1) * 0.5 + 0.5;
  14533. }
  14534. };
  14535. return easing;
  14536. });define('echarts/chart/base', [
  14537. 'require',
  14538. 'zrender/shape/Image',
  14539. '../util/shape/Icon',
  14540. '../util/shape/MarkLine',
  14541. '../util/shape/Symbol',
  14542. 'zrender/shape/Polyline',
  14543. 'zrender/shape/ShapeBundle',
  14544. '../config',
  14545. '../util/ecData',
  14546. '../util/ecAnimation',
  14547. '../util/ecEffect',
  14548. '../util/accMath',
  14549. '../component/base',
  14550. '../layout/EdgeBundling',
  14551. 'zrender/tool/util',
  14552. 'zrender/tool/area'
  14553. ], function (require) {
  14554. var ImageShape = require('zrender/shape/Image');
  14555. var IconShape = require('../util/shape/Icon');
  14556. var MarkLineShape = require('../util/shape/MarkLine');
  14557. var SymbolShape = require('../util/shape/Symbol');
  14558. var PolylineShape = require('zrender/shape/Polyline');
  14559. var ShapeBundle = require('zrender/shape/ShapeBundle');
  14560. var ecConfig = require('../config');
  14561. var ecData = require('../util/ecData');
  14562. var ecAnimation = require('../util/ecAnimation');
  14563. var ecEffect = require('../util/ecEffect');
  14564. var accMath = require('../util/accMath');
  14565. var ComponentBase = require('../component/base');
  14566. var EdgeBundling = require('../layout/EdgeBundling');
  14567. var zrUtil = require('zrender/tool/util');
  14568. var zrArea = require('zrender/tool/area');
  14569. function isCoordAvailable(coord) {
  14570. return coord.x != null && coord.y != null;
  14571. }
  14572. function Base(ecTheme, messageCenter, zr, option, myChart) {
  14573. ComponentBase.call(this, ecTheme, messageCenter, zr, option, myChart);
  14574. var self = this;
  14575. this.selectedMap = {};
  14576. this.lastShapeList = [];
  14577. this.shapeHandler = {
  14578. onclick: function () {
  14579. self.isClick = true;
  14580. },
  14581. ondragover: function (param) {
  14582. var calculableShape = param.target;
  14583. calculableShape.highlightStyle = calculableShape.highlightStyle || {};
  14584. var highlightStyle = calculableShape.highlightStyle;
  14585. var brushType = highlightStyle.brushTyep;
  14586. var strokeColor = highlightStyle.strokeColor;
  14587. var lineWidth = highlightStyle.lineWidth;
  14588. highlightStyle.brushType = 'stroke';
  14589. highlightStyle.strokeColor = self.ecTheme.calculableColor || ecConfig.calculableColor;
  14590. highlightStyle.lineWidth = calculableShape.type === 'icon' ? 30 : 10;
  14591. self.zr.addHoverShape(calculableShape);
  14592. setTimeout(function () {
  14593. if (highlightStyle) {
  14594. highlightStyle.brushType = brushType;
  14595. highlightStyle.strokeColor = strokeColor;
  14596. highlightStyle.lineWidth = lineWidth;
  14597. }
  14598. }, 20);
  14599. },
  14600. ondrop: function (param) {
  14601. if (ecData.get(param.dragged, 'data') != null) {
  14602. self.isDrop = true;
  14603. }
  14604. },
  14605. ondragend: function () {
  14606. self.isDragend = true;
  14607. }
  14608. };
  14609. }
  14610. Base.prototype = {
  14611. setCalculable: function (shape) {
  14612. shape.dragEnableTime = this.ecTheme.DRAG_ENABLE_TIME || ecConfig.DRAG_ENABLE_TIME;
  14613. shape.ondragover = this.shapeHandler.ondragover;
  14614. shape.ondragend = this.shapeHandler.ondragend;
  14615. shape.ondrop = this.shapeHandler.ondrop;
  14616. return shape;
  14617. },
  14618. ondrop: function (param, status) {
  14619. if (!this.isDrop || !param.target || status.dragIn) {
  14620. return;
  14621. }
  14622. var target = param.target;
  14623. var dragged = param.dragged;
  14624. var seriesIndex = ecData.get(target, 'seriesIndex');
  14625. var dataIndex = ecData.get(target, 'dataIndex');
  14626. var series = this.series;
  14627. var data;
  14628. var legend = this.component.legend;
  14629. if (dataIndex === -1) {
  14630. if (ecData.get(dragged, 'seriesIndex') == seriesIndex) {
  14631. status.dragOut = status.dragIn = status.needRefresh = true;
  14632. this.isDrop = false;
  14633. return;
  14634. }
  14635. data = {
  14636. value: ecData.get(dragged, 'value'),
  14637. name: ecData.get(dragged, 'name')
  14638. };
  14639. if (this.type === ecConfig.CHART_TYPE_PIE && data.value < 0) {
  14640. data.value = 0;
  14641. }
  14642. var hasFind = false;
  14643. var sData = series[seriesIndex].data;
  14644. for (var i = 0, l = sData.length; i < l; i++) {
  14645. if (sData[i].name === data.name && sData[i].value === '-') {
  14646. series[seriesIndex].data[i].value = data.value;
  14647. hasFind = true;
  14648. }
  14649. }
  14650. !hasFind && series[seriesIndex].data.push(data);
  14651. legend && legend.add(data.name, dragged.style.color || dragged.style.strokeColor);
  14652. } else {
  14653. data = series[seriesIndex].data[dataIndex] || '-';
  14654. if (data.value != null) {
  14655. if (data.value != '-') {
  14656. series[seriesIndex].data[dataIndex].value = accMath.accAdd(series[seriesIndex].data[dataIndex].value, ecData.get(dragged, 'value'));
  14657. } else {
  14658. series[seriesIndex].data[dataIndex].value = ecData.get(dragged, 'value');
  14659. }
  14660. if (this.type === ecConfig.CHART_TYPE_FUNNEL || this.type === ecConfig.CHART_TYPE_PIE) {
  14661. legend && legend.getRelatedAmount(data.name) === 1 && this.component.legend.del(data.name);
  14662. data.name += this.option.nameConnector + ecData.get(dragged, 'name');
  14663. legend && legend.add(data.name, dragged.style.color || dragged.style.strokeColor);
  14664. }
  14665. } else {
  14666. if (data != '-') {
  14667. series[seriesIndex].data[dataIndex] = accMath.accAdd(series[seriesIndex].data[dataIndex], ecData.get(dragged, 'value'));
  14668. } else {
  14669. series[seriesIndex].data[dataIndex] = ecData.get(dragged, 'value');
  14670. }
  14671. }
  14672. }
  14673. status.dragIn = status.dragIn || true;
  14674. this.isDrop = false;
  14675. var self = this;
  14676. setTimeout(function () {
  14677. self.zr.trigger('mousemove', param.event);
  14678. }, 300);
  14679. return;
  14680. },
  14681. ondragend: function (param, status) {
  14682. if (!this.isDragend || !param.target || status.dragOut) {
  14683. return;
  14684. }
  14685. var target = param.target;
  14686. var seriesIndex = ecData.get(target, 'seriesIndex');
  14687. var dataIndex = ecData.get(target, 'dataIndex');
  14688. var series = this.series;
  14689. if (series[seriesIndex].data[dataIndex].value != null) {
  14690. series[seriesIndex].data[dataIndex].value = '-';
  14691. var name = series[seriesIndex].data[dataIndex].name;
  14692. var legend = this.component.legend;
  14693. if (legend && legend.getRelatedAmount(name) === 0) {
  14694. legend.del(name);
  14695. }
  14696. } else {
  14697. series[seriesIndex].data[dataIndex] = '-';
  14698. }
  14699. status.dragOut = true;
  14700. status.needRefresh = true;
  14701. this.isDragend = false;
  14702. return;
  14703. },
  14704. onlegendSelected: function (param, status) {
  14705. var legendSelected = param.selected;
  14706. for (var itemName in this.selectedMap) {
  14707. if (this.selectedMap[itemName] != legendSelected[itemName]) {
  14708. status.needRefresh = true;
  14709. }
  14710. this.selectedMap[itemName] = legendSelected[itemName];
  14711. }
  14712. return;
  14713. },
  14714. _buildPosition: function () {
  14715. this._symbol = this.option.symbolList;
  14716. this._sIndex2ShapeMap = {};
  14717. this._sIndex2ColorMap = {};
  14718. this.selectedMap = {};
  14719. this.xMarkMap = {};
  14720. var series = this.series;
  14721. var _position2sIndexMap = {
  14722. top: [],
  14723. bottom: [],
  14724. left: [],
  14725. right: [],
  14726. other: []
  14727. };
  14728. var xAxisIndex;
  14729. var yAxisIndex;
  14730. var xAxis;
  14731. var yAxis;
  14732. for (var i = 0, l = series.length; i < l; i++) {
  14733. if (series[i].type === this.type) {
  14734. series[i] = this.reformOption(series[i]);
  14735. this.legendHoverLink = series[i].legendHoverLink || this.legendHoverLink;
  14736. xAxisIndex = series[i].xAxisIndex;
  14737. yAxisIndex = series[i].yAxisIndex;
  14738. xAxis = this.component.xAxis.getAxis(xAxisIndex);
  14739. yAxis = this.component.yAxis.getAxis(yAxisIndex);
  14740. if (xAxis.type === ecConfig.COMPONENT_TYPE_AXIS_CATEGORY) {
  14741. _position2sIndexMap[xAxis.getPosition()].push(i);
  14742. } else if (yAxis.type === ecConfig.COMPONENT_TYPE_AXIS_CATEGORY) {
  14743. _position2sIndexMap[yAxis.getPosition()].push(i);
  14744. } else {
  14745. _position2sIndexMap.other.push(i);
  14746. }
  14747. }
  14748. }
  14749. for (var position in _position2sIndexMap) {
  14750. if (_position2sIndexMap[position].length > 0) {
  14751. this._buildSinglePosition(position, _position2sIndexMap[position]);
  14752. }
  14753. }
  14754. this.addShapeList();
  14755. },
  14756. _buildSinglePosition: function (position, seriesArray) {
  14757. var mapData = this._mapData(seriesArray);
  14758. var locationMap = mapData.locationMap;
  14759. var maxDataLength = mapData.maxDataLength;
  14760. if (maxDataLength === 0 || locationMap.length === 0) {
  14761. return;
  14762. }
  14763. switch (position) {
  14764. case 'bottom':
  14765. case 'top':
  14766. this._buildHorizontal(seriesArray, maxDataLength, locationMap, this.xMarkMap);
  14767. break;
  14768. case 'left':
  14769. case 'right':
  14770. this._buildVertical(seriesArray, maxDataLength, locationMap, this.xMarkMap);
  14771. break;
  14772. case 'other':
  14773. this._buildOther(seriesArray, maxDataLength, locationMap, this.xMarkMap);
  14774. break;
  14775. }
  14776. for (var i = 0, l = seriesArray.length; i < l; i++) {
  14777. this.buildMark(seriesArray[i]);
  14778. }
  14779. },
  14780. _mapData: function (seriesArray) {
  14781. var series = this.series;
  14782. var serie;
  14783. var dataIndex = 0;
  14784. var stackMap = {};
  14785. var magicStackKey = '__kener__stack__';
  14786. var stackKey;
  14787. var serieName;
  14788. var legend = this.component.legend;
  14789. var locationMap = [];
  14790. var maxDataLength = 0;
  14791. var iconShape;
  14792. for (var i = 0, l = seriesArray.length; i < l; i++) {
  14793. serie = series[seriesArray[i]];
  14794. serieName = serie.name;
  14795. this._sIndex2ShapeMap[seriesArray[i]] = this._sIndex2ShapeMap[seriesArray[i]] || this.query(serie, 'symbol') || this._symbol[i % this._symbol.length];
  14796. if (legend) {
  14797. this.selectedMap[serieName] = legend.isSelected(serieName);
  14798. this._sIndex2ColorMap[seriesArray[i]] = legend.getColor(serieName);
  14799. iconShape = legend.getItemShape(serieName);
  14800. if (iconShape) {
  14801. var style = iconShape.style;
  14802. if (this.type == ecConfig.CHART_TYPE_LINE) {
  14803. style.iconType = 'legendLineIcon';
  14804. style.symbol = this._sIndex2ShapeMap[seriesArray[i]];
  14805. } else if (serie.itemStyle.normal.barBorderWidth > 0) {
  14806. var highlightStyle = iconShape.highlightStyle;
  14807. style.brushType = 'both';
  14808. style.x += 1;
  14809. style.y += 1;
  14810. style.width -= 2;
  14811. style.height -= 2;
  14812. style.strokeColor = highlightStyle.strokeColor = serie.itemStyle.normal.barBorderColor;
  14813. highlightStyle.lineWidth = 3;
  14814. }
  14815. legend.setItemShape(serieName, iconShape);
  14816. }
  14817. } else {
  14818. this.selectedMap[serieName] = true;
  14819. this._sIndex2ColorMap[seriesArray[i]] = this.zr.getColor(seriesArray[i]);
  14820. }
  14821. if (this.selectedMap[serieName]) {
  14822. stackKey = serie.stack || magicStackKey + seriesArray[i];
  14823. if (stackMap[stackKey] == null) {
  14824. stackMap[stackKey] = dataIndex;
  14825. locationMap[dataIndex] = [seriesArray[i]];
  14826. dataIndex++;
  14827. } else {
  14828. locationMap[stackMap[stackKey]].push(seriesArray[i]);
  14829. }
  14830. }
  14831. maxDataLength = Math.max(maxDataLength, serie.data.length);
  14832. }
  14833. return {
  14834. locationMap: locationMap,
  14835. maxDataLength: maxDataLength
  14836. };
  14837. },
  14838. _calculMarkMapXY: function (xMarkMap, locationMap, xy) {
  14839. var series = this.series;
  14840. for (var j = 0, k = locationMap.length; j < k; j++) {
  14841. for (var m = 0, n = locationMap[j].length; m < n; m++) {
  14842. var seriesIndex = locationMap[j][m];
  14843. var valueIndex = xy == 'xy' ? 0 : '';
  14844. var grid = this.component.grid;
  14845. var tarMark = xMarkMap[seriesIndex];
  14846. if (xy.indexOf('x') != '-1') {
  14847. if (tarMark['counter' + valueIndex] > 0) {
  14848. tarMark['average' + valueIndex] = tarMark['sum' + valueIndex] / tarMark['counter' + valueIndex];
  14849. }
  14850. var x = this.component.xAxis.getAxis(series[seriesIndex].xAxisIndex || 0).getCoord(tarMark['average' + valueIndex]);
  14851. tarMark['averageLine' + valueIndex] = [
  14852. [
  14853. x,
  14854. grid.getYend()
  14855. ],
  14856. [
  14857. x,
  14858. grid.getY()
  14859. ]
  14860. ];
  14861. tarMark['minLine' + valueIndex] = [
  14862. [
  14863. tarMark['minX' + valueIndex],
  14864. grid.getYend()
  14865. ],
  14866. [
  14867. tarMark['minX' + valueIndex],
  14868. grid.getY()
  14869. ]
  14870. ];
  14871. tarMark['maxLine' + valueIndex] = [
  14872. [
  14873. tarMark['maxX' + valueIndex],
  14874. grid.getYend()
  14875. ],
  14876. [
  14877. tarMark['maxX' + valueIndex],
  14878. grid.getY()
  14879. ]
  14880. ];
  14881. tarMark.isHorizontal = false;
  14882. }
  14883. valueIndex = xy == 'xy' ? 1 : '';
  14884. if (xy.indexOf('y') != '-1') {
  14885. if (tarMark['counter' + valueIndex] > 0) {
  14886. tarMark['average' + valueIndex] = tarMark['sum' + valueIndex] / tarMark['counter' + valueIndex];
  14887. }
  14888. var y = this.component.yAxis.getAxis(series[seriesIndex].yAxisIndex || 0).getCoord(tarMark['average' + valueIndex]);
  14889. tarMark['averageLine' + valueIndex] = [
  14890. [
  14891. grid.getX(),
  14892. y
  14893. ],
  14894. [
  14895. grid.getXend(),
  14896. y
  14897. ]
  14898. ];
  14899. tarMark['minLine' + valueIndex] = [
  14900. [
  14901. grid.getX(),
  14902. tarMark['minY' + valueIndex]
  14903. ],
  14904. [
  14905. grid.getXend(),
  14906. tarMark['minY' + valueIndex]
  14907. ]
  14908. ];
  14909. tarMark['maxLine' + valueIndex] = [
  14910. [
  14911. grid.getX(),
  14912. tarMark['maxY' + valueIndex]
  14913. ],
  14914. [
  14915. grid.getXend(),
  14916. tarMark['maxY' + valueIndex]
  14917. ]
  14918. ];
  14919. tarMark.isHorizontal = true;
  14920. }
  14921. }
  14922. }
  14923. },
  14924. addLabel: function (tarShape, serie, data, name, orient) {
  14925. var queryTarget = [
  14926. data,
  14927. serie
  14928. ];
  14929. var nLabel = this.deepMerge(queryTarget, 'itemStyle.normal.label');
  14930. var eLabel = this.deepMerge(queryTarget, 'itemStyle.emphasis.label');
  14931. var nTextStyle = nLabel.textStyle || {};
  14932. var eTextStyle = eLabel.textStyle || {};
  14933. if (nLabel.show) {
  14934. var style = tarShape.style;
  14935. style.text = this._getLabelText(serie, data, name, 'normal');
  14936. style.textPosition = nLabel.position == null ? orient === 'horizontal' ? 'right' : 'top' : nLabel.position;
  14937. style.textColor = nTextStyle.color;
  14938. style.textFont = this.getFont(nTextStyle);
  14939. style.textAlign = nTextStyle.align;
  14940. style.textBaseline = nTextStyle.baseline;
  14941. }
  14942. if (eLabel.show) {
  14943. var highlightStyle = tarShape.highlightStyle;
  14944. highlightStyle.text = this._getLabelText(serie, data, name, 'emphasis');
  14945. highlightStyle.textPosition = nLabel.show ? tarShape.style.textPosition : eLabel.position == null ? orient === 'horizontal' ? 'right' : 'top' : eLabel.position;
  14946. highlightStyle.textColor = eTextStyle.color;
  14947. highlightStyle.textFont = this.getFont(eTextStyle);
  14948. highlightStyle.textAlign = eTextStyle.align;
  14949. highlightStyle.textBaseline = eTextStyle.baseline;
  14950. }
  14951. return tarShape;
  14952. },
  14953. _getLabelText: function (serie, data, name, status) {
  14954. var formatter = this.deepQuery([
  14955. data,
  14956. serie
  14957. ], 'itemStyle.' + status + '.label.formatter');
  14958. if (!formatter && status === 'emphasis') {
  14959. formatter = this.deepQuery([
  14960. data,
  14961. serie
  14962. ], 'itemStyle.normal.label.formatter');
  14963. }
  14964. var value = this.getDataFromOption(data, '-');
  14965. if (formatter) {
  14966. if (typeof formatter === 'function') {
  14967. return formatter.call(this.myChart, {
  14968. seriesName: serie.name,
  14969. series: serie,
  14970. name: name,
  14971. value: value,
  14972. data: data,
  14973. status: status
  14974. });
  14975. } else if (typeof formatter === 'string') {
  14976. formatter = formatter.replace('{a}', '{a0}').replace('{b}', '{b0}').replace('{c}', '{c0}').replace('{a0}', serie.name).replace('{b0}', name).replace('{c0}', this.numAddCommas(value));
  14977. return formatter;
  14978. }
  14979. } else {
  14980. if (value instanceof Array) {
  14981. return value[2] != null ? this.numAddCommas(value[2]) : value[0] + ' , ' + value[1];
  14982. } else {
  14983. return this.numAddCommas(value);
  14984. }
  14985. }
  14986. },
  14987. buildMark: function (seriesIndex) {
  14988. var serie = this.series[seriesIndex];
  14989. if (this.selectedMap[serie.name]) {
  14990. serie.markLine && this._buildMarkLine(seriesIndex);
  14991. serie.markPoint && this._buildMarkPoint(seriesIndex);
  14992. }
  14993. },
  14994. _buildMarkPoint: function (seriesIndex) {
  14995. var attachStyle = (this.markAttachStyle || {})[seriesIndex];
  14996. var serie = this.series[seriesIndex];
  14997. var mpData;
  14998. var pos;
  14999. var markPoint = zrUtil.clone(serie.markPoint);
  15000. for (var i = 0, l = markPoint.data.length; i < l; i++) {
  15001. mpData = markPoint.data[i];
  15002. pos = this.getMarkCoord(seriesIndex, mpData);
  15003. mpData.x = mpData.x != null ? mpData.x : pos[0];
  15004. mpData.y = mpData.y != null ? mpData.y : pos[1];
  15005. if (mpData.type && (mpData.type === 'max' || mpData.type === 'min')) {
  15006. mpData.value = pos[3];
  15007. mpData.name = mpData.name || mpData.type;
  15008. mpData.symbolSize = mpData.symbolSize || zrArea.getTextWidth(pos[3], this.getFont()) / 2 + 5;
  15009. }
  15010. }
  15011. var shapeList = this._markPoint(seriesIndex, markPoint);
  15012. for (var i = 0, l = shapeList.length; i < l; i++) {
  15013. var tarShape = shapeList[i];
  15014. tarShape.zlevel = this.getZlevelBase();
  15015. tarShape.z = this.getZBase() + 1;
  15016. for (var key in attachStyle) {
  15017. tarShape[key] = zrUtil.clone(attachStyle[key]);
  15018. }
  15019. this.shapeList.push(tarShape);
  15020. }
  15021. if (this.type === ecConfig.CHART_TYPE_FORCE || this.type === ecConfig.CHART_TYPE_CHORD) {
  15022. for (var i = 0, l = shapeList.length; i < l; i++) {
  15023. this.zr.addShape(shapeList[i]);
  15024. }
  15025. }
  15026. },
  15027. _buildMarkLine: function (seriesIndex) {
  15028. var attachStyle = (this.markAttachStyle || {})[seriesIndex];
  15029. var serie = this.series[seriesIndex];
  15030. var pos;
  15031. var markLine = zrUtil.clone(serie.markLine);
  15032. for (var i = 0, l = markLine.data.length; i < l; i++) {
  15033. var mlData = markLine.data[i];
  15034. if (mlData.type && (mlData.type === 'max' || mlData.type === 'min' || mlData.type === 'average')) {
  15035. pos = this.getMarkCoord(seriesIndex, mlData);
  15036. markLine.data[i] = [
  15037. zrUtil.clone(mlData),
  15038. {}
  15039. ];
  15040. markLine.data[i][0].name = mlData.name || mlData.type;
  15041. markLine.data[i][0].value = mlData.type !== 'average' ? pos[3] : +pos[3].toFixed(markLine.precision != null ? markLine.precision : this.deepQuery([
  15042. this.ecTheme,
  15043. ecConfig
  15044. ], 'markLine.precision'));
  15045. pos = pos[2];
  15046. mlData = [
  15047. {},
  15048. {}
  15049. ];
  15050. } else {
  15051. pos = [
  15052. this.getMarkCoord(seriesIndex, mlData[0]),
  15053. this.getMarkCoord(seriesIndex, mlData[1])
  15054. ];
  15055. }
  15056. if (pos == null || pos[0] == null || pos[1] == null) {
  15057. continue;
  15058. }
  15059. markLine.data[i][0].x = mlData[0].x != null ? mlData[0].x : pos[0][0];
  15060. markLine.data[i][0].y = mlData[0].y != null ? mlData[0].y : pos[0][1];
  15061. markLine.data[i][1].x = mlData[1].x != null ? mlData[1].x : pos[1][0];
  15062. markLine.data[i][1].y = mlData[1].y != null ? mlData[1].y : pos[1][1];
  15063. }
  15064. var shapeList = this._markLine(seriesIndex, markLine);
  15065. var isLarge = markLine.large;
  15066. if (isLarge) {
  15067. var shapeBundle = new ShapeBundle({ style: { shapeList: shapeList } });
  15068. var firstShape = shapeList[0];
  15069. if (firstShape) {
  15070. zrUtil.merge(shapeBundle.style, firstShape.style);
  15071. zrUtil.merge(shapeBundle.highlightStyle = {}, firstShape.highlightStyle);
  15072. shapeBundle.style.brushType = 'stroke';
  15073. shapeBundle.zlevel = this.getZlevelBase();
  15074. shapeBundle.z = this.getZBase() + 1;
  15075. shapeBundle.hoverable = false;
  15076. for (var key in attachStyle) {
  15077. shapeBundle[key] = zrUtil.clone(attachStyle[key]);
  15078. }
  15079. }
  15080. this.shapeList.push(shapeBundle);
  15081. this.zr.addShape(shapeBundle);
  15082. shapeBundle._mark = 'largeLine';
  15083. var effect = markLine.effect;
  15084. if (effect.show) {
  15085. shapeBundle.effect = effect;
  15086. }
  15087. } else {
  15088. for (var i = 0, l = shapeList.length; i < l; i++) {
  15089. var tarShape = shapeList[i];
  15090. tarShape.zlevel = this.getZlevelBase();
  15091. tarShape.z = this.getZBase() + 1;
  15092. for (var key in attachStyle) {
  15093. tarShape[key] = zrUtil.clone(attachStyle[key]);
  15094. }
  15095. this.shapeList.push(tarShape);
  15096. }
  15097. if (this.type === ecConfig.CHART_TYPE_FORCE || this.type === ecConfig.CHART_TYPE_CHORD) {
  15098. for (var i = 0, l = shapeList.length; i < l; i++) {
  15099. this.zr.addShape(shapeList[i]);
  15100. }
  15101. }
  15102. }
  15103. },
  15104. _markPoint: function (seriesIndex, mpOption) {
  15105. var serie = this.series[seriesIndex];
  15106. var component = this.component;
  15107. zrUtil.merge(zrUtil.merge(mpOption, zrUtil.clone(this.ecTheme.markPoint || {})), zrUtil.clone(ecConfig.markPoint));
  15108. mpOption.name = serie.name;
  15109. var pList = [];
  15110. var data = mpOption.data;
  15111. var itemShape;
  15112. var dataRange = component.dataRange;
  15113. var legend = component.legend;
  15114. var color;
  15115. var value;
  15116. var queryTarget;
  15117. var nColor;
  15118. var eColor;
  15119. var effect;
  15120. var zrWidth = this.zr.getWidth();
  15121. var zrHeight = this.zr.getHeight();
  15122. if (!mpOption.large) {
  15123. for (var i = 0, l = data.length; i < l; i++) {
  15124. if (data[i].x == null || data[i].y == null) {
  15125. continue;
  15126. }
  15127. value = data[i].value != null ? data[i].value : '';
  15128. if (legend) {
  15129. color = legend.getColor(serie.name);
  15130. }
  15131. if (dataRange) {
  15132. color = isNaN(value) ? color : dataRange.getColor(value);
  15133. queryTarget = [
  15134. data[i],
  15135. mpOption
  15136. ];
  15137. nColor = this.deepQuery(queryTarget, 'itemStyle.normal.color') || color;
  15138. eColor = this.deepQuery(queryTarget, 'itemStyle.emphasis.color') || nColor;
  15139. if (nColor == null && eColor == null) {
  15140. continue;
  15141. }
  15142. }
  15143. color = color == null ? this.zr.getColor(seriesIndex) : color;
  15144. data[i].tooltip = data[i].tooltip || mpOption.tooltip || { trigger: 'item' };
  15145. data[i].name = data[i].name != null ? data[i].name : '';
  15146. data[i].value = value;
  15147. 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');
  15148. itemShape._mark = 'point';
  15149. effect = this.deepMerge([
  15150. data[i],
  15151. mpOption
  15152. ], 'effect');
  15153. if (effect.show) {
  15154. itemShape.effect = effect;
  15155. }
  15156. if (serie.type === ecConfig.CHART_TYPE_MAP) {
  15157. itemShape._geo = this.getMarkGeo(data[i]);
  15158. }
  15159. ecData.pack(itemShape, serie, seriesIndex, data[i], i, data[i].name, value);
  15160. pList.push(itemShape);
  15161. }
  15162. } else {
  15163. itemShape = this.getLargeMarkPointShape(seriesIndex, mpOption);
  15164. itemShape._mark = 'largePoint';
  15165. itemShape && pList.push(itemShape);
  15166. }
  15167. return pList;
  15168. },
  15169. _markLine: function () {
  15170. function normalizeOptionValue(mlOption, key) {
  15171. mlOption[key] = mlOption[key] instanceof Array ? mlOption[key].length > 1 ? mlOption[key] : [
  15172. mlOption[key][0],
  15173. mlOption[key][0]
  15174. ] : [
  15175. mlOption[key],
  15176. mlOption[key]
  15177. ];
  15178. }
  15179. return function (seriesIndex, mlOption) {
  15180. var serie = this.series[seriesIndex];
  15181. var component = this.component;
  15182. var dataRange = component.dataRange;
  15183. var legend = component.legend;
  15184. zrUtil.merge(zrUtil.merge(mlOption, zrUtil.clone(this.ecTheme.markLine || {})), zrUtil.clone(ecConfig.markLine));
  15185. var defaultColor = legend ? legend.getColor(serie.name) : this.zr.getColor(seriesIndex);
  15186. normalizeOptionValue(mlOption, 'symbol');
  15187. normalizeOptionValue(mlOption, 'symbolSize');
  15188. normalizeOptionValue(mlOption, 'symbolRotate');
  15189. var data = mlOption.data;
  15190. var edges = [];
  15191. var zrWidth = this.zr.getWidth();
  15192. var zrHeight = this.zr.getHeight();
  15193. for (var i = 0; i < data.length; i++) {
  15194. var mlData = data[i];
  15195. if (isCoordAvailable(mlData[0]) && isCoordAvailable(mlData[1])) {
  15196. var mergeData = this.deepMerge(mlData);
  15197. var queryTarget = [
  15198. mergeData,
  15199. mlOption
  15200. ];
  15201. var color = defaultColor;
  15202. var value = mergeData.value != null ? mergeData.value : '';
  15203. if (dataRange) {
  15204. color = isNaN(value) ? color : dataRange.getColor(value);
  15205. var nColor = this.deepQuery(queryTarget, 'itemStyle.normal.color') || color;
  15206. var eColor = this.deepQuery(queryTarget, 'itemStyle.emphasis.color') || nColor;
  15207. if (nColor == null && eColor == null) {
  15208. continue;
  15209. }
  15210. }
  15211. mlData[0].tooltip = mergeData.tooltip || mlOption.tooltip || { trigger: 'item' };
  15212. mlData[0].name = mlData[0].name || '';
  15213. mlData[1].name = mlData[1].name || '';
  15214. mlData[0].value = value;
  15215. edges.push({
  15216. points: [
  15217. [
  15218. this.parsePercent(mlData[0].x, zrWidth),
  15219. this.parsePercent(mlData[0].y, zrHeight)
  15220. ],
  15221. [
  15222. this.parsePercent(mlData[1].x, zrWidth),
  15223. this.parsePercent(mlData[1].y, zrHeight)
  15224. ]
  15225. ],
  15226. rawData: mlData,
  15227. color: color
  15228. });
  15229. }
  15230. }
  15231. var enableBundling = this.query(mlOption, 'bundling.enable');
  15232. if (enableBundling) {
  15233. var edgeBundling = new EdgeBundling();
  15234. edgeBundling.maxTurningAngle = this.query(mlOption, 'bundling.maxTurningAngle') / 180 * Math.PI;
  15235. edges = edgeBundling.run(edges);
  15236. }
  15237. mlOption.name = serie.name;
  15238. var shapeList = [];
  15239. for (var i = 0, l = edges.length; i < l; i++) {
  15240. var edge = edges[i];
  15241. var rawEdge = edge.rawEdge || edge;
  15242. var mlData = rawEdge.rawData;
  15243. var value = mlData.value != null ? mlData.value : '';
  15244. var itemShape = this.getMarkLineShape(mlOption, seriesIndex, mlData, i, edge.points, enableBundling, rawEdge.color);
  15245. itemShape._mark = 'line';
  15246. var effect = this.deepMerge([
  15247. mlData[0],
  15248. mlData[1],
  15249. mlOption
  15250. ], 'effect');
  15251. if (effect.show) {
  15252. itemShape.effect = effect;
  15253. itemShape.effect.large = mlOption.large;
  15254. }
  15255. if (serie.type === ecConfig.CHART_TYPE_MAP) {
  15256. itemShape._geo = [
  15257. this.getMarkGeo(mlData[0]),
  15258. this.getMarkGeo(mlData[1])
  15259. ];
  15260. }
  15261. ecData.pack(itemShape, serie, seriesIndex, mlData[0], i, mlData[0].name + (mlData[1].name !== '' ? ' > ' + mlData[1].name : ''), value);
  15262. shapeList.push(itemShape);
  15263. }
  15264. return shapeList;
  15265. };
  15266. }(),
  15267. getMarkCoord: function () {
  15268. return [
  15269. 0,
  15270. 0
  15271. ];
  15272. },
  15273. getSymbolShape: function (serie, seriesIndex, data, dataIndex, name, x, y, symbol, color, emptyColor, orient) {
  15274. var queryTarget = [
  15275. data,
  15276. serie
  15277. ];
  15278. var value = this.getDataFromOption(data, '-');
  15279. symbol = this.deepQuery(queryTarget, 'symbol') || symbol;
  15280. var symbolSize = this.deepQuery(queryTarget, 'symbolSize');
  15281. symbolSize = typeof symbolSize === 'function' ? symbolSize(value) : symbolSize;
  15282. var symbolRotate = this.deepQuery(queryTarget, 'symbolRotate');
  15283. var normal = this.deepMerge(queryTarget, 'itemStyle.normal');
  15284. var emphasis = this.deepMerge(queryTarget, 'itemStyle.emphasis');
  15285. var nBorderWidth = normal.borderWidth != null ? normal.borderWidth : normal.lineStyle && normal.lineStyle.width;
  15286. if (nBorderWidth == null) {
  15287. nBorderWidth = symbol.match('empty') ? 2 : 0;
  15288. }
  15289. var eBorderWidth = emphasis.borderWidth != null ? emphasis.borderWidth : emphasis.lineStyle && emphasis.lineStyle.width;
  15290. if (eBorderWidth == null) {
  15291. eBorderWidth = nBorderWidth + 2;
  15292. }
  15293. var nColor = this.getItemStyleColor(normal.color, seriesIndex, dataIndex, data);
  15294. var eColor = this.getItemStyleColor(emphasis.color, seriesIndex, dataIndex, data);
  15295. var itemShape = new IconShape({
  15296. style: {
  15297. iconType: symbol.replace('empty', '').toLowerCase(),
  15298. x: x - symbolSize,
  15299. y: y - symbolSize,
  15300. width: symbolSize * 2,
  15301. height: symbolSize * 2,
  15302. brushType: 'both',
  15303. color: symbol.match('empty') ? emptyColor : nColor || color,
  15304. strokeColor: normal.borderColor || nColor || color,
  15305. lineWidth: nBorderWidth
  15306. },
  15307. highlightStyle: {
  15308. color: symbol.match('empty') ? emptyColor : eColor || nColor || color,
  15309. strokeColor: emphasis.borderColor || normal.borderColor || eColor || nColor || color,
  15310. lineWidth: eBorderWidth
  15311. },
  15312. clickable: this.deepQuery(queryTarget, 'clickable')
  15313. });
  15314. if (symbol.match('image')) {
  15315. itemShape.style.image = symbol.replace(new RegExp('^image:\\/\\/'), '');
  15316. itemShape = new ImageShape({
  15317. style: itemShape.style,
  15318. highlightStyle: itemShape.highlightStyle,
  15319. clickable: this.deepQuery(queryTarget, 'clickable')
  15320. });
  15321. }
  15322. if (symbolRotate != null) {
  15323. itemShape.rotation = [
  15324. symbolRotate * Math.PI / 180,
  15325. x,
  15326. y
  15327. ];
  15328. }
  15329. if (symbol.match('star')) {
  15330. itemShape.style.iconType = 'star';
  15331. itemShape.style.n = symbol.replace('empty', '').replace('star', '') - 0 || 5;
  15332. }
  15333. if (symbol === 'none') {
  15334. itemShape.invisible = true;
  15335. itemShape.hoverable = false;
  15336. }
  15337. itemShape = this.addLabel(itemShape, serie, data, name, orient);
  15338. if (symbol.match('empty')) {
  15339. if (itemShape.style.textColor == null) {
  15340. itemShape.style.textColor = itemShape.style.strokeColor;
  15341. }
  15342. if (itemShape.highlightStyle.textColor == null) {
  15343. itemShape.highlightStyle.textColor = itemShape.highlightStyle.strokeColor;
  15344. }
  15345. }
  15346. ecData.pack(itemShape, serie, seriesIndex, data, dataIndex, name);
  15347. itemShape._x = x;
  15348. itemShape._y = y;
  15349. itemShape._dataIndex = dataIndex;
  15350. itemShape._seriesIndex = seriesIndex;
  15351. return itemShape;
  15352. },
  15353. getMarkLineShape: function (mlOption, seriesIndex, data, dataIndex, points, bundling, color) {
  15354. var value0 = data[0].value != null ? data[0].value : '-';
  15355. var value1 = data[1].value != null ? data[1].value : '-';
  15356. var symbol = [
  15357. data[0].symbol || mlOption.symbol[0],
  15358. data[1].symbol || mlOption.symbol[1]
  15359. ];
  15360. var symbolSize = [
  15361. data[0].symbolSize || mlOption.symbolSize[0],
  15362. data[1].symbolSize || mlOption.symbolSize[1]
  15363. ];
  15364. symbolSize[0] = typeof symbolSize[0] === 'function' ? symbolSize[0](value0) : symbolSize[0];
  15365. symbolSize[1] = typeof symbolSize[1] === 'function' ? symbolSize[1](value1) : symbolSize[1];
  15366. var symbolRotate = [
  15367. this.query(data[0], 'symbolRotate') || mlOption.symbolRotate[0],
  15368. this.query(data[1], 'symbolRotate') || mlOption.symbolRotate[1]
  15369. ];
  15370. var queryTarget = [
  15371. data[0],
  15372. data[1],
  15373. mlOption
  15374. ];
  15375. var normal = this.deepMerge(queryTarget, 'itemStyle.normal');
  15376. normal.color = this.getItemStyleColor(normal.color, seriesIndex, dataIndex, data);
  15377. var emphasis = this.deepMerge(queryTarget, 'itemStyle.emphasis');
  15378. emphasis.color = this.getItemStyleColor(emphasis.color, seriesIndex, dataIndex, data);
  15379. var nlineStyle = normal.lineStyle;
  15380. var elineStyle = emphasis.lineStyle;
  15381. var nBorderWidth = nlineStyle.width;
  15382. if (nBorderWidth == null) {
  15383. nBorderWidth = normal.borderWidth;
  15384. }
  15385. var eBorderWidth = elineStyle.width;
  15386. if (eBorderWidth == null) {
  15387. eBorderWidth = emphasis.borderWidth != null ? emphasis.borderWidth : nBorderWidth + 2;
  15388. }
  15389. var smoothness = this.deepQuery(queryTarget, 'smoothness');
  15390. if (!this.deepQuery(queryTarget, 'smooth')) {
  15391. smoothness = 0;
  15392. }
  15393. var ShapeCtor = bundling ? PolylineShape : MarkLineShape;
  15394. var itemShape = new ShapeCtor({
  15395. style: {
  15396. symbol: symbol,
  15397. symbolSize: symbolSize,
  15398. symbolRotate: symbolRotate,
  15399. brushType: 'both',
  15400. lineType: nlineStyle.type,
  15401. shadowColor: nlineStyle.shadowColor || nlineStyle.color || normal.borderColor || normal.color || color,
  15402. shadowBlur: nlineStyle.shadowBlur,
  15403. shadowOffsetX: nlineStyle.shadowOffsetX,
  15404. shadowOffsetY: nlineStyle.shadowOffsetY,
  15405. color: normal.color || color,
  15406. strokeColor: nlineStyle.color || normal.borderColor || normal.color || color,
  15407. lineWidth: nBorderWidth,
  15408. symbolBorderColor: normal.borderColor || normal.color || color,
  15409. symbolBorder: normal.borderWidth
  15410. },
  15411. highlightStyle: {
  15412. shadowColor: elineStyle.shadowColor,
  15413. shadowBlur: elineStyle.shadowBlur,
  15414. shadowOffsetX: elineStyle.shadowOffsetX,
  15415. shadowOffsetY: elineStyle.shadowOffsetY,
  15416. color: emphasis.color || normal.color || color,
  15417. strokeColor: elineStyle.color || nlineStyle.color || emphasis.borderColor || normal.borderColor || emphasis.color || normal.color || color,
  15418. lineWidth: eBorderWidth,
  15419. symbolBorderColor: emphasis.borderColor || normal.borderColor || emphasis.color || normal.color || color,
  15420. symbolBorder: emphasis.borderWidth == null ? normal.borderWidth + 2 : emphasis.borderWidth
  15421. },
  15422. clickable: this.deepQuery(queryTarget, 'clickable')
  15423. });
  15424. var shapeStyle = itemShape.style;
  15425. if (bundling) {
  15426. shapeStyle.pointList = points;
  15427. shapeStyle.smooth = smoothness;
  15428. } else {
  15429. shapeStyle.xStart = points[0][0];
  15430. shapeStyle.yStart = points[0][1];
  15431. shapeStyle.xEnd = points[1][0];
  15432. shapeStyle.yEnd = points[1][1];
  15433. shapeStyle.curveness = smoothness;
  15434. itemShape.updatePoints(itemShape.style);
  15435. }
  15436. itemShape = this.addLabel(itemShape, mlOption, data[0], data[0].name + ' : ' + data[1].name);
  15437. return itemShape;
  15438. },
  15439. getLargeMarkPointShape: function (seriesIndex, mpOption) {
  15440. var serie = this.series[seriesIndex];
  15441. var component = this.component;
  15442. var data = mpOption.data;
  15443. var itemShape;
  15444. var dataRange = component.dataRange;
  15445. var legend = component.legend;
  15446. var color;
  15447. var value;
  15448. var queryTarget = [
  15449. data[0],
  15450. mpOption
  15451. ];
  15452. var nColor;
  15453. var eColor;
  15454. var effect;
  15455. if (legend) {
  15456. color = legend.getColor(serie.name);
  15457. }
  15458. if (dataRange) {
  15459. value = data[0].value != null ? data[0].value : '';
  15460. color = isNaN(value) ? color : dataRange.getColor(value);
  15461. nColor = this.deepQuery(queryTarget, 'itemStyle.normal.color') || color;
  15462. eColor = this.deepQuery(queryTarget, 'itemStyle.emphasis.color') || nColor;
  15463. if (nColor == null && eColor == null) {
  15464. return;
  15465. }
  15466. }
  15467. color = this.deepMerge(queryTarget, 'itemStyle.normal').color || color;
  15468. var symbol = this.deepQuery(queryTarget, 'symbol') || 'circle';
  15469. symbol = symbol.replace('empty', '').replace(/\d/g, '');
  15470. effect = this.deepMerge([
  15471. data[0],
  15472. mpOption
  15473. ], 'effect');
  15474. var devicePixelRatio = window.devicePixelRatio || 1;
  15475. itemShape = new SymbolShape({
  15476. style: {
  15477. pointList: data,
  15478. color: color,
  15479. strokeColor: color,
  15480. shadowColor: effect.shadowColor || color,
  15481. shadowBlur: (effect.shadowBlur != null ? effect.shadowBlur : 8) * devicePixelRatio,
  15482. size: this.deepQuery(queryTarget, 'symbolSize'),
  15483. iconType: symbol,
  15484. brushType: 'fill',
  15485. lineWidth: 1
  15486. },
  15487. draggable: false,
  15488. hoverable: false
  15489. });
  15490. if (effect.show) {
  15491. itemShape.effect = effect;
  15492. }
  15493. return itemShape;
  15494. },
  15495. backupShapeList: function () {
  15496. if (this.shapeList && this.shapeList.length > 0) {
  15497. this.lastShapeList = this.shapeList;
  15498. this.shapeList = [];
  15499. } else {
  15500. this.lastShapeList = [];
  15501. }
  15502. },
  15503. addShapeList: function () {
  15504. var maxLenth = this.option.animationThreshold / (this.canvasSupported ? 2 : 4);
  15505. var lastShapeList = this.lastShapeList;
  15506. var shapeList = this.shapeList;
  15507. var isUpdate = lastShapeList.length > 0;
  15508. var duration = isUpdate ? this.query(this.option, 'animationDurationUpdate') : this.query(this.option, 'animationDuration');
  15509. var easing = this.query(this.option, 'animationEasing');
  15510. var delay;
  15511. var key;
  15512. var oldMap = {};
  15513. var newMap = {};
  15514. if (this.option.animation && !this.option.renderAsImage && shapeList.length < maxLenth && !this.motionlessOnce) {
  15515. for (var i = 0, l = lastShapeList.length; i < l; i++) {
  15516. key = this._getAnimationKey(lastShapeList[i]);
  15517. if (key.match('undefined')) {
  15518. this.zr.delShape(lastShapeList[i].id);
  15519. } else {
  15520. key += lastShapeList[i].type;
  15521. if (oldMap[key]) {
  15522. this.zr.delShape(lastShapeList[i].id);
  15523. } else {
  15524. oldMap[key] = lastShapeList[i];
  15525. }
  15526. }
  15527. }
  15528. for (var i = 0, l = shapeList.length; i < l; i++) {
  15529. key = this._getAnimationKey(shapeList[i]);
  15530. if (key.match('undefined')) {
  15531. this.zr.addShape(shapeList[i]);
  15532. } else {
  15533. key += shapeList[i].type;
  15534. newMap[key] = shapeList[i];
  15535. }
  15536. }
  15537. for (key in oldMap) {
  15538. if (!newMap[key]) {
  15539. this.zr.delShape(oldMap[key].id);
  15540. }
  15541. }
  15542. for (key in newMap) {
  15543. if (oldMap[key]) {
  15544. this.zr.delShape(oldMap[key].id);
  15545. this._animateMod(oldMap[key], newMap[key], duration, easing, 0, isUpdate);
  15546. } else {
  15547. delay = (this.type == ecConfig.CHART_TYPE_LINE || this.type == ecConfig.CHART_TYPE_RADAR) && key.indexOf('icon') !== 0 ? duration / 2 : 0;
  15548. this._animateMod(false, newMap[key], duration, easing, delay, isUpdate);
  15549. }
  15550. }
  15551. this.zr.refresh();
  15552. this.animationEffect();
  15553. } else {
  15554. this.motionlessOnce = false;
  15555. this.zr.delShape(lastShapeList);
  15556. for (var i = 0, l = shapeList.length; i < l; i++) {
  15557. this.zr.addShape(shapeList[i]);
  15558. }
  15559. }
  15560. },
  15561. _getAnimationKey: function (shape) {
  15562. if (this.type != ecConfig.CHART_TYPE_MAP) {
  15563. return ecData.get(shape, 'seriesIndex') + '_' + ecData.get(shape, 'dataIndex') + (shape._mark ? shape._mark : '') + (this.type === ecConfig.CHART_TYPE_RADAR ? ecData.get(shape, 'special') : '');
  15564. } else {
  15565. return ecData.get(shape, 'seriesIndex') + '_' + ecData.get(shape, 'dataIndex') + (shape._mark ? shape._mark : 'undefined');
  15566. }
  15567. },
  15568. _animateMod: function (oldShape, newShape, duration, easing, delay, isUpdate) {
  15569. switch (newShape.type) {
  15570. case 'polyline':
  15571. case 'half-smooth-polygon':
  15572. ecAnimation.pointList(this.zr, oldShape, newShape, duration, easing);
  15573. break;
  15574. case 'rectangle':
  15575. ecAnimation.rectangle(this.zr, oldShape, newShape, duration, easing);
  15576. break;
  15577. case 'image':
  15578. case 'icon':
  15579. ecAnimation.icon(this.zr, oldShape, newShape, duration, easing, delay);
  15580. break;
  15581. case 'candle':
  15582. if (!isUpdate) {
  15583. ecAnimation.candle(this.zr, oldShape, newShape, duration, easing);
  15584. } else {
  15585. this.zr.addShape(newShape);
  15586. }
  15587. break;
  15588. case 'ring':
  15589. case 'sector':
  15590. case 'circle':
  15591. if (!isUpdate) {
  15592. ecAnimation.ring(this.zr, oldShape, newShape, duration + (ecData.get(newShape, 'dataIndex') || 0) % 20 * 100, easing);
  15593. } else if (newShape.type === 'sector') {
  15594. ecAnimation.sector(this.zr, oldShape, newShape, duration, easing);
  15595. } else {
  15596. this.zr.addShape(newShape);
  15597. }
  15598. break;
  15599. case 'text':
  15600. ecAnimation.text(this.zr, oldShape, newShape, duration, easing);
  15601. break;
  15602. case 'polygon':
  15603. if (!isUpdate) {
  15604. ecAnimation.polygon(this.zr, oldShape, newShape, duration, easing);
  15605. } else {
  15606. ecAnimation.pointList(this.zr, oldShape, newShape, duration, easing);
  15607. }
  15608. break;
  15609. case 'ribbon':
  15610. ecAnimation.ribbon(this.zr, oldShape, newShape, duration, easing);
  15611. break;
  15612. case 'gauge-pointer':
  15613. ecAnimation.gaugePointer(this.zr, oldShape, newShape, duration, easing);
  15614. break;
  15615. case 'mark-line':
  15616. ecAnimation.markline(this.zr, oldShape, newShape, duration, easing);
  15617. break;
  15618. case 'bezier-curve':
  15619. case 'line':
  15620. ecAnimation.line(this.zr, oldShape, newShape, duration, easing);
  15621. break;
  15622. default:
  15623. this.zr.addShape(newShape);
  15624. break;
  15625. }
  15626. },
  15627. animationMark: function (duration, easing, shapeList) {
  15628. var shapeList = shapeList || this.shapeList;
  15629. for (var i = 0, l = shapeList.length; i < l; i++) {
  15630. if (!shapeList[i]._mark) {
  15631. continue;
  15632. }
  15633. this._animateMod(false, shapeList[i], duration, easing, 0, true);
  15634. }
  15635. this.animationEffect(shapeList);
  15636. },
  15637. animationEffect: function (shapeList) {
  15638. !shapeList && this.clearEffectShape();
  15639. shapeList = shapeList || this.shapeList;
  15640. if (shapeList == null) {
  15641. return;
  15642. }
  15643. var zlevel = ecConfig.EFFECT_ZLEVEL;
  15644. if (this.canvasSupported) {
  15645. this.zr.modLayer(zlevel, {
  15646. motionBlur: true,
  15647. lastFrameAlpha: 0.95
  15648. });
  15649. }
  15650. var shape;
  15651. for (var i = 0, l = shapeList.length; i < l; i++) {
  15652. shape = shapeList[i];
  15653. if (!(shape._mark && shape.effect && shape.effect.show && ecEffect[shape._mark])) {
  15654. continue;
  15655. }
  15656. ecEffect[shape._mark](this.zr, this.effectList, shape, zlevel);
  15657. this.effectList[this.effectList.length - 1]._mark = shape._mark;
  15658. }
  15659. },
  15660. clearEffectShape: function (clearMotionBlur) {
  15661. var effectList = this.effectList;
  15662. if (this.zr && effectList && effectList.length > 0) {
  15663. clearMotionBlur && this.zr.modLayer(ecConfig.EFFECT_ZLEVEL, { motionBlur: false });
  15664. this.zr.delShape(effectList);
  15665. for (var i = 0; i < effectList.length; i++) {
  15666. if (effectList[i].effectAnimator) {
  15667. effectList[i].effectAnimator.stop();
  15668. }
  15669. }
  15670. }
  15671. this.effectList = [];
  15672. },
  15673. addMark: function (seriesIndex, markData, markType) {
  15674. var serie = this.series[seriesIndex];
  15675. if (this.selectedMap[serie.name]) {
  15676. var duration = this.query(this.option, 'animationDurationUpdate');
  15677. var easing = this.query(this.option, 'animationEasing');
  15678. var oriMarkData = serie[markType].data;
  15679. var lastLength = this.shapeList.length;
  15680. serie[markType].data = markData.data;
  15681. this['_build' + markType.replace('m', 'M')](seriesIndex);
  15682. if (this.option.animation && !this.option.renderAsImage) {
  15683. this.animationMark(duration, easing, this.shapeList.slice(lastLength));
  15684. } else {
  15685. for (var i = lastLength, l = this.shapeList.length; i < l; i++) {
  15686. this.zr.addShape(this.shapeList[i]);
  15687. }
  15688. this.zr.refreshNextFrame();
  15689. }
  15690. serie[markType].data = oriMarkData;
  15691. }
  15692. },
  15693. delMark: function (seriesIndex, markName, markType) {
  15694. markType = markType.replace('mark', '').replace('large', '').toLowerCase();
  15695. var serie = this.series[seriesIndex];
  15696. if (this.selectedMap[serie.name]) {
  15697. var needRefresh = false;
  15698. var shapeList = [
  15699. this.shapeList,
  15700. this.effectList
  15701. ];
  15702. var len = 2;
  15703. while (len--) {
  15704. for (var i = 0, l = shapeList[len].length; i < l; i++) {
  15705. if (shapeList[len][i]._mark == markType && ecData.get(shapeList[len][i], 'seriesIndex') == seriesIndex && ecData.get(shapeList[len][i], 'name') == markName) {
  15706. this.zr.delShape(shapeList[len][i].id);
  15707. shapeList[len].splice(i, 1);
  15708. needRefresh = true;
  15709. break;
  15710. }
  15711. }
  15712. }
  15713. needRefresh && this.zr.refreshNextFrame();
  15714. }
  15715. }
  15716. };
  15717. zrUtil.inherits(Base, ComponentBase);
  15718. return Base;
  15719. });define('zrender/shape/Circle', [
  15720. 'require',
  15721. './Base',
  15722. '../tool/util'
  15723. ], function (require) {
  15724. 'use strict';
  15725. var Base = require('./Base');
  15726. var Circle = function (options) {
  15727. Base.call(this, options);
  15728. };
  15729. Circle.prototype = {
  15730. type: 'circle',
  15731. buildPath: function (ctx, style) {
  15732. ctx.moveTo(style.x + style.r, style.y);
  15733. ctx.arc(style.x, style.y, style.r, 0, Math.PI * 2, true);
  15734. return;
  15735. },
  15736. getRect: function (style) {
  15737. if (style.__rect) {
  15738. return style.__rect;
  15739. }
  15740. var lineWidth;
  15741. if (style.brushType == 'stroke' || style.brushType == 'fill') {
  15742. lineWidth = style.lineWidth || 1;
  15743. } else {
  15744. lineWidth = 0;
  15745. }
  15746. style.__rect = {
  15747. x: Math.round(style.x - style.r - lineWidth / 2),
  15748. y: Math.round(style.y - style.r - lineWidth / 2),
  15749. width: style.r * 2 + lineWidth,
  15750. height: style.r * 2 + lineWidth
  15751. };
  15752. return style.__rect;
  15753. }
  15754. };
  15755. require('../tool/util').inherits(Circle, Base);
  15756. return Circle;
  15757. });define('echarts/util/accMath', [], function () {
  15758. function accDiv(arg1, arg2) {
  15759. var s1 = arg1.toString();
  15760. var s2 = arg2.toString();
  15761. var m = 0;
  15762. try {
  15763. m = s2.split('.')[1].length;
  15764. } catch (e) {
  15765. }
  15766. try {
  15767. m -= s1.split('.')[1].length;
  15768. } catch (e) {
  15769. }
  15770. return (s1.replace('.', '') - 0) / (s2.replace('.', '') - 0) * Math.pow(10, m);
  15771. }
  15772. function accMul(arg1, arg2) {
  15773. var s1 = arg1.toString();
  15774. var s2 = arg2.toString();
  15775. var m = 0;
  15776. try {
  15777. m += s1.split('.')[1].length;
  15778. } catch (e) {
  15779. }
  15780. try {
  15781. m += s2.split('.')[1].length;
  15782. } catch (e) {
  15783. }
  15784. return (s1.replace('.', '') - 0) * (s2.replace('.', '') - 0) / Math.pow(10, m);
  15785. }
  15786. function accAdd(arg1, arg2) {
  15787. var r1 = 0;
  15788. var r2 = 0;
  15789. try {
  15790. r1 = arg1.toString().split('.')[1].length;
  15791. } catch (e) {
  15792. }
  15793. try {
  15794. r2 = arg2.toString().split('.')[1].length;
  15795. } catch (e) {
  15796. }
  15797. var m = Math.pow(10, Math.max(r1, r2));
  15798. return (Math.round(arg1 * m) + Math.round(arg2 * m)) / m;
  15799. }
  15800. function accSub(arg1, arg2) {
  15801. return accAdd(arg1, -arg2);
  15802. }
  15803. return {
  15804. accDiv: accDiv,
  15805. accMul: accMul,
  15806. accAdd: accAdd,
  15807. accSub: accSub
  15808. };
  15809. });define('echarts/util/shape/Icon', [
  15810. 'require',
  15811. 'zrender/tool/util',
  15812. 'zrender/shape/Star',
  15813. 'zrender/shape/Heart',
  15814. 'zrender/shape/Droplet',
  15815. 'zrender/shape/Image',
  15816. 'zrender/shape/Base'
  15817. ], function (require) {
  15818. var zrUtil = require('zrender/tool/util');
  15819. function _iconMark(ctx, style) {
  15820. var x = style.x;
  15821. var y = style.y;
  15822. var dx = style.width / 16;
  15823. var dy = style.height / 16;
  15824. ctx.moveTo(x, y + style.height);
  15825. ctx.lineTo(x + 5 * dx, y + 14 * dy);
  15826. ctx.lineTo(x + style.width, y + 3 * dy);
  15827. ctx.lineTo(x + 13 * dx, y);
  15828. ctx.lineTo(x + 2 * dx, y + 11 * dy);
  15829. ctx.lineTo(x, y + style.height);
  15830. ctx.moveTo(x + 6 * dx, y + 10 * dy);
  15831. ctx.lineTo(x + 14 * dx, y + 2 * dy);
  15832. ctx.moveTo(x + 10 * dx, y + 13 * dy);
  15833. ctx.lineTo(x + style.width, y + 13 * dy);
  15834. ctx.moveTo(x + 13 * dx, y + 10 * dy);
  15835. ctx.lineTo(x + 13 * dx, y + style.height);
  15836. }
  15837. function _iconMarkUndo(ctx, style) {
  15838. var x = style.x;
  15839. var y = style.y;
  15840. var dx = style.width / 16;
  15841. var dy = style.height / 16;
  15842. ctx.moveTo(x, y + style.height);
  15843. ctx.lineTo(x + 5 * dx, y + 14 * dy);
  15844. ctx.lineTo(x + style.width, y + 3 * dy);
  15845. ctx.lineTo(x + 13 * dx, y);
  15846. ctx.lineTo(x + 2 * dx, y + 11 * dy);
  15847. ctx.lineTo(x, y + style.height);
  15848. ctx.moveTo(x + 6 * dx, y + 10 * dy);
  15849. ctx.lineTo(x + 14 * dx, y + 2 * dy);
  15850. ctx.moveTo(x + 10 * dx, y + 13 * dy);
  15851. ctx.lineTo(x + style.width, y + 13 * dy);
  15852. }
  15853. function _iconMarkClear(ctx, style) {
  15854. var x = style.x;
  15855. var y = style.y;
  15856. var dx = style.width / 16;
  15857. var dy = style.height / 16;
  15858. ctx.moveTo(x + 4 * dx, y + 15 * dy);
  15859. ctx.lineTo(x + 9 * dx, y + 13 * dy);
  15860. ctx.lineTo(x + 14 * dx, y + 8 * dy);
  15861. ctx.lineTo(x + 11 * dx, y + 5 * dy);
  15862. ctx.lineTo(x + 6 * dx, y + 10 * dy);
  15863. ctx.lineTo(x + 4 * dx, y + 15 * dy);
  15864. ctx.moveTo(x + 5 * dx, y);
  15865. ctx.lineTo(x + 11 * dx, y);
  15866. ctx.moveTo(x + 5 * dx, y + dy);
  15867. ctx.lineTo(x + 11 * dx, y + dy);
  15868. ctx.moveTo(x, y + 2 * dy);
  15869. ctx.lineTo(x + style.width, y + 2 * dy);
  15870. ctx.moveTo(x, y + 5 * dy);
  15871. ctx.lineTo(x + 3 * dx, y + style.height);
  15872. ctx.lineTo(x + 13 * dx, y + style.height);
  15873. ctx.lineTo(x + style.width, y + 5 * dy);
  15874. }
  15875. function _iconDataZoom(ctx, style) {
  15876. var x = style.x;
  15877. var y = style.y;
  15878. var dx = style.width / 16;
  15879. var dy = style.height / 16;
  15880. ctx.moveTo(x, y + 3 * dy);
  15881. ctx.lineTo(x + 6 * dx, y + 3 * dy);
  15882. ctx.moveTo(x + 3 * dx, y);
  15883. ctx.lineTo(x + 3 * dx, y + 6 * dy);
  15884. ctx.moveTo(x + 3 * dx, y + 8 * dy);
  15885. ctx.lineTo(x + 3 * dx, y + style.height);
  15886. ctx.lineTo(x + style.width, y + style.height);
  15887. ctx.lineTo(x + style.width, y + 3 * dy);
  15888. ctx.lineTo(x + 8 * dx, y + 3 * dy);
  15889. }
  15890. function _iconDataZoomReset(ctx, style) {
  15891. var x = style.x;
  15892. var y = style.y;
  15893. var dx = style.width / 16;
  15894. var dy = style.height / 16;
  15895. ctx.moveTo(x + 6 * dx, y);
  15896. ctx.lineTo(x + 2 * dx, y + 3 * dy);
  15897. ctx.lineTo(x + 6 * dx, y + 6 * dy);
  15898. ctx.moveTo(x + 2 * dx, y + 3 * dy);
  15899. ctx.lineTo(x + 14 * dx, y + 3 * dy);
  15900. ctx.lineTo(x + 14 * dx, y + 11 * dy);
  15901. ctx.moveTo(x + 2 * dx, y + 5 * dy);
  15902. ctx.lineTo(x + 2 * dx, y + 13 * dy);
  15903. ctx.lineTo(x + 14 * dx, y + 13 * dy);
  15904. ctx.moveTo(x + 10 * dx, y + 10 * dy);
  15905. ctx.lineTo(x + 14 * dx, y + 13 * dy);
  15906. ctx.lineTo(x + 10 * dx, y + style.height);
  15907. }
  15908. function _iconRestore(ctx, style) {
  15909. var x = style.x;
  15910. var y = style.y;
  15911. var dx = style.width / 16;
  15912. var dy = style.height / 16;
  15913. var r = style.width / 2;
  15914. ctx.lineWidth = 1.5;
  15915. ctx.arc(x + r, y + r, r - dx, 0, Math.PI * 2 / 3);
  15916. ctx.moveTo(x + 3 * dx, y + style.height);
  15917. ctx.lineTo(x + 0 * dx, y + 12 * dy);
  15918. ctx.lineTo(x + 5 * dx, y + 11 * dy);
  15919. ctx.moveTo(x, y + 8 * dy);
  15920. ctx.arc(x + r, y + r, r - dx, Math.PI, Math.PI * 5 / 3);
  15921. ctx.moveTo(x + 13 * dx, y);
  15922. ctx.lineTo(x + style.width, y + 4 * dy);
  15923. ctx.lineTo(x + 11 * dx, y + 5 * dy);
  15924. }
  15925. function _iconLineChart(ctx, style) {
  15926. var x = style.x;
  15927. var y = style.y;
  15928. var dx = style.width / 16;
  15929. var dy = style.height / 16;
  15930. ctx.moveTo(x, y);
  15931. ctx.lineTo(x, y + style.height);
  15932. ctx.lineTo(x + style.width, y + style.height);
  15933. ctx.moveTo(x + 2 * dx, y + 14 * dy);
  15934. ctx.lineTo(x + 7 * dx, y + 6 * dy);
  15935. ctx.lineTo(x + 11 * dx, y + 11 * dy);
  15936. ctx.lineTo(x + 15 * dx, y + 2 * dy);
  15937. }
  15938. function _iconBarChart(ctx, style) {
  15939. var x = style.x;
  15940. var y = style.y;
  15941. var dx = style.width / 16;
  15942. var dy = style.height / 16;
  15943. ctx.moveTo(x, y);
  15944. ctx.lineTo(x, y + style.height);
  15945. ctx.lineTo(x + style.width, y + style.height);
  15946. ctx.moveTo(x + 3 * dx, y + 14 * dy);
  15947. ctx.lineTo(x + 3 * dx, y + 6 * dy);
  15948. ctx.lineTo(x + 4 * dx, y + 6 * dy);
  15949. ctx.lineTo(x + 4 * dx, y + 14 * dy);
  15950. ctx.moveTo(x + 7 * dx, y + 14 * dy);
  15951. ctx.lineTo(x + 7 * dx, y + 2 * dy);
  15952. ctx.lineTo(x + 8 * dx, y + 2 * dy);
  15953. ctx.lineTo(x + 8 * dx, y + 14 * dy);
  15954. ctx.moveTo(x + 11 * dx, y + 14 * dy);
  15955. ctx.lineTo(x + 11 * dx, y + 9 * dy);
  15956. ctx.lineTo(x + 12 * dx, y + 9 * dy);
  15957. ctx.lineTo(x + 12 * dx, y + 14 * dy);
  15958. }
  15959. function _iconPieChart(ctx, style) {
  15960. var x = style.x;
  15961. var y = style.y;
  15962. var width = style.width - 2;
  15963. var height = style.height - 2;
  15964. var r = Math.min(width, height) / 2;
  15965. y += 2;
  15966. ctx.moveTo(x + r + 3, y + r - 3);
  15967. ctx.arc(x + r + 3, y + r - 3, r - 1, 0, -Math.PI / 2, true);
  15968. ctx.lineTo(x + r + 3, y + r - 3);
  15969. ctx.moveTo(x + r, y);
  15970. ctx.lineTo(x + r, y + r);
  15971. ctx.arc(x + r, y + r, r, -Math.PI / 2, Math.PI * 2, true);
  15972. ctx.lineTo(x + r, y + r);
  15973. ctx.lineWidth = 1.5;
  15974. }
  15975. function _iconFunnelChart(ctx, style) {
  15976. var x = style.x;
  15977. var y = style.y;
  15978. var dx = style.width / 16;
  15979. var dy = style.height / 16;
  15980. y -= dy;
  15981. ctx.moveTo(x + 1 * dx, y + 2 * dy);
  15982. ctx.lineTo(x + 15 * dx, y + 2 * dy);
  15983. ctx.lineTo(x + 14 * dx, y + 3 * dy);
  15984. ctx.lineTo(x + 2 * dx, y + 3 * dy);
  15985. ctx.moveTo(x + 3 * dx, y + 6 * dy);
  15986. ctx.lineTo(x + 13 * dx, y + 6 * dy);
  15987. ctx.lineTo(x + 12 * dx, y + 7 * dy);
  15988. ctx.lineTo(x + 4 * dx, y + 7 * dy);
  15989. ctx.moveTo(x + 5 * dx, y + 10 * dy);
  15990. ctx.lineTo(x + 11 * dx, y + 10 * dy);
  15991. ctx.lineTo(x + 10 * dx, y + 11 * dy);
  15992. ctx.lineTo(x + 6 * dx, y + 11 * dy);
  15993. ctx.moveTo(x + 7 * dx, y + 14 * dy);
  15994. ctx.lineTo(x + 9 * dx, y + 14 * dy);
  15995. ctx.lineTo(x + 8 * dx, y + 15 * dy);
  15996. ctx.lineTo(x + 7 * dx, y + 15 * dy);
  15997. }
  15998. function _iconForceChart(ctx, style) {
  15999. var x = style.x;
  16000. var y = style.y;
  16001. var width = style.width;
  16002. var height = style.height;
  16003. var dx = width / 16;
  16004. var dy = height / 16;
  16005. var r = Math.min(dx, dy) * 2;
  16006. ctx.moveTo(x + dx + r, y + dy + r);
  16007. ctx.arc(x + dx, y + dy, r, Math.PI / 4, Math.PI * 3);
  16008. ctx.lineTo(x + 7 * dx - r, y + 6 * dy - r);
  16009. ctx.arc(x + 7 * dx, y + 6 * dy, r, Math.PI / 4 * 5, Math.PI * 4);
  16010. ctx.arc(x + 7 * dx, y + 6 * dy, r / 2, Math.PI / 4 * 5, Math.PI * 4);
  16011. ctx.moveTo(x + 7 * dx - r / 2, y + 6 * dy + r);
  16012. ctx.lineTo(x + dx + r, y + 14 * dy - r);
  16013. ctx.arc(x + dx, y + 14 * dy, r, -Math.PI / 4, Math.PI * 2);
  16014. ctx.moveTo(x + 7 * dx + r / 2, y + 6 * dy);
  16015. ctx.lineTo(x + 14 * dx - r, y + 10 * dy - r / 2);
  16016. ctx.moveTo(x + 16 * dx, y + 10 * dy);
  16017. ctx.arc(x + 14 * dx, y + 10 * dy, r, 0, Math.PI * 3);
  16018. ctx.lineWidth = 1.5;
  16019. }
  16020. function _iconChordChart(ctx, style) {
  16021. var x = style.x;
  16022. var y = style.y;
  16023. var width = style.width;
  16024. var height = style.height;
  16025. var r = Math.min(width, height) / 2;
  16026. ctx.moveTo(x + width, y + height / 2);
  16027. ctx.arc(x + r, y + r, r, 0, Math.PI * 2);
  16028. ctx.arc(x + r, y, r, Math.PI / 4, Math.PI / 5 * 4);
  16029. ctx.arc(x, y + r, r, -Math.PI / 3, Math.PI / 3);
  16030. ctx.arc(x + width, y + height, r, Math.PI, Math.PI / 2 * 3);
  16031. ctx.lineWidth = 1.5;
  16032. }
  16033. function _iconStackChart(ctx, style) {
  16034. var x = style.x;
  16035. var y = style.y;
  16036. var width = style.width;
  16037. var height = style.height;
  16038. var dy = Math.round(height / 3);
  16039. var delta = Math.round((dy - 2) / 2);
  16040. var len = 3;
  16041. while (len--) {
  16042. ctx.rect(x, y + dy * len + delta, width, 2);
  16043. }
  16044. }
  16045. function _iconTiledChart(ctx, style) {
  16046. var x = style.x;
  16047. var y = style.y;
  16048. var width = style.width;
  16049. var height = style.height;
  16050. var dx = Math.round(width / 3);
  16051. var delta = Math.round((dx - 2) / 2);
  16052. var len = 3;
  16053. while (len--) {
  16054. ctx.rect(x + dx * len + delta, y, 2, height);
  16055. }
  16056. }
  16057. function _iconDataView(ctx, style) {
  16058. var x = style.x;
  16059. var y = style.y;
  16060. var dx = style.width / 16;
  16061. ctx.moveTo(x + dx, y);
  16062. ctx.lineTo(x + dx, y + style.height);
  16063. ctx.lineTo(x + 15 * dx, y + style.height);
  16064. ctx.lineTo(x + 15 * dx, y);
  16065. ctx.lineTo(x + dx, y);
  16066. ctx.moveTo(x + 3 * dx, y + 3 * dx);
  16067. ctx.lineTo(x + 13 * dx, y + 3 * dx);
  16068. ctx.moveTo(x + 3 * dx, y + 6 * dx);
  16069. ctx.lineTo(x + 13 * dx, y + 6 * dx);
  16070. ctx.moveTo(x + 3 * dx, y + 9 * dx);
  16071. ctx.lineTo(x + 13 * dx, y + 9 * dx);
  16072. ctx.moveTo(x + 3 * dx, y + 12 * dx);
  16073. ctx.lineTo(x + 9 * dx, y + 12 * dx);
  16074. }
  16075. function _iconSave(ctx, style) {
  16076. var x = style.x;
  16077. var y = style.y;
  16078. var dx = style.width / 16;
  16079. var dy = style.height / 16;
  16080. ctx.moveTo(x, y);
  16081. ctx.lineTo(x, y + style.height);
  16082. ctx.lineTo(x + style.width, y + style.height);
  16083. ctx.lineTo(x + style.width, y);
  16084. ctx.lineTo(x, y);
  16085. ctx.moveTo(x + 4 * dx, y);
  16086. ctx.lineTo(x + 4 * dx, y + 8 * dy);
  16087. ctx.lineTo(x + 12 * dx, y + 8 * dy);
  16088. ctx.lineTo(x + 12 * dx, y);
  16089. ctx.moveTo(x + 6 * dx, y + 11 * dy);
  16090. ctx.lineTo(x + 6 * dx, y + 13 * dy);
  16091. ctx.lineTo(x + 10 * dx, y + 13 * dy);
  16092. ctx.lineTo(x + 10 * dx, y + 11 * dy);
  16093. ctx.lineTo(x + 6 * dx, y + 11 * dy);
  16094. }
  16095. function _iconCross(ctx, style) {
  16096. var x = style.x;
  16097. var y = style.y;
  16098. var width = style.width;
  16099. var height = style.height;
  16100. ctx.moveTo(x, y + height / 2);
  16101. ctx.lineTo(x + width, y + height / 2);
  16102. ctx.moveTo(x + width / 2, y);
  16103. ctx.lineTo(x + width / 2, y + height);
  16104. }
  16105. function _iconCircle(ctx, style) {
  16106. var width = style.width / 2;
  16107. var height = style.height / 2;
  16108. var r = Math.min(width, height);
  16109. ctx.moveTo(style.x + width + r, style.y + height);
  16110. ctx.arc(style.x + width, style.y + height, r, 0, Math.PI * 2);
  16111. ctx.closePath();
  16112. }
  16113. function _iconRectangle(ctx, style) {
  16114. ctx.rect(style.x, style.y, style.width, style.height);
  16115. ctx.closePath();
  16116. }
  16117. function _iconTriangle(ctx, style) {
  16118. var width = style.width / 2;
  16119. var height = style.height / 2;
  16120. var x = style.x + width;
  16121. var y = style.y + height;
  16122. var symbolSize = Math.min(width, height);
  16123. ctx.moveTo(x, y - symbolSize);
  16124. ctx.lineTo(x + symbolSize, y + symbolSize);
  16125. ctx.lineTo(x - symbolSize, y + symbolSize);
  16126. ctx.lineTo(x, y - symbolSize);
  16127. ctx.closePath();
  16128. }
  16129. function _iconDiamond(ctx, style) {
  16130. var width = style.width / 2;
  16131. var height = style.height / 2;
  16132. var x = style.x + width;
  16133. var y = style.y + height;
  16134. var symbolSize = Math.min(width, height);
  16135. ctx.moveTo(x, y - symbolSize);
  16136. ctx.lineTo(x + symbolSize, y);
  16137. ctx.lineTo(x, y + symbolSize);
  16138. ctx.lineTo(x - symbolSize, y);
  16139. ctx.lineTo(x, y - symbolSize);
  16140. ctx.closePath();
  16141. }
  16142. function _iconArrow(ctx, style) {
  16143. var x = style.x;
  16144. var y = style.y;
  16145. var dx = style.width / 16;
  16146. ctx.moveTo(x + 8 * dx, y);
  16147. ctx.lineTo(x + dx, y + style.height);
  16148. ctx.lineTo(x + 8 * dx, y + style.height / 4 * 3);
  16149. ctx.lineTo(x + 15 * dx, y + style.height);
  16150. ctx.lineTo(x + 8 * dx, y);
  16151. ctx.closePath();
  16152. }
  16153. function _iconStar(ctx, style) {
  16154. var StarShape = require('zrender/shape/Star');
  16155. var width = style.width / 2;
  16156. var height = style.height / 2;
  16157. StarShape.prototype.buildPath(ctx, {
  16158. x: style.x + width,
  16159. y: style.y + height,
  16160. r: Math.min(width, height),
  16161. n: style.n || 5
  16162. });
  16163. }
  16164. function _iconHeart(ctx, style) {
  16165. var HeartShape = require('zrender/shape/Heart');
  16166. HeartShape.prototype.buildPath(ctx, {
  16167. x: style.x + style.width / 2,
  16168. y: style.y + style.height * 0.2,
  16169. a: style.width / 2,
  16170. b: style.height * 0.8
  16171. });
  16172. }
  16173. function _iconDroplet(ctx, style) {
  16174. var DropletShape = require('zrender/shape/Droplet');
  16175. DropletShape.prototype.buildPath(ctx, {
  16176. x: style.x + style.width * 0.5,
  16177. y: style.y + style.height * 0.5,
  16178. a: style.width * 0.5,
  16179. b: style.height * 0.8
  16180. });
  16181. }
  16182. function _iconPin(ctx, style) {
  16183. var x = style.x;
  16184. var y = style.y - style.height / 2 * 1.5;
  16185. var width = style.width / 2;
  16186. var height = style.height / 2;
  16187. var r = Math.min(width, height);
  16188. ctx.arc(x + width, y + height, r, Math.PI / 5 * 4, Math.PI / 5);
  16189. ctx.lineTo(x + width, y + height + r * 1.5);
  16190. ctx.closePath();
  16191. }
  16192. function _iconImage(ctx, style, refreshNextFrame) {
  16193. var ImageShape = require('zrender/shape/Image');
  16194. this._imageShape = this._imageShape || new ImageShape({ style: {} });
  16195. for (var name in style) {
  16196. this._imageShape.style[name] = style[name];
  16197. }
  16198. this._imageShape.brush(ctx, false, refreshNextFrame);
  16199. }
  16200. var Base = require('zrender/shape/Base');
  16201. function Icon(options) {
  16202. Base.call(this, options);
  16203. }
  16204. Icon.prototype = {
  16205. type: 'icon',
  16206. iconLibrary: {
  16207. mark: _iconMark,
  16208. markUndo: _iconMarkUndo,
  16209. markClear: _iconMarkClear,
  16210. dataZoom: _iconDataZoom,
  16211. dataZoomReset: _iconDataZoomReset,
  16212. restore: _iconRestore,
  16213. lineChart: _iconLineChart,
  16214. barChart: _iconBarChart,
  16215. pieChart: _iconPieChart,
  16216. funnelChart: _iconFunnelChart,
  16217. forceChart: _iconForceChart,
  16218. chordChart: _iconChordChart,
  16219. stackChart: _iconStackChart,
  16220. tiledChart: _iconTiledChart,
  16221. dataView: _iconDataView,
  16222. saveAsImage: _iconSave,
  16223. cross: _iconCross,
  16224. circle: _iconCircle,
  16225. rectangle: _iconRectangle,
  16226. triangle: _iconTriangle,
  16227. diamond: _iconDiamond,
  16228. arrow: _iconArrow,
  16229. star: _iconStar,
  16230. heart: _iconHeart,
  16231. droplet: _iconDroplet,
  16232. pin: _iconPin,
  16233. image: _iconImage
  16234. },
  16235. brush: function (ctx, isHighlight, refreshNextFrame) {
  16236. var style = isHighlight ? this.highlightStyle : this.style;
  16237. style = style || {};
  16238. var iconType = style.iconType || this.style.iconType;
  16239. if (iconType === 'image') {
  16240. var ImageShape = require('zrender/shape/Image');
  16241. ImageShape.prototype.brush.call(this, ctx, isHighlight, refreshNextFrame);
  16242. } else {
  16243. var style = this.beforeBrush(ctx, isHighlight);
  16244. ctx.beginPath();
  16245. this.buildPath(ctx, style, refreshNextFrame);
  16246. switch (style.brushType) {
  16247. case 'both':
  16248. ctx.fill();
  16249. case 'stroke':
  16250. style.lineWidth > 0 && ctx.stroke();
  16251. break;
  16252. default:
  16253. ctx.fill();
  16254. }
  16255. this.drawText(ctx, style, this.style);
  16256. this.afterBrush(ctx);
  16257. }
  16258. },
  16259. buildPath: function (ctx, style, refreshNextFrame) {
  16260. if (this.iconLibrary[style.iconType]) {
  16261. this.iconLibrary[style.iconType].call(this, ctx, style, refreshNextFrame);
  16262. } else {
  16263. ctx.moveTo(style.x, style.y);
  16264. ctx.lineTo(style.x + style.width, style.y);
  16265. ctx.lineTo(style.x + style.width, style.y + style.height);
  16266. ctx.lineTo(style.x, style.y + style.height);
  16267. ctx.lineTo(style.x, style.y);
  16268. ctx.closePath();
  16269. }
  16270. return;
  16271. },
  16272. getRect: function (style) {
  16273. if (style.__rect) {
  16274. return style.__rect;
  16275. }
  16276. style.__rect = {
  16277. x: Math.round(style.x),
  16278. y: Math.round(style.y - (style.iconType == 'pin' ? style.height / 2 * 1.5 : 0)),
  16279. width: style.width,
  16280. height: style.height * (style.iconType === 'pin' ? 1.25 : 1)
  16281. };
  16282. return style.__rect;
  16283. },
  16284. isCover: function (x, y) {
  16285. var originPos = this.transformCoordToLocal(x, y);
  16286. x = originPos[0];
  16287. y = originPos[1];
  16288. var rect = this.style.__rect;
  16289. if (!rect) {
  16290. rect = this.style.__rect = this.getRect(this.style);
  16291. }
  16292. var delta = rect.height < 8 || rect.width < 8 ? 4 : 0;
  16293. return x >= rect.x - delta && x <= rect.x + rect.width + delta && y >= rect.y - delta && y <= rect.y + rect.height + delta;
  16294. }
  16295. };
  16296. zrUtil.inherits(Icon, Base);
  16297. return Icon;
  16298. });define('echarts/util/shape/MarkLine', [
  16299. 'require',
  16300. 'zrender/shape/Base',
  16301. './Icon',
  16302. 'zrender/shape/Line',
  16303. 'zrender/shape/BezierCurve',
  16304. 'zrender/tool/area',
  16305. 'zrender/shape/util/dashedLineTo',
  16306. 'zrender/tool/util',
  16307. 'zrender/tool/curve'
  16308. ], function (require) {
  16309. var Base = require('zrender/shape/Base');
  16310. var IconShape = require('./Icon');
  16311. var LineShape = require('zrender/shape/Line');
  16312. var lineInstance = new LineShape({});
  16313. var CurveShape = require('zrender/shape/BezierCurve');
  16314. var curveInstance = new CurveShape({});
  16315. var area = require('zrender/tool/area');
  16316. var dashedLineTo = require('zrender/shape/util/dashedLineTo');
  16317. var zrUtil = require('zrender/tool/util');
  16318. var curveTool = require('zrender/tool/curve');
  16319. function MarkLine(options) {
  16320. Base.call(this, options);
  16321. if (this.style.curveness > 0) {
  16322. this.updatePoints(this.style);
  16323. }
  16324. if (this.highlightStyle.curveness > 0) {
  16325. this.updatePoints(this.highlightStyle);
  16326. }
  16327. }
  16328. MarkLine.prototype = {
  16329. type: 'mark-line',
  16330. brush: function (ctx, isHighlight) {
  16331. var style = this.style;
  16332. if (isHighlight) {
  16333. style = this.getHighlightStyle(style, this.highlightStyle || {});
  16334. }
  16335. ctx.save();
  16336. this.setContext(ctx, style);
  16337. this.setTransform(ctx);
  16338. ctx.save();
  16339. ctx.beginPath();
  16340. this.buildPath(ctx, style);
  16341. ctx.stroke();
  16342. ctx.restore();
  16343. this.brushSymbol(ctx, style, 0);
  16344. this.brushSymbol(ctx, style, 1);
  16345. this.drawText(ctx, style, this.style);
  16346. ctx.restore();
  16347. },
  16348. buildPath: function (ctx, style) {
  16349. var lineType = style.lineType || 'solid';
  16350. ctx.moveTo(style.xStart, style.yStart);
  16351. if (style.curveness > 0) {
  16352. var lineDash = null;
  16353. switch (lineType) {
  16354. case 'dashed':
  16355. lineDash = [
  16356. 5,
  16357. 5
  16358. ];
  16359. break;
  16360. case 'dotted':
  16361. lineDash = [
  16362. 1,
  16363. 1
  16364. ];
  16365. break;
  16366. }
  16367. if (lineDash && ctx.setLineDash) {
  16368. ctx.setLineDash(lineDash);
  16369. }
  16370. ctx.quadraticCurveTo(style.cpX1, style.cpY1, style.xEnd, style.yEnd);
  16371. } else {
  16372. if (lineType == 'solid') {
  16373. ctx.lineTo(style.xEnd, style.yEnd);
  16374. } else {
  16375. var dashLength = (style.lineWidth || 1) * (style.lineType == 'dashed' ? 5 : 1);
  16376. dashedLineTo(ctx, style.xStart, style.yStart, style.xEnd, style.yEnd, dashLength);
  16377. }
  16378. }
  16379. },
  16380. updatePoints: function (style) {
  16381. var curveness = style.curveness || 0;
  16382. var inv = 1;
  16383. var x0 = style.xStart;
  16384. var y0 = style.yStart;
  16385. var x2 = style.xEnd;
  16386. var y2 = style.yEnd;
  16387. var x1 = (x0 + x2) / 2 - inv * (y0 - y2) * curveness;
  16388. var y1 = (y0 + y2) / 2 - inv * (x2 - x0) * curveness;
  16389. style.cpX1 = x1;
  16390. style.cpY1 = y1;
  16391. },
  16392. brushSymbol: function (ctx, style, idx) {
  16393. if (style.symbol[idx] == 'none') {
  16394. return;
  16395. }
  16396. ctx.save();
  16397. ctx.beginPath();
  16398. ctx.lineWidth = style.symbolBorder;
  16399. ctx.strokeStyle = style.symbolBorderColor;
  16400. var symbol = style.symbol[idx].replace('empty', '').toLowerCase();
  16401. if (style.symbol[idx].match('empty')) {
  16402. ctx.fillStyle = '#fff';
  16403. }
  16404. var x0 = style.xStart;
  16405. var y0 = style.yStart;
  16406. var x2 = style.xEnd;
  16407. var y2 = style.yEnd;
  16408. var x = idx === 0 ? x0 : x2;
  16409. var y = idx === 0 ? y0 : y2;
  16410. var curveness = style.curveness || 0;
  16411. var rotate = style.symbolRotate[idx] != null ? style.symbolRotate[idx] - 0 : 0;
  16412. rotate = rotate / 180 * Math.PI;
  16413. if (symbol == 'arrow' && rotate === 0) {
  16414. if (curveness === 0) {
  16415. var sign = idx === 0 ? -1 : 1;
  16416. rotate = Math.PI / 2 + Math.atan2(sign * (y2 - y0), sign * (x2 - x0));
  16417. } else {
  16418. var x1 = style.cpX1;
  16419. var y1 = style.cpY1;
  16420. var quadraticDerivativeAt = curveTool.quadraticDerivativeAt;
  16421. var dx = quadraticDerivativeAt(x0, x1, x2, idx);
  16422. var dy = quadraticDerivativeAt(y0, y1, y2, idx);
  16423. rotate = Math.PI / 2 + Math.atan2(dy, dx);
  16424. }
  16425. }
  16426. ctx.translate(x, y);
  16427. if (rotate !== 0) {
  16428. ctx.rotate(rotate);
  16429. }
  16430. var symbolSize = style.symbolSize[idx];
  16431. IconShape.prototype.buildPath(ctx, {
  16432. x: -symbolSize,
  16433. y: -symbolSize,
  16434. width: symbolSize * 2,
  16435. height: symbolSize * 2,
  16436. iconType: symbol
  16437. });
  16438. ctx.closePath();
  16439. ctx.fill();
  16440. ctx.stroke();
  16441. ctx.restore();
  16442. },
  16443. getRect: function (style) {
  16444. style.curveness > 0 ? curveInstance.getRect(style) : lineInstance.getRect(style);
  16445. return style.__rect;
  16446. },
  16447. isCover: function (x, y) {
  16448. var originPos = this.transformCoordToLocal(x, y);
  16449. x = originPos[0];
  16450. y = originPos[1];
  16451. if (this.isCoverRect(x, y)) {
  16452. return this.style.curveness > 0 ? area.isInside(curveInstance, this.style, x, y) : area.isInside(lineInstance, this.style, x, y);
  16453. }
  16454. return false;
  16455. }
  16456. };
  16457. zrUtil.inherits(MarkLine, Base);
  16458. return MarkLine;
  16459. });define('echarts/util/shape/Symbol', [
  16460. 'require',
  16461. 'zrender/shape/Base',
  16462. 'zrender/shape/Polygon',
  16463. 'zrender/tool/util',
  16464. './normalIsCover'
  16465. ], function (require) {
  16466. var Base = require('zrender/shape/Base');
  16467. var PolygonShape = require('zrender/shape/Polygon');
  16468. var polygonInstance = new PolygonShape({});
  16469. var zrUtil = require('zrender/tool/util');
  16470. function Symbol(options) {
  16471. Base.call(this, options);
  16472. }
  16473. Symbol.prototype = {
  16474. type: 'symbol',
  16475. buildPath: function (ctx, style) {
  16476. var pointList = style.pointList;
  16477. var len = pointList.length;
  16478. if (len === 0) {
  16479. return;
  16480. }
  16481. var subSize = 10000;
  16482. var subSetLength = Math.ceil(len / subSize);
  16483. var sub;
  16484. var subLen;
  16485. var isArray = pointList[0] instanceof Array;
  16486. var size = style.size ? style.size : 2;
  16487. var curSize = size;
  16488. var halfSize = size / 2;
  16489. var PI2 = Math.PI * 2;
  16490. var percent;
  16491. var x;
  16492. var y;
  16493. for (var j = 0; j < subSetLength; j++) {
  16494. ctx.beginPath();
  16495. sub = j * subSize;
  16496. subLen = sub + subSize;
  16497. subLen = subLen > len ? len : subLen;
  16498. for (var i = sub; i < subLen; i++) {
  16499. if (style.random) {
  16500. percent = style['randomMap' + i % 20] / 100;
  16501. curSize = size * percent * percent;
  16502. halfSize = curSize / 2;
  16503. }
  16504. if (isArray) {
  16505. x = pointList[i][0];
  16506. y = pointList[i][1];
  16507. } else {
  16508. x = pointList[i].x;
  16509. y = pointList[i].y;
  16510. }
  16511. if (curSize < 3) {
  16512. ctx.rect(x - halfSize, y - halfSize, curSize, curSize);
  16513. } else {
  16514. switch (style.iconType) {
  16515. case 'circle':
  16516. ctx.moveTo(x, y);
  16517. ctx.arc(x, y, halfSize, 0, PI2, true);
  16518. break;
  16519. case 'diamond':
  16520. ctx.moveTo(x, y - halfSize);
  16521. ctx.lineTo(x + halfSize / 3, y - halfSize / 3);
  16522. ctx.lineTo(x + halfSize, y);
  16523. ctx.lineTo(x + halfSize / 3, y + halfSize / 3);
  16524. ctx.lineTo(x, y + halfSize);
  16525. ctx.lineTo(x - halfSize / 3, y + halfSize / 3);
  16526. ctx.lineTo(x - halfSize, y);
  16527. ctx.lineTo(x - halfSize / 3, y - halfSize / 3);
  16528. ctx.lineTo(x, y - halfSize);
  16529. break;
  16530. default:
  16531. ctx.rect(x - halfSize, y - halfSize, curSize, curSize);
  16532. }
  16533. }
  16534. }
  16535. ctx.closePath();
  16536. if (j < subSetLength - 1) {
  16537. switch (style.brushType) {
  16538. case 'both':
  16539. ctx.fill();
  16540. style.lineWidth > 0 && ctx.stroke();
  16541. break;
  16542. case 'stroke':
  16543. style.lineWidth > 0 && ctx.stroke();
  16544. break;
  16545. default:
  16546. ctx.fill();
  16547. }
  16548. }
  16549. }
  16550. },
  16551. getRect: function (style) {
  16552. return style.__rect || polygonInstance.getRect(style);
  16553. },
  16554. isCover: require('./normalIsCover')
  16555. };
  16556. zrUtil.inherits(Symbol, Base);
  16557. return Symbol;
  16558. });define('zrender/shape/Polyline', [
  16559. 'require',
  16560. './Base',
  16561. './util/smoothSpline',
  16562. './util/smoothBezier',
  16563. './util/dashedLineTo',
  16564. './Polygon',
  16565. '../tool/util'
  16566. ], function (require) {
  16567. var Base = require('./Base');
  16568. var smoothSpline = require('./util/smoothSpline');
  16569. var smoothBezier = require('./util/smoothBezier');
  16570. var dashedLineTo = require('./util/dashedLineTo');
  16571. var Polyline = function (options) {
  16572. this.brushTypeOnly = 'stroke';
  16573. this.textPosition = 'end';
  16574. Base.call(this, options);
  16575. };
  16576. Polyline.prototype = {
  16577. type: 'polyline',
  16578. buildPath: function (ctx, style) {
  16579. var pointList = style.pointList;
  16580. if (pointList.length < 2) {
  16581. return;
  16582. }
  16583. var len = Math.min(style.pointList.length, Math.round(style.pointListLength || style.pointList.length));
  16584. if (style.smooth && style.smooth !== 'spline') {
  16585. if (!style.controlPointList) {
  16586. this.updateControlPoints(style);
  16587. }
  16588. var controlPointList = style.controlPointList;
  16589. ctx.moveTo(pointList[0][0], pointList[0][1]);
  16590. var cp1;
  16591. var cp2;
  16592. var p;
  16593. for (var i = 0; i < len - 1; i++) {
  16594. cp1 = controlPointList[i * 2];
  16595. cp2 = controlPointList[i * 2 + 1];
  16596. p = pointList[i + 1];
  16597. ctx.bezierCurveTo(cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]);
  16598. }
  16599. } else {
  16600. if (style.smooth === 'spline') {
  16601. pointList = smoothSpline(pointList);
  16602. len = pointList.length;
  16603. }
  16604. if (!style.lineType || style.lineType == 'solid') {
  16605. ctx.moveTo(pointList[0][0], pointList[0][1]);
  16606. for (var i = 1; i < len; i++) {
  16607. ctx.lineTo(pointList[i][0], pointList[i][1]);
  16608. }
  16609. } else if (style.lineType == 'dashed' || style.lineType == 'dotted') {
  16610. var dashLength = (style.lineWidth || 1) * (style.lineType == 'dashed' ? 5 : 1);
  16611. ctx.moveTo(pointList[0][0], pointList[0][1]);
  16612. for (var i = 1; i < len; i++) {
  16613. dashedLineTo(ctx, pointList[i - 1][0], pointList[i - 1][1], pointList[i][0], pointList[i][1], dashLength);
  16614. }
  16615. }
  16616. }
  16617. return;
  16618. },
  16619. updateControlPoints: function (style) {
  16620. style.controlPointList = smoothBezier(style.pointList, style.smooth, false, style.smoothConstraint);
  16621. },
  16622. getRect: function (style) {
  16623. return require('./Polygon').prototype.getRect(style);
  16624. }
  16625. };
  16626. require('../tool/util').inherits(Polyline, Base);
  16627. return Polyline;
  16628. });define('zrender/shape/ShapeBundle', [
  16629. 'require',
  16630. './Base',
  16631. '../tool/util'
  16632. ], function (require) {
  16633. var Base = require('./Base');
  16634. var ShapeBundle = function (options) {
  16635. Base.call(this, options);
  16636. };
  16637. ShapeBundle.prototype = {
  16638. constructor: ShapeBundle,
  16639. type: 'shape-bundle',
  16640. brush: function (ctx, isHighlight) {
  16641. var style = this.beforeBrush(ctx, isHighlight);
  16642. ctx.beginPath();
  16643. for (var i = 0; i < style.shapeList.length; i++) {
  16644. var subShape = style.shapeList[i];
  16645. var subShapeStyle = subShape.style;
  16646. if (isHighlight) {
  16647. subShapeStyle = subShape.getHighlightStyle(subShapeStyle, subShape.highlightStyle || {}, subShape.brushTypeOnly);
  16648. }
  16649. subShape.buildPath(ctx, subShapeStyle);
  16650. }
  16651. switch (style.brushType) {
  16652. case 'both':
  16653. ctx.fill();
  16654. case 'stroke':
  16655. style.lineWidth > 0 && ctx.stroke();
  16656. break;
  16657. default:
  16658. ctx.fill();
  16659. }
  16660. this.drawText(ctx, style, this.style);
  16661. this.afterBrush(ctx);
  16662. },
  16663. getRect: function (style) {
  16664. if (style.__rect) {
  16665. return style.__rect;
  16666. }
  16667. var minX = Infinity;
  16668. var maxX = -Infinity;
  16669. var minY = Infinity;
  16670. var maxY = -Infinity;
  16671. for (var i = 0; i < style.shapeList.length; i++) {
  16672. var subShape = style.shapeList[i];
  16673. var subRect = subShape.getRect(subShape.style);
  16674. var minX = Math.min(subRect.x, minX);
  16675. var minY = Math.min(subRect.y, minY);
  16676. var maxX = Math.max(subRect.x + subRect.width, maxX);
  16677. var maxY = Math.max(subRect.y + subRect.height, maxY);
  16678. }
  16679. style.__rect = {
  16680. x: minX,
  16681. y: minY,
  16682. width: maxX - minX,
  16683. height: maxY - minY
  16684. };
  16685. return style.__rect;
  16686. },
  16687. isCover: function (x, y) {
  16688. var originPos = this.transformCoordToLocal(x, y);
  16689. x = originPos[0];
  16690. y = originPos[1];
  16691. if (this.isCoverRect(x, y)) {
  16692. for (var i = 0; i < this.style.shapeList.length; i++) {
  16693. var subShape = this.style.shapeList[i];
  16694. if (subShape.isCover(x, y)) {
  16695. return true;
  16696. }
  16697. }
  16698. }
  16699. return false;
  16700. }
  16701. };
  16702. require('../tool/util').inherits(ShapeBundle, Base);
  16703. return ShapeBundle;
  16704. });define('echarts/util/ecAnimation', [
  16705. 'require',
  16706. 'zrender/tool/util',
  16707. 'zrender/tool/curve',
  16708. 'zrender/shape/Polygon'
  16709. ], function (require) {
  16710. var zrUtil = require('zrender/tool/util');
  16711. var curveTool = require('zrender/tool/curve');
  16712. function pointList(zr, oldShape, newShape, duration, easing) {
  16713. var newPointList = newShape.style.pointList;
  16714. var newPointListLen = newPointList.length;
  16715. var oldPointList;
  16716. if (!oldShape) {
  16717. oldPointList = [];
  16718. if (newShape._orient != 'vertical') {
  16719. var y = newPointList[0][1];
  16720. for (var i = 0; i < newPointListLen; i++) {
  16721. oldPointList[i] = [
  16722. newPointList[i][0],
  16723. y
  16724. ];
  16725. }
  16726. } else {
  16727. var x = newPointList[0][0];
  16728. for (var i = 0; i < newPointListLen; i++) {
  16729. oldPointList[i] = [
  16730. x,
  16731. newPointList[i][1]
  16732. ];
  16733. }
  16734. }
  16735. if (newShape.type == 'half-smooth-polygon') {
  16736. oldPointList[newPointListLen - 1] = zrUtil.clone(newPointList[newPointListLen - 1]);
  16737. oldPointList[newPointListLen - 2] = zrUtil.clone(newPointList[newPointListLen - 2]);
  16738. }
  16739. oldShape = { style: { pointList: oldPointList } };
  16740. }
  16741. oldPointList = oldShape.style.pointList;
  16742. var oldPointListLen = oldPointList.length;
  16743. if (oldPointListLen == newPointListLen) {
  16744. newShape.style.pointList = oldPointList;
  16745. } else if (oldPointListLen < newPointListLen) {
  16746. newShape.style.pointList = oldPointList.concat(newPointList.slice(oldPointListLen));
  16747. } else {
  16748. newShape.style.pointList = oldPointList.slice(0, newPointListLen);
  16749. }
  16750. zr.addShape(newShape);
  16751. newShape.__animating = true;
  16752. zr.animate(newShape.id, 'style').when(duration, { pointList: newPointList }).during(function () {
  16753. if (newShape.updateControlPoints) {
  16754. newShape.updateControlPoints(newShape.style);
  16755. }
  16756. }).done(function () {
  16757. newShape.__animating = false;
  16758. }).start(easing);
  16759. }
  16760. function cloneStyle(target, source) {
  16761. var len = arguments.length;
  16762. for (var i = 2; i < len; i++) {
  16763. var prop = arguments[i];
  16764. target.style[prop] = source.style[prop];
  16765. }
  16766. }
  16767. function rectangle(zr, oldShape, newShape, duration, easing) {
  16768. var newShapeStyle = newShape.style;
  16769. if (!oldShape) {
  16770. oldShape = {
  16771. position: newShape.position,
  16772. style: {
  16773. x: newShapeStyle.x,
  16774. y: newShape._orient == 'vertical' ? newShapeStyle.y + newShapeStyle.height : newShapeStyle.y,
  16775. width: newShape._orient == 'vertical' ? newShapeStyle.width : 0,
  16776. height: newShape._orient != 'vertical' ? newShapeStyle.height : 0
  16777. }
  16778. };
  16779. }
  16780. var newX = newShapeStyle.x;
  16781. var newY = newShapeStyle.y;
  16782. var newWidth = newShapeStyle.width;
  16783. var newHeight = newShapeStyle.height;
  16784. var newPosition = [
  16785. newShape.position[0],
  16786. newShape.position[1]
  16787. ];
  16788. cloneStyle(newShape, oldShape, 'x', 'y', 'width', 'height');
  16789. newShape.position = oldShape.position;
  16790. zr.addShape(newShape);
  16791. if (newPosition[0] != oldShape.position[0] || newPosition[1] != oldShape.position[1]) {
  16792. zr.animate(newShape.id, '').when(duration, { position: newPosition }).start(easing);
  16793. }
  16794. newShape.__animating = true;
  16795. zr.animate(newShape.id, 'style').when(duration, {
  16796. x: newX,
  16797. y: newY,
  16798. width: newWidth,
  16799. height: newHeight
  16800. }).done(function () {
  16801. newShape.__animating = false;
  16802. }).start(easing);
  16803. }
  16804. function candle(zr, oldShape, newShape, duration, easing) {
  16805. if (!oldShape) {
  16806. var y = newShape.style.y;
  16807. oldShape = {
  16808. style: {
  16809. y: [
  16810. y[0],
  16811. y[0],
  16812. y[0],
  16813. y[0]
  16814. ]
  16815. }
  16816. };
  16817. }
  16818. var newY = newShape.style.y;
  16819. newShape.style.y = oldShape.style.y;
  16820. zr.addShape(newShape);
  16821. newShape.__animating = true;
  16822. zr.animate(newShape.id, 'style').when(duration, { y: newY }).done(function () {
  16823. newShape.__animating = false;
  16824. }).start(easing);
  16825. }
  16826. function ring(zr, oldShape, newShape, duration, easing) {
  16827. var x = newShape.style.x;
  16828. var y = newShape.style.y;
  16829. var r0 = newShape.style.r0;
  16830. var r = newShape.style.r;
  16831. newShape.__animating = true;
  16832. if (newShape._animationAdd != 'r') {
  16833. newShape.style.r0 = 0;
  16834. newShape.style.r = 0;
  16835. newShape.rotation = [
  16836. Math.PI * 2,
  16837. x,
  16838. y
  16839. ];
  16840. zr.addShape(newShape);
  16841. zr.animate(newShape.id, 'style').when(duration, {
  16842. r0: r0,
  16843. r: r
  16844. }).done(function () {
  16845. newShape.__animating = false;
  16846. }).start(easing);
  16847. zr.animate(newShape.id, '').when(Math.round(duration / 3 * 2), {
  16848. rotation: [
  16849. 0,
  16850. x,
  16851. y
  16852. ]
  16853. }).start(easing);
  16854. } else {
  16855. newShape.style.r0 = newShape.style.r;
  16856. zr.addShape(newShape);
  16857. zr.animate(newShape.id, 'style').when(duration, { r0: r0 }).done(function () {
  16858. newShape.__animating = false;
  16859. }).start(easing);
  16860. }
  16861. }
  16862. function sector(zr, oldShape, newShape, duration, easing) {
  16863. if (!oldShape) {
  16864. if (newShape._animationAdd != 'r') {
  16865. oldShape = {
  16866. style: {
  16867. startAngle: newShape.style.startAngle,
  16868. endAngle: newShape.style.startAngle
  16869. }
  16870. };
  16871. } else {
  16872. oldShape = { style: { r0: newShape.style.r } };
  16873. }
  16874. }
  16875. var startAngle = newShape.style.startAngle;
  16876. var endAngle = newShape.style.endAngle;
  16877. cloneStyle(newShape, oldShape, 'startAngle', 'endAngle');
  16878. zr.addShape(newShape);
  16879. newShape.__animating = true;
  16880. zr.animate(newShape.id, 'style').when(duration, {
  16881. startAngle: startAngle,
  16882. endAngle: endAngle
  16883. }).done(function () {
  16884. newShape.__animating = false;
  16885. }).start(easing);
  16886. }
  16887. function text(zr, oldShape, newShape, duration, easing) {
  16888. if (!oldShape) {
  16889. oldShape = {
  16890. style: {
  16891. x: newShape.style.textAlign == 'left' ? newShape.style.x + 100 : newShape.style.x - 100,
  16892. y: newShape.style.y
  16893. }
  16894. };
  16895. }
  16896. var x = newShape.style.x;
  16897. var y = newShape.style.y;
  16898. cloneStyle(newShape, oldShape, 'x', 'y');
  16899. zr.addShape(newShape);
  16900. newShape.__animating = true;
  16901. zr.animate(newShape.id, 'style').when(duration, {
  16902. x: x,
  16903. y: y
  16904. }).done(function () {
  16905. newShape.__animating = false;
  16906. }).start(easing);
  16907. }
  16908. function polygon(zr, oldShape, newShape, duration, easing) {
  16909. var rect = require('zrender/shape/Polygon').prototype.getRect(newShape.style);
  16910. var x = rect.x + rect.width / 2;
  16911. var y = rect.y + rect.height / 2;
  16912. newShape.scale = [
  16913. 0.1,
  16914. 0.1,
  16915. x,
  16916. y
  16917. ];
  16918. zr.addShape(newShape);
  16919. newShape.__animating = true;
  16920. zr.animate(newShape.id, '').when(duration, {
  16921. scale: [
  16922. 1,
  16923. 1,
  16924. x,
  16925. y
  16926. ]
  16927. }).done(function () {
  16928. newShape.__animating = false;
  16929. }).start(easing);
  16930. }
  16931. function ribbon(zr, oldShape, newShape, duration, easing) {
  16932. if (!oldShape) {
  16933. oldShape = {
  16934. style: {
  16935. source0: 0,
  16936. source1: newShape.style.source1 > 0 ? 360 : -360,
  16937. target0: 0,
  16938. target1: newShape.style.target1 > 0 ? 360 : -360
  16939. }
  16940. };
  16941. }
  16942. var source0 = newShape.style.source0;
  16943. var source1 = newShape.style.source1;
  16944. var target0 = newShape.style.target0;
  16945. var target1 = newShape.style.target1;
  16946. if (oldShape.style) {
  16947. cloneStyle(newShape, oldShape, 'source0', 'source1', 'target0', 'target1');
  16948. }
  16949. zr.addShape(newShape);
  16950. newShape.__animating = true;
  16951. zr.animate(newShape.id, 'style').when(duration, {
  16952. source0: source0,
  16953. source1: source1,
  16954. target0: target0,
  16955. target1: target1
  16956. }).done(function () {
  16957. newShape.__animating = false;
  16958. }).start(easing);
  16959. }
  16960. function gaugePointer(zr, oldShape, newShape, duration, easing) {
  16961. if (!oldShape) {
  16962. oldShape = { style: { angle: newShape.style.startAngle } };
  16963. }
  16964. var angle = newShape.style.angle;
  16965. newShape.style.angle = oldShape.style.angle;
  16966. zr.addShape(newShape);
  16967. newShape.__animating = true;
  16968. zr.animate(newShape.id, 'style').when(duration, { angle: angle }).done(function () {
  16969. newShape.__animating = false;
  16970. }).start(easing);
  16971. }
  16972. function icon(zr, oldShape, newShape, duration, easing, delay) {
  16973. newShape.style._x = newShape.style.x;
  16974. newShape.style._y = newShape.style.y;
  16975. newShape.style._width = newShape.style.width;
  16976. newShape.style._height = newShape.style.height;
  16977. if (!oldShape) {
  16978. var x = newShape._x || 0;
  16979. var y = newShape._y || 0;
  16980. newShape.scale = [
  16981. 0.01,
  16982. 0.01,
  16983. x,
  16984. y
  16985. ];
  16986. zr.addShape(newShape);
  16987. newShape.__animating = true;
  16988. zr.animate(newShape.id, '').delay(delay).when(duration, {
  16989. scale: [
  16990. 1,
  16991. 1,
  16992. x,
  16993. y
  16994. ]
  16995. }).done(function () {
  16996. newShape.__animating = false;
  16997. }).start(easing || 'QuinticOut');
  16998. } else {
  16999. rectangle(zr, oldShape, newShape, duration, easing);
  17000. }
  17001. }
  17002. function line(zr, oldShape, newShape, duration, easing) {
  17003. if (!oldShape) {
  17004. oldShape = {
  17005. style: {
  17006. xStart: newShape.style.xStart,
  17007. yStart: newShape.style.yStart,
  17008. xEnd: newShape.style.xStart,
  17009. yEnd: newShape.style.yStart
  17010. }
  17011. };
  17012. }
  17013. var xStart = newShape.style.xStart;
  17014. var xEnd = newShape.style.xEnd;
  17015. var yStart = newShape.style.yStart;
  17016. var yEnd = newShape.style.yEnd;
  17017. cloneStyle(newShape, oldShape, 'xStart', 'xEnd', 'yStart', 'yEnd');
  17018. zr.addShape(newShape);
  17019. newShape.__animating = true;
  17020. zr.animate(newShape.id, 'style').when(duration, {
  17021. xStart: xStart,
  17022. xEnd: xEnd,
  17023. yStart: yStart,
  17024. yEnd: yEnd
  17025. }).done(function () {
  17026. newShape.__animating = false;
  17027. }).start(easing);
  17028. }
  17029. function markline(zr, oldShape, newShape, duration, easing) {
  17030. easing = easing || 'QuinticOut';
  17031. newShape.__animating = true;
  17032. zr.addShape(newShape);
  17033. var newShapeStyle = newShape.style;
  17034. var animationDone = function () {
  17035. newShape.__animating = false;
  17036. };
  17037. var x0 = newShapeStyle.xStart;
  17038. var y0 = newShapeStyle.yStart;
  17039. var x2 = newShapeStyle.xEnd;
  17040. var y2 = newShapeStyle.yEnd;
  17041. if (newShapeStyle.curveness > 0) {
  17042. newShape.updatePoints(newShapeStyle);
  17043. var obj = { p: 0 };
  17044. var x1 = newShapeStyle.cpX1;
  17045. var y1 = newShapeStyle.cpY1;
  17046. var newXArr = [];
  17047. var newYArr = [];
  17048. var subdivide = curveTool.quadraticSubdivide;
  17049. zr.animation.animate(obj).when(duration, { p: 1 }).during(function () {
  17050. subdivide(x0, x1, x2, obj.p, newXArr);
  17051. subdivide(y0, y1, y2, obj.p, newYArr);
  17052. newShapeStyle.cpX1 = newXArr[1];
  17053. newShapeStyle.cpY1 = newYArr[1];
  17054. newShapeStyle.xEnd = newXArr[2];
  17055. newShapeStyle.yEnd = newYArr[2];
  17056. zr.modShape(newShape);
  17057. }).done(animationDone).start(easing);
  17058. } else {
  17059. zr.animate(newShape.id, 'style').when(0, {
  17060. xEnd: x0,
  17061. yEnd: y0
  17062. }).when(duration, {
  17063. xEnd: x2,
  17064. yEnd: y2
  17065. }).done(animationDone).start(easing);
  17066. }
  17067. }
  17068. return {
  17069. pointList: pointList,
  17070. rectangle: rectangle,
  17071. candle: candle,
  17072. ring: ring,
  17073. sector: sector,
  17074. text: text,
  17075. polygon: polygon,
  17076. ribbon: ribbon,
  17077. gaugePointer: gaugePointer,
  17078. icon: icon,
  17079. line: line,
  17080. markline: markline
  17081. };
  17082. });define('echarts/util/ecEffect', [
  17083. 'require',
  17084. '../util/ecData',
  17085. 'zrender/shape/Circle',
  17086. 'zrender/shape/Image',
  17087. 'zrender/tool/curve',
  17088. '../util/shape/Icon',
  17089. '../util/shape/Symbol',
  17090. 'zrender/shape/ShapeBundle',
  17091. 'zrender/shape/Polyline',
  17092. 'zrender/tool/vector',
  17093. 'zrender/tool/env'
  17094. ], function (require) {
  17095. var ecData = require('../util/ecData');
  17096. var CircleShape = require('zrender/shape/Circle');
  17097. var ImageShape = require('zrender/shape/Image');
  17098. var curveTool = require('zrender/tool/curve');
  17099. var IconShape = require('../util/shape/Icon');
  17100. var SymbolShape = require('../util/shape/Symbol');
  17101. var ShapeBundle = require('zrender/shape/ShapeBundle');
  17102. var Polyline = require('zrender/shape/Polyline');
  17103. var vec2 = require('zrender/tool/vector');
  17104. var canvasSupported = require('zrender/tool/env').canvasSupported;
  17105. function point(zr, effectList, shape, zlevel) {
  17106. var effect = shape.effect;
  17107. var color = effect.color || shape.style.strokeColor || shape.style.color;
  17108. var shadowColor = effect.shadowColor || color;
  17109. var size = effect.scaleSize;
  17110. var distance = effect.bounceDistance;
  17111. var shadowBlur = typeof effect.shadowBlur != 'undefined' ? effect.shadowBlur : size;
  17112. var effectShape;
  17113. if (shape.type !== 'image') {
  17114. effectShape = new IconShape({
  17115. zlevel: zlevel,
  17116. style: {
  17117. brushType: 'stroke',
  17118. iconType: shape.style.iconType != 'droplet' ? shape.style.iconType : 'circle',
  17119. x: shadowBlur + 1,
  17120. y: shadowBlur + 1,
  17121. n: shape.style.n,
  17122. width: shape.style._width * size,
  17123. height: shape.style._height * size,
  17124. lineWidth: 1,
  17125. strokeColor: color,
  17126. shadowColor: shadowColor,
  17127. shadowBlur: shadowBlur
  17128. },
  17129. draggable: false,
  17130. hoverable: false
  17131. });
  17132. if (shape.style.iconType == 'pin') {
  17133. effectShape.style.y += effectShape.style.height / 2 * 1.5;
  17134. }
  17135. if (canvasSupported) {
  17136. effectShape.style.image = zr.shapeToImage(effectShape, effectShape.style.width + shadowBlur * 2 + 2, effectShape.style.height + shadowBlur * 2 + 2).style.image;
  17137. effectShape = new ImageShape({
  17138. zlevel: effectShape.zlevel,
  17139. style: effectShape.style,
  17140. draggable: false,
  17141. hoverable: false
  17142. });
  17143. }
  17144. } else {
  17145. effectShape = new ImageShape({
  17146. zlevel: zlevel,
  17147. style: shape.style,
  17148. draggable: false,
  17149. hoverable: false
  17150. });
  17151. }
  17152. ecData.clone(shape, effectShape);
  17153. effectShape.position = shape.position;
  17154. effectList.push(effectShape);
  17155. zr.addShape(effectShape);
  17156. var devicePixelRatio = shape.type !== 'image' ? window.devicePixelRatio || 1 : 1;
  17157. var offset = (effectShape.style.width / devicePixelRatio - shape.style._width) / 2;
  17158. effectShape.style.x = shape.style._x - offset;
  17159. effectShape.style.y = shape.style._y - offset;
  17160. if (shape.style.iconType == 'pin') {
  17161. effectShape.style.y -= shape.style.height / 2 * 1.5;
  17162. }
  17163. var duration = (effect.period + Math.random() * 10) * 100;
  17164. zr.modShape(shape.id, { invisible: true });
  17165. var centerX = effectShape.style.x + effectShape.style.width / 2 / devicePixelRatio;
  17166. var centerY = effectShape.style.y + effectShape.style.height / 2 / devicePixelRatio;
  17167. if (effect.type === 'scale') {
  17168. zr.modShape(effectShape.id, {
  17169. scale: [
  17170. 0.1,
  17171. 0.1,
  17172. centerX,
  17173. centerY
  17174. ]
  17175. });
  17176. zr.animate(effectShape.id, '', effect.loop).when(duration, {
  17177. scale: [
  17178. 1,
  17179. 1,
  17180. centerX,
  17181. centerY
  17182. ]
  17183. }).done(function () {
  17184. shape.effect.show = false;
  17185. zr.delShape(effectShape.id);
  17186. }).start();
  17187. } else {
  17188. zr.animate(effectShape.id, 'style', effect.loop).when(duration, { y: effectShape.style.y - distance }).when(duration * 2, { y: effectShape.style.y }).done(function () {
  17189. shape.effect.show = false;
  17190. zr.delShape(effectShape.id);
  17191. }).start();
  17192. }
  17193. }
  17194. function largePoint(zr, effectList, shape, zlevel) {
  17195. var effect = shape.effect;
  17196. var color = effect.color || shape.style.strokeColor || shape.style.color;
  17197. var size = effect.scaleSize;
  17198. var shadowColor = effect.shadowColor || color;
  17199. var shadowBlur = typeof effect.shadowBlur != 'undefined' ? effect.shadowBlur : size * 2;
  17200. var devicePixelRatio = window.devicePixelRatio || 1;
  17201. var effectShape = new SymbolShape({
  17202. zlevel: zlevel,
  17203. position: shape.position,
  17204. scale: shape.scale,
  17205. style: {
  17206. pointList: shape.style.pointList,
  17207. iconType: shape.style.iconType,
  17208. color: color,
  17209. strokeColor: color,
  17210. shadowColor: shadowColor,
  17211. shadowBlur: shadowBlur * devicePixelRatio,
  17212. random: true,
  17213. brushType: 'fill',
  17214. lineWidth: 1,
  17215. size: shape.style.size
  17216. },
  17217. draggable: false,
  17218. hoverable: false
  17219. });
  17220. effectList.push(effectShape);
  17221. zr.addShape(effectShape);
  17222. zr.modShape(shape.id, { invisible: true });
  17223. var duration = Math.round(effect.period * 100);
  17224. var clip1 = {};
  17225. var clip2 = {};
  17226. for (var i = 0; i < 20; i++) {
  17227. effectShape.style['randomMap' + i] = 0;
  17228. clip1 = {};
  17229. clip1['randomMap' + i] = 100;
  17230. clip2 = {};
  17231. clip2['randomMap' + i] = 0;
  17232. effectShape.style['randomMap' + i] = Math.random() * 100;
  17233. 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();
  17234. }
  17235. }
  17236. function line(zr, effectList, shape, zlevel, isLarge) {
  17237. var effect = shape.effect;
  17238. var shapeStyle = shape.style;
  17239. var color = effect.color || shapeStyle.strokeColor || shapeStyle.color;
  17240. var shadowColor = effect.shadowColor || shapeStyle.strokeColor || color;
  17241. var size = shapeStyle.lineWidth * effect.scaleSize;
  17242. var shadowBlur = typeof effect.shadowBlur != 'undefined' ? effect.shadowBlur : size;
  17243. var effectShape = new CircleShape({
  17244. zlevel: zlevel,
  17245. style: {
  17246. x: shadowBlur,
  17247. y: shadowBlur,
  17248. r: size,
  17249. color: color,
  17250. shadowColor: shadowColor,
  17251. shadowBlur: shadowBlur
  17252. },
  17253. hoverable: false
  17254. });
  17255. var offset = 0;
  17256. if (canvasSupported && !isLarge) {
  17257. var zlevel = effectShape.zlevel;
  17258. effectShape = zr.shapeToImage(effectShape, (size + shadowBlur) * 2, (size + shadowBlur) * 2);
  17259. effectShape.zlevel = zlevel;
  17260. effectShape.hoverable = false;
  17261. offset = shadowBlur;
  17262. }
  17263. if (!isLarge) {
  17264. ecData.clone(shape, effectShape);
  17265. effectShape.position = shape.position;
  17266. effectList.push(effectShape);
  17267. zr.addShape(effectShape);
  17268. }
  17269. var effectDone = function () {
  17270. if (!isLarge) {
  17271. shape.effect.show = false;
  17272. zr.delShape(effectShape.id);
  17273. }
  17274. effectShape.effectAnimator = null;
  17275. };
  17276. if (shape instanceof Polyline) {
  17277. var distanceList = [0];
  17278. var totalDist = 0;
  17279. var pointList = shapeStyle.pointList;
  17280. var controlPointList = shapeStyle.controlPointList;
  17281. for (var i = 1; i < pointList.length; i++) {
  17282. if (controlPointList) {
  17283. var cp1 = controlPointList[(i - 1) * 2];
  17284. var cp2 = controlPointList[(i - 1) * 2 + 1];
  17285. totalDist += vec2.dist(pointList[i - 1], cp1) + vec2.dist(cp1, cp2) + vec2.dist(cp2, pointList[i]);
  17286. } else {
  17287. totalDist += vec2.dist(pointList[i - 1], pointList[i]);
  17288. }
  17289. distanceList.push(totalDist);
  17290. }
  17291. var obj = { p: 0 };
  17292. var animator = zr.animation.animate(obj, { loop: effect.loop });
  17293. for (var i = 0; i < distanceList.length; i++) {
  17294. animator.when(distanceList[i] * effect.period, { p: i });
  17295. }
  17296. animator.during(function () {
  17297. var i = Math.floor(obj.p);
  17298. var x, y;
  17299. if (i == pointList.length - 1) {
  17300. x = pointList[i][0];
  17301. y = pointList[i][1];
  17302. } else {
  17303. var t = obj.p - i;
  17304. var p0 = pointList[i];
  17305. var p1 = pointList[i + 1];
  17306. if (controlPointList) {
  17307. var cp1 = controlPointList[i * 2];
  17308. var cp2 = controlPointList[i * 2 + 1];
  17309. x = curveTool.cubicAt(p0[0], cp1[0], cp2[0], p1[0], t);
  17310. y = curveTool.cubicAt(p0[1], cp1[1], cp2[1], p1[1], t);
  17311. } else {
  17312. x = (p1[0] - p0[0]) * t + p0[0];
  17313. y = (p1[1] - p0[1]) * t + p0[1];
  17314. }
  17315. }
  17316. effectShape.style.x = x;
  17317. effectShape.style.y = y;
  17318. if (!isLarge) {
  17319. zr.modShape(effectShape);
  17320. }
  17321. }).done(effectDone).start();
  17322. animator.duration = totalDist * effect.period;
  17323. effectShape.effectAnimator = animator;
  17324. } else {
  17325. var x0 = shapeStyle.xStart - offset;
  17326. var y0 = shapeStyle.yStart - offset;
  17327. var x2 = shapeStyle.xEnd - offset;
  17328. var y2 = shapeStyle.yEnd - offset;
  17329. effectShape.style.x = x0;
  17330. effectShape.style.y = y0;
  17331. var distance = (x2 - x0) * (x2 - x0) + (y2 - y0) * (y2 - y0);
  17332. var duration = Math.round(Math.sqrt(Math.round(distance * effect.period * effect.period)));
  17333. if (shape.style.curveness > 0) {
  17334. var x1 = shapeStyle.cpX1 - offset;
  17335. var y1 = shapeStyle.cpY1 - offset;
  17336. effectShape.effectAnimator = zr.animation.animate(effectShape, { loop: effect.loop }).when(duration, { p: 1 }).during(function (target, t) {
  17337. effectShape.style.x = curveTool.quadraticAt(x0, x1, x2, t);
  17338. effectShape.style.y = curveTool.quadraticAt(y0, y1, y2, t);
  17339. if (!isLarge) {
  17340. zr.modShape(effectShape);
  17341. }
  17342. }).done(effectDone).start();
  17343. } else {
  17344. effectShape.effectAnimator = zr.animation.animate(effectShape.style, { loop: effect.loop }).when(duration, {
  17345. x: x2,
  17346. y: y2
  17347. }).during(function () {
  17348. if (!isLarge) {
  17349. zr.modShape(effectShape);
  17350. }
  17351. }).done(effectDone).start();
  17352. }
  17353. effectShape.effectAnimator.duration = duration;
  17354. }
  17355. return effectShape;
  17356. }
  17357. function largeLine(zr, effectList, shape, zlevel) {
  17358. var effectShape = new ShapeBundle({
  17359. style: { shapeList: [] },
  17360. zlevel: zlevel,
  17361. hoverable: false
  17362. });
  17363. var shapeList = shape.style.shapeList;
  17364. var effect = shape.effect;
  17365. effectShape.position = shape.position;
  17366. var maxDuration = 0;
  17367. var subEffectAnimators = [];
  17368. for (var i = 0; i < shapeList.length; i++) {
  17369. shapeList[i].effect = effect;
  17370. var subEffectShape = line(zr, null, shapeList[i], zlevel, true);
  17371. var subEffectAnimator = subEffectShape.effectAnimator;
  17372. effectShape.style.shapeList.push(subEffectShape);
  17373. if (subEffectAnimator.duration > maxDuration) {
  17374. maxDuration = subEffectAnimator.duration;
  17375. }
  17376. if (i === 0) {
  17377. effectShape.style.color = subEffectShape.style.color;
  17378. effectShape.style.shadowBlur = subEffectShape.style.shadowBlur;
  17379. effectShape.style.shadowColor = subEffectShape.style.shadowColor;
  17380. }
  17381. subEffectAnimators.push(subEffectAnimator);
  17382. }
  17383. effectList.push(effectShape);
  17384. zr.addShape(effectShape);
  17385. var clearAllAnimators = function () {
  17386. for (var i = 0; i < subEffectAnimators.length; i++) {
  17387. subEffectAnimators[i].stop();
  17388. }
  17389. };
  17390. if (maxDuration) {
  17391. effectShape.__dummy = 0;
  17392. var animator = zr.animate(effectShape.id, '', effect.loop).when(maxDuration, { __dummy: 1 }).during(function () {
  17393. zr.modShape(effectShape);
  17394. }).done(function () {
  17395. shape.effect.show = false;
  17396. zr.delShape(effectShape.id);
  17397. }).start();
  17398. var oldStop = animator.stop;
  17399. animator.stop = function () {
  17400. clearAllAnimators();
  17401. oldStop.call(this);
  17402. };
  17403. }
  17404. }
  17405. return {
  17406. point: point,
  17407. largePoint: largePoint,
  17408. line: line,
  17409. largeLine: largeLine
  17410. };
  17411. });define('echarts/component/base', [
  17412. 'require',
  17413. '../config',
  17414. '../util/ecData',
  17415. '../util/ecQuery',
  17416. '../util/number',
  17417. 'zrender/tool/util',
  17418. 'zrender/tool/env'
  17419. ], function (require) {
  17420. var ecConfig = require('../config');
  17421. var ecData = require('../util/ecData');
  17422. var ecQuery = require('../util/ecQuery');
  17423. var number = require('../util/number');
  17424. var zrUtil = require('zrender/tool/util');
  17425. function Base(ecTheme, messageCenter, zr, option, myChart) {
  17426. this.ecTheme = ecTheme;
  17427. this.messageCenter = messageCenter;
  17428. this.zr = zr;
  17429. this.option = option;
  17430. this.series = option.series;
  17431. this.myChart = myChart;
  17432. this.component = myChart.component;
  17433. this.shapeList = [];
  17434. this.effectList = [];
  17435. var self = this;
  17436. self._onlegendhoverlink = function (param) {
  17437. if (self.legendHoverLink) {
  17438. var targetName = param.target;
  17439. var name;
  17440. for (var i = self.shapeList.length - 1; i >= 0; i--) {
  17441. 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;
  17442. if (name == targetName && !self.shapeList[i].invisible && !self.shapeList[i].__animating) {
  17443. self.zr.addHoverShape(self.shapeList[i]);
  17444. }
  17445. }
  17446. }
  17447. };
  17448. messageCenter && messageCenter.bind(ecConfig.EVENT.LEGEND_HOVERLINK, this._onlegendhoverlink);
  17449. }
  17450. Base.prototype = {
  17451. canvasSupported: require('zrender/tool/env').canvasSupported,
  17452. _getZ: function (zWhat) {
  17453. if (this[zWhat] != null) {
  17454. return this[zWhat];
  17455. }
  17456. var opt = this.ecTheme[this.type];
  17457. if (opt && opt[zWhat] != null) {
  17458. return opt[zWhat];
  17459. }
  17460. opt = ecConfig[this.type];
  17461. if (opt && opt[zWhat] != null) {
  17462. return opt[zWhat];
  17463. }
  17464. return 0;
  17465. },
  17466. getZlevelBase: function () {
  17467. return this._getZ('zlevel');
  17468. },
  17469. getZBase: function () {
  17470. return this._getZ('z');
  17471. },
  17472. reformOption: function (opt) {
  17473. opt = zrUtil.merge(zrUtil.merge(opt || {}, zrUtil.clone(this.ecTheme[this.type] || {})), zrUtil.clone(ecConfig[this.type] || {}));
  17474. this.z = opt.z;
  17475. this.zlevel = opt.zlevel;
  17476. return opt;
  17477. },
  17478. reformCssArray: function (p) {
  17479. if (p instanceof Array) {
  17480. switch (p.length + '') {
  17481. case '4':
  17482. return p;
  17483. case '3':
  17484. return [
  17485. p[0],
  17486. p[1],
  17487. p[2],
  17488. p[1]
  17489. ];
  17490. case '2':
  17491. return [
  17492. p[0],
  17493. p[1],
  17494. p[0],
  17495. p[1]
  17496. ];
  17497. case '1':
  17498. return [
  17499. p[0],
  17500. p[0],
  17501. p[0],
  17502. p[0]
  17503. ];
  17504. case '0':
  17505. return [
  17506. 0,
  17507. 0,
  17508. 0,
  17509. 0
  17510. ];
  17511. }
  17512. } else {
  17513. return [
  17514. p,
  17515. p,
  17516. p,
  17517. p
  17518. ];
  17519. }
  17520. },
  17521. getShapeById: function (id) {
  17522. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  17523. if (this.shapeList[i].id === id) {
  17524. return this.shapeList[i];
  17525. }
  17526. }
  17527. return null;
  17528. },
  17529. getFont: function (textStyle) {
  17530. var finalTextStyle = this.getTextStyle(zrUtil.clone(textStyle));
  17531. return finalTextStyle.fontStyle + ' ' + finalTextStyle.fontWeight + ' ' + finalTextStyle.fontSize + 'px ' + finalTextStyle.fontFamily;
  17532. },
  17533. getTextStyle: function (targetStyle) {
  17534. return zrUtil.merge(zrUtil.merge(targetStyle || {}, this.ecTheme.textStyle), ecConfig.textStyle);
  17535. },
  17536. getItemStyleColor: function (itemColor, seriesIndex, dataIndex, data) {
  17537. return typeof itemColor === 'function' ? itemColor.call(this.myChart, {
  17538. seriesIndex: seriesIndex,
  17539. series: this.series[seriesIndex],
  17540. dataIndex: dataIndex,
  17541. data: data
  17542. }) : itemColor;
  17543. },
  17544. getDataFromOption: function (data, defaultData) {
  17545. return data != null ? data.value != null ? data.value : data : defaultData;
  17546. },
  17547. subPixelOptimize: function (position, lineWidth) {
  17548. if (lineWidth % 2 === 1) {
  17549. position = Math.floor(position) + 0.5;
  17550. } else {
  17551. position = Math.round(position);
  17552. }
  17553. return position;
  17554. },
  17555. resize: function () {
  17556. this.refresh && this.refresh();
  17557. this.clearEffectShape && this.clearEffectShape(true);
  17558. var self = this;
  17559. setTimeout(function () {
  17560. self.animationEffect && self.animationEffect();
  17561. }, 200);
  17562. },
  17563. clear: function () {
  17564. this.clearEffectShape && this.clearEffectShape();
  17565. this.zr && this.zr.delShape(this.shapeList);
  17566. this.shapeList = [];
  17567. },
  17568. dispose: function () {
  17569. this.onbeforDispose && this.onbeforDispose();
  17570. this.clear();
  17571. this.shapeList = null;
  17572. this.effectList = null;
  17573. this.messageCenter && this.messageCenter.unbind(ecConfig.EVENT.LEGEND_HOVERLINK, this._onlegendhoverlink);
  17574. this.onafterDispose && this.onafterDispose();
  17575. },
  17576. query: ecQuery.query,
  17577. deepQuery: ecQuery.deepQuery,
  17578. deepMerge: ecQuery.deepMerge,
  17579. parsePercent: number.parsePercent,
  17580. parseCenter: number.parseCenter,
  17581. parseRadius: number.parseRadius,
  17582. numAddCommas: number.addCommas
  17583. };
  17584. return Base;
  17585. });define('echarts/layout/EdgeBundling', [
  17586. 'require',
  17587. '../data/KDTree',
  17588. 'zrender/tool/vector'
  17589. ], function (require) {
  17590. var KDTree = require('../data/KDTree');
  17591. var vec2 = require('zrender/tool/vector');
  17592. var v2Create = vec2.create;
  17593. var v2DistSquare = vec2.distSquare;
  17594. var v2Dist = vec2.dist;
  17595. var v2Copy = vec2.copy;
  17596. var v2Clone = vec2.clone;
  17597. function squaredDistance(a, b) {
  17598. a = a.array;
  17599. b = b.array;
  17600. var x = b[0] - a[0];
  17601. var y = b[1] - a[1];
  17602. var z = b[2] - a[2];
  17603. var w = b[3] - a[3];
  17604. return x * x + y * y + z * z + w * w;
  17605. }
  17606. function CoarsenedEdge(group) {
  17607. this.points = [
  17608. group.mp0,
  17609. group.mp1
  17610. ];
  17611. this.group = group;
  17612. }
  17613. function Edge(edge) {
  17614. var points = edge.points;
  17615. if (points[0][1] < points[1][1] || edge instanceof CoarsenedEdge) {
  17616. this.array = [
  17617. points[0][0],
  17618. points[0][1],
  17619. points[1][0],
  17620. points[1][1]
  17621. ];
  17622. this._startPoint = points[0];
  17623. this._endPoint = points[1];
  17624. } else {
  17625. this.array = [
  17626. points[1][0],
  17627. points[1][1],
  17628. points[0][0],
  17629. points[0][1]
  17630. ];
  17631. this._startPoint = points[1];
  17632. this._endPoint = points[0];
  17633. }
  17634. this.ink = v2Dist(points[0], points[1]);
  17635. this.edge = edge;
  17636. this.group = null;
  17637. }
  17638. Edge.prototype.getStartPoint = function () {
  17639. return this._startPoint;
  17640. };
  17641. Edge.prototype.getEndPoint = function () {
  17642. return this._endPoint;
  17643. };
  17644. function BundledEdgeGroup() {
  17645. this.edgeList = [];
  17646. this.mp0 = v2Create();
  17647. this.mp1 = v2Create();
  17648. this.ink = 0;
  17649. }
  17650. BundledEdgeGroup.prototype.addEdge = function (edge) {
  17651. edge.group = this;
  17652. this.edgeList.push(edge);
  17653. };
  17654. BundledEdgeGroup.prototype.removeEdge = function (edge) {
  17655. edge.group = null;
  17656. this.edgeList.splice(this.edgeList.indexOf(edge), 1);
  17657. };
  17658. function EdgeBundling() {
  17659. this.maxNearestEdge = 6;
  17660. this.maxTurningAngle = Math.PI / 4;
  17661. this.maxIteration = 20;
  17662. }
  17663. EdgeBundling.prototype = {
  17664. constructor: EdgeBundling,
  17665. run: function (rawEdges) {
  17666. var res = this._iterate(rawEdges);
  17667. var nIterate = 0;
  17668. while (nIterate++ < this.maxIteration) {
  17669. var coarsenedEdges = [];
  17670. for (var i = 0; i < res.groups.length; i++) {
  17671. coarsenedEdges.push(new CoarsenedEdge(res.groups[i]));
  17672. }
  17673. var newRes = this._iterate(coarsenedEdges);
  17674. if (newRes.savedInk <= 0) {
  17675. break;
  17676. } else {
  17677. res = newRes;
  17678. }
  17679. }
  17680. var newEdges = [];
  17681. function pointApproxEqual(p0, p1) {
  17682. return v2DistSquare(p0, p1) < 1e-10;
  17683. }
  17684. function cleanEdgePoints(edgePoints, rawEdgePoints) {
  17685. var res = [];
  17686. var off = 0;
  17687. for (var i = 0; i < edgePoints.length; i++) {
  17688. if (!(off > 0 && pointApproxEqual(edgePoints[i], res[off - 1]))) {
  17689. res[off++] = v2Clone(edgePoints[i]);
  17690. }
  17691. }
  17692. if (rawEdgePoints[0] && !pointApproxEqual(res[0], rawEdgePoints[0])) {
  17693. res = res.reverse();
  17694. }
  17695. return res;
  17696. }
  17697. var buildNewEdges = function (groups, fromEdgePoints) {
  17698. var newEdgePoints;
  17699. for (var i = 0; i < groups.length; i++) {
  17700. var group = groups[i];
  17701. if (group.edgeList[0] && group.edgeList[0].edge instanceof CoarsenedEdge) {
  17702. var newGroups = [];
  17703. for (var j = 0; j < group.edgeList.length; j++) {
  17704. newGroups.push(group.edgeList[j].edge.group);
  17705. }
  17706. if (!fromEdgePoints) {
  17707. newEdgePoints = [];
  17708. } else {
  17709. newEdgePoints = fromEdgePoints.slice();
  17710. }
  17711. newEdgePoints.unshift(group.mp0);
  17712. newEdgePoints.push(group.mp1);
  17713. buildNewEdges(newGroups, newEdgePoints);
  17714. } else {
  17715. for (var j = 0; j < group.edgeList.length; j++) {
  17716. var edge = group.edgeList[j];
  17717. if (!fromEdgePoints) {
  17718. newEdgePoints = [];
  17719. } else {
  17720. newEdgePoints = fromEdgePoints.slice();
  17721. }
  17722. newEdgePoints.unshift(group.mp0);
  17723. newEdgePoints.push(group.mp1);
  17724. newEdgePoints.unshift(edge.getStartPoint());
  17725. newEdgePoints.push(edge.getEndPoint());
  17726. newEdges.push({
  17727. points: cleanEdgePoints(newEdgePoints, edge.edge.points),
  17728. rawEdge: edge.edge
  17729. });
  17730. }
  17731. }
  17732. }
  17733. };
  17734. buildNewEdges(res.groups);
  17735. return newEdges;
  17736. },
  17737. _iterate: function (rawEdges) {
  17738. var edges = [];
  17739. var groups = [];
  17740. var totalSavedInk = 0;
  17741. for (var i = 0; i < rawEdges.length; i++) {
  17742. var edge = new Edge(rawEdges[i]);
  17743. edges.push(edge);
  17744. }
  17745. var tree = new KDTree(edges, 4);
  17746. var nearests = [];
  17747. var _mp0 = v2Create();
  17748. var _mp1 = v2Create();
  17749. var _newGroupInk = 0;
  17750. var mp0 = v2Create();
  17751. var mp1 = v2Create();
  17752. var newGroupInk = 0;
  17753. for (var i = 0; i < edges.length; i++) {
  17754. var edge = edges[i];
  17755. if (edge.group) {
  17756. continue;
  17757. }
  17758. tree.nearestN(edge, this.maxNearestEdge, squaredDistance, nearests);
  17759. var maxSavedInk = 0;
  17760. var mostSavingInkEdge = null;
  17761. var lastCheckedGroup = null;
  17762. for (var j = 0; j < nearests.length; j++) {
  17763. var nearest = nearests[j];
  17764. var savedInk = 0;
  17765. if (nearest.group) {
  17766. if (nearest.group !== lastCheckedGroup) {
  17767. lastCheckedGroup = nearest.group;
  17768. _newGroupInk = this._calculateGroupEdgeInk(nearest.group, edge, _mp0, _mp1);
  17769. savedInk = nearest.group.ink + edge.ink - _newGroupInk;
  17770. }
  17771. } else {
  17772. _newGroupInk = this._calculateEdgeEdgeInk(edge, nearest, _mp0, _mp1);
  17773. savedInk = nearest.ink + edge.ink - _newGroupInk;
  17774. }
  17775. if (savedInk > maxSavedInk) {
  17776. maxSavedInk = savedInk;
  17777. mostSavingInkEdge = nearest;
  17778. v2Copy(mp1, _mp1);
  17779. v2Copy(mp0, _mp0);
  17780. newGroupInk = _newGroupInk;
  17781. }
  17782. }
  17783. if (mostSavingInkEdge) {
  17784. totalSavedInk += maxSavedInk;
  17785. var group;
  17786. if (!mostSavingInkEdge.group) {
  17787. group = new BundledEdgeGroup();
  17788. groups.push(group);
  17789. group.addEdge(mostSavingInkEdge);
  17790. }
  17791. group = mostSavingInkEdge.group;
  17792. v2Copy(group.mp0, mp0);
  17793. v2Copy(group.mp1, mp1);
  17794. group.ink = newGroupInk;
  17795. mostSavingInkEdge.group.addEdge(edge);
  17796. } else {
  17797. var group = new BundledEdgeGroup();
  17798. groups.push(group);
  17799. v2Copy(group.mp0, edge.getStartPoint());
  17800. v2Copy(group.mp1, edge.getEndPoint());
  17801. group.ink = edge.ink;
  17802. group.addEdge(edge);
  17803. }
  17804. }
  17805. return {
  17806. groups: groups,
  17807. edges: edges,
  17808. savedInk: totalSavedInk
  17809. };
  17810. },
  17811. _calculateEdgeEdgeInk: function () {
  17812. var startPointSet = [];
  17813. var endPointSet = [];
  17814. return function (e0, e1, mp0, mp1) {
  17815. startPointSet[0] = e0.getStartPoint();
  17816. startPointSet[1] = e1.getStartPoint();
  17817. endPointSet[0] = e0.getEndPoint();
  17818. endPointSet[1] = e1.getEndPoint();
  17819. this._calculateMeetPoints(startPointSet, endPointSet, mp0, mp1);
  17820. var ink = v2Dist(startPointSet[0], mp0) + v2Dist(mp0, mp1) + v2Dist(mp1, endPointSet[0]) + v2Dist(startPointSet[1], mp0) + v2Dist(mp1, endPointSet[1]);
  17821. return ink;
  17822. };
  17823. }(),
  17824. _calculateGroupEdgeInk: function (group, edgeTryAdd, mp0, mp1) {
  17825. var startPointSet = [];
  17826. var endPointSet = [];
  17827. for (var i = 0; i < group.edgeList.length; i++) {
  17828. var edge = group.edgeList[i];
  17829. startPointSet.push(edge.getStartPoint());
  17830. endPointSet.push(edge.getEndPoint());
  17831. }
  17832. startPointSet.push(edgeTryAdd.getStartPoint());
  17833. endPointSet.push(edgeTryAdd.getEndPoint());
  17834. this._calculateMeetPoints(startPointSet, endPointSet, mp0, mp1);
  17835. var ink = v2Dist(mp0, mp1);
  17836. for (var i = 0; i < startPointSet.length; i++) {
  17837. ink += v2Dist(startPointSet[i], mp0) + v2Dist(endPointSet[i], mp1);
  17838. }
  17839. return ink;
  17840. },
  17841. _calculateMeetPoints: function () {
  17842. var cp0 = v2Create();
  17843. var cp1 = v2Create();
  17844. return function (startPointSet, endPointSet, mp0, mp1) {
  17845. vec2.set(cp0, 0, 0);
  17846. vec2.set(cp1, 0, 0);
  17847. var len = startPointSet.length;
  17848. for (var i = 0; i < len; i++) {
  17849. vec2.add(cp0, cp0, startPointSet[i]);
  17850. }
  17851. vec2.scale(cp0, cp0, 1 / len);
  17852. len = endPointSet.length;
  17853. for (var i = 0; i < len; i++) {
  17854. vec2.add(cp1, cp1, endPointSet[i]);
  17855. }
  17856. vec2.scale(cp1, cp1, 1 / len);
  17857. this._limitTurningAngle(startPointSet, cp0, cp1, mp0);
  17858. this._limitTurningAngle(endPointSet, cp1, cp0, mp1);
  17859. };
  17860. }(),
  17861. _limitTurningAngle: function () {
  17862. var v10 = v2Create();
  17863. var vTmp = v2Create();
  17864. var project = v2Create();
  17865. var tmpOut = v2Create();
  17866. return function (pointSet, p0, p1, out) {
  17867. var maxTurningAngleCos = Math.cos(this.maxTurningAngle);
  17868. var maxTurningAngleTan = Math.tan(this.maxTurningAngle);
  17869. vec2.sub(v10, p0, p1);
  17870. vec2.normalize(v10, v10);
  17871. vec2.copy(out, p0);
  17872. var maxMovement = 0;
  17873. for (var i = 0; i < pointSet.length; i++) {
  17874. var p = pointSet[i];
  17875. vec2.sub(vTmp, p, p0);
  17876. var len = vec2.len(vTmp);
  17877. vec2.scale(vTmp, vTmp, 1 / len);
  17878. var turningAngleCos = vec2.dot(vTmp, v10);
  17879. if (turningAngleCos < maxTurningAngleCos) {
  17880. vec2.scaleAndAdd(project, p0, v10, len * turningAngleCos);
  17881. var distance = v2Dist(project, p);
  17882. var d = distance / maxTurningAngleTan;
  17883. vec2.scaleAndAdd(tmpOut, project, v10, -d);
  17884. var movement = v2DistSquare(tmpOut, p0);
  17885. if (movement > maxMovement) {
  17886. maxMovement = movement;
  17887. vec2.copy(out, tmpOut);
  17888. }
  17889. }
  17890. }
  17891. };
  17892. }()
  17893. };
  17894. return EdgeBundling;
  17895. });define('zrender/shape/Star', [
  17896. 'require',
  17897. '../tool/math',
  17898. './Base',
  17899. '../tool/util'
  17900. ], function (require) {
  17901. var math = require('../tool/math');
  17902. var sin = math.sin;
  17903. var cos = math.cos;
  17904. var PI = Math.PI;
  17905. var Base = require('./Base');
  17906. var Star = function (options) {
  17907. Base.call(this, options);
  17908. };
  17909. Star.prototype = {
  17910. type: 'star',
  17911. buildPath: function (ctx, style) {
  17912. var n = style.n;
  17913. if (!n || n < 2) {
  17914. return;
  17915. }
  17916. var x = style.x;
  17917. var y = style.y;
  17918. var r = style.r;
  17919. var r0 = style.r0;
  17920. if (r0 == null) {
  17921. r0 = n > 4 ? r * cos(2 * PI / n) / cos(PI / n) : r / 3;
  17922. }
  17923. var dStep = PI / n;
  17924. var deg = -PI / 2;
  17925. var xStart = x + r * cos(deg);
  17926. var yStart = y + r * sin(deg);
  17927. deg += dStep;
  17928. var pointList = style.pointList = [];
  17929. pointList.push([
  17930. xStart,
  17931. yStart
  17932. ]);
  17933. for (var i = 0, end = n * 2 - 1, ri; i < end; i++) {
  17934. ri = i % 2 === 0 ? r0 : r;
  17935. pointList.push([
  17936. x + ri * cos(deg),
  17937. y + ri * sin(deg)
  17938. ]);
  17939. deg += dStep;
  17940. }
  17941. pointList.push([
  17942. xStart,
  17943. yStart
  17944. ]);
  17945. ctx.moveTo(pointList[0][0], pointList[0][1]);
  17946. for (var i = 0; i < pointList.length; i++) {
  17947. ctx.lineTo(pointList[i][0], pointList[i][1]);
  17948. }
  17949. ctx.closePath();
  17950. return;
  17951. },
  17952. getRect: function (style) {
  17953. if (style.__rect) {
  17954. return style.__rect;
  17955. }
  17956. var lineWidth;
  17957. if (style.brushType == 'stroke' || style.brushType == 'fill') {
  17958. lineWidth = style.lineWidth || 1;
  17959. } else {
  17960. lineWidth = 0;
  17961. }
  17962. style.__rect = {
  17963. x: Math.round(style.x - style.r - lineWidth / 2),
  17964. y: Math.round(style.y - style.r - lineWidth / 2),
  17965. width: style.r * 2 + lineWidth,
  17966. height: style.r * 2 + lineWidth
  17967. };
  17968. return style.__rect;
  17969. }
  17970. };
  17971. require('../tool/util').inherits(Star, Base);
  17972. return Star;
  17973. });define('zrender/shape/Heart', [
  17974. 'require',
  17975. './Base',
  17976. './util/PathProxy',
  17977. '../tool/area',
  17978. '../tool/util'
  17979. ], function (require) {
  17980. 'use strict';
  17981. var Base = require('./Base');
  17982. var PathProxy = require('./util/PathProxy');
  17983. var area = require('../tool/area');
  17984. var Heart = function (options) {
  17985. Base.call(this, options);
  17986. this._pathProxy = new PathProxy();
  17987. };
  17988. Heart.prototype = {
  17989. type: 'heart',
  17990. buildPath: function (ctx, style) {
  17991. var path = this._pathProxy || new PathProxy();
  17992. path.begin(ctx);
  17993. path.moveTo(style.x, style.y);
  17994. 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);
  17995. 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);
  17996. path.closePath();
  17997. return;
  17998. },
  17999. getRect: function (style) {
  18000. if (style.__rect) {
  18001. return style.__rect;
  18002. }
  18003. if (!this._pathProxy.isEmpty()) {
  18004. this.buildPath(null, style);
  18005. }
  18006. return this._pathProxy.fastBoundingRect();
  18007. },
  18008. isCover: function (x, y) {
  18009. var originPos = this.transformCoordToLocal(x, y);
  18010. x = originPos[0];
  18011. y = originPos[1];
  18012. if (this.isCoverRect(x, y)) {
  18013. return area.isInsidePath(this._pathProxy.pathCommands, this.style.lineWidth, this.style.brushType, x, y);
  18014. }
  18015. }
  18016. };
  18017. require('../tool/util').inherits(Heart, Base);
  18018. return Heart;
  18019. });define('zrender/shape/Droplet', [
  18020. 'require',
  18021. './Base',
  18022. './util/PathProxy',
  18023. '../tool/area',
  18024. '../tool/util'
  18025. ], function (require) {
  18026. 'use strict';
  18027. var Base = require('./Base');
  18028. var PathProxy = require('./util/PathProxy');
  18029. var area = require('../tool/area');
  18030. var Droplet = function (options) {
  18031. Base.call(this, options);
  18032. this._pathProxy = new PathProxy();
  18033. };
  18034. Droplet.prototype = {
  18035. type: 'droplet',
  18036. buildPath: function (ctx, style) {
  18037. var path = this._pathProxy || new PathProxy();
  18038. path.begin(ctx);
  18039. path.moveTo(style.x, style.y + style.a);
  18040. 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);
  18041. 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);
  18042. path.closePath();
  18043. },
  18044. getRect: function (style) {
  18045. if (style.__rect) {
  18046. return style.__rect;
  18047. }
  18048. if (!this._pathProxy.isEmpty()) {
  18049. this.buildPath(null, style);
  18050. }
  18051. return this._pathProxy.fastBoundingRect();
  18052. },
  18053. isCover: function (x, y) {
  18054. var originPos = this.transformCoordToLocal(x, y);
  18055. x = originPos[0];
  18056. y = originPos[1];
  18057. if (this.isCoverRect(x, y)) {
  18058. return area.isInsidePath(this._pathProxy.pathCommands, this.style.lineWidth, this.style.brushType, x, y);
  18059. }
  18060. }
  18061. };
  18062. require('../tool/util').inherits(Droplet, Base);
  18063. return Droplet;
  18064. });define('zrender/tool/math', [], function () {
  18065. var _radians = Math.PI / 180;
  18066. function sin(angle, isDegrees) {
  18067. return Math.sin(isDegrees ? angle * _radians : angle);
  18068. }
  18069. function cos(angle, isDegrees) {
  18070. return Math.cos(isDegrees ? angle * _radians : angle);
  18071. }
  18072. function degreeToRadian(angle) {
  18073. return angle * _radians;
  18074. }
  18075. function radianToDegree(angle) {
  18076. return angle / _radians;
  18077. }
  18078. return {
  18079. sin: sin,
  18080. cos: cos,
  18081. degreeToRadian: degreeToRadian,
  18082. radianToDegree: radianToDegree
  18083. };
  18084. });define('zrender/shape/util/PathProxy', [
  18085. 'require',
  18086. '../../tool/vector'
  18087. ], function (require) {
  18088. var vector = require('../../tool/vector');
  18089. var PathSegment = function (command, points) {
  18090. this.command = command;
  18091. this.points = points || null;
  18092. };
  18093. var PathProxy = function () {
  18094. this.pathCommands = [];
  18095. this._ctx = null;
  18096. this._min = [];
  18097. this._max = [];
  18098. };
  18099. PathProxy.prototype.fastBoundingRect = function () {
  18100. var min = this._min;
  18101. var max = this._max;
  18102. min[0] = min[1] = Infinity;
  18103. max[0] = max[1] = -Infinity;
  18104. for (var i = 0; i < this.pathCommands.length; i++) {
  18105. var seg = this.pathCommands[i];
  18106. var p = seg.points;
  18107. switch (seg.command) {
  18108. case 'M':
  18109. vector.min(min, min, p);
  18110. vector.max(max, max, p);
  18111. break;
  18112. case 'L':
  18113. vector.min(min, min, p);
  18114. vector.max(max, max, p);
  18115. break;
  18116. case 'C':
  18117. for (var j = 0; j < 6; j += 2) {
  18118. min[0] = Math.min(min[0], min[0], p[j]);
  18119. min[1] = Math.min(min[1], min[1], p[j + 1]);
  18120. max[0] = Math.max(max[0], max[0], p[j]);
  18121. max[1] = Math.max(max[1], max[1], p[j + 1]);
  18122. }
  18123. break;
  18124. case 'Q':
  18125. for (var j = 0; j < 4; j += 2) {
  18126. min[0] = Math.min(min[0], min[0], p[j]);
  18127. min[1] = Math.min(min[1], min[1], p[j + 1]);
  18128. max[0] = Math.max(max[0], max[0], p[j]);
  18129. max[1] = Math.max(max[1], max[1], p[j + 1]);
  18130. }
  18131. break;
  18132. case 'A':
  18133. var cx = p[0];
  18134. var cy = p[1];
  18135. var rx = p[2];
  18136. var ry = p[3];
  18137. min[0] = Math.min(min[0], min[0], cx - rx);
  18138. min[1] = Math.min(min[1], min[1], cy - ry);
  18139. max[0] = Math.max(max[0], max[0], cx + rx);
  18140. max[1] = Math.max(max[1], max[1], cy + ry);
  18141. break;
  18142. }
  18143. }
  18144. return {
  18145. x: min[0],
  18146. y: min[1],
  18147. width: max[0] - min[0],
  18148. height: max[1] - min[1]
  18149. };
  18150. };
  18151. PathProxy.prototype.begin = function (ctx) {
  18152. this._ctx = ctx || null;
  18153. this.pathCommands.length = 0;
  18154. return this;
  18155. };
  18156. PathProxy.prototype.moveTo = function (x, y) {
  18157. this.pathCommands.push(new PathSegment('M', [
  18158. x,
  18159. y
  18160. ]));
  18161. if (this._ctx) {
  18162. this._ctx.moveTo(x, y);
  18163. }
  18164. return this;
  18165. };
  18166. PathProxy.prototype.lineTo = function (x, y) {
  18167. this.pathCommands.push(new PathSegment('L', [
  18168. x,
  18169. y
  18170. ]));
  18171. if (this._ctx) {
  18172. this._ctx.lineTo(x, y);
  18173. }
  18174. return this;
  18175. };
  18176. PathProxy.prototype.bezierCurveTo = function (x1, y1, x2, y2, x3, y3) {
  18177. this.pathCommands.push(new PathSegment('C', [
  18178. x1,
  18179. y1,
  18180. x2,
  18181. y2,
  18182. x3,
  18183. y3
  18184. ]));
  18185. if (this._ctx) {
  18186. this._ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  18187. }
  18188. return this;
  18189. };
  18190. PathProxy.prototype.quadraticCurveTo = function (x1, y1, x2, y2) {
  18191. this.pathCommands.push(new PathSegment('Q', [
  18192. x1,
  18193. y1,
  18194. x2,
  18195. y2
  18196. ]));
  18197. if (this._ctx) {
  18198. this._ctx.quadraticCurveTo(x1, y1, x2, y2);
  18199. }
  18200. return this;
  18201. };
  18202. PathProxy.prototype.arc = function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  18203. this.pathCommands.push(new PathSegment('A', [
  18204. cx,
  18205. cy,
  18206. r,
  18207. r,
  18208. startAngle,
  18209. endAngle - startAngle,
  18210. 0,
  18211. anticlockwise ? 0 : 1
  18212. ]));
  18213. if (this._ctx) {
  18214. this._ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  18215. }
  18216. return this;
  18217. };
  18218. PathProxy.prototype.arcTo = function (x1, y1, x2, y2, radius) {
  18219. if (this._ctx) {
  18220. this._ctx.arcTo(x1, y1, x2, y2, radius);
  18221. }
  18222. return this;
  18223. };
  18224. PathProxy.prototype.rect = function (x, y, w, h) {
  18225. if (this._ctx) {
  18226. this._ctx.rect(x, y, w, h);
  18227. }
  18228. return this;
  18229. };
  18230. PathProxy.prototype.closePath = function () {
  18231. this.pathCommands.push(new PathSegment('z'));
  18232. if (this._ctx) {
  18233. this._ctx.closePath();
  18234. }
  18235. return this;
  18236. };
  18237. PathProxy.prototype.isEmpty = function () {
  18238. return this.pathCommands.length === 0;
  18239. };
  18240. PathProxy.PathSegment = PathSegment;
  18241. return PathProxy;
  18242. });define('zrender/shape/Line', [
  18243. 'require',
  18244. './Base',
  18245. './util/dashedLineTo',
  18246. '../tool/util'
  18247. ], function (require) {
  18248. var Base = require('./Base');
  18249. var dashedLineTo = require('./util/dashedLineTo');
  18250. var Line = function (options) {
  18251. this.brushTypeOnly = 'stroke';
  18252. this.textPosition = 'end';
  18253. Base.call(this, options);
  18254. };
  18255. Line.prototype = {
  18256. type: 'line',
  18257. buildPath: function (ctx, style) {
  18258. if (!style.lineType || style.lineType == 'solid') {
  18259. ctx.moveTo(style.xStart, style.yStart);
  18260. ctx.lineTo(style.xEnd, style.yEnd);
  18261. } else if (style.lineType == 'dashed' || style.lineType == 'dotted') {
  18262. var dashLength = (style.lineWidth || 1) * (style.lineType == 'dashed' ? 5 : 1);
  18263. dashedLineTo(ctx, style.xStart, style.yStart, style.xEnd, style.yEnd, dashLength);
  18264. }
  18265. },
  18266. getRect: function (style) {
  18267. if (style.__rect) {
  18268. return style.__rect;
  18269. }
  18270. var lineWidth = style.lineWidth || 1;
  18271. style.__rect = {
  18272. x: Math.min(style.xStart, style.xEnd) - lineWidth,
  18273. y: Math.min(style.yStart, style.yEnd) - lineWidth,
  18274. width: Math.abs(style.xStart - style.xEnd) + lineWidth,
  18275. height: Math.abs(style.yStart - style.yEnd) + lineWidth
  18276. };
  18277. return style.__rect;
  18278. }
  18279. };
  18280. require('../tool/util').inherits(Line, Base);
  18281. return Line;
  18282. });define('zrender/shape/BezierCurve', [
  18283. 'require',
  18284. './Base',
  18285. '../tool/util'
  18286. ], function (require) {
  18287. 'use strict';
  18288. var Base = require('./Base');
  18289. var BezierCurve = function (options) {
  18290. this.brushTypeOnly = 'stroke';
  18291. this.textPosition = 'end';
  18292. Base.call(this, options);
  18293. };
  18294. BezierCurve.prototype = {
  18295. type: 'bezier-curve',
  18296. buildPath: function (ctx, style) {
  18297. ctx.moveTo(style.xStart, style.yStart);
  18298. if (typeof style.cpX2 != 'undefined' && typeof style.cpY2 != 'undefined') {
  18299. ctx.bezierCurveTo(style.cpX1, style.cpY1, style.cpX2, style.cpY2, style.xEnd, style.yEnd);
  18300. } else {
  18301. ctx.quadraticCurveTo(style.cpX1, style.cpY1, style.xEnd, style.yEnd);
  18302. }
  18303. },
  18304. getRect: function (style) {
  18305. if (style.__rect) {
  18306. return style.__rect;
  18307. }
  18308. var _minX = Math.min(style.xStart, style.xEnd, style.cpX1);
  18309. var _minY = Math.min(style.yStart, style.yEnd, style.cpY1);
  18310. var _maxX = Math.max(style.xStart, style.xEnd, style.cpX1);
  18311. var _maxY = Math.max(style.yStart, style.yEnd, style.cpY1);
  18312. var _x2 = style.cpX2;
  18313. var _y2 = style.cpY2;
  18314. if (typeof _x2 != 'undefined' && typeof _y2 != 'undefined') {
  18315. _minX = Math.min(_minX, _x2);
  18316. _minY = Math.min(_minY, _y2);
  18317. _maxX = Math.max(_maxX, _x2);
  18318. _maxY = Math.max(_maxY, _y2);
  18319. }
  18320. var lineWidth = style.lineWidth || 1;
  18321. style.__rect = {
  18322. x: _minX - lineWidth,
  18323. y: _minY - lineWidth,
  18324. width: _maxX - _minX + lineWidth,
  18325. height: _maxY - _minY + lineWidth
  18326. };
  18327. return style.__rect;
  18328. }
  18329. };
  18330. require('../tool/util').inherits(BezierCurve, Base);
  18331. return BezierCurve;
  18332. });define('zrender/shape/util/dashedLineTo', [], function () {
  18333. var dashPattern = [
  18334. 5,
  18335. 5
  18336. ];
  18337. return function (ctx, x1, y1, x2, y2, dashLength) {
  18338. if (ctx.setLineDash) {
  18339. dashPattern[0] = dashPattern[1] = dashLength;
  18340. ctx.setLineDash(dashPattern);
  18341. ctx.moveTo(x1, y1);
  18342. ctx.lineTo(x2, y2);
  18343. return;
  18344. }
  18345. dashLength = typeof dashLength != 'number' ? 5 : dashLength;
  18346. var dx = x2 - x1;
  18347. var dy = y2 - y1;
  18348. var numDashes = Math.floor(Math.sqrt(dx * dx + dy * dy) / dashLength);
  18349. dx = dx / numDashes;
  18350. dy = dy / numDashes;
  18351. var flag = true;
  18352. for (var i = 0; i < numDashes; ++i) {
  18353. if (flag) {
  18354. ctx.moveTo(x1, y1);
  18355. } else {
  18356. ctx.lineTo(x1, y1);
  18357. }
  18358. flag = !flag;
  18359. x1 += dx;
  18360. y1 += dy;
  18361. }
  18362. ctx.lineTo(x2, y2);
  18363. };
  18364. });define('zrender/shape/Polygon', [
  18365. 'require',
  18366. './Base',
  18367. './util/smoothSpline',
  18368. './util/smoothBezier',
  18369. './util/dashedLineTo',
  18370. '../tool/util'
  18371. ], function (require) {
  18372. var Base = require('./Base');
  18373. var smoothSpline = require('./util/smoothSpline');
  18374. var smoothBezier = require('./util/smoothBezier');
  18375. var dashedLineTo = require('./util/dashedLineTo');
  18376. var Polygon = function (options) {
  18377. Base.call(this, options);
  18378. };
  18379. Polygon.prototype = {
  18380. type: 'polygon',
  18381. buildPath: function (ctx, style) {
  18382. var pointList = style.pointList;
  18383. if (pointList.length < 2) {
  18384. return;
  18385. }
  18386. if (style.smooth && style.smooth !== 'spline') {
  18387. var controlPoints = smoothBezier(pointList, style.smooth, true, style.smoothConstraint);
  18388. ctx.moveTo(pointList[0][0], pointList[0][1]);
  18389. var cp1;
  18390. var cp2;
  18391. var p;
  18392. var len = pointList.length;
  18393. for (var i = 0; i < len; i++) {
  18394. cp1 = controlPoints[i * 2];
  18395. cp2 = controlPoints[i * 2 + 1];
  18396. p = pointList[(i + 1) % len];
  18397. ctx.bezierCurveTo(cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]);
  18398. }
  18399. } else {
  18400. if (style.smooth === 'spline') {
  18401. pointList = smoothSpline(pointList, true);
  18402. }
  18403. if (!style.lineType || style.lineType == 'solid') {
  18404. ctx.moveTo(pointList[0][0], pointList[0][1]);
  18405. for (var i = 1, l = pointList.length; i < l; i++) {
  18406. ctx.lineTo(pointList[i][0], pointList[i][1]);
  18407. }
  18408. ctx.lineTo(pointList[0][0], pointList[0][1]);
  18409. } else if (style.lineType == 'dashed' || style.lineType == 'dotted') {
  18410. var dashLength = style._dashLength || (style.lineWidth || 1) * (style.lineType == 'dashed' ? 5 : 1);
  18411. style._dashLength = dashLength;
  18412. ctx.moveTo(pointList[0][0], pointList[0][1]);
  18413. for (var i = 1, l = pointList.length; i < l; i++) {
  18414. dashedLineTo(ctx, pointList[i - 1][0], pointList[i - 1][1], pointList[i][0], pointList[i][1], dashLength);
  18415. }
  18416. dashedLineTo(ctx, pointList[pointList.length - 1][0], pointList[pointList.length - 1][1], pointList[0][0], pointList[0][1], dashLength);
  18417. }
  18418. }
  18419. ctx.closePath();
  18420. return;
  18421. },
  18422. getRect: function (style) {
  18423. if (style.__rect) {
  18424. return style.__rect;
  18425. }
  18426. var minX = Number.MAX_VALUE;
  18427. var maxX = Number.MIN_VALUE;
  18428. var minY = Number.MAX_VALUE;
  18429. var maxY = Number.MIN_VALUE;
  18430. var pointList = style.pointList;
  18431. for (var i = 0, l = pointList.length; i < l; i++) {
  18432. if (pointList[i][0] < minX) {
  18433. minX = pointList[i][0];
  18434. }
  18435. if (pointList[i][0] > maxX) {
  18436. maxX = pointList[i][0];
  18437. }
  18438. if (pointList[i][1] < minY) {
  18439. minY = pointList[i][1];
  18440. }
  18441. if (pointList[i][1] > maxY) {
  18442. maxY = pointList[i][1];
  18443. }
  18444. }
  18445. var lineWidth;
  18446. if (style.brushType == 'stroke' || style.brushType == 'fill') {
  18447. lineWidth = style.lineWidth || 1;
  18448. } else {
  18449. lineWidth = 0;
  18450. }
  18451. style.__rect = {
  18452. x: Math.round(minX - lineWidth / 2),
  18453. y: Math.round(minY - lineWidth / 2),
  18454. width: maxX - minX + lineWidth,
  18455. height: maxY - minY + lineWidth
  18456. };
  18457. return style.__rect;
  18458. }
  18459. };
  18460. require('../tool/util').inherits(Polygon, Base);
  18461. return Polygon;
  18462. });define('echarts/util/shape/normalIsCover', [], function () {
  18463. return function (x, y) {
  18464. var originPos = this.transformCoordToLocal(x, y);
  18465. x = originPos[0];
  18466. y = originPos[1];
  18467. return this.isCoverRect(x, y);
  18468. };
  18469. });define('zrender/shape/util/smoothSpline', [
  18470. 'require',
  18471. '../../tool/vector'
  18472. ], function (require) {
  18473. var vector = require('../../tool/vector');
  18474. function interpolate(p0, p1, p2, p3, t, t2, t3) {
  18475. var v0 = (p2 - p0) * 0.5;
  18476. var v1 = (p3 - p1) * 0.5;
  18477. return (2 * (p1 - p2) + v0 + v1) * t3 + (-3 * (p1 - p2) - 2 * v0 - v1) * t2 + v0 * t + p1;
  18478. }
  18479. return function (points, isLoop, constraint) {
  18480. var len = points.length;
  18481. var ret = [];
  18482. var distance = 0;
  18483. for (var i = 1; i < len; i++) {
  18484. distance += vector.distance(points[i - 1], points[i]);
  18485. }
  18486. var segs = distance / 5;
  18487. segs = segs < len ? len : segs;
  18488. for (var i = 0; i < segs; i++) {
  18489. var pos = i / (segs - 1) * (isLoop ? len : len - 1);
  18490. var idx = Math.floor(pos);
  18491. var w = pos - idx;
  18492. var p0;
  18493. var p1 = points[idx % len];
  18494. var p2;
  18495. var p3;
  18496. if (!isLoop) {
  18497. p0 = points[idx === 0 ? idx : idx - 1];
  18498. p2 = points[idx > len - 2 ? len - 1 : idx + 1];
  18499. p3 = points[idx > len - 3 ? len - 1 : idx + 2];
  18500. } else {
  18501. p0 = points[(idx - 1 + len) % len];
  18502. p2 = points[(idx + 1) % len];
  18503. p3 = points[(idx + 2) % len];
  18504. }
  18505. var w2 = w * w;
  18506. var w3 = w * w2;
  18507. ret.push([
  18508. interpolate(p0[0], p1[0], p2[0], p3[0], w, w2, w3),
  18509. interpolate(p0[1], p1[1], p2[1], p3[1], w, w2, w3)
  18510. ]);
  18511. }
  18512. return ret;
  18513. };
  18514. });define('zrender/shape/util/smoothBezier', [
  18515. 'require',
  18516. '../../tool/vector'
  18517. ], function (require) {
  18518. var vector = require('../../tool/vector');
  18519. return function (points, smooth, isLoop, constraint) {
  18520. var cps = [];
  18521. var v = [];
  18522. var v1 = [];
  18523. var v2 = [];
  18524. var prevPoint;
  18525. var nextPoint;
  18526. var hasConstraint = !!constraint;
  18527. var min, max;
  18528. if (hasConstraint) {
  18529. min = [
  18530. Infinity,
  18531. Infinity
  18532. ];
  18533. max = [
  18534. -Infinity,
  18535. -Infinity
  18536. ];
  18537. for (var i = 0, len = points.length; i < len; i++) {
  18538. vector.min(min, min, points[i]);
  18539. vector.max(max, max, points[i]);
  18540. }
  18541. vector.min(min, min, constraint[0]);
  18542. vector.max(max, max, constraint[1]);
  18543. }
  18544. for (var i = 0, len = points.length; i < len; i++) {
  18545. var point = points[i];
  18546. var prevPoint;
  18547. var nextPoint;
  18548. if (isLoop) {
  18549. prevPoint = points[i ? i - 1 : len - 1];
  18550. nextPoint = points[(i + 1) % len];
  18551. } else {
  18552. if (i === 0 || i === len - 1) {
  18553. cps.push(vector.clone(points[i]));
  18554. continue;
  18555. } else {
  18556. prevPoint = points[i - 1];
  18557. nextPoint = points[i + 1];
  18558. }
  18559. }
  18560. vector.sub(v, nextPoint, prevPoint);
  18561. vector.scale(v, v, smooth);
  18562. var d0 = vector.distance(point, prevPoint);
  18563. var d1 = vector.distance(point, nextPoint);
  18564. var sum = d0 + d1;
  18565. if (sum !== 0) {
  18566. d0 /= sum;
  18567. d1 /= sum;
  18568. }
  18569. vector.scale(v1, v, -d0);
  18570. vector.scale(v2, v, d1);
  18571. var cp0 = vector.add([], point, v1);
  18572. var cp1 = vector.add([], point, v2);
  18573. if (hasConstraint) {
  18574. vector.max(cp0, cp0, min);
  18575. vector.min(cp0, cp0, max);
  18576. vector.max(cp1, cp1, min);
  18577. vector.min(cp1, cp1, max);
  18578. }
  18579. cps.push(cp0);
  18580. cps.push(cp1);
  18581. }
  18582. if (isLoop) {
  18583. cps.push(vector.clone(cps.shift()));
  18584. }
  18585. return cps;
  18586. };
  18587. });define('echarts/util/ecQuery', [
  18588. 'require',
  18589. 'zrender/tool/util'
  18590. ], function (require) {
  18591. var zrUtil = require('zrender/tool/util');
  18592. function query(optionTarget, optionLocation) {
  18593. if (typeof optionTarget == 'undefined') {
  18594. return;
  18595. }
  18596. if (!optionLocation) {
  18597. return optionTarget;
  18598. }
  18599. optionLocation = optionLocation.split('.');
  18600. var length = optionLocation.length;
  18601. var curIdx = 0;
  18602. while (curIdx < length) {
  18603. optionTarget = optionTarget[optionLocation[curIdx]];
  18604. if (typeof optionTarget == 'undefined') {
  18605. return;
  18606. }
  18607. curIdx++;
  18608. }
  18609. return optionTarget;
  18610. }
  18611. function deepQuery(ctrList, optionLocation) {
  18612. var finalOption;
  18613. for (var i = 0, l = ctrList.length; i < l; i++) {
  18614. finalOption = query(ctrList[i], optionLocation);
  18615. if (typeof finalOption != 'undefined') {
  18616. return finalOption;
  18617. }
  18618. }
  18619. }
  18620. function deepMerge(ctrList, optionLocation) {
  18621. var finalOption;
  18622. var len = ctrList.length;
  18623. while (len--) {
  18624. var tempOption = query(ctrList[len], optionLocation);
  18625. if (typeof tempOption != 'undefined') {
  18626. if (typeof finalOption == 'undefined') {
  18627. finalOption = zrUtil.clone(tempOption);
  18628. } else {
  18629. zrUtil.merge(finalOption, tempOption, true);
  18630. }
  18631. }
  18632. }
  18633. return finalOption;
  18634. }
  18635. return {
  18636. query: query,
  18637. deepQuery: deepQuery,
  18638. deepMerge: deepMerge
  18639. };
  18640. });define('echarts/util/number', [], function () {
  18641. function _trim(str) {
  18642. return str.replace(/^\s+/, '').replace(/\s+$/, '');
  18643. }
  18644. function parsePercent(value, maxValue) {
  18645. if (typeof value === 'string') {
  18646. if (_trim(value).match(/%$/)) {
  18647. return parseFloat(value) / 100 * maxValue;
  18648. }
  18649. return parseFloat(value);
  18650. }
  18651. return value;
  18652. }
  18653. function parseCenter(zr, center) {
  18654. return [
  18655. parsePercent(center[0], zr.getWidth()),
  18656. parsePercent(center[1], zr.getHeight())
  18657. ];
  18658. }
  18659. function parseRadius(zr, radius) {
  18660. if (!(radius instanceof Array)) {
  18661. radius = [
  18662. 0,
  18663. radius
  18664. ];
  18665. }
  18666. var zrSize = Math.min(zr.getWidth(), zr.getHeight()) / 2;
  18667. return [
  18668. parsePercent(radius[0], zrSize),
  18669. parsePercent(radius[1], zrSize)
  18670. ];
  18671. }
  18672. function addCommas(x) {
  18673. if (isNaN(x)) {
  18674. return '-';
  18675. }
  18676. x = (x + '').split('.');
  18677. return x[0].replace(/(\d{1,3})(?=(?:\d{3})+(?!\d))/g, '$1,') + (x.length > 1 ? '.' + x[1] : '');
  18678. }
  18679. return {
  18680. parsePercent: parsePercent,
  18681. parseCenter: parseCenter,
  18682. parseRadius: parseRadius,
  18683. addCommas: addCommas
  18684. };
  18685. });define('echarts/data/KDTree', [
  18686. 'require',
  18687. './quickSelect'
  18688. ], function (require) {
  18689. var quickSelect = require('./quickSelect');
  18690. function Node(axis, data) {
  18691. this.left = null;
  18692. this.right = null;
  18693. this.axis = axis;
  18694. this.data = data;
  18695. }
  18696. var KDTree = function (points, dimension) {
  18697. if (!points.length) {
  18698. return;
  18699. }
  18700. if (!dimension) {
  18701. dimension = points[0].array.length;
  18702. }
  18703. this.dimension = dimension;
  18704. this.root = this._buildTree(points, 0, points.length - 1, 0);
  18705. this._stack = [];
  18706. this._nearstNList = [];
  18707. };
  18708. KDTree.prototype._buildTree = function (points, left, right, axis) {
  18709. if (right < left) {
  18710. return null;
  18711. }
  18712. var medianIndex = Math.floor((left + right) / 2);
  18713. medianIndex = quickSelect(points, left, right, medianIndex, function (a, b) {
  18714. return a.array[axis] - b.array[axis];
  18715. });
  18716. var median = points[medianIndex];
  18717. var node = new Node(axis, median);
  18718. axis = (axis + 1) % this.dimension;
  18719. if (right > left) {
  18720. node.left = this._buildTree(points, left, medianIndex - 1, axis);
  18721. node.right = this._buildTree(points, medianIndex + 1, right, axis);
  18722. }
  18723. return node;
  18724. };
  18725. KDTree.prototype.nearest = function (target, squaredDistance) {
  18726. var curr = this.root;
  18727. var stack = this._stack;
  18728. var idx = 0;
  18729. var minDist = Infinity;
  18730. var nearestNode = null;
  18731. if (curr.data !== target) {
  18732. minDist = squaredDistance(curr.data, target);
  18733. nearestNode = curr;
  18734. }
  18735. if (target.array[curr.axis] < curr.data.array[curr.axis]) {
  18736. curr.right && (stack[idx++] = curr.right);
  18737. curr.left && (stack[idx++] = curr.left);
  18738. } else {
  18739. curr.left && (stack[idx++] = curr.left);
  18740. curr.right && (stack[idx++] = curr.right);
  18741. }
  18742. while (idx--) {
  18743. curr = stack[idx];
  18744. var currDist = target.array[curr.axis] - curr.data.array[curr.axis];
  18745. var isLeft = currDist < 0;
  18746. var needsCheckOtherSide = false;
  18747. currDist = currDist * currDist;
  18748. if (currDist < minDist) {
  18749. currDist = squaredDistance(curr.data, target);
  18750. if (currDist < minDist && curr.data !== target) {
  18751. minDist = currDist;
  18752. nearestNode = curr;
  18753. }
  18754. needsCheckOtherSide = true;
  18755. }
  18756. if (isLeft) {
  18757. if (needsCheckOtherSide) {
  18758. curr.right && (stack[idx++] = curr.right);
  18759. }
  18760. curr.left && (stack[idx++] = curr.left);
  18761. } else {
  18762. if (needsCheckOtherSide) {
  18763. curr.left && (stack[idx++] = curr.left);
  18764. }
  18765. curr.right && (stack[idx++] = curr.right);
  18766. }
  18767. }
  18768. return nearestNode.data;
  18769. };
  18770. KDTree.prototype._addNearest = function (found, dist, node) {
  18771. var nearestNList = this._nearstNList;
  18772. for (var i = found - 1; i > 0; i--) {
  18773. if (dist >= nearestNList[i - 1].dist) {
  18774. break;
  18775. } else {
  18776. nearestNList[i].dist = nearestNList[i - 1].dist;
  18777. nearestNList[i].node = nearestNList[i - 1].node;
  18778. }
  18779. }
  18780. nearestNList[i].dist = dist;
  18781. nearestNList[i].node = node;
  18782. };
  18783. KDTree.prototype.nearestN = function (target, N, squaredDistance, output) {
  18784. if (N <= 0) {
  18785. output.length = 0;
  18786. return output;
  18787. }
  18788. var curr = this.root;
  18789. var stack = this._stack;
  18790. var idx = 0;
  18791. var nearestNList = this._nearstNList;
  18792. for (var i = 0; i < N; i++) {
  18793. if (!nearestNList[i]) {
  18794. nearestNList[i] = {};
  18795. }
  18796. nearestNList[i].dist = 0;
  18797. nearestNList[i].node = null;
  18798. }
  18799. var currDist = squaredDistance(curr.data, target);
  18800. var found = 0;
  18801. if (curr.data !== target) {
  18802. found++;
  18803. this._addNearest(found, currDist, curr);
  18804. }
  18805. if (target.array[curr.axis] < curr.data.array[curr.axis]) {
  18806. curr.right && (stack[idx++] = curr.right);
  18807. curr.left && (stack[idx++] = curr.left);
  18808. } else {
  18809. curr.left && (stack[idx++] = curr.left);
  18810. curr.right && (stack[idx++] = curr.right);
  18811. }
  18812. while (idx--) {
  18813. curr = stack[idx];
  18814. var currDist = target.array[curr.axis] - curr.data.array[curr.axis];
  18815. var isLeft = currDist < 0;
  18816. var needsCheckOtherSide = false;
  18817. currDist = currDist * currDist;
  18818. if (found < N || currDist < nearestNList[found - 1].dist) {
  18819. currDist = squaredDistance(curr.data, target);
  18820. if ((found < N || currDist < nearestNList[found - 1].dist) && curr.data !== target) {
  18821. if (found < N) {
  18822. found++;
  18823. }
  18824. this._addNearest(found, currDist, curr);
  18825. }
  18826. needsCheckOtherSide = true;
  18827. }
  18828. if (isLeft) {
  18829. if (needsCheckOtherSide) {
  18830. curr.right && (stack[idx++] = curr.right);
  18831. }
  18832. curr.left && (stack[idx++] = curr.left);
  18833. } else {
  18834. if (needsCheckOtherSide) {
  18835. curr.left && (stack[idx++] = curr.left);
  18836. }
  18837. curr.right && (stack[idx++] = curr.right);
  18838. }
  18839. }
  18840. for (var i = 0; i < found; i++) {
  18841. output[i] = nearestNList[i].node.data;
  18842. }
  18843. output.length = found;
  18844. return output;
  18845. };
  18846. return KDTree;
  18847. });define('echarts/data/quickSelect', ['require'], function (require) {
  18848. function defaultCompareFunc(a, b) {
  18849. return a - b;
  18850. }
  18851. function swapElement(list, idx0, idx1) {
  18852. var tmp = list[idx0];
  18853. list[idx0] = list[idx1];
  18854. list[idx1] = tmp;
  18855. }
  18856. function select(list, left, right, nth, compareFunc) {
  18857. var pivotIdx = left;
  18858. while (right > left) {
  18859. var pivotIdx = Math.round((right + left) / 2);
  18860. var pivotValue = list[pivotIdx];
  18861. swapElement(list, pivotIdx, right);
  18862. pivotIdx = left;
  18863. for (var i = left; i <= right - 1; i++) {
  18864. if (compareFunc(pivotValue, list[i]) >= 0) {
  18865. swapElement(list, i, pivotIdx);
  18866. pivotIdx++;
  18867. }
  18868. }
  18869. swapElement(list, right, pivotIdx);
  18870. if (pivotIdx === nth) {
  18871. return pivotIdx;
  18872. } else if (pivotIdx < nth) {
  18873. left = pivotIdx + 1;
  18874. } else {
  18875. right = pivotIdx - 1;
  18876. }
  18877. }
  18878. return left;
  18879. }
  18880. function quickSelect(list, left, right, nth, compareFunc) {
  18881. if (arguments.length <= 3) {
  18882. nth = left;
  18883. if (arguments.length == 2) {
  18884. compareFunc = defaultCompareFunc;
  18885. } else {
  18886. compareFunc = right;
  18887. }
  18888. left = 0;
  18889. right = list.length - 1;
  18890. }
  18891. return select(list, left, right, nth, compareFunc);
  18892. }
  18893. return quickSelect;
  18894. });define('echarts/component/dataView', [
  18895. 'require',
  18896. './base',
  18897. '../config',
  18898. 'zrender/tool/util',
  18899. '../component'
  18900. ], function (require) {
  18901. var Base = require('./base');
  18902. var ecConfig = require('../config');
  18903. var zrUtil = require('zrender/tool/util');
  18904. function DataView(ecTheme, messageCenter, zr, option, myChart) {
  18905. Base.call(this, ecTheme, messageCenter, zr, option, myChart);
  18906. this.dom = myChart.dom;
  18907. this._tDom = document.createElement('div');
  18908. this._textArea = document.createElement('textArea');
  18909. this._buttonRefresh = document.createElement('button');
  18910. this._buttonClose = document.createElement('button');
  18911. this._hasShow = false;
  18912. this._zrHeight = zr.getHeight();
  18913. this._zrWidth = zr.getWidth();
  18914. this._tDom.className = 'echarts-dataview';
  18915. this.hide();
  18916. this.dom.firstChild.appendChild(this._tDom);
  18917. if (window.addEventListener) {
  18918. this._tDom.addEventListener('click', this._stop);
  18919. this._tDom.addEventListener('mousewheel', this._stop);
  18920. this._tDom.addEventListener('mousemove', this._stop);
  18921. this._tDom.addEventListener('mousedown', this._stop);
  18922. this._tDom.addEventListener('mouseup', this._stop);
  18923. this._tDom.addEventListener('touchstart', this._stop);
  18924. this._tDom.addEventListener('touchmove', this._stop);
  18925. this._tDom.addEventListener('touchend', this._stop);
  18926. } else {
  18927. this._tDom.attachEvent('onclick', this._stop);
  18928. this._tDom.attachEvent('onmousewheel', this._stop);
  18929. this._tDom.attachEvent('onmousemove', this._stop);
  18930. this._tDom.attachEvent('onmousedown', this._stop);
  18931. this._tDom.attachEvent('onmouseup', this._stop);
  18932. }
  18933. }
  18934. DataView.prototype = {
  18935. type: ecConfig.COMPONENT_TYPE_DATAVIEW,
  18936. _lang: [
  18937. 'Data View',
  18938. 'close',
  18939. 'refresh'
  18940. ],
  18941. _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;',
  18942. hide: function () {
  18943. this._sizeCssText = 'width:' + this._zrWidth + 'px;' + 'height:' + 0 + 'px;' + 'background-color:#f0ffff;';
  18944. this._tDom.style.cssText = this._gCssText + this._sizeCssText;
  18945. },
  18946. show: function (newOption) {
  18947. this._hasShow = true;
  18948. var lang = this.query(this.option, 'toolbox.feature.dataView.lang') || this._lang;
  18949. this.option = newOption;
  18950. this._tDom.innerHTML = '<p style="padding:8px 0;margin:0 0 10px 0;' + 'border-bottom:1px solid #eee">' + (lang[0] || this._lang[0]) + '</p>';
  18951. var customContent = this.query(this.option, 'toolbox.feature.dataView.optionToContent');
  18952. if (typeof customContent != 'function') {
  18953. this._textArea.value = this._optionToContent();
  18954. } else {
  18955. this._textArea = document.createElement('div');
  18956. this._textArea.innerHTML = customContent(this.option);
  18957. }
  18958. this._textArea.style.cssText = 'display:block;margin:0 0 8px 0;padding:4px 6px;overflow:auto;' + 'width:100%;' + 'height:' + (this._zrHeight - 100) + 'px;';
  18959. this._tDom.appendChild(this._textArea);
  18960. this._buttonClose.style.cssText = 'float:right;padding:1px 6px;';
  18961. this._buttonClose.innerHTML = lang[1] || this._lang[1];
  18962. var self = this;
  18963. this._buttonClose.onclick = function () {
  18964. self.hide();
  18965. };
  18966. this._tDom.appendChild(this._buttonClose);
  18967. if (this.query(this.option, 'toolbox.feature.dataView.readOnly') === false) {
  18968. this._buttonRefresh.style.cssText = 'float:right;margin-right:10px;padding:1px 6px;';
  18969. this._buttonRefresh.innerHTML = lang[2] || this._lang[2];
  18970. this._buttonRefresh.onclick = function () {
  18971. self._save();
  18972. };
  18973. this._textArea.readOnly = false;
  18974. this._textArea.style.cursor = 'default';
  18975. } else {
  18976. this._buttonRefresh.style.cssText = 'display:none';
  18977. this._textArea.readOnly = true;
  18978. this._textArea.style.cursor = 'text';
  18979. }
  18980. this._tDom.appendChild(this._buttonRefresh);
  18981. this._sizeCssText = 'width:' + this._zrWidth + 'px;' + 'height:' + this._zrHeight + 'px;' + 'background-color:#fff;';
  18982. this._tDom.style.cssText = this._gCssText + this._sizeCssText;
  18983. },
  18984. _optionToContent: function () {
  18985. var i;
  18986. var j;
  18987. var k;
  18988. var len;
  18989. var data;
  18990. var valueList;
  18991. var axisList = [];
  18992. var content = '';
  18993. if (this.option.xAxis) {
  18994. if (this.option.xAxis instanceof Array) {
  18995. axisList = this.option.xAxis;
  18996. } else {
  18997. axisList = [this.option.xAxis];
  18998. }
  18999. for (i = 0, len = axisList.length; i < len; i++) {
  19000. if ((axisList[i].type || 'category') == 'category') {
  19001. valueList = [];
  19002. for (j = 0, k = axisList[i].data.length; j < k; j++) {
  19003. valueList.push(this.getDataFromOption(axisList[i].data[j]));
  19004. }
  19005. content += valueList.join(', ') + '\n\n';
  19006. }
  19007. }
  19008. }
  19009. if (this.option.yAxis) {
  19010. if (this.option.yAxis instanceof Array) {
  19011. axisList = this.option.yAxis;
  19012. } else {
  19013. axisList = [this.option.yAxis];
  19014. }
  19015. for (i = 0, len = axisList.length; i < len; i++) {
  19016. if (axisList[i].type == 'category') {
  19017. valueList = [];
  19018. for (j = 0, k = axisList[i].data.length; j < k; j++) {
  19019. valueList.push(this.getDataFromOption(axisList[i].data[j]));
  19020. }
  19021. content += valueList.join(', ') + '\n\n';
  19022. }
  19023. }
  19024. }
  19025. var series = this.option.series;
  19026. var itemName;
  19027. for (i = 0, len = series.length; i < len; i++) {
  19028. valueList = [];
  19029. for (j = 0, k = series[i].data.length; j < k; j++) {
  19030. data = series[i].data[j];
  19031. if (series[i].type == ecConfig.CHART_TYPE_PIE || series[i].type == ecConfig.CHART_TYPE_MAP) {
  19032. itemName = (data.name || '-') + ':';
  19033. } else {
  19034. itemName = '';
  19035. }
  19036. if (series[i].type == ecConfig.CHART_TYPE_SCATTER) {
  19037. data = this.getDataFromOption(data).join(', ');
  19038. }
  19039. valueList.push(itemName + this.getDataFromOption(data));
  19040. }
  19041. content += (series[i].name || '-') + ' : \n';
  19042. content += valueList.join(series[i].type == ecConfig.CHART_TYPE_SCATTER ? '\n' : ', ');
  19043. content += '\n\n';
  19044. }
  19045. return content;
  19046. },
  19047. _save: function () {
  19048. var customContent = this.query(this.option, 'toolbox.feature.dataView.contentToOption');
  19049. if (typeof customContent != 'function') {
  19050. var text = this._textArea.value.split('\n');
  19051. var content = [];
  19052. for (var i = 0, l = text.length; i < l; i++) {
  19053. text[i] = this._trim(text[i]);
  19054. if (text[i] !== '') {
  19055. content.push(text[i]);
  19056. }
  19057. }
  19058. this._contentToOption(content);
  19059. } else {
  19060. customContent(this._textArea, this.option);
  19061. }
  19062. this.hide();
  19063. var self = this;
  19064. setTimeout(function () {
  19065. self.messageCenter && self.messageCenter.dispatch(ecConfig.EVENT.DATA_VIEW_CHANGED, null, { option: self.option }, self.myChart);
  19066. }, self.canvasSupported ? 800 : 100);
  19067. },
  19068. _contentToOption: function (content) {
  19069. var i;
  19070. var j;
  19071. var k;
  19072. var len;
  19073. var data;
  19074. var axisList = [];
  19075. var contentIdx = 0;
  19076. var contentValueList;
  19077. var value;
  19078. if (this.option.xAxis) {
  19079. if (this.option.xAxis instanceof Array) {
  19080. axisList = this.option.xAxis;
  19081. } else {
  19082. axisList = [this.option.xAxis];
  19083. }
  19084. for (i = 0, len = axisList.length; i < len; i++) {
  19085. if ((axisList[i].type || 'category') == 'category') {
  19086. contentValueList = content[contentIdx].split(',');
  19087. for (j = 0, k = axisList[i].data.length; j < k; j++) {
  19088. value = this._trim(contentValueList[j] || '');
  19089. data = axisList[i].data[j];
  19090. if (typeof axisList[i].data[j].value != 'undefined') {
  19091. axisList[i].data[j].value = value;
  19092. } else {
  19093. axisList[i].data[j] = value;
  19094. }
  19095. }
  19096. contentIdx++;
  19097. }
  19098. }
  19099. }
  19100. if (this.option.yAxis) {
  19101. if (this.option.yAxis instanceof Array) {
  19102. axisList = this.option.yAxis;
  19103. } else {
  19104. axisList = [this.option.yAxis];
  19105. }
  19106. for (i = 0, len = axisList.length; i < len; i++) {
  19107. if (axisList[i].type == 'category') {
  19108. contentValueList = content[contentIdx].split(',');
  19109. for (j = 0, k = axisList[i].data.length; j < k; j++) {
  19110. value = this._trim(contentValueList[j] || '');
  19111. data = axisList[i].data[j];
  19112. if (typeof axisList[i].data[j].value != 'undefined') {
  19113. axisList[i].data[j].value = value;
  19114. } else {
  19115. axisList[i].data[j] = value;
  19116. }
  19117. }
  19118. contentIdx++;
  19119. }
  19120. }
  19121. }
  19122. var series = this.option.series;
  19123. for (i = 0, len = series.length; i < len; i++) {
  19124. contentIdx++;
  19125. if (series[i].type == ecConfig.CHART_TYPE_SCATTER) {
  19126. for (var j = 0, k = series[i].data.length; j < k; j++) {
  19127. contentValueList = content[contentIdx];
  19128. value = contentValueList.replace(' ', '').split(',');
  19129. if (typeof series[i].data[j].value != 'undefined') {
  19130. series[i].data[j].value = value;
  19131. } else {
  19132. series[i].data[j] = value;
  19133. }
  19134. contentIdx++;
  19135. }
  19136. } else {
  19137. contentValueList = content[contentIdx].split(',');
  19138. for (var j = 0, k = series[i].data.length; j < k; j++) {
  19139. value = (contentValueList[j] || '').replace(/.*:/, '');
  19140. value = this._trim(value);
  19141. value = value != '-' && value !== '' ? value - 0 : '-';
  19142. if (typeof series[i].data[j].value != 'undefined') {
  19143. series[i].data[j].value = value;
  19144. } else {
  19145. series[i].data[j] = value;
  19146. }
  19147. }
  19148. contentIdx++;
  19149. }
  19150. }
  19151. },
  19152. _trim: function (str) {
  19153. var trimer = new RegExp('(^[\\s\\t\\xa0\\u3000]+)|([\\u3000\\xa0\\s\\t]+$)', 'g');
  19154. return str.replace(trimer, '');
  19155. },
  19156. _stop: function (e) {
  19157. e = e || window.event;
  19158. if (e.stopPropagation) {
  19159. e.stopPropagation();
  19160. } else {
  19161. e.cancelBubble = true;
  19162. }
  19163. },
  19164. resize: function () {
  19165. this._zrHeight = this.zr.getHeight();
  19166. this._zrWidth = this.zr.getWidth();
  19167. if (this._tDom.offsetHeight > 10) {
  19168. this._sizeCssText = 'width:' + this._zrWidth + 'px;' + 'height:' + this._zrHeight + 'px;' + 'background-color:#fff;';
  19169. this._tDom.style.cssText = this._gCssText + this._sizeCssText;
  19170. this._textArea.style.cssText = 'display:block;margin:0 0 8px 0;' + 'padding:4px 6px;overflow:auto;' + 'width:100%;' + 'height:' + (this._zrHeight - 100) + 'px;';
  19171. }
  19172. },
  19173. dispose: function () {
  19174. if (window.removeEventListener) {
  19175. this._tDom.removeEventListener('click', this._stop);
  19176. this._tDom.removeEventListener('mousewheel', this._stop);
  19177. this._tDom.removeEventListener('mousemove', this._stop);
  19178. this._tDom.removeEventListener('mousedown', this._stop);
  19179. this._tDom.removeEventListener('mouseup', this._stop);
  19180. this._tDom.removeEventListener('touchstart', this._stop);
  19181. this._tDom.removeEventListener('touchmove', this._stop);
  19182. this._tDom.removeEventListener('touchend', this._stop);
  19183. } else {
  19184. this._tDom.detachEvent('onclick', this._stop);
  19185. this._tDom.detachEvent('onmousewheel', this._stop);
  19186. this._tDom.detachEvent('onmousemove', this._stop);
  19187. this._tDom.detachEvent('onmousedown', this._stop);
  19188. this._tDom.detachEvent('onmouseup', this._stop);
  19189. }
  19190. this._buttonRefresh.onclick = null;
  19191. this._buttonClose.onclick = null;
  19192. if (this._hasShow) {
  19193. this._tDom.removeChild(this._textArea);
  19194. this._tDom.removeChild(this._buttonRefresh);
  19195. this._tDom.removeChild(this._buttonClose);
  19196. }
  19197. this._textArea = null;
  19198. this._buttonRefresh = null;
  19199. this._buttonClose = null;
  19200. this.dom.firstChild.removeChild(this._tDom);
  19201. this._tDom = null;
  19202. }
  19203. };
  19204. zrUtil.inherits(DataView, Base);
  19205. require('../component').define('dataView', DataView);
  19206. return DataView;
  19207. });define('echarts/util/shape/Cross', [
  19208. 'require',
  19209. 'zrender/shape/Base',
  19210. 'zrender/shape/Line',
  19211. 'zrender/tool/util',
  19212. './normalIsCover'
  19213. ], function (require) {
  19214. var Base = require('zrender/shape/Base');
  19215. var LineShape = require('zrender/shape/Line');
  19216. var zrUtil = require('zrender/tool/util');
  19217. function Cross(options) {
  19218. Base.call(this, options);
  19219. }
  19220. Cross.prototype = {
  19221. type: 'cross',
  19222. buildPath: function (ctx, style) {
  19223. var rect = style.rect;
  19224. style.xStart = rect.x;
  19225. style.xEnd = rect.x + rect.width;
  19226. style.yStart = style.yEnd = style.y;
  19227. LineShape.prototype.buildPath(ctx, style);
  19228. style.xStart = style.xEnd = style.x;
  19229. style.yStart = rect.y;
  19230. style.yEnd = rect.y + rect.height;
  19231. LineShape.prototype.buildPath(ctx, style);
  19232. },
  19233. getRect: function (style) {
  19234. return style.rect;
  19235. },
  19236. isCover: require('./normalIsCover')
  19237. };
  19238. zrUtil.inherits(Cross, Base);
  19239. return Cross;
  19240. });define('zrender/shape/Sector', [
  19241. 'require',
  19242. '../tool/math',
  19243. '../tool/computeBoundingBox',
  19244. '../tool/vector',
  19245. './Base',
  19246. '../tool/util'
  19247. ], function (require) {
  19248. var math = require('../tool/math');
  19249. var computeBoundingBox = require('../tool/computeBoundingBox');
  19250. var vec2 = require('../tool/vector');
  19251. var Base = require('./Base');
  19252. var min0 = vec2.create();
  19253. var min1 = vec2.create();
  19254. var max0 = vec2.create();
  19255. var max1 = vec2.create();
  19256. var Sector = function (options) {
  19257. Base.call(this, options);
  19258. };
  19259. Sector.prototype = {
  19260. type: 'sector',
  19261. buildPath: function (ctx, style) {
  19262. var x = style.x;
  19263. var y = style.y;
  19264. var r0 = style.r0 || 0;
  19265. var r = style.r;
  19266. var startAngle = style.startAngle;
  19267. var endAngle = style.endAngle;
  19268. var clockWise = style.clockWise || false;
  19269. startAngle = math.degreeToRadian(startAngle);
  19270. endAngle = math.degreeToRadian(endAngle);
  19271. if (!clockWise) {
  19272. startAngle = -startAngle;
  19273. endAngle = -endAngle;
  19274. }
  19275. var unitX = math.cos(startAngle);
  19276. var unitY = math.sin(startAngle);
  19277. ctx.moveTo(unitX * r0 + x, unitY * r0 + y);
  19278. ctx.lineTo(unitX * r + x, unitY * r + y);
  19279. ctx.arc(x, y, r, startAngle, endAngle, !clockWise);
  19280. ctx.lineTo(math.cos(endAngle) * r0 + x, math.sin(endAngle) * r0 + y);
  19281. if (r0 !== 0) {
  19282. ctx.arc(x, y, r0, endAngle, startAngle, clockWise);
  19283. }
  19284. ctx.closePath();
  19285. return;
  19286. },
  19287. getRect: function (style) {
  19288. if (style.__rect) {
  19289. return style.__rect;
  19290. }
  19291. var x = style.x;
  19292. var y = style.y;
  19293. var r0 = style.r0 || 0;
  19294. var r = style.r;
  19295. var startAngle = math.degreeToRadian(style.startAngle);
  19296. var endAngle = math.degreeToRadian(style.endAngle);
  19297. var clockWise = style.clockWise;
  19298. if (!clockWise) {
  19299. startAngle = -startAngle;
  19300. endAngle = -endAngle;
  19301. }
  19302. if (r0 > 1) {
  19303. computeBoundingBox.arc(x, y, r0, startAngle, endAngle, !clockWise, min0, max0);
  19304. } else {
  19305. min0[0] = max0[0] = x;
  19306. min0[1] = max0[1] = y;
  19307. }
  19308. computeBoundingBox.arc(x, y, r, startAngle, endAngle, !clockWise, min1, max1);
  19309. vec2.min(min0, min0, min1);
  19310. vec2.max(max0, max0, max1);
  19311. style.__rect = {
  19312. x: min0[0],
  19313. y: min0[1],
  19314. width: max0[0] - min0[0],
  19315. height: max0[1] - min0[1]
  19316. };
  19317. return style.__rect;
  19318. }
  19319. };
  19320. require('../tool/util').inherits(Sector, Base);
  19321. return Sector;
  19322. });define('echarts/util/shape/Candle', [
  19323. 'require',
  19324. 'zrender/shape/Base',
  19325. 'zrender/tool/util',
  19326. './normalIsCover'
  19327. ], function (require) {
  19328. var Base = require('zrender/shape/Base');
  19329. var zrUtil = require('zrender/tool/util');
  19330. function Candle(options) {
  19331. Base.call(this, options);
  19332. }
  19333. Candle.prototype = {
  19334. type: 'candle',
  19335. _numberOrder: function (a, b) {
  19336. return b - a;
  19337. },
  19338. buildPath: function (ctx, style) {
  19339. var yList = zrUtil.clone(style.y).sort(this._numberOrder);
  19340. ctx.moveTo(style.x, yList[3]);
  19341. ctx.lineTo(style.x, yList[2]);
  19342. ctx.moveTo(style.x - style.width / 2, yList[2]);
  19343. ctx.rect(style.x - style.width / 2, yList[2], style.width, yList[1] - yList[2]);
  19344. ctx.moveTo(style.x, yList[1]);
  19345. ctx.lineTo(style.x, yList[0]);
  19346. },
  19347. getRect: function (style) {
  19348. if (!style.__rect) {
  19349. var lineWidth = 0;
  19350. if (style.brushType == 'stroke' || style.brushType == 'fill') {
  19351. lineWidth = style.lineWidth || 1;
  19352. }
  19353. var yList = zrUtil.clone(style.y).sort(this._numberOrder);
  19354. style.__rect = {
  19355. x: Math.round(style.x - style.width / 2 - lineWidth / 2),
  19356. y: Math.round(yList[3] - lineWidth / 2),
  19357. width: style.width + lineWidth,
  19358. height: yList[0] - yList[3] + lineWidth
  19359. };
  19360. }
  19361. return style.__rect;
  19362. },
  19363. isCover: require('./normalIsCover')
  19364. };
  19365. zrUtil.inherits(Candle, Base);
  19366. return Candle;
  19367. });define('zrender/tool/computeBoundingBox', [
  19368. 'require',
  19369. './vector',
  19370. './curve'
  19371. ], function (require) {
  19372. var vec2 = require('./vector');
  19373. var curve = require('./curve');
  19374. function computeBoundingBox(points, min, max) {
  19375. if (points.length === 0) {
  19376. return;
  19377. }
  19378. var left = points[0][0];
  19379. var right = points[0][0];
  19380. var top = points[0][1];
  19381. var bottom = points[0][1];
  19382. for (var i = 1; i < points.length; i++) {
  19383. var p = points[i];
  19384. if (p[0] < left) {
  19385. left = p[0];
  19386. }
  19387. if (p[0] > right) {
  19388. right = p[0];
  19389. }
  19390. if (p[1] < top) {
  19391. top = p[1];
  19392. }
  19393. if (p[1] > bottom) {
  19394. bottom = p[1];
  19395. }
  19396. }
  19397. min[0] = left;
  19398. min[1] = top;
  19399. max[0] = right;
  19400. max[1] = bottom;
  19401. }
  19402. function computeCubeBezierBoundingBox(p0, p1, p2, p3, min, max) {
  19403. var xDim = [];
  19404. curve.cubicExtrema(p0[0], p1[0], p2[0], p3[0], xDim);
  19405. for (var i = 0; i < xDim.length; i++) {
  19406. xDim[i] = curve.cubicAt(p0[0], p1[0], p2[0], p3[0], xDim[i]);
  19407. }
  19408. var yDim = [];
  19409. curve.cubicExtrema(p0[1], p1[1], p2[1], p3[1], yDim);
  19410. for (var i = 0; i < yDim.length; i++) {
  19411. yDim[i] = curve.cubicAt(p0[1], p1[1], p2[1], p3[1], yDim[i]);
  19412. }
  19413. xDim.push(p0[0], p3[0]);
  19414. yDim.push(p0[1], p3[1]);
  19415. var left = Math.min.apply(null, xDim);
  19416. var right = Math.max.apply(null, xDim);
  19417. var top = Math.min.apply(null, yDim);
  19418. var bottom = Math.max.apply(null, yDim);
  19419. min[0] = left;
  19420. min[1] = top;
  19421. max[0] = right;
  19422. max[1] = bottom;
  19423. }
  19424. function computeQuadraticBezierBoundingBox(p0, p1, p2, min, max) {
  19425. var t1 = curve.quadraticExtremum(p0[0], p1[0], p2[0]);
  19426. var t2 = curve.quadraticExtremum(p0[1], p1[1], p2[1]);
  19427. t1 = Math.max(Math.min(t1, 1), 0);
  19428. t2 = Math.max(Math.min(t2, 1), 0);
  19429. var ct1 = 1 - t1;
  19430. var ct2 = 1 - t2;
  19431. var x1 = ct1 * ct1 * p0[0] + 2 * ct1 * t1 * p1[0] + t1 * t1 * p2[0];
  19432. var y1 = ct1 * ct1 * p0[1] + 2 * ct1 * t1 * p1[1] + t1 * t1 * p2[1];
  19433. var x2 = ct2 * ct2 * p0[0] + 2 * ct2 * t2 * p1[0] + t2 * t2 * p2[0];
  19434. var y2 = ct2 * ct2 * p0[1] + 2 * ct2 * t2 * p1[1] + t2 * t2 * p2[1];
  19435. min[0] = Math.min(p0[0], p2[0], x1, x2);
  19436. min[1] = Math.min(p0[1], p2[1], y1, y2);
  19437. max[0] = Math.max(p0[0], p2[0], x1, x2);
  19438. max[1] = Math.max(p0[1], p2[1], y1, y2);
  19439. }
  19440. var start = vec2.create();
  19441. var end = vec2.create();
  19442. var extremity = vec2.create();
  19443. var computeArcBoundingBox = function (x, y, r, startAngle, endAngle, anticlockwise, min, max) {
  19444. if (Math.abs(startAngle - endAngle) >= Math.PI * 2) {
  19445. min[0] = x - r;
  19446. min[1] = y - r;
  19447. max[0] = x + r;
  19448. max[1] = y + r;
  19449. return;
  19450. }
  19451. start[0] = Math.cos(startAngle) * r + x;
  19452. start[1] = Math.sin(startAngle) * r + y;
  19453. end[0] = Math.cos(endAngle) * r + x;
  19454. end[1] = Math.sin(endAngle) * r + y;
  19455. vec2.min(min, start, end);
  19456. vec2.max(max, start, end);
  19457. startAngle = startAngle % (Math.PI * 2);
  19458. if (startAngle < 0) {
  19459. startAngle = startAngle + Math.PI * 2;
  19460. }
  19461. endAngle = endAngle % (Math.PI * 2);
  19462. if (endAngle < 0) {
  19463. endAngle = endAngle + Math.PI * 2;
  19464. }
  19465. if (startAngle > endAngle && !anticlockwise) {
  19466. endAngle += Math.PI * 2;
  19467. } else if (startAngle < endAngle && anticlockwise) {
  19468. startAngle += Math.PI * 2;
  19469. }
  19470. if (anticlockwise) {
  19471. var tmp = endAngle;
  19472. endAngle = startAngle;
  19473. startAngle = tmp;
  19474. }
  19475. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  19476. if (angle > startAngle) {
  19477. extremity[0] = Math.cos(angle) * r + x;
  19478. extremity[1] = Math.sin(angle) * r + y;
  19479. vec2.min(min, extremity, min);
  19480. vec2.max(max, extremity, max);
  19481. }
  19482. }
  19483. };
  19484. computeBoundingBox.cubeBezier = computeCubeBezierBoundingBox;
  19485. computeBoundingBox.quadraticBezier = computeQuadraticBezierBoundingBox;
  19486. computeBoundingBox.arc = computeArcBoundingBox;
  19487. return computeBoundingBox;
  19488. });define('echarts/util/shape/Chain', [
  19489. 'require',
  19490. 'zrender/shape/Base',
  19491. './Icon',
  19492. 'zrender/shape/util/dashedLineTo',
  19493. 'zrender/tool/util',
  19494. 'zrender/tool/matrix'
  19495. ], function (require) {
  19496. var Base = require('zrender/shape/Base');
  19497. var IconShape = require('./Icon');
  19498. var dashedLineTo = require('zrender/shape/util/dashedLineTo');
  19499. var zrUtil = require('zrender/tool/util');
  19500. var matrix = require('zrender/tool/matrix');
  19501. function Chain(options) {
  19502. Base.call(this, options);
  19503. }
  19504. Chain.prototype = {
  19505. type: 'chain',
  19506. brush: function (ctx, isHighlight) {
  19507. var style = this.style;
  19508. if (isHighlight) {
  19509. style = this.getHighlightStyle(style, this.highlightStyle || {});
  19510. }
  19511. ctx.save();
  19512. this.setContext(ctx, style);
  19513. this.setTransform(ctx);
  19514. ctx.save();
  19515. ctx.beginPath();
  19516. this.buildLinePath(ctx, style);
  19517. ctx.stroke();
  19518. ctx.restore();
  19519. this.brushSymbol(ctx, style);
  19520. ctx.restore();
  19521. return;
  19522. },
  19523. buildLinePath: function (ctx, style) {
  19524. var x = style.x;
  19525. var y = style.y + 5;
  19526. var width = style.width;
  19527. var height = style.height / 2 - 10;
  19528. ctx.moveTo(x, y);
  19529. ctx.lineTo(x, y + height);
  19530. ctx.moveTo(x + width, y);
  19531. ctx.lineTo(x + width, y + height);
  19532. ctx.moveTo(x, y + height / 2);
  19533. if (!style.lineType || style.lineType == 'solid') {
  19534. ctx.lineTo(x + width, y + height / 2);
  19535. } else if (style.lineType == 'dashed' || style.lineType == 'dotted') {
  19536. var dashLength = (style.lineWidth || 1) * (style.lineType == 'dashed' ? 5 : 1);
  19537. dashedLineTo(ctx, x, y + height / 2, x + width, y + height / 2, dashLength);
  19538. }
  19539. },
  19540. brushSymbol: function (ctx, style) {
  19541. var y = style.y + style.height / 4;
  19542. ctx.save();
  19543. var chainPoint = style.chainPoint;
  19544. var curPoint;
  19545. for (var idx = 0, l = chainPoint.length; idx < l; idx++) {
  19546. curPoint = chainPoint[idx];
  19547. if (curPoint.symbol != 'none') {
  19548. ctx.beginPath();
  19549. var symbolSize = curPoint.symbolSize;
  19550. IconShape.prototype.buildPath(ctx, {
  19551. iconType: curPoint.symbol,
  19552. x: curPoint.x - symbolSize,
  19553. y: y - symbolSize,
  19554. width: symbolSize * 2,
  19555. height: symbolSize * 2,
  19556. n: curPoint.n
  19557. });
  19558. ctx.fillStyle = curPoint.isEmpty ? '#fff' : style.strokeColor;
  19559. ctx.closePath();
  19560. ctx.fill();
  19561. ctx.stroke();
  19562. }
  19563. if (curPoint.showLabel) {
  19564. ctx.font = curPoint.textFont;
  19565. ctx.fillStyle = curPoint.textColor;
  19566. ctx.textAlign = curPoint.textAlign;
  19567. ctx.textBaseline = curPoint.textBaseline;
  19568. if (curPoint.rotation) {
  19569. ctx.save();
  19570. this._updateTextTransform(ctx, curPoint.rotation);
  19571. ctx.fillText(curPoint.name, curPoint.textX, curPoint.textY);
  19572. ctx.restore();
  19573. } else {
  19574. ctx.fillText(curPoint.name, curPoint.textX, curPoint.textY);
  19575. }
  19576. }
  19577. }
  19578. ctx.restore();
  19579. },
  19580. _updateTextTransform: function (ctx, rotation) {
  19581. var _transform = matrix.create();
  19582. matrix.identity(_transform);
  19583. if (rotation[0] !== 0) {
  19584. var originX = rotation[1] || 0;
  19585. var originY = rotation[2] || 0;
  19586. if (originX || originY) {
  19587. matrix.translate(_transform, _transform, [
  19588. -originX,
  19589. -originY
  19590. ]);
  19591. }
  19592. matrix.rotate(_transform, _transform, rotation[0]);
  19593. if (originX || originY) {
  19594. matrix.translate(_transform, _transform, [
  19595. originX,
  19596. originY
  19597. ]);
  19598. }
  19599. }
  19600. ctx.transform.apply(ctx, _transform);
  19601. },
  19602. isCover: function (x, y) {
  19603. var rect = this.style;
  19604. if (x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height) {
  19605. return true;
  19606. } else {
  19607. return false;
  19608. }
  19609. }
  19610. };
  19611. zrUtil.inherits(Chain, Base);
  19612. return Chain;
  19613. });define('zrender/shape/Ring', [
  19614. 'require',
  19615. './Base',
  19616. '../tool/util'
  19617. ], function (require) {
  19618. var Base = require('./Base');
  19619. var Ring = function (options) {
  19620. Base.call(this, options);
  19621. };
  19622. Ring.prototype = {
  19623. type: 'ring',
  19624. buildPath: function (ctx, style) {
  19625. ctx.arc(style.x, style.y, style.r, 0, Math.PI * 2, false);
  19626. ctx.moveTo(style.x + style.r0, style.y);
  19627. ctx.arc(style.x, style.y, style.r0, 0, Math.PI * 2, true);
  19628. return;
  19629. },
  19630. getRect: function (style) {
  19631. if (style.__rect) {
  19632. return style.__rect;
  19633. }
  19634. var lineWidth;
  19635. if (style.brushType == 'stroke' || style.brushType == 'fill') {
  19636. lineWidth = style.lineWidth || 1;
  19637. } else {
  19638. lineWidth = 0;
  19639. }
  19640. style.__rect = {
  19641. x: Math.round(style.x - style.r - lineWidth / 2),
  19642. y: Math.round(style.y - style.r - lineWidth / 2),
  19643. width: style.r * 2 + lineWidth,
  19644. height: style.r * 2 + lineWidth
  19645. };
  19646. return style.__rect;
  19647. }
  19648. };
  19649. require('../tool/util').inherits(Ring, Base);
  19650. return Ring;
  19651. });define('echarts/component/axis', [
  19652. 'require',
  19653. './base',
  19654. 'zrender/shape/Line',
  19655. '../config',
  19656. '../util/ecData',
  19657. 'zrender/tool/util',
  19658. 'zrender/tool/color',
  19659. './categoryAxis',
  19660. './valueAxis',
  19661. '../component'
  19662. ], function (require) {
  19663. var Base = require('./base');
  19664. var LineShape = require('zrender/shape/Line');
  19665. var ecConfig = require('../config');
  19666. var ecData = require('../util/ecData');
  19667. var zrUtil = require('zrender/tool/util');
  19668. var zrColor = require('zrender/tool/color');
  19669. function Axis(ecTheme, messageCenter, zr, option, myChart, axisType) {
  19670. Base.call(this, ecTheme, messageCenter, zr, option, myChart);
  19671. this.axisType = axisType;
  19672. this._axisList = [];
  19673. this.refresh(option);
  19674. }
  19675. Axis.prototype = {
  19676. type: ecConfig.COMPONENT_TYPE_AXIS,
  19677. axisBase: {
  19678. _buildAxisLine: function () {
  19679. var lineWidth = this.option.axisLine.lineStyle.width;
  19680. var halfLineWidth = lineWidth / 2;
  19681. var axShape = {
  19682. _axisShape: 'axisLine',
  19683. zlevel: this.getZlevelBase(),
  19684. z: this.getZBase() + 3,
  19685. hoverable: false
  19686. };
  19687. var grid = this.grid;
  19688. switch (this.option.position) {
  19689. case 'left':
  19690. axShape.style = {
  19691. xStart: grid.getX() - halfLineWidth,
  19692. yStart: grid.getYend(),
  19693. xEnd: grid.getX() - halfLineWidth,
  19694. yEnd: grid.getY(),
  19695. lineCap: 'round'
  19696. };
  19697. break;
  19698. case 'right':
  19699. axShape.style = {
  19700. xStart: grid.getXend() + halfLineWidth,
  19701. yStart: grid.getYend(),
  19702. xEnd: grid.getXend() + halfLineWidth,
  19703. yEnd: grid.getY(),
  19704. lineCap: 'round'
  19705. };
  19706. break;
  19707. case 'bottom':
  19708. axShape.style = {
  19709. xStart: grid.getX(),
  19710. yStart: grid.getYend() + halfLineWidth,
  19711. xEnd: grid.getXend(),
  19712. yEnd: grid.getYend() + halfLineWidth,
  19713. lineCap: 'round'
  19714. };
  19715. break;
  19716. case 'top':
  19717. axShape.style = {
  19718. xStart: grid.getX(),
  19719. yStart: grid.getY() - halfLineWidth,
  19720. xEnd: grid.getXend(),
  19721. yEnd: grid.getY() - halfLineWidth,
  19722. lineCap: 'round'
  19723. };
  19724. break;
  19725. }
  19726. var style = axShape.style;
  19727. if (this.option.name !== '') {
  19728. style.text = this.option.name;
  19729. style.textPosition = this.option.nameLocation;
  19730. style.textFont = this.getFont(this.option.nameTextStyle);
  19731. if (this.option.nameTextStyle.align) {
  19732. style.textAlign = this.option.nameTextStyle.align;
  19733. }
  19734. if (this.option.nameTextStyle.baseline) {
  19735. style.textBaseline = this.option.nameTextStyle.baseline;
  19736. }
  19737. if (this.option.nameTextStyle.color) {
  19738. style.textColor = this.option.nameTextStyle.color;
  19739. }
  19740. }
  19741. style.strokeColor = this.option.axisLine.lineStyle.color;
  19742. style.lineWidth = lineWidth;
  19743. if (this.isHorizontal()) {
  19744. style.yStart = style.yEnd = this.subPixelOptimize(style.yEnd, lineWidth);
  19745. } else {
  19746. style.xStart = style.xEnd = this.subPixelOptimize(style.xEnd, lineWidth);
  19747. }
  19748. style.lineType = this.option.axisLine.lineStyle.type;
  19749. axShape = new LineShape(axShape);
  19750. this.shapeList.push(axShape);
  19751. },
  19752. _axisLabelClickable: function (clickable, axShape) {
  19753. if (clickable) {
  19754. ecData.pack(axShape, undefined, -1, undefined, -1, axShape.style.text);
  19755. axShape.hoverable = true;
  19756. axShape.clickable = true;
  19757. axShape.highlightStyle = {
  19758. color: zrColor.lift(axShape.style.color, 1),
  19759. brushType: 'fill'
  19760. };
  19761. return axShape;
  19762. } else {
  19763. return axShape;
  19764. }
  19765. },
  19766. refixAxisShape: function (zeroX, zeroY) {
  19767. if (!this.option.axisLine.onZero) {
  19768. return;
  19769. }
  19770. var tickLength;
  19771. if (this.isHorizontal() && zeroY != null) {
  19772. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  19773. if (this.shapeList[i]._axisShape === 'axisLine') {
  19774. this.shapeList[i].style.yStart = this.shapeList[i].style.yEnd = this.subPixelOptimize(zeroY, this.shapeList[i].stylelineWidth);
  19775. this.zr.modShape(this.shapeList[i].id);
  19776. } else if (this.shapeList[i]._axisShape === 'axisTick') {
  19777. tickLength = this.shapeList[i].style.yEnd - this.shapeList[i].style.yStart;
  19778. this.shapeList[i].style.yStart = zeroY - tickLength;
  19779. this.shapeList[i].style.yEnd = zeroY;
  19780. this.zr.modShape(this.shapeList[i].id);
  19781. }
  19782. }
  19783. }
  19784. if (!this.isHorizontal() && zeroX != null) {
  19785. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  19786. if (this.shapeList[i]._axisShape === 'axisLine') {
  19787. this.shapeList[i].style.xStart = this.shapeList[i].style.xEnd = this.subPixelOptimize(zeroX, this.shapeList[i].stylelineWidth);
  19788. this.zr.modShape(this.shapeList[i].id);
  19789. } else if (this.shapeList[i]._axisShape === 'axisTick') {
  19790. tickLength = this.shapeList[i].style.xEnd - this.shapeList[i].style.xStart;
  19791. this.shapeList[i].style.xStart = zeroX;
  19792. this.shapeList[i].style.xEnd = zeroX + tickLength;
  19793. this.zr.modShape(this.shapeList[i].id);
  19794. }
  19795. }
  19796. }
  19797. },
  19798. getPosition: function () {
  19799. return this.option.position;
  19800. },
  19801. isHorizontal: function () {
  19802. return this.option.position === 'bottom' || this.option.position === 'top';
  19803. }
  19804. },
  19805. reformOption: function (opt) {
  19806. if (!opt || opt instanceof Array && opt.length === 0) {
  19807. opt = [{ type: ecConfig.COMPONENT_TYPE_AXIS_VALUE }];
  19808. } else if (!(opt instanceof Array)) {
  19809. opt = [opt];
  19810. }
  19811. if (opt.length > 2) {
  19812. opt = [
  19813. opt[0],
  19814. opt[1]
  19815. ];
  19816. }
  19817. if (this.axisType === 'xAxis') {
  19818. if (!opt[0].position || opt[0].position != 'bottom' && opt[0].position != 'top') {
  19819. opt[0].position = 'bottom';
  19820. }
  19821. if (opt.length > 1) {
  19822. opt[1].position = opt[0].position === 'bottom' ? 'top' : 'bottom';
  19823. }
  19824. for (var i = 0, l = opt.length; i < l; i++) {
  19825. opt[i].type = opt[i].type || 'category';
  19826. opt[i].xAxisIndex = i;
  19827. opt[i].yAxisIndex = -1;
  19828. }
  19829. } else {
  19830. if (!opt[0].position || opt[0].position != 'left' && opt[0].position != 'right') {
  19831. opt[0].position = 'left';
  19832. }
  19833. if (opt.length > 1) {
  19834. opt[1].position = opt[0].position === 'left' ? 'right' : 'left';
  19835. }
  19836. for (var i = 0, l = opt.length; i < l; i++) {
  19837. opt[i].type = opt[i].type || 'value';
  19838. opt[i].xAxisIndex = -1;
  19839. opt[i].yAxisIndex = i;
  19840. }
  19841. }
  19842. return opt;
  19843. },
  19844. refresh: function (newOption) {
  19845. var axisOption;
  19846. if (newOption) {
  19847. this.option = newOption;
  19848. if (this.axisType === 'xAxis') {
  19849. this.option.xAxis = this.reformOption(newOption.xAxis);
  19850. axisOption = this.option.xAxis;
  19851. } else {
  19852. this.option.yAxis = this.reformOption(newOption.yAxis);
  19853. axisOption = this.option.yAxis;
  19854. }
  19855. this.series = newOption.series;
  19856. }
  19857. var CategoryAxis = require('./categoryAxis');
  19858. var ValueAxis = require('./valueAxis');
  19859. var len = Math.max(axisOption && axisOption.length || 0, this._axisList.length);
  19860. for (var i = 0; i < len; i++) {
  19861. if (this._axisList[i] && newOption && (!axisOption[i] || this._axisList[i].type != axisOption[i].type)) {
  19862. this._axisList[i].dispose && this._axisList[i].dispose();
  19863. this._axisList[i] = false;
  19864. }
  19865. if (this._axisList[i]) {
  19866. this._axisList[i].refresh && this._axisList[i].refresh(axisOption ? axisOption[i] : false, this.series);
  19867. } else if (axisOption && axisOption[i]) {
  19868. 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);
  19869. }
  19870. }
  19871. },
  19872. getAxis: function (idx) {
  19873. return this._axisList[idx];
  19874. },
  19875. clear: function () {
  19876. for (var i = 0, l = this._axisList.length; i < l; i++) {
  19877. this._axisList[i].dispose && this._axisList[i].dispose();
  19878. }
  19879. this._axisList = [];
  19880. }
  19881. };
  19882. zrUtil.inherits(Axis, Base);
  19883. require('../component').define('axis', Axis);
  19884. return Axis;
  19885. });define('echarts/component/grid', [
  19886. 'require',
  19887. './base',
  19888. 'zrender/shape/Rectangle',
  19889. '../config',
  19890. 'zrender/tool/util',
  19891. '../component'
  19892. ], function (require) {
  19893. var Base = require('./base');
  19894. var RectangleShape = require('zrender/shape/Rectangle');
  19895. var ecConfig = require('../config');
  19896. ecConfig.grid = {
  19897. zlevel: 0,
  19898. z: 0,
  19899. x: 80,
  19900. y: 60,
  19901. x2: 80,
  19902. y2: 60,
  19903. backgroundColor: 'rgba(0,0,0,0)',
  19904. borderWidth: 1,
  19905. borderColor: '#ccc'
  19906. };
  19907. var zrUtil = require('zrender/tool/util');
  19908. function Grid(ecTheme, messageCenter, zr, option, myChart) {
  19909. Base.call(this, ecTheme, messageCenter, zr, option, myChart);
  19910. this.refresh(option);
  19911. }
  19912. Grid.prototype = {
  19913. type: ecConfig.COMPONENT_TYPE_GRID,
  19914. getX: function () {
  19915. return this._x;
  19916. },
  19917. getY: function () {
  19918. return this._y;
  19919. },
  19920. getWidth: function () {
  19921. return this._width;
  19922. },
  19923. getHeight: function () {
  19924. return this._height;
  19925. },
  19926. getXend: function () {
  19927. return this._x + this._width;
  19928. },
  19929. getYend: function () {
  19930. return this._y + this._height;
  19931. },
  19932. getArea: function () {
  19933. return {
  19934. x: this._x,
  19935. y: this._y,
  19936. width: this._width,
  19937. height: this._height
  19938. };
  19939. },
  19940. getBbox: function () {
  19941. return [
  19942. [
  19943. this._x,
  19944. this._y
  19945. ],
  19946. [
  19947. this.getXend(),
  19948. this.getYend()
  19949. ]
  19950. ];
  19951. },
  19952. refixAxisShape: function (component) {
  19953. var zeroX;
  19954. var zeroY;
  19955. var axisList = component.xAxis._axisList.concat(component.yAxis ? component.yAxis._axisList : []);
  19956. var len = axisList.length;
  19957. var axis;
  19958. while (len--) {
  19959. axis = axisList[len];
  19960. if (axis.type == ecConfig.COMPONENT_TYPE_AXIS_VALUE && axis._min < 0 && axis._max >= 0) {
  19961. axis.isHorizontal() ? zeroX = axis.getCoord(0) : zeroY = axis.getCoord(0);
  19962. }
  19963. }
  19964. if (typeof zeroX != 'undefined' || typeof zeroY != 'undefined') {
  19965. len = axisList.length;
  19966. while (len--) {
  19967. axisList[len].refixAxisShape(zeroX, zeroY);
  19968. }
  19969. }
  19970. },
  19971. refresh: function (newOption) {
  19972. if (newOption || this._zrWidth != this.zr.getWidth() || this._zrHeight != this.zr.getHeight()) {
  19973. this.clear();
  19974. this.option = newOption || this.option;
  19975. this.option.grid = this.reformOption(this.option.grid);
  19976. var gridOption = this.option.grid;
  19977. this._zrWidth = this.zr.getWidth();
  19978. this._zrHeight = this.zr.getHeight();
  19979. this._x = this.parsePercent(gridOption.x, this._zrWidth);
  19980. this._y = this.parsePercent(gridOption.y, this._zrHeight);
  19981. var x2 = this.parsePercent(gridOption.x2, this._zrWidth);
  19982. var y2 = this.parsePercent(gridOption.y2, this._zrHeight);
  19983. if (typeof gridOption.width == 'undefined') {
  19984. this._width = this._zrWidth - this._x - x2;
  19985. } else {
  19986. this._width = this.parsePercent(gridOption.width, this._zrWidth);
  19987. }
  19988. this._width = this._width <= 0 ? 10 : this._width;
  19989. if (typeof gridOption.height == 'undefined') {
  19990. this._height = this._zrHeight - this._y - y2;
  19991. } else {
  19992. this._height = this.parsePercent(gridOption.height, this._zrHeight);
  19993. }
  19994. this._height = this._height <= 0 ? 10 : this._height;
  19995. this._x = this.subPixelOptimize(this._x, gridOption.borderWidth);
  19996. this._y = this.subPixelOptimize(this._y, gridOption.borderWidth);
  19997. this.shapeList.push(new RectangleShape({
  19998. zlevel: this.getZlevelBase(),
  19999. z: this.getZBase(),
  20000. hoverable: false,
  20001. style: {
  20002. x: this._x,
  20003. y: this._y,
  20004. width: this._width,
  20005. height: this._height,
  20006. brushType: gridOption.borderWidth > 0 ? 'both' : 'fill',
  20007. color: gridOption.backgroundColor,
  20008. strokeColor: gridOption.borderColor,
  20009. lineWidth: gridOption.borderWidth
  20010. }
  20011. }));
  20012. this.zr.addShape(this.shapeList[0]);
  20013. }
  20014. }
  20015. };
  20016. zrUtil.inherits(Grid, Base);
  20017. require('../component').define('grid', Grid);
  20018. return Grid;
  20019. });define('echarts/component/dataZoom', [
  20020. 'require',
  20021. './base',
  20022. 'zrender/shape/Rectangle',
  20023. 'zrender/shape/Polygon',
  20024. '../util/shape/Icon',
  20025. '../config',
  20026. '../util/date',
  20027. 'zrender/tool/util',
  20028. '../component'
  20029. ], function (require) {
  20030. var Base = require('./base');
  20031. var RectangleShape = require('zrender/shape/Rectangle');
  20032. var PolygonShape = require('zrender/shape/Polygon');
  20033. var IconShape = require('../util/shape/Icon');
  20034. var ecConfig = require('../config');
  20035. ecConfig.dataZoom = {
  20036. zlevel: 0,
  20037. z: 4,
  20038. show: false,
  20039. orient: 'horizontal',
  20040. backgroundColor: 'rgba(0,0,0,0)',
  20041. dataBackgroundColor: '#eee',
  20042. fillerColor: 'rgba(144,197,237,0.2)',
  20043. handleColor: 'rgba(70,130,180,0.8)',
  20044. handleSize: 8,
  20045. showDetail: true,
  20046. realtime: true
  20047. };
  20048. var ecDate = require('../util/date');
  20049. var zrUtil = require('zrender/tool/util');
  20050. function DataZoom(ecTheme, messageCenter, zr, option, myChart) {
  20051. Base.call(this, ecTheme, messageCenter, zr, option, myChart);
  20052. var self = this;
  20053. self._ondrift = function (dx, dy) {
  20054. return self.__ondrift(this, dx, dy);
  20055. };
  20056. self._ondragend = function () {
  20057. return self.__ondragend();
  20058. };
  20059. this._fillerSize = 30;
  20060. this._isSilence = false;
  20061. this._zoom = {};
  20062. this.option.dataZoom = this.reformOption(this.option.dataZoom);
  20063. this.zoomOption = this.option.dataZoom;
  20064. this._handleSize = this.zoomOption.handleSize;
  20065. if (!this.myChart.canvasSupported) {
  20066. this.zoomOption.realtime = false;
  20067. }
  20068. this._location = this._getLocation();
  20069. this._zoom = this._getZoom();
  20070. this._backupData();
  20071. if (this.option.dataZoom.show) {
  20072. this._buildShape();
  20073. }
  20074. this._syncData();
  20075. }
  20076. DataZoom.prototype = {
  20077. type: ecConfig.COMPONENT_TYPE_DATAZOOM,
  20078. _buildShape: function () {
  20079. this._buildBackground();
  20080. this._buildFiller();
  20081. this._buildHandle();
  20082. this._buildFrame();
  20083. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  20084. this.zr.addShape(this.shapeList[i]);
  20085. }
  20086. this._syncFrameShape();
  20087. },
  20088. _getLocation: function () {
  20089. var x;
  20090. var y;
  20091. var width;
  20092. var height;
  20093. var grid = this.component.grid;
  20094. if (this.zoomOption.orient == 'horizontal') {
  20095. width = this.zoomOption.width || grid.getWidth();
  20096. height = this.zoomOption.height || this._fillerSize;
  20097. x = this.zoomOption.x != null ? this.zoomOption.x : grid.getX();
  20098. y = this.zoomOption.y != null ? this.zoomOption.y : this.zr.getHeight() - height - 2;
  20099. } else {
  20100. width = this.zoomOption.width || this._fillerSize;
  20101. height = this.zoomOption.height || grid.getHeight();
  20102. x = this.zoomOption.x != null ? this.zoomOption.x : 2;
  20103. y = this.zoomOption.y != null ? this.zoomOption.y : grid.getY();
  20104. }
  20105. return {
  20106. x: x,
  20107. y: y,
  20108. width: width,
  20109. height: height
  20110. };
  20111. },
  20112. _getZoom: function () {
  20113. var series = this.option.series;
  20114. var xAxis = this.option.xAxis;
  20115. if (xAxis && !(xAxis instanceof Array)) {
  20116. xAxis = [xAxis];
  20117. this.option.xAxis = xAxis;
  20118. }
  20119. var yAxis = this.option.yAxis;
  20120. if (yAxis && !(yAxis instanceof Array)) {
  20121. yAxis = [yAxis];
  20122. this.option.yAxis = yAxis;
  20123. }
  20124. var zoomSeriesIndex = [];
  20125. var xAxisIndex;
  20126. var yAxisIndex;
  20127. var zOptIdx = this.zoomOption.xAxisIndex;
  20128. if (xAxis && zOptIdx == null) {
  20129. xAxisIndex = [];
  20130. for (var i = 0, l = xAxis.length; i < l; i++) {
  20131. if (xAxis[i].type == 'category' || xAxis[i].type == null) {
  20132. xAxisIndex.push(i);
  20133. }
  20134. }
  20135. } else {
  20136. if (zOptIdx instanceof Array) {
  20137. xAxisIndex = zOptIdx;
  20138. } else if (zOptIdx != null) {
  20139. xAxisIndex = [zOptIdx];
  20140. } else {
  20141. xAxisIndex = [];
  20142. }
  20143. }
  20144. zOptIdx = this.zoomOption.yAxisIndex;
  20145. if (yAxis && zOptIdx == null) {
  20146. yAxisIndex = [];
  20147. for (var i = 0, l = yAxis.length; i < l; i++) {
  20148. if (yAxis[i].type == 'category') {
  20149. yAxisIndex.push(i);
  20150. }
  20151. }
  20152. } else {
  20153. if (zOptIdx instanceof Array) {
  20154. yAxisIndex = zOptIdx;
  20155. } else if (zOptIdx != null) {
  20156. yAxisIndex = [zOptIdx];
  20157. } else {
  20158. yAxisIndex = [];
  20159. }
  20160. }
  20161. var serie;
  20162. for (var i = 0, l = series.length; i < l; i++) {
  20163. serie = series[i];
  20164. 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) {
  20165. continue;
  20166. }
  20167. for (var j = 0, k = xAxisIndex.length; j < k; j++) {
  20168. if (xAxisIndex[j] == (serie.xAxisIndex || 0)) {
  20169. zoomSeriesIndex.push(i);
  20170. break;
  20171. }
  20172. }
  20173. for (var j = 0, k = yAxisIndex.length; j < k; j++) {
  20174. if (yAxisIndex[j] == (serie.yAxisIndex || 0)) {
  20175. zoomSeriesIndex.push(i);
  20176. break;
  20177. }
  20178. }
  20179. 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)) {
  20180. zoomSeriesIndex.push(i);
  20181. }
  20182. }
  20183. var start = this._zoom.start != null ? this._zoom.start : this.zoomOption.start != null ? this.zoomOption.start : 0;
  20184. var end = this._zoom.end != null ? this._zoom.end : this.zoomOption.end != null ? this.zoomOption.end : 100;
  20185. if (start > end) {
  20186. start = start + end;
  20187. end = start - end;
  20188. start = start - end;
  20189. }
  20190. var size = Math.round((end - start) / 100 * (this.zoomOption.orient == 'horizontal' ? this._location.width : this._location.height));
  20191. return {
  20192. start: start,
  20193. end: end,
  20194. start2: 0,
  20195. end2: 100,
  20196. size: size,
  20197. xAxisIndex: xAxisIndex,
  20198. yAxisIndex: yAxisIndex,
  20199. seriesIndex: zoomSeriesIndex,
  20200. scatterMap: this._zoom.scatterMap || {}
  20201. };
  20202. },
  20203. _backupData: function () {
  20204. this._originalData = {
  20205. xAxis: {},
  20206. yAxis: {},
  20207. series: {}
  20208. };
  20209. var xAxis = this.option.xAxis;
  20210. var xAxisIndex = this._zoom.xAxisIndex;
  20211. for (var i = 0, l = xAxisIndex.length; i < l; i++) {
  20212. this._originalData.xAxis[xAxisIndex[i]] = xAxis[xAxisIndex[i]].data;
  20213. }
  20214. var yAxis = this.option.yAxis;
  20215. var yAxisIndex = this._zoom.yAxisIndex;
  20216. for (var i = 0, l = yAxisIndex.length; i < l; i++) {
  20217. this._originalData.yAxis[yAxisIndex[i]] = yAxis[yAxisIndex[i]].data;
  20218. }
  20219. var series = this.option.series;
  20220. var seriesIndex = this._zoom.seriesIndex;
  20221. var serie;
  20222. for (var i = 0, l = seriesIndex.length; i < l; i++) {
  20223. serie = series[seriesIndex[i]];
  20224. this._originalData.series[seriesIndex[i]] = serie.data;
  20225. 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)) {
  20226. this._backupScale();
  20227. this._calculScatterMap(seriesIndex[i]);
  20228. }
  20229. }
  20230. },
  20231. _calculScatterMap: function (seriesIndex) {
  20232. this._zoom.scatterMap = this._zoom.scatterMap || {};
  20233. this._zoom.scatterMap[seriesIndex] = this._zoom.scatterMap[seriesIndex] || {};
  20234. var componentLibrary = require('../component');
  20235. var Axis = componentLibrary.get('axis');
  20236. var axisOption = zrUtil.clone(this.option.xAxis);
  20237. if (axisOption[0].type == 'category') {
  20238. axisOption[0].type = 'value';
  20239. }
  20240. if (axisOption[1] && axisOption[1].type == 'category') {
  20241. axisOption[1].type = 'value';
  20242. }
  20243. var vAxis = new Axis(this.ecTheme, null, false, {
  20244. xAxis: axisOption,
  20245. series: this.option.series
  20246. }, this, 'xAxis');
  20247. var axisIndex = this.option.series[seriesIndex].xAxisIndex || 0;
  20248. this._zoom.scatterMap[seriesIndex].x = vAxis.getAxis(axisIndex).getExtremum();
  20249. vAxis.dispose();
  20250. axisOption = zrUtil.clone(this.option.yAxis);
  20251. if (axisOption[0].type == 'category') {
  20252. axisOption[0].type = 'value';
  20253. }
  20254. if (axisOption[1] && axisOption[1].type == 'category') {
  20255. axisOption[1].type = 'value';
  20256. }
  20257. vAxis = new Axis(this.ecTheme, null, false, {
  20258. yAxis: axisOption,
  20259. series: this.option.series
  20260. }, this, 'yAxis');
  20261. axisIndex = this.option.series[seriesIndex].yAxisIndex || 0;
  20262. this._zoom.scatterMap[seriesIndex].y = vAxis.getAxis(axisIndex).getExtremum();
  20263. vAxis.dispose();
  20264. },
  20265. _buildBackground: function () {
  20266. var width = this._location.width;
  20267. var height = this._location.height;
  20268. this.shapeList.push(new RectangleShape({
  20269. zlevel: this.getZlevelBase(),
  20270. z: this.getZBase(),
  20271. hoverable: false,
  20272. style: {
  20273. x: this._location.x,
  20274. y: this._location.y,
  20275. width: width,
  20276. height: height,
  20277. color: this.zoomOption.backgroundColor
  20278. }
  20279. }));
  20280. var maxLength = 0;
  20281. var xAxis = this._originalData.xAxis;
  20282. var xAxisIndex = this._zoom.xAxisIndex;
  20283. for (var i = 0, l = xAxisIndex.length; i < l; i++) {
  20284. maxLength = Math.max(maxLength, xAxis[xAxisIndex[i]].length);
  20285. }
  20286. var yAxis = this._originalData.yAxis;
  20287. var yAxisIndex = this._zoom.yAxisIndex;
  20288. for (var i = 0, l = yAxisIndex.length; i < l; i++) {
  20289. maxLength = Math.max(maxLength, yAxis[yAxisIndex[i]].length);
  20290. }
  20291. var seriesIndex = this._zoom.seriesIndex[0];
  20292. var data = this._originalData.series[seriesIndex];
  20293. var maxValue = Number.MIN_VALUE;
  20294. var minValue = Number.MAX_VALUE;
  20295. var value;
  20296. for (var i = 0, l = data.length; i < l; i++) {
  20297. value = this.getDataFromOption(data[i], 0);
  20298. if (this.option.series[seriesIndex].type == ecConfig.CHART_TYPE_K) {
  20299. value = value[1];
  20300. }
  20301. if (isNaN(value)) {
  20302. value = 0;
  20303. }
  20304. maxValue = Math.max(maxValue, value);
  20305. minValue = Math.min(minValue, value);
  20306. }
  20307. var valueRange = maxValue - minValue;
  20308. var pointList = [];
  20309. var x = width / (maxLength - (maxLength > 1 ? 1 : 0));
  20310. var y = height / (maxLength - (maxLength > 1 ? 1 : 0));
  20311. var step = 1;
  20312. if (this.zoomOption.orient == 'horizontal' && x < 1) {
  20313. step = Math.floor(maxLength * 3 / width);
  20314. } else if (this.zoomOption.orient == 'vertical' && y < 1) {
  20315. step = Math.floor(maxLength * 3 / height);
  20316. }
  20317. for (var i = 0, l = maxLength; i < l; i += step) {
  20318. value = this.getDataFromOption(data[i], 0);
  20319. if (this.option.series[seriesIndex].type == ecConfig.CHART_TYPE_K) {
  20320. value = value[1];
  20321. }
  20322. if (isNaN(value)) {
  20323. value = 0;
  20324. }
  20325. if (this.zoomOption.orient == 'horizontal') {
  20326. pointList.push([
  20327. this._location.x + x * i,
  20328. this._location.y + height - 1 - Math.round((value - minValue) / valueRange * (height - 10))
  20329. ]);
  20330. } else {
  20331. pointList.push([
  20332. this._location.x + 1 + Math.round((value - minValue) / valueRange * (width - 10)),
  20333. this._location.y + y * (l - i - 1)
  20334. ]);
  20335. }
  20336. }
  20337. if (this.zoomOption.orient == 'horizontal') {
  20338. pointList.push([
  20339. this._location.x + width,
  20340. this._location.y + height
  20341. ]);
  20342. pointList.push([
  20343. this._location.x,
  20344. this._location.y + height
  20345. ]);
  20346. } else {
  20347. pointList.push([
  20348. this._location.x,
  20349. this._location.y
  20350. ]);
  20351. pointList.push([
  20352. this._location.x,
  20353. this._location.y + height
  20354. ]);
  20355. }
  20356. this.shapeList.push(new PolygonShape({
  20357. zlevel: this.getZlevelBase(),
  20358. z: this.getZBase(),
  20359. style: {
  20360. pointList: pointList,
  20361. color: this.zoomOption.dataBackgroundColor
  20362. },
  20363. hoverable: false
  20364. }));
  20365. },
  20366. _buildFiller: function () {
  20367. this._fillerShae = {
  20368. zlevel: this.getZlevelBase(),
  20369. z: this.getZBase(),
  20370. draggable: true,
  20371. ondrift: this._ondrift,
  20372. ondragend: this._ondragend,
  20373. _type: 'filler'
  20374. };
  20375. if (this.zoomOption.orient == 'horizontal') {
  20376. this._fillerShae.style = {
  20377. x: this._location.x + Math.round(this._zoom.start / 100 * this._location.width) + this._handleSize,
  20378. y: this._location.y,
  20379. width: this._zoom.size - this._handleSize * 2,
  20380. height: this._location.height,
  20381. color: this.zoomOption.fillerColor,
  20382. text: ':::',
  20383. textPosition: 'inside'
  20384. };
  20385. } else {
  20386. this._fillerShae.style = {
  20387. x: this._location.x,
  20388. y: this._location.y + Math.round(this._zoom.start / 100 * this._location.height) + this._handleSize,
  20389. width: this._location.width,
  20390. height: this._zoom.size - this._handleSize * 2,
  20391. color: this.zoomOption.fillerColor,
  20392. text: '::',
  20393. textPosition: 'inside'
  20394. };
  20395. }
  20396. this._fillerShae.highlightStyle = {
  20397. brushType: 'fill',
  20398. color: 'rgba(0,0,0,0)'
  20399. };
  20400. this._fillerShae = new RectangleShape(this._fillerShae);
  20401. this.shapeList.push(this._fillerShae);
  20402. },
  20403. _buildHandle: function () {
  20404. var detail = this.zoomOption.showDetail ? this._getDetail() : {
  20405. start: '',
  20406. end: ''
  20407. };
  20408. this._startShape = {
  20409. zlevel: this.getZlevelBase(),
  20410. z: this.getZBase(),
  20411. draggable: true,
  20412. style: {
  20413. iconType: 'rectangle',
  20414. x: this._location.x,
  20415. y: this._location.y,
  20416. width: this._handleSize,
  20417. height: this._handleSize,
  20418. color: this.zoomOption.handleColor,
  20419. text: '=',
  20420. textPosition: 'inside'
  20421. },
  20422. highlightStyle: {
  20423. text: detail.start,
  20424. brushType: 'fill',
  20425. textPosition: 'left'
  20426. },
  20427. ondrift: this._ondrift,
  20428. ondragend: this._ondragend
  20429. };
  20430. if (this.zoomOption.orient == 'horizontal') {
  20431. this._startShape.style.height = this._location.height;
  20432. this._endShape = zrUtil.clone(this._startShape);
  20433. this._startShape.style.x = this._fillerShae.style.x - this._handleSize, this._endShape.style.x = this._fillerShae.style.x + this._fillerShae.style.width;
  20434. this._endShape.highlightStyle.text = detail.end;
  20435. this._endShape.highlightStyle.textPosition = 'right';
  20436. } else {
  20437. this._startShape.style.width = this._location.width;
  20438. this._endShape = zrUtil.clone(this._startShape);
  20439. this._startShape.style.y = this._fillerShae.style.y + this._fillerShae.style.height;
  20440. this._startShape.highlightStyle.textPosition = 'bottom';
  20441. this._endShape.style.y = this._fillerShae.style.y - this._handleSize;
  20442. this._endShape.highlightStyle.text = detail.end;
  20443. this._endShape.highlightStyle.textPosition = 'top';
  20444. }
  20445. this._startShape = new IconShape(this._startShape);
  20446. this._endShape = new IconShape(this._endShape);
  20447. this.shapeList.push(this._startShape);
  20448. this.shapeList.push(this._endShape);
  20449. },
  20450. _buildFrame: function () {
  20451. var x = this.subPixelOptimize(this._location.x, 1);
  20452. var y = this.subPixelOptimize(this._location.y, 1);
  20453. this._startFrameShape = {
  20454. zlevel: this.getZlevelBase(),
  20455. z: this.getZBase(),
  20456. hoverable: false,
  20457. style: {
  20458. x: x,
  20459. y: y,
  20460. width: this._location.width - (x > this._location.x ? 1 : 0),
  20461. height: this._location.height - (y > this._location.y ? 1 : 0),
  20462. lineWidth: 1,
  20463. brushType: 'stroke',
  20464. strokeColor: this.zoomOption.handleColor
  20465. }
  20466. };
  20467. this._endFrameShape = zrUtil.clone(this._startFrameShape);
  20468. this._startFrameShape = new RectangleShape(this._startFrameShape);
  20469. this._endFrameShape = new RectangleShape(this._endFrameShape);
  20470. this.shapeList.push(this._startFrameShape);
  20471. this.shapeList.push(this._endFrameShape);
  20472. return;
  20473. },
  20474. _syncHandleShape: function () {
  20475. if (this.zoomOption.orient == 'horizontal') {
  20476. this._startShape.style.x = this._fillerShae.style.x - this._handleSize;
  20477. this._endShape.style.x = this._fillerShae.style.x + this._fillerShae.style.width;
  20478. this._zoom.start = (this._startShape.style.x - this._location.x) / this._location.width * 100;
  20479. this._zoom.end = (this._endShape.style.x + this._handleSize - this._location.x) / this._location.width * 100;
  20480. } else {
  20481. this._startShape.style.y = this._fillerShae.style.y + this._fillerShae.style.height;
  20482. this._endShape.style.y = this._fillerShae.style.y - this._handleSize;
  20483. this._zoom.start = (this._location.y + this._location.height - this._startShape.style.y) / this._location.height * 100;
  20484. this._zoom.end = (this._location.y + this._location.height - this._endShape.style.y - this._handleSize) / this._location.height * 100;
  20485. }
  20486. this.zr.modShape(this._startShape.id);
  20487. this.zr.modShape(this._endShape.id);
  20488. this._syncFrameShape();
  20489. this.zr.refreshNextFrame();
  20490. },
  20491. _syncFillerShape: function () {
  20492. var a;
  20493. var b;
  20494. if (this.zoomOption.orient == 'horizontal') {
  20495. a = this._startShape.style.x;
  20496. b = this._endShape.style.x;
  20497. this._fillerShae.style.x = Math.min(a, b) + this._handleSize;
  20498. this._fillerShae.style.width = Math.abs(a - b) - this._handleSize;
  20499. this._zoom.start = (Math.min(a, b) - this._location.x) / this._location.width * 100;
  20500. this._zoom.end = (Math.max(a, b) + this._handleSize - this._location.x) / this._location.width * 100;
  20501. } else {
  20502. a = this._startShape.style.y;
  20503. b = this._endShape.style.y;
  20504. this._fillerShae.style.y = Math.min(a, b) + this._handleSize;
  20505. this._fillerShae.style.height = Math.abs(a - b) - this._handleSize;
  20506. this._zoom.start = (this._location.y + this._location.height - Math.max(a, b)) / this._location.height * 100;
  20507. this._zoom.end = (this._location.y + this._location.height - Math.min(a, b) - this._handleSize) / this._location.height * 100;
  20508. }
  20509. this.zr.modShape(this._fillerShae.id);
  20510. this._syncFrameShape();
  20511. this.zr.refreshNextFrame();
  20512. },
  20513. _syncFrameShape: function () {
  20514. if (this.zoomOption.orient == 'horizontal') {
  20515. this._startFrameShape.style.width = this._fillerShae.style.x - this._location.x;
  20516. this._endFrameShape.style.x = this._fillerShae.style.x + this._fillerShae.style.width;
  20517. this._endFrameShape.style.width = this._location.x + this._location.width - this._endFrameShape.style.x;
  20518. } else {
  20519. this._startFrameShape.style.y = this._fillerShae.style.y + this._fillerShae.style.height;
  20520. this._startFrameShape.style.height = this._location.y + this._location.height - this._startFrameShape.style.y;
  20521. this._endFrameShape.style.height = this._fillerShae.style.y - this._location.y;
  20522. }
  20523. this.zr.modShape(this._startFrameShape.id);
  20524. this.zr.modShape(this._endFrameShape.id);
  20525. },
  20526. _syncShape: function () {
  20527. if (!this.zoomOption.show) {
  20528. return;
  20529. }
  20530. if (this.zoomOption.orient == 'horizontal') {
  20531. this._startShape.style.x = this._location.x + this._zoom.start / 100 * this._location.width;
  20532. this._endShape.style.x = this._location.x + this._zoom.end / 100 * this._location.width - this._handleSize;
  20533. this._fillerShae.style.x = this._startShape.style.x + this._handleSize;
  20534. this._fillerShae.style.width = this._endShape.style.x - this._startShape.style.x - this._handleSize;
  20535. } else {
  20536. this._startShape.style.y = this._location.y + this._location.height - this._zoom.start / 100 * this._location.height;
  20537. this._endShape.style.y = this._location.y + this._location.height - this._zoom.end / 100 * this._location.height - this._handleSize;
  20538. this._fillerShae.style.y = this._endShape.style.y + this._handleSize;
  20539. this._fillerShae.style.height = this._startShape.style.y - this._endShape.style.y - this._handleSize;
  20540. }
  20541. this.zr.modShape(this._startShape.id);
  20542. this.zr.modShape(this._endShape.id);
  20543. this.zr.modShape(this._fillerShae.id);
  20544. this._syncFrameShape();
  20545. this.zr.refresh();
  20546. },
  20547. _syncData: function (dispatchNow) {
  20548. var target;
  20549. var start;
  20550. var end;
  20551. var length;
  20552. var data;
  20553. for (var key in this._originalData) {
  20554. target = this._originalData[key];
  20555. for (var idx in target) {
  20556. data = target[idx];
  20557. if (data == null) {
  20558. continue;
  20559. }
  20560. length = data.length;
  20561. start = Math.floor(this._zoom.start / 100 * length);
  20562. end = Math.ceil(this._zoom.end / 100 * length);
  20563. if (!(this.getDataFromOption(data[0]) instanceof Array) || this.option[key][idx].type == ecConfig.CHART_TYPE_K) {
  20564. this.option[key][idx].data = data.slice(start, end);
  20565. } else {
  20566. this._setScale();
  20567. this.option[key][idx].data = this._synScatterData(idx, data);
  20568. }
  20569. }
  20570. }
  20571. if (!this._isSilence && (this.zoomOption.realtime || dispatchNow)) {
  20572. this.messageCenter.dispatch(ecConfig.EVENT.DATA_ZOOM, null, { zoom: this._zoom }, this.myChart);
  20573. }
  20574. },
  20575. _synScatterData: function (seriesIndex, data) {
  20576. if (this._zoom.start === 0 && this._zoom.end == 100 && this._zoom.start2 === 0 && this._zoom.end2 == 100) {
  20577. return data;
  20578. }
  20579. var newData = [];
  20580. var scale = this._zoom.scatterMap[seriesIndex];
  20581. var total;
  20582. var xStart;
  20583. var xEnd;
  20584. var yStart;
  20585. var yEnd;
  20586. if (this.zoomOption.orient == 'horizontal') {
  20587. total = scale.x.max - scale.x.min;
  20588. xStart = this._zoom.start / 100 * total + scale.x.min;
  20589. xEnd = this._zoom.end / 100 * total + scale.x.min;
  20590. total = scale.y.max - scale.y.min;
  20591. yStart = this._zoom.start2 / 100 * total + scale.y.min;
  20592. yEnd = this._zoom.end2 / 100 * total + scale.y.min;
  20593. } else {
  20594. total = scale.x.max - scale.x.min;
  20595. xStart = this._zoom.start2 / 100 * total + scale.x.min;
  20596. xEnd = this._zoom.end2 / 100 * total + scale.x.min;
  20597. total = scale.y.max - scale.y.min;
  20598. yStart = this._zoom.start / 100 * total + scale.y.min;
  20599. yEnd = this._zoom.end / 100 * total + scale.y.min;
  20600. }
  20601. var value;
  20602. for (var i = 0, l = data.length; i < l; i++) {
  20603. value = data[i].value || data[i];
  20604. if (value[0] >= xStart && value[0] <= xEnd && value[1] >= yStart && value[1] <= yEnd) {
  20605. newData.push(data[i]);
  20606. }
  20607. }
  20608. return newData;
  20609. },
  20610. _setScale: function () {
  20611. var needScale = this._zoom.start !== 0 || this._zoom.end !== 100 || this._zoom.start2 !== 0 || this._zoom.end2 !== 100;
  20612. var axis = {
  20613. xAxis: this.option.xAxis,
  20614. yAxis: this.option.yAxis
  20615. };
  20616. for (var key in axis) {
  20617. for (var i = 0, l = axis[key].length; i < l; i++) {
  20618. axis[key][i].scale = needScale || axis[key][i]._scale;
  20619. }
  20620. }
  20621. },
  20622. _backupScale: function () {
  20623. var axis = {
  20624. xAxis: this.option.xAxis,
  20625. yAxis: this.option.yAxis
  20626. };
  20627. for (var key in axis) {
  20628. for (var i = 0, l = axis[key].length; i < l; i++) {
  20629. axis[key][i]._scale = axis[key][i].scale;
  20630. }
  20631. }
  20632. },
  20633. _getDetail: function () {
  20634. var key = [
  20635. 'xAxis',
  20636. 'yAxis'
  20637. ];
  20638. for (var i = 0, l = key.length; i < l; i++) {
  20639. var target = this._originalData[key[i]];
  20640. for (var idx in target) {
  20641. var data = target[idx];
  20642. if (data == null) {
  20643. continue;
  20644. }
  20645. var length = data.length;
  20646. var start = Math.floor(this._zoom.start / 100 * length);
  20647. var end = Math.ceil(this._zoom.end / 100 * length);
  20648. end -= end > 0 ? 1 : 0;
  20649. return {
  20650. start: this.getDataFromOption(data[start]),
  20651. end: this.getDataFromOption(data[end])
  20652. };
  20653. }
  20654. }
  20655. key = this.zoomOption.orient == 'horizontal' ? 'xAxis' : 'yAxis';
  20656. var seriesIndex = this._zoom.seriesIndex[0];
  20657. var axisIndex = this.option.series[seriesIndex][key + 'Index'] || 0;
  20658. var axisType = this.option[key][axisIndex].type;
  20659. var min = this._zoom.scatterMap[seriesIndex][key.charAt(0)].min;
  20660. var max = this._zoom.scatterMap[seriesIndex][key.charAt(0)].max;
  20661. var gap = max - min;
  20662. if (axisType == 'value') {
  20663. return {
  20664. start: min + gap * this._zoom.start / 100,
  20665. end: min + gap * this._zoom.end / 100
  20666. };
  20667. } else if (axisType == 'time') {
  20668. max = min + gap * this._zoom.end / 100;
  20669. min = min + gap * this._zoom.start / 100;
  20670. var formatter = ecDate.getAutoFormatter(min, max).formatter;
  20671. return {
  20672. start: ecDate.format(formatter, min),
  20673. end: ecDate.format(formatter, max)
  20674. };
  20675. }
  20676. return {
  20677. start: '',
  20678. end: ''
  20679. };
  20680. },
  20681. __ondrift: function (shape, dx, dy) {
  20682. if (this.zoomOption.zoomLock) {
  20683. shape = this._fillerShae;
  20684. }
  20685. var detailSize = shape._type == 'filler' ? this._handleSize : 0;
  20686. if (this.zoomOption.orient == 'horizontal') {
  20687. if (shape.style.x + dx - detailSize <= this._location.x) {
  20688. shape.style.x = this._location.x + detailSize;
  20689. } else if (shape.style.x + dx + shape.style.width + detailSize >= this._location.x + this._location.width) {
  20690. shape.style.x = this._location.x + this._location.width - shape.style.width - detailSize;
  20691. } else {
  20692. shape.style.x += dx;
  20693. }
  20694. } else {
  20695. if (shape.style.y + dy - detailSize <= this._location.y) {
  20696. shape.style.y = this._location.y + detailSize;
  20697. } else if (shape.style.y + dy + shape.style.height + detailSize >= this._location.y + this._location.height) {
  20698. shape.style.y = this._location.y + this._location.height - shape.style.height - detailSize;
  20699. } else {
  20700. shape.style.y += dy;
  20701. }
  20702. }
  20703. if (shape._type == 'filler') {
  20704. this._syncHandleShape();
  20705. } else {
  20706. this._syncFillerShape();
  20707. }
  20708. if (this.zoomOption.realtime) {
  20709. this._syncData();
  20710. }
  20711. if (this.zoomOption.showDetail) {
  20712. var detail = this._getDetail();
  20713. this._startShape.style.text = this._startShape.highlightStyle.text = detail.start;
  20714. this._endShape.style.text = this._endShape.highlightStyle.text = detail.end;
  20715. this._startShape.style.textPosition = this._startShape.highlightStyle.textPosition;
  20716. this._endShape.style.textPosition = this._endShape.highlightStyle.textPosition;
  20717. }
  20718. return true;
  20719. },
  20720. __ondragend: function () {
  20721. if (this.zoomOption.showDetail) {
  20722. this._startShape.style.text = this._endShape.style.text = '=';
  20723. this._startShape.style.textPosition = this._endShape.style.textPosition = 'inside';
  20724. this.zr.modShape(this._startShape.id);
  20725. this.zr.modShape(this._endShape.id);
  20726. this.zr.refreshNextFrame();
  20727. }
  20728. this.isDragend = true;
  20729. },
  20730. ondragend: function (param, status) {
  20731. if (!this.isDragend || !param.target) {
  20732. return;
  20733. }
  20734. !this.zoomOption.realtime && this._syncData();
  20735. status.dragOut = true;
  20736. status.dragIn = true;
  20737. if (!this._isSilence && !this.zoomOption.realtime) {
  20738. this.messageCenter.dispatch(ecConfig.EVENT.DATA_ZOOM, null, { zoom: this._zoom }, this.myChart);
  20739. }
  20740. status.needRefresh = false;
  20741. this.isDragend = false;
  20742. return;
  20743. },
  20744. ondataZoom: function (param, status) {
  20745. status.needRefresh = true;
  20746. return;
  20747. },
  20748. absoluteZoom: function (param) {
  20749. this._zoom.start = param.start;
  20750. this._zoom.end = param.end;
  20751. this._zoom.start2 = param.start2;
  20752. this._zoom.end2 = param.end2;
  20753. this._syncShape();
  20754. this._syncData(true);
  20755. return;
  20756. },
  20757. rectZoom: function (param) {
  20758. if (!param) {
  20759. this._zoom.start = this._zoom.start2 = 0;
  20760. this._zoom.end = this._zoom.end2 = 100;
  20761. this._syncShape();
  20762. this._syncData(true);
  20763. return this._zoom;
  20764. }
  20765. var gridArea = this.component.grid.getArea();
  20766. var rect = {
  20767. x: param.x,
  20768. y: param.y,
  20769. width: param.width,
  20770. height: param.height
  20771. };
  20772. if (rect.width < 0) {
  20773. rect.x += rect.width;
  20774. rect.width = -rect.width;
  20775. }
  20776. if (rect.height < 0) {
  20777. rect.y += rect.height;
  20778. rect.height = -rect.height;
  20779. }
  20780. if (rect.x > gridArea.x + gridArea.width || rect.y > gridArea.y + gridArea.height) {
  20781. return false;
  20782. }
  20783. if (rect.x < gridArea.x) {
  20784. rect.x = gridArea.x;
  20785. }
  20786. if (rect.x + rect.width > gridArea.x + gridArea.width) {
  20787. rect.width = gridArea.x + gridArea.width - rect.x;
  20788. }
  20789. if (rect.y + rect.height > gridArea.y + gridArea.height) {
  20790. rect.height = gridArea.y + gridArea.height - rect.y;
  20791. }
  20792. var total;
  20793. var sdx = (rect.x - gridArea.x) / gridArea.width;
  20794. var edx = 1 - (rect.x + rect.width - gridArea.x) / gridArea.width;
  20795. var sdy = 1 - (rect.y + rect.height - gridArea.y) / gridArea.height;
  20796. var edy = (rect.y - gridArea.y) / gridArea.height;
  20797. if (this.zoomOption.orient == 'horizontal') {
  20798. total = this._zoom.end - this._zoom.start;
  20799. this._zoom.start += total * sdx;
  20800. this._zoom.end -= total * edx;
  20801. total = this._zoom.end2 - this._zoom.start2;
  20802. this._zoom.start2 += total * sdy;
  20803. this._zoom.end2 -= total * edy;
  20804. } else {
  20805. total = this._zoom.end - this._zoom.start;
  20806. this._zoom.start += total * sdy;
  20807. this._zoom.end -= total * edy;
  20808. total = this._zoom.end2 - this._zoom.start2;
  20809. this._zoom.start2 += total * sdx;
  20810. this._zoom.end2 -= total * edx;
  20811. }
  20812. this._syncShape();
  20813. this._syncData(true);
  20814. return this._zoom;
  20815. },
  20816. syncBackupData: function (curOption) {
  20817. var start;
  20818. var target = this._originalData['series'];
  20819. var curSeries = curOption.series;
  20820. var curData;
  20821. for (var i = 0, l = curSeries.length; i < l; i++) {
  20822. curData = curSeries[i].data || curSeries[i].eventList;
  20823. if (target[i]) {
  20824. start = Math.floor(this._zoom.start / 100 * target[i].length);
  20825. } else {
  20826. start = 0;
  20827. }
  20828. for (var j = 0, k = curData.length; j < k; j++) {
  20829. if (target[i]) {
  20830. target[i][j + start] = curData[j];
  20831. }
  20832. }
  20833. }
  20834. },
  20835. syncOption: function (magicOption) {
  20836. this.silence(true);
  20837. this.option = magicOption;
  20838. this.option.dataZoom = this.reformOption(this.option.dataZoom);
  20839. this.zoomOption = this.option.dataZoom;
  20840. if (!this.myChart.canvasSupported) {
  20841. this.zoomOption.realtime = false;
  20842. }
  20843. this.clear();
  20844. this._location = this._getLocation();
  20845. this._zoom = this._getZoom();
  20846. this._backupData();
  20847. if (this.option.dataZoom && this.option.dataZoom.show) {
  20848. this._buildShape();
  20849. }
  20850. this._syncData();
  20851. this.silence(false);
  20852. },
  20853. silence: function (s) {
  20854. this._isSilence = s;
  20855. },
  20856. getRealDataIndex: function (sIdx, dIdx) {
  20857. if (!this._originalData || this._zoom.start === 0 && this._zoom.end == 100) {
  20858. return dIdx;
  20859. }
  20860. var sreies = this._originalData.series;
  20861. if (sreies[sIdx]) {
  20862. return Math.floor(this._zoom.start / 100 * sreies[sIdx].length) + dIdx;
  20863. }
  20864. return -1;
  20865. },
  20866. resize: function () {
  20867. this.clear();
  20868. this._location = this._getLocation();
  20869. this._zoom = this._getZoom();
  20870. if (this.option.dataZoom.show) {
  20871. this._buildShape();
  20872. }
  20873. }
  20874. };
  20875. zrUtil.inherits(DataZoom, Base);
  20876. require('../component').define('dataZoom', DataZoom);
  20877. return DataZoom;
  20878. });define('echarts/component/categoryAxis', [
  20879. 'require',
  20880. './base',
  20881. 'zrender/shape/Text',
  20882. 'zrender/shape/Line',
  20883. 'zrender/shape/Rectangle',
  20884. '../config',
  20885. 'zrender/tool/util',
  20886. 'zrender/tool/area',
  20887. '../component'
  20888. ], function (require) {
  20889. var Base = require('./base');
  20890. var TextShape = require('zrender/shape/Text');
  20891. var LineShape = require('zrender/shape/Line');
  20892. var RectangleShape = require('zrender/shape/Rectangle');
  20893. var ecConfig = require('../config');
  20894. ecConfig.categoryAxis = {
  20895. zlevel: 0,
  20896. z: 0,
  20897. show: true,
  20898. position: 'bottom',
  20899. name: '',
  20900. nameLocation: 'end',
  20901. nameTextStyle: {},
  20902. boundaryGap: true,
  20903. axisLine: {
  20904. show: true,
  20905. onZero: true,
  20906. lineStyle: {
  20907. color: '#48b',
  20908. width: 2,
  20909. type: 'solid'
  20910. }
  20911. },
  20912. axisTick: {
  20913. show: true,
  20914. interval: 'auto',
  20915. inside: false,
  20916. length: 5,
  20917. lineStyle: {
  20918. color: '#333',
  20919. width: 1
  20920. }
  20921. },
  20922. axisLabel: {
  20923. show: true,
  20924. interval: 'auto',
  20925. rotate: 0,
  20926. margin: 8,
  20927. textStyle: { color: '#333' }
  20928. },
  20929. splitLine: {
  20930. show: true,
  20931. lineStyle: {
  20932. color: ['#ccc'],
  20933. width: 1,
  20934. type: 'solid'
  20935. }
  20936. },
  20937. splitArea: {
  20938. show: false,
  20939. areaStyle: {
  20940. color: [
  20941. 'rgba(250,250,250,0.3)',
  20942. 'rgba(200,200,200,0.3)'
  20943. ]
  20944. }
  20945. }
  20946. };
  20947. var zrUtil = require('zrender/tool/util');
  20948. var zrArea = require('zrender/tool/area');
  20949. function CategoryAxis(ecTheme, messageCenter, zr, option, myChart, axisBase) {
  20950. if (option.data.length < 1) {
  20951. console.error('option.data.length < 1.');
  20952. return;
  20953. }
  20954. Base.call(this, ecTheme, messageCenter, zr, option, myChart);
  20955. this.grid = this.component.grid;
  20956. for (var method in axisBase) {
  20957. this[method] = axisBase[method];
  20958. }
  20959. this.refresh(option);
  20960. }
  20961. CategoryAxis.prototype = {
  20962. type: ecConfig.COMPONENT_TYPE_AXIS_CATEGORY,
  20963. _getReformedLabel: function (idx) {
  20964. var data = this.getDataFromOption(this.option.data[idx]);
  20965. var formatter = this.option.data[idx].formatter || this.option.axisLabel.formatter;
  20966. if (formatter) {
  20967. if (typeof formatter == 'function') {
  20968. data = formatter.call(this.myChart, data);
  20969. } else if (typeof formatter == 'string') {
  20970. data = formatter.replace('{value}', data);
  20971. }
  20972. }
  20973. return data;
  20974. },
  20975. _getInterval: function () {
  20976. var interval = this.option.axisLabel.interval;
  20977. if (interval == 'auto') {
  20978. var fontSize = this.option.axisLabel.textStyle.fontSize;
  20979. var data = this.option.data;
  20980. var dataLength = this.option.data.length;
  20981. if (this.isHorizontal()) {
  20982. if (dataLength > 3) {
  20983. var gap = this.getGap();
  20984. var isEnough = false;
  20985. var labelSpace;
  20986. var labelSize;
  20987. var step = Math.floor(0.5 / gap);
  20988. step = step < 1 ? 1 : step;
  20989. interval = Math.floor(15 / gap);
  20990. while (!isEnough && interval < dataLength) {
  20991. interval += step;
  20992. isEnough = true;
  20993. labelSpace = Math.floor(gap * interval);
  20994. for (var i = Math.floor((dataLength - 1) / interval) * interval; i >= 0; i -= interval) {
  20995. if (this.option.axisLabel.rotate !== 0) {
  20996. labelSize = fontSize;
  20997. } else if (data[i].textStyle) {
  20998. labelSize = zrArea.getTextWidth(this._getReformedLabel(i), this.getFont(zrUtil.merge(data[i].textStyle, this.option.axisLabel.textStyle)));
  20999. } else {
  21000. var label = this._getReformedLabel(i) + '';
  21001. var wLen = (label.match(/\w/g) || '').length;
  21002. var oLen = label.length - wLen;
  21003. labelSize = wLen * fontSize * 2 / 3 + oLen * fontSize;
  21004. }
  21005. if (labelSpace < labelSize) {
  21006. isEnough = false;
  21007. break;
  21008. }
  21009. }
  21010. }
  21011. } else {
  21012. interval = 1;
  21013. }
  21014. } else {
  21015. if (dataLength > 3) {
  21016. var gap = this.getGap();
  21017. interval = Math.floor(11 / gap);
  21018. while (gap * interval - 6 < fontSize && interval < dataLength) {
  21019. interval++;
  21020. }
  21021. } else {
  21022. interval = 1;
  21023. }
  21024. }
  21025. } else {
  21026. interval = typeof interval == 'function' ? 1 : interval - 0 + 1;
  21027. }
  21028. return interval;
  21029. },
  21030. _buildShape: function () {
  21031. this._interval = this._getInterval();
  21032. if (!this.option.show) {
  21033. return;
  21034. }
  21035. this.option.splitArea.show && this._buildSplitArea();
  21036. this.option.splitLine.show && this._buildSplitLine();
  21037. this.option.axisLine.show && this._buildAxisLine();
  21038. this.option.axisTick.show && this._buildAxisTick();
  21039. this.option.axisLabel.show && this._buildAxisLabel();
  21040. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  21041. this.zr.addShape(this.shapeList[i]);
  21042. }
  21043. },
  21044. _buildAxisTick: function () {
  21045. var axShape;
  21046. var data = this.option.data;
  21047. var dataLength = this.option.data.length;
  21048. var tickOption = this.option.axisTick;
  21049. var length = tickOption.length;
  21050. var color = tickOption.lineStyle.color;
  21051. var lineWidth = tickOption.lineStyle.width;
  21052. var intervalFunction = typeof tickOption.interval == 'function' ? tickOption.interval : tickOption.interval == 'auto' ? typeof this.option.axisLabel.interval == 'function' ? this.option.axisLabel.interval : false : false;
  21053. var interval = intervalFunction ? 1 : tickOption.interval == 'auto' ? this._interval : tickOption.interval - 0 + 1;
  21054. var onGap = tickOption.onGap;
  21055. var optGap = onGap ? this.getGap() / 2 : typeof onGap == 'undefined' ? this.option.boundaryGap ? this.getGap() / 2 : 0 : 0;
  21056. var startIndex = optGap > 0 ? -interval : 0;
  21057. if (this.isHorizontal()) {
  21058. 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;
  21059. var x;
  21060. for (var i = startIndex; i < dataLength; i += interval) {
  21061. if (intervalFunction && !intervalFunction(i, data[i])) {
  21062. continue;
  21063. }
  21064. x = this.subPixelOptimize(this.getCoordByIndex(i) + (i >= 0 ? optGap : 0), lineWidth);
  21065. axShape = {
  21066. _axisShape: 'axisTick',
  21067. zlevel: this.getZlevelBase(),
  21068. z: this.getZBase(),
  21069. hoverable: false,
  21070. style: {
  21071. xStart: x,
  21072. yStart: yPosition,
  21073. xEnd: x,
  21074. yEnd: yPosition + length,
  21075. strokeColor: color,
  21076. lineWidth: lineWidth
  21077. }
  21078. };
  21079. this.shapeList.push(new LineShape(axShape));
  21080. }
  21081. } else {
  21082. 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;
  21083. var y;
  21084. for (var i = startIndex; i < dataLength; i += interval) {
  21085. if (intervalFunction && !intervalFunction(i, data[i])) {
  21086. continue;
  21087. }
  21088. y = this.subPixelOptimize(this.getCoordByIndex(i) - (i >= 0 ? optGap : 0), lineWidth);
  21089. axShape = {
  21090. _axisShape: 'axisTick',
  21091. zlevel: this.getZlevelBase(),
  21092. z: this.getZBase(),
  21093. hoverable: false,
  21094. style: {
  21095. xStart: xPosition,
  21096. yStart: y,
  21097. xEnd: xPosition + length,
  21098. yEnd: y,
  21099. strokeColor: color,
  21100. lineWidth: lineWidth
  21101. }
  21102. };
  21103. this.shapeList.push(new LineShape(axShape));
  21104. }
  21105. }
  21106. },
  21107. _buildAxisLabel: function () {
  21108. var axShape;
  21109. var data = this.option.data;
  21110. var dataLength = this.option.data.length;
  21111. var labelOption = this.option.axisLabel;
  21112. var rotate = labelOption.rotate;
  21113. var margin = labelOption.margin;
  21114. var clickable = labelOption.clickable;
  21115. var textStyle = labelOption.textStyle;
  21116. var intervalFunction = typeof labelOption.interval == 'function' ? labelOption.interval : false;
  21117. var dataTextStyle;
  21118. if (this.isHorizontal()) {
  21119. var yPosition;
  21120. var baseLine;
  21121. if (this.option.position == 'bottom') {
  21122. yPosition = this.grid.getYend() + margin;
  21123. baseLine = 'top';
  21124. } else {
  21125. yPosition = this.grid.getY() - margin;
  21126. baseLine = 'bottom';
  21127. }
  21128. for (var i = 0; i < dataLength; i += this._interval) {
  21129. if (intervalFunction && !intervalFunction(i, data[i]) || this._getReformedLabel(i) === '') {
  21130. continue;
  21131. }
  21132. dataTextStyle = zrUtil.merge(data[i].textStyle || {}, textStyle);
  21133. axShape = {
  21134. zlevel: this.getZlevelBase(),
  21135. z: this.getZBase() + 3,
  21136. hoverable: false,
  21137. style: {
  21138. x: this.getCoordByIndex(i),
  21139. y: yPosition,
  21140. color: dataTextStyle.color,
  21141. text: this._getReformedLabel(i),
  21142. textFont: this.getFont(dataTextStyle),
  21143. textAlign: dataTextStyle.align || 'center',
  21144. textBaseline: dataTextStyle.baseline || baseLine
  21145. }
  21146. };
  21147. if (rotate) {
  21148. axShape.style.textAlign = rotate > 0 ? this.option.position == 'bottom' ? 'right' : 'left' : this.option.position == 'bottom' ? 'left' : 'right';
  21149. axShape.rotation = [
  21150. rotate * Math.PI / 180,
  21151. axShape.style.x,
  21152. axShape.style.y
  21153. ];
  21154. }
  21155. this.shapeList.push(new TextShape(this._axisLabelClickable(clickable, axShape)));
  21156. }
  21157. } else {
  21158. var xPosition;
  21159. var align;
  21160. if (this.option.position == 'left') {
  21161. xPosition = this.grid.getX() - margin;
  21162. align = 'right';
  21163. } else {
  21164. xPosition = this.grid.getXend() + margin;
  21165. align = 'left';
  21166. }
  21167. for (var i = 0; i < dataLength; i += this._interval) {
  21168. if (intervalFunction && !intervalFunction(i, data[i]) || this._getReformedLabel(i) === '') {
  21169. continue;
  21170. }
  21171. dataTextStyle = zrUtil.merge(data[i].textStyle || {}, textStyle);
  21172. axShape = {
  21173. zlevel: this.getZlevelBase(),
  21174. z: this.getZBase() + 3,
  21175. hoverable: false,
  21176. style: {
  21177. x: xPosition,
  21178. y: this.getCoordByIndex(i),
  21179. color: dataTextStyle.color,
  21180. text: this._getReformedLabel(i),
  21181. textFont: this.getFont(dataTextStyle),
  21182. textAlign: dataTextStyle.align || align,
  21183. textBaseline: dataTextStyle.baseline || i === 0 && this.option.name !== '' ? 'bottom' : i == dataLength - 1 && this.option.name !== '' ? 'top' : 'middle'
  21184. }
  21185. };
  21186. if (rotate) {
  21187. axShape.rotation = [
  21188. rotate * Math.PI / 180,
  21189. axShape.style.x,
  21190. axShape.style.y
  21191. ];
  21192. }
  21193. this.shapeList.push(new TextShape(this._axisLabelClickable(clickable, axShape)));
  21194. }
  21195. }
  21196. },
  21197. _buildSplitLine: function () {
  21198. var axShape;
  21199. var data = this.option.data;
  21200. var dataLength = this.option.data.length;
  21201. var sLineOption = this.option.splitLine;
  21202. var lineType = sLineOption.lineStyle.type;
  21203. var lineWidth = sLineOption.lineStyle.width;
  21204. var color = sLineOption.lineStyle.color;
  21205. color = color instanceof Array ? color : [color];
  21206. var colorLength = color.length;
  21207. var intervalFunction = typeof this.option.axisLabel.interval == 'function' ? this.option.axisLabel.interval : false;
  21208. var onGap = sLineOption.onGap;
  21209. var optGap = onGap ? this.getGap() / 2 : typeof onGap == 'undefined' ? this.option.boundaryGap ? this.getGap() / 2 : 0 : 0;
  21210. dataLength -= onGap || typeof onGap == 'undefined' && this.option.boundaryGap ? 1 : 0;
  21211. if (this.isHorizontal()) {
  21212. var sy = this.grid.getY();
  21213. var ey = this.grid.getYend();
  21214. var x;
  21215. for (var i = 0; i < dataLength; i += this._interval) {
  21216. if (intervalFunction && !intervalFunction(i, data[i])) {
  21217. continue;
  21218. }
  21219. x = this.subPixelOptimize(this.getCoordByIndex(i) + optGap, lineWidth);
  21220. axShape = {
  21221. zlevel: this.getZlevelBase(),
  21222. z: this.getZBase(),
  21223. hoverable: false,
  21224. style: {
  21225. xStart: x,
  21226. yStart: sy,
  21227. xEnd: x,
  21228. yEnd: ey,
  21229. strokeColor: color[i / this._interval % colorLength],
  21230. lineType: lineType,
  21231. lineWidth: lineWidth
  21232. }
  21233. };
  21234. this.shapeList.push(new LineShape(axShape));
  21235. }
  21236. } else {
  21237. var sx = this.grid.getX();
  21238. var ex = this.grid.getXend();
  21239. var y;
  21240. for (var i = 0; i < dataLength; i += this._interval) {
  21241. if (intervalFunction && !intervalFunction(i, data[i])) {
  21242. continue;
  21243. }
  21244. y = this.subPixelOptimize(this.getCoordByIndex(i) - optGap, lineWidth);
  21245. axShape = {
  21246. zlevel: this.getZlevelBase(),
  21247. z: this.getZBase(),
  21248. hoverable: false,
  21249. style: {
  21250. xStart: sx,
  21251. yStart: y,
  21252. xEnd: ex,
  21253. yEnd: y,
  21254. strokeColor: color[i / this._interval % colorLength],
  21255. lineType: lineType,
  21256. lineWidth: lineWidth
  21257. }
  21258. };
  21259. this.shapeList.push(new LineShape(axShape));
  21260. }
  21261. }
  21262. },
  21263. _buildSplitArea: function () {
  21264. var axShape;
  21265. var data = this.option.data;
  21266. var sAreaOption = this.option.splitArea;
  21267. var color = sAreaOption.areaStyle.color;
  21268. if (!(color instanceof Array)) {
  21269. axShape = {
  21270. zlevel: this.getZlevelBase(),
  21271. z: this.getZBase(),
  21272. hoverable: false,
  21273. style: {
  21274. x: this.grid.getX(),
  21275. y: this.grid.getY(),
  21276. width: this.grid.getWidth(),
  21277. height: this.grid.getHeight(),
  21278. color: color
  21279. }
  21280. };
  21281. this.shapeList.push(new RectangleShape(axShape));
  21282. } else {
  21283. var colorLength = color.length;
  21284. var dataLength = this.option.data.length;
  21285. var intervalFunction = typeof this.option.axisLabel.interval == 'function' ? this.option.axisLabel.interval : false;
  21286. var onGap = sAreaOption.onGap;
  21287. var optGap = onGap ? this.getGap() / 2 : typeof onGap == 'undefined' ? this.option.boundaryGap ? this.getGap() / 2 : 0 : 0;
  21288. if (this.isHorizontal()) {
  21289. var y = this.grid.getY();
  21290. var height = this.grid.getHeight();
  21291. var lastX = this.grid.getX();
  21292. var curX;
  21293. for (var i = 0; i <= dataLength; i += this._interval) {
  21294. if (intervalFunction && !intervalFunction(i, data[i]) && i < dataLength) {
  21295. continue;
  21296. }
  21297. curX = i < dataLength ? this.getCoordByIndex(i) + optGap : this.grid.getXend();
  21298. axShape = {
  21299. zlevel: this.getZlevelBase(),
  21300. z: this.getZBase(),
  21301. hoverable: false,
  21302. style: {
  21303. x: lastX,
  21304. y: y,
  21305. width: curX - lastX,
  21306. height: height,
  21307. color: color[i / this._interval % colorLength]
  21308. }
  21309. };
  21310. this.shapeList.push(new RectangleShape(axShape));
  21311. lastX = curX;
  21312. }
  21313. } else {
  21314. var x = this.grid.getX();
  21315. var width = this.grid.getWidth();
  21316. var lastYend = this.grid.getYend();
  21317. var curY;
  21318. for (var i = 0; i <= dataLength; i += this._interval) {
  21319. if (intervalFunction && !intervalFunction(i, data[i]) && i < dataLength) {
  21320. continue;
  21321. }
  21322. curY = i < dataLength ? this.getCoordByIndex(i) - optGap : this.grid.getY();
  21323. axShape = {
  21324. zlevel: this.getZlevelBase(),
  21325. z: this.getZBase(),
  21326. hoverable: false,
  21327. style: {
  21328. x: x,
  21329. y: curY,
  21330. width: width,
  21331. height: lastYend - curY,
  21332. color: color[i / this._interval % colorLength]
  21333. }
  21334. };
  21335. this.shapeList.push(new RectangleShape(axShape));
  21336. lastYend = curY;
  21337. }
  21338. }
  21339. }
  21340. },
  21341. refresh: function (newOption) {
  21342. if (newOption) {
  21343. this.option = this.reformOption(newOption);
  21344. this.option.axisLabel.textStyle = this.getTextStyle(this.option.axisLabel.textStyle);
  21345. }
  21346. this.clear();
  21347. this._buildShape();
  21348. },
  21349. getGap: function () {
  21350. var dataLength = this.option.data.length;
  21351. var total = this.isHorizontal() ? this.grid.getWidth() : this.grid.getHeight();
  21352. if (this.option.boundaryGap) {
  21353. return total / dataLength;
  21354. } else {
  21355. return total / (dataLength > 1 ? dataLength - 1 : 1);
  21356. }
  21357. },
  21358. getCoord: function (value) {
  21359. var data = this.option.data;
  21360. var dataLength = data.length;
  21361. var gap = this.getGap();
  21362. var position = this.option.boundaryGap ? gap / 2 : 0;
  21363. for (var i = 0; i < dataLength; i++) {
  21364. if (this.getDataFromOption(data[i]) == value) {
  21365. if (this.isHorizontal()) {
  21366. position = this.grid.getX() + position;
  21367. } else {
  21368. position = this.grid.getYend() - position;
  21369. }
  21370. return position;
  21371. }
  21372. position += gap;
  21373. }
  21374. },
  21375. getCoordByIndex: function (dataIndex) {
  21376. if (dataIndex < 0) {
  21377. if (this.isHorizontal()) {
  21378. return this.grid.getX();
  21379. } else {
  21380. return this.grid.getYend();
  21381. }
  21382. } else if (dataIndex > this.option.data.length - 1) {
  21383. if (this.isHorizontal()) {
  21384. return this.grid.getXend();
  21385. } else {
  21386. return this.grid.getY();
  21387. }
  21388. } else {
  21389. var gap = this.getGap();
  21390. var position = this.option.boundaryGap ? gap / 2 : 0;
  21391. position += dataIndex * gap;
  21392. if (this.isHorizontal()) {
  21393. position = this.grid.getX() + position;
  21394. } else {
  21395. position = this.grid.getYend() - position;
  21396. }
  21397. return position;
  21398. }
  21399. },
  21400. getNameByIndex: function (dataIndex) {
  21401. return this.getDataFromOption(this.option.data[dataIndex]);
  21402. },
  21403. getIndexByName: function (name) {
  21404. var data = this.option.data;
  21405. var dataLength = data.length;
  21406. for (var i = 0; i < dataLength; i++) {
  21407. if (this.getDataFromOption(data[i]) == name) {
  21408. return i;
  21409. }
  21410. }
  21411. return -1;
  21412. },
  21413. getValueFromCoord: function () {
  21414. return '';
  21415. },
  21416. isMainAxis: function (dataIndex) {
  21417. return dataIndex % this._interval === 0;
  21418. }
  21419. };
  21420. zrUtil.inherits(CategoryAxis, Base);
  21421. require('../component').define('categoryAxis', CategoryAxis);
  21422. return CategoryAxis;
  21423. });define('echarts/component/valueAxis', [
  21424. 'require',
  21425. './base',
  21426. 'zrender/shape/Text',
  21427. 'zrender/shape/Line',
  21428. 'zrender/shape/Rectangle',
  21429. '../config',
  21430. '../util/date',
  21431. 'zrender/tool/util',
  21432. '../util/smartSteps',
  21433. '../util/accMath',
  21434. '../component'
  21435. ], function (require) {
  21436. var Base = require('./base');
  21437. var TextShape = require('zrender/shape/Text');
  21438. var LineShape = require('zrender/shape/Line');
  21439. var RectangleShape = require('zrender/shape/Rectangle');
  21440. var ecConfig = require('../config');
  21441. ecConfig.valueAxis = {
  21442. zlevel: 0,
  21443. z: 0,
  21444. show: true,
  21445. position: 'left',
  21446. name: '',
  21447. nameLocation: 'end',
  21448. nameTextStyle: {},
  21449. boundaryGap: [
  21450. 0,
  21451. 0
  21452. ],
  21453. axisLine: {
  21454. show: true,
  21455. onZero: true,
  21456. lineStyle: {
  21457. color: '#48b',
  21458. width: 2,
  21459. type: 'solid'
  21460. }
  21461. },
  21462. axisTick: {
  21463. show: false,
  21464. inside: false,
  21465. length: 5,
  21466. lineStyle: {
  21467. color: '#333',
  21468. width: 1
  21469. }
  21470. },
  21471. axisLabel: {
  21472. show: true,
  21473. rotate: 0,
  21474. margin: 8,
  21475. textStyle: { color: '#333' }
  21476. },
  21477. splitLine: {
  21478. show: true,
  21479. lineStyle: {
  21480. color: ['#ccc'],
  21481. width: 1,
  21482. type: 'solid'
  21483. }
  21484. },
  21485. splitArea: {
  21486. show: false,
  21487. areaStyle: {
  21488. color: [
  21489. 'rgba(250,250,250,0.3)',
  21490. 'rgba(200,200,200,0.3)'
  21491. ]
  21492. }
  21493. }
  21494. };
  21495. var ecDate = require('../util/date');
  21496. var zrUtil = require('zrender/tool/util');
  21497. function ValueAxis(ecTheme, messageCenter, zr, option, myChart, axisBase, series) {
  21498. if (!series || series.length === 0) {
  21499. console.err('option.series.length == 0.');
  21500. return;
  21501. }
  21502. Base.call(this, ecTheme, messageCenter, zr, option, myChart);
  21503. this.series = series;
  21504. this.grid = this.component.grid;
  21505. for (var method in axisBase) {
  21506. this[method] = axisBase[method];
  21507. }
  21508. this.refresh(option, series);
  21509. }
  21510. ValueAxis.prototype = {
  21511. type: ecConfig.COMPONENT_TYPE_AXIS_VALUE,
  21512. _buildShape: function () {
  21513. this._hasData = false;
  21514. this._calculateValue();
  21515. if (!this._hasData || !this.option.show) {
  21516. return;
  21517. }
  21518. this.option.splitArea.show && this._buildSplitArea();
  21519. this.option.splitLine.show && this._buildSplitLine();
  21520. this.option.axisLine.show && this._buildAxisLine();
  21521. this.option.axisTick.show && this._buildAxisTick();
  21522. this.option.axisLabel.show && this._buildAxisLabel();
  21523. for (var i = 0, l = this.shapeList.length; i < l; i++) {
  21524. this.zr.addShape(this.shapeList[i]);
  21525. }
  21526. },
  21527. _buildAxisTick: function () {
  21528. var axShape;
  21529. var data = this._valueList;
  21530. var dataLength = this._valueList.length;
  21531. var tickOption = this.option.axisTick;
  21532. var length = tickOption.length;
  21533. var color = tickOption.lineStyle.color;
  21534. var lineWidth = tickOption.lineStyle.width;
  21535. if (this.isHorizontal()) {
  21536. 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;
  21537. var x;
  21538. for (var i = 0; i < dataLength; i++) {
  21539. x = this.subPixelOptimize(this.getCoord(data[i]), lineWidth);
  21540. axShape = {
  21541. _axisShape: 'axisTick',
  21542. zlevel: this.getZlevelBase(),
  21543. z: this.getZBase(),
  21544. hoverable: false,
  21545. style: {
  21546. xStart: x,
  21547. yStart: yPosition,
  21548. xEnd: x,
  21549. yEnd: yPosition + length,
  21550. strokeColor: color,
  21551. lineWidth: lineWidth
  21552. }
  21553. };
  21554. this.shapeList.push(new LineShape(axShape));
  21555. }
  21556. } else {
  21557. 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;
  21558. var y;
  21559. for (var i = 0; i < dataLength; i++) {
  21560. y = this.subPixelOptimize(this.getCoord(data[i]), lineWidth);
  21561. axShape = {
  21562. _axisShape: 'axisTick',
  21563. zlevel: this.getZlevelBase(),
  21564. z: this.getZBase(),
  21565. hoverable: false,
  21566. style: {
  21567. xStart: xPosition,
  21568. yStart: y,
  21569. xEnd: xPosition + length,
  21570. yEnd: y,
  21571. strokeColor: color,
  21572. lineWidth: lineWidth
  21573. }
  21574. };
  21575. this.shapeList.push(new LineShape(axShape));
  21576. }
  21577. }
  21578. },
  21579. _buildAxisLabel: function () {
  21580. var axShape;
  21581. var data = this._valueList;
  21582. var dataLength = this._valueList.length;
  21583. var rotate = this.option.axisLabel.rotate;
  21584. var margin = this.option.axisLabel.margin;
  21585. var clickable = this.option.axisLabel.clickable;
  21586. var textStyle = this.option.axisLabel.textStyle;
  21587. if (this.isHorizontal()) {
  21588. var yPosition;
  21589. var baseLine;
  21590. if (this.option.position === 'bottom') {
  21591. yPosition = this.grid.getYend() + margin;
  21592. baseLine = 'top';
  21593. } else {
  21594. yPosition = this.grid.getY() - margin;
  21595. baseLine = 'bottom';
  21596. }
  21597. for (var i = 0; i < dataLength; i++) {
  21598. axShape = {
  21599. zlevel: this.getZlevelBase(),
  21600. z: this.getZBase() + 3,
  21601. hoverable: false,
  21602. style: {
  21603. x: this.getCoord(data[i]),
  21604. y: yPosition,
  21605. color: typeof textStyle.color === 'function' ? textStyle.color(data[i]) : textStyle.color,
  21606. text: this._valueLabel[i],
  21607. textFont: this.getFont(textStyle),
  21608. textAlign: textStyle.align || 'center',
  21609. textBaseline: textStyle.baseline || baseLine
  21610. }
  21611. };
  21612. if (rotate) {
  21613. axShape.style.textAlign = rotate > 0 ? this.option.position === 'bottom' ? 'right' : 'left' : this.option.position === 'bottom' ? 'left' : 'right';
  21614. axShape.rotation = [
  21615. rotate * Math.PI / 180,
  21616. axShape.style.x,
  21617. axShape.style.y
  21618. ];
  21619. }
  21620. this.shapeList.push(new TextShape(this._axisLabelClickable(clickable, axShape)));
  21621. }
  21622. } else {
  21623. var xPosition;
  21624. var align;
  21625. if (this.option.position === 'left') {
  21626. xPosition = this.grid.getX() - margin;
  21627. align = 'right';
  21628. } else {
  21629. xPosition = this.grid.getXend() + margin;
  21630. align = 'left';
  21631. }
  21632. for (var i = 0; i < dataLength; i++) {
  21633. axShape = {
  21634. zlevel: this.getZlevelBase(),
  21635. z: this.getZBase() + 3,
  21636. hoverable: false,
  21637. style: {
  21638. x: xPosition,
  21639. y: this.getCoord(data[i]),
  21640. color: typeof textStyle.color === 'function' ? textStyle.color(data[i]) : textStyle.color,
  21641. text: this._valueLabel[i],
  21642. textFont: this.getFont(textStyle),
  21643. textAlign: textStyle.align || align,
  21644. textBaseline: textStyle.baseline || (i === 0 && this.option.name !== '' ? 'bottom' : i === dataLength - 1 && this.option.name !== '' ? 'top' : 'middle')
  21645. }
  21646. };
  21647. if (rotate) {
  21648. axShape.rotation = [
  21649. rotate * Math.PI / 180,
  21650. axShape.style.x,
  21651. axShape.style.y
  21652. ];
  21653. }
  21654. this.shapeList.push(new TextShape(this._axisLabelClickable(clickable, axShape)));
  21655. }
  21656. }
  21657. },
  21658. _buildSplitLine: function () {
  21659. var axShape;
  21660. var data = this._valueList;
  21661. var dataLength = this._valueList.length;
  21662. var sLineOption = this.option.splitLine;
  21663. var lineType = sLineOption.lineStyle.type;
  21664. var lineWidth = sLineOption.lineStyle.width;
  21665. var color = sLineOption.lineStyle.color;
  21666. color = color instanceof Array ? color : [color];
  21667. var colorLength = color.length;
  21668. if (this.isHorizontal()) {
  21669. var sy = this.grid.getY();
  21670. var ey = this.grid.getYend();
  21671. var x;
  21672. for (var i = 0; i < dataLength; i++) {
  21673. x = this.subPixelOptimize(this.getCoord(data[i]), lineWidth);
  21674. axShape = {
  21675. zlevel: this.getZlevelBase(),
  21676. z: this.getZBase(),
  21677. hoverable: false,
  21678. style: {
  21679. xStart: x,
  21680. yStart: sy,
  21681. xEnd: x,
  21682. yEnd: ey,
  21683. strokeColor: color[i % colorLength],
  21684. lineType: lineType,
  21685. lineWidth: lineWidth
  21686. }
  21687. };
  21688. this.shapeList.push(new LineShape(axShape));
  21689. }
  21690. } else {
  21691. var sx = this.grid.getX();
  21692. var ex = this.grid.getXend();
  21693. var y;
  21694. for (var i = 0; i < dataLength; i++) {
  21695. y = this.subPixelOptimize(this.getCoord(data[i]), lineWidth);
  21696. axShape = {
  21697. zlevel: this.getZlevelBase(),
  21698. z: this.getZBase(),
  21699. hoverable: false,
  21700. style: {
  21701. xStart: sx,
  21702. yStart: y,
  21703. xEnd: ex,
  21704. yEnd: y,
  21705. strokeColor: color[i % colorLength],
  21706. lineType: lineType,
  21707. lineWidth: lineWidth
  21708. }
  21709. };
  21710. this.shapeList.push(new LineShape(axShape));
  21711. }
  21712. }
  21713. },
  21714. _buildSplitArea: function () {
  21715. var axShape;
  21716. var color = this.option.splitArea.areaStyle.color;
  21717. if (!(color instanceof Array)) {
  21718. axShape = {
  21719. zlevel: this.getZlevelBase(),
  21720. z: this.getZBase(),
  21721. hoverable: false,
  21722. style: {
  21723. x: this.grid.getX(),
  21724. y: this.grid.getY(),
  21725. width: this.grid.getWidth(),
  21726. height: this.grid.getHeight(),
  21727. color: color
  21728. }
  21729. };
  21730. this.shapeList.push(new RectangleShape(axShape));
  21731. } else {
  21732. var colorLength = color.length;
  21733. var data = this._valueList;
  21734. var dataLength = this._valueList.length;
  21735. if (this.isHorizontal()) {
  21736. var y = this.grid.getY();
  21737. var height = this.grid.getHeight();
  21738. var lastX = this.grid.getX();
  21739. var curX;
  21740. for (var i = 0; i <= dataLength; i++) {
  21741. curX = i < dataLength ? this.getCoord(data[i]) : this.grid.getXend();
  21742. axShape = {
  21743. zlevel: this.getZlevelBase(),
  21744. z: this.getZBase(),
  21745. hoverable: false,
  21746. style: {
  21747. x: lastX,
  21748. y: y,
  21749. width: curX - lastX,
  21750. height: height,
  21751. color: color[i % colorLength]
  21752. }
  21753. };
  21754. this.shapeList.push(new RectangleShape(axShape));
  21755. lastX = curX;
  21756. }
  21757. } else {
  21758. var x = this.grid.getX();
  21759. var width = this.grid.getWidth();
  21760. var lastYend = this.grid.getYend();
  21761. var curY;
  21762. for (var i = 0; i <= dataLength; i++) {
  21763. curY = i < dataLength ? this.getCoord(data[i]) : this.grid.getY();
  21764. axShape = {
  21765. zlevel: this.getZlevelBase(),
  21766. z: this.getZBase(),
  21767. hoverable: false,
  21768. style: {
  21769. x: x,
  21770. y: curY,
  21771. width: width,
  21772. height: lastYend - curY,
  21773. color: color[i % colorLength]
  21774. }
  21775. };
  21776. this.shapeList.push(new RectangleShape(axShape));
  21777. lastYend = curY;
  21778. }
  21779. }
  21780. }
  21781. },
  21782. _calculateValue: function () {
  21783. if (isNaN(this.option.min - 0) || isNaN(this.option.max - 0)) {
  21784. var data = {};
  21785. var xIdx;
  21786. var yIdx;
  21787. var legend = this.component.legend;
  21788. for (var i = 0, l = this.series.length; i < l; i++) {
  21789. 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) {
  21790. continue;
  21791. }
  21792. if (legend && !legend.isSelected(this.series[i].name)) {
  21793. continue;
  21794. }
  21795. xIdx = this.series[i].xAxisIndex || 0;
  21796. yIdx = this.series[i].yAxisIndex || 0;
  21797. if (this.option.xAxisIndex != xIdx && this.option.yAxisIndex != yIdx) {
  21798. continue;
  21799. }
  21800. this._calculSum(data, i);
  21801. }
  21802. var oriData;
  21803. for (var i in data) {
  21804. oriData = data[i];
  21805. for (var j = 0, k = oriData.length; j < k; j++) {
  21806. if (!isNaN(oriData[j])) {
  21807. this._hasData = true;
  21808. this._min = oriData[j];
  21809. this._max = oriData[j];
  21810. break;
  21811. }
  21812. }
  21813. if (this._hasData) {
  21814. break;
  21815. }
  21816. }
  21817. for (var i in data) {
  21818. oriData = data[i];
  21819. for (var j = 0, k = oriData.length; j < k; j++) {
  21820. if (!isNaN(oriData[j])) {
  21821. this._min = Math.min(this._min, oriData[j]);
  21822. this._max = Math.max(this._max, oriData[j]);
  21823. }
  21824. }
  21825. }
  21826. var gap = Math.abs(this._max - this._min);
  21827. this._min = isNaN(this.option.min - 0) ? this._min - Math.abs(gap * this.option.boundaryGap[0]) : this.option.min - 0;
  21828. this._max = isNaN(this.option.max - 0) ? this._max + Math.abs(gap * this.option.boundaryGap[1]) : this.option.max - 0;
  21829. if (this._min === this._max) {
  21830. if (this._max === 0) {
  21831. this._max = 1;
  21832. } else if (this._max > 0) {
  21833. this._min = this._max / this.option.splitNumber != null ? this.option.splitNumber : 5;
  21834. } else {
  21835. this._max = this._max / this.option.splitNumber != null ? this.option.splitNumber : 5;
  21836. }
  21837. }
  21838. this.option.type != 'time' ? this._reformValue(this.option.scale) : this._reformTimeValue();
  21839. } else {
  21840. this._hasData = true;
  21841. this._min = this.option.min - 0;
  21842. this._max = this.option.max - 0;
  21843. this.option.type != 'time' ? this._customerValue() : this._reformTimeValue();
  21844. }
  21845. },
  21846. _calculSum: function (data, i) {
  21847. var key = this.series[i].name || 'kener';
  21848. var value;
  21849. var oriData;
  21850. if (!this.series[i].stack) {
  21851. data[key] = data[key] || [];
  21852. if (this.series[i].type != ecConfig.CHART_TYPE_EVENTRIVER) {
  21853. oriData = this.series[i].data;
  21854. for (var j = 0, k = oriData.length; j < k; j++) {
  21855. value = this.getDataFromOption(oriData[j]);
  21856. if (this.series[i].type === ecConfig.CHART_TYPE_K) {
  21857. data[key].push(value[0]);
  21858. data[key].push(value[1]);
  21859. data[key].push(value[2]);
  21860. data[key].push(value[3]);
  21861. } else if (value instanceof Array) {
  21862. if (this.option.xAxisIndex != -1) {
  21863. data[key].push(this.option.type != 'time' ? value[0] : ecDate.getNewDate(value[0]));
  21864. }
  21865. if (this.option.yAxisIndex != -1) {
  21866. data[key].push(this.option.type != 'time' ? value[1] : ecDate.getNewDate(value[1]));
  21867. }
  21868. } else {
  21869. data[key].push(value);
  21870. }
  21871. }
  21872. } else {
  21873. oriData = this.series[i].data;
  21874. for (var j = 0, k = oriData.length; j < k; j++) {
  21875. var evolution = oriData[j].evolution;
  21876. for (var m = 0, n = evolution.length; m < n; m++) {
  21877. data[key].push(ecDate.getNewDate(evolution[m].time));
  21878. }
  21879. }
  21880. }
  21881. } else {
  21882. var keyP = '__Magic_Key_Positive__' + this.series[i].stack;
  21883. var keyN = '__Magic_Key_Negative__' + this.series[i].stack;
  21884. data[keyP] = data[keyP] || [];
  21885. data[keyN] = data[keyN] || [];
  21886. data[key] = data[key] || [];
  21887. oriData = this.series[i].data;
  21888. for (var j = 0, k = oriData.length; j < k; j++) {
  21889. value = this.getDataFromOption(oriData[j]);
  21890. if (value === '-') {
  21891. continue;
  21892. }
  21893. value = value - 0;
  21894. if (value >= 0) {
  21895. if (data[keyP][j] != null) {
  21896. data[keyP][j] += value;
  21897. } else {
  21898. data[keyP][j] = value;
  21899. }
  21900. } else {
  21901. if (data[keyN][j] != null) {
  21902. data[keyN][j] += value;
  21903. } else {
  21904. data[keyN][j] = value;
  21905. }
  21906. }
  21907. if (this.option.scale) {
  21908. data[key].push(value);
  21909. }
  21910. }
  21911. }
  21912. },
  21913. _reformValue: function (scale) {
  21914. var smartSteps = require('../util/smartSteps');
  21915. var splitNumber = this.option.splitNumber;
  21916. if (!scale && this._min >= 0 && this._max >= 0) {
  21917. this._min = 0;
  21918. }
  21919. if (!scale && this._min <= 0 && this._max <= 0) {
  21920. this._max = 0;
  21921. }
  21922. var stepOpt = smartSteps(this._min, this._max, splitNumber);
  21923. splitNumber = splitNumber != null ? splitNumber : stepOpt.secs;
  21924. this._min = stepOpt.min;
  21925. this._max = stepOpt.max;
  21926. this._valueList = stepOpt.pnts;
  21927. this._reformLabelData();
  21928. },
  21929. _reformTimeValue: function () {
  21930. var splitNumber = this.option.splitNumber != null ? this.option.splitNumber : 5;
  21931. var curValue = ecDate.getAutoFormatter(this._min, this._max, splitNumber);
  21932. var formatter = curValue.formatter;
  21933. var gapValue = curValue.gapValue;
  21934. this._valueList = [ecDate.getNewDate(this._min)];
  21935. var startGap;
  21936. switch (formatter) {
  21937. case 'week':
  21938. startGap = ecDate.nextMonday(this._min);
  21939. break;
  21940. case 'month':
  21941. startGap = ecDate.nextNthOnMonth(this._min, 1);
  21942. break;
  21943. case 'quarter':
  21944. startGap = ecDate.nextNthOnQuarterYear(this._min, 1);
  21945. break;
  21946. case 'half-year':
  21947. startGap = ecDate.nextNthOnHalfYear(this._min, 1);
  21948. break;
  21949. case 'year':
  21950. startGap = ecDate.nextNthOnYear(this._min, 1);
  21951. break;
  21952. default:
  21953. if (gapValue <= 3600000 * 2) {
  21954. startGap = (Math.floor(this._min / gapValue) + 1) * gapValue;
  21955. } else {
  21956. startGap = ecDate.getNewDate(this._min - -gapValue);
  21957. startGap.setHours(Math.round(startGap.getHours() / 6) * 6);
  21958. startGap.setMinutes(0);
  21959. startGap.setSeconds(0);
  21960. }
  21961. break;
  21962. }
  21963. if (startGap - this._min < gapValue / 2) {
  21964. startGap -= -gapValue;
  21965. }
  21966. curValue = ecDate.getNewDate(startGap);
  21967. splitNumber *= 1.5;
  21968. while (splitNumber-- >= 0) {
  21969. if (formatter == 'month' || formatter == 'quarter' || formatter == 'half-year' || formatter == 'year') {
  21970. curValue.setDate(1);
  21971. }
  21972. if (this._max - curValue < gapValue / 2) {
  21973. break;
  21974. }
  21975. this._valueList.push(curValue);
  21976. curValue = ecDate.getNewDate(curValue - -gapValue);
  21977. }
  21978. this._valueList.push(ecDate.getNewDate(this._max));
  21979. this._reformLabelData(formatter);
  21980. },
  21981. _customerValue: function () {
  21982. var accMath = require('../util/accMath');
  21983. var splitNumber = this.option.splitNumber != null ? this.option.splitNumber : 5;
  21984. var splitGap = (this._max - this._min) / splitNumber;
  21985. this._valueList = [];
  21986. for (var i = 0; i <= splitNumber; i++) {
  21987. this._valueList.push(accMath.accAdd(this._min, accMath.accMul(splitGap, i)));
  21988. }
  21989. this._reformLabelData();
  21990. },
  21991. _reformLabelData: function (timeFormatter) {
  21992. this._valueLabel = [];
  21993. var formatter = this.option.axisLabel.formatter;
  21994. if (formatter) {
  21995. for (var i = 0, l = this._valueList.length; i < l; i++) {
  21996. if (typeof formatter === 'function') {
  21997. this._valueLabel.push(timeFormatter ? formatter.call(this.myChart, this._valueList[i], timeFormatter) : formatter.call(this.myChart, this._valueList[i]));
  21998. } else if (typeof formatter === 'string') {
  21999. this._valueLabel.push(timeFormatter ? ecDate.format(formatter, this._valueList[i]) : formatter.replace('{value}', this._valueList[i]));
  22000. }
  22001. }
  22002. } else if (timeFormatter) {
  22003. for (var i = 0, l = this._valueList.length; i < l; i++) {
  22004. this._valueLabel.push(ecDate.format(timeFormatter, this._valueList[i]));
  22005. }
  22006. } else {
  22007. for (var i = 0, l = this._valueList.length; i < l; i++) {
  22008. this._valueLabel.push(this.numAddCommas(this._valueList[i]));
  22009. }
  22010. }
  22011. },
  22012. getExtremum: function () {
  22013. this._calculateValue();
  22014. return {
  22015. min: this._min,
  22016. max: this._max
  22017. };
  22018. },
  22019. refresh: function (newOption, newSeries) {
  22020. if (newOption) {
  22021. this.option = this.reformOption(newOption);
  22022. this.option.axisLabel.textStyle = zrUtil.merge(this.option.axisLabel.textStyle || {}, this.ecTheme.textStyle);
  22023. this.series = newSeries;
  22024. }
  22025. if (this.zr) {
  22026. this.clear();
  22027. this._buildShape();
  22028. }
  22029. },
  22030. getCoord: function (value) {
  22031. value = value < this._min ? this._min : value;
  22032. value = value > this._max ? this._max : value;
  22033. var result;
  22034. if (!this.isHorizontal()) {
  22035. result = this.grid.getYend() - (value - this._min) / (this._max - this._min) * this.grid.getHeight();
  22036. } else {
  22037. result = this.grid.getX() + (value - this._min) / (this._max - this._min) * this.grid.getWidth();
  22038. }
  22039. return result;
  22040. },
  22041. getCoordSize: function (value) {
  22042. if (!this.isHorizontal()) {
  22043. return Math.abs(value / (this._max - this._min) * this.grid.getHeight());
  22044. } else {
  22045. return Math.abs(value / (this._max - this._min) * this.grid.getWidth());
  22046. }
  22047. },
  22048. getValueFromCoord: function (coord) {
  22049. var result;
  22050. if (!this.isHorizontal()) {
  22051. coord = coord < this.grid.getY() ? this.grid.getY() : coord;
  22052. coord = coord > this.grid.getYend() ? this.grid.getYend() : coord;
  22053. result = this._max - (coord - this.grid.getY()) / this.grid.getHeight() * (this._max - this._min);
  22054. } else {
  22055. coord = coord < this.grid.getX() ? this.grid.getX() : coord;
  22056. coord = coord > this.grid.getXend() ? this.grid.getXend() : coord;
  22057. result = this._min + (coord - this.grid.getX()) / this.grid.getWidth() * (this._max - this._min);
  22058. }
  22059. return result.toFixed(2) - 0;
  22060. },
  22061. isMaindAxis: function (value) {
  22062. for (var i = 0, l = this._valueList.length; i < l; i++) {
  22063. if (this._valueList[i] === value) {
  22064. return true;
  22065. }
  22066. }
  22067. return false;
  22068. }
  22069. };
  22070. zrUtil.inherits(ValueAxis, Base);
  22071. require('../component').define('valueAxis', ValueAxis);
  22072. return ValueAxis;
  22073. });define('echarts/util/date', [], function () {
  22074. var _timeGap = [
  22075. {
  22076. formatter: 'hh : mm : ss',
  22077. value: 1000
  22078. },
  22079. {
  22080. formatter: 'hh : mm : ss',
  22081. value: 1000 * 5
  22082. },
  22083. {
  22084. formatter: 'hh : mm : ss',
  22085. value: 1000 * 10
  22086. },
  22087. {
  22088. formatter: 'hh : mm : ss',
  22089. value: 1000 * 15
  22090. },
  22091. {
  22092. formatter: 'hh : mm : ss',
  22093. value: 1000 * 30
  22094. },
  22095. {
  22096. formatter: 'hh : mm\nMM - dd',
  22097. value: 60000
  22098. },
  22099. {
  22100. formatter: 'hh : mm\nMM - dd',
  22101. value: 60000 * 5
  22102. },
  22103. {
  22104. formatter: 'hh : mm\nMM - dd',
  22105. value: 60000 * 10
  22106. },
  22107. {
  22108. formatter: 'hh : mm\nMM - dd',
  22109. value: 60000 * 15
  22110. },
  22111. {
  22112. formatter: 'hh : mm\nMM - dd',
  22113. value: 60000 * 30
  22114. },
  22115. {
  22116. formatter: 'hh : mm\nMM - dd',
  22117. value: 3600000
  22118. },
  22119. {
  22120. formatter: 'hh : mm\nMM - dd',
  22121. value: 3600000 * 2
  22122. },
  22123. {
  22124. formatter: 'hh : mm\nMM - dd',
  22125. value: 3600000 * 6
  22126. },
  22127. {
  22128. formatter: 'hh : mm\nMM - dd',
  22129. value: 3600000 * 12
  22130. },
  22131. {
  22132. formatter: 'MM - dd\nyyyy',
  22133. value: 3600000 * 24
  22134. },
  22135. {
  22136. formatter: 'week',
  22137. value: 3600000 * 24 * 7
  22138. },
  22139. {
  22140. formatter: 'month',
  22141. value: 3600000 * 24 * 31
  22142. },
  22143. {
  22144. formatter: 'quarter',
  22145. value: 3600000 * 24 * 380 / 4
  22146. },
  22147. {
  22148. formatter: 'half-year',
  22149. value: 3600000 * 24 * 380 / 2
  22150. },
  22151. {
  22152. formatter: 'year',
  22153. value: 3600000 * 24 * 380
  22154. }
  22155. ];
  22156. function getAutoFormatter(min, max, splitNumber) {
  22157. splitNumber = splitNumber > 1 ? splitNumber : 2;
  22158. var curValue;
  22159. var totalGap;
  22160. var formatter;
  22161. var gapValue;
  22162. for (var i = 0, l = _timeGap.length; i < l; i++) {
  22163. curValue = _timeGap[i].value;
  22164. totalGap = Math.ceil(max / curValue) * curValue - Math.floor(min / curValue) * curValue;
  22165. if (Math.round(totalGap / curValue) <= splitNumber * 1.2) {
  22166. formatter = _timeGap[i].formatter;
  22167. gapValue = _timeGap[i].value;
  22168. break;
  22169. }
  22170. }
  22171. if (formatter == null) {
  22172. formatter = 'year';
  22173. curValue = 3600000 * 24 * 367;
  22174. totalGap = Math.ceil(max / curValue) * curValue - Math.floor(min / curValue) * curValue;
  22175. gapValue = Math.round(totalGap / (splitNumber - 1) / curValue) * curValue;
  22176. }
  22177. return {
  22178. formatter: formatter,
  22179. gapValue: gapValue
  22180. };
  22181. }
  22182. function s2d(v) {
  22183. return v < 10 ? '0' + v : v;
  22184. }
  22185. function format(formatter, value) {
  22186. if (formatter == 'week' || formatter == 'month' || formatter == 'quarter' || formatter == 'half-year' || formatter == 'year') {
  22187. formatter = 'MM - dd\nyyyy';
  22188. }
  22189. var date = getNewDate(value);
  22190. var y = date.getFullYear();
  22191. var M = date.getMonth() + 1;
  22192. var d = date.getDate();
  22193. var h = date.getHours();
  22194. var m = date.getMinutes();
  22195. var s = date.getSeconds();
  22196. formatter = formatter.replace('MM', s2d(M));
  22197. formatter = formatter.toLowerCase();
  22198. formatter = formatter.replace('yyyy', y);
  22199. formatter = formatter.replace('yy', y % 100);
  22200. formatter = formatter.replace('dd', s2d(d));
  22201. formatter = formatter.replace('d', d);
  22202. formatter = formatter.replace('hh', s2d(h));
  22203. formatter = formatter.replace('h', h);
  22204. formatter = formatter.replace('mm', s2d(m));
  22205. formatter = formatter.replace('m', m);
  22206. formatter = formatter.replace('ss', s2d(s));
  22207. formatter = formatter.replace('s', s);
  22208. return formatter;
  22209. }
  22210. function nextMonday(value) {
  22211. value = getNewDate(value);
  22212. value.setDate(value.getDate() + 8 - value.getDay());
  22213. return value;
  22214. }
  22215. function nextNthPerNmonth(value, nth, nmon) {
  22216. value = getNewDate(value);
  22217. value.setMonth(Math.ceil((value.getMonth() + 1) / nmon) * nmon);
  22218. value.setDate(nth);
  22219. return value;
  22220. }
  22221. function nextNthOnMonth(value, nth) {
  22222. return nextNthPerNmonth(value, nth, 1);
  22223. }
  22224. function nextNthOnQuarterYear(value, nth) {
  22225. return nextNthPerNmonth(value, nth, 3);
  22226. }
  22227. function nextNthOnHalfYear(value, nth) {
  22228. return nextNthPerNmonth(value, nth, 6);
  22229. }
  22230. function nextNthOnYear(value, nth) {
  22231. return nextNthPerNmonth(value, nth, 12);
  22232. }
  22233. function getNewDate(value) {
  22234. return value instanceof Date ? value : new Date(typeof value == 'string' ? value.replace(/-/g, '/') : value);
  22235. }
  22236. return {
  22237. getAutoFormatter: getAutoFormatter,
  22238. getNewDate: getNewDate,
  22239. format: format,
  22240. nextMonday: nextMonday,
  22241. nextNthPerNmonth: nextNthPerNmonth,
  22242. nextNthOnMonth: nextNthOnMonth,
  22243. nextNthOnQuarterYear: nextNthOnQuarterYear,
  22244. nextNthOnHalfYear: nextNthOnHalfYear,
  22245. nextNthOnYear: nextNthOnYear
  22246. };
  22247. });define('echarts/util/smartSteps', [], function () {
  22248. var mySteps = [
  22249. 10,
  22250. 20,
  22251. 25,
  22252. 50
  22253. ];
  22254. var mySections = [
  22255. 4,
  22256. 5,
  22257. 6
  22258. ];
  22259. var custOpts;
  22260. var custSteps;
  22261. var custSecs;
  22262. var minLocked;
  22263. var maxLocked;
  22264. var MT = Math;
  22265. var MATH_ROUND = MT.round;
  22266. var MATH_FLOOR = MT.floor;
  22267. var MATH_CEIL = MT.ceil;
  22268. var MATH_ABS = MT.abs;
  22269. function MATH_LOG(n) {
  22270. return MT.log(MATH_ABS(n)) / MT.LN10;
  22271. }
  22272. function MATH_POW(n) {
  22273. return MT.pow(10, n);
  22274. }
  22275. function MATH_ISINT(n) {
  22276. return n === MATH_FLOOR(n);
  22277. }
  22278. function smartSteps(min, max, section, opts) {
  22279. custOpts = opts || {};
  22280. custSteps = custOpts.steps || mySteps;
  22281. custSecs = custOpts.secs || mySections;
  22282. section = MATH_ROUND(+section || 0) % 99;
  22283. min = +min || 0;
  22284. max = +max || 0;
  22285. minLocked = maxLocked = 0;
  22286. if ('min' in custOpts) {
  22287. min = +custOpts.min || 0;
  22288. minLocked = 1;
  22289. }
  22290. if ('max' in custOpts) {
  22291. max = +custOpts.max || 0;
  22292. maxLocked = 1;
  22293. }
  22294. if (min > max) {
  22295. max = [
  22296. min,
  22297. min = max
  22298. ][0];
  22299. }
  22300. var span = max - min;
  22301. if (minLocked && maxLocked) {
  22302. return bothLocked(min, max, section);
  22303. }
  22304. if (span < (section || 5)) {
  22305. if (MATH_ISINT(min) && MATH_ISINT(max)) {
  22306. return forInteger(min, max, section);
  22307. } else if (span === 0) {
  22308. return forSpan0(min, max, section);
  22309. }
  22310. }
  22311. return coreCalc(min, max, section);
  22312. }
  22313. function makeResult(newMin, newMax, section, expon) {
  22314. expon = expon || 0;
  22315. var expStep = expNum((newMax - newMin) / section, -1);
  22316. var expMin = expNum(newMin, -1, 1);
  22317. var expMax = expNum(newMax, -1);
  22318. var minExp = MT.min(expStep.e, expMin.e, expMax.e);
  22319. if (expMin.c === 0) {
  22320. minExp = MT.min(expStep.e, expMax.e);
  22321. } else if (expMax.c === 0) {
  22322. minExp = MT.min(expStep.e, expMin.e);
  22323. }
  22324. expFixTo(expStep, {
  22325. c: 0,
  22326. e: minExp
  22327. });
  22328. expFixTo(expMin, expStep, 1);
  22329. expFixTo(expMax, expStep);
  22330. expon += minExp;
  22331. newMin = expMin.c;
  22332. newMax = expMax.c;
  22333. var step = (newMax - newMin) / section;
  22334. var zoom = MATH_POW(expon);
  22335. var fixTo = 0;
  22336. var points = [];
  22337. for (var i = section + 1; i--;) {
  22338. points[i] = (newMin + step * i) * zoom;
  22339. }
  22340. if (expon < 0) {
  22341. fixTo = decimals(zoom);
  22342. step = +(step * zoom).toFixed(fixTo);
  22343. newMin = +(newMin * zoom).toFixed(fixTo);
  22344. newMax = +(newMax * zoom).toFixed(fixTo);
  22345. for (var i = points.length; i--;) {
  22346. points[i] = points[i].toFixed(fixTo);
  22347. +points[i] === 0 && (points[i] = '0');
  22348. }
  22349. } else {
  22350. newMin *= zoom;
  22351. newMax *= zoom;
  22352. step *= zoom;
  22353. }
  22354. custSecs = 0;
  22355. custSteps = 0;
  22356. custOpts = 0;
  22357. return {
  22358. min: newMin,
  22359. max: newMax,
  22360. secs: section,
  22361. step: step,
  22362. fix: fixTo,
  22363. exp: expon,
  22364. pnts: points
  22365. };
  22366. }
  22367. function expNum(num, digit, byFloor) {
  22368. digit = MATH_ROUND(digit % 10) || 2;
  22369. if (digit < 0) {
  22370. if (MATH_ISINT(num)) {
  22371. digit = ('' + MATH_ABS(num)).replace(/0+$/, '').length || 1;
  22372. } else {
  22373. num = num.toFixed(15).replace(/0+$/, '');
  22374. digit = num.replace('.', '').replace(/^[-0]+/, '').length;
  22375. num = +num;
  22376. }
  22377. }
  22378. var expon = MATH_FLOOR(MATH_LOG(num)) - digit + 1;
  22379. var cNum = +(num * MATH_POW(-expon)).toFixed(15) || 0;
  22380. cNum = byFloor ? MATH_FLOOR(cNum) : MATH_CEIL(cNum);
  22381. !cNum && (expon = 0);
  22382. if (('' + MATH_ABS(cNum)).length > digit) {
  22383. expon += 1;
  22384. cNum /= 10;
  22385. }
  22386. return {
  22387. c: cNum,
  22388. e: expon
  22389. };
  22390. }
  22391. function expFixTo(expnum1, expnum2, byFloor) {
  22392. var deltaExp = expnum2.e - expnum1.e;
  22393. if (deltaExp) {
  22394. expnum1.e += deltaExp;
  22395. expnum1.c *= MATH_POW(-deltaExp);
  22396. expnum1.c = byFloor ? MATH_FLOOR(expnum1.c) : MATH_CEIL(expnum1.c);
  22397. }
  22398. }
  22399. function expFixMin(expnum1, expnum2, byFloor) {
  22400. if (expnum1.e < expnum2.e) {
  22401. expFixTo(expnum2, expnum1, byFloor);
  22402. } else {
  22403. expFixTo(expnum1, expnum2, byFloor);
  22404. }
  22405. }
  22406. function getCeil(num, rounds) {
  22407. rounds = rounds || mySteps;
  22408. num = expNum(num);
  22409. var cNum = num.c;
  22410. var i = 0;
  22411. while (cNum > rounds[i]) {
  22412. i++;
  22413. }
  22414. if (!rounds[i]) {
  22415. cNum /= 10;
  22416. num.e += 1;
  22417. i = 0;
  22418. while (cNum > rounds[i]) {
  22419. i++;
  22420. }
  22421. }
  22422. num.c = rounds[i];
  22423. return num;
  22424. }
  22425. function coreCalc(min, max, section) {
  22426. var step;
  22427. var secs = section || +custSecs.slice(-1);
  22428. var expStep = getCeil((max - min) / secs, custSteps);
  22429. var expSpan = expNum(max - min);
  22430. var expMin = expNum(min, -1, 1);
  22431. var expMax = expNum(max, -1);
  22432. expFixTo(expSpan, expStep);
  22433. expFixTo(expMin, expStep, 1);
  22434. expFixTo(expMax, expStep);
  22435. if (!section) {
  22436. secs = look4sections(expMin, expMax);
  22437. } else {
  22438. step = look4step(expMin, expMax, secs);
  22439. }
  22440. if (MATH_ISINT(min) && MATH_ISINT(max) && min * max >= 0) {
  22441. if (max - min < secs) {
  22442. return forInteger(min, max, secs);
  22443. }
  22444. secs = tryForInt(min, max, section, expMin, expMax, secs);
  22445. }
  22446. var arrMM = cross0(min, max, expMin.c, expMax.c);
  22447. expMin.c = arrMM[0];
  22448. expMax.c = arrMM[1];
  22449. if (minLocked || maxLocked) {
  22450. singleLocked(min, max, expMin, expMax);
  22451. }
  22452. return makeResult(expMin.c, expMax.c, secs, expMax.e);
  22453. }
  22454. function look4sections(expMin, expMax) {
  22455. var section;
  22456. var tmpStep, tmpMin, tmpMax;
  22457. var reference = [];
  22458. for (var i = custSecs.length; i--;) {
  22459. section = custSecs[i];
  22460. tmpStep = getCeil((expMax.c - expMin.c) / section, custSteps);
  22461. tmpStep = tmpStep.c * MATH_POW(tmpStep.e);
  22462. tmpMin = MATH_FLOOR(expMin.c / tmpStep) * tmpStep;
  22463. tmpMax = MATH_CEIL(expMax.c / tmpStep) * tmpStep;
  22464. reference[i] = {
  22465. min: tmpMin,
  22466. max: tmpMax,
  22467. step: tmpStep,
  22468. span: tmpMax - tmpMin
  22469. };
  22470. }
  22471. reference.sort(function (a, b) {
  22472. var delta = a.span - b.span;
  22473. if (delta === 0) {
  22474. delta = a.step - b.step;
  22475. }
  22476. return delta;
  22477. });
  22478. reference = reference[0];
  22479. section = reference.span / reference.step;
  22480. expMin.c = reference.min;
  22481. expMax.c = reference.max;
  22482. return section < 3 ? section * 2 : section;
  22483. }
  22484. function look4step(expMin, expMax, secs) {
  22485. var span;
  22486. var tmpMax;
  22487. var tmpMin = expMax.c;
  22488. var tmpStep = (expMax.c - expMin.c) / secs - 1;
  22489. while (tmpMin > expMin.c) {
  22490. tmpStep = getCeil(tmpStep + 1, custSteps);
  22491. tmpStep = tmpStep.c * MATH_POW(tmpStep.e);
  22492. span = tmpStep * secs;
  22493. tmpMax = MATH_CEIL(expMax.c / tmpStep) * tmpStep;
  22494. tmpMin = tmpMax - span;
  22495. }
  22496. var deltaMin = expMin.c - tmpMin;
  22497. var deltaMax = tmpMax - expMax.c;
  22498. var deltaDelta = deltaMin - deltaMax;
  22499. if (deltaDelta > tmpStep * 1.1) {
  22500. deltaDelta = MATH_ROUND(deltaDelta / tmpStep / 2) * tmpStep;
  22501. tmpMin += deltaDelta;
  22502. tmpMax += deltaDelta;
  22503. }
  22504. expMin.c = tmpMin;
  22505. expMax.c = tmpMax;
  22506. return tmpStep;
  22507. }
  22508. function tryForInt(min, max, section, expMin, expMax, secs) {
  22509. var span = expMax.c - expMin.c;
  22510. var step = span / secs * MATH_POW(expMax.e);
  22511. if (!MATH_ISINT(step)) {
  22512. step = MATH_FLOOR(step);
  22513. span = step * secs;
  22514. if (span < max - min) {
  22515. step += 1;
  22516. span = step * secs;
  22517. if (!section && step * (secs - 1) >= max - min) {
  22518. secs -= 1;
  22519. span = step * secs;
  22520. }
  22521. }
  22522. if (span >= max - min) {
  22523. var delta = span - (max - min);
  22524. expMin.c = MATH_ROUND(min - delta / 2);
  22525. expMax.c = MATH_ROUND(max + delta / 2);
  22526. expMin.e = 0;
  22527. expMax.e = 0;
  22528. }
  22529. }
  22530. return secs;
  22531. }
  22532. function forInteger(min, max, section) {
  22533. section = section || 5;
  22534. if (minLocked) {
  22535. max = min + section;
  22536. } else if (maxLocked) {
  22537. min = max - section;
  22538. } else {
  22539. var delta = section - (max - min);
  22540. var newMin = MATH_ROUND(min - delta / 2);
  22541. var newMax = MATH_ROUND(max + delta / 2);
  22542. var arrMM = cross0(min, max, newMin, newMax);
  22543. min = arrMM[0];
  22544. max = arrMM[1];
  22545. }
  22546. return makeResult(min, max, section);
  22547. }
  22548. function forSpan0(min, max, section) {
  22549. section = section || 5;
  22550. var delta = MT.min(MATH_ABS(max / section), section) / 2.1;
  22551. if (minLocked) {
  22552. max = min + delta;
  22553. } else if (maxLocked) {
  22554. min = max - delta;
  22555. } else {
  22556. min = min - delta;
  22557. max = max + delta;
  22558. }
  22559. return coreCalc(min, max, section);
  22560. }
  22561. function cross0(min, max, newMin, newMax) {
  22562. if (min >= 0 && newMin < 0) {
  22563. newMax -= newMin;
  22564. newMin = 0;
  22565. } else if (max <= 0 && newMax > 0) {
  22566. newMin -= newMax;
  22567. newMax = 0;
  22568. }
  22569. return [
  22570. newMin,
  22571. newMax
  22572. ];
  22573. }
  22574. function decimals(num) {
  22575. num = (+num).toFixed(15).split('.');
  22576. return num.pop().replace(/0+$/, '').length;
  22577. }
  22578. function singleLocked(min, max, emin, emax) {
  22579. if (minLocked) {
  22580. var expMin = expNum(min, 4, 1);
  22581. if (emin.e - expMin.e > 6) {
  22582. expMin = {
  22583. c: 0,
  22584. e: emin.e
  22585. };
  22586. }
  22587. expFixMin(emin, expMin);
  22588. expFixMin(emax, expMin);
  22589. emax.c += expMin.c - emin.c;
  22590. emin.c = expMin.c;
  22591. } else if (maxLocked) {
  22592. var expMax = expNum(max, 4);
  22593. if (emax.e - expMax.e > 6) {
  22594. expMax = {
  22595. c: 0,
  22596. e: emax.e
  22597. };
  22598. }
  22599. expFixMin(emin, expMax);
  22600. expFixMin(emax, expMax);
  22601. emin.c += expMax.c - emax.c;
  22602. emax.c = expMax.c;
  22603. }
  22604. }
  22605. function bothLocked(min, max, section) {
  22606. var trySecs = section ? [section] : custSecs;
  22607. var span = max - min;
  22608. if (span === 0) {
  22609. max = expNum(max, 3);
  22610. section = trySecs[0];
  22611. max.c = MATH_ROUND(max.c + section / 2);
  22612. return makeResult(max.c - section, max.c, section, max.e);
  22613. }
  22614. if (MATH_ABS(max / span) < 0.000001) {
  22615. max = 0;
  22616. }
  22617. if (MATH_ABS(min / span) < 0.000001) {
  22618. min = 0;
  22619. }
  22620. var step, deltaSpan, score;
  22621. var scoreS = [
  22622. [
  22623. 5,
  22624. 10
  22625. ],
  22626. [
  22627. 10,
  22628. 2
  22629. ],
  22630. [
  22631. 50,
  22632. 10
  22633. ],
  22634. [
  22635. 100,
  22636. 2
  22637. ]
  22638. ];
  22639. var reference = [];
  22640. var debugLog = [];
  22641. var expSpan = expNum(max - min, 3);
  22642. var expMin = expNum(min, -1, 1);
  22643. var expMax = expNum(max, -1);
  22644. expFixTo(expMin, expSpan, 1);
  22645. expFixTo(expMax, expSpan);
  22646. span = expMax.c - expMin.c;
  22647. expSpan.c = span;
  22648. for (var i = trySecs.length; i--;) {
  22649. section = trySecs[i];
  22650. step = MATH_CEIL(span / section);
  22651. deltaSpan = step * section - span;
  22652. score = (deltaSpan + 3) * 3;
  22653. score += (section - trySecs[0] + 2) * 2;
  22654. if (section % 5 === 0) {
  22655. score -= 10;
  22656. }
  22657. for (var j = scoreS.length; j--;) {
  22658. if (step % scoreS[j][0] === 0) {
  22659. score /= scoreS[j][1];
  22660. }
  22661. }
  22662. debugLog[i] = [
  22663. section,
  22664. step,
  22665. deltaSpan,
  22666. score
  22667. ].join();
  22668. reference[i] = {
  22669. secs: section,
  22670. step: step,
  22671. delta: deltaSpan,
  22672. score: score
  22673. };
  22674. }
  22675. reference.sort(function (a, b) {
  22676. return a.score - b.score;
  22677. });
  22678. reference = reference[0];
  22679. expMin.c = MATH_ROUND(expMin.c - reference.delta / 2);
  22680. expMax.c = MATH_ROUND(expMax.c + reference.delta / 2);
  22681. return makeResult(expMin.c, expMax.c, reference.secs, expSpan.e);
  22682. }
  22683. return smartSteps;
  22684. });