echarts.common.js 1.3 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory();
  4. else if(typeof define === 'function' && define.amd)
  5. define([], factory);
  6. else if(typeof exports === 'object')
  7. exports["echarts"] = factory();
  8. else
  9. root["echarts"] = factory();
  10. })(this, function() {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/ // The require function
  15. /******/ function __webpack_require__(moduleId) {
  16. /******/ // Check if module is in cache
  17. /******/ if(installedModules[moduleId])
  18. /******/ return installedModules[moduleId].exports;
  19. /******/ // Create a new module (and put it into the cache)
  20. /******/ var module = installedModules[moduleId] = {
  21. /******/ exports: {},
  22. /******/ id: moduleId,
  23. /******/ loaded: false
  24. /******/ };
  25. /******/ // Execute the module function
  26. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  27. /******/ // Flag the module as loaded
  28. /******/ module.loaded = true;
  29. /******/ // Return the exports of the module
  30. /******/ return module.exports;
  31. /******/ }
  32. /******/ // expose the modules object (__webpack_modules__)
  33. /******/ __webpack_require__.m = modules;
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/ // __webpack_public_path__
  37. /******/ __webpack_require__.p = "";
  38. /******/ // Load entry module and return exports
  39. /******/ return __webpack_require__(0);
  40. /******/ })
  41. /************************************************************************/
  42. /******/ ([
  43. /* 0 */
  44. /***/ function(module, exports, __webpack_require__) {
  45. /**
  46. * Export echarts as CommonJS module
  47. */
  48. module.exports = __webpack_require__(1);
  49. __webpack_require__(100);
  50. __webpack_require__(134);
  51. __webpack_require__(141);
  52. __webpack_require__(150);
  53. __webpack_require__(292);
  54. __webpack_require__(299);
  55. __webpack_require__(293);
  56. __webpack_require__(113);
  57. __webpack_require__(328);
  58. __webpack_require__(358);
  59. __webpack_require__(364);
  60. __webpack_require__(367);
  61. __webpack_require__(329);
  62. __webpack_require__(379);
  63. __webpack_require__(391);
  64. /***/ },
  65. /* 1 */
  66. /***/ function(module, exports, __webpack_require__) {
  67. // Enable DEV mode when using source code without build. which has no __DEV__ variable
  68. // In build process 'typeof __DEV__' will be replace with 'boolean'
  69. // So this code will be removed or disabled anyway after built.
  70. if (false) {
  71. // In browser
  72. if (typeof window !== 'undefined') {
  73. window.__DEV__ = true;
  74. }
  75. // In node
  76. else if (typeof global !== 'undefined') {
  77. global.__DEV__ = true;
  78. }
  79. }
  80. /*!
  81. * ECharts, a javascript interactive chart library.
  82. *
  83. * Copyright (c) 2015, Baidu Inc.
  84. * All rights reserved.
  85. *
  86. * LICENSE
  87. * https://github.com/ecomfe/echarts/blob/master/LICENSE.txt
  88. */
  89. /**
  90. * @module echarts
  91. */
  92. var env = __webpack_require__(2);
  93. var GlobalModel = __webpack_require__(3);
  94. var ExtensionAPI = __webpack_require__(25);
  95. var CoordinateSystemManager = __webpack_require__(26);
  96. var OptionManager = __webpack_require__(27);
  97. var ComponentModel = __webpack_require__(19);
  98. var SeriesModel = __webpack_require__(28);
  99. var ComponentView = __webpack_require__(29);
  100. var ChartView = __webpack_require__(42);
  101. var graphic = __webpack_require__(43);
  102. var modelUtil = __webpack_require__(5);
  103. var throttle = __webpack_require__(81);
  104. var zrender = __webpack_require__(82);
  105. var zrUtil = __webpack_require__(4);
  106. var colorTool = __webpack_require__(39);
  107. var Eventful = __webpack_require__(33);
  108. var timsort = __webpack_require__(86);
  109. var each = zrUtil.each;
  110. var parseClassType = ComponentModel.parseClassType;
  111. var PRIORITY_PROCESSOR_FILTER = 1000;
  112. var PRIORITY_PROCESSOR_STATISTIC = 5000;
  113. var PRIORITY_VISUAL_LAYOUT = 1000;
  114. var PRIORITY_VISUAL_GLOBAL = 2000;
  115. var PRIORITY_VISUAL_CHART = 3000;
  116. var PRIORITY_VISUAL_COMPONENT = 4000;
  117. // FIXME
  118. // necessary?
  119. var PRIORITY_VISUAL_BRUSH = 5000;
  120. // Main process have three entries: `setOption`, `dispatchAction` and `resize`,
  121. // where they must not be invoked nestedly, except the only case: invoke
  122. // dispatchAction with updateMethod "none" in main process.
  123. // This flag is used to carry out this rule.
  124. // All events will be triggered out side main process (i.e. when !this[IN_MAIN_PROCESS]).
  125. var IN_MAIN_PROCESS = '__flagInMainProcess';
  126. var HAS_GRADIENT_OR_PATTERN_BG = '__hasGradientOrPatternBg';
  127. var OPTION_UPDATED = '__optionUpdated';
  128. var ACTION_REG = /^[a-zA-Z0-9_]+$/;
  129. function createRegisterEventWithLowercaseName(method) {
  130. return function (eventName, handler, context) {
  131. // Event name is all lowercase
  132. eventName = eventName && eventName.toLowerCase();
  133. Eventful.prototype[method].call(this, eventName, handler, context);
  134. };
  135. }
  136. /**
  137. * @module echarts~MessageCenter
  138. */
  139. function MessageCenter() {
  140. Eventful.call(this);
  141. }
  142. MessageCenter.prototype.on = createRegisterEventWithLowercaseName('on');
  143. MessageCenter.prototype.off = createRegisterEventWithLowercaseName('off');
  144. MessageCenter.prototype.one = createRegisterEventWithLowercaseName('one');
  145. zrUtil.mixin(MessageCenter, Eventful);
  146. /**
  147. * @module echarts~ECharts
  148. */
  149. function ECharts (dom, theme, opts) {
  150. opts = opts || {};
  151. // Get theme by name
  152. if (typeof theme === 'string') {
  153. theme = themeStorage[theme];
  154. }
  155. /**
  156. * @type {string}
  157. */
  158. this.id;
  159. /**
  160. * Group id
  161. * @type {string}
  162. */
  163. this.group;
  164. /**
  165. * @type {HTMLDomElement}
  166. * @private
  167. */
  168. this._dom = dom;
  169. /**
  170. * @type {module:zrender/ZRender}
  171. * @private
  172. */
  173. var zr = this._zr = zrender.init(dom, {
  174. renderer: opts.renderer || 'canvas',
  175. devicePixelRatio: opts.devicePixelRatio,
  176. width: opts.width,
  177. height: opts.height
  178. });
  179. /**
  180. * Expect 60 pfs.
  181. * @type {Function}
  182. * @private
  183. */
  184. this._throttledZrFlush = throttle.throttle(zrUtil.bind(zr.flush, zr), 17);
  185. /**
  186. * @type {Object}
  187. * @private
  188. */
  189. this._theme = zrUtil.clone(theme);
  190. /**
  191. * @type {Array.<module:echarts/view/Chart>}
  192. * @private
  193. */
  194. this._chartsViews = [];
  195. /**
  196. * @type {Object.<string, module:echarts/view/Chart>}
  197. * @private
  198. */
  199. this._chartsMap = {};
  200. /**
  201. * @type {Array.<module:echarts/view/Component>}
  202. * @private
  203. */
  204. this._componentsViews = [];
  205. /**
  206. * @type {Object.<string, module:echarts/view/Component>}
  207. * @private
  208. */
  209. this._componentsMap = {};
  210. /**
  211. * @type {module:echarts/ExtensionAPI}
  212. * @private
  213. */
  214. this._api = new ExtensionAPI(this);
  215. /**
  216. * @type {module:echarts/CoordinateSystem}
  217. * @private
  218. */
  219. this._coordSysMgr = new CoordinateSystemManager();
  220. Eventful.call(this);
  221. /**
  222. * @type {module:echarts~MessageCenter}
  223. * @private
  224. */
  225. this._messageCenter = new MessageCenter();
  226. // Init mouse events
  227. this._initEvents();
  228. // In case some people write `window.onresize = chart.resize`
  229. this.resize = zrUtil.bind(this.resize, this);
  230. // Can't dispatch action during rendering procedure
  231. this._pendingActions = [];
  232. // Sort on demand
  233. function prioritySortFunc(a, b) {
  234. return a.prio - b.prio;
  235. }
  236. timsort(visualFuncs, prioritySortFunc);
  237. timsort(dataProcessorFuncs, prioritySortFunc);
  238. zr.animation.on('frame', this._onframe, this);
  239. }
  240. var echartsProto = ECharts.prototype;
  241. echartsProto._onframe = function () {
  242. // Lazy update
  243. if (this[OPTION_UPDATED]) {
  244. var silent = this[OPTION_UPDATED].silent;
  245. this[IN_MAIN_PROCESS] = true;
  246. updateMethods.prepareAndUpdate.call(this);
  247. this[IN_MAIN_PROCESS] = false;
  248. this[OPTION_UPDATED] = false;
  249. flushPendingActions.call(this, silent);
  250. triggerUpdatedEvent.call(this, silent);
  251. }
  252. };
  253. /**
  254. * @return {HTMLDomElement}
  255. */
  256. echartsProto.getDom = function () {
  257. return this._dom;
  258. };
  259. /**
  260. * @return {module:zrender~ZRender}
  261. */
  262. echartsProto.getZr = function () {
  263. return this._zr;
  264. };
  265. /**
  266. * Usage:
  267. * chart.setOption(option, notMerge, lazyUpdate);
  268. * chart.setOption(option, {
  269. * notMerge: ...,
  270. * lazyUpdate: ...,
  271. * silent: ...
  272. * });
  273. *
  274. * @param {Object} option
  275. * @param {Object|boolean} [opts] opts or notMerge.
  276. * @param {boolean} [opts.notMerge=false]
  277. * @param {boolean} [opts.lazyUpdate=false] Useful when setOption frequently.
  278. */
  279. echartsProto.setOption = function (option, notMerge, lazyUpdate) {
  280. if (true) {
  281. zrUtil.assert(!this[IN_MAIN_PROCESS], '`setOption` should not be called during main process.');
  282. }
  283. var silent;
  284. if (zrUtil.isObject(notMerge)) {
  285. lazyUpdate = notMerge.lazyUpdate;
  286. silent = notMerge.silent;
  287. notMerge = notMerge.notMerge;
  288. }
  289. this[IN_MAIN_PROCESS] = true;
  290. if (!this._model || notMerge) {
  291. var optionManager = new OptionManager(this._api);
  292. var theme = this._theme;
  293. var ecModel = this._model = new GlobalModel(null, null, theme, optionManager);
  294. ecModel.init(null, null, theme, optionManager);
  295. }
  296. // FIXME
  297. // ugly
  298. this.__lastOnlyGraphic = !!(option && option.graphic);
  299. zrUtil.each(option, function (o, mainType) {
  300. mainType !== 'graphic' && (this.__lastOnlyGraphic = false);
  301. }, this);
  302. this._model.setOption(option, optionPreprocessorFuncs);
  303. if (lazyUpdate) {
  304. this[OPTION_UPDATED] = {silent: silent};
  305. this[IN_MAIN_PROCESS] = false;
  306. }
  307. else {
  308. updateMethods.prepareAndUpdate.call(this);
  309. // Ensure zr refresh sychronously, and then pixel in canvas can be
  310. // fetched after `setOption`.
  311. this._zr.flush();
  312. this[OPTION_UPDATED] = false;
  313. this[IN_MAIN_PROCESS] = false;
  314. flushPendingActions.call(this, silent);
  315. triggerUpdatedEvent.call(this, silent);
  316. }
  317. };
  318. /**
  319. * @DEPRECATED
  320. */
  321. echartsProto.setTheme = function () {
  322. console.log('ECharts#setTheme() is DEPRECATED in ECharts 3.0');
  323. };
  324. /**
  325. * @return {module:echarts/model/Global}
  326. */
  327. echartsProto.getModel = function () {
  328. return this._model;
  329. };
  330. /**
  331. * @return {Object}
  332. */
  333. echartsProto.getOption = function () {
  334. return this._model && this._model.getOption();
  335. };
  336. /**
  337. * @return {number}
  338. */
  339. echartsProto.getWidth = function () {
  340. return this._zr.getWidth();
  341. };
  342. /**
  343. * @return {number}
  344. */
  345. echartsProto.getHeight = function () {
  346. return this._zr.getHeight();
  347. };
  348. /**
  349. * Get canvas which has all thing rendered
  350. * @param {Object} opts
  351. * @param {string} [opts.backgroundColor]
  352. */
  353. echartsProto.getRenderedCanvas = function (opts) {
  354. if (!env.canvasSupported) {
  355. return;
  356. }
  357. opts = opts || {};
  358. opts.pixelRatio = opts.pixelRatio || 1;
  359. opts.backgroundColor = opts.backgroundColor
  360. || this._model.get('backgroundColor');
  361. var zr = this._zr;
  362. var list = zr.storage.getDisplayList();
  363. // Stop animations
  364. zrUtil.each(list, function (el) {
  365. el.stopAnimation(true);
  366. });
  367. return zr.painter.getRenderedCanvas(opts);
  368. };
  369. /**
  370. * @return {string}
  371. * @param {Object} opts
  372. * @param {string} [opts.type='png']
  373. * @param {string} [opts.pixelRatio=1]
  374. * @param {string} [opts.backgroundColor]
  375. * @param {string} [opts.excludeComponents]
  376. */
  377. echartsProto.getDataURL = function (opts) {
  378. opts = opts || {};
  379. var excludeComponents = opts.excludeComponents;
  380. var ecModel = this._model;
  381. var excludesComponentViews = [];
  382. var self = this;
  383. each(excludeComponents, function (componentType) {
  384. ecModel.eachComponent({
  385. mainType: componentType
  386. }, function (component) {
  387. var view = self._componentsMap[component.__viewId];
  388. if (!view.group.ignore) {
  389. excludesComponentViews.push(view);
  390. view.group.ignore = true;
  391. }
  392. });
  393. });
  394. var url = this.getRenderedCanvas(opts).toDataURL(
  395. 'image/' + (opts && opts.type || 'png')
  396. );
  397. each(excludesComponentViews, function (view) {
  398. view.group.ignore = false;
  399. });
  400. return url;
  401. };
  402. /**
  403. * @return {string}
  404. * @param {Object} opts
  405. * @param {string} [opts.type='png']
  406. * @param {string} [opts.pixelRatio=1]
  407. * @param {string} [opts.backgroundColor]
  408. */
  409. echartsProto.getConnectedDataURL = function (opts) {
  410. if (!env.canvasSupported) {
  411. return;
  412. }
  413. var groupId = this.group;
  414. var mathMin = Math.min;
  415. var mathMax = Math.max;
  416. var MAX_NUMBER = Infinity;
  417. if (connectedGroups[groupId]) {
  418. var left = MAX_NUMBER;
  419. var top = MAX_NUMBER;
  420. var right = -MAX_NUMBER;
  421. var bottom = -MAX_NUMBER;
  422. var canvasList = [];
  423. var dpr = (opts && opts.pixelRatio) || 1;
  424. zrUtil.each(instances, function (chart, id) {
  425. if (chart.group === groupId) {
  426. var canvas = chart.getRenderedCanvas(
  427. zrUtil.clone(opts)
  428. );
  429. var boundingRect = chart.getDom().getBoundingClientRect();
  430. left = mathMin(boundingRect.left, left);
  431. top = mathMin(boundingRect.top, top);
  432. right = mathMax(boundingRect.right, right);
  433. bottom = mathMax(boundingRect.bottom, bottom);
  434. canvasList.push({
  435. dom: canvas,
  436. left: boundingRect.left,
  437. top: boundingRect.top
  438. });
  439. }
  440. });
  441. left *= dpr;
  442. top *= dpr;
  443. right *= dpr;
  444. bottom *= dpr;
  445. var width = right - left;
  446. var height = bottom - top;
  447. var targetCanvas = zrUtil.createCanvas();
  448. targetCanvas.width = width;
  449. targetCanvas.height = height;
  450. var zr = zrender.init(targetCanvas);
  451. each(canvasList, function (item) {
  452. var img = new graphic.Image({
  453. style: {
  454. x: item.left * dpr - left,
  455. y: item.top * dpr - top,
  456. image: item.dom
  457. }
  458. });
  459. zr.add(img);
  460. });
  461. zr.refreshImmediately();
  462. return targetCanvas.toDataURL('image/' + (opts && opts.type || 'png'));
  463. }
  464. else {
  465. return this.getDataURL(opts);
  466. }
  467. };
  468. /**
  469. * Convert from logical coordinate system to pixel coordinate system.
  470. * See CoordinateSystem#convertToPixel.
  471. * @param {string|Object} finder
  472. * If string, e.g., 'geo', means {geoIndex: 0}.
  473. * If Object, could contain some of these properties below:
  474. * {
  475. * seriesIndex / seriesId / seriesName,
  476. * geoIndex / geoId, geoName,
  477. * bmapIndex / bmapId / bmapName,
  478. * xAxisIndex / xAxisId / xAxisName,
  479. * yAxisIndex / yAxisId / yAxisName,
  480. * gridIndex / gridId / gridName,
  481. * ... (can be extended)
  482. * }
  483. * @param {Array|number} value
  484. * @return {Array|number} result
  485. */
  486. echartsProto.convertToPixel = zrUtil.curry(doConvertPixel, 'convertToPixel');
  487. /**
  488. * Convert from pixel coordinate system to logical coordinate system.
  489. * See CoordinateSystem#convertFromPixel.
  490. * @param {string|Object} finder
  491. * If string, e.g., 'geo', means {geoIndex: 0}.
  492. * If Object, could contain some of these properties below:
  493. * {
  494. * seriesIndex / seriesId / seriesName,
  495. * geoIndex / geoId / geoName,
  496. * bmapIndex / bmapId / bmapName,
  497. * xAxisIndex / xAxisId / xAxisName,
  498. * yAxisIndex / yAxisId / yAxisName
  499. * gridIndex / gridId / gridName,
  500. * ... (can be extended)
  501. * }
  502. * @param {Array|number} value
  503. * @return {Array|number} result
  504. */
  505. echartsProto.convertFromPixel = zrUtil.curry(doConvertPixel, 'convertFromPixel');
  506. function doConvertPixel(methodName, finder, value) {
  507. var ecModel = this._model;
  508. var coordSysList = this._coordSysMgr.getCoordinateSystems();
  509. var result;
  510. finder = modelUtil.parseFinder(ecModel, finder);
  511. for (var i = 0; i < coordSysList.length; i++) {
  512. var coordSys = coordSysList[i];
  513. if (coordSys[methodName]
  514. && (result = coordSys[methodName](ecModel, finder, value)) != null
  515. ) {
  516. return result;
  517. }
  518. }
  519. if (true) {
  520. console.warn(
  521. 'No coordinate system that supports ' + methodName + ' found by the given finder.'
  522. );
  523. }
  524. }
  525. /**
  526. * Is the specified coordinate systems or components contain the given pixel point.
  527. * @param {string|Object} finder
  528. * If string, e.g., 'geo', means {geoIndex: 0}.
  529. * If Object, could contain some of these properties below:
  530. * {
  531. * seriesIndex / seriesId / seriesName,
  532. * geoIndex / geoId / geoName,
  533. * bmapIndex / bmapId / bmapName,
  534. * xAxisIndex / xAxisId / xAxisName,
  535. * yAxisIndex / yAxisId / yAxisName
  536. * gridIndex / gridId / gridName,
  537. * ... (can be extended)
  538. * }
  539. * @param {Array|number} value
  540. * @return {boolean} result
  541. */
  542. echartsProto.containPixel = function (finder, value) {
  543. var ecModel = this._model;
  544. var result;
  545. finder = modelUtil.parseFinder(ecModel, finder);
  546. zrUtil.each(finder, function (models, key) {
  547. key.indexOf('Models') >= 0 && zrUtil.each(models, function (model) {
  548. var coordSys = model.coordinateSystem;
  549. if (coordSys && coordSys.containPoint) {
  550. result |= !!coordSys.containPoint(value);
  551. }
  552. else if (key === 'seriesModels') {
  553. var view = this._chartsMap[model.__viewId];
  554. if (view && view.containPoint) {
  555. result |= view.containPoint(value, model);
  556. }
  557. else {
  558. if (true) {
  559. console.warn(key + ': ' + (view
  560. ? 'The found component do not support containPoint.'
  561. : 'No view mapping to the found component.'
  562. ));
  563. }
  564. }
  565. }
  566. else {
  567. if (true) {
  568. console.warn(key + ': containPoint is not supported');
  569. }
  570. }
  571. }, this);
  572. }, this);
  573. return !!result;
  574. };
  575. /**
  576. * Get visual from series or data.
  577. * @param {string|Object} finder
  578. * If string, e.g., 'series', means {seriesIndex: 0}.
  579. * If Object, could contain some of these properties below:
  580. * {
  581. * seriesIndex / seriesId / seriesName,
  582. * dataIndex / dataIndexInside
  583. * }
  584. * If dataIndex is not specified, series visual will be fetched,
  585. * but not data item visual.
  586. * If all of seriesIndex, seriesId, seriesName are not specified,
  587. * visual will be fetched from first series.
  588. * @param {string} visualType 'color', 'symbol', 'symbolSize'
  589. */
  590. echartsProto.getVisual = function (finder, visualType) {
  591. var ecModel = this._model;
  592. finder = modelUtil.parseFinder(ecModel, finder, {defaultMainType: 'series'});
  593. var seriesModel = finder.seriesModel;
  594. if (true) {
  595. if (!seriesModel) {
  596. console.warn('There is no specified seires model');
  597. }
  598. }
  599. var data = seriesModel.getData();
  600. var dataIndexInside = finder.hasOwnProperty('dataIndexInside')
  601. ? finder.dataIndexInside
  602. : finder.hasOwnProperty('dataIndex')
  603. ? data.indexOfRawIndex(finder.dataIndex)
  604. : null;
  605. return dataIndexInside != null
  606. ? data.getItemVisual(dataIndexInside, visualType)
  607. : data.getVisual(visualType);
  608. };
  609. var updateMethods = {
  610. /**
  611. * @param {Object} payload
  612. * @private
  613. */
  614. update: function (payload) {
  615. // console.time && console.time('update');
  616. var ecModel = this._model;
  617. var api = this._api;
  618. var coordSysMgr = this._coordSysMgr;
  619. var zr = this._zr;
  620. // update before setOption
  621. if (!ecModel) {
  622. return;
  623. }
  624. // Fixme First time update ?
  625. ecModel.restoreData();
  626. // TODO
  627. // Save total ecModel here for undo/redo (after restoring data and before processing data).
  628. // Undo (restoration of total ecModel) can be carried out in 'action' or outside API call.
  629. // Create new coordinate system each update
  630. // In LineView may save the old coordinate system and use it to get the orignal point
  631. coordSysMgr.create(this._model, this._api);
  632. processData.call(this, ecModel, api);
  633. stackSeriesData.call(this, ecModel);
  634. coordSysMgr.update(ecModel, api);
  635. doVisualEncoding.call(this, ecModel, payload);
  636. doRender.call(this, ecModel, payload);
  637. // Set background
  638. var backgroundColor = ecModel.get('backgroundColor') || 'transparent';
  639. var painter = zr.painter;
  640. // TODO all use clearColor ?
  641. if (painter.isSingleCanvas && painter.isSingleCanvas()) {
  642. zr.configLayer(0, {
  643. clearColor: backgroundColor
  644. });
  645. }
  646. else {
  647. // In IE8
  648. if (!env.canvasSupported) {
  649. var colorArr = colorTool.parse(backgroundColor);
  650. backgroundColor = colorTool.stringify(colorArr, 'rgb');
  651. if (colorArr[3] === 0) {
  652. backgroundColor = 'transparent';
  653. }
  654. }
  655. if (backgroundColor.colorStops || backgroundColor.image) {
  656. // Gradient background
  657. // FIXME Fixed layer?
  658. zr.configLayer(0, {
  659. clearColor: backgroundColor
  660. });
  661. this[HAS_GRADIENT_OR_PATTERN_BG] = true;
  662. this._dom.style.background = 'transparent';
  663. }
  664. else {
  665. if (this[HAS_GRADIENT_OR_PATTERN_BG]) {
  666. zr.configLayer(0, {
  667. clearColor: null
  668. });
  669. }
  670. this[HAS_GRADIENT_OR_PATTERN_BG] = false;
  671. this._dom.style.background = backgroundColor;
  672. }
  673. }
  674. // console.time && console.timeEnd('update');
  675. },
  676. /**
  677. * @param {Object} payload
  678. * @private
  679. */
  680. updateView: function (payload) {
  681. var ecModel = this._model;
  682. // update before setOption
  683. if (!ecModel) {
  684. return;
  685. }
  686. ecModel.eachSeries(function (seriesModel) {
  687. seriesModel.getData().clearAllVisual();
  688. });
  689. doVisualEncoding.call(this, ecModel, payload);
  690. invokeUpdateMethod.call(this, 'updateView', ecModel, payload);
  691. },
  692. /**
  693. * @param {Object} payload
  694. * @private
  695. */
  696. updateVisual: function (payload) {
  697. var ecModel = this._model;
  698. // update before setOption
  699. if (!ecModel) {
  700. return;
  701. }
  702. ecModel.eachSeries(function (seriesModel) {
  703. seriesModel.getData().clearAllVisual();
  704. });
  705. doVisualEncoding.call(this, ecModel, payload, true);
  706. invokeUpdateMethod.call(this, 'updateVisual', ecModel, payload);
  707. },
  708. /**
  709. * @param {Object} payload
  710. * @private
  711. */
  712. updateLayout: function (payload) {
  713. var ecModel = this._model;
  714. // update before setOption
  715. if (!ecModel) {
  716. return;
  717. }
  718. doLayout.call(this, ecModel, payload);
  719. invokeUpdateMethod.call(this, 'updateLayout', ecModel, payload);
  720. },
  721. /**
  722. * @param {Object} payload
  723. * @private
  724. */
  725. prepareAndUpdate: function (payload) {
  726. var ecModel = this._model;
  727. prepareView.call(this, 'component', ecModel);
  728. prepareView.call(this, 'chart', ecModel);
  729. // FIXME
  730. // ugly
  731. if (this.__lastOnlyGraphic) {
  732. each(this._componentsViews, function (componentView) {
  733. var componentModel = componentView.__model;
  734. if (componentModel && componentModel.mainType === 'graphic') {
  735. componentView.render(componentModel, ecModel, this._api, payload);
  736. updateZ(componentModel, componentView);
  737. }
  738. }, this);
  739. this.__lastOnlyGraphic = false;
  740. }
  741. else {
  742. updateMethods.update.call(this, payload);
  743. }
  744. }
  745. };
  746. /**
  747. * @private
  748. */
  749. function updateDirectly(ecIns, method, payload, mainType, subType) {
  750. var ecModel = ecIns._model;
  751. var query = {};
  752. query[mainType + 'Id'] = payload[mainType + 'Id'];
  753. query[mainType + 'Index'] = payload[mainType + 'Index'];
  754. query[mainType + 'Name'] = payload[mainType + 'Name'];
  755. var condition = {mainType: mainType, query: query};
  756. subType && (condition.subType = subType); // subType may be '' by parseClassType;
  757. // If dispatchAction before setOption, do nothing.
  758. ecModel && ecModel.eachComponent(condition, function (model, index) {
  759. var view = ecIns[
  760. mainType === 'series' ? '_chartsMap' : '_componentsMap'
  761. ][model.__viewId];
  762. if (view && view.__alive) {
  763. view[method](model, ecModel, ecIns._api, payload);
  764. }
  765. }, ecIns);
  766. }
  767. /**
  768. * Resize the chart
  769. * @param {Object} opts
  770. * @param {number} [opts.width] Can be 'auto' (the same as null/undefined)
  771. * @param {number} [opts.height] Can be 'auto' (the same as null/undefined)
  772. * @param {boolean} [opts.silent=false]
  773. */
  774. echartsProto.resize = function (opts) {
  775. if (true) {
  776. zrUtil.assert(!this[IN_MAIN_PROCESS], '`resize` should not be called during main process.');
  777. }
  778. this[IN_MAIN_PROCESS] = true;
  779. this._zr.resize(opts);
  780. var optionChanged = this._model && this._model.resetOption('media');
  781. var updateMethod = optionChanged ? 'prepareAndUpdate' : 'update';
  782. updateMethods[updateMethod].call(this);
  783. // Resize loading effect
  784. this._loadingFX && this._loadingFX.resize();
  785. this[IN_MAIN_PROCESS] = false;
  786. var silent = opts && opts.silent;
  787. flushPendingActions.call(this, silent);
  788. triggerUpdatedEvent.call(this, silent);
  789. };
  790. /**
  791. * Show loading effect
  792. * @param {string} [name='default']
  793. * @param {Object} [cfg]
  794. */
  795. echartsProto.showLoading = function (name, cfg) {
  796. if (zrUtil.isObject(name)) {
  797. cfg = name;
  798. name = '';
  799. }
  800. name = name || 'default';
  801. this.hideLoading();
  802. if (!loadingEffects[name]) {
  803. if (true) {
  804. console.warn('Loading effects ' + name + ' not exists.');
  805. }
  806. return;
  807. }
  808. var el = loadingEffects[name](this._api, cfg);
  809. var zr = this._zr;
  810. this._loadingFX = el;
  811. zr.add(el);
  812. };
  813. /**
  814. * Hide loading effect
  815. */
  816. echartsProto.hideLoading = function () {
  817. this._loadingFX && this._zr.remove(this._loadingFX);
  818. this._loadingFX = null;
  819. };
  820. /**
  821. * @param {Object} eventObj
  822. * @return {Object}
  823. */
  824. echartsProto.makeActionFromEvent = function (eventObj) {
  825. var payload = zrUtil.extend({}, eventObj);
  826. payload.type = eventActionMap[eventObj.type];
  827. return payload;
  828. };
  829. /**
  830. * @pubilc
  831. * @param {Object} payload
  832. * @param {string} [payload.type] Action type
  833. * @param {Object|boolean} [opt] If pass boolean, means opt.silent
  834. * @param {boolean} [opt.silent=false] Whether trigger events.
  835. * @param {boolean} [opt.flush=undefined]
  836. * true: Flush immediately, and then pixel in canvas can be fetched
  837. * immediately. Caution: it might affect performance.
  838. * false: Not not flush.
  839. * undefined: Auto decide whether perform flush.
  840. */
  841. echartsProto.dispatchAction = function (payload, opt) {
  842. if (!zrUtil.isObject(opt)) {
  843. opt = {silent: !!opt};
  844. }
  845. if (!actions[payload.type]) {
  846. return;
  847. }
  848. // if (__DEV__) {
  849. // zrUtil.assert(
  850. // !this[IN_MAIN_PROCESS],
  851. // '`dispatchAction` should not be called during main process.'
  852. // + 'unless updateMathod is "none".'
  853. // );
  854. // }
  855. // May dispatchAction in rendering procedure
  856. if (this[IN_MAIN_PROCESS]) {
  857. this._pendingActions.push(payload);
  858. return;
  859. }
  860. doDispatchAction.call(this, payload, opt.silent);
  861. if (opt.flush) {
  862. this._zr.flush(true);
  863. }
  864. else if (opt.flush !== false && env.browser.weChat) {
  865. // In WeChat embeded browser, `requestAnimationFrame` and `setInterval`
  866. // hang when sliding page (on touch event), which cause that zr does not
  867. // refresh util user interaction finished, which is not expected.
  868. // But `dispatchAction` may be called too frequently when pan on touch
  869. // screen, which impacts performance if do not throttle them.
  870. this._throttledZrFlush();
  871. }
  872. flushPendingActions.call(this, opt.silent);
  873. triggerUpdatedEvent.call(this, opt.silent);
  874. };
  875. function doDispatchAction(payload, silent) {
  876. var payloadType = payload.type;
  877. var actionWrap = actions[payloadType];
  878. var actionInfo = actionWrap.actionInfo;
  879. var cptType = (actionInfo.update || 'update').split(':');
  880. var updateMethod = cptType.pop();
  881. cptType = cptType[0] && parseClassType(cptType[0]);
  882. this[IN_MAIN_PROCESS] = true;
  883. var payloads = [payload];
  884. var batched = false;
  885. // Batch action
  886. if (payload.batch) {
  887. batched = true;
  888. payloads = zrUtil.map(payload.batch, function (item) {
  889. item = zrUtil.defaults(zrUtil.extend({}, item), payload);
  890. item.batch = null;
  891. return item;
  892. });
  893. }
  894. var eventObjBatch = [];
  895. var eventObj;
  896. var isHighDown = payloadType === 'highlight' || payloadType === 'downplay';
  897. for (var i = 0; i < payloads.length; i++) {
  898. var batchItem = payloads[i];
  899. // Action can specify the event by return it.
  900. eventObj = actionWrap.action(batchItem, this._model);
  901. // Emit event outside
  902. eventObj = eventObj || zrUtil.extend({}, batchItem);
  903. // Convert type to eventType
  904. eventObj.type = actionInfo.event || eventObj.type;
  905. eventObjBatch.push(eventObj);
  906. // light update does not perform data process, layout and visual.
  907. if (isHighDown) {
  908. // method, payload, mainType, subType
  909. updateDirectly(this, updateMethod, batchItem, 'series');
  910. }
  911. else if (cptType) {
  912. updateDirectly(this, updateMethod, batchItem, cptType.main, cptType.sub);
  913. }
  914. }
  915. if (updateMethod !== 'none' && !isHighDown && !cptType) {
  916. // Still dirty
  917. if (this[OPTION_UPDATED]) {
  918. // FIXME Pass payload ?
  919. updateMethods.prepareAndUpdate.call(this, payload);
  920. this[OPTION_UPDATED] = false;
  921. }
  922. else {
  923. updateMethods[updateMethod].call(this, payload);
  924. }
  925. }
  926. // Follow the rule of action batch
  927. if (batched) {
  928. eventObj = {
  929. type: actionInfo.event || payloadType,
  930. batch: eventObjBatch
  931. };
  932. }
  933. else {
  934. eventObj = eventObjBatch[0];
  935. }
  936. this[IN_MAIN_PROCESS] = false;
  937. !silent && this._messageCenter.trigger(eventObj.type, eventObj);
  938. }
  939. function flushPendingActions(silent) {
  940. var pendingActions = this._pendingActions;
  941. while (pendingActions.length) {
  942. var payload = pendingActions.shift();
  943. doDispatchAction.call(this, payload, silent);
  944. }
  945. }
  946. function triggerUpdatedEvent(silent) {
  947. !silent && this.trigger('updated');
  948. }
  949. /**
  950. * Register event
  951. * @method
  952. */
  953. echartsProto.on = createRegisterEventWithLowercaseName('on');
  954. echartsProto.off = createRegisterEventWithLowercaseName('off');
  955. echartsProto.one = createRegisterEventWithLowercaseName('one');
  956. /**
  957. * @param {string} methodName
  958. * @private
  959. */
  960. function invokeUpdateMethod(methodName, ecModel, payload) {
  961. var api = this._api;
  962. // Update all components
  963. each(this._componentsViews, function (component) {
  964. var componentModel = component.__model;
  965. component[methodName](componentModel, ecModel, api, payload);
  966. updateZ(componentModel, component);
  967. }, this);
  968. // Upate all charts
  969. ecModel.eachSeries(function (seriesModel, idx) {
  970. var chart = this._chartsMap[seriesModel.__viewId];
  971. chart[methodName](seriesModel, ecModel, api, payload);
  972. updateZ(seriesModel, chart);
  973. updateProgressiveAndBlend(seriesModel, chart);
  974. }, this);
  975. // If use hover layer
  976. updateHoverLayerStatus(this._zr, ecModel);
  977. }
  978. /**
  979. * Prepare view instances of charts and components
  980. * @param {module:echarts/model/Global} ecModel
  981. * @private
  982. */
  983. function prepareView(type, ecModel) {
  984. var isComponent = type === 'component';
  985. var viewList = isComponent ? this._componentsViews : this._chartsViews;
  986. var viewMap = isComponent ? this._componentsMap : this._chartsMap;
  987. var zr = this._zr;
  988. for (var i = 0; i < viewList.length; i++) {
  989. viewList[i].__alive = false;
  990. }
  991. ecModel[isComponent ? 'eachComponent' : 'eachSeries'](function (componentType, model) {
  992. if (isComponent) {
  993. if (componentType === 'series') {
  994. return;
  995. }
  996. }
  997. else {
  998. model = componentType;
  999. }
  1000. // Consider: id same and type changed.
  1001. var viewId = model.id + '_' + model.type;
  1002. var view = viewMap[viewId];
  1003. if (!view) {
  1004. var classType = parseClassType(model.type);
  1005. var Clazz = isComponent
  1006. ? ComponentView.getClass(classType.main, classType.sub)
  1007. : ChartView.getClass(classType.sub);
  1008. if (Clazz) {
  1009. view = new Clazz();
  1010. view.init(ecModel, this._api);
  1011. viewMap[viewId] = view;
  1012. viewList.push(view);
  1013. zr.add(view.group);
  1014. }
  1015. else {
  1016. // Error
  1017. return;
  1018. }
  1019. }
  1020. model.__viewId = viewId;
  1021. view.__alive = true;
  1022. view.__id = viewId;
  1023. view.__model = model;
  1024. }, this);
  1025. for (var i = 0; i < viewList.length;) {
  1026. var view = viewList[i];
  1027. if (!view.__alive) {
  1028. zr.remove(view.group);
  1029. view.dispose(ecModel, this._api);
  1030. viewList.splice(i, 1);
  1031. delete viewMap[view.__id];
  1032. }
  1033. else {
  1034. i++;
  1035. }
  1036. }
  1037. }
  1038. /**
  1039. * Processor data in each series
  1040. *
  1041. * @param {module:echarts/model/Global} ecModel
  1042. * @private
  1043. */
  1044. function processData(ecModel, api) {
  1045. each(dataProcessorFuncs, function (process) {
  1046. process.func(ecModel, api);
  1047. });
  1048. }
  1049. /**
  1050. * @private
  1051. */
  1052. function stackSeriesData(ecModel) {
  1053. var stackedDataMap = {};
  1054. ecModel.eachSeries(function (series) {
  1055. var stack = series.get('stack');
  1056. var data = series.getData();
  1057. if (stack && data.type === 'list') {
  1058. var previousStack = stackedDataMap[stack];
  1059. if (previousStack) {
  1060. data.stackedOn = previousStack;
  1061. }
  1062. stackedDataMap[stack] = data;
  1063. }
  1064. });
  1065. }
  1066. /**
  1067. * Layout before each chart render there series, special visual encoding stage
  1068. *
  1069. * @param {module:echarts/model/Global} ecModel
  1070. * @private
  1071. */
  1072. function doLayout(ecModel, payload) {
  1073. var api = this._api;
  1074. each(visualFuncs, function (visual) {
  1075. if (visual.isLayout) {
  1076. visual.func(ecModel, api, payload);
  1077. }
  1078. });
  1079. }
  1080. /**
  1081. * Encode visual infomation from data after data processing
  1082. *
  1083. * @param {module:echarts/model/Global} ecModel
  1084. * @param {object} layout
  1085. * @param {boolean} [excludesLayout]
  1086. * @private
  1087. */
  1088. function doVisualEncoding(ecModel, payload, excludesLayout) {
  1089. var api = this._api;
  1090. ecModel.clearColorPalette();
  1091. ecModel.eachSeries(function (seriesModel) {
  1092. seriesModel.clearColorPalette();
  1093. });
  1094. each(visualFuncs, function (visual) {
  1095. (!excludesLayout || !visual.isLayout)
  1096. && visual.func(ecModel, api, payload);
  1097. });
  1098. }
  1099. /**
  1100. * Render each chart and component
  1101. * @private
  1102. */
  1103. function doRender(ecModel, payload) {
  1104. var api = this._api;
  1105. // Render all components
  1106. each(this._componentsViews, function (componentView) {
  1107. var componentModel = componentView.__model;
  1108. componentView.render(componentModel, ecModel, api, payload);
  1109. updateZ(componentModel, componentView);
  1110. }, this);
  1111. each(this._chartsViews, function (chart) {
  1112. chart.__alive = false;
  1113. }, this);
  1114. // Render all charts
  1115. ecModel.eachSeries(function (seriesModel, idx) {
  1116. var chartView = this._chartsMap[seriesModel.__viewId];
  1117. chartView.__alive = true;
  1118. chartView.render(seriesModel, ecModel, api, payload);
  1119. chartView.group.silent = !!seriesModel.get('silent');
  1120. updateZ(seriesModel, chartView);
  1121. updateProgressiveAndBlend(seriesModel, chartView);
  1122. }, this);
  1123. // If use hover layer
  1124. updateHoverLayerStatus(this._zr, ecModel);
  1125. // Remove groups of unrendered charts
  1126. each(this._chartsViews, function (chart) {
  1127. if (!chart.__alive) {
  1128. chart.remove(ecModel, api);
  1129. }
  1130. }, this);
  1131. }
  1132. var MOUSE_EVENT_NAMES = [
  1133. 'click', 'dblclick', 'mouseover', 'mouseout', 'mousemove',
  1134. 'mousedown', 'mouseup', 'globalout', 'contextmenu'
  1135. ];
  1136. /**
  1137. * @private
  1138. */
  1139. echartsProto._initEvents = function () {
  1140. each(MOUSE_EVENT_NAMES, function (eveName) {
  1141. this._zr.on(eveName, function (e) {
  1142. var ecModel = this.getModel();
  1143. var el = e.target;
  1144. var params;
  1145. // no e.target when 'globalout'.
  1146. if (eveName === 'globalout') {
  1147. params = {};
  1148. }
  1149. else if (el && el.dataIndex != null) {
  1150. var dataModel = el.dataModel || ecModel.getSeriesByIndex(el.seriesIndex);
  1151. params = dataModel && dataModel.getDataParams(el.dataIndex, el.dataType) || {};
  1152. }
  1153. // If element has custom eventData of components
  1154. else if (el && el.eventData) {
  1155. params = zrUtil.extend({}, el.eventData);
  1156. }
  1157. if (params) {
  1158. params.event = e;
  1159. params.type = eveName;
  1160. this.trigger(eveName, params);
  1161. }
  1162. }, this);
  1163. }, this);
  1164. each(eventActionMap, function (actionType, eventType) {
  1165. this._messageCenter.on(eventType, function (event) {
  1166. this.trigger(eventType, event);
  1167. }, this);
  1168. }, this);
  1169. };
  1170. /**
  1171. * @return {boolean}
  1172. */
  1173. echartsProto.isDisposed = function () {
  1174. return this._disposed;
  1175. };
  1176. /**
  1177. * Clear
  1178. */
  1179. echartsProto.clear = function () {
  1180. this.setOption({ series: [] }, true);
  1181. };
  1182. /**
  1183. * Dispose instance
  1184. */
  1185. echartsProto.dispose = function () {
  1186. if (this._disposed) {
  1187. if (true) {
  1188. console.warn('Instance ' + this.id + ' has been disposed');
  1189. }
  1190. return;
  1191. }
  1192. this._disposed = true;
  1193. var api = this._api;
  1194. var ecModel = this._model;
  1195. each(this._componentsViews, function (component) {
  1196. component.dispose(ecModel, api);
  1197. });
  1198. each(this._chartsViews, function (chart) {
  1199. chart.dispose(ecModel, api);
  1200. });
  1201. // Dispose after all views disposed
  1202. this._zr.dispose();
  1203. delete instances[this.id];
  1204. };
  1205. zrUtil.mixin(ECharts, Eventful);
  1206. function updateHoverLayerStatus(zr, ecModel) {
  1207. var storage = zr.storage;
  1208. var elCount = 0;
  1209. storage.traverse(function (el) {
  1210. if (!el.isGroup) {
  1211. elCount++;
  1212. }
  1213. });
  1214. if (elCount > ecModel.get('hoverLayerThreshold') && !env.node) {
  1215. storage.traverse(function (el) {
  1216. if (!el.isGroup) {
  1217. el.useHoverLayer = true;
  1218. }
  1219. });
  1220. }
  1221. }
  1222. /**
  1223. * Update chart progressive and blend.
  1224. * @param {module:echarts/model/Series|module:echarts/model/Component} model
  1225. * @param {module:echarts/view/Component|module:echarts/view/Chart} view
  1226. */
  1227. function updateProgressiveAndBlend(seriesModel, chartView) {
  1228. // Progressive configuration
  1229. var elCount = 0;
  1230. chartView.group.traverse(function (el) {
  1231. if (el.type !== 'group' && !el.ignore) {
  1232. elCount++;
  1233. }
  1234. });
  1235. var frameDrawNum = +seriesModel.get('progressive');
  1236. var needProgressive = elCount > seriesModel.get('progressiveThreshold') && frameDrawNum && !env.node;
  1237. if (needProgressive) {
  1238. chartView.group.traverse(function (el) {
  1239. // FIXME marker and other components
  1240. if (!el.isGroup) {
  1241. el.progressive = needProgressive ?
  1242. Math.floor(elCount++ / frameDrawNum) : -1;
  1243. if (needProgressive) {
  1244. el.stopAnimation(true);
  1245. }
  1246. }
  1247. });
  1248. }
  1249. // Blend configration
  1250. var blendMode = seriesModel.get('blendMode') || null;
  1251. if (true) {
  1252. if (!env.canvasSupported && blendMode && blendMode !== 'source-over') {
  1253. console.warn('Only canvas support blendMode');
  1254. }
  1255. }
  1256. chartView.group.traverse(function (el) {
  1257. // FIXME marker and other components
  1258. if (!el.isGroup) {
  1259. el.setStyle('blend', blendMode);
  1260. }
  1261. });
  1262. }
  1263. /**
  1264. * @param {module:echarts/model/Series|module:echarts/model/Component} model
  1265. * @param {module:echarts/view/Component|module:echarts/view/Chart} view
  1266. */
  1267. function updateZ(model, view) {
  1268. var z = model.get('z');
  1269. var zlevel = model.get('zlevel');
  1270. // Set z and zlevel
  1271. view.group.traverse(function (el) {
  1272. if (el.type !== 'group') {
  1273. z != null && (el.z = z);
  1274. zlevel != null && (el.zlevel = zlevel);
  1275. }
  1276. });
  1277. }
  1278. /**
  1279. * @type {Array.<Function>}
  1280. * @inner
  1281. */
  1282. var actions = [];
  1283. /**
  1284. * Map eventType to actionType
  1285. * @type {Object}
  1286. */
  1287. var eventActionMap = {};
  1288. /**
  1289. * Data processor functions of each stage
  1290. * @type {Array.<Object.<string, Function>>}
  1291. * @inner
  1292. */
  1293. var dataProcessorFuncs = [];
  1294. /**
  1295. * @type {Array.<Function>}
  1296. * @inner
  1297. */
  1298. var optionPreprocessorFuncs = [];
  1299. /**
  1300. * Visual encoding functions of each stage
  1301. * @type {Array.<Object.<string, Function>>}
  1302. * @inner
  1303. */
  1304. var visualFuncs = [];
  1305. /**
  1306. * Theme storage
  1307. * @type {Object.<key, Object>}
  1308. */
  1309. var themeStorage = {};
  1310. /**
  1311. * Loading effects
  1312. */
  1313. var loadingEffects = {};
  1314. var instances = {};
  1315. var connectedGroups = {};
  1316. var idBase = new Date() - 0;
  1317. var groupIdBase = new Date() - 0;
  1318. var DOM_ATTRIBUTE_KEY = '_echarts_instance_';
  1319. /**
  1320. * @alias module:echarts
  1321. */
  1322. var echarts = {
  1323. /**
  1324. * @type {number}
  1325. */
  1326. version: '3.4.0',
  1327. dependencies: {
  1328. zrender: '3.3.0'
  1329. }
  1330. };
  1331. function enableConnect(chart) {
  1332. var STATUS_PENDING = 0;
  1333. var STATUS_UPDATING = 1;
  1334. var STATUS_UPDATED = 2;
  1335. var STATUS_KEY = '__connectUpdateStatus';
  1336. function updateConnectedChartsStatus(charts, status) {
  1337. for (var i = 0; i < charts.length; i++) {
  1338. var otherChart = charts[i];
  1339. otherChart[STATUS_KEY] = status;
  1340. }
  1341. }
  1342. zrUtil.each(eventActionMap, function (actionType, eventType) {
  1343. chart._messageCenter.on(eventType, function (event) {
  1344. if (connectedGroups[chart.group] && chart[STATUS_KEY] !== STATUS_PENDING) {
  1345. var action = chart.makeActionFromEvent(event);
  1346. var otherCharts = [];
  1347. zrUtil.each(instances, function (otherChart) {
  1348. if (otherChart !== chart && otherChart.group === chart.group) {
  1349. otherCharts.push(otherChart);
  1350. }
  1351. });
  1352. updateConnectedChartsStatus(otherCharts, STATUS_PENDING);
  1353. each(otherCharts, function (otherChart) {
  1354. if (otherChart[STATUS_KEY] !== STATUS_UPDATING) {
  1355. otherChart.dispatchAction(action);
  1356. }
  1357. });
  1358. updateConnectedChartsStatus(otherCharts, STATUS_UPDATED);
  1359. }
  1360. });
  1361. });
  1362. }
  1363. /**
  1364. * @param {HTMLDomElement} dom
  1365. * @param {Object} [theme]
  1366. * @param {Object} opts
  1367. * @param {number} [opts.devicePixelRatio] Use window.devicePixelRatio by default
  1368. * @param {string} [opts.renderer] Currently only 'canvas' is supported.
  1369. * @param {number} [opts.width] Use clientWidth of the input `dom` by default.
  1370. * Can be 'auto' (the same as null/undefined)
  1371. * @param {number} [opts.height] Use clientHeight of the input `dom` by default.
  1372. * Can be 'auto' (the same as null/undefined)
  1373. */
  1374. echarts.init = function (dom, theme, opts) {
  1375. if (true) {
  1376. // Check version
  1377. if ((zrender.version.replace('.', '') - 0) < (echarts.dependencies.zrender.replace('.', '') - 0)) {
  1378. throw new Error(
  1379. 'ZRender ' + zrender.version
  1380. + ' is too old for ECharts ' + echarts.version
  1381. + '. Current version need ZRender '
  1382. + echarts.dependencies.zrender + '+'
  1383. );
  1384. }
  1385. if (!dom) {
  1386. throw new Error('Initialize failed: invalid dom.');
  1387. }
  1388. if (zrUtil.isDom(dom) && dom.nodeName.toUpperCase() !== 'CANVAS' && (!dom.clientWidth || !dom.clientHeight)) {
  1389. console.warn('Can\'t get dom width or height');
  1390. }
  1391. }
  1392. var chart = new ECharts(dom, theme, opts);
  1393. chart.id = 'ec_' + idBase++;
  1394. instances[chart.id] = chart;
  1395. dom.setAttribute &&
  1396. dom.setAttribute(DOM_ATTRIBUTE_KEY, chart.id);
  1397. enableConnect(chart);
  1398. return chart;
  1399. };
  1400. /**
  1401. * @return {string|Array.<module:echarts~ECharts>} groupId
  1402. */
  1403. echarts.connect = function (groupId) {
  1404. // Is array of charts
  1405. if (zrUtil.isArray(groupId)) {
  1406. var charts = groupId;
  1407. groupId = null;
  1408. // If any chart has group
  1409. zrUtil.each(charts, function (chart) {
  1410. if (chart.group != null) {
  1411. groupId = chart.group;
  1412. }
  1413. });
  1414. groupId = groupId || ('g_' + groupIdBase++);
  1415. zrUtil.each(charts, function (chart) {
  1416. chart.group = groupId;
  1417. });
  1418. }
  1419. connectedGroups[groupId] = true;
  1420. return groupId;
  1421. };
  1422. /**
  1423. * @return {string} groupId
  1424. */
  1425. echarts.disConnect = function (groupId) {
  1426. connectedGroups[groupId] = false;
  1427. };
  1428. /**
  1429. * Dispose a chart instance
  1430. * @param {module:echarts~ECharts|HTMLDomElement|string} chart
  1431. */
  1432. echarts.dispose = function (chart) {
  1433. if (zrUtil.isDom(chart)) {
  1434. chart = echarts.getInstanceByDom(chart);
  1435. }
  1436. else if (typeof chart === 'string') {
  1437. chart = instances[chart];
  1438. }
  1439. if ((chart instanceof ECharts) && !chart.isDisposed()) {
  1440. chart.dispose();
  1441. }
  1442. };
  1443. /**
  1444. * @param {HTMLDomElement} dom
  1445. * @return {echarts~ECharts}
  1446. */
  1447. echarts.getInstanceByDom = function (dom) {
  1448. var key = dom.getAttribute(DOM_ATTRIBUTE_KEY);
  1449. return instances[key];
  1450. };
  1451. /**
  1452. * @param {string} key
  1453. * @return {echarts~ECharts}
  1454. */
  1455. echarts.getInstanceById = function (key) {
  1456. return instances[key];
  1457. };
  1458. /**
  1459. * Register theme
  1460. */
  1461. echarts.registerTheme = function (name, theme) {
  1462. themeStorage[name] = theme;
  1463. };
  1464. /**
  1465. * Register option preprocessor
  1466. * @param {Function} preprocessorFunc
  1467. */
  1468. echarts.registerPreprocessor = function (preprocessorFunc) {
  1469. optionPreprocessorFuncs.push(preprocessorFunc);
  1470. };
  1471. /**
  1472. * @param {number} [priority=1000]
  1473. * @param {Function} processorFunc
  1474. */
  1475. echarts.registerProcessor = function (priority, processorFunc) {
  1476. if (typeof priority === 'function') {
  1477. processorFunc = priority;
  1478. priority = PRIORITY_PROCESSOR_FILTER;
  1479. }
  1480. if (true) {
  1481. if (isNaN(priority)) {
  1482. throw new Error('Unkown processor priority');
  1483. }
  1484. }
  1485. dataProcessorFuncs.push({
  1486. prio: priority,
  1487. func: processorFunc
  1488. });
  1489. };
  1490. /**
  1491. * Usage:
  1492. * registerAction('someAction', 'someEvent', function () { ... });
  1493. * registerAction('someAction', function () { ... });
  1494. * registerAction(
  1495. * {type: 'someAction', event: 'someEvent', update: 'updateView'},
  1496. * function () { ... }
  1497. * );
  1498. *
  1499. * @param {(string|Object)} actionInfo
  1500. * @param {string} actionInfo.type
  1501. * @param {string} [actionInfo.event]
  1502. * @param {string} [actionInfo.update]
  1503. * @param {string} [eventName]
  1504. * @param {Function} action
  1505. */
  1506. echarts.registerAction = function (actionInfo, eventName, action) {
  1507. if (typeof eventName === 'function') {
  1508. action = eventName;
  1509. eventName = '';
  1510. }
  1511. var actionType = zrUtil.isObject(actionInfo)
  1512. ? actionInfo.type
  1513. : ([actionInfo, actionInfo = {
  1514. event: eventName
  1515. }][0]);
  1516. // Event name is all lowercase
  1517. actionInfo.event = (actionInfo.event || actionType).toLowerCase();
  1518. eventName = actionInfo.event;
  1519. // Validate action type and event name.
  1520. zrUtil.assert(ACTION_REG.test(actionType) && ACTION_REG.test(eventName));
  1521. if (!actions[actionType]) {
  1522. actions[actionType] = {action: action, actionInfo: actionInfo};
  1523. }
  1524. eventActionMap[eventName] = actionType;
  1525. };
  1526. /**
  1527. * @param {string} type
  1528. * @param {*} CoordinateSystem
  1529. */
  1530. echarts.registerCoordinateSystem = function (type, CoordinateSystem) {
  1531. CoordinateSystemManager.register(type, CoordinateSystem);
  1532. };
  1533. /**
  1534. * Layout is a special stage of visual encoding
  1535. * Most visual encoding like color are common for different chart
  1536. * But each chart has it's own layout algorithm
  1537. *
  1538. * @param {number} [priority=1000]
  1539. * @param {Function} layoutFunc
  1540. */
  1541. echarts.registerLayout = function (priority, layoutFunc) {
  1542. if (typeof priority === 'function') {
  1543. layoutFunc = priority;
  1544. priority = PRIORITY_VISUAL_LAYOUT;
  1545. }
  1546. if (true) {
  1547. if (isNaN(priority)) {
  1548. throw new Error('Unkown layout priority');
  1549. }
  1550. }
  1551. visualFuncs.push({
  1552. prio: priority,
  1553. func: layoutFunc,
  1554. isLayout: true
  1555. });
  1556. };
  1557. /**
  1558. * @param {number} [priority=3000]
  1559. * @param {Function} visualFunc
  1560. */
  1561. echarts.registerVisual = function (priority, visualFunc) {
  1562. if (typeof priority === 'function') {
  1563. visualFunc = priority;
  1564. priority = PRIORITY_VISUAL_CHART;
  1565. }
  1566. if (true) {
  1567. if (isNaN(priority)) {
  1568. throw new Error('Unkown visual priority');
  1569. }
  1570. }
  1571. visualFuncs.push({
  1572. prio: priority,
  1573. func: visualFunc
  1574. });
  1575. };
  1576. /**
  1577. * @param {string} name
  1578. */
  1579. echarts.registerLoading = function (name, loadingFx) {
  1580. loadingEffects[name] = loadingFx;
  1581. };
  1582. /**
  1583. * @param {Object} opts
  1584. * @param {string} [superClass]
  1585. */
  1586. echarts.extendComponentModel = function (opts/*, superClass*/) {
  1587. // var Clazz = ComponentModel;
  1588. // if (superClass) {
  1589. // var classType = parseClassType(superClass);
  1590. // Clazz = ComponentModel.getClass(classType.main, classType.sub, true);
  1591. // }
  1592. return ComponentModel.extend(opts);
  1593. };
  1594. /**
  1595. * @param {Object} opts
  1596. * @param {string} [superClass]
  1597. */
  1598. echarts.extendComponentView = function (opts/*, superClass*/) {
  1599. // var Clazz = ComponentView;
  1600. // if (superClass) {
  1601. // var classType = parseClassType(superClass);
  1602. // Clazz = ComponentView.getClass(classType.main, classType.sub, true);
  1603. // }
  1604. return ComponentView.extend(opts);
  1605. };
  1606. /**
  1607. * @param {Object} opts
  1608. * @param {string} [superClass]
  1609. */
  1610. echarts.extendSeriesModel = function (opts/*, superClass*/) {
  1611. // var Clazz = SeriesModel;
  1612. // if (superClass) {
  1613. // superClass = 'series.' + superClass.replace('series.', '');
  1614. // var classType = parseClassType(superClass);
  1615. // Clazz = ComponentModel.getClass(classType.main, classType.sub, true);
  1616. // }
  1617. return SeriesModel.extend(opts);
  1618. };
  1619. /**
  1620. * @param {Object} opts
  1621. * @param {string} [superClass]
  1622. */
  1623. echarts.extendChartView = function (opts/*, superClass*/) {
  1624. // var Clazz = ChartView;
  1625. // if (superClass) {
  1626. // superClass = superClass.replace('series.', '');
  1627. // var classType = parseClassType(superClass);
  1628. // Clazz = ChartView.getClass(classType.main, true);
  1629. // }
  1630. return ChartView.extend(opts);
  1631. };
  1632. /**
  1633. * ZRender need a canvas context to do measureText.
  1634. * But in node environment canvas may be created by node-canvas.
  1635. * So we need to specify how to create a canvas instead of using document.createElement('canvas')
  1636. *
  1637. * Be careful of using it in the browser.
  1638. *
  1639. * @param {Function} creator
  1640. * @example
  1641. * var Canvas = require('canvas');
  1642. * var echarts = require('echarts');
  1643. * echarts.setCanvasCreator(function () {
  1644. * // Small size is enough.
  1645. * return new Canvas(32, 32);
  1646. * });
  1647. */
  1648. echarts.setCanvasCreator = function (creator) {
  1649. zrUtil.createCanvas = creator;
  1650. };
  1651. echarts.registerVisual(PRIORITY_VISUAL_GLOBAL, __webpack_require__(94));
  1652. echarts.registerPreprocessor(__webpack_require__(95));
  1653. echarts.registerLoading('default', __webpack_require__(97));
  1654. // Default action
  1655. echarts.registerAction({
  1656. type: 'highlight',
  1657. event: 'highlight',
  1658. update: 'highlight'
  1659. }, zrUtil.noop);
  1660. echarts.registerAction({
  1661. type: 'downplay',
  1662. event: 'downplay',
  1663. update: 'downplay'
  1664. }, zrUtil.noop);
  1665. // --------
  1666. // Exports
  1667. // --------
  1668. //
  1669. echarts.List = __webpack_require__(98);
  1670. echarts.Model = __webpack_require__(12);
  1671. echarts.graphic = __webpack_require__(43);
  1672. echarts.number = __webpack_require__(7);
  1673. echarts.format = __webpack_require__(6);
  1674. echarts.throttle = throttle.throttle;
  1675. echarts.matrix = __webpack_require__(11);
  1676. echarts.vector = __webpack_require__(10);
  1677. echarts.color = __webpack_require__(39);
  1678. echarts.util = {};
  1679. each([
  1680. 'map', 'each', 'filter', 'indexOf', 'inherits', 'reduce', 'filter',
  1681. 'bind', 'curry', 'isArray', 'isString', 'isObject', 'isFunction',
  1682. 'extend', 'defaults', 'clone'
  1683. ],
  1684. function (name) {
  1685. echarts.util[name] = zrUtil[name];
  1686. }
  1687. );
  1688. // PRIORITY
  1689. echarts.PRIORITY = {
  1690. PROCESSOR: {
  1691. FILTER: PRIORITY_PROCESSOR_FILTER,
  1692. STATISTIC: PRIORITY_PROCESSOR_STATISTIC
  1693. },
  1694. VISUAL: {
  1695. LAYOUT: PRIORITY_VISUAL_LAYOUT,
  1696. GLOBAL: PRIORITY_VISUAL_GLOBAL,
  1697. CHART: PRIORITY_VISUAL_CHART,
  1698. COMPONENT: PRIORITY_VISUAL_COMPONENT,
  1699. BRUSH: PRIORITY_VISUAL_BRUSH
  1700. }
  1701. };
  1702. module.exports = echarts;
  1703. /***/ },
  1704. /* 2 */
  1705. /***/ function(module, exports) {
  1706. /**
  1707. * echarts设备环境识别
  1708. *
  1709. * @desc echarts基于Canvas,纯Javascript图表库,提供直观,生动,可交互,可个性化定制的数据统计图表。
  1710. * @author firede[firede@firede.us]
  1711. * @desc thanks zepto.
  1712. */
  1713. var env = {};
  1714. if (typeof navigator === 'undefined') {
  1715. // In node
  1716. env = {
  1717. browser: {},
  1718. os: {},
  1719. node: true,
  1720. // Assume canvas is supported
  1721. canvasSupported: true
  1722. };
  1723. }
  1724. else {
  1725. env = detect(navigator.userAgent);
  1726. }
  1727. module.exports = env;
  1728. // Zepto.js
  1729. // (c) 2010-2013 Thomas Fuchs
  1730. // Zepto.js may be freely distributed under the MIT license.
  1731. function detect(ua) {
  1732. var os = {};
  1733. var browser = {};
  1734. // var webkit = ua.match(/Web[kK]it[\/]{0,1}([\d.]+)/);
  1735. // var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
  1736. // var ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
  1737. // var ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
  1738. // var iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/);
  1739. // var webos = ua.match(/(webOS|hpwOS)[\s\/]([\d.]+)/);
  1740. // var touchpad = webos && ua.match(/TouchPad/);
  1741. // var kindle = ua.match(/Kindle\/([\d.]+)/);
  1742. // var silk = ua.match(/Silk\/([\d._]+)/);
  1743. // var blackberry = ua.match(/(BlackBerry).*Version\/([\d.]+)/);
  1744. // var bb10 = ua.match(/(BB10).*Version\/([\d.]+)/);
  1745. // var rimtabletos = ua.match(/(RIM\sTablet\sOS)\s([\d.]+)/);
  1746. // var playbook = ua.match(/PlayBook/);
  1747. // var chrome = ua.match(/Chrome\/([\d.]+)/) || ua.match(/CriOS\/([\d.]+)/);
  1748. var firefox = ua.match(/Firefox\/([\d.]+)/);
  1749. // var safari = webkit && ua.match(/Mobile\//) && !chrome;
  1750. // var webview = ua.match(/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/) && !chrome;
  1751. var ie = ua.match(/MSIE\s([\d.]+)/)
  1752. // IE 11 Trident/7.0; rv:11.0
  1753. || ua.match(/Trident\/.+?rv:(([\d.]+))/);
  1754. var edge = ua.match(/Edge\/([\d.]+)/); // IE 12 and 12+
  1755. var weChat = (/micromessenger/i).test(ua);
  1756. // Todo: clean this up with a better OS/browser seperation:
  1757. // - discern (more) between multiple browsers on android
  1758. // - decide if kindle fire in silk mode is android or not
  1759. // - Firefox on Android doesn't specify the Android version
  1760. // - possibly devide in os, device and browser hashes
  1761. // if (browser.webkit = !!webkit) browser.version = webkit[1];
  1762. // if (android) os.android = true, os.version = android[2];
  1763. // if (iphone && !ipod) os.ios = os.iphone = true, os.version = iphone[2].replace(/_/g, '.');
  1764. // if (ipad) os.ios = os.ipad = true, os.version = ipad[2].replace(/_/g, '.');
  1765. // if (ipod) os.ios = os.ipod = true, os.version = ipod[3] ? ipod[3].replace(/_/g, '.') : null;
  1766. // if (webos) os.webos = true, os.version = webos[2];
  1767. // if (touchpad) os.touchpad = true;
  1768. // if (blackberry) os.blackberry = true, os.version = blackberry[2];
  1769. // if (bb10) os.bb10 = true, os.version = bb10[2];
  1770. // if (rimtabletos) os.rimtabletos = true, os.version = rimtabletos[2];
  1771. // if (playbook) browser.playbook = true;
  1772. // if (kindle) os.kindle = true, os.version = kindle[1];
  1773. // if (silk) browser.silk = true, browser.version = silk[1];
  1774. // if (!silk && os.android && ua.match(/Kindle Fire/)) browser.silk = true;
  1775. // if (chrome) browser.chrome = true, browser.version = chrome[1];
  1776. if (firefox) {
  1777. browser.firefox = true;
  1778. browser.version = firefox[1];
  1779. }
  1780. // if (safari && (ua.match(/Safari/) || !!os.ios)) browser.safari = true;
  1781. // if (webview) browser.webview = true;
  1782. if (ie) {
  1783. browser.ie = true;
  1784. browser.version = ie[1];
  1785. }
  1786. if (edge) {
  1787. browser.edge = true;
  1788. browser.version = edge[1];
  1789. }
  1790. // It is difficult to detect WeChat in Win Phone precisely, because ua can
  1791. // not be set on win phone. So we do not consider Win Phone.
  1792. if (weChat) {
  1793. browser.weChat = true;
  1794. }
  1795. // os.tablet = !!(ipad || playbook || (android && !ua.match(/Mobile/)) ||
  1796. // (firefox && ua.match(/Tablet/)) || (ie && !ua.match(/Phone/) && ua.match(/Touch/)));
  1797. // os.phone = !!(!os.tablet && !os.ipod && (android || iphone || webos ||
  1798. // (chrome && ua.match(/Android/)) || (chrome && ua.match(/CriOS\/([\d.]+)/)) ||
  1799. // (firefox && ua.match(/Mobile/)) || (ie && ua.match(/Touch/))));
  1800. return {
  1801. browser: browser,
  1802. os: os,
  1803. node: false,
  1804. // 原生canvas支持,改极端点了
  1805. // canvasSupported : !(browser.ie && parseFloat(browser.version) < 9)
  1806. canvasSupported : document.createElement('canvas').getContext ? true : false,
  1807. // @see <http://stackoverflow.com/questions/4817029/whats-the-best-way-to-detect-a-touch-screen-device-using-javascript>
  1808. // works on most browsers
  1809. // IE10/11 does not support touch event, and MS Edge supports them but not by
  1810. // default, so we dont check navigator.maxTouchPoints for them here.
  1811. touchEventsSupported: 'ontouchstart' in window && !browser.ie && !browser.edge,
  1812. // <http://caniuse.com/#search=pointer%20event>.
  1813. pointerEventsSupported: 'onpointerdown' in window
  1814. // Firefox supports pointer but not by default, only MS browsers are reliable on pointer
  1815. // events currently. So we dont use that on other browsers unless tested sufficiently.
  1816. // Although IE 10 supports pointer event, it use old style and is different from the
  1817. // standard. So we exclude that. (IE 10 is hardly used on touch device)
  1818. && (browser.edge || (browser.ie && browser.version >= 11))
  1819. };
  1820. }
  1821. /***/ },
  1822. /* 3 */
  1823. /***/ function(module, exports, __webpack_require__) {
  1824. /**
  1825. * ECharts global model
  1826. *
  1827. * @module {echarts/model/Global}
  1828. */
  1829. /**
  1830. * Caution: If the mechanism should be changed some day, these cases
  1831. * should be considered:
  1832. *
  1833. * (1) In `merge option` mode, if using the same option to call `setOption`
  1834. * many times, the result should be the same (try our best to ensure that).
  1835. * (2) In `merge option` mode, if a component has no id/name specified, it
  1836. * will be merged by index, and the result sequence of the components is
  1837. * consistent to the original sequence.
  1838. * (3) `reset` feature (in toolbox). Find detailed info in comments about
  1839. * `mergeOption` in module:echarts/model/OptionManager.
  1840. */
  1841. var zrUtil = __webpack_require__(4);
  1842. var modelUtil = __webpack_require__(5);
  1843. var Model = __webpack_require__(12);
  1844. var each = zrUtil.each;
  1845. var filter = zrUtil.filter;
  1846. var map = zrUtil.map;
  1847. var isArray = zrUtil.isArray;
  1848. var indexOf = zrUtil.indexOf;
  1849. var isObject = zrUtil.isObject;
  1850. var ComponentModel = __webpack_require__(19);
  1851. var globalDefault = __webpack_require__(23);
  1852. var OPTION_INNER_KEY = '\0_ec_inner';
  1853. /**
  1854. * @alias module:echarts/model/Global
  1855. *
  1856. * @param {Object} option
  1857. * @param {module:echarts/model/Model} parentModel
  1858. * @param {Object} theme
  1859. */
  1860. var GlobalModel = Model.extend({
  1861. constructor: GlobalModel,
  1862. init: function (option, parentModel, theme, optionManager) {
  1863. theme = theme || {};
  1864. this.option = null; // Mark as not initialized.
  1865. /**
  1866. * @type {module:echarts/model/Model}
  1867. * @private
  1868. */
  1869. this._theme = new Model(theme);
  1870. /**
  1871. * @type {module:echarts/model/OptionManager}
  1872. */
  1873. this._optionManager = optionManager;
  1874. },
  1875. setOption: function (option, optionPreprocessorFuncs) {
  1876. zrUtil.assert(
  1877. !(OPTION_INNER_KEY in option),
  1878. 'please use chart.getOption()'
  1879. );
  1880. this._optionManager.setOption(option, optionPreprocessorFuncs);
  1881. this.resetOption();
  1882. },
  1883. /**
  1884. * @param {string} type null/undefined: reset all.
  1885. * 'recreate': force recreate all.
  1886. * 'timeline': only reset timeline option
  1887. * 'media': only reset media query option
  1888. * @return {boolean} Whether option changed.
  1889. */
  1890. resetOption: function (type) {
  1891. var optionChanged = false;
  1892. var optionManager = this._optionManager;
  1893. if (!type || type === 'recreate') {
  1894. var baseOption = optionManager.mountOption(type === 'recreate');
  1895. if (!this.option || type === 'recreate') {
  1896. initBase.call(this, baseOption);
  1897. }
  1898. else {
  1899. this.restoreData();
  1900. this.mergeOption(baseOption);
  1901. }
  1902. optionChanged = true;
  1903. }
  1904. if (type === 'timeline' || type === 'media') {
  1905. this.restoreData();
  1906. }
  1907. if (!type || type === 'recreate' || type === 'timeline') {
  1908. var timelineOption = optionManager.getTimelineOption(this);
  1909. timelineOption && (this.mergeOption(timelineOption), optionChanged = true);
  1910. }
  1911. if (!type || type === 'recreate' || type === 'media') {
  1912. var mediaOptions = optionManager.getMediaOption(this, this._api);
  1913. if (mediaOptions.length) {
  1914. each(mediaOptions, function (mediaOption) {
  1915. this.mergeOption(mediaOption, optionChanged = true);
  1916. }, this);
  1917. }
  1918. }
  1919. return optionChanged;
  1920. },
  1921. /**
  1922. * @protected
  1923. */
  1924. mergeOption: function (newOption) {
  1925. var option = this.option;
  1926. var componentsMap = this._componentsMap;
  1927. var newCptTypes = [];
  1928. // 如果不存在对应的 component model 则直接 merge
  1929. each(newOption, function (componentOption, mainType) {
  1930. if (componentOption == null) {
  1931. return;
  1932. }
  1933. if (!ComponentModel.hasClass(mainType)) {
  1934. option[mainType] = option[mainType] == null
  1935. ? zrUtil.clone(componentOption)
  1936. : zrUtil.merge(option[mainType], componentOption, true);
  1937. }
  1938. else {
  1939. newCptTypes.push(mainType);
  1940. }
  1941. });
  1942. // FIXME OPTION 同步是否要改回原来的
  1943. ComponentModel.topologicalTravel(
  1944. newCptTypes, ComponentModel.getAllClassMainTypes(), visitComponent, this
  1945. );
  1946. this._seriesIndices = this._seriesIndices || [];
  1947. function visitComponent(mainType, dependencies) {
  1948. var newCptOptionList = modelUtil.normalizeToArray(newOption[mainType]);
  1949. var mapResult = modelUtil.mappingToExists(
  1950. componentsMap[mainType], newCptOptionList
  1951. );
  1952. modelUtil.makeIdAndName(mapResult);
  1953. // Set mainType and complete subType.
  1954. each(mapResult, function (item, index) {
  1955. var opt = item.option;
  1956. if (isObject(opt)) {
  1957. item.keyInfo.mainType = mainType;
  1958. item.keyInfo.subType = determineSubType(mainType, opt, item.exist);
  1959. }
  1960. });
  1961. var dependentModels = getComponentsByTypes(
  1962. componentsMap, dependencies
  1963. );
  1964. option[mainType] = [];
  1965. componentsMap[mainType] = [];
  1966. each(mapResult, function (resultItem, index) {
  1967. var componentModel = resultItem.exist;
  1968. var newCptOption = resultItem.option;
  1969. zrUtil.assert(
  1970. isObject(newCptOption) || componentModel,
  1971. 'Empty component definition'
  1972. );
  1973. // Consider where is no new option and should be merged using {},
  1974. // see removeEdgeAndAdd in topologicalTravel and
  1975. // ComponentModel.getAllClassMainTypes.
  1976. if (!newCptOption) {
  1977. componentModel.mergeOption({}, this);
  1978. componentModel.optionUpdated({}, false);
  1979. }
  1980. else {
  1981. var ComponentModelClass = ComponentModel.getClass(
  1982. mainType, resultItem.keyInfo.subType, true
  1983. );
  1984. if (componentModel && componentModel instanceof ComponentModelClass) {
  1985. componentModel.name = resultItem.keyInfo.name;
  1986. componentModel.mergeOption(newCptOption, this);
  1987. componentModel.optionUpdated(newCptOption, false);
  1988. }
  1989. else {
  1990. // PENDING Global as parent ?
  1991. var extraOpt = zrUtil.extend(
  1992. {
  1993. dependentModels: dependentModels,
  1994. componentIndex: index
  1995. },
  1996. resultItem.keyInfo
  1997. );
  1998. componentModel = new ComponentModelClass(
  1999. newCptOption, this, this, extraOpt
  2000. );
  2001. zrUtil.extend(componentModel, extraOpt);
  2002. componentModel.init(newCptOption, this, this, extraOpt);
  2003. // Call optionUpdated after init.
  2004. // newCptOption has been used as componentModel.option
  2005. // and may be merged with theme and default, so pass null
  2006. // to avoid confusion.
  2007. componentModel.optionUpdated(null, true);
  2008. }
  2009. }
  2010. componentsMap[mainType][index] = componentModel;
  2011. option[mainType][index] = componentModel.option;
  2012. }, this);
  2013. // Backup series for filtering.
  2014. if (mainType === 'series') {
  2015. this._seriesIndices = createSeriesIndices(componentsMap.series);
  2016. }
  2017. }
  2018. },
  2019. /**
  2020. * Get option for output (cloned option and inner info removed)
  2021. * @public
  2022. * @return {Object}
  2023. */
  2024. getOption: function () {
  2025. var option = zrUtil.clone(this.option);
  2026. each(option, function (opts, mainType) {
  2027. if (ComponentModel.hasClass(mainType)) {
  2028. var opts = modelUtil.normalizeToArray(opts);
  2029. for (var i = opts.length - 1; i >= 0; i--) {
  2030. // Remove options with inner id.
  2031. if (modelUtil.isIdInner(opts[i])) {
  2032. opts.splice(i, 1);
  2033. }
  2034. }
  2035. option[mainType] = opts;
  2036. }
  2037. });
  2038. delete option[OPTION_INNER_KEY];
  2039. return option;
  2040. },
  2041. /**
  2042. * @return {module:echarts/model/Model}
  2043. */
  2044. getTheme: function () {
  2045. return this._theme;
  2046. },
  2047. /**
  2048. * @param {string} mainType
  2049. * @param {number} [idx=0]
  2050. * @return {module:echarts/model/Component}
  2051. */
  2052. getComponent: function (mainType, idx) {
  2053. var list = this._componentsMap[mainType];
  2054. if (list) {
  2055. return list[idx || 0];
  2056. }
  2057. },
  2058. /**
  2059. * If none of index and id and name used, return all components with mainType.
  2060. * @param {Object} condition
  2061. * @param {string} condition.mainType
  2062. * @param {string} [condition.subType] If ignore, only query by mainType
  2063. * @param {number|Array.<number>} [condition.index] Either input index or id or name.
  2064. * @param {string|Array.<string>} [condition.id] Either input index or id or name.
  2065. * @param {string|Array.<string>} [condition.name] Either input index or id or name.
  2066. * @return {Array.<module:echarts/model/Component>}
  2067. */
  2068. queryComponents: function (condition) {
  2069. var mainType = condition.mainType;
  2070. if (!mainType) {
  2071. return [];
  2072. }
  2073. var index = condition.index;
  2074. var id = condition.id;
  2075. var name = condition.name;
  2076. var cpts = this._componentsMap[mainType];
  2077. if (!cpts || !cpts.length) {
  2078. return [];
  2079. }
  2080. var result;
  2081. if (index != null) {
  2082. if (!isArray(index)) {
  2083. index = [index];
  2084. }
  2085. result = filter(map(index, function (idx) {
  2086. return cpts[idx];
  2087. }), function (val) {
  2088. return !!val;
  2089. });
  2090. }
  2091. else if (id != null) {
  2092. var isIdArray = isArray(id);
  2093. result = filter(cpts, function (cpt) {
  2094. return (isIdArray && indexOf(id, cpt.id) >= 0)
  2095. || (!isIdArray && cpt.id === id);
  2096. });
  2097. }
  2098. else if (name != null) {
  2099. var isNameArray = isArray(name);
  2100. result = filter(cpts, function (cpt) {
  2101. return (isNameArray && indexOf(name, cpt.name) >= 0)
  2102. || (!isNameArray && cpt.name === name);
  2103. });
  2104. }
  2105. else {
  2106. // Return all components with mainType
  2107. result = cpts;
  2108. }
  2109. return filterBySubType(result, condition);
  2110. },
  2111. /**
  2112. * The interface is different from queryComponents,
  2113. * which is convenient for inner usage.
  2114. *
  2115. * @usage
  2116. * var result = findComponents(
  2117. * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}}
  2118. * );
  2119. * var result = findComponents(
  2120. * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}}
  2121. * );
  2122. * var result = findComponents(
  2123. * {mainType: 'series'},
  2124. * function (model, index) {...}
  2125. * );
  2126. * // result like [component0, componnet1, ...]
  2127. *
  2128. * @param {Object} condition
  2129. * @param {string} condition.mainType Mandatory.
  2130. * @param {string} [condition.subType] Optional.
  2131. * @param {Object} [condition.query] like {xxxIndex, xxxId, xxxName},
  2132. * where xxx is mainType.
  2133. * If query attribute is null/undefined or has no index/id/name,
  2134. * do not filtering by query conditions, which is convenient for
  2135. * no-payload situations or when target of action is global.
  2136. * @param {Function} [condition.filter] parameter: component, return boolean.
  2137. * @return {Array.<module:echarts/model/Component>}
  2138. */
  2139. findComponents: function (condition) {
  2140. var query = condition.query;
  2141. var mainType = condition.mainType;
  2142. var queryCond = getQueryCond(query);
  2143. var result = queryCond
  2144. ? this.queryComponents(queryCond)
  2145. : this._componentsMap[mainType];
  2146. return doFilter(filterBySubType(result, condition));
  2147. function getQueryCond(q) {
  2148. var indexAttr = mainType + 'Index';
  2149. var idAttr = mainType + 'Id';
  2150. var nameAttr = mainType + 'Name';
  2151. return q && (
  2152. q[indexAttr] != null
  2153. || q[idAttr] != null
  2154. || q[nameAttr] != null
  2155. )
  2156. ? {
  2157. mainType: mainType,
  2158. // subType will be filtered finally.
  2159. index: q[indexAttr],
  2160. id: q[idAttr],
  2161. name: q[nameAttr]
  2162. }
  2163. : null;
  2164. }
  2165. function doFilter(res) {
  2166. return condition.filter
  2167. ? filter(res, condition.filter)
  2168. : res;
  2169. }
  2170. },
  2171. /**
  2172. * @usage
  2173. * eachComponent('legend', function (legendModel, index) {
  2174. * ...
  2175. * });
  2176. * eachComponent(function (componentType, model, index) {
  2177. * // componentType does not include subType
  2178. * // (componentType is 'xxx' but not 'xxx.aa')
  2179. * });
  2180. * eachComponent(
  2181. * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}},
  2182. * function (model, index) {...}
  2183. * );
  2184. * eachComponent(
  2185. * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}},
  2186. * function (model, index) {...}
  2187. * );
  2188. *
  2189. * @param {string|Object=} mainType When mainType is object, the definition
  2190. * is the same as the method 'findComponents'.
  2191. * @param {Function} cb
  2192. * @param {*} context
  2193. */
  2194. eachComponent: function (mainType, cb, context) {
  2195. var componentsMap = this._componentsMap;
  2196. if (typeof mainType === 'function') {
  2197. context = cb;
  2198. cb = mainType;
  2199. each(componentsMap, function (components, componentType) {
  2200. each(components, function (component, index) {
  2201. cb.call(context, componentType, component, index);
  2202. });
  2203. });
  2204. }
  2205. else if (zrUtil.isString(mainType)) {
  2206. each(componentsMap[mainType], cb, context);
  2207. }
  2208. else if (isObject(mainType)) {
  2209. var queryResult = this.findComponents(mainType);
  2210. each(queryResult, cb, context);
  2211. }
  2212. },
  2213. /**
  2214. * @param {string} name
  2215. * @return {Array.<module:echarts/model/Series>}
  2216. */
  2217. getSeriesByName: function (name) {
  2218. var series = this._componentsMap.series;
  2219. return filter(series, function (oneSeries) {
  2220. return oneSeries.name === name;
  2221. });
  2222. },
  2223. /**
  2224. * @param {number} seriesIndex
  2225. * @return {module:echarts/model/Series}
  2226. */
  2227. getSeriesByIndex: function (seriesIndex) {
  2228. return this._componentsMap.series[seriesIndex];
  2229. },
  2230. /**
  2231. * @param {string} subType
  2232. * @return {Array.<module:echarts/model/Series>}
  2233. */
  2234. getSeriesByType: function (subType) {
  2235. var series = this._componentsMap.series;
  2236. return filter(series, function (oneSeries) {
  2237. return oneSeries.subType === subType;
  2238. });
  2239. },
  2240. /**
  2241. * @return {Array.<module:echarts/model/Series>}
  2242. */
  2243. getSeries: function () {
  2244. return this._componentsMap.series.slice();
  2245. },
  2246. /**
  2247. * After filtering, series may be different
  2248. * frome raw series.
  2249. *
  2250. * @param {Function} cb
  2251. * @param {*} context
  2252. */
  2253. eachSeries: function (cb, context) {
  2254. assertSeriesInitialized(this);
  2255. each(this._seriesIndices, function (rawSeriesIndex) {
  2256. var series = this._componentsMap.series[rawSeriesIndex];
  2257. cb.call(context, series, rawSeriesIndex);
  2258. }, this);
  2259. },
  2260. /**
  2261. * Iterate raw series before filtered.
  2262. *
  2263. * @param {Function} cb
  2264. * @param {*} context
  2265. */
  2266. eachRawSeries: function (cb, context) {
  2267. each(this._componentsMap.series, cb, context);
  2268. },
  2269. /**
  2270. * After filtering, series may be different.
  2271. * frome raw series.
  2272. *
  2273. * @parma {string} subType
  2274. * @param {Function} cb
  2275. * @param {*} context
  2276. */
  2277. eachSeriesByType: function (subType, cb, context) {
  2278. assertSeriesInitialized(this);
  2279. each(this._seriesIndices, function (rawSeriesIndex) {
  2280. var series = this._componentsMap.series[rawSeriesIndex];
  2281. if (series.subType === subType) {
  2282. cb.call(context, series, rawSeriesIndex);
  2283. }
  2284. }, this);
  2285. },
  2286. /**
  2287. * Iterate raw series before filtered of given type.
  2288. *
  2289. * @parma {string} subType
  2290. * @param {Function} cb
  2291. * @param {*} context
  2292. */
  2293. eachRawSeriesByType: function (subType, cb, context) {
  2294. return each(this.getSeriesByType(subType), cb, context);
  2295. },
  2296. /**
  2297. * @param {module:echarts/model/Series} seriesModel
  2298. */
  2299. isSeriesFiltered: function (seriesModel) {
  2300. assertSeriesInitialized(this);
  2301. return zrUtil.indexOf(this._seriesIndices, seriesModel.componentIndex) < 0;
  2302. },
  2303. /**
  2304. * @param {Function} cb
  2305. * @param {*} context
  2306. */
  2307. filterSeries: function (cb, context) {
  2308. assertSeriesInitialized(this);
  2309. var filteredSeries = filter(
  2310. this._componentsMap.series, cb, context
  2311. );
  2312. this._seriesIndices = createSeriesIndices(filteredSeries);
  2313. },
  2314. restoreData: function () {
  2315. var componentsMap = this._componentsMap;
  2316. this._seriesIndices = createSeriesIndices(componentsMap.series);
  2317. var componentTypes = [];
  2318. each(componentsMap, function (components, componentType) {
  2319. componentTypes.push(componentType);
  2320. });
  2321. ComponentModel.topologicalTravel(
  2322. componentTypes,
  2323. ComponentModel.getAllClassMainTypes(),
  2324. function (componentType, dependencies) {
  2325. each(componentsMap[componentType], function (component) {
  2326. component.restoreData();
  2327. });
  2328. }
  2329. );
  2330. }
  2331. });
  2332. /**
  2333. * @inner
  2334. */
  2335. function mergeTheme(option, theme) {
  2336. zrUtil.each(theme, function (themeItem, name) {
  2337. // 如果有 component model 则把具体的 merge 逻辑交给该 model 处理
  2338. if (!ComponentModel.hasClass(name)) {
  2339. if (typeof themeItem === 'object') {
  2340. option[name] = !option[name]
  2341. ? zrUtil.clone(themeItem)
  2342. : zrUtil.merge(option[name], themeItem, false);
  2343. }
  2344. else {
  2345. if (option[name] == null) {
  2346. option[name] = themeItem;
  2347. }
  2348. }
  2349. }
  2350. });
  2351. }
  2352. function initBase(baseOption) {
  2353. baseOption = baseOption;
  2354. // Using OPTION_INNER_KEY to mark that this option can not be used outside,
  2355. // i.e. `chart.setOption(chart.getModel().option);` is forbiden.
  2356. this.option = {};
  2357. this.option[OPTION_INNER_KEY] = 1;
  2358. /**
  2359. * @type {Object.<string, Array.<module:echarts/model/Model>>}
  2360. * @private
  2361. */
  2362. this._componentsMap = {};
  2363. /**
  2364. * Mapping between filtered series list and raw series list.
  2365. * key: filtered series indices, value: raw series indices.
  2366. * @type {Array.<nubmer>}
  2367. * @private
  2368. */
  2369. this._seriesIndices = null;
  2370. mergeTheme(baseOption, this._theme.option);
  2371. // TODO Needs clone when merging to the unexisted property
  2372. zrUtil.merge(baseOption, globalDefault, false);
  2373. this.mergeOption(baseOption);
  2374. }
  2375. /**
  2376. * @inner
  2377. * @param {Array.<string>|string} types model types
  2378. * @return {Object} key: {string} type, value: {Array.<Object>} models
  2379. */
  2380. function getComponentsByTypes(componentsMap, types) {
  2381. if (!zrUtil.isArray(types)) {
  2382. types = types ? [types] : [];
  2383. }
  2384. var ret = {};
  2385. each(types, function (type) {
  2386. ret[type] = (componentsMap[type] || []).slice();
  2387. });
  2388. return ret;
  2389. }
  2390. /**
  2391. * @inner
  2392. */
  2393. function determineSubType(mainType, newCptOption, existComponent) {
  2394. var subType = newCptOption.type
  2395. ? newCptOption.type
  2396. : existComponent
  2397. ? existComponent.subType
  2398. // Use determineSubType only when there is no existComponent.
  2399. : ComponentModel.determineSubType(mainType, newCptOption);
  2400. // tooltip, markline, markpoint may always has no subType
  2401. return subType;
  2402. }
  2403. /**
  2404. * @inner
  2405. */
  2406. function createSeriesIndices(seriesModels) {
  2407. return map(seriesModels, function (series) {
  2408. return series.componentIndex;
  2409. }) || [];
  2410. }
  2411. /**
  2412. * @inner
  2413. */
  2414. function filterBySubType(components, condition) {
  2415. // Using hasOwnProperty for restrict. Consider
  2416. // subType is undefined in user payload.
  2417. return condition.hasOwnProperty('subType')
  2418. ? filter(components, function (cpt) {
  2419. return cpt.subType === condition.subType;
  2420. })
  2421. : components;
  2422. }
  2423. /**
  2424. * @inner
  2425. */
  2426. function assertSeriesInitialized(ecModel) {
  2427. // Components that use _seriesIndices should depends on series component,
  2428. // which make sure that their initialization is after series.
  2429. if (true) {
  2430. if (!ecModel._seriesIndices) {
  2431. throw new Error('Series has not been initialized yet.');
  2432. }
  2433. }
  2434. }
  2435. zrUtil.mixin(GlobalModel, __webpack_require__(24));
  2436. module.exports = GlobalModel;
  2437. /***/ },
  2438. /* 4 */
  2439. /***/ function(module, exports) {
  2440. /**
  2441. * @module zrender/core/util
  2442. */
  2443. // 用于处理merge时无法遍历Date等对象的问题
  2444. var BUILTIN_OBJECT = {
  2445. '[object Function]': 1,
  2446. '[object RegExp]': 1,
  2447. '[object Date]': 1,
  2448. '[object Error]': 1,
  2449. '[object CanvasGradient]': 1,
  2450. '[object CanvasPattern]': 1,
  2451. // For node-canvas
  2452. '[object Image]': 1,
  2453. '[object Canvas]': 1
  2454. };
  2455. var TYPED_ARRAY = {
  2456. '[object Int8Array]': 1,
  2457. '[object Uint8Array]': 1,
  2458. '[object Uint8ClampedArray]': 1,
  2459. '[object Int16Array]': 1,
  2460. '[object Uint16Array]': 1,
  2461. '[object Int32Array]': 1,
  2462. '[object Uint32Array]': 1,
  2463. '[object Float32Array]': 1,
  2464. '[object Float64Array]': 1
  2465. };
  2466. var objToString = Object.prototype.toString;
  2467. var arrayProto = Array.prototype;
  2468. var nativeForEach = arrayProto.forEach;
  2469. var nativeFilter = arrayProto.filter;
  2470. var nativeSlice = arrayProto.slice;
  2471. var nativeMap = arrayProto.map;
  2472. var nativeReduce = arrayProto.reduce;
  2473. /**
  2474. * Those data types can be cloned:
  2475. * Plain object, Array, TypedArray, number, string, null, undefined.
  2476. * Those data types will be assgined using the orginal data:
  2477. * BUILTIN_OBJECT
  2478. * Instance of user defined class will be cloned to a plain object, without
  2479. * properties in prototype.
  2480. * Other data types is not supported (not sure what will happen).
  2481. *
  2482. * Caution: do not support clone Date, for performance consideration.
  2483. * (There might be a large number of date in `series.data`).
  2484. * So date should not be modified in and out of echarts.
  2485. *
  2486. * @param {*} source
  2487. * @return {*} new
  2488. */
  2489. function clone(source) {
  2490. if (source == null || typeof source != 'object') {
  2491. return source;
  2492. }
  2493. var result = source;
  2494. var typeStr = objToString.call(source);
  2495. if (typeStr === '[object Array]') {
  2496. result = [];
  2497. for (var i = 0, len = source.length; i < len; i++) {
  2498. result[i] = clone(source[i]);
  2499. }
  2500. }
  2501. else if (TYPED_ARRAY[typeStr]) {
  2502. result = source.constructor.from(source);
  2503. }
  2504. else if (!BUILTIN_OBJECT[typeStr] && !isDom(source)) {
  2505. result = {};
  2506. for (var key in source) {
  2507. if (source.hasOwnProperty(key)) {
  2508. result[key] = clone(source[key]);
  2509. }
  2510. }
  2511. }
  2512. return result;
  2513. }
  2514. /**
  2515. * @memberOf module:zrender/core/util
  2516. * @param {*} target
  2517. * @param {*} source
  2518. * @param {boolean} [overwrite=false]
  2519. */
  2520. function merge(target, source, overwrite) {
  2521. // We should escapse that source is string
  2522. // and enter for ... in ...
  2523. if (!isObject(source) || !isObject(target)) {
  2524. return overwrite ? clone(source) : target;
  2525. }
  2526. for (var key in source) {
  2527. if (source.hasOwnProperty(key)) {
  2528. var targetProp = target[key];
  2529. var sourceProp = source[key];
  2530. if (isObject(sourceProp)
  2531. && isObject(targetProp)
  2532. && !isArray(sourceProp)
  2533. && !isArray(targetProp)
  2534. && !isDom(sourceProp)
  2535. && !isDom(targetProp)
  2536. && !isBuildInObject(sourceProp)
  2537. && !isBuildInObject(targetProp)
  2538. ) {
  2539. // 如果需要递归覆盖,就递归调用merge
  2540. merge(targetProp, sourceProp, overwrite);
  2541. }
  2542. else if (overwrite || !(key in target)) {
  2543. // 否则只处理overwrite为true,或者在目标对象中没有此属性的情况
  2544. // NOTE,在 target[key] 不存在的时候也是直接覆盖
  2545. target[key] = clone(source[key], true);
  2546. }
  2547. }
  2548. }
  2549. return target;
  2550. }
  2551. /**
  2552. * @param {Array} targetAndSources The first item is target, and the rests are source.
  2553. * @param {boolean} [overwrite=false]
  2554. * @return {*} target
  2555. */
  2556. function mergeAll(targetAndSources, overwrite) {
  2557. var result = targetAndSources[0];
  2558. for (var i = 1, len = targetAndSources.length; i < len; i++) {
  2559. result = merge(result, targetAndSources[i], overwrite);
  2560. }
  2561. return result;
  2562. }
  2563. /**
  2564. * @param {*} target
  2565. * @param {*} source
  2566. * @memberOf module:zrender/core/util
  2567. */
  2568. function extend(target, source) {
  2569. for (var key in source) {
  2570. if (source.hasOwnProperty(key)) {
  2571. target[key] = source[key];
  2572. }
  2573. }
  2574. return target;
  2575. }
  2576. /**
  2577. * @param {*} target
  2578. * @param {*} source
  2579. * @param {boolen} [overlay=false]
  2580. * @memberOf module:zrender/core/util
  2581. */
  2582. function defaults(target, source, overlay) {
  2583. for (var key in source) {
  2584. if (source.hasOwnProperty(key)
  2585. && (overlay ? source[key] != null : target[key] == null)
  2586. ) {
  2587. target[key] = source[key];
  2588. }
  2589. }
  2590. return target;
  2591. }
  2592. function createCanvas() {
  2593. return document.createElement('canvas');
  2594. }
  2595. // FIXME
  2596. var _ctx;
  2597. function getContext() {
  2598. if (!_ctx) {
  2599. // Use util.createCanvas instead of createCanvas
  2600. // because createCanvas may be overwritten in different environment
  2601. _ctx = util.createCanvas().getContext('2d');
  2602. }
  2603. return _ctx;
  2604. }
  2605. /**
  2606. * 查询数组中元素的index
  2607. * @memberOf module:zrender/core/util
  2608. */
  2609. function indexOf(array, value) {
  2610. if (array) {
  2611. if (array.indexOf) {
  2612. return array.indexOf(value);
  2613. }
  2614. for (var i = 0, len = array.length; i < len; i++) {
  2615. if (array[i] === value) {
  2616. return i;
  2617. }
  2618. }
  2619. }
  2620. return -1;
  2621. }
  2622. /**
  2623. * 构造类继承关系
  2624. *
  2625. * @memberOf module:zrender/core/util
  2626. * @param {Function} clazz 源类
  2627. * @param {Function} baseClazz 基类
  2628. */
  2629. function inherits(clazz, baseClazz) {
  2630. var clazzPrototype = clazz.prototype;
  2631. function F() {}
  2632. F.prototype = baseClazz.prototype;
  2633. clazz.prototype = new F();
  2634. for (var prop in clazzPrototype) {
  2635. clazz.prototype[prop] = clazzPrototype[prop];
  2636. }
  2637. clazz.prototype.constructor = clazz;
  2638. clazz.superClass = baseClazz;
  2639. }
  2640. /**
  2641. * @memberOf module:zrender/core/util
  2642. * @param {Object|Function} target
  2643. * @param {Object|Function} sorce
  2644. * @param {boolean} overlay
  2645. */
  2646. function mixin(target, source, overlay) {
  2647. target = 'prototype' in target ? target.prototype : target;
  2648. source = 'prototype' in source ? source.prototype : source;
  2649. defaults(target, source, overlay);
  2650. }
  2651. /**
  2652. * @param {Array|TypedArray} data
  2653. */
  2654. function isArrayLike(data) {
  2655. if (! data) {
  2656. return;
  2657. }
  2658. if (typeof data == 'string') {
  2659. return false;
  2660. }
  2661. return typeof data.length == 'number';
  2662. }
  2663. /**
  2664. * 数组或对象遍历
  2665. * @memberOf module:zrender/core/util
  2666. * @param {Object|Array} obj
  2667. * @param {Function} cb
  2668. * @param {*} [context]
  2669. */
  2670. function each(obj, cb, context) {
  2671. if (!(obj && cb)) {
  2672. return;
  2673. }
  2674. if (obj.forEach && obj.forEach === nativeForEach) {
  2675. obj.forEach(cb, context);
  2676. }
  2677. else if (obj.length === +obj.length) {
  2678. for (var i = 0, len = obj.length; i < len; i++) {
  2679. cb.call(context, obj[i], i, obj);
  2680. }
  2681. }
  2682. else {
  2683. for (var key in obj) {
  2684. if (obj.hasOwnProperty(key)) {
  2685. cb.call(context, obj[key], key, obj);
  2686. }
  2687. }
  2688. }
  2689. }
  2690. /**
  2691. * 数组映射
  2692. * @memberOf module:zrender/core/util
  2693. * @param {Array} obj
  2694. * @param {Function} cb
  2695. * @param {*} [context]
  2696. * @return {Array}
  2697. */
  2698. function map(obj, cb, context) {
  2699. if (!(obj && cb)) {
  2700. return;
  2701. }
  2702. if (obj.map && obj.map === nativeMap) {
  2703. return obj.map(cb, context);
  2704. }
  2705. else {
  2706. var result = [];
  2707. for (var i = 0, len = obj.length; i < len; i++) {
  2708. result.push(cb.call(context, obj[i], i, obj));
  2709. }
  2710. return result;
  2711. }
  2712. }
  2713. /**
  2714. * @memberOf module:zrender/core/util
  2715. * @param {Array} obj
  2716. * @param {Function} cb
  2717. * @param {Object} [memo]
  2718. * @param {*} [context]
  2719. * @return {Array}
  2720. */
  2721. function reduce(obj, cb, memo, context) {
  2722. if (!(obj && cb)) {
  2723. return;
  2724. }
  2725. if (obj.reduce && obj.reduce === nativeReduce) {
  2726. return obj.reduce(cb, memo, context);
  2727. }
  2728. else {
  2729. for (var i = 0, len = obj.length; i < len; i++) {
  2730. memo = cb.call(context, memo, obj[i], i, obj);
  2731. }
  2732. return memo;
  2733. }
  2734. }
  2735. /**
  2736. * 数组过滤
  2737. * @memberOf module:zrender/core/util
  2738. * @param {Array} obj
  2739. * @param {Function} cb
  2740. * @param {*} [context]
  2741. * @return {Array}
  2742. */
  2743. function filter(obj, cb, context) {
  2744. if (!(obj && cb)) {
  2745. return;
  2746. }
  2747. if (obj.filter && obj.filter === nativeFilter) {
  2748. return obj.filter(cb, context);
  2749. }
  2750. else {
  2751. var result = [];
  2752. for (var i = 0, len = obj.length; i < len; i++) {
  2753. if (cb.call(context, obj[i], i, obj)) {
  2754. result.push(obj[i]);
  2755. }
  2756. }
  2757. return result;
  2758. }
  2759. }
  2760. /**
  2761. * 数组项查找
  2762. * @memberOf module:zrender/core/util
  2763. * @param {Array} obj
  2764. * @param {Function} cb
  2765. * @param {*} [context]
  2766. * @return {Array}
  2767. */
  2768. function find(obj, cb, context) {
  2769. if (!(obj && cb)) {
  2770. return;
  2771. }
  2772. for (var i = 0, len = obj.length; i < len; i++) {
  2773. if (cb.call(context, obj[i], i, obj)) {
  2774. return obj[i];
  2775. }
  2776. }
  2777. }
  2778. /**
  2779. * @memberOf module:zrender/core/util
  2780. * @param {Function} func
  2781. * @param {*} context
  2782. * @return {Function}
  2783. */
  2784. function bind(func, context) {
  2785. var args = nativeSlice.call(arguments, 2);
  2786. return function () {
  2787. return func.apply(context, args.concat(nativeSlice.call(arguments)));
  2788. };
  2789. }
  2790. /**
  2791. * @memberOf module:zrender/core/util
  2792. * @param {Function} func
  2793. * @return {Function}
  2794. */
  2795. function curry(func) {
  2796. var args = nativeSlice.call(arguments, 1);
  2797. return function () {
  2798. return func.apply(this, args.concat(nativeSlice.call(arguments)));
  2799. };
  2800. }
  2801. /**
  2802. * @memberOf module:zrender/core/util
  2803. * @param {*} value
  2804. * @return {boolean}
  2805. */
  2806. function isArray(value) {
  2807. return objToString.call(value) === '[object Array]';
  2808. }
  2809. /**
  2810. * @memberOf module:zrender/core/util
  2811. * @param {*} value
  2812. * @return {boolean}
  2813. */
  2814. function isFunction(value) {
  2815. return typeof value === 'function';
  2816. }
  2817. /**
  2818. * @memberOf module:zrender/core/util
  2819. * @param {*} value
  2820. * @return {boolean}
  2821. */
  2822. function isString(value) {
  2823. return objToString.call(value) === '[object String]';
  2824. }
  2825. /**
  2826. * @memberOf module:zrender/core/util
  2827. * @param {*} value
  2828. * @return {boolean}
  2829. */
  2830. function isObject(value) {
  2831. // Avoid a V8 JIT bug in Chrome 19-20.
  2832. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  2833. var type = typeof value;
  2834. return type === 'function' || (!!value && type == 'object');
  2835. }
  2836. /**
  2837. * @memberOf module:zrender/core/util
  2838. * @param {*} value
  2839. * @return {boolean}
  2840. */
  2841. function isBuildInObject(value) {
  2842. return !!BUILTIN_OBJECT[objToString.call(value)];
  2843. }
  2844. /**
  2845. * @memberOf module:zrender/core/util
  2846. * @param {*} value
  2847. * @return {boolean}
  2848. */
  2849. function isDom(value) {
  2850. return typeof value === 'object'
  2851. && typeof value.nodeType === 'number'
  2852. && typeof value.ownerDocument === 'object';
  2853. }
  2854. /**
  2855. * Whether is exactly NaN. Notice isNaN('a') returns true.
  2856. * @param {*} value
  2857. * @return {boolean}
  2858. */
  2859. function eqNaN(value) {
  2860. return value !== value;
  2861. }
  2862. /**
  2863. * If value1 is not null, then return value1, otherwise judget rest of values.
  2864. * @memberOf module:zrender/core/util
  2865. * @return {*} Final value
  2866. */
  2867. function retrieve(values) {
  2868. for (var i = 0, len = arguments.length; i < len; i++) {
  2869. if (arguments[i] != null) {
  2870. return arguments[i];
  2871. }
  2872. }
  2873. }
  2874. /**
  2875. * @memberOf module:zrender/core/util
  2876. * @param {Array} arr
  2877. * @param {number} startIndex
  2878. * @param {number} endIndex
  2879. * @return {Array}
  2880. */
  2881. function slice() {
  2882. return Function.call.apply(nativeSlice, arguments);
  2883. }
  2884. /**
  2885. * @memberOf module:zrender/core/util
  2886. * @param {boolean} condition
  2887. * @param {string} message
  2888. */
  2889. function assert(condition, message) {
  2890. if (!condition) {
  2891. throw new Error(message);
  2892. }
  2893. }
  2894. var util = {
  2895. inherits: inherits,
  2896. mixin: mixin,
  2897. clone: clone,
  2898. merge: merge,
  2899. mergeAll: mergeAll,
  2900. extend: extend,
  2901. defaults: defaults,
  2902. getContext: getContext,
  2903. createCanvas: createCanvas,
  2904. indexOf: indexOf,
  2905. slice: slice,
  2906. find: find,
  2907. isArrayLike: isArrayLike,
  2908. each: each,
  2909. map: map,
  2910. reduce: reduce,
  2911. filter: filter,
  2912. bind: bind,
  2913. curry: curry,
  2914. isArray: isArray,
  2915. isString: isString,
  2916. isObject: isObject,
  2917. isFunction: isFunction,
  2918. isBuildInObject: isBuildInObject,
  2919. isDom: isDom,
  2920. eqNaN: eqNaN,
  2921. retrieve: retrieve,
  2922. assert: assert,
  2923. noop: function () {}
  2924. };
  2925. module.exports = util;
  2926. /***/ },
  2927. /* 5 */
  2928. /***/ function(module, exports, __webpack_require__) {
  2929. var formatUtil = __webpack_require__(6);
  2930. var nubmerUtil = __webpack_require__(7);
  2931. var Model = __webpack_require__(12);
  2932. var zrUtil = __webpack_require__(4);
  2933. var each = zrUtil.each;
  2934. var isObject = zrUtil.isObject;
  2935. var modelUtil = {};
  2936. /**
  2937. * If value is not array, then translate it to array.
  2938. * @param {*} value
  2939. * @return {Array} [value] or value
  2940. */
  2941. modelUtil.normalizeToArray = function (value) {
  2942. return value instanceof Array
  2943. ? value
  2944. : value == null
  2945. ? []
  2946. : [value];
  2947. };
  2948. /**
  2949. * Sync default option between normal and emphasis like `position` and `show`
  2950. * In case some one will write code like
  2951. * label: {
  2952. * normal: {
  2953. * show: false,
  2954. * position: 'outside',
  2955. * textStyle: {
  2956. * fontSize: 18
  2957. * }
  2958. * },
  2959. * emphasis: {
  2960. * show: true
  2961. * }
  2962. * }
  2963. * @param {Object} opt
  2964. * @param {Array.<string>} subOpts
  2965. */
  2966. modelUtil.defaultEmphasis = function (opt, subOpts) {
  2967. if (opt) {
  2968. var emphasisOpt = opt.emphasis = opt.emphasis || {};
  2969. var normalOpt = opt.normal = opt.normal || {};
  2970. // Default emphasis option from normal
  2971. each(subOpts, function (subOptName) {
  2972. var val = zrUtil.retrieve(emphasisOpt[subOptName], normalOpt[subOptName]);
  2973. if (val != null) {
  2974. emphasisOpt[subOptName] = val;
  2975. }
  2976. });
  2977. }
  2978. };
  2979. modelUtil.LABEL_OPTIONS = ['position', 'offset', 'show', 'textStyle', 'distance', 'formatter'];
  2980. /**
  2981. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  2982. * This helper method retieves value from data.
  2983. * @param {string|number|Date|Array|Object} dataItem
  2984. * @return {number|string|Date|Array.<number|string|Date>}
  2985. */
  2986. modelUtil.getDataItemValue = function (dataItem) {
  2987. // Performance sensitive.
  2988. return dataItem && (dataItem.value == null ? dataItem : dataItem.value);
  2989. };
  2990. /**
  2991. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  2992. * This helper method determine if dataItem has extra option besides value
  2993. * @param {string|number|Date|Array|Object} dataItem
  2994. */
  2995. modelUtil.isDataItemOption = function (dataItem) {
  2996. return isObject(dataItem)
  2997. && !(dataItem instanceof Array);
  2998. // // markLine data can be array
  2999. // && !(dataItem[0] && isObject(dataItem[0]) && !(dataItem[0] instanceof Array));
  3000. };
  3001. /**
  3002. * This helper method convert value in data.
  3003. * @param {string|number|Date} value
  3004. * @param {Object|string} [dimInfo] If string (like 'x'), dimType defaults 'number'.
  3005. */
  3006. modelUtil.converDataValue = function (value, dimInfo) {
  3007. // Performance sensitive.
  3008. var dimType = dimInfo && dimInfo.type;
  3009. if (dimType === 'ordinal') {
  3010. return value;
  3011. }
  3012. if (dimType === 'time' && !isFinite(value) && value != null && value !== '-') {
  3013. value = +nubmerUtil.parseDate(value);
  3014. }
  3015. // dimType defaults 'number'.
  3016. // If dimType is not ordinal and value is null or undefined or NaN or '-',
  3017. // parse to NaN.
  3018. return (value == null || value === '')
  3019. ? NaN : +value; // If string (like '-'), using '+' parse to NaN
  3020. };
  3021. /**
  3022. * Create a model proxy to be used in tooltip for edge data, markLine data, markPoint data.
  3023. * @param {module:echarts/data/List} data
  3024. * @param {Object} opt
  3025. * @param {string} [opt.seriesIndex]
  3026. * @param {Object} [opt.name]
  3027. * @param {Object} [opt.mainType]
  3028. * @param {Object} [opt.subType]
  3029. */
  3030. modelUtil.createDataFormatModel = function (data, opt) {
  3031. var model = new Model();
  3032. zrUtil.mixin(model, modelUtil.dataFormatMixin);
  3033. model.seriesIndex = opt.seriesIndex;
  3034. model.name = opt.name || '';
  3035. model.mainType = opt.mainType;
  3036. model.subType = opt.subType;
  3037. model.getData = function () {
  3038. return data;
  3039. };
  3040. return model;
  3041. };
  3042. // PENDING A little ugly
  3043. modelUtil.dataFormatMixin = {
  3044. /**
  3045. * Get params for formatter
  3046. * @param {number} dataIndex
  3047. * @param {string} [dataType]
  3048. * @return {Object}
  3049. */
  3050. getDataParams: function (dataIndex, dataType) {
  3051. var data = this.getData(dataType);
  3052. var seriesIndex = this.seriesIndex;
  3053. var seriesName = this.name;
  3054. var rawValue = this.getRawValue(dataIndex, dataType);
  3055. var rawDataIndex = data.getRawIndex(dataIndex);
  3056. var name = data.getName(dataIndex, true);
  3057. var itemOpt = data.getRawDataItem(dataIndex);
  3058. return {
  3059. componentType: this.mainType,
  3060. componentSubType: this.subType,
  3061. seriesType: this.mainType === 'series' ? this.subType : null,
  3062. seriesIndex: seriesIndex,
  3063. seriesName: seriesName,
  3064. name: name,
  3065. dataIndex: rawDataIndex,
  3066. data: itemOpt,
  3067. dataType: dataType,
  3068. value: rawValue,
  3069. color: data.getItemVisual(dataIndex, 'color'),
  3070. // Param name list for mapping `a`, `b`, `c`, `d`, `e`
  3071. $vars: ['seriesName', 'name', 'value']
  3072. };
  3073. },
  3074. /**
  3075. * Format label
  3076. * @param {number} dataIndex
  3077. * @param {string} [status='normal'] 'normal' or 'emphasis'
  3078. * @param {string} [dataType]
  3079. * @param {number} [dimIndex]
  3080. * @return {string}
  3081. */
  3082. getFormattedLabel: function (dataIndex, status, dataType, dimIndex) {
  3083. status = status || 'normal';
  3084. var data = this.getData(dataType);
  3085. var itemModel = data.getItemModel(dataIndex);
  3086. var params = this.getDataParams(dataIndex, dataType);
  3087. if (dimIndex != null && (params.value instanceof Array)) {
  3088. params.value = params.value[dimIndex];
  3089. }
  3090. var formatter = itemModel.get(['label', status, 'formatter']);
  3091. if (typeof formatter === 'function') {
  3092. params.status = status;
  3093. return formatter(params);
  3094. }
  3095. else if (typeof formatter === 'string') {
  3096. return formatUtil.formatTpl(formatter, params);
  3097. }
  3098. },
  3099. /**
  3100. * Get raw value in option
  3101. * @param {number} idx
  3102. * @param {string} [dataType]
  3103. * @return {Object}
  3104. */
  3105. getRawValue: function (idx, dataType) {
  3106. var data = this.getData(dataType);
  3107. var dataItem = data.getRawDataItem(idx);
  3108. if (dataItem != null) {
  3109. return (isObject(dataItem) && !(dataItem instanceof Array))
  3110. ? dataItem.value : dataItem;
  3111. }
  3112. },
  3113. /**
  3114. * Should be implemented.
  3115. * @param {number} dataIndex
  3116. * @param {boolean} [multipleSeries=false]
  3117. * @param {number} [dataType]
  3118. * @return {string} tooltip string
  3119. */
  3120. formatTooltip: zrUtil.noop
  3121. };
  3122. /**
  3123. * Mapping to exists for merge.
  3124. *
  3125. * @public
  3126. * @param {Array.<Object>|Array.<module:echarts/model/Component>} exists
  3127. * @param {Object|Array.<Object>} newCptOptions
  3128. * @return {Array.<Object>} Result, like [{exist: ..., option: ...}, {}],
  3129. * index of which is the same as exists.
  3130. */
  3131. modelUtil.mappingToExists = function (exists, newCptOptions) {
  3132. // Mapping by the order by original option (but not order of
  3133. // new option) in merge mode. Because we should ensure
  3134. // some specified index (like xAxisIndex) is consistent with
  3135. // original option, which is easy to understand, espatially in
  3136. // media query. And in most case, merge option is used to
  3137. // update partial option but not be expected to change order.
  3138. newCptOptions = (newCptOptions || []).slice();
  3139. var result = zrUtil.map(exists || [], function (obj, index) {
  3140. return {exist: obj};
  3141. });
  3142. // Mapping by id or name if specified.
  3143. each(newCptOptions, function (cptOption, index) {
  3144. if (!isObject(cptOption)) {
  3145. return;
  3146. }
  3147. // id has highest priority.
  3148. for (var i = 0; i < result.length; i++) {
  3149. if (!result[i].option // Consider name: two map to one.
  3150. && cptOption.id != null
  3151. && result[i].exist.id === cptOption.id + ''
  3152. ) {
  3153. result[i].option = cptOption;
  3154. newCptOptions[index] = null;
  3155. return;
  3156. }
  3157. }
  3158. for (var i = 0; i < result.length; i++) {
  3159. var exist = result[i].exist;
  3160. if (!result[i].option // Consider name: two map to one.
  3161. // Can not match when both ids exist but different.
  3162. && (exist.id == null || cptOption.id == null)
  3163. && cptOption.name != null
  3164. && !modelUtil.isIdInner(cptOption)
  3165. && !modelUtil.isIdInner(exist)
  3166. && exist.name === cptOption.name + ''
  3167. ) {
  3168. result[i].option = cptOption;
  3169. newCptOptions[index] = null;
  3170. return;
  3171. }
  3172. }
  3173. });
  3174. // Otherwise mapping by index.
  3175. each(newCptOptions, function (cptOption, index) {
  3176. if (!isObject(cptOption)) {
  3177. return;
  3178. }
  3179. var i = 0;
  3180. for (; i < result.length; i++) {
  3181. var exist = result[i].exist;
  3182. if (!result[i].option
  3183. // Existing model that already has id should be able to
  3184. // mapped to (because after mapping performed model may
  3185. // be assigned with a id, whish should not affect next
  3186. // mapping), except those has inner id.
  3187. && !modelUtil.isIdInner(exist)
  3188. // Caution:
  3189. // Do not overwrite id. But name can be overwritten,
  3190. // because axis use name as 'show label text'.
  3191. // 'exist' always has id and name and we dont
  3192. // need to check it.
  3193. && cptOption.id == null
  3194. ) {
  3195. result[i].option = cptOption;
  3196. break;
  3197. }
  3198. }
  3199. if (i >= result.length) {
  3200. result.push({option: cptOption});
  3201. }
  3202. });
  3203. return result;
  3204. };
  3205. /**
  3206. * Make id and name for mapping result (result of mappingToExists)
  3207. * into `keyInfo` field.
  3208. *
  3209. * @public
  3210. * @param {Array.<Object>} Result, like [{exist: ..., option: ...}, {}],
  3211. * which order is the same as exists.
  3212. * @return {Array.<Object>} The input.
  3213. */
  3214. modelUtil.makeIdAndName = function (mapResult) {
  3215. // We use this id to hash component models and view instances
  3216. // in echarts. id can be specified by user, or auto generated.
  3217. // The id generation rule ensures new view instance are able
  3218. // to mapped to old instance when setOption are called in
  3219. // no-merge mode. So we generate model id by name and plus
  3220. // type in view id.
  3221. // name can be duplicated among components, which is convenient
  3222. // to specify multi components (like series) by one name.
  3223. // Ensure that each id is distinct.
  3224. var idMap = {};
  3225. each(mapResult, function (item, index) {
  3226. var existCpt = item.exist;
  3227. existCpt && (idMap[existCpt.id] = item);
  3228. });
  3229. each(mapResult, function (item, index) {
  3230. var opt = item.option;
  3231. zrUtil.assert(
  3232. !opt || opt.id == null || !idMap[opt.id] || idMap[opt.id] === item,
  3233. 'id duplicates: ' + (opt && opt.id)
  3234. );
  3235. opt && opt.id != null && (idMap[opt.id] = item);
  3236. !item.keyInfo && (item.keyInfo = {});
  3237. });
  3238. // Make name and id.
  3239. each(mapResult, function (item, index) {
  3240. var existCpt = item.exist;
  3241. var opt = item.option;
  3242. var keyInfo = item.keyInfo;
  3243. if (!isObject(opt)) {
  3244. return;
  3245. }
  3246. // name can be overwitten. Consider case: axis.name = '20km'.
  3247. // But id generated by name will not be changed, which affect
  3248. // only in that case: setOption with 'not merge mode' and view
  3249. // instance will be recreated, which can be accepted.
  3250. keyInfo.name = opt.name != null
  3251. ? opt.name + ''
  3252. : existCpt
  3253. ? existCpt.name
  3254. : '\0-';
  3255. if (existCpt) {
  3256. keyInfo.id = existCpt.id;
  3257. }
  3258. else if (opt.id != null) {
  3259. keyInfo.id = opt.id + '';
  3260. }
  3261. else {
  3262. // Consider this situatoin:
  3263. // optionA: [{name: 'a'}, {name: 'a'}, {..}]
  3264. // optionB [{..}, {name: 'a'}, {name: 'a'}]
  3265. // Series with the same name between optionA and optionB
  3266. // should be mapped.
  3267. var idNum = 0;
  3268. do {
  3269. keyInfo.id = '\0' + keyInfo.name + '\0' + idNum++;
  3270. }
  3271. while (idMap[keyInfo.id]);
  3272. }
  3273. idMap[keyInfo.id] = item;
  3274. });
  3275. };
  3276. /**
  3277. * @public
  3278. * @param {Object} cptOption
  3279. * @return {boolean}
  3280. */
  3281. modelUtil.isIdInner = function (cptOption) {
  3282. return isObject(cptOption)
  3283. && cptOption.id
  3284. && (cptOption.id + '').indexOf('\0_ec_\0') === 0;
  3285. };
  3286. /**
  3287. * A helper for removing duplicate items between batchA and batchB,
  3288. * and in themselves, and categorize by series.
  3289. *
  3290. * @param {Array.<Object>} batchA Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
  3291. * @param {Array.<Object>} batchB Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
  3292. * @return {Array.<Array.<Object>, Array.<Object>>} result: [resultBatchA, resultBatchB]
  3293. */
  3294. modelUtil.compressBatches = function (batchA, batchB) {
  3295. var mapA = {};
  3296. var mapB = {};
  3297. makeMap(batchA || [], mapA);
  3298. makeMap(batchB || [], mapB, mapA);
  3299. return [mapToArray(mapA), mapToArray(mapB)];
  3300. function makeMap(sourceBatch, map, otherMap) {
  3301. for (var i = 0, len = sourceBatch.length; i < len; i++) {
  3302. var seriesId = sourceBatch[i].seriesId;
  3303. var dataIndices = modelUtil.normalizeToArray(sourceBatch[i].dataIndex);
  3304. var otherDataIndices = otherMap && otherMap[seriesId];
  3305. for (var j = 0, lenj = dataIndices.length; j < lenj; j++) {
  3306. var dataIndex = dataIndices[j];
  3307. if (otherDataIndices && otherDataIndices[dataIndex]) {
  3308. otherDataIndices[dataIndex] = null;
  3309. }
  3310. else {
  3311. (map[seriesId] || (map[seriesId] = {}))[dataIndex] = 1;
  3312. }
  3313. }
  3314. }
  3315. }
  3316. function mapToArray(map, isData) {
  3317. var result = [];
  3318. for (var i in map) {
  3319. if (map.hasOwnProperty(i) && map[i] != null) {
  3320. if (isData) {
  3321. result.push(+i);
  3322. }
  3323. else {
  3324. var dataIndices = mapToArray(map[i], true);
  3325. dataIndices.length && result.push({seriesId: i, dataIndex: dataIndices});
  3326. }
  3327. }
  3328. }
  3329. return result;
  3330. }
  3331. };
  3332. /**
  3333. * @param {module:echarts/data/List} data
  3334. * @param {Object} payload Contains dataIndex (means rawIndex) / dataIndexInside / name
  3335. * each of which can be Array or primary type.
  3336. * @return {number|Array.<number>} dataIndex If not found, return undefined/null.
  3337. */
  3338. modelUtil.queryDataIndex = function (data, payload) {
  3339. if (payload.dataIndexInside != null) {
  3340. return payload.dataIndexInside;
  3341. }
  3342. else if (payload.dataIndex != null) {
  3343. return zrUtil.isArray(payload.dataIndex)
  3344. ? zrUtil.map(payload.dataIndex, function (value) {
  3345. return data.indexOfRawIndex(value);
  3346. })
  3347. : data.indexOfRawIndex(payload.dataIndex);
  3348. }
  3349. else if (payload.name != null) {
  3350. return zrUtil.isArray(payload.name)
  3351. ? zrUtil.map(payload.name, function (value) {
  3352. return data.indexOfName(value);
  3353. })
  3354. : data.indexOfName(payload.name);
  3355. }
  3356. };
  3357. /**
  3358. * @param {module:echarts/model/Global} ecModel
  3359. * @param {string|Object} finder
  3360. * If string, e.g., 'geo', means {geoIndex: 0}.
  3361. * If Object, could contain some of these properties below:
  3362. * {
  3363. * seriesIndex, seriesId, seriesName,
  3364. * geoIndex, geoId, goeName,
  3365. * bmapIndex, bmapId, bmapName,
  3366. * xAxisIndex, xAxisId, xAxisName,
  3367. * yAxisIndex, yAxisId, yAxisName,
  3368. * gridIndex, gridId, gridName,
  3369. * ... (can be extended)
  3370. * }
  3371. * Each properties can be number|string|Array.<number>|Array.<string>
  3372. * For example, a finder could be
  3373. * {
  3374. * seriesIndex: 3,
  3375. * geoId: ['aa', 'cc'],
  3376. * gridName: ['xx', 'rr']
  3377. * }
  3378. * @param {Object} [opt]
  3379. * @param {string} [opt.defaultMainType]
  3380. * @return {Object} result like:
  3381. * {
  3382. * seriesModels: [seriesModel1, seriesModel2],
  3383. * seriesModel: seriesModel1, // The first model
  3384. * geoModels: [geoModel1, geoModel2],
  3385. * geoModel: geoModel1, // The first model
  3386. * ...
  3387. * }
  3388. */
  3389. modelUtil.parseFinder = function (ecModel, finder, opt) {
  3390. if (zrUtil.isString(finder)) {
  3391. var obj = {};
  3392. obj[finder + 'Index'] = 0;
  3393. finder = obj;
  3394. }
  3395. var defaultMainType = opt && opt.defaultMainType;
  3396. if (defaultMainType
  3397. && !has(finder, defaultMainType + 'Index')
  3398. && !has(finder, defaultMainType + 'Id')
  3399. && !has(finder, defaultMainType + 'Name')
  3400. ) {
  3401. finder[defaultMainType + 'Index'] = 0;
  3402. }
  3403. var result = {};
  3404. each(finder, function (value, key) {
  3405. var value = finder[key];
  3406. // Exclude 'dataIndex' and other illgal keys.
  3407. if (key === 'dataIndex' || key === 'dataIndexInside') {
  3408. result[key] = value;
  3409. return;
  3410. }
  3411. var parsedKey = key.match(/^(\w+)(Index|Id|Name)$/) || [];
  3412. var mainType = parsedKey[1];
  3413. var queryType = parsedKey[2];
  3414. if (!mainType || !queryType) {
  3415. return;
  3416. }
  3417. var queryParam = {mainType: mainType};
  3418. queryParam[queryType.toLowerCase()] = value;
  3419. var models = ecModel.queryComponents(queryParam);
  3420. result[mainType + 'Models'] = models;
  3421. result[mainType + 'Model'] = models[0];
  3422. });
  3423. return result;
  3424. };
  3425. function has(obj, prop) {
  3426. return obj && obj.hasOwnProperty(prop);
  3427. }
  3428. module.exports = modelUtil;
  3429. /***/ },
  3430. /* 6 */
  3431. /***/ function(module, exports, __webpack_require__) {
  3432. var zrUtil = __webpack_require__(4);
  3433. var numberUtil = __webpack_require__(7);
  3434. var textContain = __webpack_require__(8);
  3435. var formatUtil = {};
  3436. /**
  3437. * 每三位默认加,格式化
  3438. * @type {string|number} x
  3439. */
  3440. formatUtil.addCommas = function (x) {
  3441. if (isNaN(x)) {
  3442. return '-';
  3443. }
  3444. x = (x + '').split('.');
  3445. return x[0].replace(/(\d{1,3})(?=(?:\d{3})+(?!\d))/g,'$1,')
  3446. + (x.length > 1 ? ('.' + x[1]) : '');
  3447. };
  3448. /**
  3449. * @param {string} str
  3450. * @param {boolean} [upperCaseFirst=false]
  3451. * @return {string} str
  3452. */
  3453. formatUtil.toCamelCase = function (str, upperCaseFirst) {
  3454. str = (str || '').toLowerCase().replace(/-(.)/g, function(match, group1) {
  3455. return group1.toUpperCase();
  3456. });
  3457. if (upperCaseFirst && str) {
  3458. str = str.charAt(0).toUpperCase() + str.slice(1);
  3459. }
  3460. return str;
  3461. };
  3462. /**
  3463. * Normalize css liked array configuration
  3464. * e.g.
  3465. * 3 => [3, 3, 3, 3]
  3466. * [4, 2] => [4, 2, 4, 2]
  3467. * [4, 3, 2] => [4, 3, 2, 3]
  3468. * @param {number|Array.<number>} val
  3469. */
  3470. formatUtil.normalizeCssArray = function (val) {
  3471. var len = val.length;
  3472. if (typeof (val) === 'number') {
  3473. return [val, val, val, val];
  3474. }
  3475. else if (len === 2) {
  3476. // vertical | horizontal
  3477. return [val[0], val[1], val[0], val[1]];
  3478. }
  3479. else if (len === 3) {
  3480. // top | horizontal | bottom
  3481. return [val[0], val[1], val[2], val[1]];
  3482. }
  3483. return val;
  3484. };
  3485. var encodeHTML = formatUtil.encodeHTML = function (source) {
  3486. return String(source)
  3487. .replace(/&/g, '&amp;')
  3488. .replace(/</g, '&lt;')
  3489. .replace(/>/g, '&gt;')
  3490. .replace(/"/g, '&quot;')
  3491. .replace(/'/g, '&#39;');
  3492. };
  3493. var TPL_VAR_ALIAS = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
  3494. var wrapVar = function (varName, seriesIdx) {
  3495. return '{' + varName + (seriesIdx == null ? '' : seriesIdx) + '}';
  3496. };
  3497. /**
  3498. * Template formatter
  3499. * @param {string} tpl
  3500. * @param {Array.<Object>|Object} paramsList
  3501. * @param {boolean} [encode=false]
  3502. * @return {string}
  3503. */
  3504. formatUtil.formatTpl = function (tpl, paramsList, encode) {
  3505. if (!zrUtil.isArray(paramsList)) {
  3506. paramsList = [paramsList];
  3507. }
  3508. var seriesLen = paramsList.length;
  3509. if (!seriesLen) {
  3510. return '';
  3511. }
  3512. var $vars = paramsList[0].$vars || [];
  3513. for (var i = 0; i < $vars.length; i++) {
  3514. var alias = TPL_VAR_ALIAS[i];
  3515. var val = wrapVar(alias, 0);
  3516. tpl = tpl.replace(wrapVar(alias), encode ? encodeHTML(val) : val);
  3517. }
  3518. for (var seriesIdx = 0; seriesIdx < seriesLen; seriesIdx++) {
  3519. for (var k = 0; k < $vars.length; k++) {
  3520. var val = paramsList[seriesIdx][$vars[k]];
  3521. tpl = tpl.replace(
  3522. wrapVar(TPL_VAR_ALIAS[k], seriesIdx),
  3523. encode ? encodeHTML(val) : val
  3524. );
  3525. }
  3526. }
  3527. return tpl;
  3528. };
  3529. /**
  3530. * @param {string} str
  3531. * @return {string}
  3532. * @inner
  3533. */
  3534. var s2d = function (str) {
  3535. return str < 10 ? ('0' + str) : str;
  3536. };
  3537. /**
  3538. * ISO Date format
  3539. * @param {string} tpl
  3540. * @param {number} value
  3541. * @inner
  3542. */
  3543. formatUtil.formatTime = function (tpl, value) {
  3544. if (tpl === 'week'
  3545. || tpl === 'month'
  3546. || tpl === 'quarter'
  3547. || tpl === 'half-year'
  3548. || tpl === 'year'
  3549. ) {
  3550. tpl = 'MM-dd\nyyyy';
  3551. }
  3552. var date = numberUtil.parseDate(value);
  3553. var y = date.getFullYear();
  3554. var M = date.getMonth() + 1;
  3555. var d = date.getDate();
  3556. var h = date.getHours();
  3557. var m = date.getMinutes();
  3558. var s = date.getSeconds();
  3559. tpl = tpl.replace('MM', s2d(M))
  3560. .toLowerCase()
  3561. .replace('yyyy', y)
  3562. .replace('yy', y % 100)
  3563. .replace('dd', s2d(d))
  3564. .replace('d', d)
  3565. .replace('hh', s2d(h))
  3566. .replace('h', h)
  3567. .replace('mm', s2d(m))
  3568. .replace('m', m)
  3569. .replace('ss', s2d(s))
  3570. .replace('s', s);
  3571. return tpl;
  3572. };
  3573. /**
  3574. * Capital first
  3575. * @param {string} str
  3576. * @return {string}
  3577. */
  3578. formatUtil.capitalFirst = function (str) {
  3579. return str ? str.charAt(0).toUpperCase() + str.substr(1) : str;
  3580. };
  3581. formatUtil.truncateText = textContain.truncateText;
  3582. module.exports = formatUtil;
  3583. /***/ },
  3584. /* 7 */
  3585. /***/ function(module, exports) {
  3586. /**
  3587. * 数值处理模块
  3588. * @module echarts/util/number
  3589. */
  3590. var number = {};
  3591. var RADIAN_EPSILON = 1e-4;
  3592. function _trim(str) {
  3593. return str.replace(/^\s+/, '').replace(/\s+$/, '');
  3594. }
  3595. /**
  3596. * Linear mapping a value from domain to range
  3597. * @memberOf module:echarts/util/number
  3598. * @param {(number|Array.<number>)} val
  3599. * @param {Array.<number>} domain Domain extent domain[0] can be bigger than domain[1]
  3600. * @param {Array.<number>} range Range extent range[0] can be bigger than range[1]
  3601. * @param {boolean} clamp
  3602. * @return {(number|Array.<number>}
  3603. */
  3604. number.linearMap = function (val, domain, range, clamp) {
  3605. var subDomain = domain[1] - domain[0];
  3606. var subRange = range[1] - range[0];
  3607. if (subDomain === 0) {
  3608. return subRange === 0
  3609. ? range[0]
  3610. : (range[0] + range[1]) / 2;
  3611. }
  3612. // Avoid accuracy problem in edge, such as
  3613. // 146.39 - 62.83 === 83.55999999999999.
  3614. // See echarts/test/ut/spec/util/number.js#linearMap#accuracyError
  3615. // It is a little verbose for efficiency considering this method
  3616. // is a hotspot.
  3617. if (clamp) {
  3618. if (subDomain > 0) {
  3619. if (val <= domain[0]) {
  3620. return range[0];
  3621. }
  3622. else if (val >= domain[1]) {
  3623. return range[1];
  3624. }
  3625. }
  3626. else {
  3627. if (val >= domain[0]) {
  3628. return range[0];
  3629. }
  3630. else if (val <= domain[1]) {
  3631. return range[1];
  3632. }
  3633. }
  3634. }
  3635. else {
  3636. if (val === domain[0]) {
  3637. return range[0];
  3638. }
  3639. if (val === domain[1]) {
  3640. return range[1];
  3641. }
  3642. }
  3643. return (val - domain[0]) / subDomain * subRange + range[0];
  3644. };
  3645. /**
  3646. * Convert a percent string to absolute number.
  3647. * Returns NaN if percent is not a valid string or number
  3648. * @memberOf module:echarts/util/number
  3649. * @param {string|number} percent
  3650. * @param {number} all
  3651. * @return {number}
  3652. */
  3653. number.parsePercent = function(percent, all) {
  3654. switch (percent) {
  3655. case 'center':
  3656. case 'middle':
  3657. percent = '50%';
  3658. break;
  3659. case 'left':
  3660. case 'top':
  3661. percent = '0%';
  3662. break;
  3663. case 'right':
  3664. case 'bottom':
  3665. percent = '100%';
  3666. break;
  3667. }
  3668. if (typeof percent === 'string') {
  3669. if (_trim(percent).match(/%$/)) {
  3670. return parseFloat(percent) / 100 * all;
  3671. }
  3672. return parseFloat(percent);
  3673. }
  3674. return percent == null ? NaN : +percent;
  3675. };
  3676. /**
  3677. * Fix rounding error of float numbers
  3678. * @param {number} x
  3679. * @return {number}
  3680. */
  3681. number.round = function (x, precision) {
  3682. if (precision == null) {
  3683. precision = 10;
  3684. }
  3685. // Avoid range error
  3686. precision = Math.min(Math.max(0, precision), 20);
  3687. return +(+x).toFixed(precision);
  3688. };
  3689. number.asc = function (arr) {
  3690. arr.sort(function (a, b) {
  3691. return a - b;
  3692. });
  3693. return arr;
  3694. };
  3695. /**
  3696. * Get precision
  3697. * @param {number} val
  3698. */
  3699. number.getPrecision = function (val) {
  3700. val = +val;
  3701. if (isNaN(val)) {
  3702. return 0;
  3703. }
  3704. // It is much faster than methods converting number to string as follows
  3705. // var tmp = val.toString();
  3706. // return tmp.length - 1 - tmp.indexOf('.');
  3707. // especially when precision is low
  3708. var e = 1;
  3709. var count = 0;
  3710. while (Math.round(val * e) / e !== val) {
  3711. e *= 10;
  3712. count++;
  3713. }
  3714. return count;
  3715. };
  3716. number.getPrecisionSafe = function (val) {
  3717. var str = val.toString();
  3718. var dotIndex = str.indexOf('.');
  3719. if (dotIndex < 0) {
  3720. return 0;
  3721. }
  3722. return str.length - 1 - dotIndex;
  3723. };
  3724. /**
  3725. * Minimal dicernible data precisioin according to a single pixel.
  3726. * @param {Array.<number>} dataExtent
  3727. * @param {Array.<number>} pixelExtent
  3728. * @return {number} precision
  3729. */
  3730. number.getPixelPrecision = function (dataExtent, pixelExtent) {
  3731. var log = Math.log;
  3732. var LN10 = Math.LN10;
  3733. var dataQuantity = Math.floor(log(dataExtent[1] - dataExtent[0]) / LN10);
  3734. var sizeQuantity = Math.round(log(Math.abs(pixelExtent[1] - pixelExtent[0])) / LN10);
  3735. // toFixed() digits argument must be between 0 and 20.
  3736. var precision = Math.min(Math.max(-dataQuantity + sizeQuantity, 0), 20);
  3737. return !isFinite(precision) ? 20 : precision;
  3738. };
  3739. // Number.MAX_SAFE_INTEGER, ie do not support.
  3740. number.MAX_SAFE_INTEGER = 9007199254740991;
  3741. /**
  3742. * To 0 - 2 * PI, considering negative radian.
  3743. * @param {number} radian
  3744. * @return {number}
  3745. */
  3746. number.remRadian = function (radian) {
  3747. var pi2 = Math.PI * 2;
  3748. return (radian % pi2 + pi2) % pi2;
  3749. };
  3750. /**
  3751. * @param {type} radian
  3752. * @return {boolean}
  3753. */
  3754. number.isRadianAroundZero = function (val) {
  3755. return val > -RADIAN_EPSILON && val < RADIAN_EPSILON;
  3756. };
  3757. /**
  3758. * @param {string|Date|number} value
  3759. * @return {Date} date
  3760. */
  3761. number.parseDate = function (value) {
  3762. if (value instanceof Date) {
  3763. return value;
  3764. }
  3765. else if (typeof value === 'string') {
  3766. // Treat as ISO format. See issue #3623
  3767. var ret = new Date(value);
  3768. if (isNaN(+ret)) {
  3769. // FIXME new Date('1970-01-01') is UTC, new Date('1970/01/01') is local
  3770. ret = new Date(new Date(value.replace(/-/g, '/')) - new Date('1970/01/01'));
  3771. }
  3772. return ret;
  3773. }
  3774. return new Date(Math.round(value));
  3775. };
  3776. /**
  3777. * Quantity of a number. e.g. 0.1, 1, 10, 100
  3778. * @param {number} val
  3779. * @return {number}
  3780. */
  3781. number.quantity = function (val) {
  3782. return Math.pow(10, Math.floor(Math.log(val) / Math.LN10));
  3783. };
  3784. // "Nice Numbers for Graph Labels" of Graphic Gems
  3785. /**
  3786. * find a “nice” number approximately equal to x. Round the number if round = true, take ceiling if round = false
  3787. * The primary observation is that the “nicest” numbers in decimal are 1, 2, and 5, and all power-of-ten multiples of these numbers.
  3788. * @param {number} val
  3789. * @param {boolean} round
  3790. * @return {number}
  3791. */
  3792. number.nice = function (val, round) {
  3793. var exp10 = number.quantity(val);
  3794. var f = val / exp10; // between 1 and 10
  3795. var nf;
  3796. if (round) {
  3797. if (f < 1.5) { nf = 1; }
  3798. else if (f < 2.5) { nf = 2; }
  3799. else if (f < 4) { nf = 3; }
  3800. else if (f < 7) { nf = 5; }
  3801. else { nf = 10; }
  3802. }
  3803. else {
  3804. if (f < 1) { nf = 1; }
  3805. else if (f < 2) { nf = 2; }
  3806. else if (f < 3) { nf = 3; }
  3807. else if (f < 5) { nf = 5; }
  3808. else { nf = 10; }
  3809. }
  3810. return nf * exp10;
  3811. };
  3812. /**
  3813. * Order intervals asc, and split them when overlap.
  3814. * expect(numberUtil.reformIntervals([
  3815. * {interval: [18, 62], close: [1, 1]},
  3816. * {interval: [-Infinity, -70], close: [0, 0]},
  3817. * {interval: [-70, -26], close: [1, 1]},
  3818. * {interval: [-26, 18], close: [1, 1]},
  3819. * {interval: [62, 150], close: [1, 1]},
  3820. * {interval: [106, 150], close: [1, 1]},
  3821. * {interval: [150, Infinity], close: [0, 0]}
  3822. * ])).toEqual([
  3823. * {interval: [-Infinity, -70], close: [0, 0]},
  3824. * {interval: [-70, -26], close: [1, 1]},
  3825. * {interval: [-26, 18], close: [0, 1]},
  3826. * {interval: [18, 62], close: [0, 1]},
  3827. * {interval: [62, 150], close: [0, 1]},
  3828. * {interval: [150, Infinity], close: [0, 0]}
  3829. * ]);
  3830. * @param {Array.<Object>} list, where `close` mean open or close
  3831. * of the interval, and Infinity can be used.
  3832. * @return {Array.<Object>} The origin list, which has been reformed.
  3833. */
  3834. number.reformIntervals = function (list) {
  3835. list.sort(function (a, b) {
  3836. return littleThan(a, b, 0) ? -1 : 1;
  3837. });
  3838. var curr = -Infinity;
  3839. var currClose = 1;
  3840. for (var i = 0; i < list.length;) {
  3841. var interval = list[i].interval;
  3842. var close = list[i].close;
  3843. for (var lg = 0; lg < 2; lg++) {
  3844. if (interval[lg] <= curr) {
  3845. interval[lg] = curr;
  3846. close[lg] = !lg ? 1 - currClose : 1;
  3847. }
  3848. curr = interval[lg];
  3849. currClose = close[lg];
  3850. }
  3851. if (interval[0] === interval[1] && close[0] * close[1] !== 1) {
  3852. list.splice(i, 1);
  3853. }
  3854. else {
  3855. i++;
  3856. }
  3857. }
  3858. return list;
  3859. function littleThan(a, b, lg) {
  3860. return a.interval[lg] < b.interval[lg]
  3861. || (
  3862. a.interval[lg] === b.interval[lg]
  3863. && (
  3864. (a.close[lg] - b.close[lg] === (!lg ? 1 : -1))
  3865. || (!lg && littleThan(a, b, 1))
  3866. )
  3867. );
  3868. }
  3869. };
  3870. /**
  3871. * parseFloat NaNs numeric-cast false positives (null|true|false|"")
  3872. * ...but misinterprets leading-number strings, particularly hex literals ("0x...")
  3873. * subtraction forces infinities to NaN
  3874. * @param {*} v
  3875. * @return {boolean}
  3876. */
  3877. number.isNumeric = function (v) {
  3878. return v - parseFloat(v) >= 0;
  3879. };
  3880. module.exports = number;
  3881. /***/ },
  3882. /* 8 */
  3883. /***/ function(module, exports, __webpack_require__) {
  3884. var textWidthCache = {};
  3885. var textWidthCacheCounter = 0;
  3886. var TEXT_CACHE_MAX = 5000;
  3887. var util = __webpack_require__(4);
  3888. var BoundingRect = __webpack_require__(9);
  3889. var retrieve = util.retrieve;
  3890. function getTextWidth(text, textFont) {
  3891. var key = text + ':' + textFont;
  3892. if (textWidthCache[key]) {
  3893. return textWidthCache[key];
  3894. }
  3895. var textLines = (text + '').split('\n');
  3896. var width = 0;
  3897. for (var i = 0, l = textLines.length; i < l; i++) {
  3898. // measureText 可以被覆盖以兼容不支持 Canvas 的环境
  3899. width = Math.max(textContain.measureText(textLines[i], textFont).width, width);
  3900. }
  3901. if (textWidthCacheCounter > TEXT_CACHE_MAX) {
  3902. textWidthCacheCounter = 0;
  3903. textWidthCache = {};
  3904. }
  3905. textWidthCacheCounter++;
  3906. textWidthCache[key] = width;
  3907. return width;
  3908. }
  3909. function getTextRect(text, textFont, textAlign, textBaseline) {
  3910. var textLineLen = ((text || '') + '').split('\n').length;
  3911. var width = getTextWidth(text, textFont);
  3912. // FIXME 高度计算比较粗暴
  3913. var lineHeight = getTextWidth('国', textFont);
  3914. var height = textLineLen * lineHeight;
  3915. var rect = new BoundingRect(0, 0, width, height);
  3916. // Text has a special line height property
  3917. rect.lineHeight = lineHeight;
  3918. switch (textBaseline) {
  3919. case 'bottom':
  3920. case 'alphabetic':
  3921. rect.y -= lineHeight;
  3922. break;
  3923. case 'middle':
  3924. rect.y -= lineHeight / 2;
  3925. break;
  3926. // case 'hanging':
  3927. // case 'top':
  3928. }
  3929. // FIXME Right to left language
  3930. switch (textAlign) {
  3931. case 'end':
  3932. case 'right':
  3933. rect.x -= rect.width;
  3934. break;
  3935. case 'center':
  3936. rect.x -= rect.width / 2;
  3937. break;
  3938. // case 'start':
  3939. // case 'left':
  3940. }
  3941. return rect;
  3942. }
  3943. function adjustTextPositionOnRect(textPosition, rect, textRect, distance) {
  3944. var x = rect.x;
  3945. var y = rect.y;
  3946. var height = rect.height;
  3947. var width = rect.width;
  3948. var textHeight = textRect.height;
  3949. var halfHeight = height / 2 - textHeight / 2;
  3950. var textAlign = 'left';
  3951. switch (textPosition) {
  3952. case 'left':
  3953. x -= distance;
  3954. y += halfHeight;
  3955. textAlign = 'right';
  3956. break;
  3957. case 'right':
  3958. x += distance + width;
  3959. y += halfHeight;
  3960. textAlign = 'left';
  3961. break;
  3962. case 'top':
  3963. x += width / 2;
  3964. y -= distance + textHeight;
  3965. textAlign = 'center';
  3966. break;
  3967. case 'bottom':
  3968. x += width / 2;
  3969. y += height + distance;
  3970. textAlign = 'center';
  3971. break;
  3972. case 'inside':
  3973. x += width / 2;
  3974. y += halfHeight;
  3975. textAlign = 'center';
  3976. break;
  3977. case 'insideLeft':
  3978. x += distance;
  3979. y += halfHeight;
  3980. textAlign = 'left';
  3981. break;
  3982. case 'insideRight':
  3983. x += width - distance;
  3984. y += halfHeight;
  3985. textAlign = 'right';
  3986. break;
  3987. case 'insideTop':
  3988. x += width / 2;
  3989. y += distance;
  3990. textAlign = 'center';
  3991. break;
  3992. case 'insideBottom':
  3993. x += width / 2;
  3994. y += height - textHeight - distance;
  3995. textAlign = 'center';
  3996. break;
  3997. case 'insideTopLeft':
  3998. x += distance;
  3999. y += distance;
  4000. textAlign = 'left';
  4001. break;
  4002. case 'insideTopRight':
  4003. x += width - distance;
  4004. y += distance;
  4005. textAlign = 'right';
  4006. break;
  4007. case 'insideBottomLeft':
  4008. x += distance;
  4009. y += height - textHeight - distance;
  4010. break;
  4011. case 'insideBottomRight':
  4012. x += width - distance;
  4013. y += height - textHeight - distance;
  4014. textAlign = 'right';
  4015. break;
  4016. }
  4017. return {
  4018. x: x,
  4019. y: y,
  4020. textAlign: textAlign,
  4021. textBaseline: 'top'
  4022. };
  4023. }
  4024. /**
  4025. * Show ellipsis if overflow.
  4026. *
  4027. * @param {string} text
  4028. * @param {string} containerWidth
  4029. * @param {string} textFont
  4030. * @param {number} [ellipsis='...']
  4031. * @param {Object} [options]
  4032. * @param {number} [options.maxIterations=3]
  4033. * @param {number} [options.minChar=0] If truncate result are less
  4034. * then minChar, ellipsis will not show, which is
  4035. * better for user hint in some cases.
  4036. * @param {number} [options.placeholder=''] When all truncated, use the placeholder.
  4037. * @return {string}
  4038. */
  4039. function truncateText(text, containerWidth, textFont, ellipsis, options) {
  4040. if (!containerWidth) {
  4041. return '';
  4042. }
  4043. options = options || {};
  4044. ellipsis = retrieve(ellipsis, '...');
  4045. var maxIterations = retrieve(options.maxIterations, 2);
  4046. var minChar = retrieve(options.minChar, 0);
  4047. // FIXME
  4048. // Other languages?
  4049. var cnCharWidth = getTextWidth('国', textFont);
  4050. // FIXME
  4051. // Consider proportional font?
  4052. var ascCharWidth = getTextWidth('a', textFont);
  4053. var placeholder = retrieve(options.placeholder, '');
  4054. // Example 1: minChar: 3, text: 'asdfzxcv', truncate result: 'asdf', but not: 'a...'.
  4055. // Example 2: minChar: 3, text: '维度', truncate result: '维', but not: '...'.
  4056. var contentWidth = containerWidth = Math.max(0, containerWidth - 1); // Reserve some gap.
  4057. for (var i = 0; i < minChar && contentWidth >= ascCharWidth; i++) {
  4058. contentWidth -= ascCharWidth;
  4059. }
  4060. var ellipsisWidth = getTextWidth(ellipsis);
  4061. if (ellipsisWidth > contentWidth) {
  4062. ellipsis = '';
  4063. ellipsisWidth = 0;
  4064. }
  4065. contentWidth = containerWidth - ellipsisWidth;
  4066. var textLines = (text + '').split('\n');
  4067. for (var i = 0, len = textLines.length; i < len; i++) {
  4068. var textLine = textLines[i];
  4069. var lineWidth = getTextWidth(textLine, textFont);
  4070. if (lineWidth <= containerWidth) {
  4071. continue;
  4072. }
  4073. for (var j = 0;; j++) {
  4074. if (lineWidth <= contentWidth || j >= maxIterations) {
  4075. textLine += ellipsis;
  4076. break;
  4077. }
  4078. var subLength = j === 0
  4079. ? estimateLength(textLine, contentWidth, ascCharWidth, cnCharWidth)
  4080. : lineWidth > 0
  4081. ? Math.floor(textLine.length * contentWidth / lineWidth)
  4082. : 0;
  4083. textLine = textLine.substr(0, subLength);
  4084. lineWidth = getTextWidth(textLine, textFont);
  4085. }
  4086. if (textLine === '') {
  4087. textLine = placeholder;
  4088. }
  4089. textLines[i] = textLine;
  4090. }
  4091. return textLines.join('\n');
  4092. }
  4093. function estimateLength(text, contentWidth, ascCharWidth, cnCharWidth) {
  4094. var width = 0;
  4095. var i = 0;
  4096. for (var len = text.length; i < len && width < contentWidth; i++) {
  4097. var charCode = text.charCodeAt(i);
  4098. width += (0 <= charCode && charCode <= 127) ? ascCharWidth : cnCharWidth;
  4099. }
  4100. return i;
  4101. }
  4102. var textContain = {
  4103. getWidth: getTextWidth,
  4104. getBoundingRect: getTextRect,
  4105. adjustTextPositionOnRect: adjustTextPositionOnRect,
  4106. truncateText: truncateText,
  4107. measureText: function (text, textFont) {
  4108. var ctx = util.getContext();
  4109. ctx.font = textFont || '12px sans-serif';
  4110. return ctx.measureText(text);
  4111. }
  4112. };
  4113. module.exports = textContain;
  4114. /***/ },
  4115. /* 9 */
  4116. /***/ function(module, exports, __webpack_require__) {
  4117. 'use strict';
  4118. /**
  4119. * @module echarts/core/BoundingRect
  4120. */
  4121. var vec2 = __webpack_require__(10);
  4122. var matrix = __webpack_require__(11);
  4123. var v2ApplyTransform = vec2.applyTransform;
  4124. var mathMin = Math.min;
  4125. var mathMax = Math.max;
  4126. /**
  4127. * @alias module:echarts/core/BoundingRect
  4128. */
  4129. function BoundingRect(x, y, width, height) {
  4130. if (width < 0) {
  4131. x = x + width;
  4132. width = -width;
  4133. }
  4134. if (height < 0) {
  4135. y = y + height;
  4136. height = -height;
  4137. }
  4138. /**
  4139. * @type {number}
  4140. */
  4141. this.x = x;
  4142. /**
  4143. * @type {number}
  4144. */
  4145. this.y = y;
  4146. /**
  4147. * @type {number}
  4148. */
  4149. this.width = width;
  4150. /**
  4151. * @type {number}
  4152. */
  4153. this.height = height;
  4154. }
  4155. BoundingRect.prototype = {
  4156. constructor: BoundingRect,
  4157. /**
  4158. * @param {module:echarts/core/BoundingRect} other
  4159. */
  4160. union: function (other) {
  4161. var x = mathMin(other.x, this.x);
  4162. var y = mathMin(other.y, this.y);
  4163. this.width = mathMax(
  4164. other.x + other.width,
  4165. this.x + this.width
  4166. ) - x;
  4167. this.height = mathMax(
  4168. other.y + other.height,
  4169. this.y + this.height
  4170. ) - y;
  4171. this.x = x;
  4172. this.y = y;
  4173. },
  4174. /**
  4175. * @param {Array.<number>} m
  4176. * @methods
  4177. */
  4178. applyTransform: (function () {
  4179. var lt = [];
  4180. var rb = [];
  4181. var lb = [];
  4182. var rt = [];
  4183. return function (m) {
  4184. // In case usage like this
  4185. // el.getBoundingRect().applyTransform(el.transform)
  4186. // And element has no transform
  4187. if (!m) {
  4188. return;
  4189. }
  4190. lt[0] = lb[0] = this.x;
  4191. lt[1] = rt[1] = this.y;
  4192. rb[0] = rt[0] = this.x + this.width;
  4193. rb[1] = lb[1] = this.y + this.height;
  4194. v2ApplyTransform(lt, lt, m);
  4195. v2ApplyTransform(rb, rb, m);
  4196. v2ApplyTransform(lb, lb, m);
  4197. v2ApplyTransform(rt, rt, m);
  4198. this.x = mathMin(lt[0], rb[0], lb[0], rt[0]);
  4199. this.y = mathMin(lt[1], rb[1], lb[1], rt[1]);
  4200. var maxX = mathMax(lt[0], rb[0], lb[0], rt[0]);
  4201. var maxY = mathMax(lt[1], rb[1], lb[1], rt[1]);
  4202. this.width = maxX - this.x;
  4203. this.height = maxY - this.y;
  4204. };
  4205. })(),
  4206. /**
  4207. * Calculate matrix of transforming from self to target rect
  4208. * @param {module:zrender/core/BoundingRect} b
  4209. * @return {Array.<number>}
  4210. */
  4211. calculateTransform: function (b) {
  4212. var a = this;
  4213. var sx = b.width / a.width;
  4214. var sy = b.height / a.height;
  4215. var m = matrix.create();
  4216. // 矩阵右乘
  4217. matrix.translate(m, m, [-a.x, -a.y]);
  4218. matrix.scale(m, m, [sx, sy]);
  4219. matrix.translate(m, m, [b.x, b.y]);
  4220. return m;
  4221. },
  4222. /**
  4223. * @param {(module:echarts/core/BoundingRect|Object)} b
  4224. * @return {boolean}
  4225. */
  4226. intersect: function (b) {
  4227. if (!b) {
  4228. return false;
  4229. }
  4230. if (!(b instanceof BoundingRect)) {
  4231. // Normalize negative width/height.
  4232. b = BoundingRect.create(b);
  4233. }
  4234. var a = this;
  4235. var ax0 = a.x;
  4236. var ax1 = a.x + a.width;
  4237. var ay0 = a.y;
  4238. var ay1 = a.y + a.height;
  4239. var bx0 = b.x;
  4240. var bx1 = b.x + b.width;
  4241. var by0 = b.y;
  4242. var by1 = b.y + b.height;
  4243. return ! (ax1 < bx0 || bx1 < ax0 || ay1 < by0 || by1 < ay0);
  4244. },
  4245. contain: function (x, y) {
  4246. var rect = this;
  4247. return x >= rect.x
  4248. && x <= (rect.x + rect.width)
  4249. && y >= rect.y
  4250. && y <= (rect.y + rect.height);
  4251. },
  4252. /**
  4253. * @return {module:echarts/core/BoundingRect}
  4254. */
  4255. clone: function () {
  4256. return new BoundingRect(this.x, this.y, this.width, this.height);
  4257. },
  4258. /**
  4259. * Copy from another rect
  4260. */
  4261. copy: function (other) {
  4262. this.x = other.x;
  4263. this.y = other.y;
  4264. this.width = other.width;
  4265. this.height = other.height;
  4266. },
  4267. plain: function () {
  4268. return {
  4269. x: this.x,
  4270. y: this.y,
  4271. width: this.width,
  4272. height: this.height
  4273. };
  4274. }
  4275. };
  4276. /**
  4277. * @param {Object|module:zrender/core/BoundingRect} rect
  4278. * @param {number} rect.x
  4279. * @param {number} rect.y
  4280. * @param {number} rect.width
  4281. * @param {number} rect.height
  4282. * @return {module:zrender/core/BoundingRect}
  4283. */
  4284. BoundingRect.create = function (rect) {
  4285. return new BoundingRect(rect.x, rect.y, rect.width, rect.height);
  4286. };
  4287. module.exports = BoundingRect;
  4288. /***/ },
  4289. /* 10 */
  4290. /***/ function(module, exports) {
  4291. var ArrayCtor = typeof Float32Array === 'undefined'
  4292. ? Array
  4293. : Float32Array;
  4294. /**
  4295. * @typedef {Float32Array|Array.<number>} Vector2
  4296. */
  4297. /**
  4298. * 二维向量类
  4299. * @exports zrender/tool/vector
  4300. */
  4301. var vector = {
  4302. /**
  4303. * 创建一个向量
  4304. * @param {number} [x=0]
  4305. * @param {number} [y=0]
  4306. * @return {Vector2}
  4307. */
  4308. create: function (x, y) {
  4309. var out = new ArrayCtor(2);
  4310. if (x == null) {
  4311. x = 0;
  4312. }
  4313. if (y == null) {
  4314. y = 0;
  4315. }
  4316. out[0] = x;
  4317. out[1] = y;
  4318. return out;
  4319. },
  4320. /**
  4321. * 复制向量数据
  4322. * @param {Vector2} out
  4323. * @param {Vector2} v
  4324. * @return {Vector2}
  4325. */
  4326. copy: function (out, v) {
  4327. out[0] = v[0];
  4328. out[1] = v[1];
  4329. return out;
  4330. },
  4331. /**
  4332. * 克隆一个向量
  4333. * @param {Vector2} v
  4334. * @return {Vector2}
  4335. */
  4336. clone: function (v) {
  4337. var out = new ArrayCtor(2);
  4338. out[0] = v[0];
  4339. out[1] = v[1];
  4340. return out;
  4341. },
  4342. /**
  4343. * 设置向量的两个项
  4344. * @param {Vector2} out
  4345. * @param {number} a
  4346. * @param {number} b
  4347. * @return {Vector2} 结果
  4348. */
  4349. set: function (out, a, b) {
  4350. out[0] = a;
  4351. out[1] = b;
  4352. return out;
  4353. },
  4354. /**
  4355. * 向量相加
  4356. * @param {Vector2} out
  4357. * @param {Vector2} v1
  4358. * @param {Vector2} v2
  4359. */
  4360. add: function (out, v1, v2) {
  4361. out[0] = v1[0] + v2[0];
  4362. out[1] = v1[1] + v2[1];
  4363. return out;
  4364. },
  4365. /**
  4366. * 向量缩放后相加
  4367. * @param {Vector2} out
  4368. * @param {Vector2} v1
  4369. * @param {Vector2} v2
  4370. * @param {number} a
  4371. */
  4372. scaleAndAdd: function (out, v1, v2, a) {
  4373. out[0] = v1[0] + v2[0] * a;
  4374. out[1] = v1[1] + v2[1] * a;
  4375. return out;
  4376. },
  4377. /**
  4378. * 向量相减
  4379. * @param {Vector2} out
  4380. * @param {Vector2} v1
  4381. * @param {Vector2} v2
  4382. */
  4383. sub: function (out, v1, v2) {
  4384. out[0] = v1[0] - v2[0];
  4385. out[1] = v1[1] - v2[1];
  4386. return out;
  4387. },
  4388. /**
  4389. * 向量长度
  4390. * @param {Vector2} v
  4391. * @return {number}
  4392. */
  4393. len: function (v) {
  4394. return Math.sqrt(this.lenSquare(v));
  4395. },
  4396. /**
  4397. * 向量长度平方
  4398. * @param {Vector2} v
  4399. * @return {number}
  4400. */
  4401. lenSquare: function (v) {
  4402. return v[0] * v[0] + v[1] * v[1];
  4403. },
  4404. /**
  4405. * 向量乘法
  4406. * @param {Vector2} out
  4407. * @param {Vector2} v1
  4408. * @param {Vector2} v2
  4409. */
  4410. mul: function (out, v1, v2) {
  4411. out[0] = v1[0] * v2[0];
  4412. out[1] = v1[1] * v2[1];
  4413. return out;
  4414. },
  4415. /**
  4416. * 向量除法
  4417. * @param {Vector2} out
  4418. * @param {Vector2} v1
  4419. * @param {Vector2} v2
  4420. */
  4421. div: function (out, v1, v2) {
  4422. out[0] = v1[0] / v2[0];
  4423. out[1] = v1[1] / v2[1];
  4424. return out;
  4425. },
  4426. /**
  4427. * 向量点乘
  4428. * @param {Vector2} v1
  4429. * @param {Vector2} v2
  4430. * @return {number}
  4431. */
  4432. dot: function (v1, v2) {
  4433. return v1[0] * v2[0] + v1[1] * v2[1];
  4434. },
  4435. /**
  4436. * 向量缩放
  4437. * @param {Vector2} out
  4438. * @param {Vector2} v
  4439. * @param {number} s
  4440. */
  4441. scale: function (out, v, s) {
  4442. out[0] = v[0] * s;
  4443. out[1] = v[1] * s;
  4444. return out;
  4445. },
  4446. /**
  4447. * 向量归一化
  4448. * @param {Vector2} out
  4449. * @param {Vector2} v
  4450. */
  4451. normalize: function (out, v) {
  4452. var d = vector.len(v);
  4453. if (d === 0) {
  4454. out[0] = 0;
  4455. out[1] = 0;
  4456. }
  4457. else {
  4458. out[0] = v[0] / d;
  4459. out[1] = v[1] / d;
  4460. }
  4461. return out;
  4462. },
  4463. /**
  4464. * 计算向量间距离
  4465. * @param {Vector2} v1
  4466. * @param {Vector2} v2
  4467. * @return {number}
  4468. */
  4469. distance: function (v1, v2) {
  4470. return Math.sqrt(
  4471. (v1[0] - v2[0]) * (v1[0] - v2[0])
  4472. + (v1[1] - v2[1]) * (v1[1] - v2[1])
  4473. );
  4474. },
  4475. /**
  4476. * 向量距离平方
  4477. * @param {Vector2} v1
  4478. * @param {Vector2} v2
  4479. * @return {number}
  4480. */
  4481. distanceSquare: function (v1, v2) {
  4482. return (v1[0] - v2[0]) * (v1[0] - v2[0])
  4483. + (v1[1] - v2[1]) * (v1[1] - v2[1]);
  4484. },
  4485. /**
  4486. * 求负向量
  4487. * @param {Vector2} out
  4488. * @param {Vector2} v
  4489. */
  4490. negate: function (out, v) {
  4491. out[0] = -v[0];
  4492. out[1] = -v[1];
  4493. return out;
  4494. },
  4495. /**
  4496. * 插值两个点
  4497. * @param {Vector2} out
  4498. * @param {Vector2} v1
  4499. * @param {Vector2} v2
  4500. * @param {number} t
  4501. */
  4502. lerp: function (out, v1, v2, t) {
  4503. out[0] = v1[0] + t * (v2[0] - v1[0]);
  4504. out[1] = v1[1] + t * (v2[1] - v1[1]);
  4505. return out;
  4506. },
  4507. /**
  4508. * 矩阵左乘向量
  4509. * @param {Vector2} out
  4510. * @param {Vector2} v
  4511. * @param {Vector2} m
  4512. */
  4513. applyTransform: function (out, v, m) {
  4514. var x = v[0];
  4515. var y = v[1];
  4516. out[0] = m[0] * x + m[2] * y + m[4];
  4517. out[1] = m[1] * x + m[3] * y + m[5];
  4518. return out;
  4519. },
  4520. /**
  4521. * 求两个向量最小值
  4522. * @param {Vector2} out
  4523. * @param {Vector2} v1
  4524. * @param {Vector2} v2
  4525. */
  4526. min: function (out, v1, v2) {
  4527. out[0] = Math.min(v1[0], v2[0]);
  4528. out[1] = Math.min(v1[1], v2[1]);
  4529. return out;
  4530. },
  4531. /**
  4532. * 求两个向量最大值
  4533. * @param {Vector2} out
  4534. * @param {Vector2} v1
  4535. * @param {Vector2} v2
  4536. */
  4537. max: function (out, v1, v2) {
  4538. out[0] = Math.max(v1[0], v2[0]);
  4539. out[1] = Math.max(v1[1], v2[1]);
  4540. return out;
  4541. }
  4542. };
  4543. vector.length = vector.len;
  4544. vector.lengthSquare = vector.lenSquare;
  4545. vector.dist = vector.distance;
  4546. vector.distSquare = vector.distanceSquare;
  4547. module.exports = vector;
  4548. /***/ },
  4549. /* 11 */
  4550. /***/ function(module, exports) {
  4551. var ArrayCtor = typeof Float32Array === 'undefined'
  4552. ? Array
  4553. : Float32Array;
  4554. /**
  4555. * 3x2矩阵操作类
  4556. * @exports zrender/tool/matrix
  4557. */
  4558. var matrix = {
  4559. /**
  4560. * 创建一个单位矩阵
  4561. * @return {Float32Array|Array.<number>}
  4562. */
  4563. create : function() {
  4564. var out = new ArrayCtor(6);
  4565. matrix.identity(out);
  4566. return out;
  4567. },
  4568. /**
  4569. * 设置矩阵为单位矩阵
  4570. * @param {Float32Array|Array.<number>} out
  4571. */
  4572. identity : function(out) {
  4573. out[0] = 1;
  4574. out[1] = 0;
  4575. out[2] = 0;
  4576. out[3] = 1;
  4577. out[4] = 0;
  4578. out[5] = 0;
  4579. return out;
  4580. },
  4581. /**
  4582. * 复制矩阵
  4583. * @param {Float32Array|Array.<number>} out
  4584. * @param {Float32Array|Array.<number>} m
  4585. */
  4586. copy: function(out, m) {
  4587. out[0] = m[0];
  4588. out[1] = m[1];
  4589. out[2] = m[2];
  4590. out[3] = m[3];
  4591. out[4] = m[4];
  4592. out[5] = m[5];
  4593. return out;
  4594. },
  4595. /**
  4596. * 矩阵相乘
  4597. * @param {Float32Array|Array.<number>} out
  4598. * @param {Float32Array|Array.<number>} m1
  4599. * @param {Float32Array|Array.<number>} m2
  4600. */
  4601. mul : function (out, m1, m2) {
  4602. // Consider matrix.mul(m, m2, m);
  4603. // where out is the same as m2.
  4604. // So use temp variable to escape error.
  4605. var out0 = m1[0] * m2[0] + m1[2] * m2[1];
  4606. var out1 = m1[1] * m2[0] + m1[3] * m2[1];
  4607. var out2 = m1[0] * m2[2] + m1[2] * m2[3];
  4608. var out3 = m1[1] * m2[2] + m1[3] * m2[3];
  4609. var out4 = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  4610. var out5 = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  4611. out[0] = out0;
  4612. out[1] = out1;
  4613. out[2] = out2;
  4614. out[3] = out3;
  4615. out[4] = out4;
  4616. out[5] = out5;
  4617. return out;
  4618. },
  4619. /**
  4620. * 平移变换
  4621. * @param {Float32Array|Array.<number>} out
  4622. * @param {Float32Array|Array.<number>} a
  4623. * @param {Float32Array|Array.<number>} v
  4624. */
  4625. translate : function(out, a, v) {
  4626. out[0] = a[0];
  4627. out[1] = a[1];
  4628. out[2] = a[2];
  4629. out[3] = a[3];
  4630. out[4] = a[4] + v[0];
  4631. out[5] = a[5] + v[1];
  4632. return out;
  4633. },
  4634. /**
  4635. * 旋转变换
  4636. * @param {Float32Array|Array.<number>} out
  4637. * @param {Float32Array|Array.<number>} a
  4638. * @param {number} rad
  4639. */
  4640. rotate : function(out, a, rad) {
  4641. var aa = a[0];
  4642. var ac = a[2];
  4643. var atx = a[4];
  4644. var ab = a[1];
  4645. var ad = a[3];
  4646. var aty = a[5];
  4647. var st = Math.sin(rad);
  4648. var ct = Math.cos(rad);
  4649. out[0] = aa * ct + ab * st;
  4650. out[1] = -aa * st + ab * ct;
  4651. out[2] = ac * ct + ad * st;
  4652. out[3] = -ac * st + ct * ad;
  4653. out[4] = ct * atx + st * aty;
  4654. out[5] = ct * aty - st * atx;
  4655. return out;
  4656. },
  4657. /**
  4658. * 缩放变换
  4659. * @param {Float32Array|Array.<number>} out
  4660. * @param {Float32Array|Array.<number>} a
  4661. * @param {Float32Array|Array.<number>} v
  4662. */
  4663. scale : function(out, a, v) {
  4664. var vx = v[0];
  4665. var vy = v[1];
  4666. out[0] = a[0] * vx;
  4667. out[1] = a[1] * vy;
  4668. out[2] = a[2] * vx;
  4669. out[3] = a[3] * vy;
  4670. out[4] = a[4] * vx;
  4671. out[5] = a[5] * vy;
  4672. return out;
  4673. },
  4674. /**
  4675. * 求逆矩阵
  4676. * @param {Float32Array|Array.<number>} out
  4677. * @param {Float32Array|Array.<number>} a
  4678. */
  4679. invert : function(out, a) {
  4680. var aa = a[0];
  4681. var ac = a[2];
  4682. var atx = a[4];
  4683. var ab = a[1];
  4684. var ad = a[3];
  4685. var aty = a[5];
  4686. var det = aa * ad - ab * ac;
  4687. if (!det) {
  4688. return null;
  4689. }
  4690. det = 1.0 / det;
  4691. out[0] = ad * det;
  4692. out[1] = -ab * det;
  4693. out[2] = -ac * det;
  4694. out[3] = aa * det;
  4695. out[4] = (ac * aty - ad * atx) * det;
  4696. out[5] = (ab * atx - aa * aty) * det;
  4697. return out;
  4698. }
  4699. };
  4700. module.exports = matrix;
  4701. /***/ },
  4702. /* 12 */
  4703. /***/ function(module, exports, __webpack_require__) {
  4704. /**
  4705. * @module echarts/model/Model
  4706. */
  4707. var zrUtil = __webpack_require__(4);
  4708. var clazzUtil = __webpack_require__(13);
  4709. var env = __webpack_require__(2);
  4710. /**
  4711. * @alias module:echarts/model/Model
  4712. * @constructor
  4713. * @param {Object} option
  4714. * @param {module:echarts/model/Model} [parentModel]
  4715. * @param {module:echarts/model/Global} [ecModel]
  4716. */
  4717. function Model(option, parentModel, ecModel) {
  4718. /**
  4719. * @type {module:echarts/model/Model}
  4720. * @readOnly
  4721. */
  4722. this.parentModel = parentModel;
  4723. /**
  4724. * @type {module:echarts/model/Global}
  4725. * @readOnly
  4726. */
  4727. this.ecModel = ecModel;
  4728. /**
  4729. * @type {Object}
  4730. * @protected
  4731. */
  4732. this.option = option;
  4733. // Simple optimization
  4734. // if (this.init) {
  4735. // if (arguments.length <= 4) {
  4736. // this.init(option, parentModel, ecModel, extraOpt);
  4737. // }
  4738. // else {
  4739. // this.init.apply(this, arguments);
  4740. // }
  4741. // }
  4742. }
  4743. Model.prototype = {
  4744. constructor: Model,
  4745. /**
  4746. * Model 的初始化函数
  4747. * @param {Object} option
  4748. */
  4749. init: null,
  4750. /**
  4751. * 从新的 Option merge
  4752. */
  4753. mergeOption: function (option) {
  4754. zrUtil.merge(this.option, option, true);
  4755. },
  4756. /**
  4757. * @param {string|Array.<string>} path
  4758. * @param {boolean} [ignoreParent=false]
  4759. * @return {*}
  4760. */
  4761. get: function (path, ignoreParent) {
  4762. if (path == null) {
  4763. return this.option;
  4764. }
  4765. return doGet(
  4766. this.option,
  4767. this.parsePath(path),
  4768. !ignoreParent && getParent(this, path)
  4769. );
  4770. },
  4771. /**
  4772. * @param {string} key
  4773. * @param {boolean} [ignoreParent=false]
  4774. * @return {*}
  4775. */
  4776. getShallow: function (key, ignoreParent) {
  4777. var option = this.option;
  4778. var val = option == null ? option : option[key];
  4779. var parentModel = !ignoreParent && getParent(this, key);
  4780. if (val == null && parentModel) {
  4781. val = parentModel.getShallow(key);
  4782. }
  4783. return val;
  4784. },
  4785. /**
  4786. * @param {string|Array.<string>} path
  4787. * @param {module:echarts/model/Model} [parentModel]
  4788. * @return {module:echarts/model/Model}
  4789. */
  4790. getModel: function (path, parentModel) {
  4791. var obj = path == null
  4792. ? this.option
  4793. : doGet(this.option, path = this.parsePath(path));
  4794. var thisParentModel;
  4795. parentModel = parentModel || (
  4796. (thisParentModel = getParent(this, path))
  4797. && thisParentModel.getModel(path)
  4798. );
  4799. return new Model(obj, parentModel, this.ecModel);
  4800. },
  4801. /**
  4802. * If model has option
  4803. */
  4804. isEmpty: function () {
  4805. return this.option == null;
  4806. },
  4807. restoreData: function () {},
  4808. // Pending
  4809. clone: function () {
  4810. var Ctor = this.constructor;
  4811. return new Ctor(zrUtil.clone(this.option));
  4812. },
  4813. setReadOnly: function (properties) {
  4814. clazzUtil.setReadOnly(this, properties);
  4815. },
  4816. // If path is null/undefined, return null/undefined.
  4817. parsePath: function(path) {
  4818. if (typeof path === 'string') {
  4819. path = path.split('.');
  4820. }
  4821. return path;
  4822. },
  4823. /**
  4824. * @param {Function} getParentMethod
  4825. * param {Array.<string>|string} path
  4826. * return {module:echarts/model/Model}
  4827. */
  4828. customizeGetParent: function (getParentMethod) {
  4829. clazzUtil.set(this, 'getParent', getParentMethod);
  4830. },
  4831. isAnimationEnabled: function () {
  4832. if (!env.node) {
  4833. if (this.option.animation != null) {
  4834. return !!this.option.animation;
  4835. }
  4836. else if (this.parentModel) {
  4837. return this.parentModel.isAnimationEnabled();
  4838. }
  4839. }
  4840. }
  4841. };
  4842. function doGet(obj, pathArr, parentModel) {
  4843. for (var i = 0; i < pathArr.length; i++) {
  4844. // Ignore empty
  4845. if (!pathArr[i]) {
  4846. continue;
  4847. }
  4848. // obj could be number/string/... (like 0)
  4849. obj = (obj && typeof obj === 'object') ? obj[pathArr[i]] : null;
  4850. if (obj == null) {
  4851. break;
  4852. }
  4853. }
  4854. if (obj == null && parentModel) {
  4855. obj = parentModel.get(pathArr);
  4856. }
  4857. return obj;
  4858. }
  4859. function getParent(model, path) {
  4860. var getParentMethod = clazzUtil.get(model, 'getParent');
  4861. return getParentMethod ? getParentMethod.call(model, path) : model.parentModel;
  4862. }
  4863. // Enable Model.extend.
  4864. clazzUtil.enableClassExtend(Model);
  4865. var mixin = zrUtil.mixin;
  4866. mixin(Model, __webpack_require__(14));
  4867. mixin(Model, __webpack_require__(16));
  4868. mixin(Model, __webpack_require__(17));
  4869. mixin(Model, __webpack_require__(18));
  4870. module.exports = Model;
  4871. /***/ },
  4872. /* 13 */
  4873. /***/ function(module, exports, __webpack_require__) {
  4874. var zrUtil = __webpack_require__(4);
  4875. var clazz = {};
  4876. var TYPE_DELIMITER = '.';
  4877. var IS_CONTAINER = '___EC__COMPONENT__CONTAINER___';
  4878. var MEMBER_PRIFIX = '\0ec_\0';
  4879. /**
  4880. * Hide private class member.
  4881. * The same behavior as `host[name] = value;` (can be right-value)
  4882. * @public
  4883. */
  4884. clazz.set = function (host, name, value) {
  4885. return (host[MEMBER_PRIFIX + name] = value);
  4886. };
  4887. /**
  4888. * Hide private class member.
  4889. * The same behavior as `host[name];`
  4890. * @public
  4891. */
  4892. clazz.get = function (host, name) {
  4893. return host[MEMBER_PRIFIX + name];
  4894. };
  4895. /**
  4896. * For hidden private class member.
  4897. * The same behavior as `host.hasOwnProperty(name);`
  4898. * @public
  4899. */
  4900. clazz.hasOwn = function (host, name) {
  4901. return host.hasOwnProperty(MEMBER_PRIFIX + name);
  4902. };
  4903. /**
  4904. * @public
  4905. */
  4906. var parseClassType = clazz.parseClassType = function (componentType) {
  4907. var ret = {main: '', sub: ''};
  4908. if (componentType) {
  4909. componentType = componentType.split(TYPE_DELIMITER);
  4910. ret.main = componentType[0] || '';
  4911. ret.sub = componentType[1] || '';
  4912. }
  4913. return ret;
  4914. };
  4915. /**
  4916. * @public
  4917. */
  4918. function checkClassType(componentType) {
  4919. zrUtil.assert(
  4920. /^[a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)?$/.test(componentType),
  4921. 'componentType "' + componentType + '" illegal'
  4922. );
  4923. }
  4924. /**
  4925. * @public
  4926. */
  4927. clazz.enableClassExtend = function (RootClass, mandatoryMethods) {
  4928. RootClass.$constructor = RootClass;
  4929. RootClass.extend = function (proto) {
  4930. if (true) {
  4931. zrUtil.each(mandatoryMethods, function (method) {
  4932. if (!proto[method]) {
  4933. console.warn(
  4934. 'Method `' + method + '` should be implemented'
  4935. + (proto.type ? ' in ' + proto.type : '') + '.'
  4936. );
  4937. }
  4938. });
  4939. }
  4940. var superClass = this;
  4941. var ExtendedClass = function () {
  4942. if (!proto.$constructor) {
  4943. superClass.apply(this, arguments);
  4944. }
  4945. else {
  4946. proto.$constructor.apply(this, arguments);
  4947. }
  4948. };
  4949. zrUtil.extend(ExtendedClass.prototype, proto);
  4950. ExtendedClass.extend = this.extend;
  4951. ExtendedClass.superCall = superCall;
  4952. ExtendedClass.superApply = superApply;
  4953. zrUtil.inherits(ExtendedClass, this);
  4954. ExtendedClass.superClass = superClass;
  4955. return ExtendedClass;
  4956. };
  4957. };
  4958. // superCall should have class info, which can not be fetch from 'this'.
  4959. // Consider this case:
  4960. // class A has method f,
  4961. // class B inherits class A, overrides method f, f call superApply('f'),
  4962. // class C inherits class B, do not overrides method f,
  4963. // then when method of class C is called, dead loop occured.
  4964. function superCall(context, methodName) {
  4965. var args = zrUtil.slice(arguments, 2);
  4966. return this.superClass.prototype[methodName].apply(context, args);
  4967. }
  4968. function superApply(context, methodName, args) {
  4969. return this.superClass.prototype[methodName].apply(context, args);
  4970. }
  4971. /**
  4972. * @param {Object} entity
  4973. * @param {Object} options
  4974. * @param {boolean} [options.registerWhenExtend]
  4975. * @public
  4976. */
  4977. clazz.enableClassManagement = function (entity, options) {
  4978. options = options || {};
  4979. /**
  4980. * Component model classes
  4981. * key: componentType,
  4982. * value:
  4983. * componentClass, when componentType is 'xxx'
  4984. * or Object.<subKey, componentClass>, when componentType is 'xxx.yy'
  4985. * @type {Object}
  4986. */
  4987. var storage = {};
  4988. entity.registerClass = function (Clazz, componentType) {
  4989. if (componentType) {
  4990. checkClassType(componentType);
  4991. componentType = parseClassType(componentType);
  4992. if (!componentType.sub) {
  4993. if (true) {
  4994. if (storage[componentType.main]) {
  4995. console.warn(componentType.main + ' exists.');
  4996. }
  4997. }
  4998. storage[componentType.main] = Clazz;
  4999. }
  5000. else if (componentType.sub !== IS_CONTAINER) {
  5001. var container = makeContainer(componentType);
  5002. container[componentType.sub] = Clazz;
  5003. }
  5004. }
  5005. return Clazz;
  5006. };
  5007. entity.getClass = function (componentMainType, subType, throwWhenNotFound) {
  5008. var Clazz = storage[componentMainType];
  5009. if (Clazz && Clazz[IS_CONTAINER]) {
  5010. Clazz = subType ? Clazz[subType] : null;
  5011. }
  5012. if (throwWhenNotFound && !Clazz) {
  5013. throw new Error(
  5014. !subType
  5015. ? componentMainType + '.' + 'type should be specified.'
  5016. : 'Component ' + componentMainType + '.' + (subType || '') + ' not exists. Load it first.'
  5017. );
  5018. }
  5019. return Clazz;
  5020. };
  5021. entity.getClassesByMainType = function (componentType) {
  5022. componentType = parseClassType(componentType);
  5023. var result = [];
  5024. var obj = storage[componentType.main];
  5025. if (obj && obj[IS_CONTAINER]) {
  5026. zrUtil.each(obj, function (o, type) {
  5027. type !== IS_CONTAINER && result.push(o);
  5028. });
  5029. }
  5030. else {
  5031. result.push(obj);
  5032. }
  5033. return result;
  5034. };
  5035. entity.hasClass = function (componentType) {
  5036. // Just consider componentType.main.
  5037. componentType = parseClassType(componentType);
  5038. return !!storage[componentType.main];
  5039. };
  5040. /**
  5041. * @return {Array.<string>} Like ['aa', 'bb'], but can not be ['aa.xx']
  5042. */
  5043. entity.getAllClassMainTypes = function () {
  5044. var types = [];
  5045. zrUtil.each(storage, function (obj, type) {
  5046. types.push(type);
  5047. });
  5048. return types;
  5049. };
  5050. /**
  5051. * If a main type is container and has sub types
  5052. * @param {string} mainType
  5053. * @return {boolean}
  5054. */
  5055. entity.hasSubTypes = function (componentType) {
  5056. componentType = parseClassType(componentType);
  5057. var obj = storage[componentType.main];
  5058. return obj && obj[IS_CONTAINER];
  5059. };
  5060. entity.parseClassType = parseClassType;
  5061. function makeContainer(componentType) {
  5062. var container = storage[componentType.main];
  5063. if (!container || !container[IS_CONTAINER]) {
  5064. container = storage[componentType.main] = {};
  5065. container[IS_CONTAINER] = true;
  5066. }
  5067. return container;
  5068. }
  5069. if (options.registerWhenExtend) {
  5070. var originalExtend = entity.extend;
  5071. if (originalExtend) {
  5072. entity.extend = function (proto) {
  5073. var ExtendedClass = originalExtend.call(this, proto);
  5074. return entity.registerClass(ExtendedClass, proto.type);
  5075. };
  5076. }
  5077. }
  5078. return entity;
  5079. };
  5080. /**
  5081. * @param {string|Array.<string>} properties
  5082. */
  5083. clazz.setReadOnly = function (obj, properties) {
  5084. // FIXME It seems broken in IE8 simulation of IE11
  5085. // if (!zrUtil.isArray(properties)) {
  5086. // properties = properties != null ? [properties] : [];
  5087. // }
  5088. // zrUtil.each(properties, function (prop) {
  5089. // var value = obj[prop];
  5090. // Object.defineProperty
  5091. // && Object.defineProperty(obj, prop, {
  5092. // value: value, writable: false
  5093. // });
  5094. // zrUtil.isArray(obj[prop])
  5095. // && Object.freeze
  5096. // && Object.freeze(obj[prop]);
  5097. // });
  5098. };
  5099. module.exports = clazz;
  5100. /***/ },
  5101. /* 14 */
  5102. /***/ function(module, exports, __webpack_require__) {
  5103. var getLineStyle = __webpack_require__(15)(
  5104. [
  5105. ['lineWidth', 'width'],
  5106. ['stroke', 'color'],
  5107. ['opacity'],
  5108. ['shadowBlur'],
  5109. ['shadowOffsetX'],
  5110. ['shadowOffsetY'],
  5111. ['shadowColor']
  5112. ]
  5113. );
  5114. module.exports = {
  5115. getLineStyle: function (excludes) {
  5116. var style = getLineStyle.call(this, excludes);
  5117. var lineDash = this.getLineDash(style.lineWidth);
  5118. lineDash && (style.lineDash = lineDash);
  5119. return style;
  5120. },
  5121. getLineDash: function (lineWidth) {
  5122. if (lineWidth == null) {
  5123. lineWidth = 1;
  5124. }
  5125. var lineType = this.get('type');
  5126. var dotSize = Math.max(lineWidth, 2);
  5127. var dashSize = lineWidth * 4;
  5128. return (lineType === 'solid' || lineType == null) ? null
  5129. : (lineType === 'dashed' ? [dashSize, dashSize] : [dotSize, dotSize]);
  5130. }
  5131. };
  5132. /***/ },
  5133. /* 15 */
  5134. /***/ function(module, exports, __webpack_require__) {
  5135. // TODO Parse shadow style
  5136. // TODO Only shallow path support
  5137. var zrUtil = __webpack_require__(4);
  5138. module.exports = function (properties) {
  5139. // Normalize
  5140. for (var i = 0; i < properties.length; i++) {
  5141. if (!properties[i][1]) {
  5142. properties[i][1] = properties[i][0];
  5143. }
  5144. }
  5145. return function (excludes) {
  5146. var style = {};
  5147. for (var i = 0; i < properties.length; i++) {
  5148. var propName = properties[i][1];
  5149. if (excludes && zrUtil.indexOf(excludes, propName) >= 0) {
  5150. continue;
  5151. }
  5152. var val = this.getShallow(propName);
  5153. if (val != null) {
  5154. style[properties[i][0]] = val;
  5155. }
  5156. }
  5157. return style;
  5158. };
  5159. };
  5160. /***/ },
  5161. /* 16 */
  5162. /***/ function(module, exports, __webpack_require__) {
  5163. module.exports = {
  5164. getAreaStyle: __webpack_require__(15)(
  5165. [
  5166. ['fill', 'color'],
  5167. ['shadowBlur'],
  5168. ['shadowOffsetX'],
  5169. ['shadowOffsetY'],
  5170. ['opacity'],
  5171. ['shadowColor']
  5172. ]
  5173. )
  5174. };
  5175. /***/ },
  5176. /* 17 */
  5177. /***/ function(module, exports, __webpack_require__) {
  5178. var textContain = __webpack_require__(8);
  5179. function getShallow(model, path) {
  5180. return model && model.getShallow(path);
  5181. }
  5182. module.exports = {
  5183. /**
  5184. * Get color property or get color from option.textStyle.color
  5185. * @return {string}
  5186. */
  5187. getTextColor: function () {
  5188. var ecModel = this.ecModel;
  5189. return this.getShallow('color')
  5190. || (ecModel && ecModel.get('textStyle.color'));
  5191. },
  5192. /**
  5193. * Create font string from fontStyle, fontWeight, fontSize, fontFamily
  5194. * @return {string}
  5195. */
  5196. getFont: function () {
  5197. var ecModel = this.ecModel;
  5198. var gTextStyleModel = ecModel && ecModel.getModel('textStyle');
  5199. return [
  5200. // FIXME in node-canvas fontWeight is before fontStyle
  5201. this.getShallow('fontStyle') || getShallow(gTextStyleModel, 'fontStyle'),
  5202. this.getShallow('fontWeight') || getShallow(gTextStyleModel, 'fontWeight'),
  5203. (this.getShallow('fontSize') || getShallow(gTextStyleModel, 'fontSize') || 12) + 'px',
  5204. this.getShallow('fontFamily') || getShallow(gTextStyleModel, 'fontFamily') || 'sans-serif'
  5205. ].join(' ');
  5206. },
  5207. getTextRect: function (text) {
  5208. return textContain.getBoundingRect(
  5209. text,
  5210. this.getFont(),
  5211. this.getShallow('align'),
  5212. this.getShallow('baseline')
  5213. );
  5214. },
  5215. truncateText: function (text, containerWidth, ellipsis, options) {
  5216. return textContain.truncateText(
  5217. text, containerWidth, this.getFont(), ellipsis, options
  5218. );
  5219. }
  5220. };
  5221. /***/ },
  5222. /* 18 */
  5223. /***/ function(module, exports, __webpack_require__) {
  5224. var getItemStyle = __webpack_require__(15)(
  5225. [
  5226. ['fill', 'color'],
  5227. ['stroke', 'borderColor'],
  5228. ['lineWidth', 'borderWidth'],
  5229. ['opacity'],
  5230. ['shadowBlur'],
  5231. ['shadowOffsetX'],
  5232. ['shadowOffsetY'],
  5233. ['shadowColor'],
  5234. ['textPosition'],
  5235. ['textAlign']
  5236. ]
  5237. );
  5238. module.exports = {
  5239. getItemStyle: function (excludes) {
  5240. var style = getItemStyle.call(this, excludes);
  5241. var lineDash = this.getBorderLineDash();
  5242. lineDash && (style.lineDash = lineDash);
  5243. return style;
  5244. },
  5245. getBorderLineDash: function () {
  5246. var lineType = this.get('borderType');
  5247. return (lineType === 'solid' || lineType == null) ? null
  5248. : (lineType === 'dashed' ? [5, 5] : [1, 1]);
  5249. }
  5250. };
  5251. /***/ },
  5252. /* 19 */
  5253. /***/ function(module, exports, __webpack_require__) {
  5254. /**
  5255. * Component model
  5256. *
  5257. * @module echarts/model/Component
  5258. */
  5259. var Model = __webpack_require__(12);
  5260. var zrUtil = __webpack_require__(4);
  5261. var arrayPush = Array.prototype.push;
  5262. var componentUtil = __webpack_require__(20);
  5263. var clazzUtil = __webpack_require__(13);
  5264. var layout = __webpack_require__(21);
  5265. /**
  5266. * @alias module:echarts/model/Component
  5267. * @constructor
  5268. * @param {Object} option
  5269. * @param {module:echarts/model/Model} parentModel
  5270. * @param {module:echarts/model/Model} ecModel
  5271. */
  5272. var ComponentModel = Model.extend({
  5273. type: 'component',
  5274. /**
  5275. * @readOnly
  5276. * @type {string}
  5277. */
  5278. id: '',
  5279. /**
  5280. * @readOnly
  5281. */
  5282. name: '',
  5283. /**
  5284. * @readOnly
  5285. * @type {string}
  5286. */
  5287. mainType: '',
  5288. /**
  5289. * @readOnly
  5290. * @type {string}
  5291. */
  5292. subType: '',
  5293. /**
  5294. * @readOnly
  5295. * @type {number}
  5296. */
  5297. componentIndex: 0,
  5298. /**
  5299. * @type {Object}
  5300. * @protected
  5301. */
  5302. defaultOption: null,
  5303. /**
  5304. * @type {module:echarts/model/Global}
  5305. * @readOnly
  5306. */
  5307. ecModel: null,
  5308. /**
  5309. * key: componentType
  5310. * value: Component model list, can not be null.
  5311. * @type {Object.<string, Array.<module:echarts/model/Model>>}
  5312. * @readOnly
  5313. */
  5314. dependentModels: [],
  5315. /**
  5316. * @type {string}
  5317. * @readOnly
  5318. */
  5319. uid: null,
  5320. /**
  5321. * Support merge layout params.
  5322. * Only support 'box' now (left/right/top/bottom/width/height).
  5323. * @type {string|Object} Object can be {ignoreSize: true}
  5324. * @readOnly
  5325. */
  5326. layoutMode: null,
  5327. $constructor: function (option, parentModel, ecModel, extraOpt) {
  5328. Model.call(this, option, parentModel, ecModel, extraOpt);
  5329. this.uid = componentUtil.getUID('componentModel');
  5330. },
  5331. init: function (option, parentModel, ecModel, extraOpt) {
  5332. this.mergeDefaultAndTheme(option, ecModel);
  5333. },
  5334. mergeDefaultAndTheme: function (option, ecModel) {
  5335. var layoutMode = this.layoutMode;
  5336. var inputPositionParams = layoutMode
  5337. ? layout.getLayoutParams(option) : {};
  5338. var themeModel = ecModel.getTheme();
  5339. zrUtil.merge(option, themeModel.get(this.mainType));
  5340. zrUtil.merge(option, this.getDefaultOption());
  5341. if (layoutMode) {
  5342. layout.mergeLayoutParam(option, inputPositionParams, layoutMode);
  5343. }
  5344. },
  5345. mergeOption: function (option, extraOpt) {
  5346. zrUtil.merge(this.option, option, true);
  5347. var layoutMode = this.layoutMode;
  5348. if (layoutMode) {
  5349. layout.mergeLayoutParam(this.option, option, layoutMode);
  5350. }
  5351. },
  5352. // Hooker after init or mergeOption
  5353. optionUpdated: function (newCptOption, isInit) {},
  5354. getDefaultOption: function () {
  5355. if (!clazzUtil.hasOwn(this, '__defaultOption')) {
  5356. var optList = [];
  5357. var Class = this.constructor;
  5358. while (Class) {
  5359. var opt = Class.prototype.defaultOption;
  5360. opt && optList.push(opt);
  5361. Class = Class.superClass;
  5362. }
  5363. var defaultOption = {};
  5364. for (var i = optList.length - 1; i >= 0; i--) {
  5365. defaultOption = zrUtil.merge(defaultOption, optList[i], true);
  5366. }
  5367. clazzUtil.set(this, '__defaultOption', defaultOption);
  5368. }
  5369. return clazzUtil.get(this, '__defaultOption');
  5370. },
  5371. getReferringComponents: function (mainType) {
  5372. return this.ecModel.queryComponents({
  5373. mainType: mainType,
  5374. index: this.get(mainType + 'Index', true),
  5375. id: this.get(mainType + 'Id', true)
  5376. });
  5377. }
  5378. });
  5379. // Reset ComponentModel.extend, add preConstruct.
  5380. // clazzUtil.enableClassExtend(
  5381. // ComponentModel,
  5382. // function (option, parentModel, ecModel, extraOpt) {
  5383. // // Set dependentModels, componentIndex, name, id, mainType, subType.
  5384. // zrUtil.extend(this, extraOpt);
  5385. // this.uid = componentUtil.getUID('componentModel');
  5386. // // this.setReadOnly([
  5387. // // 'type', 'id', 'uid', 'name', 'mainType', 'subType',
  5388. // // 'dependentModels', 'componentIndex'
  5389. // // ]);
  5390. // }
  5391. // );
  5392. // Add capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  5393. clazzUtil.enableClassManagement(
  5394. ComponentModel, {registerWhenExtend: true}
  5395. );
  5396. componentUtil.enableSubTypeDefaulter(ComponentModel);
  5397. // Add capability of ComponentModel.topologicalTravel.
  5398. componentUtil.enableTopologicalTravel(ComponentModel, getDependencies);
  5399. function getDependencies(componentType) {
  5400. var deps = [];
  5401. zrUtil.each(ComponentModel.getClassesByMainType(componentType), function (Clazz) {
  5402. arrayPush.apply(deps, Clazz.prototype.dependencies || []);
  5403. });
  5404. // Ensure main type
  5405. return zrUtil.map(deps, function (type) {
  5406. return clazzUtil.parseClassType(type).main;
  5407. });
  5408. }
  5409. zrUtil.mixin(ComponentModel, __webpack_require__(22));
  5410. module.exports = ComponentModel;
  5411. /***/ },
  5412. /* 20 */
  5413. /***/ function(module, exports, __webpack_require__) {
  5414. var zrUtil = __webpack_require__(4);
  5415. var clazz = __webpack_require__(13);
  5416. var parseClassType = clazz.parseClassType;
  5417. var base = 0;
  5418. var componentUtil = {};
  5419. var DELIMITER = '_';
  5420. /**
  5421. * @public
  5422. * @param {string} type
  5423. * @return {string}
  5424. */
  5425. componentUtil.getUID = function (type) {
  5426. // Considering the case of crossing js context,
  5427. // use Math.random to make id as unique as possible.
  5428. return [(type || ''), base++, Math.random()].join(DELIMITER);
  5429. };
  5430. /**
  5431. * @inner
  5432. */
  5433. componentUtil.enableSubTypeDefaulter = function (entity) {
  5434. var subTypeDefaulters = {};
  5435. entity.registerSubTypeDefaulter = function (componentType, defaulter) {
  5436. componentType = parseClassType(componentType);
  5437. subTypeDefaulters[componentType.main] = defaulter;
  5438. };
  5439. entity.determineSubType = function (componentType, option) {
  5440. var type = option.type;
  5441. if (!type) {
  5442. var componentTypeMain = parseClassType(componentType).main;
  5443. if (entity.hasSubTypes(componentType) && subTypeDefaulters[componentTypeMain]) {
  5444. type = subTypeDefaulters[componentTypeMain](option);
  5445. }
  5446. }
  5447. return type;
  5448. };
  5449. return entity;
  5450. };
  5451. /**
  5452. * Topological travel on Activity Network (Activity On Vertices).
  5453. * Dependencies is defined in Model.prototype.dependencies, like ['xAxis', 'yAxis'].
  5454. *
  5455. * If 'xAxis' or 'yAxis' is absent in componentTypeList, just ignore it in topology.
  5456. *
  5457. * If there is circle dependencey, Error will be thrown.
  5458. *
  5459. */
  5460. componentUtil.enableTopologicalTravel = function (entity, dependencyGetter) {
  5461. /**
  5462. * @public
  5463. * @param {Array.<string>} targetNameList Target Component type list.
  5464. * Can be ['aa', 'bb', 'aa.xx']
  5465. * @param {Array.<string>} fullNameList By which we can build dependency graph.
  5466. * @param {Function} callback Params: componentType, dependencies.
  5467. * @param {Object} context Scope of callback.
  5468. */
  5469. entity.topologicalTravel = function (targetNameList, fullNameList, callback, context) {
  5470. if (!targetNameList.length) {
  5471. return;
  5472. }
  5473. var result = makeDepndencyGraph(fullNameList);
  5474. var graph = result.graph;
  5475. var stack = result.noEntryList;
  5476. var targetNameSet = {};
  5477. zrUtil.each(targetNameList, function (name) {
  5478. targetNameSet[name] = true;
  5479. });
  5480. while (stack.length) {
  5481. var currComponentType = stack.pop();
  5482. var currVertex = graph[currComponentType];
  5483. var isInTargetNameSet = !!targetNameSet[currComponentType];
  5484. if (isInTargetNameSet) {
  5485. callback.call(context, currComponentType, currVertex.originalDeps.slice());
  5486. delete targetNameSet[currComponentType];
  5487. }
  5488. zrUtil.each(
  5489. currVertex.successor,
  5490. isInTargetNameSet ? removeEdgeAndAdd : removeEdge
  5491. );
  5492. }
  5493. zrUtil.each(targetNameSet, function () {
  5494. throw new Error('Circle dependency may exists');
  5495. });
  5496. function removeEdge(succComponentType) {
  5497. graph[succComponentType].entryCount--;
  5498. if (graph[succComponentType].entryCount === 0) {
  5499. stack.push(succComponentType);
  5500. }
  5501. }
  5502. // Consider this case: legend depends on series, and we call
  5503. // chart.setOption({series: [...]}), where only series is in option.
  5504. // If we do not have 'removeEdgeAndAdd', legendModel.mergeOption will
  5505. // not be called, but only sereis.mergeOption is called. Thus legend
  5506. // have no chance to update its local record about series (like which
  5507. // name of series is available in legend).
  5508. function removeEdgeAndAdd(succComponentType) {
  5509. targetNameSet[succComponentType] = true;
  5510. removeEdge(succComponentType);
  5511. }
  5512. };
  5513. /**
  5514. * DepndencyGraph: {Object}
  5515. * key: conponentType,
  5516. * value: {
  5517. * successor: [conponentTypes...],
  5518. * originalDeps: [conponentTypes...],
  5519. * entryCount: {number}
  5520. * }
  5521. */
  5522. function makeDepndencyGraph(fullNameList) {
  5523. var graph = {};
  5524. var noEntryList = [];
  5525. zrUtil.each(fullNameList, function (name) {
  5526. var thisItem = createDependencyGraphItem(graph, name);
  5527. var originalDeps = thisItem.originalDeps = dependencyGetter(name);
  5528. var availableDeps = getAvailableDependencies(originalDeps, fullNameList);
  5529. thisItem.entryCount = availableDeps.length;
  5530. if (thisItem.entryCount === 0) {
  5531. noEntryList.push(name);
  5532. }
  5533. zrUtil.each(availableDeps, function (dependentName) {
  5534. if (zrUtil.indexOf(thisItem.predecessor, dependentName) < 0) {
  5535. thisItem.predecessor.push(dependentName);
  5536. }
  5537. var thatItem = createDependencyGraphItem(graph, dependentName);
  5538. if (zrUtil.indexOf(thatItem.successor, dependentName) < 0) {
  5539. thatItem.successor.push(name);
  5540. }
  5541. });
  5542. });
  5543. return {graph: graph, noEntryList: noEntryList};
  5544. }
  5545. function createDependencyGraphItem(graph, name) {
  5546. if (!graph[name]) {
  5547. graph[name] = {predecessor: [], successor: []};
  5548. }
  5549. return graph[name];
  5550. }
  5551. function getAvailableDependencies(originalDeps, fullNameList) {
  5552. var availableDeps = [];
  5553. zrUtil.each(originalDeps, function (dep) {
  5554. zrUtil.indexOf(fullNameList, dep) >= 0 && availableDeps.push(dep);
  5555. });
  5556. return availableDeps;
  5557. }
  5558. };
  5559. module.exports = componentUtil;
  5560. /***/ },
  5561. /* 21 */
  5562. /***/ function(module, exports, __webpack_require__) {
  5563. 'use strict';
  5564. // Layout helpers for each component positioning
  5565. var zrUtil = __webpack_require__(4);
  5566. var BoundingRect = __webpack_require__(9);
  5567. var numberUtil = __webpack_require__(7);
  5568. var formatUtil = __webpack_require__(6);
  5569. var parsePercent = numberUtil.parsePercent;
  5570. var each = zrUtil.each;
  5571. var layout = {};
  5572. var LOCATION_PARAMS = layout.LOCATION_PARAMS = [
  5573. 'left', 'right', 'top', 'bottom', 'width', 'height'
  5574. ];
  5575. function boxLayout(orient, group, gap, maxWidth, maxHeight) {
  5576. var x = 0;
  5577. var y = 0;
  5578. if (maxWidth == null) {
  5579. maxWidth = Infinity;
  5580. }
  5581. if (maxHeight == null) {
  5582. maxHeight = Infinity;
  5583. }
  5584. var currentLineMaxSize = 0;
  5585. group.eachChild(function (child, idx) {
  5586. var position = child.position;
  5587. var rect = child.getBoundingRect();
  5588. var nextChild = group.childAt(idx + 1);
  5589. var nextChildRect = nextChild && nextChild.getBoundingRect();
  5590. var nextX;
  5591. var nextY;
  5592. if (orient === 'horizontal') {
  5593. var moveX = rect.width + (nextChildRect ? (-nextChildRect.x + rect.x) : 0);
  5594. nextX = x + moveX;
  5595. // Wrap when width exceeds maxWidth or meet a `newline` group
  5596. if (nextX > maxWidth || child.newline) {
  5597. x = 0;
  5598. nextX = moveX;
  5599. y += currentLineMaxSize + gap;
  5600. currentLineMaxSize = rect.height;
  5601. }
  5602. else {
  5603. currentLineMaxSize = Math.max(currentLineMaxSize, rect.height);
  5604. }
  5605. }
  5606. else {
  5607. var moveY = rect.height + (nextChildRect ? (-nextChildRect.y + rect.y) : 0);
  5608. nextY = y + moveY;
  5609. // Wrap when width exceeds maxHeight or meet a `newline` group
  5610. if (nextY > maxHeight || child.newline) {
  5611. x += currentLineMaxSize + gap;
  5612. y = 0;
  5613. nextY = moveY;
  5614. currentLineMaxSize = rect.width;
  5615. }
  5616. else {
  5617. currentLineMaxSize = Math.max(currentLineMaxSize, rect.width);
  5618. }
  5619. }
  5620. if (child.newline) {
  5621. return;
  5622. }
  5623. position[0] = x;
  5624. position[1] = y;
  5625. orient === 'horizontal'
  5626. ? (x = nextX + gap)
  5627. : (y = nextY + gap);
  5628. });
  5629. }
  5630. /**
  5631. * VBox or HBox layouting
  5632. * @param {string} orient
  5633. * @param {module:zrender/container/Group} group
  5634. * @param {number} gap
  5635. * @param {number} [width=Infinity]
  5636. * @param {number} [height=Infinity]
  5637. */
  5638. layout.box = boxLayout;
  5639. /**
  5640. * VBox layouting
  5641. * @param {module:zrender/container/Group} group
  5642. * @param {number} gap
  5643. * @param {number} [width=Infinity]
  5644. * @param {number} [height=Infinity]
  5645. */
  5646. layout.vbox = zrUtil.curry(boxLayout, 'vertical');
  5647. /**
  5648. * HBox layouting
  5649. * @param {module:zrender/container/Group} group
  5650. * @param {number} gap
  5651. * @param {number} [width=Infinity]
  5652. * @param {number} [height=Infinity]
  5653. */
  5654. layout.hbox = zrUtil.curry(boxLayout, 'horizontal');
  5655. /**
  5656. * If x or x2 is not specified or 'center' 'left' 'right',
  5657. * the width would be as long as possible.
  5658. * If y or y2 is not specified or 'middle' 'top' 'bottom',
  5659. * the height would be as long as possible.
  5660. *
  5661. * @param {Object} positionInfo
  5662. * @param {number|string} [positionInfo.x]
  5663. * @param {number|string} [positionInfo.y]
  5664. * @param {number|string} [positionInfo.x2]
  5665. * @param {number|string} [positionInfo.y2]
  5666. * @param {Object} containerRect
  5667. * @param {string|number} margin
  5668. * @return {Object} {width, height}
  5669. */
  5670. layout.getAvailableSize = function (positionInfo, containerRect, margin) {
  5671. var containerWidth = containerRect.width;
  5672. var containerHeight = containerRect.height;
  5673. var x = parsePercent(positionInfo.x, containerWidth);
  5674. var y = parsePercent(positionInfo.y, containerHeight);
  5675. var x2 = parsePercent(positionInfo.x2, containerWidth);
  5676. var y2 = parsePercent(positionInfo.y2, containerHeight);
  5677. (isNaN(x) || isNaN(parseFloat(positionInfo.x))) && (x = 0);
  5678. (isNaN(x2) || isNaN(parseFloat(positionInfo.x2))) && (x2 = containerWidth);
  5679. (isNaN(y) || isNaN(parseFloat(positionInfo.y))) && (y = 0);
  5680. (isNaN(y2) || isNaN(parseFloat(positionInfo.y2))) && (y2 = containerHeight);
  5681. margin = formatUtil.normalizeCssArray(margin || 0);
  5682. return {
  5683. width: Math.max(x2 - x - margin[1] - margin[3], 0),
  5684. height: Math.max(y2 - y - margin[0] - margin[2], 0)
  5685. };
  5686. };
  5687. /**
  5688. * Parse position info.
  5689. *
  5690. * @param {Object} positionInfo
  5691. * @param {number|string} [positionInfo.left]
  5692. * @param {number|string} [positionInfo.top]
  5693. * @param {number|string} [positionInfo.right]
  5694. * @param {number|string} [positionInfo.bottom]
  5695. * @param {number|string} [positionInfo.width]
  5696. * @param {number|string} [positionInfo.height]
  5697. * @param {number|string} [positionInfo.aspect] Aspect is width / height
  5698. * @param {Object} containerRect
  5699. * @param {string|number} [margin]
  5700. *
  5701. * @return {module:zrender/core/BoundingRect}
  5702. */
  5703. layout.getLayoutRect = function (
  5704. positionInfo, containerRect, margin
  5705. ) {
  5706. margin = formatUtil.normalizeCssArray(margin || 0);
  5707. var containerWidth = containerRect.width;
  5708. var containerHeight = containerRect.height;
  5709. var left = parsePercent(positionInfo.left, containerWidth);
  5710. var top = parsePercent(positionInfo.top, containerHeight);
  5711. var right = parsePercent(positionInfo.right, containerWidth);
  5712. var bottom = parsePercent(positionInfo.bottom, containerHeight);
  5713. var width = parsePercent(positionInfo.width, containerWidth);
  5714. var height = parsePercent(positionInfo.height, containerHeight);
  5715. var verticalMargin = margin[2] + margin[0];
  5716. var horizontalMargin = margin[1] + margin[3];
  5717. var aspect = positionInfo.aspect;
  5718. // If width is not specified, calculate width from left and right
  5719. if (isNaN(width)) {
  5720. width = containerWidth - right - horizontalMargin - left;
  5721. }
  5722. if (isNaN(height)) {
  5723. height = containerHeight - bottom - verticalMargin - top;
  5724. }
  5725. // If width and height are not given
  5726. // 1. Graph should not exceeds the container
  5727. // 2. Aspect must be keeped
  5728. // 3. Graph should take the space as more as possible
  5729. if (isNaN(width) && isNaN(height)) {
  5730. if (aspect > containerWidth / containerHeight) {
  5731. width = containerWidth * 0.8;
  5732. }
  5733. else {
  5734. height = containerHeight * 0.8;
  5735. }
  5736. }
  5737. if (aspect != null) {
  5738. // Calculate width or height with given aspect
  5739. if (isNaN(width)) {
  5740. width = aspect * height;
  5741. }
  5742. if (isNaN(height)) {
  5743. height = width / aspect;
  5744. }
  5745. }
  5746. // If left is not specified, calculate left from right and width
  5747. if (isNaN(left)) {
  5748. left = containerWidth - right - width - horizontalMargin;
  5749. }
  5750. if (isNaN(top)) {
  5751. top = containerHeight - bottom - height - verticalMargin;
  5752. }
  5753. // Align left and top
  5754. switch (positionInfo.left || positionInfo.right) {
  5755. case 'center':
  5756. left = containerWidth / 2 - width / 2 - margin[3];
  5757. break;
  5758. case 'right':
  5759. left = containerWidth - width - horizontalMargin;
  5760. break;
  5761. }
  5762. switch (positionInfo.top || positionInfo.bottom) {
  5763. case 'middle':
  5764. case 'center':
  5765. top = containerHeight / 2 - height / 2 - margin[0];
  5766. break;
  5767. case 'bottom':
  5768. top = containerHeight - height - verticalMargin;
  5769. break;
  5770. }
  5771. // If something is wrong and left, top, width, height are calculated as NaN
  5772. left = left || 0;
  5773. top = top || 0;
  5774. if (isNaN(width)) {
  5775. // Width may be NaN if only one value is given except width
  5776. width = containerWidth - left - (right || 0);
  5777. }
  5778. if (isNaN(height)) {
  5779. // Height may be NaN if only one value is given except height
  5780. height = containerHeight - top - (bottom || 0);
  5781. }
  5782. var rect = new BoundingRect(left + margin[3], top + margin[0], width, height);
  5783. rect.margin = margin;
  5784. return rect;
  5785. };
  5786. /**
  5787. * Position a zr element in viewport
  5788. * Group position is specified by either
  5789. * {left, top}, {right, bottom}
  5790. * If all properties exists, right and bottom will be igonred.
  5791. *
  5792. * Logic:
  5793. * 1. Scale (against origin point in parent coord)
  5794. * 2. Rotate (against origin point in parent coord)
  5795. * 3. Traslate (with el.position by this method)
  5796. * So this method only fixes the last step 'Traslate', which does not affect
  5797. * scaling and rotating.
  5798. *
  5799. * If be called repeatly with the same input el, the same result will be gotten.
  5800. *
  5801. * @param {module:zrender/Element} el Should have `getBoundingRect` method.
  5802. * @param {Object} positionInfo
  5803. * @param {number|string} [positionInfo.left]
  5804. * @param {number|string} [positionInfo.top]
  5805. * @param {number|string} [positionInfo.right]
  5806. * @param {number|string} [positionInfo.bottom]
  5807. * @param {Object} containerRect
  5808. * @param {string|number} margin
  5809. * @param {Object} [opt]
  5810. * @param {Array.<number>} [opt.hv=[1,1]] Only horizontal or only vertical.
  5811. * @param {Array.<number>} [opt.boundingMode='all']
  5812. * Specify how to calculate boundingRect when locating.
  5813. * 'all': Position the boundingRect that is transformed and uioned
  5814. * both itself and its descendants.
  5815. * This mode simplies confine the elements in the bounding
  5816. * of their container (e.g., using 'right: 0').
  5817. * 'raw': Position the boundingRect that is not transformed and only itself.
  5818. * This mode is useful when you want a element can overflow its
  5819. * container. (Consider a rotated circle needs to be located in a corner.)
  5820. * In this mode positionInfo.width/height can only be number.
  5821. */
  5822. layout.positionElement = function (el, positionInfo, containerRect, margin, opt) {
  5823. var h = !opt || !opt.hv || opt.hv[0];
  5824. var v = !opt || !opt.hv || opt.hv[1];
  5825. var boundingMode = opt && opt.boundingMode || 'all';
  5826. if (!h && !v) {
  5827. return;
  5828. }
  5829. var rect;
  5830. if (boundingMode === 'raw') {
  5831. rect = el.type === 'group'
  5832. ? new BoundingRect(0, 0, +positionInfo.width || 0, +positionInfo.height || 0)
  5833. : el.getBoundingRect();
  5834. }
  5835. else {
  5836. rect = el.getBoundingRect();
  5837. if (el.needLocalTransform()) {
  5838. var transform = el.getLocalTransform();
  5839. // Notice: raw rect may be inner object of el,
  5840. // which should not be modified.
  5841. rect = rect.clone();
  5842. rect.applyTransform(transform);
  5843. }
  5844. }
  5845. positionInfo = layout.getLayoutRect(
  5846. zrUtil.defaults(
  5847. {width: rect.width, height: rect.height},
  5848. positionInfo
  5849. ),
  5850. containerRect,
  5851. margin
  5852. );
  5853. // Because 'tranlate' is the last step in transform
  5854. // (see zrender/core/Transformable#getLocalTransfrom),
  5855. // we can just only modify el.position to get final result.
  5856. var elPos = el.position;
  5857. var dx = h ? positionInfo.x - rect.x : 0;
  5858. var dy = v ? positionInfo.y - rect.y : 0;
  5859. el.attr('position', boundingMode === 'raw' ? [dx, dy] : [elPos[0] + dx, elPos[1] + dy]);
  5860. };
  5861. /**
  5862. * Consider Case:
  5863. * When defulat option has {left: 0, width: 100}, and we set {right: 0}
  5864. * through setOption or media query, using normal zrUtil.merge will cause
  5865. * {right: 0} does not take effect.
  5866. *
  5867. * @example
  5868. * ComponentModel.extend({
  5869. * init: function () {
  5870. * ...
  5871. * var inputPositionParams = layout.getLayoutParams(option);
  5872. * this.mergeOption(inputPositionParams);
  5873. * },
  5874. * mergeOption: function (newOption) {
  5875. * newOption && zrUtil.merge(thisOption, newOption, true);
  5876. * layout.mergeLayoutParam(thisOption, newOption);
  5877. * }
  5878. * });
  5879. *
  5880. * @param {Object} targetOption
  5881. * @param {Object} newOption
  5882. * @param {Object|string} [opt]
  5883. * @param {boolean} [opt.ignoreSize=false] Some component must has width and height.
  5884. */
  5885. layout.mergeLayoutParam = function (targetOption, newOption, opt) {
  5886. !zrUtil.isObject(opt) && (opt = {});
  5887. var hNames = ['width', 'left', 'right']; // Order by priority.
  5888. var vNames = ['height', 'top', 'bottom']; // Order by priority.
  5889. var hResult = merge(hNames);
  5890. var vResult = merge(vNames);
  5891. copy(hNames, targetOption, hResult);
  5892. copy(vNames, targetOption, vResult);
  5893. function merge(names) {
  5894. var newParams = {};
  5895. var newValueCount = 0;
  5896. var merged = {};
  5897. var mergedValueCount = 0;
  5898. var enoughParamNumber = opt.ignoreSize ? 1 : 2;
  5899. each(names, function (name) {
  5900. merged[name] = targetOption[name];
  5901. });
  5902. each(names, function (name) {
  5903. // Consider case: newOption.width is null, which is
  5904. // set by user for removing width setting.
  5905. hasProp(newOption, name) && (newParams[name] = merged[name] = newOption[name]);
  5906. hasValue(newParams, name) && newValueCount++;
  5907. hasValue(merged, name) && mergedValueCount++;
  5908. });
  5909. // Case: newOption: {width: ..., right: ...},
  5910. // or targetOption: {right: ...} and newOption: {width: ...},
  5911. // There is no conflict when merged only has params count
  5912. // little than enoughParamNumber.
  5913. if (mergedValueCount === enoughParamNumber || !newValueCount) {
  5914. return merged;
  5915. }
  5916. // Case: newOption: {width: ..., right: ...},
  5917. // Than we can make sure user only want those two, and ignore
  5918. // all origin params in targetOption.
  5919. else if (newValueCount >= enoughParamNumber) {
  5920. return newParams;
  5921. }
  5922. else {
  5923. // Chose another param from targetOption by priority.
  5924. // When 'ignoreSize', enoughParamNumber is 1 and those will not happen.
  5925. for (var i = 0; i < names.length; i++) {
  5926. var name = names[i];
  5927. if (!hasProp(newParams, name) && hasProp(targetOption, name)) {
  5928. newParams[name] = targetOption[name];
  5929. break;
  5930. }
  5931. }
  5932. return newParams;
  5933. }
  5934. }
  5935. function hasProp(obj, name) {
  5936. return obj.hasOwnProperty(name);
  5937. }
  5938. function hasValue(obj, name) {
  5939. return obj[name] != null && obj[name] !== 'auto';
  5940. }
  5941. function copy(names, target, source) {
  5942. each(names, function (name) {
  5943. target[name] = source[name];
  5944. });
  5945. }
  5946. };
  5947. /**
  5948. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  5949. * @param {Object} source
  5950. * @return {Object} Result contains those props.
  5951. */
  5952. layout.getLayoutParams = function (source) {
  5953. return layout.copyLayoutParams({}, source);
  5954. };
  5955. /**
  5956. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  5957. * @param {Object} source
  5958. * @return {Object} Result contains those props.
  5959. */
  5960. layout.copyLayoutParams = function (target, source) {
  5961. source && target && each(LOCATION_PARAMS, function (name) {
  5962. source.hasOwnProperty(name) && (target[name] = source[name]);
  5963. });
  5964. return target;
  5965. };
  5966. module.exports = layout;
  5967. /***/ },
  5968. /* 22 */
  5969. /***/ function(module, exports) {
  5970. module.exports = {
  5971. getBoxLayoutParams: function () {
  5972. return {
  5973. left: this.get('left'),
  5974. top: this.get('top'),
  5975. right: this.get('right'),
  5976. bottom: this.get('bottom'),
  5977. width: this.get('width'),
  5978. height: this.get('height')
  5979. };
  5980. }
  5981. };
  5982. /***/ },
  5983. /* 23 */
  5984. /***/ function(module, exports) {
  5985. var platform = '';
  5986. // Navigator not exists in node
  5987. if (typeof navigator !== 'undefined') {
  5988. platform = navigator.platform || '';
  5989. }
  5990. module.exports = {
  5991. // 全图默认背景
  5992. // backgroundColor: 'rgba(0,0,0,0)',
  5993. // https://dribbble.com/shots/1065960-Infographic-Pie-chart-visualization
  5994. // color: ['#5793f3', '#d14a61', '#fd9c35', '#675bba', '#fec42c', '#dd4444', '#d4df5a', '#cd4870'],
  5995. // 浅色
  5996. // color: ['#bcd3bb', '#e88f70', '#edc1a5', '#9dc5c8', '#e1e8c8', '#7b7c68', '#e5b5b5', '#f0b489', '#928ea8', '#bda29a'],
  5997. // color: ['#cc5664', '#9bd6ec', '#ea946e', '#8acaaa', '#f1ec64', '#ee8686', '#a48dc1', '#5da6bc', '#b9dcae'],
  5998. // 深色
  5999. color: ['#c23531','#2f4554', '#61a0a8', '#d48265', '#91c7ae','#749f83', '#ca8622', '#bda29a','#6e7074', '#546570', '#c4ccd3'],
  6000. // 默认需要 Grid 配置项
  6001. // grid: {},
  6002. // 主题,主题
  6003. textStyle: {
  6004. // color: '#000',
  6005. // decoration: 'none',
  6006. // PENDING
  6007. fontFamily: platform.match(/^Win/) ? 'Microsoft YaHei' : 'sans-serif',
  6008. // fontFamily: 'Arial, Verdana, sans-serif',
  6009. fontSize: 12,
  6010. fontStyle: 'normal',
  6011. fontWeight: 'normal'
  6012. },
  6013. // http://blogs.adobe.com/webplatform/2014/02/24/using-blend-modes-in-html-canvas/
  6014. // https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
  6015. // Default is source-over
  6016. blendMode: null,
  6017. animation: true,
  6018. animationDuration: 1000,
  6019. animationDurationUpdate: 300,
  6020. animationEasing: 'exponentialOut',
  6021. animationEasingUpdate: 'cubicOut',
  6022. animationThreshold: 2000,
  6023. // Configuration for progressive/incremental rendering
  6024. progressiveThreshold: 3000,
  6025. progressive: 400,
  6026. // Threshold of if use single hover layer to optimize.
  6027. // It is recommended that `hoverLayerThreshold` is equivalent to or less than
  6028. // `progressiveThreshold`, otherwise hover will cause restart of progressive,
  6029. // which is unexpected.
  6030. // see example <echarts/test/heatmap-large.html>.
  6031. hoverLayerThreshold: 3000
  6032. };
  6033. /***/ },
  6034. /* 24 */
  6035. /***/ function(module, exports, __webpack_require__) {
  6036. var classUtil = __webpack_require__(13);
  6037. var set = classUtil.set;
  6038. var get = classUtil.get;
  6039. module.exports = {
  6040. clearColorPalette: function () {
  6041. set(this, 'colorIdx', 0);
  6042. set(this, 'colorNameMap', {});
  6043. },
  6044. getColorFromPalette: function (name, scope) {
  6045. scope = scope || this;
  6046. var colorIdx = get(scope, 'colorIdx') || 0;
  6047. var colorNameMap = get(scope, 'colorNameMap') || set(scope, 'colorNameMap', {});
  6048. if (colorNameMap[name]) {
  6049. return colorNameMap[name];
  6050. }
  6051. var colorPalette = this.get('color', true) || [];
  6052. if (!colorPalette.length) {
  6053. return;
  6054. }
  6055. var color = colorPalette[colorIdx];
  6056. if (name) {
  6057. colorNameMap[name] = color;
  6058. }
  6059. set(scope, 'colorIdx', (colorIdx + 1) % colorPalette.length);
  6060. return color;
  6061. }
  6062. };
  6063. /***/ },
  6064. /* 25 */
  6065. /***/ function(module, exports, __webpack_require__) {
  6066. 'use strict';
  6067. var zrUtil = __webpack_require__(4);
  6068. var echartsAPIList = [
  6069. 'getDom', 'getZr', 'getWidth', 'getHeight', 'dispatchAction', 'isDisposed',
  6070. 'on', 'off', 'getDataURL', 'getConnectedDataURL', 'getModel', 'getOption'
  6071. ];
  6072. function ExtensionAPI(chartInstance) {
  6073. zrUtil.each(echartsAPIList, function (name) {
  6074. this[name] = zrUtil.bind(chartInstance[name], chartInstance);
  6075. }, this);
  6076. }
  6077. module.exports = ExtensionAPI;
  6078. /***/ },
  6079. /* 26 */
  6080. /***/ function(module, exports, __webpack_require__) {
  6081. 'use strict';
  6082. var zrUtil = __webpack_require__(4);
  6083. /**
  6084. * Interface of Coordinate System Class
  6085. *
  6086. * create:
  6087. * @param {module:echarts/model/Global} ecModel
  6088. * @param {module:echarts/ExtensionAPI} api
  6089. * @return {Object} coordinate system instance
  6090. *
  6091. * update:
  6092. * @param {module:echarts/model/Global} ecModel
  6093. * @param {module:echarts/ExtensionAPI} api
  6094. *
  6095. * convertToPixel:
  6096. * convertFromPixel:
  6097. * These two methods is also responsible for determine whether this
  6098. * coodinate system is applicable to the given `finder`.
  6099. * Each coordinate system will be tried, util one returns none
  6100. * null/undefined value.
  6101. * @param {module:echarts/model/Global} ecModel
  6102. * @param {Object} finder
  6103. * @param {Array|number} value
  6104. * @return {Array|number} convert result.
  6105. *
  6106. * containPoint:
  6107. * @param {Array.<number>} point In pixel coordinate system.
  6108. * @return {boolean}
  6109. */
  6110. var coordinateSystemCreators = {};
  6111. function CoordinateSystemManager() {
  6112. this._coordinateSystems = [];
  6113. }
  6114. CoordinateSystemManager.prototype = {
  6115. constructor: CoordinateSystemManager,
  6116. create: function (ecModel, api) {
  6117. var coordinateSystems = [];
  6118. zrUtil.each(coordinateSystemCreators, function (creater, type) {
  6119. var list = creater.create(ecModel, api);
  6120. coordinateSystems = coordinateSystems.concat(list || []);
  6121. });
  6122. this._coordinateSystems = coordinateSystems;
  6123. },
  6124. update: function (ecModel, api) {
  6125. zrUtil.each(this._coordinateSystems, function (coordSys) {
  6126. // FIXME MUST have
  6127. coordSys.update && coordSys.update(ecModel, api);
  6128. });
  6129. },
  6130. getCoordinateSystems: function () {
  6131. return this._coordinateSystems.slice();
  6132. }
  6133. };
  6134. CoordinateSystemManager.register = function (type, coordinateSystemCreator) {
  6135. coordinateSystemCreators[type] = coordinateSystemCreator;
  6136. };
  6137. CoordinateSystemManager.get = function (type) {
  6138. return coordinateSystemCreators[type];
  6139. };
  6140. module.exports = CoordinateSystemManager;
  6141. /***/ },
  6142. /* 27 */
  6143. /***/ function(module, exports, __webpack_require__) {
  6144. /**
  6145. * ECharts option manager
  6146. *
  6147. * @module {echarts/model/OptionManager}
  6148. */
  6149. var zrUtil = __webpack_require__(4);
  6150. var modelUtil = __webpack_require__(5);
  6151. var ComponentModel = __webpack_require__(19);
  6152. var each = zrUtil.each;
  6153. var clone = zrUtil.clone;
  6154. var map = zrUtil.map;
  6155. var merge = zrUtil.merge;
  6156. var QUERY_REG = /^(min|max)?(.+)$/;
  6157. /**
  6158. * TERM EXPLANATIONS:
  6159. *
  6160. * [option]:
  6161. *
  6162. * An object that contains definitions of components. For example:
  6163. * var option = {
  6164. * title: {...},
  6165. * legend: {...},
  6166. * visualMap: {...},
  6167. * series: [
  6168. * {data: [...]},
  6169. * {data: [...]},
  6170. * ...
  6171. * ]
  6172. * };
  6173. *
  6174. * [rawOption]:
  6175. *
  6176. * An object input to echarts.setOption. 'rawOption' may be an
  6177. * 'option', or may be an object contains multi-options. For example:
  6178. * var option = {
  6179. * baseOption: {
  6180. * title: {...},
  6181. * legend: {...},
  6182. * series: [
  6183. * {data: [...]},
  6184. * {data: [...]},
  6185. * ...
  6186. * ]
  6187. * },
  6188. * timeline: {...},
  6189. * options: [
  6190. * {title: {...}, series: {data: [...]}},
  6191. * {title: {...}, series: {data: [...]}},
  6192. * ...
  6193. * ],
  6194. * media: [
  6195. * {
  6196. * query: {maxWidth: 320},
  6197. * option: {series: {x: 20}, visualMap: {show: false}}
  6198. * },
  6199. * {
  6200. * query: {minWidth: 320, maxWidth: 720},
  6201. * option: {series: {x: 500}, visualMap: {show: true}}
  6202. * },
  6203. * {
  6204. * option: {series: {x: 1200}, visualMap: {show: true}}
  6205. * }
  6206. * ]
  6207. * };
  6208. *
  6209. * @alias module:echarts/model/OptionManager
  6210. * @param {module:echarts/ExtensionAPI} api
  6211. */
  6212. function OptionManager(api) {
  6213. /**
  6214. * @private
  6215. * @type {module:echarts/ExtensionAPI}
  6216. */
  6217. this._api = api;
  6218. /**
  6219. * @private
  6220. * @type {Array.<number>}
  6221. */
  6222. this._timelineOptions = [];
  6223. /**
  6224. * @private
  6225. * @type {Array.<Object>}
  6226. */
  6227. this._mediaList = [];
  6228. /**
  6229. * @private
  6230. * @type {Object}
  6231. */
  6232. this._mediaDefault;
  6233. /**
  6234. * -1, means default.
  6235. * empty means no media.
  6236. * @private
  6237. * @type {Array.<number>}
  6238. */
  6239. this._currentMediaIndices = [];
  6240. /**
  6241. * @private
  6242. * @type {Object}
  6243. */
  6244. this._optionBackup;
  6245. /**
  6246. * @private
  6247. * @type {Object}
  6248. */
  6249. this._newBaseOption;
  6250. }
  6251. // timeline.notMerge is not supported in ec3. Firstly there is rearly
  6252. // case that notMerge is needed. Secondly supporting 'notMerge' requires
  6253. // rawOption cloned and backuped when timeline changed, which does no
  6254. // good to performance. What's more, that both timeline and setOption
  6255. // method supply 'notMerge' brings complex and some problems.
  6256. // Consider this case:
  6257. // (step1) chart.setOption({timeline: {notMerge: false}, ...}, false);
  6258. // (step2) chart.setOption({timeline: {notMerge: true}, ...}, false);
  6259. OptionManager.prototype = {
  6260. constructor: OptionManager,
  6261. /**
  6262. * @public
  6263. * @param {Object} rawOption Raw option.
  6264. * @param {module:echarts/model/Global} ecModel
  6265. * @param {Array.<Function>} optionPreprocessorFuncs
  6266. * @return {Object} Init option
  6267. */
  6268. setOption: function (rawOption, optionPreprocessorFuncs) {
  6269. rawOption = clone(rawOption, true);
  6270. // FIXME
  6271. // 如果 timeline options 或者 media 中设置了某个属性,而baseOption中没有设置,则进行警告。
  6272. var oldOptionBackup = this._optionBackup;
  6273. var newParsedOption = parseRawOption.call(
  6274. this, rawOption, optionPreprocessorFuncs, !oldOptionBackup
  6275. );
  6276. this._newBaseOption = newParsedOption.baseOption;
  6277. // For setOption at second time (using merge mode);
  6278. if (oldOptionBackup) {
  6279. // Only baseOption can be merged.
  6280. mergeOption(oldOptionBackup.baseOption, newParsedOption.baseOption);
  6281. // For simplicity, timeline options and media options do not support merge,
  6282. // that is, if you `setOption` twice and both has timeline options, the latter
  6283. // timeline opitons will not be merged to the formers, but just substitude them.
  6284. if (newParsedOption.timelineOptions.length) {
  6285. oldOptionBackup.timelineOptions = newParsedOption.timelineOptions;
  6286. }
  6287. if (newParsedOption.mediaList.length) {
  6288. oldOptionBackup.mediaList = newParsedOption.mediaList;
  6289. }
  6290. if (newParsedOption.mediaDefault) {
  6291. oldOptionBackup.mediaDefault = newParsedOption.mediaDefault;
  6292. }
  6293. }
  6294. else {
  6295. this._optionBackup = newParsedOption;
  6296. }
  6297. },
  6298. /**
  6299. * @param {boolean} isRecreate
  6300. * @return {Object}
  6301. */
  6302. mountOption: function (isRecreate) {
  6303. var optionBackup = this._optionBackup;
  6304. // TODO
  6305. // 如果没有reset功能则不clone。
  6306. this._timelineOptions = map(optionBackup.timelineOptions, clone);
  6307. this._mediaList = map(optionBackup.mediaList, clone);
  6308. this._mediaDefault = clone(optionBackup.mediaDefault);
  6309. this._currentMediaIndices = [];
  6310. return clone(isRecreate
  6311. // this._optionBackup.baseOption, which is created at the first `setOption`
  6312. // called, and is merged into every new option by inner method `mergeOption`
  6313. // each time `setOption` called, can be only used in `isRecreate`, because
  6314. // its reliability is under suspicion. In other cases option merge is
  6315. // performed by `model.mergeOption`.
  6316. ? optionBackup.baseOption : this._newBaseOption
  6317. );
  6318. },
  6319. /**
  6320. * @param {module:echarts/model/Global} ecModel
  6321. * @return {Object}
  6322. */
  6323. getTimelineOption: function (ecModel) {
  6324. var option;
  6325. var timelineOptions = this._timelineOptions;
  6326. if (timelineOptions.length) {
  6327. // getTimelineOption can only be called after ecModel inited,
  6328. // so we can get currentIndex from timelineModel.
  6329. var timelineModel = ecModel.getComponent('timeline');
  6330. if (timelineModel) {
  6331. option = clone(
  6332. timelineOptions[timelineModel.getCurrentIndex()],
  6333. true
  6334. );
  6335. }
  6336. }
  6337. return option;
  6338. },
  6339. /**
  6340. * @param {module:echarts/model/Global} ecModel
  6341. * @return {Array.<Object>}
  6342. */
  6343. getMediaOption: function (ecModel) {
  6344. var ecWidth = this._api.getWidth();
  6345. var ecHeight = this._api.getHeight();
  6346. var mediaList = this._mediaList;
  6347. var mediaDefault = this._mediaDefault;
  6348. var indices = [];
  6349. var result = [];
  6350. // No media defined.
  6351. if (!mediaList.length && !mediaDefault) {
  6352. return result;
  6353. }
  6354. // Multi media may be applied, the latter defined media has higher priority.
  6355. for (var i = 0, len = mediaList.length; i < len; i++) {
  6356. if (applyMediaQuery(mediaList[i].query, ecWidth, ecHeight)) {
  6357. indices.push(i);
  6358. }
  6359. }
  6360. // FIXME
  6361. // 是否mediaDefault应该强制用户设置,否则可能修改不能回归。
  6362. if (!indices.length && mediaDefault) {
  6363. indices = [-1];
  6364. }
  6365. if (indices.length && !indicesEquals(indices, this._currentMediaIndices)) {
  6366. result = map(indices, function (index) {
  6367. return clone(
  6368. index === -1 ? mediaDefault.option : mediaList[index].option
  6369. );
  6370. });
  6371. }
  6372. // Otherwise return nothing.
  6373. this._currentMediaIndices = indices;
  6374. return result;
  6375. }
  6376. };
  6377. function parseRawOption(rawOption, optionPreprocessorFuncs, isNew) {
  6378. var timelineOptions = [];
  6379. var mediaList = [];
  6380. var mediaDefault;
  6381. var baseOption;
  6382. // Compatible with ec2.
  6383. var timelineOpt = rawOption.timeline;
  6384. if (rawOption.baseOption) {
  6385. baseOption = rawOption.baseOption;
  6386. }
  6387. // For timeline
  6388. if (timelineOpt || rawOption.options) {
  6389. baseOption = baseOption || {};
  6390. timelineOptions = (rawOption.options || []).slice();
  6391. }
  6392. // For media query
  6393. if (rawOption.media) {
  6394. baseOption = baseOption || {};
  6395. var media = rawOption.media;
  6396. each(media, function (singleMedia) {
  6397. if (singleMedia && singleMedia.option) {
  6398. if (singleMedia.query) {
  6399. mediaList.push(singleMedia);
  6400. }
  6401. else if (!mediaDefault) {
  6402. // Use the first media default.
  6403. mediaDefault = singleMedia;
  6404. }
  6405. }
  6406. });
  6407. }
  6408. // For normal option
  6409. if (!baseOption) {
  6410. baseOption = rawOption;
  6411. }
  6412. // Set timelineOpt to baseOption in ec3,
  6413. // which is convenient for merge option.
  6414. if (!baseOption.timeline) {
  6415. baseOption.timeline = timelineOpt;
  6416. }
  6417. // Preprocess.
  6418. each([baseOption].concat(timelineOptions)
  6419. .concat(zrUtil.map(mediaList, function (media) {
  6420. return media.option;
  6421. })),
  6422. function (option) {
  6423. each(optionPreprocessorFuncs, function (preProcess) {
  6424. preProcess(option, isNew);
  6425. });
  6426. }
  6427. );
  6428. return {
  6429. baseOption: baseOption,
  6430. timelineOptions: timelineOptions,
  6431. mediaDefault: mediaDefault,
  6432. mediaList: mediaList
  6433. };
  6434. }
  6435. /**
  6436. * @see <http://www.w3.org/TR/css3-mediaqueries/#media1>
  6437. * Support: width, height, aspectRatio
  6438. * Can use max or min as prefix.
  6439. */
  6440. function applyMediaQuery(query, ecWidth, ecHeight) {
  6441. var realMap = {
  6442. width: ecWidth,
  6443. height: ecHeight,
  6444. aspectratio: ecWidth / ecHeight // lowser case for convenientce.
  6445. };
  6446. var applicatable = true;
  6447. zrUtil.each(query, function (value, attr) {
  6448. var matched = attr.match(QUERY_REG);
  6449. if (!matched || !matched[1] || !matched[2]) {
  6450. return;
  6451. }
  6452. var operator = matched[1];
  6453. var realAttr = matched[2].toLowerCase();
  6454. if (!compare(realMap[realAttr], value, operator)) {
  6455. applicatable = false;
  6456. }
  6457. });
  6458. return applicatable;
  6459. }
  6460. function compare(real, expect, operator) {
  6461. if (operator === 'min') {
  6462. return real >= expect;
  6463. }
  6464. else if (operator === 'max') {
  6465. return real <= expect;
  6466. }
  6467. else { // Equals
  6468. return real === expect;
  6469. }
  6470. }
  6471. function indicesEquals(indices1, indices2) {
  6472. // indices is always order by asc and has only finite number.
  6473. return indices1.join(',') === indices2.join(',');
  6474. }
  6475. /**
  6476. * Consider case:
  6477. * `chart.setOption(opt1);`
  6478. * Then user do some interaction like dataZoom, dataView changing.
  6479. * `chart.setOption(opt2);`
  6480. * Then user press 'reset button' in toolbox.
  6481. *
  6482. * After doing that all of the interaction effects should be reset, the
  6483. * chart should be the same as the result of invoke
  6484. * `chart.setOption(opt1); chart.setOption(opt2);`.
  6485. *
  6486. * Although it is not able ensure that
  6487. * `chart.setOption(opt1); chart.setOption(opt2);` is equivalents to
  6488. * `chart.setOption(merge(opt1, opt2));` exactly,
  6489. * this might be the only simple way to implement that feature.
  6490. *
  6491. * MEMO: We've considered some other approaches:
  6492. * 1. Each model handle its self restoration but not uniform treatment.
  6493. * (Too complex in logic and error-prone)
  6494. * 2. Use a shadow ecModel. (Performace expensive)
  6495. */
  6496. function mergeOption(oldOption, newOption) {
  6497. newOption = newOption || {};
  6498. each(newOption, function (newCptOpt, mainType) {
  6499. if (newCptOpt == null) {
  6500. return;
  6501. }
  6502. var oldCptOpt = oldOption[mainType];
  6503. if (!ComponentModel.hasClass(mainType)) {
  6504. oldOption[mainType] = merge(oldCptOpt, newCptOpt, true);
  6505. }
  6506. else {
  6507. newCptOpt = modelUtil.normalizeToArray(newCptOpt);
  6508. oldCptOpt = modelUtil.normalizeToArray(oldCptOpt);
  6509. var mapResult = modelUtil.mappingToExists(oldCptOpt, newCptOpt);
  6510. oldOption[mainType] = map(mapResult, function (item) {
  6511. return (item.option && item.exist)
  6512. ? merge(item.exist, item.option, true)
  6513. : (item.exist || item.option);
  6514. });
  6515. }
  6516. });
  6517. }
  6518. module.exports = OptionManager;
  6519. /***/ },
  6520. /* 28 */
  6521. /***/ function(module, exports, __webpack_require__) {
  6522. 'use strict';
  6523. var zrUtil = __webpack_require__(4);
  6524. var formatUtil = __webpack_require__(6);
  6525. var classUtil = __webpack_require__(13);
  6526. var modelUtil = __webpack_require__(5);
  6527. var ComponentModel = __webpack_require__(19);
  6528. var colorPaletteMixin = __webpack_require__(24);
  6529. var env = __webpack_require__(2);
  6530. var layout = __webpack_require__(21);
  6531. var set = classUtil.set;
  6532. var get = classUtil.get;
  6533. var encodeHTML = formatUtil.encodeHTML;
  6534. var addCommas = formatUtil.addCommas;
  6535. var SeriesModel = ComponentModel.extend({
  6536. type: 'series.__base__',
  6537. /**
  6538. * @readOnly
  6539. */
  6540. seriesIndex: 0,
  6541. // coodinateSystem will be injected in the echarts/CoordinateSystem
  6542. coordinateSystem: null,
  6543. /**
  6544. * @type {Object}
  6545. * @protected
  6546. */
  6547. defaultOption: null,
  6548. /**
  6549. * Data provided for legend
  6550. * @type {Function}
  6551. */
  6552. // PENDING
  6553. legendDataProvider: null,
  6554. /**
  6555. * Access path of color for visual
  6556. */
  6557. visualColorAccessPath: 'itemStyle.normal.color',
  6558. /**
  6559. * Support merge layout params.
  6560. * Only support 'box' now (left/right/top/bottom/width/height).
  6561. * @type {string|Object} Object can be {ignoreSize: true}
  6562. * @readOnly
  6563. */
  6564. layoutMode: null,
  6565. init: function (option, parentModel, ecModel, extraOpt) {
  6566. /**
  6567. * @type {number}
  6568. * @readOnly
  6569. */
  6570. this.seriesIndex = this.componentIndex;
  6571. this.mergeDefaultAndTheme(option, ecModel);
  6572. /**
  6573. * @type {module:echarts/data/List|module:echarts/data/Tree|module:echarts/data/Graph}
  6574. * @private
  6575. */
  6576. set(this, 'dataBeforeProcessed', this.getInitialData(option, ecModel));
  6577. // If we reverse the order (make data firstly, and then make
  6578. // dataBeforeProcessed by cloneShallow), cloneShallow will
  6579. // cause data.graph.data !== data when using
  6580. // module:echarts/data/Graph or module:echarts/data/Tree.
  6581. // See module:echarts/data/helper/linkList
  6582. this.restoreData();
  6583. },
  6584. /**
  6585. * Util for merge default and theme to option
  6586. * @param {Object} option
  6587. * @param {module:echarts/model/Global} ecModel
  6588. */
  6589. mergeDefaultAndTheme: function (option, ecModel) {
  6590. var layoutMode = this.layoutMode;
  6591. var inputPositionParams = layoutMode
  6592. ? layout.getLayoutParams(option) : {};
  6593. zrUtil.merge(
  6594. option,
  6595. ecModel.getTheme().get(this.subType)
  6596. );
  6597. zrUtil.merge(option, this.getDefaultOption());
  6598. // Default label emphasis `position` and `show`
  6599. // FIXME Set label in mergeOption
  6600. modelUtil.defaultEmphasis(option.label, modelUtil.LABEL_OPTIONS);
  6601. this.fillDataTextStyle(option.data);
  6602. if (layoutMode) {
  6603. layout.mergeLayoutParam(option, inputPositionParams, layoutMode);
  6604. }
  6605. },
  6606. mergeOption: function (newSeriesOption, ecModel) {
  6607. newSeriesOption = zrUtil.merge(this.option, newSeriesOption, true);
  6608. this.fillDataTextStyle(newSeriesOption.data);
  6609. var layoutMode = this.layoutMode;
  6610. if (layoutMode) {
  6611. layout.mergeLayoutParam(this.option, newSeriesOption, layoutMode);
  6612. }
  6613. var data = this.getInitialData(newSeriesOption, ecModel);
  6614. // TODO Merge data?
  6615. if (data) {
  6616. set(this, 'data', data);
  6617. set(this, 'dataBeforeProcessed', data.cloneShallow());
  6618. }
  6619. },
  6620. fillDataTextStyle: function (data) {
  6621. // Default data label emphasis `position` and `show`
  6622. // FIXME Tree structure data ?
  6623. // FIXME Performance ?
  6624. if (data) {
  6625. for (var i = 0; i < data.length; i++) {
  6626. if (data[i] && data[i].label) {
  6627. modelUtil.defaultEmphasis(data[i].label, modelUtil.LABEL_OPTIONS);
  6628. }
  6629. }
  6630. }
  6631. },
  6632. /**
  6633. * Init a data structure from data related option in series
  6634. * Must be overwritten
  6635. */
  6636. getInitialData: function () {},
  6637. /**
  6638. * @param {string} [dataType]
  6639. * @return {module:echarts/data/List}
  6640. */
  6641. getData: function (dataType) {
  6642. var data = get(this, 'data');
  6643. return dataType == null ? data : data.getLinkedData(dataType);
  6644. },
  6645. /**
  6646. * @param {module:echarts/data/List} data
  6647. */
  6648. setData: function (data) {
  6649. set(this, 'data', data);
  6650. },
  6651. /**
  6652. * Get data before processed
  6653. * @return {module:echarts/data/List}
  6654. */
  6655. getRawData: function () {
  6656. return get(this, 'dataBeforeProcessed');
  6657. },
  6658. /**
  6659. * Coord dimension to data dimension.
  6660. *
  6661. * By default the result is the same as dimensions of series data.
  6662. * But in some series data dimensions are different from coord dimensions (i.e.
  6663. * candlestick and boxplot). Override this method to handle those cases.
  6664. *
  6665. * Coord dimension to data dimension can be one-to-many
  6666. *
  6667. * @param {string} coordDim
  6668. * @return {Array.<string>} dimensions on the axis.
  6669. */
  6670. coordDimToDataDim: function (coordDim) {
  6671. return [coordDim];
  6672. },
  6673. /**
  6674. * Convert data dimension to coord dimension.
  6675. *
  6676. * @param {string|number} dataDim
  6677. * @return {string}
  6678. */
  6679. dataDimToCoordDim: function (dataDim) {
  6680. return dataDim;
  6681. },
  6682. /**
  6683. * Get base axis if has coordinate system and has axis.
  6684. * By default use coordSys.getBaseAxis();
  6685. * Can be overrided for some chart.
  6686. * @return {type} description
  6687. */
  6688. getBaseAxis: function () {
  6689. var coordSys = this.coordinateSystem;
  6690. return coordSys && coordSys.getBaseAxis && coordSys.getBaseAxis();
  6691. },
  6692. // FIXME
  6693. /**
  6694. * Default tooltip formatter
  6695. *
  6696. * @param {number} dataIndex
  6697. * @param {boolean} [multipleSeries=false]
  6698. * @param {number} [dataType]
  6699. */
  6700. formatTooltip: function (dataIndex, multipleSeries, dataType) {
  6701. function formatArrayValue(value) {
  6702. var result = [];
  6703. zrUtil.each(value, function (val, idx) {
  6704. var dimInfo = data.getDimensionInfo(idx);
  6705. var dimType = dimInfo && dimInfo.type;
  6706. var valStr;
  6707. if (dimType === 'ordinal') {
  6708. valStr = val + '';
  6709. }
  6710. else if (dimType === 'time') {
  6711. valStr = multipleSeries ? '' : formatUtil.formatTime('yyyy/MM/dd hh:mm:ss', val);
  6712. }
  6713. else {
  6714. valStr = addCommas(val);
  6715. }
  6716. valStr && result.push(valStr);
  6717. });
  6718. return result.join(', ');
  6719. }
  6720. var data = get(this, 'data');
  6721. var value = this.getRawValue(dataIndex);
  6722. var formattedValue = encodeHTML(
  6723. zrUtil.isArray(value) ? formatArrayValue(value) : addCommas(value)
  6724. );
  6725. var name = data.getName(dataIndex);
  6726. var color = data.getItemVisual(dataIndex, 'color');
  6727. if (zrUtil.isObject(color) && color.colorStops) {
  6728. color = (color.colorStops[0] || {}).color;
  6729. }
  6730. color = color || 'transparent';
  6731. var colorEl = '<span style="display:inline-block;margin-right:5px;'
  6732. + 'border-radius:10px;width:9px;height:9px;background-color:' + encodeHTML(color) + '"></span>';
  6733. var seriesName = this.name;
  6734. // FIXME
  6735. if (seriesName === '\0-') {
  6736. // Not show '-'
  6737. seriesName = '';
  6738. }
  6739. return !multipleSeries
  6740. ? ((seriesName && encodeHTML(seriesName) + '<br />') + colorEl
  6741. + (name
  6742. ? encodeHTML(name) + ' : ' + formattedValue
  6743. : formattedValue
  6744. )
  6745. )
  6746. : (colorEl + encodeHTML(this.name) + ' : ' + formattedValue);
  6747. },
  6748. /**
  6749. * @return {boolean}
  6750. */
  6751. isAnimationEnabled: function () {
  6752. if (env.node) {
  6753. return false;
  6754. }
  6755. var animationEnabled = this.getShallow('animation');
  6756. if (animationEnabled) {
  6757. if (this.getData().count() > this.getShallow('animationThreshold')) {
  6758. animationEnabled = false;
  6759. }
  6760. }
  6761. return animationEnabled;
  6762. },
  6763. restoreData: function () {
  6764. set(this, 'data', get(this, 'dataBeforeProcessed').cloneShallow());
  6765. },
  6766. getColorFromPalette: function (name, scope) {
  6767. var ecModel = this.ecModel;
  6768. // PENDING
  6769. var color = colorPaletteMixin.getColorFromPalette.call(this, name, scope);
  6770. if (!color) {
  6771. color = ecModel.getColorFromPalette(name, scope);
  6772. }
  6773. return color;
  6774. },
  6775. /**
  6776. * Get data indices for show tooltip content. See tooltip.
  6777. * @abstract
  6778. * @param {Array.<string>|string} dim
  6779. * @param {Array.<number>} value
  6780. * @param {module:echarts/coord/single/SingleAxis} baseAxis
  6781. * @return {Array.<number>} data indices.
  6782. */
  6783. getAxisTooltipDataIndex: null,
  6784. /**
  6785. * See tooltip.
  6786. * @abstract
  6787. * @param {number} dataIndex
  6788. * @return {Array.<number>} Point of tooltip. null/undefined can be returned.
  6789. */
  6790. getTooltipPosition: null
  6791. });
  6792. zrUtil.mixin(SeriesModel, modelUtil.dataFormatMixin);
  6793. zrUtil.mixin(SeriesModel, colorPaletteMixin);
  6794. module.exports = SeriesModel;
  6795. /***/ },
  6796. /* 29 */
  6797. /***/ function(module, exports, __webpack_require__) {
  6798. var Group = __webpack_require__(30);
  6799. var componentUtil = __webpack_require__(20);
  6800. var clazzUtil = __webpack_require__(13);
  6801. var Component = function () {
  6802. /**
  6803. * @type {module:zrender/container/Group}
  6804. * @readOnly
  6805. */
  6806. this.group = new Group();
  6807. /**
  6808. * @type {string}
  6809. * @readOnly
  6810. */
  6811. this.uid = componentUtil.getUID('viewComponent');
  6812. };
  6813. Component.prototype = {
  6814. constructor: Component,
  6815. init: function (ecModel, api) {},
  6816. render: function (componentModel, ecModel, api, payload) {},
  6817. dispose: function () {}
  6818. };
  6819. var componentProto = Component.prototype;
  6820. componentProto.updateView
  6821. = componentProto.updateLayout
  6822. = componentProto.updateVisual
  6823. = function (seriesModel, ecModel, api, payload) {
  6824. // Do nothing;
  6825. };
  6826. // Enable Component.extend.
  6827. clazzUtil.enableClassExtend(Component);
  6828. // Enable capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  6829. clazzUtil.enableClassManagement(Component, {registerWhenExtend: true});
  6830. module.exports = Component;
  6831. /***/ },
  6832. /* 30 */
  6833. /***/ function(module, exports, __webpack_require__) {
  6834. /**
  6835. * Group是一个容器,可以插入子节点,Group的变换也会被应用到子节点上
  6836. * @module zrender/graphic/Group
  6837. * @example
  6838. * var Group = require('zrender/lib/container/Group');
  6839. * var Circle = require('zrender/lib/graphic/shape/Circle');
  6840. * var g = new Group();
  6841. * g.position[0] = 100;
  6842. * g.position[1] = 100;
  6843. * g.add(new Circle({
  6844. * style: {
  6845. * x: 100,
  6846. * y: 100,
  6847. * r: 20,
  6848. * }
  6849. * }));
  6850. * zr.add(g);
  6851. */
  6852. var zrUtil = __webpack_require__(4);
  6853. var Element = __webpack_require__(31);
  6854. var BoundingRect = __webpack_require__(9);
  6855. /**
  6856. * @alias module:zrender/graphic/Group
  6857. * @constructor
  6858. * @extends module:zrender/mixin/Transformable
  6859. * @extends module:zrender/mixin/Eventful
  6860. */
  6861. var Group = function (opts) {
  6862. opts = opts || {};
  6863. Element.call(this, opts);
  6864. for (var key in opts) {
  6865. if (opts.hasOwnProperty(key)) {
  6866. this[key] = opts[key];
  6867. }
  6868. }
  6869. this._children = [];
  6870. this.__storage = null;
  6871. this.__dirty = true;
  6872. };
  6873. Group.prototype = {
  6874. constructor: Group,
  6875. isGroup: true,
  6876. /**
  6877. * @type {string}
  6878. */
  6879. type: 'group',
  6880. /**
  6881. * 所有子孙元素是否响应鼠标事件
  6882. * @name module:/zrender/container/Group#silent
  6883. * @type {boolean}
  6884. * @default false
  6885. */
  6886. silent: false,
  6887. /**
  6888. * @return {Array.<module:zrender/Element>}
  6889. */
  6890. children: function () {
  6891. return this._children.slice();
  6892. },
  6893. /**
  6894. * 获取指定 index 的儿子节点
  6895. * @param {number} idx
  6896. * @return {module:zrender/Element}
  6897. */
  6898. childAt: function (idx) {
  6899. return this._children[idx];
  6900. },
  6901. /**
  6902. * 获取指定名字的儿子节点
  6903. * @param {string} name
  6904. * @return {module:zrender/Element}
  6905. */
  6906. childOfName: function (name) {
  6907. var children = this._children;
  6908. for (var i = 0; i < children.length; i++) {
  6909. if (children[i].name === name) {
  6910. return children[i];
  6911. }
  6912. }
  6913. },
  6914. /**
  6915. * @return {number}
  6916. */
  6917. childCount: function () {
  6918. return this._children.length;
  6919. },
  6920. /**
  6921. * 添加子节点到最后
  6922. * @param {module:zrender/Element} child
  6923. */
  6924. add: function (child) {
  6925. if (child && child !== this && child.parent !== this) {
  6926. this._children.push(child);
  6927. this._doAdd(child);
  6928. }
  6929. return this;
  6930. },
  6931. /**
  6932. * 添加子节点在 nextSibling 之前
  6933. * @param {module:zrender/Element} child
  6934. * @param {module:zrender/Element} nextSibling
  6935. */
  6936. addBefore: function (child, nextSibling) {
  6937. if (child && child !== this && child.parent !== this
  6938. && nextSibling && nextSibling.parent === this) {
  6939. var children = this._children;
  6940. var idx = children.indexOf(nextSibling);
  6941. if (idx >= 0) {
  6942. children.splice(idx, 0, child);
  6943. this._doAdd(child);
  6944. }
  6945. }
  6946. return this;
  6947. },
  6948. _doAdd: function (child) {
  6949. if (child.parent) {
  6950. child.parent.remove(child);
  6951. }
  6952. child.parent = this;
  6953. var storage = this.__storage;
  6954. var zr = this.__zr;
  6955. if (storage && storage !== child.__storage) {
  6956. storage.addToMap(child);
  6957. if (child instanceof Group) {
  6958. child.addChildrenToStorage(storage);
  6959. }
  6960. }
  6961. zr && zr.refresh();
  6962. },
  6963. /**
  6964. * 移除子节点
  6965. * @param {module:zrender/Element} child
  6966. */
  6967. remove: function (child) {
  6968. var zr = this.__zr;
  6969. var storage = this.__storage;
  6970. var children = this._children;
  6971. var idx = zrUtil.indexOf(children, child);
  6972. if (idx < 0) {
  6973. return this;
  6974. }
  6975. children.splice(idx, 1);
  6976. child.parent = null;
  6977. if (storage) {
  6978. storage.delFromMap(child.id);
  6979. if (child instanceof Group) {
  6980. child.delChildrenFromStorage(storage);
  6981. }
  6982. }
  6983. zr && zr.refresh();
  6984. return this;
  6985. },
  6986. /**
  6987. * 移除所有子节点
  6988. */
  6989. removeAll: function () {
  6990. var children = this._children;
  6991. var storage = this.__storage;
  6992. var child;
  6993. var i;
  6994. for (i = 0; i < children.length; i++) {
  6995. child = children[i];
  6996. if (storage) {
  6997. storage.delFromMap(child.id);
  6998. if (child instanceof Group) {
  6999. child.delChildrenFromStorage(storage);
  7000. }
  7001. }
  7002. child.parent = null;
  7003. }
  7004. children.length = 0;
  7005. return this;
  7006. },
  7007. /**
  7008. * 遍历所有子节点
  7009. * @param {Function} cb
  7010. * @param {} context
  7011. */
  7012. eachChild: function (cb, context) {
  7013. var children = this._children;
  7014. for (var i = 0; i < children.length; i++) {
  7015. var child = children[i];
  7016. cb.call(context, child, i);
  7017. }
  7018. return this;
  7019. },
  7020. /**
  7021. * 深度优先遍历所有子孙节点
  7022. * @param {Function} cb
  7023. * @param {} context
  7024. */
  7025. traverse: function (cb, context) {
  7026. for (var i = 0; i < this._children.length; i++) {
  7027. var child = this._children[i];
  7028. cb.call(context, child);
  7029. if (child.type === 'group') {
  7030. child.traverse(cb, context);
  7031. }
  7032. }
  7033. return this;
  7034. },
  7035. addChildrenToStorage: function (storage) {
  7036. for (var i = 0; i < this._children.length; i++) {
  7037. var child = this._children[i];
  7038. storage.addToMap(child);
  7039. if (child instanceof Group) {
  7040. child.addChildrenToStorage(storage);
  7041. }
  7042. }
  7043. },
  7044. delChildrenFromStorage: function (storage) {
  7045. for (var i = 0; i < this._children.length; i++) {
  7046. var child = this._children[i];
  7047. storage.delFromMap(child.id);
  7048. if (child instanceof Group) {
  7049. child.delChildrenFromStorage(storage);
  7050. }
  7051. }
  7052. },
  7053. dirty: function () {
  7054. this.__dirty = true;
  7055. this.__zr && this.__zr.refresh();
  7056. return this;
  7057. },
  7058. /**
  7059. * @return {module:zrender/core/BoundingRect}
  7060. */
  7061. getBoundingRect: function (includeChildren) {
  7062. // TODO Caching
  7063. var rect = null;
  7064. var tmpRect = new BoundingRect(0, 0, 0, 0);
  7065. var children = includeChildren || this._children;
  7066. var tmpMat = [];
  7067. for (var i = 0; i < children.length; i++) {
  7068. var child = children[i];
  7069. if (child.ignore || child.invisible) {
  7070. continue;
  7071. }
  7072. var childRect = child.getBoundingRect();
  7073. var transform = child.getLocalTransform(tmpMat);
  7074. // TODO
  7075. // The boundingRect cacluated by transforming original
  7076. // rect may be bigger than the actual bundingRect when rotation
  7077. // is used. (Consider a circle rotated aginst its center, where
  7078. // the actual boundingRect should be the same as that not be
  7079. // rotated.) But we can not find better approach to calculate
  7080. // actual boundingRect yet, considering performance.
  7081. if (transform) {
  7082. tmpRect.copy(childRect);
  7083. tmpRect.applyTransform(transform);
  7084. rect = rect || tmpRect.clone();
  7085. rect.union(tmpRect);
  7086. }
  7087. else {
  7088. rect = rect || childRect.clone();
  7089. rect.union(childRect);
  7090. }
  7091. }
  7092. return rect || tmpRect;
  7093. }
  7094. };
  7095. zrUtil.inherits(Group, Element);
  7096. module.exports = Group;
  7097. /***/ },
  7098. /* 31 */
  7099. /***/ function(module, exports, __webpack_require__) {
  7100. 'use strict';
  7101. /**
  7102. * @module zrender/Element
  7103. */
  7104. var guid = __webpack_require__(32);
  7105. var Eventful = __webpack_require__(33);
  7106. var Transformable = __webpack_require__(34);
  7107. var Animatable = __webpack_require__(35);
  7108. var zrUtil = __webpack_require__(4);
  7109. /**
  7110. * @alias module:zrender/Element
  7111. * @constructor
  7112. * @extends {module:zrender/mixin/Animatable}
  7113. * @extends {module:zrender/mixin/Transformable}
  7114. * @extends {module:zrender/mixin/Eventful}
  7115. */
  7116. var Element = function (opts) {
  7117. Transformable.call(this, opts);
  7118. Eventful.call(this, opts);
  7119. Animatable.call(this, opts);
  7120. /**
  7121. * 画布元素ID
  7122. * @type {string}
  7123. */
  7124. this.id = opts.id || guid();
  7125. };
  7126. Element.prototype = {
  7127. /**
  7128. * 元素类型
  7129. * Element type
  7130. * @type {string}
  7131. */
  7132. type: 'element',
  7133. /**
  7134. * 元素名字
  7135. * Element name
  7136. * @type {string}
  7137. */
  7138. name: '',
  7139. /**
  7140. * ZRender 实例对象,会在 element 添加到 zrender 实例中后自动赋值
  7141. * ZRender instance will be assigned when element is associated with zrender
  7142. * @name module:/zrender/Element#__zr
  7143. * @type {module:zrender/ZRender}
  7144. */
  7145. __zr: null,
  7146. /**
  7147. * 图形是否忽略,为true时忽略图形的绘制以及事件触发
  7148. * If ignore drawing and events of the element object
  7149. * @name module:/zrender/Element#ignore
  7150. * @type {boolean}
  7151. * @default false
  7152. */
  7153. ignore: false,
  7154. /**
  7155. * 用于裁剪的路径(shape),所有 Group 内的路径在绘制时都会被这个路径裁剪
  7156. * 该路径会继承被裁减对象的变换
  7157. * @type {module:zrender/graphic/Path}
  7158. * @see http://www.w3.org/TR/2dcontext/#clipping-region
  7159. * @readOnly
  7160. */
  7161. clipPath: null,
  7162. /**
  7163. * Drift element
  7164. * @param {number} dx dx on the global space
  7165. * @param {number} dy dy on the global space
  7166. */
  7167. drift: function (dx, dy) {
  7168. switch (this.draggable) {
  7169. case 'horizontal':
  7170. dy = 0;
  7171. break;
  7172. case 'vertical':
  7173. dx = 0;
  7174. break;
  7175. }
  7176. var m = this.transform;
  7177. if (!m) {
  7178. m = this.transform = [1, 0, 0, 1, 0, 0];
  7179. }
  7180. m[4] += dx;
  7181. m[5] += dy;
  7182. this.decomposeTransform();
  7183. this.dirty(false);
  7184. },
  7185. /**
  7186. * Hook before update
  7187. */
  7188. beforeUpdate: function () {},
  7189. /**
  7190. * Hook after update
  7191. */
  7192. afterUpdate: function () {},
  7193. /**
  7194. * Update each frame
  7195. */
  7196. update: function () {
  7197. this.updateTransform();
  7198. },
  7199. /**
  7200. * @param {Function} cb
  7201. * @param {} context
  7202. */
  7203. traverse: function (cb, context) {},
  7204. /**
  7205. * @protected
  7206. */
  7207. attrKV: function (key, value) {
  7208. if (key === 'position' || key === 'scale' || key === 'origin') {
  7209. // Copy the array
  7210. if (value) {
  7211. var target = this[key];
  7212. if (!target) {
  7213. target = this[key] = [];
  7214. }
  7215. target[0] = value[0];
  7216. target[1] = value[1];
  7217. }
  7218. }
  7219. else {
  7220. this[key] = value;
  7221. }
  7222. },
  7223. /**
  7224. * Hide the element
  7225. */
  7226. hide: function () {
  7227. this.ignore = true;
  7228. this.__zr && this.__zr.refresh();
  7229. },
  7230. /**
  7231. * Show the element
  7232. */
  7233. show: function () {
  7234. this.ignore = false;
  7235. this.__zr && this.__zr.refresh();
  7236. },
  7237. /**
  7238. * @param {string|Object} key
  7239. * @param {*} value
  7240. */
  7241. attr: function (key, value) {
  7242. if (typeof key === 'string') {
  7243. this.attrKV(key, value);
  7244. }
  7245. else if (zrUtil.isObject(key)) {
  7246. for (var name in key) {
  7247. if (key.hasOwnProperty(name)) {
  7248. this.attrKV(name, key[name]);
  7249. }
  7250. }
  7251. }
  7252. this.dirty(false);
  7253. return this;
  7254. },
  7255. /**
  7256. * @param {module:zrender/graphic/Path} clipPath
  7257. */
  7258. setClipPath: function (clipPath) {
  7259. var zr = this.__zr;
  7260. if (zr) {
  7261. clipPath.addSelfToZr(zr);
  7262. }
  7263. // Remove previous clip path
  7264. if (this.clipPath && this.clipPath !== clipPath) {
  7265. this.removeClipPath();
  7266. }
  7267. this.clipPath = clipPath;
  7268. clipPath.__zr = zr;
  7269. clipPath.__clipTarget = this;
  7270. this.dirty(false);
  7271. },
  7272. /**
  7273. */
  7274. removeClipPath: function () {
  7275. var clipPath = this.clipPath;
  7276. if (clipPath) {
  7277. if (clipPath.__zr) {
  7278. clipPath.removeSelfFromZr(clipPath.__zr);
  7279. }
  7280. clipPath.__zr = null;
  7281. clipPath.__clipTarget = null;
  7282. this.clipPath = null;
  7283. this.dirty(false);
  7284. }
  7285. },
  7286. /**
  7287. * Add self from zrender instance.
  7288. * Not recursively because it will be invoked when element added to storage.
  7289. * @param {module:zrender/ZRender} zr
  7290. */
  7291. addSelfToZr: function (zr) {
  7292. this.__zr = zr;
  7293. // 添加动画
  7294. var animators = this.animators;
  7295. if (animators) {
  7296. for (var i = 0; i < animators.length; i++) {
  7297. zr.animation.addAnimator(animators[i]);
  7298. }
  7299. }
  7300. if (this.clipPath) {
  7301. this.clipPath.addSelfToZr(zr);
  7302. }
  7303. },
  7304. /**
  7305. * Remove self from zrender instance.
  7306. * Not recursively because it will be invoked when element added to storage.
  7307. * @param {module:zrender/ZRender} zr
  7308. */
  7309. removeSelfFromZr: function (zr) {
  7310. this.__zr = null;
  7311. // 移除动画
  7312. var animators = this.animators;
  7313. if (animators) {
  7314. for (var i = 0; i < animators.length; i++) {
  7315. zr.animation.removeAnimator(animators[i]);
  7316. }
  7317. }
  7318. if (this.clipPath) {
  7319. this.clipPath.removeSelfFromZr(zr);
  7320. }
  7321. }
  7322. };
  7323. zrUtil.mixin(Element, Animatable);
  7324. zrUtil.mixin(Element, Transformable);
  7325. zrUtil.mixin(Element, Eventful);
  7326. module.exports = Element;
  7327. /***/ },
  7328. /* 32 */
  7329. /***/ function(module, exports) {
  7330. /**
  7331. * zrender: 生成唯一id
  7332. *
  7333. * @author errorrik (errorrik@gmail.com)
  7334. */
  7335. var idStart = 0x0907;
  7336. module.exports = function () {
  7337. return idStart++;
  7338. };
  7339. /***/ },
  7340. /* 33 */
  7341. /***/ function(module, exports) {
  7342. /**
  7343. * 事件扩展
  7344. * @module zrender/mixin/Eventful
  7345. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  7346. * pissang (https://www.github.com/pissang)
  7347. */
  7348. var arrySlice = Array.prototype.slice;
  7349. /**
  7350. * 事件分发器
  7351. * @alias module:zrender/mixin/Eventful
  7352. * @constructor
  7353. */
  7354. var Eventful = function () {
  7355. this._$handlers = {};
  7356. };
  7357. Eventful.prototype = {
  7358. constructor: Eventful,
  7359. /**
  7360. * 单次触发绑定,trigger后销毁
  7361. *
  7362. * @param {string} event 事件名
  7363. * @param {Function} handler 响应函数
  7364. * @param {Object} context
  7365. */
  7366. one: function (event, handler, context) {
  7367. var _h = this._$handlers;
  7368. if (!handler || !event) {
  7369. return this;
  7370. }
  7371. if (!_h[event]) {
  7372. _h[event] = [];
  7373. }
  7374. for (var i = 0; i < _h[event].length; i++) {
  7375. if (_h[event][i].h === handler) {
  7376. return this;
  7377. }
  7378. }
  7379. _h[event].push({
  7380. h: handler,
  7381. one: true,
  7382. ctx: context || this
  7383. });
  7384. return this;
  7385. },
  7386. /**
  7387. * 绑定事件
  7388. * @param {string} event 事件名
  7389. * @param {Function} handler 事件处理函数
  7390. * @param {Object} [context]
  7391. */
  7392. on: function (event, handler, context) {
  7393. var _h = this._$handlers;
  7394. if (!handler || !event) {
  7395. return this;
  7396. }
  7397. if (!_h[event]) {
  7398. _h[event] = [];
  7399. }
  7400. for (var i = 0; i < _h[event].length; i++) {
  7401. if (_h[event][i].h === handler) {
  7402. return this;
  7403. }
  7404. }
  7405. _h[event].push({
  7406. h: handler,
  7407. one: false,
  7408. ctx: context || this
  7409. });
  7410. return this;
  7411. },
  7412. /**
  7413. * 是否绑定了事件
  7414. * @param {string} event
  7415. * @return {boolean}
  7416. */
  7417. isSilent: function (event) {
  7418. var _h = this._$handlers;
  7419. return _h[event] && _h[event].length;
  7420. },
  7421. /**
  7422. * 解绑事件
  7423. * @param {string} event 事件名
  7424. * @param {Function} [handler] 事件处理函数
  7425. */
  7426. off: function (event, handler) {
  7427. var _h = this._$handlers;
  7428. if (!event) {
  7429. this._$handlers = {};
  7430. return this;
  7431. }
  7432. if (handler) {
  7433. if (_h[event]) {
  7434. var newList = [];
  7435. for (var i = 0, l = _h[event].length; i < l; i++) {
  7436. if (_h[event][i]['h'] != handler) {
  7437. newList.push(_h[event][i]);
  7438. }
  7439. }
  7440. _h[event] = newList;
  7441. }
  7442. if (_h[event] && _h[event].length === 0) {
  7443. delete _h[event];
  7444. }
  7445. }
  7446. else {
  7447. delete _h[event];
  7448. }
  7449. return this;
  7450. },
  7451. /**
  7452. * 事件分发
  7453. *
  7454. * @param {string} type 事件类型
  7455. */
  7456. trigger: function (type) {
  7457. if (this._$handlers[type]) {
  7458. var args = arguments;
  7459. var argLen = args.length;
  7460. if (argLen > 3) {
  7461. args = arrySlice.call(args, 1);
  7462. }
  7463. var _h = this._$handlers[type];
  7464. var len = _h.length;
  7465. for (var i = 0; i < len;) {
  7466. // Optimize advise from backbone
  7467. switch (argLen) {
  7468. case 1:
  7469. _h[i]['h'].call(_h[i]['ctx']);
  7470. break;
  7471. case 2:
  7472. _h[i]['h'].call(_h[i]['ctx'], args[1]);
  7473. break;
  7474. case 3:
  7475. _h[i]['h'].call(_h[i]['ctx'], args[1], args[2]);
  7476. break;
  7477. default:
  7478. // have more than 2 given arguments
  7479. _h[i]['h'].apply(_h[i]['ctx'], args);
  7480. break;
  7481. }
  7482. if (_h[i]['one']) {
  7483. _h.splice(i, 1);
  7484. len--;
  7485. }
  7486. else {
  7487. i++;
  7488. }
  7489. }
  7490. }
  7491. return this;
  7492. },
  7493. /**
  7494. * 带有context的事件分发, 最后一个参数是事件回调的context
  7495. * @param {string} type 事件类型
  7496. */
  7497. triggerWithContext: function (type) {
  7498. if (this._$handlers[type]) {
  7499. var args = arguments;
  7500. var argLen = args.length;
  7501. if (argLen > 4) {
  7502. args = arrySlice.call(args, 1, args.length - 1);
  7503. }
  7504. var ctx = args[args.length - 1];
  7505. var _h = this._$handlers[type];
  7506. var len = _h.length;
  7507. for (var i = 0; i < len;) {
  7508. // Optimize advise from backbone
  7509. switch (argLen) {
  7510. case 1:
  7511. _h[i]['h'].call(ctx);
  7512. break;
  7513. case 2:
  7514. _h[i]['h'].call(ctx, args[1]);
  7515. break;
  7516. case 3:
  7517. _h[i]['h'].call(ctx, args[1], args[2]);
  7518. break;
  7519. default:
  7520. // have more than 2 given arguments
  7521. _h[i]['h'].apply(ctx, args);
  7522. break;
  7523. }
  7524. if (_h[i]['one']) {
  7525. _h.splice(i, 1);
  7526. len--;
  7527. }
  7528. else {
  7529. i++;
  7530. }
  7531. }
  7532. }
  7533. return this;
  7534. }
  7535. };
  7536. // 对象可以通过 onxxxx 绑定事件
  7537. /**
  7538. * @event module:zrender/mixin/Eventful#onclick
  7539. * @type {Function}
  7540. * @default null
  7541. */
  7542. /**
  7543. * @event module:zrender/mixin/Eventful#onmouseover
  7544. * @type {Function}
  7545. * @default null
  7546. */
  7547. /**
  7548. * @event module:zrender/mixin/Eventful#onmouseout
  7549. * @type {Function}
  7550. * @default null
  7551. */
  7552. /**
  7553. * @event module:zrender/mixin/Eventful#onmousemove
  7554. * @type {Function}
  7555. * @default null
  7556. */
  7557. /**
  7558. * @event module:zrender/mixin/Eventful#onmousewheel
  7559. * @type {Function}
  7560. * @default null
  7561. */
  7562. /**
  7563. * @event module:zrender/mixin/Eventful#onmousedown
  7564. * @type {Function}
  7565. * @default null
  7566. */
  7567. /**
  7568. * @event module:zrender/mixin/Eventful#onmouseup
  7569. * @type {Function}
  7570. * @default null
  7571. */
  7572. /**
  7573. * @event module:zrender/mixin/Eventful#ondrag
  7574. * @type {Function}
  7575. * @default null
  7576. */
  7577. /**
  7578. * @event module:zrender/mixin/Eventful#ondragstart
  7579. * @type {Function}
  7580. * @default null
  7581. */
  7582. /**
  7583. * @event module:zrender/mixin/Eventful#ondragend
  7584. * @type {Function}
  7585. * @default null
  7586. */
  7587. /**
  7588. * @event module:zrender/mixin/Eventful#ondragenter
  7589. * @type {Function}
  7590. * @default null
  7591. */
  7592. /**
  7593. * @event module:zrender/mixin/Eventful#ondragleave
  7594. * @type {Function}
  7595. * @default null
  7596. */
  7597. /**
  7598. * @event module:zrender/mixin/Eventful#ondragover
  7599. * @type {Function}
  7600. * @default null
  7601. */
  7602. /**
  7603. * @event module:zrender/mixin/Eventful#ondrop
  7604. * @type {Function}
  7605. * @default null
  7606. */
  7607. module.exports = Eventful;
  7608. /***/ },
  7609. /* 34 */
  7610. /***/ function(module, exports, __webpack_require__) {
  7611. 'use strict';
  7612. /**
  7613. * 提供变换扩展
  7614. * @module zrender/mixin/Transformable
  7615. * @author pissang (https://www.github.com/pissang)
  7616. */
  7617. var matrix = __webpack_require__(11);
  7618. var vector = __webpack_require__(10);
  7619. var mIdentity = matrix.identity;
  7620. var EPSILON = 5e-5;
  7621. function isNotAroundZero(val) {
  7622. return val > EPSILON || val < -EPSILON;
  7623. }
  7624. /**
  7625. * @alias module:zrender/mixin/Transformable
  7626. * @constructor
  7627. */
  7628. var Transformable = function (opts) {
  7629. opts = opts || {};
  7630. // If there are no given position, rotation, scale
  7631. if (!opts.position) {
  7632. /**
  7633. * 平移
  7634. * @type {Array.<number>}
  7635. * @default [0, 0]
  7636. */
  7637. this.position = [0, 0];
  7638. }
  7639. if (opts.rotation == null) {
  7640. /**
  7641. * 旋转
  7642. * @type {Array.<number>}
  7643. * @default 0
  7644. */
  7645. this.rotation = 0;
  7646. }
  7647. if (!opts.scale) {
  7648. /**
  7649. * 缩放
  7650. * @type {Array.<number>}
  7651. * @default [1, 1]
  7652. */
  7653. this.scale = [1, 1];
  7654. }
  7655. /**
  7656. * 旋转和缩放的原点
  7657. * @type {Array.<number>}
  7658. * @default null
  7659. */
  7660. this.origin = this.origin || null;
  7661. };
  7662. var transformableProto = Transformable.prototype;
  7663. transformableProto.transform = null;
  7664. /**
  7665. * 判断是否需要有坐标变换
  7666. * 如果有坐标变换, 则从position, rotation, scale以及父节点的transform计算出自身的transform矩阵
  7667. */
  7668. transformableProto.needLocalTransform = function () {
  7669. return isNotAroundZero(this.rotation)
  7670. || isNotAroundZero(this.position[0])
  7671. || isNotAroundZero(this.position[1])
  7672. || isNotAroundZero(this.scale[0] - 1)
  7673. || isNotAroundZero(this.scale[1] - 1);
  7674. };
  7675. transformableProto.updateTransform = function () {
  7676. var parent = this.parent;
  7677. var parentHasTransform = parent && parent.transform;
  7678. var needLocalTransform = this.needLocalTransform();
  7679. var m = this.transform;
  7680. if (!(needLocalTransform || parentHasTransform)) {
  7681. m && mIdentity(m);
  7682. return;
  7683. }
  7684. m = m || matrix.create();
  7685. if (needLocalTransform) {
  7686. this.getLocalTransform(m);
  7687. }
  7688. else {
  7689. mIdentity(m);
  7690. }
  7691. // 应用父节点变换
  7692. if (parentHasTransform) {
  7693. if (needLocalTransform) {
  7694. matrix.mul(m, parent.transform, m);
  7695. }
  7696. else {
  7697. matrix.copy(m, parent.transform);
  7698. }
  7699. }
  7700. // 保存这个变换矩阵
  7701. this.transform = m;
  7702. this.invTransform = this.invTransform || matrix.create();
  7703. matrix.invert(this.invTransform, m);
  7704. };
  7705. transformableProto.getLocalTransform = function (m) {
  7706. m = m || [];
  7707. mIdentity(m);
  7708. var origin = this.origin;
  7709. var scale = this.scale;
  7710. var rotation = this.rotation;
  7711. var position = this.position;
  7712. if (origin) {
  7713. // Translate to origin
  7714. m[4] -= origin[0];
  7715. m[5] -= origin[1];
  7716. }
  7717. matrix.scale(m, m, scale);
  7718. if (rotation) {
  7719. matrix.rotate(m, m, rotation);
  7720. }
  7721. if (origin) {
  7722. // Translate back from origin
  7723. m[4] += origin[0];
  7724. m[5] += origin[1];
  7725. }
  7726. m[4] += position[0];
  7727. m[5] += position[1];
  7728. return m;
  7729. };
  7730. /**
  7731. * 将自己的transform应用到context上
  7732. * @param {Context2D} ctx
  7733. */
  7734. transformableProto.setTransform = function (ctx) {
  7735. var m = this.transform;
  7736. var dpr = ctx.dpr || 1;
  7737. if (m) {
  7738. ctx.setTransform(dpr * m[0], dpr * m[1], dpr * m[2], dpr * m[3], dpr * m[4], dpr * m[5]);
  7739. }
  7740. else {
  7741. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  7742. }
  7743. };
  7744. transformableProto.restoreTransform = function (ctx) {
  7745. var m = this.transform;
  7746. var dpr = ctx.dpr || 1;
  7747. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  7748. }
  7749. var tmpTransform = [];
  7750. /**
  7751. * 分解`transform`矩阵到`position`, `rotation`, `scale`
  7752. */
  7753. transformableProto.decomposeTransform = function () {
  7754. if (!this.transform) {
  7755. return;
  7756. }
  7757. var parent = this.parent;
  7758. var m = this.transform;
  7759. if (parent && parent.transform) {
  7760. // Get local transform and decompose them to position, scale, rotation
  7761. matrix.mul(tmpTransform, parent.invTransform, m);
  7762. m = tmpTransform;
  7763. }
  7764. var sx = m[0] * m[0] + m[1] * m[1];
  7765. var sy = m[2] * m[2] + m[3] * m[3];
  7766. var position = this.position;
  7767. var scale = this.scale;
  7768. if (isNotAroundZero(sx - 1)) {
  7769. sx = Math.sqrt(sx);
  7770. }
  7771. if (isNotAroundZero(sy - 1)) {
  7772. sy = Math.sqrt(sy);
  7773. }
  7774. if (m[0] < 0) {
  7775. sx = -sx;
  7776. }
  7777. if (m[3] < 0) {
  7778. sy = -sy;
  7779. }
  7780. position[0] = m[4];
  7781. position[1] = m[5];
  7782. scale[0] = sx;
  7783. scale[1] = sy;
  7784. this.rotation = Math.atan2(-m[1] / sy, m[0] / sx);
  7785. };
  7786. /**
  7787. * Get global scale
  7788. * @return {Array.<number>}
  7789. */
  7790. transformableProto.getGlobalScale = function () {
  7791. var m = this.transform;
  7792. if (!m) {
  7793. return [1, 1];
  7794. }
  7795. var sx = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
  7796. var sy = Math.sqrt(m[2] * m[2] + m[3] * m[3]);
  7797. if (m[0] < 0) {
  7798. sx = -sx;
  7799. }
  7800. if (m[3] < 0) {
  7801. sy = -sy;
  7802. }
  7803. return [sx, sy];
  7804. };
  7805. /**
  7806. * 变换坐标位置到 shape 的局部坐标空间
  7807. * @method
  7808. * @param {number} x
  7809. * @param {number} y
  7810. * @return {Array.<number>}
  7811. */
  7812. transformableProto.transformCoordToLocal = function (x, y) {
  7813. var v2 = [x, y];
  7814. var invTransform = this.invTransform;
  7815. if (invTransform) {
  7816. vector.applyTransform(v2, v2, invTransform);
  7817. }
  7818. return v2;
  7819. };
  7820. /**
  7821. * 变换局部坐标位置到全局坐标空间
  7822. * @method
  7823. * @param {number} x
  7824. * @param {number} y
  7825. * @return {Array.<number>}
  7826. */
  7827. transformableProto.transformCoordToGlobal = function (x, y) {
  7828. var v2 = [x, y];
  7829. var transform = this.transform;
  7830. if (transform) {
  7831. vector.applyTransform(v2, v2, transform);
  7832. }
  7833. return v2;
  7834. };
  7835. module.exports = Transformable;
  7836. /***/ },
  7837. /* 35 */
  7838. /***/ function(module, exports, __webpack_require__) {
  7839. 'use strict';
  7840. /**
  7841. * @module zrender/mixin/Animatable
  7842. */
  7843. var Animator = __webpack_require__(36);
  7844. var util = __webpack_require__(4);
  7845. var isString = util.isString;
  7846. var isFunction = util.isFunction;
  7847. var isObject = util.isObject;
  7848. var log = __webpack_require__(40);
  7849. /**
  7850. * @alias modue:zrender/mixin/Animatable
  7851. * @constructor
  7852. */
  7853. var Animatable = function () {
  7854. /**
  7855. * @type {Array.<module:zrender/animation/Animator>}
  7856. * @readOnly
  7857. */
  7858. this.animators = [];
  7859. };
  7860. Animatable.prototype = {
  7861. constructor: Animatable,
  7862. /**
  7863. * 动画
  7864. *
  7865. * @param {string} path 需要添加动画的属性获取路径,可以通过a.b.c来获取深层的属性
  7866. * @param {boolean} [loop] 动画是否循环
  7867. * @return {module:zrender/animation/Animator}
  7868. * @example:
  7869. * el.animate('style', false)
  7870. * .when(1000, {x: 10} )
  7871. * .done(function(){ // Animation done })
  7872. * .start()
  7873. */
  7874. animate: function (path, loop) {
  7875. var target;
  7876. var animatingShape = false;
  7877. var el = this;
  7878. var zr = this.__zr;
  7879. if (path) {
  7880. var pathSplitted = path.split('.');
  7881. var prop = el;
  7882. // If animating shape
  7883. animatingShape = pathSplitted[0] === 'shape';
  7884. for (var i = 0, l = pathSplitted.length; i < l; i++) {
  7885. if (!prop) {
  7886. continue;
  7887. }
  7888. prop = prop[pathSplitted[i]];
  7889. }
  7890. if (prop) {
  7891. target = prop;
  7892. }
  7893. }
  7894. else {
  7895. target = el;
  7896. }
  7897. if (!target) {
  7898. log(
  7899. 'Property "'
  7900. + path
  7901. + '" is not existed in element '
  7902. + el.id
  7903. );
  7904. return;
  7905. }
  7906. var animators = el.animators;
  7907. var animator = new Animator(target, loop);
  7908. animator.during(function (target) {
  7909. el.dirty(animatingShape);
  7910. })
  7911. .done(function () {
  7912. // FIXME Animator will not be removed if use `Animator#stop` to stop animation
  7913. animators.splice(util.indexOf(animators, animator), 1);
  7914. });
  7915. animators.push(animator);
  7916. // If animate after added to the zrender
  7917. if (zr) {
  7918. zr.animation.addAnimator(animator);
  7919. }
  7920. return animator;
  7921. },
  7922. /**
  7923. * 停止动画
  7924. * @param {boolean} forwardToLast If move to last frame before stop
  7925. */
  7926. stopAnimation: function (forwardToLast) {
  7927. var animators = this.animators;
  7928. var len = animators.length;
  7929. for (var i = 0; i < len; i++) {
  7930. animators[i].stop(forwardToLast);
  7931. }
  7932. animators.length = 0;
  7933. return this;
  7934. },
  7935. /**
  7936. * @param {Object} target
  7937. * @param {number} [time=500] Time in ms
  7938. * @param {string} [easing='linear']
  7939. * @param {number} [delay=0]
  7940. * @param {Function} [callback]
  7941. *
  7942. * @example
  7943. * // Animate position
  7944. * el.animateTo({
  7945. * position: [10, 10]
  7946. * }, function () { // done })
  7947. *
  7948. * // Animate shape, style and position in 100ms, delayed 100ms, with cubicOut easing
  7949. * el.animateTo({
  7950. * shape: {
  7951. * width: 500
  7952. * },
  7953. * style: {
  7954. * fill: 'red'
  7955. * }
  7956. * position: [10, 10]
  7957. * }, 100, 100, 'cubicOut', function () { // done })
  7958. */
  7959. // TODO Return animation key
  7960. animateTo: function (target, time, delay, easing, callback) {
  7961. // animateTo(target, time, easing, callback);
  7962. if (isString(delay)) {
  7963. callback = easing;
  7964. easing = delay;
  7965. delay = 0;
  7966. }
  7967. // animateTo(target, time, delay, callback);
  7968. else if (isFunction(easing)) {
  7969. callback = easing;
  7970. easing = 'linear';
  7971. delay = 0;
  7972. }
  7973. // animateTo(target, time, callback);
  7974. else if (isFunction(delay)) {
  7975. callback = delay;
  7976. delay = 0;
  7977. }
  7978. // animateTo(target, callback)
  7979. else if (isFunction(time)) {
  7980. callback = time;
  7981. time = 500;
  7982. }
  7983. // animateTo(target)
  7984. else if (!time) {
  7985. time = 500;
  7986. }
  7987. // Stop all previous animations
  7988. this.stopAnimation();
  7989. this._animateToShallow('', this, target, time, delay, easing, callback);
  7990. // Animators may be removed immediately after start
  7991. // if there is nothing to animate
  7992. var animators = this.animators.slice();
  7993. var count = animators.length;
  7994. function done() {
  7995. count--;
  7996. if (!count) {
  7997. callback && callback();
  7998. }
  7999. }
  8000. // No animators. This should be checked before animators[i].start(),
  8001. // because 'done' may be executed immediately if no need to animate.
  8002. if (!count) {
  8003. callback && callback();
  8004. }
  8005. // Start after all animators created
  8006. // Incase any animator is done immediately when all animation properties are not changed
  8007. for (var i = 0; i < animators.length; i++) {
  8008. animators[i]
  8009. .done(done)
  8010. .start(easing);
  8011. }
  8012. },
  8013. /**
  8014. * @private
  8015. * @param {string} path=''
  8016. * @param {Object} source=this
  8017. * @param {Object} target
  8018. * @param {number} [time=500]
  8019. * @param {number} [delay=0]
  8020. *
  8021. * @example
  8022. * // Animate position
  8023. * el._animateToShallow({
  8024. * position: [10, 10]
  8025. * })
  8026. *
  8027. * // Animate shape, style and position in 100ms, delayed 100ms
  8028. * el._animateToShallow({
  8029. * shape: {
  8030. * width: 500
  8031. * },
  8032. * style: {
  8033. * fill: 'red'
  8034. * }
  8035. * position: [10, 10]
  8036. * }, 100, 100)
  8037. */
  8038. _animateToShallow: function (path, source, target, time, delay) {
  8039. var objShallow = {};
  8040. var propertyCount = 0;
  8041. for (var name in target) {
  8042. if (!target.hasOwnProperty(name)) {
  8043. continue;
  8044. }
  8045. if (source[name] != null) {
  8046. if (isObject(target[name]) && !util.isArrayLike(target[name])) {
  8047. this._animateToShallow(
  8048. path ? path + '.' + name : name,
  8049. source[name],
  8050. target[name],
  8051. time,
  8052. delay
  8053. );
  8054. }
  8055. else {
  8056. objShallow[name] = target[name];
  8057. propertyCount++;
  8058. }
  8059. }
  8060. else if (target[name] != null) {
  8061. // Attr directly if not has property
  8062. // FIXME, if some property not needed for element ?
  8063. if (!path) {
  8064. this.attr(name, target[name]);
  8065. }
  8066. else { // Shape or style
  8067. var props = {};
  8068. props[path] = {};
  8069. props[path][name] = target[name];
  8070. this.attr(props);
  8071. }
  8072. }
  8073. }
  8074. if (propertyCount > 0) {
  8075. this.animate(path, false)
  8076. .when(time == null ? 500 : time, objShallow)
  8077. .delay(delay || 0);
  8078. }
  8079. return this;
  8080. }
  8081. };
  8082. module.exports = Animatable;
  8083. /***/ },
  8084. /* 36 */
  8085. /***/ function(module, exports, __webpack_require__) {
  8086. /**
  8087. * @module echarts/animation/Animator
  8088. */
  8089. var Clip = __webpack_require__(37);
  8090. var color = __webpack_require__(39);
  8091. var util = __webpack_require__(4);
  8092. var isArrayLike = util.isArrayLike;
  8093. var arraySlice = Array.prototype.slice;
  8094. function defaultGetter(target, key) {
  8095. return target[key];
  8096. }
  8097. function defaultSetter(target, key, value) {
  8098. target[key] = value;
  8099. }
  8100. /**
  8101. * @param {number} p0
  8102. * @param {number} p1
  8103. * @param {number} percent
  8104. * @return {number}
  8105. */
  8106. function interpolateNumber(p0, p1, percent) {
  8107. return (p1 - p0) * percent + p0;
  8108. }
  8109. /**
  8110. * @param {string} p0
  8111. * @param {string} p1
  8112. * @param {number} percent
  8113. * @return {string}
  8114. */
  8115. function interpolateString(p0, p1, percent) {
  8116. return percent > 0.5 ? p1 : p0;
  8117. }
  8118. /**
  8119. * @param {Array} p0
  8120. * @param {Array} p1
  8121. * @param {number} percent
  8122. * @param {Array} out
  8123. * @param {number} arrDim
  8124. */
  8125. function interpolateArray(p0, p1, percent, out, arrDim) {
  8126. var len = p0.length;
  8127. if (arrDim == 1) {
  8128. for (var i = 0; i < len; i++) {
  8129. out[i] = interpolateNumber(p0[i], p1[i], percent);
  8130. }
  8131. }
  8132. else {
  8133. var len2 = p0[0].length;
  8134. for (var i = 0; i < len; i++) {
  8135. for (var j = 0; j < len2; j++) {
  8136. out[i][j] = interpolateNumber(
  8137. p0[i][j], p1[i][j], percent
  8138. );
  8139. }
  8140. }
  8141. }
  8142. }
  8143. // arr0 is source array, arr1 is target array.
  8144. // Do some preprocess to avoid error happened when interpolating from arr0 to arr1
  8145. function fillArr(arr0, arr1, arrDim) {
  8146. var arr0Len = arr0.length;
  8147. var arr1Len = arr1.length;
  8148. if (arr0Len !== arr1Len) {
  8149. // FIXME Not work for TypedArray
  8150. var isPreviousLarger = arr0Len > arr1Len;
  8151. if (isPreviousLarger) {
  8152. // Cut the previous
  8153. arr0.length = arr1Len;
  8154. }
  8155. else {
  8156. // Fill the previous
  8157. for (var i = arr0Len; i < arr1Len; i++) {
  8158. arr0.push(
  8159. arrDim === 1 ? arr1[i] : arraySlice.call(arr1[i])
  8160. );
  8161. }
  8162. }
  8163. }
  8164. // Handling NaN value
  8165. var len2 = arr0[0] && arr0[0].length;
  8166. for (var i = 0; i < arr0.length; i++) {
  8167. if (arrDim === 1) {
  8168. if (isNaN(arr0[i])) {
  8169. arr0[i] = arr1[i];
  8170. }
  8171. }
  8172. else {
  8173. for (var j = 0; j < len2; j++) {
  8174. if (isNaN(arr0[i][j])) {
  8175. arr0[i][j] = arr1[i][j];
  8176. }
  8177. }
  8178. }
  8179. }
  8180. }
  8181. /**
  8182. * @param {Array} arr0
  8183. * @param {Array} arr1
  8184. * @param {number} arrDim
  8185. * @return {boolean}
  8186. */
  8187. function isArraySame(arr0, arr1, arrDim) {
  8188. if (arr0 === arr1) {
  8189. return true;
  8190. }
  8191. var len = arr0.length;
  8192. if (len !== arr1.length) {
  8193. return false;
  8194. }
  8195. if (arrDim === 1) {
  8196. for (var i = 0; i < len; i++) {
  8197. if (arr0[i] !== arr1[i]) {
  8198. return false;
  8199. }
  8200. }
  8201. }
  8202. else {
  8203. var len2 = arr0[0].length;
  8204. for (var i = 0; i < len; i++) {
  8205. for (var j = 0; j < len2; j++) {
  8206. if (arr0[i][j] !== arr1[i][j]) {
  8207. return false;
  8208. }
  8209. }
  8210. }
  8211. }
  8212. return true;
  8213. }
  8214. /**
  8215. * Catmull Rom interpolate array
  8216. * @param {Array} p0
  8217. * @param {Array} p1
  8218. * @param {Array} p2
  8219. * @param {Array} p3
  8220. * @param {number} t
  8221. * @param {number} t2
  8222. * @param {number} t3
  8223. * @param {Array} out
  8224. * @param {number} arrDim
  8225. */
  8226. function catmullRomInterpolateArray(
  8227. p0, p1, p2, p3, t, t2, t3, out, arrDim
  8228. ) {
  8229. var len = p0.length;
  8230. if (arrDim == 1) {
  8231. for (var i = 0; i < len; i++) {
  8232. out[i] = catmullRomInterpolate(
  8233. p0[i], p1[i], p2[i], p3[i], t, t2, t3
  8234. );
  8235. }
  8236. }
  8237. else {
  8238. var len2 = p0[0].length;
  8239. for (var i = 0; i < len; i++) {
  8240. for (var j = 0; j < len2; j++) {
  8241. out[i][j] = catmullRomInterpolate(
  8242. p0[i][j], p1[i][j], p2[i][j], p3[i][j],
  8243. t, t2, t3
  8244. );
  8245. }
  8246. }
  8247. }
  8248. }
  8249. /**
  8250. * Catmull Rom interpolate number
  8251. * @param {number} p0
  8252. * @param {number} p1
  8253. * @param {number} p2
  8254. * @param {number} p3
  8255. * @param {number} t
  8256. * @param {number} t2
  8257. * @param {number} t3
  8258. * @return {number}
  8259. */
  8260. function catmullRomInterpolate(p0, p1, p2, p3, t, t2, t3) {
  8261. var v0 = (p2 - p0) * 0.5;
  8262. var v1 = (p3 - p1) * 0.5;
  8263. return (2 * (p1 - p2) + v0 + v1) * t3
  8264. + (-3 * (p1 - p2) - 2 * v0 - v1) * t2
  8265. + v0 * t + p1;
  8266. }
  8267. function cloneValue(value) {
  8268. if (isArrayLike(value)) {
  8269. var len = value.length;
  8270. if (isArrayLike(value[0])) {
  8271. var ret = [];
  8272. for (var i = 0; i < len; i++) {
  8273. ret.push(arraySlice.call(value[i]));
  8274. }
  8275. return ret;
  8276. }
  8277. return arraySlice.call(value);
  8278. }
  8279. return value;
  8280. }
  8281. function rgba2String(rgba) {
  8282. rgba[0] = Math.floor(rgba[0]);
  8283. rgba[1] = Math.floor(rgba[1]);
  8284. rgba[2] = Math.floor(rgba[2]);
  8285. return 'rgba(' + rgba.join(',') + ')';
  8286. }
  8287. function createTrackClip (animator, easing, oneTrackDone, keyframes, propName) {
  8288. var getter = animator._getter;
  8289. var setter = animator._setter;
  8290. var useSpline = easing === 'spline';
  8291. var trackLen = keyframes.length;
  8292. if (!trackLen) {
  8293. return;
  8294. }
  8295. // Guess data type
  8296. var firstVal = keyframes[0].value;
  8297. var isValueArray = isArrayLike(firstVal);
  8298. var isValueColor = false;
  8299. var isValueString = false;
  8300. // For vertices morphing
  8301. var arrDim = (
  8302. isValueArray
  8303. && isArrayLike(firstVal[0])
  8304. )
  8305. ? 2 : 1;
  8306. var trackMaxTime;
  8307. // Sort keyframe as ascending
  8308. keyframes.sort(function(a, b) {
  8309. return a.time - b.time;
  8310. });
  8311. trackMaxTime = keyframes[trackLen - 1].time;
  8312. // Percents of each keyframe
  8313. var kfPercents = [];
  8314. // Value of each keyframe
  8315. var kfValues = [];
  8316. var prevValue = keyframes[0].value;
  8317. var isAllValueEqual = true;
  8318. for (var i = 0; i < trackLen; i++) {
  8319. kfPercents.push(keyframes[i].time / trackMaxTime);
  8320. // Assume value is a color when it is a string
  8321. var value = keyframes[i].value;
  8322. // Check if value is equal, deep check if value is array
  8323. if (!((isValueArray && isArraySame(value, prevValue, arrDim))
  8324. || (!isValueArray && value === prevValue))) {
  8325. isAllValueEqual = false;
  8326. }
  8327. prevValue = value;
  8328. // Try converting a string to a color array
  8329. if (typeof value == 'string') {
  8330. var colorArray = color.parse(value);
  8331. if (colorArray) {
  8332. value = colorArray;
  8333. isValueColor = true;
  8334. }
  8335. else {
  8336. isValueString = true;
  8337. }
  8338. }
  8339. kfValues.push(value);
  8340. }
  8341. if (isAllValueEqual) {
  8342. return;
  8343. }
  8344. var lastValue = kfValues[trackLen - 1];
  8345. // Polyfill array and NaN value
  8346. for (var i = 0; i < trackLen - 1; i++) {
  8347. if (isValueArray) {
  8348. fillArr(kfValues[i], lastValue, arrDim);
  8349. }
  8350. else {
  8351. if (isNaN(kfValues[i]) && !isNaN(lastValue) && !isValueString && !isValueColor) {
  8352. kfValues[i] = lastValue;
  8353. }
  8354. }
  8355. }
  8356. isValueArray && fillArr(getter(animator._target, propName), lastValue, arrDim);
  8357. // Cache the key of last frame to speed up when
  8358. // animation playback is sequency
  8359. var lastFrame = 0;
  8360. var lastFramePercent = 0;
  8361. var start;
  8362. var w;
  8363. var p0;
  8364. var p1;
  8365. var p2;
  8366. var p3;
  8367. if (isValueColor) {
  8368. var rgba = [0, 0, 0, 0];
  8369. }
  8370. var onframe = function (target, percent) {
  8371. // Find the range keyframes
  8372. // kf1-----kf2---------current--------kf3
  8373. // find kf2 and kf3 and do interpolation
  8374. var frame;
  8375. // In the easing function like elasticOut, percent may less than 0
  8376. if (percent < 0) {
  8377. frame = 0;
  8378. }
  8379. else if (percent < lastFramePercent) {
  8380. // Start from next key
  8381. // PENDING start from lastFrame ?
  8382. start = Math.min(lastFrame + 1, trackLen - 1);
  8383. for (frame = start; frame >= 0; frame--) {
  8384. if (kfPercents[frame] <= percent) {
  8385. break;
  8386. }
  8387. }
  8388. // PENDING really need to do this ?
  8389. frame = Math.min(frame, trackLen - 2);
  8390. }
  8391. else {
  8392. for (frame = lastFrame; frame < trackLen; frame++) {
  8393. if (kfPercents[frame] > percent) {
  8394. break;
  8395. }
  8396. }
  8397. frame = Math.min(frame - 1, trackLen - 2);
  8398. }
  8399. lastFrame = frame;
  8400. lastFramePercent = percent;
  8401. var range = (kfPercents[frame + 1] - kfPercents[frame]);
  8402. if (range === 0) {
  8403. return;
  8404. }
  8405. else {
  8406. w = (percent - kfPercents[frame]) / range;
  8407. }
  8408. if (useSpline) {
  8409. p1 = kfValues[frame];
  8410. p0 = kfValues[frame === 0 ? frame : frame - 1];
  8411. p2 = kfValues[frame > trackLen - 2 ? trackLen - 1 : frame + 1];
  8412. p3 = kfValues[frame > trackLen - 3 ? trackLen - 1 : frame + 2];
  8413. if (isValueArray) {
  8414. catmullRomInterpolateArray(
  8415. p0, p1, p2, p3, w, w * w, w * w * w,
  8416. getter(target, propName),
  8417. arrDim
  8418. );
  8419. }
  8420. else {
  8421. var value;
  8422. if (isValueColor) {
  8423. value = catmullRomInterpolateArray(
  8424. p0, p1, p2, p3, w, w * w, w * w * w,
  8425. rgba, 1
  8426. );
  8427. value = rgba2String(rgba);
  8428. }
  8429. else if (isValueString) {
  8430. // String is step(0.5)
  8431. return interpolateString(p1, p2, w);
  8432. }
  8433. else {
  8434. value = catmullRomInterpolate(
  8435. p0, p1, p2, p3, w, w * w, w * w * w
  8436. );
  8437. }
  8438. setter(
  8439. target,
  8440. propName,
  8441. value
  8442. );
  8443. }
  8444. }
  8445. else {
  8446. if (isValueArray) {
  8447. interpolateArray(
  8448. kfValues[frame], kfValues[frame + 1], w,
  8449. getter(target, propName),
  8450. arrDim
  8451. );
  8452. }
  8453. else {
  8454. var value;
  8455. if (isValueColor) {
  8456. interpolateArray(
  8457. kfValues[frame], kfValues[frame + 1], w,
  8458. rgba, 1
  8459. );
  8460. value = rgba2String(rgba);
  8461. }
  8462. else if (isValueString) {
  8463. // String is step(0.5)
  8464. return interpolateString(kfValues[frame], kfValues[frame + 1], w);
  8465. }
  8466. else {
  8467. value = interpolateNumber(kfValues[frame], kfValues[frame + 1], w);
  8468. }
  8469. setter(
  8470. target,
  8471. propName,
  8472. value
  8473. );
  8474. }
  8475. }
  8476. };
  8477. var clip = new Clip({
  8478. target: animator._target,
  8479. life: trackMaxTime,
  8480. loop: animator._loop,
  8481. delay: animator._delay,
  8482. onframe: onframe,
  8483. ondestroy: oneTrackDone
  8484. });
  8485. if (easing && easing !== 'spline') {
  8486. clip.easing = easing;
  8487. }
  8488. return clip;
  8489. }
  8490. /**
  8491. * @alias module:zrender/animation/Animator
  8492. * @constructor
  8493. * @param {Object} target
  8494. * @param {boolean} loop
  8495. * @param {Function} getter
  8496. * @param {Function} setter
  8497. */
  8498. var Animator = function(target, loop, getter, setter) {
  8499. this._tracks = {};
  8500. this._target = target;
  8501. this._loop = loop || false;
  8502. this._getter = getter || defaultGetter;
  8503. this._setter = setter || defaultSetter;
  8504. this._clipCount = 0;
  8505. this._delay = 0;
  8506. this._doneList = [];
  8507. this._onframeList = [];
  8508. this._clipList = [];
  8509. };
  8510. Animator.prototype = {
  8511. /**
  8512. * 设置动画关键帧
  8513. * @param {number} time 关键帧时间,单位是ms
  8514. * @param {Object} props 关键帧的属性值,key-value表示
  8515. * @return {module:zrender/animation/Animator}
  8516. */
  8517. when: function(time /* ms */, props) {
  8518. var tracks = this._tracks;
  8519. for (var propName in props) {
  8520. if (!props.hasOwnProperty(propName)) {
  8521. continue;
  8522. }
  8523. if (!tracks[propName]) {
  8524. tracks[propName] = [];
  8525. // Invalid value
  8526. var value = this._getter(this._target, propName);
  8527. if (value == null) {
  8528. // zrLog('Invalid property ' + propName);
  8529. continue;
  8530. }
  8531. // If time is 0
  8532. // Then props is given initialize value
  8533. // Else
  8534. // Initialize value from current prop value
  8535. if (time !== 0) {
  8536. tracks[propName].push({
  8537. time: 0,
  8538. value: cloneValue(value)
  8539. });
  8540. }
  8541. }
  8542. tracks[propName].push({
  8543. time: time,
  8544. value: props[propName]
  8545. });
  8546. }
  8547. return this;
  8548. },
  8549. /**
  8550. * 添加动画每一帧的回调函数
  8551. * @param {Function} callback
  8552. * @return {module:zrender/animation/Animator}
  8553. */
  8554. during: function (callback) {
  8555. this._onframeList.push(callback);
  8556. return this;
  8557. },
  8558. _doneCallback: function () {
  8559. // Clear all tracks
  8560. this._tracks = {};
  8561. // Clear all clips
  8562. this._clipList.length = 0;
  8563. var doneList = this._doneList;
  8564. var len = doneList.length;
  8565. for (var i = 0; i < len; i++) {
  8566. doneList[i].call(this);
  8567. }
  8568. },
  8569. /**
  8570. * 开始执行动画
  8571. * @param {string|Function} easing
  8572. * 动画缓动函数,详见{@link module:zrender/animation/easing}
  8573. * @return {module:zrender/animation/Animator}
  8574. */
  8575. start: function (easing) {
  8576. var self = this;
  8577. var clipCount = 0;
  8578. var oneTrackDone = function() {
  8579. clipCount--;
  8580. if (!clipCount) {
  8581. self._doneCallback();
  8582. }
  8583. };
  8584. var lastClip;
  8585. for (var propName in this._tracks) {
  8586. if (!this._tracks.hasOwnProperty(propName)) {
  8587. continue;
  8588. }
  8589. var clip = createTrackClip(
  8590. this, easing, oneTrackDone,
  8591. this._tracks[propName], propName
  8592. );
  8593. if (clip) {
  8594. this._clipList.push(clip);
  8595. clipCount++;
  8596. // If start after added to animation
  8597. if (this.animation) {
  8598. this.animation.addClip(clip);
  8599. }
  8600. lastClip = clip;
  8601. }
  8602. }
  8603. // Add during callback on the last clip
  8604. if (lastClip) {
  8605. var oldOnFrame = lastClip.onframe;
  8606. lastClip.onframe = function (target, percent) {
  8607. oldOnFrame(target, percent);
  8608. for (var i = 0; i < self._onframeList.length; i++) {
  8609. self._onframeList[i](target, percent);
  8610. }
  8611. };
  8612. }
  8613. if (!clipCount) {
  8614. this._doneCallback();
  8615. }
  8616. return this;
  8617. },
  8618. /**
  8619. * 停止动画
  8620. * @param {boolean} forwardToLast If move to last frame before stop
  8621. */
  8622. stop: function (forwardToLast) {
  8623. var clipList = this._clipList;
  8624. var animation = this.animation;
  8625. for (var i = 0; i < clipList.length; i++) {
  8626. var clip = clipList[i];
  8627. if (forwardToLast) {
  8628. // Move to last frame before stop
  8629. clip.onframe(this._target, 1);
  8630. }
  8631. animation && animation.removeClip(clip);
  8632. }
  8633. clipList.length = 0;
  8634. },
  8635. /**
  8636. * 设置动画延迟开始的时间
  8637. * @param {number} time 单位ms
  8638. * @return {module:zrender/animation/Animator}
  8639. */
  8640. delay: function (time) {
  8641. this._delay = time;
  8642. return this;
  8643. },
  8644. /**
  8645. * 添加动画结束的回调
  8646. * @param {Function} cb
  8647. * @return {module:zrender/animation/Animator}
  8648. */
  8649. done: function(cb) {
  8650. if (cb) {
  8651. this._doneList.push(cb);
  8652. }
  8653. return this;
  8654. },
  8655. /**
  8656. * @return {Array.<module:zrender/animation/Clip>}
  8657. */
  8658. getClips: function () {
  8659. return this._clipList;
  8660. }
  8661. };
  8662. module.exports = Animator;
  8663. /***/ },
  8664. /* 37 */
  8665. /***/ function(module, exports, __webpack_require__) {
  8666. /**
  8667. * 动画主控制器
  8668. * @config target 动画对象,可以是数组,如果是数组的话会批量分发onframe等事件
  8669. * @config life(1000) 动画时长
  8670. * @config delay(0) 动画延迟时间
  8671. * @config loop(true)
  8672. * @config gap(0) 循环的间隔时间
  8673. * @config onframe
  8674. * @config easing(optional)
  8675. * @config ondestroy(optional)
  8676. * @config onrestart(optional)
  8677. *
  8678. * TODO pause
  8679. */
  8680. var easingFuncs = __webpack_require__(38);
  8681. function Clip(options) {
  8682. this._target = options.target;
  8683. // 生命周期
  8684. this._life = options.life || 1000;
  8685. // 延时
  8686. this._delay = options.delay || 0;
  8687. // 开始时间
  8688. // this._startTime = new Date().getTime() + this._delay;// 单位毫秒
  8689. this._initialized = false;
  8690. // 是否循环
  8691. this.loop = options.loop == null ? false : options.loop;
  8692. this.gap = options.gap || 0;
  8693. this.easing = options.easing || 'Linear';
  8694. this.onframe = options.onframe;
  8695. this.ondestroy = options.ondestroy;
  8696. this.onrestart = options.onrestart;
  8697. }
  8698. Clip.prototype = {
  8699. constructor: Clip,
  8700. step: function (globalTime) {
  8701. // Set startTime on first step, or _startTime may has milleseconds different between clips
  8702. // PENDING
  8703. if (!this._initialized) {
  8704. this._startTime = globalTime + this._delay;
  8705. this._initialized = true;
  8706. }
  8707. var percent = (globalTime - this._startTime) / this._life;
  8708. // 还没开始
  8709. if (percent < 0) {
  8710. return;
  8711. }
  8712. percent = Math.min(percent, 1);
  8713. var easing = this.easing;
  8714. var easingFunc = typeof easing == 'string' ? easingFuncs[easing] : easing;
  8715. var schedule = typeof easingFunc === 'function'
  8716. ? easingFunc(percent)
  8717. : percent;
  8718. this.fire('frame', schedule);
  8719. // 结束
  8720. if (percent == 1) {
  8721. if (this.loop) {
  8722. this.restart (globalTime);
  8723. // 重新开始周期
  8724. // 抛出而不是直接调用事件直到 stage.update 后再统一调用这些事件
  8725. return 'restart';
  8726. }
  8727. // 动画完成将这个控制器标识为待删除
  8728. // 在Animation.update中进行批量删除
  8729. this._needsRemove = true;
  8730. return 'destroy';
  8731. }
  8732. return null;
  8733. },
  8734. restart: function (globalTime) {
  8735. var remainder = (globalTime - this._startTime) % this._life;
  8736. this._startTime = globalTime - remainder + this.gap;
  8737. this._needsRemove = false;
  8738. },
  8739. fire: function(eventType, arg) {
  8740. eventType = 'on' + eventType;
  8741. if (this[eventType]) {
  8742. this[eventType](this._target, arg);
  8743. }
  8744. }
  8745. };
  8746. module.exports = Clip;
  8747. /***/ },
  8748. /* 38 */
  8749. /***/ function(module, exports) {
  8750. /**
  8751. * 缓动代码来自 https://github.com/sole/tween.js/blob/master/src/Tween.js
  8752. * @see http://sole.github.io/tween.js/examples/03_graphs.html
  8753. * @exports zrender/animation/easing
  8754. */
  8755. var easing = {
  8756. /**
  8757. * @param {number} k
  8758. * @return {number}
  8759. */
  8760. linear: function (k) {
  8761. return k;
  8762. },
  8763. /**
  8764. * @param {number} k
  8765. * @return {number}
  8766. */
  8767. quadraticIn: function (k) {
  8768. return k * k;
  8769. },
  8770. /**
  8771. * @param {number} k
  8772. * @return {number}
  8773. */
  8774. quadraticOut: function (k) {
  8775. return k * (2 - k);
  8776. },
  8777. /**
  8778. * @param {number} k
  8779. * @return {number}
  8780. */
  8781. quadraticInOut: function (k) {
  8782. if ((k *= 2) < 1) {
  8783. return 0.5 * k * k;
  8784. }
  8785. return -0.5 * (--k * (k - 2) - 1);
  8786. },
  8787. // 三次方的缓动(t^3)
  8788. /**
  8789. * @param {number} k
  8790. * @return {number}
  8791. */
  8792. cubicIn: function (k) {
  8793. return k * k * k;
  8794. },
  8795. /**
  8796. * @param {number} k
  8797. * @return {number}
  8798. */
  8799. cubicOut: function (k) {
  8800. return --k * k * k + 1;
  8801. },
  8802. /**
  8803. * @param {number} k
  8804. * @return {number}
  8805. */
  8806. cubicInOut: function (k) {
  8807. if ((k *= 2) < 1) {
  8808. return 0.5 * k * k * k;
  8809. }
  8810. return 0.5 * ((k -= 2) * k * k + 2);
  8811. },
  8812. // 四次方的缓动(t^4)
  8813. /**
  8814. * @param {number} k
  8815. * @return {number}
  8816. */
  8817. quarticIn: function (k) {
  8818. return k * k * k * k;
  8819. },
  8820. /**
  8821. * @param {number} k
  8822. * @return {number}
  8823. */
  8824. quarticOut: function (k) {
  8825. return 1 - (--k * k * k * k);
  8826. },
  8827. /**
  8828. * @param {number} k
  8829. * @return {number}
  8830. */
  8831. quarticInOut: function (k) {
  8832. if ((k *= 2) < 1) {
  8833. return 0.5 * k * k * k * k;
  8834. }
  8835. return -0.5 * ((k -= 2) * k * k * k - 2);
  8836. },
  8837. // 五次方的缓动(t^5)
  8838. /**
  8839. * @param {number} k
  8840. * @return {number}
  8841. */
  8842. quinticIn: function (k) {
  8843. return k * k * k * k * k;
  8844. },
  8845. /**
  8846. * @param {number} k
  8847. * @return {number}
  8848. */
  8849. quinticOut: function (k) {
  8850. return --k * k * k * k * k + 1;
  8851. },
  8852. /**
  8853. * @param {number} k
  8854. * @return {number}
  8855. */
  8856. quinticInOut: function (k) {
  8857. if ((k *= 2) < 1) {
  8858. return 0.5 * k * k * k * k * k;
  8859. }
  8860. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  8861. },
  8862. // 正弦曲线的缓动(sin(t))
  8863. /**
  8864. * @param {number} k
  8865. * @return {number}
  8866. */
  8867. sinusoidalIn: function (k) {
  8868. return 1 - Math.cos(k * Math.PI / 2);
  8869. },
  8870. /**
  8871. * @param {number} k
  8872. * @return {number}
  8873. */
  8874. sinusoidalOut: function (k) {
  8875. return Math.sin(k * Math.PI / 2);
  8876. },
  8877. /**
  8878. * @param {number} k
  8879. * @return {number}
  8880. */
  8881. sinusoidalInOut: function (k) {
  8882. return 0.5 * (1 - Math.cos(Math.PI * k));
  8883. },
  8884. // 指数曲线的缓动(2^t)
  8885. /**
  8886. * @param {number} k
  8887. * @return {number}
  8888. */
  8889. exponentialIn: function (k) {
  8890. return k === 0 ? 0 : Math.pow(1024, k - 1);
  8891. },
  8892. /**
  8893. * @param {number} k
  8894. * @return {number}
  8895. */
  8896. exponentialOut: function (k) {
  8897. return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
  8898. },
  8899. /**
  8900. * @param {number} k
  8901. * @return {number}
  8902. */
  8903. exponentialInOut: function (k) {
  8904. if (k === 0) {
  8905. return 0;
  8906. }
  8907. if (k === 1) {
  8908. return 1;
  8909. }
  8910. if ((k *= 2) < 1) {
  8911. return 0.5 * Math.pow(1024, k - 1);
  8912. }
  8913. return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
  8914. },
  8915. // 圆形曲线的缓动(sqrt(1-t^2))
  8916. /**
  8917. * @param {number} k
  8918. * @return {number}
  8919. */
  8920. circularIn: function (k) {
  8921. return 1 - Math.sqrt(1 - k * k);
  8922. },
  8923. /**
  8924. * @param {number} k
  8925. * @return {number}
  8926. */
  8927. circularOut: function (k) {
  8928. return Math.sqrt(1 - (--k * k));
  8929. },
  8930. /**
  8931. * @param {number} k
  8932. * @return {number}
  8933. */
  8934. circularInOut: function (k) {
  8935. if ((k *= 2) < 1) {
  8936. return -0.5 * (Math.sqrt(1 - k * k) - 1);
  8937. }
  8938. return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
  8939. },
  8940. // 创建类似于弹簧在停止前来回振荡的动画
  8941. /**
  8942. * @param {number} k
  8943. * @return {number}
  8944. */
  8945. elasticIn: function (k) {
  8946. var s;
  8947. var a = 0.1;
  8948. var p = 0.4;
  8949. if (k === 0) {
  8950. return 0;
  8951. }
  8952. if (k === 1) {
  8953. return 1;
  8954. }
  8955. if (!a || a < 1) {
  8956. a = 1; s = p / 4;
  8957. }
  8958. else {
  8959. s = p * Math.asin(1 / a) / (2 * Math.PI);
  8960. }
  8961. return -(a * Math.pow(2, 10 * (k -= 1)) *
  8962. Math.sin((k - s) * (2 * Math.PI) / p));
  8963. },
  8964. /**
  8965. * @param {number} k
  8966. * @return {number}
  8967. */
  8968. elasticOut: function (k) {
  8969. var s;
  8970. var a = 0.1;
  8971. var p = 0.4;
  8972. if (k === 0) {
  8973. return 0;
  8974. }
  8975. if (k === 1) {
  8976. return 1;
  8977. }
  8978. if (!a || a < 1) {
  8979. a = 1; s = p / 4;
  8980. }
  8981. else {
  8982. s = p * Math.asin(1 / a) / (2 * Math.PI);
  8983. }
  8984. return (a * Math.pow(2, -10 * k) *
  8985. Math.sin((k - s) * (2 * Math.PI) / p) + 1);
  8986. },
  8987. /**
  8988. * @param {number} k
  8989. * @return {number}
  8990. */
  8991. elasticInOut: function (k) {
  8992. var s;
  8993. var a = 0.1;
  8994. var p = 0.4;
  8995. if (k === 0) {
  8996. return 0;
  8997. }
  8998. if (k === 1) {
  8999. return 1;
  9000. }
  9001. if (!a || a < 1) {
  9002. a = 1; s = p / 4;
  9003. }
  9004. else {
  9005. s = p * Math.asin(1 / a) / (2 * Math.PI);
  9006. }
  9007. if ((k *= 2) < 1) {
  9008. return -0.5 * (a * Math.pow(2, 10 * (k -= 1))
  9009. * Math.sin((k - s) * (2 * Math.PI) / p));
  9010. }
  9011. return a * Math.pow(2, -10 * (k -= 1))
  9012. * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
  9013. },
  9014. // 在某一动画开始沿指示的路径进行动画处理前稍稍收回该动画的移动
  9015. /**
  9016. * @param {number} k
  9017. * @return {number}
  9018. */
  9019. backIn: function (k) {
  9020. var s = 1.70158;
  9021. return k * k * ((s + 1) * k - s);
  9022. },
  9023. /**
  9024. * @param {number} k
  9025. * @return {number}
  9026. */
  9027. backOut: function (k) {
  9028. var s = 1.70158;
  9029. return --k * k * ((s + 1) * k + s) + 1;
  9030. },
  9031. /**
  9032. * @param {number} k
  9033. * @return {number}
  9034. */
  9035. backInOut: function (k) {
  9036. var s = 1.70158 * 1.525;
  9037. if ((k *= 2) < 1) {
  9038. return 0.5 * (k * k * ((s + 1) * k - s));
  9039. }
  9040. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  9041. },
  9042. // 创建弹跳效果
  9043. /**
  9044. * @param {number} k
  9045. * @return {number}
  9046. */
  9047. bounceIn: function (k) {
  9048. return 1 - easing.bounceOut(1 - k);
  9049. },
  9050. /**
  9051. * @param {number} k
  9052. * @return {number}
  9053. */
  9054. bounceOut: function (k) {
  9055. if (k < (1 / 2.75)) {
  9056. return 7.5625 * k * k;
  9057. }
  9058. else if (k < (2 / 2.75)) {
  9059. return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;
  9060. }
  9061. else if (k < (2.5 / 2.75)) {
  9062. return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;
  9063. }
  9064. else {
  9065. return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;
  9066. }
  9067. },
  9068. /**
  9069. * @param {number} k
  9070. * @return {number}
  9071. */
  9072. bounceInOut: function (k) {
  9073. if (k < 0.5) {
  9074. return easing.bounceIn(k * 2) * 0.5;
  9075. }
  9076. return easing.bounceOut(k * 2 - 1) * 0.5 + 0.5;
  9077. }
  9078. };
  9079. module.exports = easing;
  9080. /***/ },
  9081. /* 39 */
  9082. /***/ function(module, exports) {
  9083. /**
  9084. * @module zrender/tool/color
  9085. */
  9086. var kCSSColorTable = {
  9087. 'transparent': [0,0,0,0], 'aliceblue': [240,248,255,1],
  9088. 'antiquewhite': [250,235,215,1], 'aqua': [0,255,255,1],
  9089. 'aquamarine': [127,255,212,1], 'azure': [240,255,255,1],
  9090. 'beige': [245,245,220,1], 'bisque': [255,228,196,1],
  9091. 'black': [0,0,0,1], 'blanchedalmond': [255,235,205,1],
  9092. 'blue': [0,0,255,1], 'blueviolet': [138,43,226,1],
  9093. 'brown': [165,42,42,1], 'burlywood': [222,184,135,1],
  9094. 'cadetblue': [95,158,160,1], 'chartreuse': [127,255,0,1],
  9095. 'chocolate': [210,105,30,1], 'coral': [255,127,80,1],
  9096. 'cornflowerblue': [100,149,237,1], 'cornsilk': [255,248,220,1],
  9097. 'crimson': [220,20,60,1], 'cyan': [0,255,255,1],
  9098. 'darkblue': [0,0,139,1], 'darkcyan': [0,139,139,1],
  9099. 'darkgoldenrod': [184,134,11,1], 'darkgray': [169,169,169,1],
  9100. 'darkgreen': [0,100,0,1], 'darkgrey': [169,169,169,1],
  9101. 'darkkhaki': [189,183,107,1], 'darkmagenta': [139,0,139,1],
  9102. 'darkolivegreen': [85,107,47,1], 'darkorange': [255,140,0,1],
  9103. 'darkorchid': [153,50,204,1], 'darkred': [139,0,0,1],
  9104. 'darksalmon': [233,150,122,1], 'darkseagreen': [143,188,143,1],
  9105. 'darkslateblue': [72,61,139,1], 'darkslategray': [47,79,79,1],
  9106. 'darkslategrey': [47,79,79,1], 'darkturquoise': [0,206,209,1],
  9107. 'darkviolet': [148,0,211,1], 'deeppink': [255,20,147,1],
  9108. 'deepskyblue': [0,191,255,1], 'dimgray': [105,105,105,1],
  9109. 'dimgrey': [105,105,105,1], 'dodgerblue': [30,144,255,1],
  9110. 'firebrick': [178,34,34,1], 'floralwhite': [255,250,240,1],
  9111. 'forestgreen': [34,139,34,1], 'fuchsia': [255,0,255,1],
  9112. 'gainsboro': [220,220,220,1], 'ghostwhite': [248,248,255,1],
  9113. 'gold': [255,215,0,1], 'goldenrod': [218,165,32,1],
  9114. 'gray': [128,128,128,1], 'green': [0,128,0,1],
  9115. 'greenyellow': [173,255,47,1], 'grey': [128,128,128,1],
  9116. 'honeydew': [240,255,240,1], 'hotpink': [255,105,180,1],
  9117. 'indianred': [205,92,92,1], 'indigo': [75,0,130,1],
  9118. 'ivory': [255,255,240,1], 'khaki': [240,230,140,1],
  9119. 'lavender': [230,230,250,1], 'lavenderblush': [255,240,245,1],
  9120. 'lawngreen': [124,252,0,1], 'lemonchiffon': [255,250,205,1],
  9121. 'lightblue': [173,216,230,1], 'lightcoral': [240,128,128,1],
  9122. 'lightcyan': [224,255,255,1], 'lightgoldenrodyellow': [250,250,210,1],
  9123. 'lightgray': [211,211,211,1], 'lightgreen': [144,238,144,1],
  9124. 'lightgrey': [211,211,211,1], 'lightpink': [255,182,193,1],
  9125. 'lightsalmon': [255,160,122,1], 'lightseagreen': [32,178,170,1],
  9126. 'lightskyblue': [135,206,250,1], 'lightslategray': [119,136,153,1],
  9127. 'lightslategrey': [119,136,153,1], 'lightsteelblue': [176,196,222,1],
  9128. 'lightyellow': [255,255,224,1], 'lime': [0,255,0,1],
  9129. 'limegreen': [50,205,50,1], 'linen': [250,240,230,1],
  9130. 'magenta': [255,0,255,1], 'maroon': [128,0,0,1],
  9131. 'mediumaquamarine': [102,205,170,1], 'mediumblue': [0,0,205,1],
  9132. 'mediumorchid': [186,85,211,1], 'mediumpurple': [147,112,219,1],
  9133. 'mediumseagreen': [60,179,113,1], 'mediumslateblue': [123,104,238,1],
  9134. 'mediumspringgreen': [0,250,154,1], 'mediumturquoise': [72,209,204,1],
  9135. 'mediumvioletred': [199,21,133,1], 'midnightblue': [25,25,112,1],
  9136. 'mintcream': [245,255,250,1], 'mistyrose': [255,228,225,1],
  9137. 'moccasin': [255,228,181,1], 'navajowhite': [255,222,173,1],
  9138. 'navy': [0,0,128,1], 'oldlace': [253,245,230,1],
  9139. 'olive': [128,128,0,1], 'olivedrab': [107,142,35,1],
  9140. 'orange': [255,165,0,1], 'orangered': [255,69,0,1],
  9141. 'orchid': [218,112,214,1], 'palegoldenrod': [238,232,170,1],
  9142. 'palegreen': [152,251,152,1], 'paleturquoise': [175,238,238,1],
  9143. 'palevioletred': [219,112,147,1], 'papayawhip': [255,239,213,1],
  9144. 'peachpuff': [255,218,185,1], 'peru': [205,133,63,1],
  9145. 'pink': [255,192,203,1], 'plum': [221,160,221,1],
  9146. 'powderblue': [176,224,230,1], 'purple': [128,0,128,1],
  9147. 'red': [255,0,0,1], 'rosybrown': [188,143,143,1],
  9148. 'royalblue': [65,105,225,1], 'saddlebrown': [139,69,19,1],
  9149. 'salmon': [250,128,114,1], 'sandybrown': [244,164,96,1],
  9150. 'seagreen': [46,139,87,1], 'seashell': [255,245,238,1],
  9151. 'sienna': [160,82,45,1], 'silver': [192,192,192,1],
  9152. 'skyblue': [135,206,235,1], 'slateblue': [106,90,205,1],
  9153. 'slategray': [112,128,144,1], 'slategrey': [112,128,144,1],
  9154. 'snow': [255,250,250,1], 'springgreen': [0,255,127,1],
  9155. 'steelblue': [70,130,180,1], 'tan': [210,180,140,1],
  9156. 'teal': [0,128,128,1], 'thistle': [216,191,216,1],
  9157. 'tomato': [255,99,71,1], 'turquoise': [64,224,208,1],
  9158. 'violet': [238,130,238,1], 'wheat': [245,222,179,1],
  9159. 'white': [255,255,255,1], 'whitesmoke': [245,245,245,1],
  9160. 'yellow': [255,255,0,1], 'yellowgreen': [154,205,50,1]
  9161. };
  9162. function clampCssByte(i) { // Clamp to integer 0 .. 255.
  9163. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  9164. return i < 0 ? 0 : i > 255 ? 255 : i;
  9165. }
  9166. function clampCssAngle(i) { // Clamp to integer 0 .. 360.
  9167. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  9168. return i < 0 ? 0 : i > 360 ? 360 : i;
  9169. }
  9170. function clampCssFloat(f) { // Clamp to float 0.0 .. 1.0.
  9171. return f < 0 ? 0 : f > 1 ? 1 : f;
  9172. }
  9173. function parseCssInt(str) { // int or percentage.
  9174. if (str.length && str.charAt(str.length - 1) === '%') {
  9175. return clampCssByte(parseFloat(str) / 100 * 255);
  9176. }
  9177. return clampCssByte(parseInt(str, 10));
  9178. }
  9179. function parseCssFloat(str) { // float or percentage.
  9180. if (str.length && str.charAt(str.length - 1) === '%') {
  9181. return clampCssFloat(parseFloat(str) / 100);
  9182. }
  9183. return clampCssFloat(parseFloat(str));
  9184. }
  9185. function cssHueToRgb(m1, m2, h) {
  9186. if (h < 0) {
  9187. h += 1;
  9188. }
  9189. else if (h > 1) {
  9190. h -= 1;
  9191. }
  9192. if (h * 6 < 1) {
  9193. return m1 + (m2 - m1) * h * 6;
  9194. }
  9195. if (h * 2 < 1) {
  9196. return m2;
  9197. }
  9198. if (h * 3 < 2) {
  9199. return m1 + (m2 - m1) * (2/3 - h) * 6;
  9200. }
  9201. return m1;
  9202. }
  9203. function lerp(a, b, p) {
  9204. return a + (b - a) * p;
  9205. }
  9206. /**
  9207. * @param {string} colorStr
  9208. * @return {Array.<number>}
  9209. * @memberOf module:zrender/util/color
  9210. */
  9211. function parse(colorStr) {
  9212. if (!colorStr) {
  9213. return;
  9214. }
  9215. // colorStr may be not string
  9216. colorStr = colorStr + '';
  9217. // Remove all whitespace, not compliant, but should just be more accepting.
  9218. var str = colorStr.replace(/ /g, '').toLowerCase();
  9219. // Color keywords (and transparent) lookup.
  9220. if (str in kCSSColorTable) {
  9221. return kCSSColorTable[str].slice(); // dup.
  9222. }
  9223. // #abc and #abc123 syntax.
  9224. if (str.charAt(0) === '#') {
  9225. if (str.length === 4) {
  9226. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  9227. if (!(iv >= 0 && iv <= 0xfff)) {
  9228. return; // Covers NaN.
  9229. }
  9230. return [
  9231. ((iv & 0xf00) >> 4) | ((iv & 0xf00) >> 8),
  9232. (iv & 0xf0) | ((iv & 0xf0) >> 4),
  9233. (iv & 0xf) | ((iv & 0xf) << 4),
  9234. 1
  9235. ];
  9236. }
  9237. else if (str.length === 7) {
  9238. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  9239. if (!(iv >= 0 && iv <= 0xffffff)) {
  9240. return; // Covers NaN.
  9241. }
  9242. return [
  9243. (iv & 0xff0000) >> 16,
  9244. (iv & 0xff00) >> 8,
  9245. iv & 0xff,
  9246. 1
  9247. ];
  9248. }
  9249. return;
  9250. }
  9251. var op = str.indexOf('('), ep = str.indexOf(')');
  9252. if (op !== -1 && ep + 1 === str.length) {
  9253. var fname = str.substr(0, op);
  9254. var params = str.substr(op + 1, ep - (op + 1)).split(',');
  9255. var alpha = 1; // To allow case fallthrough.
  9256. switch (fname) {
  9257. case 'rgba':
  9258. if (params.length !== 4) {
  9259. return;
  9260. }
  9261. alpha = parseCssFloat(params.pop()); // jshint ignore:line
  9262. // Fall through.
  9263. case 'rgb':
  9264. if (params.length !== 3) {
  9265. return;
  9266. }
  9267. return [
  9268. parseCssInt(params[0]),
  9269. parseCssInt(params[1]),
  9270. parseCssInt(params[2]),
  9271. alpha
  9272. ];
  9273. case 'hsla':
  9274. if (params.length !== 4) {
  9275. return;
  9276. }
  9277. params[3] = parseCssFloat(params[3]);
  9278. return hsla2rgba(params);
  9279. case 'hsl':
  9280. if (params.length !== 3) {
  9281. return;
  9282. }
  9283. return hsla2rgba(params);
  9284. default:
  9285. return;
  9286. }
  9287. }
  9288. return;
  9289. }
  9290. /**
  9291. * @param {Array.<number>} hsla
  9292. * @return {Array.<number>} rgba
  9293. */
  9294. function hsla2rgba(hsla) {
  9295. var h = (((parseFloat(hsla[0]) % 360) + 360) % 360) / 360; // 0 .. 1
  9296. // NOTE(deanm): According to the CSS spec s/l should only be
  9297. // percentages, but we don't bother and let float or percentage.
  9298. var s = parseCssFloat(hsla[1]);
  9299. var l = parseCssFloat(hsla[2]);
  9300. var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  9301. var m1 = l * 2 - m2;
  9302. var rgba = [
  9303. clampCssByte(cssHueToRgb(m1, m2, h + 1 / 3) * 255),
  9304. clampCssByte(cssHueToRgb(m1, m2, h) * 255),
  9305. clampCssByte(cssHueToRgb(m1, m2, h - 1 / 3) * 255)
  9306. ];
  9307. if (hsla.length === 4) {
  9308. rgba[3] = hsla[3];
  9309. }
  9310. return rgba;
  9311. }
  9312. /**
  9313. * @param {Array.<number>} rgba
  9314. * @return {Array.<number>} hsla
  9315. */
  9316. function rgba2hsla(rgba) {
  9317. if (!rgba) {
  9318. return;
  9319. }
  9320. // RGB from 0 to 255
  9321. var R = rgba[0] / 255;
  9322. var G = rgba[1] / 255;
  9323. var B = rgba[2] / 255;
  9324. var vMin = Math.min(R, G, B); // Min. value of RGB
  9325. var vMax = Math.max(R, G, B); // Max. value of RGB
  9326. var delta = vMax - vMin; // Delta RGB value
  9327. var L = (vMax + vMin) / 2;
  9328. var H;
  9329. var S;
  9330. // HSL results from 0 to 1
  9331. if (delta === 0) {
  9332. H = 0;
  9333. S = 0;
  9334. }
  9335. else {
  9336. if (L < 0.5) {
  9337. S = delta / (vMax + vMin);
  9338. }
  9339. else {
  9340. S = delta / (2 - vMax - vMin);
  9341. }
  9342. var deltaR = (((vMax - R) / 6) + (delta / 2)) / delta;
  9343. var deltaG = (((vMax - G) / 6) + (delta / 2)) / delta;
  9344. var deltaB = (((vMax - B) / 6) + (delta / 2)) / delta;
  9345. if (R === vMax) {
  9346. H = deltaB - deltaG;
  9347. }
  9348. else if (G === vMax) {
  9349. H = (1 / 3) + deltaR - deltaB;
  9350. }
  9351. else if (B === vMax) {
  9352. H = (2 / 3) + deltaG - deltaR;
  9353. }
  9354. if (H < 0) {
  9355. H += 1;
  9356. }
  9357. if (H > 1) {
  9358. H -= 1;
  9359. }
  9360. }
  9361. var hsla = [H * 360, S, L];
  9362. if (rgba[3] != null) {
  9363. hsla.push(rgba[3]);
  9364. }
  9365. return hsla;
  9366. }
  9367. /**
  9368. * @param {string} color
  9369. * @param {number} level
  9370. * @return {string}
  9371. * @memberOf module:zrender/util/color
  9372. */
  9373. function lift(color, level) {
  9374. var colorArr = parse(color);
  9375. if (colorArr) {
  9376. for (var i = 0; i < 3; i++) {
  9377. if (level < 0) {
  9378. colorArr[i] = colorArr[i] * (1 - level) | 0;
  9379. }
  9380. else {
  9381. colorArr[i] = ((255 - colorArr[i]) * level + colorArr[i]) | 0;
  9382. }
  9383. }
  9384. return stringify(colorArr, colorArr.length === 4 ? 'rgba' : 'rgb');
  9385. }
  9386. }
  9387. /**
  9388. * @param {string} color
  9389. * @return {string}
  9390. * @memberOf module:zrender/util/color
  9391. */
  9392. function toHex(color, level) {
  9393. var colorArr = parse(color);
  9394. if (colorArr) {
  9395. return ((1 << 24) + (colorArr[0] << 16) + (colorArr[1] << 8) + (+colorArr[2])).toString(16).slice(1);
  9396. }
  9397. }
  9398. /**
  9399. * Map value to color. Faster than mapToColor methods because color is represented by rgba array
  9400. * @param {number} normalizedValue A float between 0 and 1.
  9401. * @param {Array.<Array.<number>>} colors List of rgba color array
  9402. * @param {Array.<number>} [out] Mapped gba color array
  9403. * @return {Array.<number>}
  9404. */
  9405. function fastMapToColor(normalizedValue, colors, out) {
  9406. if (!(colors && colors.length)
  9407. || !(normalizedValue >= 0 && normalizedValue <= 1)
  9408. ) {
  9409. return;
  9410. }
  9411. out = out || [0, 0, 0, 0];
  9412. var value = normalizedValue * (colors.length - 1);
  9413. var leftIndex = Math.floor(value);
  9414. var rightIndex = Math.ceil(value);
  9415. var leftColor = colors[leftIndex];
  9416. var rightColor = colors[rightIndex];
  9417. var dv = value - leftIndex;
  9418. out[0] = clampCssByte(lerp(leftColor[0], rightColor[0], dv));
  9419. out[1] = clampCssByte(lerp(leftColor[1], rightColor[1], dv));
  9420. out[2] = clampCssByte(lerp(leftColor[2], rightColor[2], dv));
  9421. out[3] = clampCssByte(lerp(leftColor[3], rightColor[3], dv));
  9422. return out;
  9423. }
  9424. /**
  9425. * @param {number} normalizedValue A float between 0 and 1.
  9426. * @param {Array.<string>} colors Color list.
  9427. * @param {boolean=} fullOutput Default false.
  9428. * @return {(string|Object)} Result color. If fullOutput,
  9429. * return {color: ..., leftIndex: ..., rightIndex: ..., value: ...},
  9430. * @memberOf module:zrender/util/color
  9431. */
  9432. function mapToColor(normalizedValue, colors, fullOutput) {
  9433. if (!(colors && colors.length)
  9434. || !(normalizedValue >= 0 && normalizedValue <= 1)
  9435. ) {
  9436. return;
  9437. }
  9438. var value = normalizedValue * (colors.length - 1);
  9439. var leftIndex = Math.floor(value);
  9440. var rightIndex = Math.ceil(value);
  9441. var leftColor = parse(colors[leftIndex]);
  9442. var rightColor = parse(colors[rightIndex]);
  9443. var dv = value - leftIndex;
  9444. var color = stringify(
  9445. [
  9446. clampCssByte(lerp(leftColor[0], rightColor[0], dv)),
  9447. clampCssByte(lerp(leftColor[1], rightColor[1], dv)),
  9448. clampCssByte(lerp(leftColor[2], rightColor[2], dv)),
  9449. clampCssFloat(lerp(leftColor[3], rightColor[3], dv))
  9450. ],
  9451. 'rgba'
  9452. );
  9453. return fullOutput
  9454. ? {
  9455. color: color,
  9456. leftIndex: leftIndex,
  9457. rightIndex: rightIndex,
  9458. value: value
  9459. }
  9460. : color;
  9461. }
  9462. /**
  9463. * @param {string} color
  9464. * @param {number=} h 0 ~ 360, ignore when null.
  9465. * @param {number=} s 0 ~ 1, ignore when null.
  9466. * @param {number=} l 0 ~ 1, ignore when null.
  9467. * @return {string} Color string in rgba format.
  9468. * @memberOf module:zrender/util/color
  9469. */
  9470. function modifyHSL(color, h, s, l) {
  9471. color = parse(color);
  9472. if (color) {
  9473. color = rgba2hsla(color);
  9474. h != null && (color[0] = clampCssAngle(h));
  9475. s != null && (color[1] = parseCssFloat(s));
  9476. l != null && (color[2] = parseCssFloat(l));
  9477. return stringify(hsla2rgba(color), 'rgba');
  9478. }
  9479. }
  9480. /**
  9481. * @param {string} color
  9482. * @param {number=} alpha 0 ~ 1
  9483. * @return {string} Color string in rgba format.
  9484. * @memberOf module:zrender/util/color
  9485. */
  9486. function modifyAlpha(color, alpha) {
  9487. color = parse(color);
  9488. if (color && alpha != null) {
  9489. color[3] = clampCssFloat(alpha);
  9490. return stringify(color, 'rgba');
  9491. }
  9492. }
  9493. /**
  9494. * @param {Array.<string>} colors Color list.
  9495. * @param {string} type 'rgba', 'hsva', ...
  9496. * @return {string} Result color.
  9497. */
  9498. function stringify(arrColor, type) {
  9499. var colorStr = arrColor[0] + ',' + arrColor[1] + ',' + arrColor[2];
  9500. if (type === 'rgba' || type === 'hsva' || type === 'hsla') {
  9501. colorStr += ',' + arrColor[3];
  9502. }
  9503. return type + '(' + colorStr + ')';
  9504. }
  9505. module.exports = {
  9506. parse: parse,
  9507. lift: lift,
  9508. toHex: toHex,
  9509. fastMapToColor: fastMapToColor,
  9510. mapToColor: mapToColor,
  9511. modifyHSL: modifyHSL,
  9512. modifyAlpha: modifyAlpha,
  9513. stringify: stringify
  9514. };
  9515. /***/ },
  9516. /* 40 */
  9517. /***/ function(module, exports, __webpack_require__) {
  9518. var config = __webpack_require__(41);
  9519. /**
  9520. * @exports zrender/tool/log
  9521. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  9522. */
  9523. module.exports = function() {
  9524. if (config.debugMode === 0) {
  9525. return;
  9526. }
  9527. else if (config.debugMode == 1) {
  9528. for (var k in arguments) {
  9529. throw new Error(arguments[k]);
  9530. }
  9531. }
  9532. else if (config.debugMode > 1) {
  9533. for (var k in arguments) {
  9534. console.log(arguments[k]);
  9535. }
  9536. }
  9537. };
  9538. /* for debug
  9539. return function(mes) {
  9540. document.getElementById('wrong-message').innerHTML =
  9541. mes + ' ' + (new Date() - 0)
  9542. + '<br/>'
  9543. + document.getElementById('wrong-message').innerHTML;
  9544. };
  9545. */
  9546. /***/ },
  9547. /* 41 */
  9548. /***/ function(module, exports) {
  9549. var dpr = 1;
  9550. // If in browser environment
  9551. if (typeof window !== 'undefined') {
  9552. dpr = Math.max(window.devicePixelRatio || 1, 1);
  9553. }
  9554. /**
  9555. * config默认配置项
  9556. * @exports zrender/config
  9557. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  9558. */
  9559. var config = {
  9560. /**
  9561. * debug日志选项:catchBrushException为true下有效
  9562. * 0 : 不生成debug数据,发布用
  9563. * 1 : 异常抛出,调试用
  9564. * 2 : 控制台输出,调试用
  9565. */
  9566. debugMode: 0,
  9567. // retina 屏幕优化
  9568. devicePixelRatio: dpr
  9569. };
  9570. module.exports = config;
  9571. /***/ },
  9572. /* 42 */
  9573. /***/ function(module, exports, __webpack_require__) {
  9574. var Group = __webpack_require__(30);
  9575. var componentUtil = __webpack_require__(20);
  9576. var clazzUtil = __webpack_require__(13);
  9577. var modelUtil = __webpack_require__(5);
  9578. var zrUtil = __webpack_require__(4);
  9579. function Chart() {
  9580. /**
  9581. * @type {module:zrender/container/Group}
  9582. * @readOnly
  9583. */
  9584. this.group = new Group();
  9585. /**
  9586. * @type {string}
  9587. * @readOnly
  9588. */
  9589. this.uid = componentUtil.getUID('viewChart');
  9590. }
  9591. Chart.prototype = {
  9592. type: 'chart',
  9593. /**
  9594. * Init the chart
  9595. * @param {module:echarts/model/Global} ecModel
  9596. * @param {module:echarts/ExtensionAPI} api
  9597. */
  9598. init: function (ecModel, api) {},
  9599. /**
  9600. * Render the chart
  9601. * @param {module:echarts/model/Series} seriesModel
  9602. * @param {module:echarts/model/Global} ecModel
  9603. * @param {module:echarts/ExtensionAPI} api
  9604. * @param {Object} payload
  9605. */
  9606. render: function (seriesModel, ecModel, api, payload) {},
  9607. /**
  9608. * Highlight series or specified data item
  9609. * @param {module:echarts/model/Series} seriesModel
  9610. * @param {module:echarts/model/Global} ecModel
  9611. * @param {module:echarts/ExtensionAPI} api
  9612. * @param {Object} payload
  9613. */
  9614. highlight: function (seriesModel, ecModel, api, payload) {
  9615. toggleHighlight(seriesModel.getData(), payload, 'emphasis');
  9616. },
  9617. /**
  9618. * Downplay series or specified data item
  9619. * @param {module:echarts/model/Series} seriesModel
  9620. * @param {module:echarts/model/Global} ecModel
  9621. * @param {module:echarts/ExtensionAPI} api
  9622. * @param {Object} payload
  9623. */
  9624. downplay: function (seriesModel, ecModel, api, payload) {
  9625. toggleHighlight(seriesModel.getData(), payload, 'normal');
  9626. },
  9627. /**
  9628. * Remove self
  9629. * @param {module:echarts/model/Global} ecModel
  9630. * @param {module:echarts/ExtensionAPI} api
  9631. */
  9632. remove: function (ecModel, api) {
  9633. this.group.removeAll();
  9634. },
  9635. /**
  9636. * Dispose self
  9637. * @param {module:echarts/model/Global} ecModel
  9638. * @param {module:echarts/ExtensionAPI} api
  9639. */
  9640. dispose: function () {}
  9641. /**
  9642. * The view contains the given point.
  9643. * @interface
  9644. * @param {Array.<number>} point
  9645. * @return {boolean}
  9646. */
  9647. // containPoint: function () {}
  9648. };
  9649. var chartProto = Chart.prototype;
  9650. chartProto.updateView
  9651. = chartProto.updateLayout
  9652. = chartProto.updateVisual
  9653. = function (seriesModel, ecModel, api, payload) {
  9654. this.render(seriesModel, ecModel, api, payload);
  9655. };
  9656. /**
  9657. * Set state of single element
  9658. * @param {module:zrender/Element} el
  9659. * @param {string} state
  9660. */
  9661. function elSetState(el, state) {
  9662. if (el) {
  9663. el.trigger(state);
  9664. if (el.type === 'group') {
  9665. for (var i = 0; i < el.childCount(); i++) {
  9666. elSetState(el.childAt(i), state);
  9667. }
  9668. }
  9669. }
  9670. }
  9671. /**
  9672. * @param {module:echarts/data/List} data
  9673. * @param {Object} payload
  9674. * @param {string} state 'normal'|'emphasis'
  9675. * @inner
  9676. */
  9677. function toggleHighlight(data, payload, state) {
  9678. var dataIndex = modelUtil.queryDataIndex(data, payload);
  9679. if (dataIndex != null) {
  9680. zrUtil.each(modelUtil.normalizeToArray(dataIndex), function (dataIdx) {
  9681. elSetState(data.getItemGraphicEl(dataIdx), state);
  9682. });
  9683. }
  9684. else {
  9685. data.eachItemGraphicEl(function (el) {
  9686. elSetState(el, state);
  9687. });
  9688. }
  9689. }
  9690. // Enable Chart.extend.
  9691. clazzUtil.enableClassExtend(Chart, ['dispose']);
  9692. // Add capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  9693. clazzUtil.enableClassManagement(Chart, {registerWhenExtend: true});
  9694. module.exports = Chart;
  9695. /***/ },
  9696. /* 43 */
  9697. /***/ function(module, exports, __webpack_require__) {
  9698. 'use strict';
  9699. var zrUtil = __webpack_require__(4);
  9700. var pathTool = __webpack_require__(44);
  9701. var round = Math.round;
  9702. var Path = __webpack_require__(45);
  9703. var colorTool = __webpack_require__(39);
  9704. var matrix = __webpack_require__(11);
  9705. var vector = __webpack_require__(10);
  9706. var graphic = {};
  9707. graphic.Group = __webpack_require__(30);
  9708. graphic.Image = __webpack_require__(61);
  9709. graphic.Text = __webpack_require__(63);
  9710. graphic.Circle = __webpack_require__(64);
  9711. graphic.Sector = __webpack_require__(65);
  9712. graphic.Ring = __webpack_require__(66);
  9713. graphic.Polygon = __webpack_require__(67);
  9714. graphic.Polyline = __webpack_require__(71);
  9715. graphic.Rect = __webpack_require__(72);
  9716. graphic.Line = __webpack_require__(74);
  9717. graphic.BezierCurve = __webpack_require__(75);
  9718. graphic.Arc = __webpack_require__(76);
  9719. graphic.CompoundPath = __webpack_require__(77);
  9720. graphic.LinearGradient = __webpack_require__(78);
  9721. graphic.RadialGradient = __webpack_require__(80);
  9722. graphic.BoundingRect = __webpack_require__(9);
  9723. /**
  9724. * Extend shape with parameters
  9725. */
  9726. graphic.extendShape = function (opts) {
  9727. return Path.extend(opts);
  9728. };
  9729. /**
  9730. * Extend path
  9731. */
  9732. graphic.extendPath = function (pathData, opts) {
  9733. return pathTool.extendFromString(pathData, opts);
  9734. };
  9735. /**
  9736. * Create a path element from path data string
  9737. * @param {string} pathData
  9738. * @param {Object} opts
  9739. * @param {module:zrender/core/BoundingRect} rect
  9740. * @param {string} [layout=cover] 'center' or 'cover'
  9741. */
  9742. graphic.makePath = function (pathData, opts, rect, layout) {
  9743. var path = pathTool.createFromString(pathData, opts);
  9744. var boundingRect = path.getBoundingRect();
  9745. if (rect) {
  9746. var aspect = boundingRect.width / boundingRect.height;
  9747. if (layout === 'center') {
  9748. // Set rect to center, keep width / height ratio.
  9749. var width = rect.height * aspect;
  9750. var height;
  9751. if (width <= rect.width) {
  9752. height = rect.height;
  9753. }
  9754. else {
  9755. width = rect.width;
  9756. height = width / aspect;
  9757. }
  9758. var cx = rect.x + rect.width / 2;
  9759. var cy = rect.y + rect.height / 2;
  9760. rect.x = cx - width / 2;
  9761. rect.y = cy - height / 2;
  9762. rect.width = width;
  9763. rect.height = height;
  9764. }
  9765. graphic.resizePath(path, rect);
  9766. }
  9767. return path;
  9768. };
  9769. graphic.mergePath = pathTool.mergePath,
  9770. /**
  9771. * Resize a path to fit the rect
  9772. * @param {module:zrender/graphic/Path} path
  9773. * @param {Object} rect
  9774. */
  9775. graphic.resizePath = function (path, rect) {
  9776. if (!path.applyTransform) {
  9777. return;
  9778. }
  9779. var pathRect = path.getBoundingRect();
  9780. var m = pathRect.calculateTransform(rect);
  9781. path.applyTransform(m);
  9782. };
  9783. /**
  9784. * Sub pixel optimize line for canvas
  9785. *
  9786. * @param {Object} param
  9787. * @param {Object} [param.shape]
  9788. * @param {number} [param.shape.x1]
  9789. * @param {number} [param.shape.y1]
  9790. * @param {number} [param.shape.x2]
  9791. * @param {number} [param.shape.y2]
  9792. * @param {Object} [param.style]
  9793. * @param {number} [param.style.lineWidth]
  9794. * @return {Object} Modified param
  9795. */
  9796. graphic.subPixelOptimizeLine = function (param) {
  9797. var subPixelOptimize = graphic.subPixelOptimize;
  9798. var shape = param.shape;
  9799. var lineWidth = param.style.lineWidth;
  9800. if (round(shape.x1 * 2) === round(shape.x2 * 2)) {
  9801. shape.x1 = shape.x2 = subPixelOptimize(shape.x1, lineWidth, true);
  9802. }
  9803. if (round(shape.y1 * 2) === round(shape.y2 * 2)) {
  9804. shape.y1 = shape.y2 = subPixelOptimize(shape.y1, lineWidth, true);
  9805. }
  9806. return param;
  9807. };
  9808. /**
  9809. * Sub pixel optimize rect for canvas
  9810. *
  9811. * @param {Object} param
  9812. * @param {Object} [param.shape]
  9813. * @param {number} [param.shape.x]
  9814. * @param {number} [param.shape.y]
  9815. * @param {number} [param.shape.width]
  9816. * @param {number} [param.shape.height]
  9817. * @param {Object} [param.style]
  9818. * @param {number} [param.style.lineWidth]
  9819. * @return {Object} Modified param
  9820. */
  9821. graphic.subPixelOptimizeRect = function (param) {
  9822. var subPixelOptimize = graphic.subPixelOptimize;
  9823. var shape = param.shape;
  9824. var lineWidth = param.style.lineWidth;
  9825. var originX = shape.x;
  9826. var originY = shape.y;
  9827. var originWidth = shape.width;
  9828. var originHeight = shape.height;
  9829. shape.x = subPixelOptimize(shape.x, lineWidth, true);
  9830. shape.y = subPixelOptimize(shape.y, lineWidth, true);
  9831. shape.width = Math.max(
  9832. subPixelOptimize(originX + originWidth, lineWidth, false) - shape.x,
  9833. originWidth === 0 ? 0 : 1
  9834. );
  9835. shape.height = Math.max(
  9836. subPixelOptimize(originY + originHeight, lineWidth, false) - shape.y,
  9837. originHeight === 0 ? 0 : 1
  9838. );
  9839. return param;
  9840. };
  9841. /**
  9842. * Sub pixel optimize for canvas
  9843. *
  9844. * @param {number} position Coordinate, such as x, y
  9845. * @param {number} lineWidth Should be nonnegative integer.
  9846. * @param {boolean=} positiveOrNegative Default false (negative).
  9847. * @return {number} Optimized position.
  9848. */
  9849. graphic.subPixelOptimize = function (position, lineWidth, positiveOrNegative) {
  9850. // Assure that (position + lineWidth / 2) is near integer edge,
  9851. // otherwise line will be fuzzy in canvas.
  9852. var doubledPosition = round(position * 2);
  9853. return (doubledPosition + round(lineWidth)) % 2 === 0
  9854. ? doubledPosition / 2
  9855. : (doubledPosition + (positiveOrNegative ? 1 : -1)) / 2;
  9856. };
  9857. function hasFillOrStroke(fillOrStroke) {
  9858. return fillOrStroke != null && fillOrStroke != 'none';
  9859. }
  9860. function liftColor(color) {
  9861. return typeof color === 'string' ? colorTool.lift(color, -0.1) : color;
  9862. }
  9863. /**
  9864. * @private
  9865. */
  9866. function cacheElementStl(el) {
  9867. if (el.__hoverStlDirty) {
  9868. var stroke = el.style.stroke;
  9869. var fill = el.style.fill;
  9870. // Create hoverStyle on mouseover
  9871. var hoverStyle = el.__hoverStl;
  9872. hoverStyle.fill = hoverStyle.fill
  9873. || (hasFillOrStroke(fill) ? liftColor(fill) : null);
  9874. hoverStyle.stroke = hoverStyle.stroke
  9875. || (hasFillOrStroke(stroke) ? liftColor(stroke) : null);
  9876. var normalStyle = {};
  9877. for (var name in hoverStyle) {
  9878. if (hoverStyle.hasOwnProperty(name)) {
  9879. normalStyle[name] = el.style[name];
  9880. }
  9881. }
  9882. el.__normalStl = normalStyle;
  9883. el.__hoverStlDirty = false;
  9884. }
  9885. }
  9886. /**
  9887. * @private
  9888. */
  9889. function doSingleEnterHover(el) {
  9890. if (el.__isHover) {
  9891. return;
  9892. }
  9893. cacheElementStl(el);
  9894. if (el.useHoverLayer) {
  9895. el.__zr && el.__zr.addHover(el, el.__hoverStl);
  9896. }
  9897. else {
  9898. el.setStyle(el.__hoverStl);
  9899. el.z2 += 1;
  9900. }
  9901. el.__isHover = true;
  9902. }
  9903. /**
  9904. * @inner
  9905. */
  9906. function doSingleLeaveHover(el) {
  9907. if (!el.__isHover) {
  9908. return;
  9909. }
  9910. var normalStl = el.__normalStl;
  9911. if (el.useHoverLayer) {
  9912. el.__zr && el.__zr.removeHover(el);
  9913. }
  9914. else {
  9915. normalStl && el.setStyle(normalStl);
  9916. el.z2 -= 1;
  9917. }
  9918. el.__isHover = false;
  9919. }
  9920. /**
  9921. * @inner
  9922. */
  9923. function doEnterHover(el) {
  9924. el.type === 'group'
  9925. ? el.traverse(function (child) {
  9926. if (child.type !== 'group') {
  9927. doSingleEnterHover(child);
  9928. }
  9929. })
  9930. : doSingleEnterHover(el);
  9931. }
  9932. function doLeaveHover(el) {
  9933. el.type === 'group'
  9934. ? el.traverse(function (child) {
  9935. if (child.type !== 'group') {
  9936. doSingleLeaveHover(child);
  9937. }
  9938. })
  9939. : doSingleLeaveHover(el);
  9940. }
  9941. /**
  9942. * @inner
  9943. */
  9944. function setElementHoverStl(el, hoverStl) {
  9945. // If element has sepcified hoverStyle, then use it instead of given hoverStyle
  9946. // Often used when item group has a label element and it's hoverStyle is different
  9947. el.__hoverStl = el.hoverStyle || hoverStl || {};
  9948. el.__hoverStlDirty = true;
  9949. if (el.__isHover) {
  9950. cacheElementStl(el);
  9951. }
  9952. }
  9953. /**
  9954. * @inner
  9955. */
  9956. function onElementMouseOver(e) {
  9957. if (this.__hoverSilentOnTouch && e.zrByTouch) {
  9958. return;
  9959. }
  9960. // Only if element is not in emphasis status
  9961. !this.__isEmphasis && doEnterHover(this);
  9962. }
  9963. /**
  9964. * @inner
  9965. */
  9966. function onElementMouseOut(e) {
  9967. if (this.__hoverSilentOnTouch && e.zrByTouch) {
  9968. return;
  9969. }
  9970. // Only if element is not in emphasis status
  9971. !this.__isEmphasis && doLeaveHover(this);
  9972. }
  9973. /**
  9974. * @inner
  9975. */
  9976. function enterEmphasis() {
  9977. this.__isEmphasis = true;
  9978. doEnterHover(this);
  9979. }
  9980. /**
  9981. * @inner
  9982. */
  9983. function leaveEmphasis() {
  9984. this.__isEmphasis = false;
  9985. doLeaveHover(this);
  9986. }
  9987. /**
  9988. * Set hover style of element
  9989. * @param {module:zrender/Element} el
  9990. * @param {Object} [hoverStyle]
  9991. * @param {Object} [opt]
  9992. * @param {boolean} [opt.hoverSilentOnTouch=false]
  9993. * In touch device, mouseover event will be trigger on touchstart event
  9994. * (see module:zrender/dom/HandlerProxy). By this mechanism, we can
  9995. * conviniently use hoverStyle when tap on touch screen without additional
  9996. * code for compatibility.
  9997. * But if the chart/component has select feature, which usually also use
  9998. * hoverStyle, there might be conflict between 'select-highlight' and
  9999. * 'hover-highlight' especially when roam is enabled (see geo for example).
  10000. * In this case, hoverSilentOnTouch should be used to disable hover-highlight
  10001. * on touch device.
  10002. */
  10003. graphic.setHoverStyle = function (el, hoverStyle, opt) {
  10004. el.__hoverSilentOnTouch = opt && opt.hoverSilentOnTouch;
  10005. el.type === 'group'
  10006. ? el.traverse(function (child) {
  10007. if (child.type !== 'group') {
  10008. setElementHoverStl(child, hoverStyle);
  10009. }
  10010. })
  10011. : setElementHoverStl(el, hoverStyle);
  10012. // Duplicated function will be auto-ignored, see Eventful.js.
  10013. el.on('mouseover', onElementMouseOver)
  10014. .on('mouseout', onElementMouseOut);
  10015. // Emphasis, normal can be triggered manually
  10016. el.on('emphasis', enterEmphasis)
  10017. .on('normal', leaveEmphasis);
  10018. };
  10019. /**
  10020. * Set text option in the style
  10021. * @param {Object} textStyle
  10022. * @param {module:echarts/model/Model} labelModel
  10023. * @param {string} color
  10024. */
  10025. graphic.setText = function (textStyle, labelModel, color) {
  10026. var labelPosition = labelModel.getShallow('position') || 'inside';
  10027. var labelOffset = labelModel.getShallow('offset');
  10028. var labelColor = labelPosition.indexOf('inside') >= 0 ? 'white' : color;
  10029. var textStyleModel = labelModel.getModel('textStyle');
  10030. zrUtil.extend(textStyle, {
  10031. textDistance: labelModel.getShallow('distance') || 5,
  10032. textFont: textStyleModel.getFont(),
  10033. textPosition: labelPosition,
  10034. textOffset: labelOffset,
  10035. textFill: textStyleModel.getTextColor() || labelColor
  10036. });
  10037. };
  10038. function animateOrSetProps(isUpdate, el, props, animatableModel, dataIndex, cb) {
  10039. if (typeof dataIndex === 'function') {
  10040. cb = dataIndex;
  10041. dataIndex = null;
  10042. }
  10043. // Do not check 'animation' property directly here. Consider this case:
  10044. // animation model is an `itemModel`, whose does not have `isAnimationEnabled`
  10045. // but its parent model (`seriesModel`) does.
  10046. var animationEnabled = animatableModel && animatableModel.isAnimationEnabled();
  10047. if (animationEnabled) {
  10048. var postfix = isUpdate ? 'Update' : '';
  10049. var duration = animatableModel.getShallow('animationDuration' + postfix);
  10050. var animationEasing = animatableModel.getShallow('animationEasing' + postfix);
  10051. var animationDelay = animatableModel.getShallow('animationDelay' + postfix);
  10052. if (typeof animationDelay === 'function') {
  10053. animationDelay = animationDelay(
  10054. dataIndex,
  10055. animatableModel.getAnimationDelayParams
  10056. ? animatableModel.getAnimationDelayParams(el, dataIndex)
  10057. : null
  10058. );
  10059. }
  10060. if (typeof duration === 'function') {
  10061. duration = duration(dataIndex);
  10062. }
  10063. duration > 0
  10064. ? el.animateTo(props, duration, animationDelay || 0, animationEasing, cb)
  10065. : (el.attr(props), cb && cb());
  10066. }
  10067. else {
  10068. el.attr(props);
  10069. cb && cb();
  10070. }
  10071. }
  10072. /**
  10073. * Update graphic element properties with or without animation according to the configuration in series
  10074. * @param {module:zrender/Element} el
  10075. * @param {Object} props
  10076. * @param {module:echarts/model/Model} [animatableModel]
  10077. * @param {number} [dataIndex]
  10078. * @param {Function} [cb]
  10079. * @example
  10080. * graphic.updateProps(el, {
  10081. * position: [100, 100]
  10082. * }, seriesModel, dataIndex, function () { console.log('Animation done!'); });
  10083. * // Or
  10084. * graphic.updateProps(el, {
  10085. * position: [100, 100]
  10086. * }, seriesModel, function () { console.log('Animation done!'); });
  10087. */
  10088. graphic.updateProps = function (el, props, animatableModel, dataIndex, cb) {
  10089. animateOrSetProps(true, el, props, animatableModel, dataIndex, cb);
  10090. };
  10091. /**
  10092. * Init graphic element properties with or without animation according to the configuration in series
  10093. * @param {module:zrender/Element} el
  10094. * @param {Object} props
  10095. * @param {module:echarts/model/Model} [animatableModel]
  10096. * @param {number} [dataIndex]
  10097. * @param {Function} cb
  10098. */
  10099. graphic.initProps = function (el, props, animatableModel, dataIndex, cb) {
  10100. animateOrSetProps(false, el, props, animatableModel, dataIndex, cb);
  10101. };
  10102. /**
  10103. * Get transform matrix of target (param target),
  10104. * in coordinate of its ancestor (param ancestor)
  10105. *
  10106. * @param {module:zrender/mixin/Transformable} target
  10107. * @param {module:zrender/mixin/Transformable} [ancestor]
  10108. */
  10109. graphic.getTransform = function (target, ancestor) {
  10110. var mat = matrix.identity([]);
  10111. while (target && target !== ancestor) {
  10112. matrix.mul(mat, target.getLocalTransform(), mat);
  10113. target = target.parent;
  10114. }
  10115. return mat;
  10116. };
  10117. /**
  10118. * Apply transform to an vertex.
  10119. * @param {Array.<number>} vertex [x, y]
  10120. * @param {Array.<number>} transform Transform matrix: like [1, 0, 0, 1, 0, 0]
  10121. * @param {boolean=} invert Whether use invert matrix.
  10122. * @return {Array.<number>} [x, y]
  10123. */
  10124. graphic.applyTransform = function (vertex, transform, invert) {
  10125. if (invert) {
  10126. transform = matrix.invert([], transform);
  10127. }
  10128. return vector.applyTransform([], vertex, transform);
  10129. };
  10130. /**
  10131. * @param {string} direction 'left' 'right' 'top' 'bottom'
  10132. * @param {Array.<number>} transform Transform matrix: like [1, 0, 0, 1, 0, 0]
  10133. * @param {boolean=} invert Whether use invert matrix.
  10134. * @return {string} Transformed direction. 'left' 'right' 'top' 'bottom'
  10135. */
  10136. graphic.transformDirection = function (direction, transform, invert) {
  10137. // Pick a base, ensure that transform result will not be (0, 0).
  10138. var hBase = (transform[4] === 0 || transform[5] === 0 || transform[0] === 0)
  10139. ? 1 : Math.abs(2 * transform[4] / transform[0]);
  10140. var vBase = (transform[4] === 0 || transform[5] === 0 || transform[2] === 0)
  10141. ? 1 : Math.abs(2 * transform[4] / transform[2]);
  10142. var vertex = [
  10143. direction === 'left' ? -hBase : direction === 'right' ? hBase : 0,
  10144. direction === 'top' ? -vBase : direction === 'bottom' ? vBase : 0
  10145. ];
  10146. vertex = graphic.applyTransform(vertex, transform, invert);
  10147. return Math.abs(vertex[0]) > Math.abs(vertex[1])
  10148. ? (vertex[0] > 0 ? 'right' : 'left')
  10149. : (vertex[1] > 0 ? 'bottom' : 'top');
  10150. };
  10151. /**
  10152. * Apply group transition animation from g1 to g2
  10153. */
  10154. graphic.groupTransition = function (g1, g2, animatableModel, cb) {
  10155. if (!g1 || !g2) {
  10156. return;
  10157. }
  10158. function getElMap(g) {
  10159. var elMap = {};
  10160. g.traverse(function (el) {
  10161. if (!el.isGroup && el.anid) {
  10162. elMap[el.anid] = el;
  10163. }
  10164. });
  10165. return elMap;
  10166. }
  10167. function getAnimatableProps(el) {
  10168. var obj = {
  10169. position: vector.clone(el.position),
  10170. rotation: el.rotation
  10171. };
  10172. if (el.shape) {
  10173. obj.shape = zrUtil.extend({}, el.shape);
  10174. }
  10175. return obj;
  10176. }
  10177. var elMap1 = getElMap(g1);
  10178. g2.traverse(function (el) {
  10179. if (!el.isGroup && el.anid) {
  10180. var oldEl = elMap1[el.anid];
  10181. if (oldEl) {
  10182. var newProp = getAnimatableProps(el);
  10183. el.attr(getAnimatableProps(oldEl));
  10184. graphic.updateProps(el, newProp, animatableModel, el.dataIndex);
  10185. }
  10186. // else {
  10187. // if (el.previousProps) {
  10188. // graphic.updateProps
  10189. // }
  10190. // }
  10191. }
  10192. });
  10193. };
  10194. module.exports = graphic;
  10195. /***/ },
  10196. /* 44 */
  10197. /***/ function(module, exports, __webpack_require__) {
  10198. var Path = __webpack_require__(45);
  10199. var PathProxy = __webpack_require__(49);
  10200. var transformPath = __webpack_require__(60);
  10201. var matrix = __webpack_require__(11);
  10202. // command chars
  10203. var cc = [
  10204. 'm', 'M', 'l', 'L', 'v', 'V', 'h', 'H', 'z', 'Z',
  10205. 'c', 'C', 'q', 'Q', 't', 'T', 's', 'S', 'a', 'A'
  10206. ];
  10207. var mathSqrt = Math.sqrt;
  10208. var mathSin = Math.sin;
  10209. var mathCos = Math.cos;
  10210. var PI = Math.PI;
  10211. var vMag = function(v) {
  10212. return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
  10213. };
  10214. var vRatio = function(u, v) {
  10215. return (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v));
  10216. };
  10217. var vAngle = function(u, v) {
  10218. return (u[0] * v[1] < u[1] * v[0] ? -1 : 1)
  10219. * Math.acos(vRatio(u, v));
  10220. };
  10221. function processArc(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg, cmd, path) {
  10222. var psi = psiDeg * (PI / 180.0);
  10223. var xp = mathCos(psi) * (x1 - x2) / 2.0
  10224. + mathSin(psi) * (y1 - y2) / 2.0;
  10225. var yp = -1 * mathSin(psi) * (x1 - x2) / 2.0
  10226. + mathCos(psi) * (y1 - y2) / 2.0;
  10227. var lambda = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry);
  10228. if (lambda > 1) {
  10229. rx *= mathSqrt(lambda);
  10230. ry *= mathSqrt(lambda);
  10231. }
  10232. var f = (fa === fs ? -1 : 1)
  10233. * mathSqrt((((rx * rx) * (ry * ry))
  10234. - ((rx * rx) * (yp * yp))
  10235. - ((ry * ry) * (xp * xp))) / ((rx * rx) * (yp * yp)
  10236. + (ry * ry) * (xp * xp))
  10237. ) || 0;
  10238. var cxp = f * rx * yp / ry;
  10239. var cyp = f * -ry * xp / rx;
  10240. var cx = (x1 + x2) / 2.0
  10241. + mathCos(psi) * cxp
  10242. - mathSin(psi) * cyp;
  10243. var cy = (y1 + y2) / 2.0
  10244. + mathSin(psi) * cxp
  10245. + mathCos(psi) * cyp;
  10246. var theta = vAngle([ 1, 0 ], [ (xp - cxp) / rx, (yp - cyp) / ry ]);
  10247. var u = [ (xp - cxp) / rx, (yp - cyp) / ry ];
  10248. var v = [ (-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry ];
  10249. var dTheta = vAngle(u, v);
  10250. if (vRatio(u, v) <= -1) {
  10251. dTheta = PI;
  10252. }
  10253. if (vRatio(u, v) >= 1) {
  10254. dTheta = 0;
  10255. }
  10256. if (fs === 0 && dTheta > 0) {
  10257. dTheta = dTheta - 2 * PI;
  10258. }
  10259. if (fs === 1 && dTheta < 0) {
  10260. dTheta = dTheta + 2 * PI;
  10261. }
  10262. path.addData(cmd, cx, cy, rx, ry, theta, dTheta, psi, fs);
  10263. }
  10264. function createPathProxyFromString(data) {
  10265. if (!data) {
  10266. return [];
  10267. }
  10268. // command string
  10269. var cs = data.replace(/-/g, ' -')
  10270. .replace(/ /g, ' ')
  10271. .replace(/ /g, ',')
  10272. .replace(/,,/g, ',');
  10273. var n;
  10274. // create pipes so that we can split the data
  10275. for (n = 0; n < cc.length; n++) {
  10276. cs = cs.replace(new RegExp(cc[n], 'g'), '|' + cc[n]);
  10277. }
  10278. // create array
  10279. var arr = cs.split('|');
  10280. // init context point
  10281. var cpx = 0;
  10282. var cpy = 0;
  10283. var path = new PathProxy();
  10284. var CMD = PathProxy.CMD;
  10285. var prevCmd;
  10286. for (n = 1; n < arr.length; n++) {
  10287. var str = arr[n];
  10288. var c = str.charAt(0);
  10289. var off = 0;
  10290. var p = str.slice(1).replace(/e,-/g, 'e-').split(',');
  10291. var cmd;
  10292. if (p.length > 0 && p[0] === '') {
  10293. p.shift();
  10294. }
  10295. for (var i = 0; i < p.length; i++) {
  10296. p[i] = parseFloat(p[i]);
  10297. }
  10298. while (off < p.length && !isNaN(p[off])) {
  10299. if (isNaN(p[0])) {
  10300. break;
  10301. }
  10302. var ctlPtx;
  10303. var ctlPty;
  10304. var rx;
  10305. var ry;
  10306. var psi;
  10307. var fa;
  10308. var fs;
  10309. var x1 = cpx;
  10310. var y1 = cpy;
  10311. // convert l, H, h, V, and v to L
  10312. switch (c) {
  10313. case 'l':
  10314. cpx += p[off++];
  10315. cpy += p[off++];
  10316. cmd = CMD.L;
  10317. path.addData(cmd, cpx, cpy);
  10318. break;
  10319. case 'L':
  10320. cpx = p[off++];
  10321. cpy = p[off++];
  10322. cmd = CMD.L;
  10323. path.addData(cmd, cpx, cpy);
  10324. break;
  10325. case 'm':
  10326. cpx += p[off++];
  10327. cpy += p[off++];
  10328. cmd = CMD.M;
  10329. path.addData(cmd, cpx, cpy);
  10330. c = 'l';
  10331. break;
  10332. case 'M':
  10333. cpx = p[off++];
  10334. cpy = p[off++];
  10335. cmd = CMD.M;
  10336. path.addData(cmd, cpx, cpy);
  10337. c = 'L';
  10338. break;
  10339. case 'h':
  10340. cpx += p[off++];
  10341. cmd = CMD.L;
  10342. path.addData(cmd, cpx, cpy);
  10343. break;
  10344. case 'H':
  10345. cpx = p[off++];
  10346. cmd = CMD.L;
  10347. path.addData(cmd, cpx, cpy);
  10348. break;
  10349. case 'v':
  10350. cpy += p[off++];
  10351. cmd = CMD.L;
  10352. path.addData(cmd, cpx, cpy);
  10353. break;
  10354. case 'V':
  10355. cpy = p[off++];
  10356. cmd = CMD.L;
  10357. path.addData(cmd, cpx, cpy);
  10358. break;
  10359. case 'C':
  10360. cmd = CMD.C;
  10361. path.addData(
  10362. cmd, p[off++], p[off++], p[off++], p[off++], p[off++], p[off++]
  10363. );
  10364. cpx = p[off - 2];
  10365. cpy = p[off - 1];
  10366. break;
  10367. case 'c':
  10368. cmd = CMD.C;
  10369. path.addData(
  10370. cmd,
  10371. p[off++] + cpx, p[off++] + cpy,
  10372. p[off++] + cpx, p[off++] + cpy,
  10373. p[off++] + cpx, p[off++] + cpy
  10374. );
  10375. cpx += p[off - 2];
  10376. cpy += p[off - 1];
  10377. break;
  10378. case 'S':
  10379. ctlPtx = cpx;
  10380. ctlPty = cpy;
  10381. var len = path.len();
  10382. var pathData = path.data;
  10383. if (prevCmd === CMD.C) {
  10384. ctlPtx += cpx - pathData[len - 4];
  10385. ctlPty += cpy - pathData[len - 3];
  10386. }
  10387. cmd = CMD.C;
  10388. x1 = p[off++];
  10389. y1 = p[off++];
  10390. cpx = p[off++];
  10391. cpy = p[off++];
  10392. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  10393. break;
  10394. case 's':
  10395. ctlPtx = cpx;
  10396. ctlPty = cpy;
  10397. var len = path.len();
  10398. var pathData = path.data;
  10399. if (prevCmd === CMD.C) {
  10400. ctlPtx += cpx - pathData[len - 4];
  10401. ctlPty += cpy - pathData[len - 3];
  10402. }
  10403. cmd = CMD.C;
  10404. x1 = cpx + p[off++];
  10405. y1 = cpy + p[off++];
  10406. cpx += p[off++];
  10407. cpy += p[off++];
  10408. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  10409. break;
  10410. case 'Q':
  10411. x1 = p[off++];
  10412. y1 = p[off++];
  10413. cpx = p[off++];
  10414. cpy = p[off++];
  10415. cmd = CMD.Q;
  10416. path.addData(cmd, x1, y1, cpx, cpy);
  10417. break;
  10418. case 'q':
  10419. x1 = p[off++] + cpx;
  10420. y1 = p[off++] + cpy;
  10421. cpx += p[off++];
  10422. cpy += p[off++];
  10423. cmd = CMD.Q;
  10424. path.addData(cmd, x1, y1, cpx, cpy);
  10425. break;
  10426. case 'T':
  10427. ctlPtx = cpx;
  10428. ctlPty = cpy;
  10429. var len = path.len();
  10430. var pathData = path.data;
  10431. if (prevCmd === CMD.Q) {
  10432. ctlPtx += cpx - pathData[len - 4];
  10433. ctlPty += cpy - pathData[len - 3];
  10434. }
  10435. cpx = p[off++];
  10436. cpy = p[off++];
  10437. cmd = CMD.Q;
  10438. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  10439. break;
  10440. case 't':
  10441. ctlPtx = cpx;
  10442. ctlPty = cpy;
  10443. var len = path.len();
  10444. var pathData = path.data;
  10445. if (prevCmd === CMD.Q) {
  10446. ctlPtx += cpx - pathData[len - 4];
  10447. ctlPty += cpy - pathData[len - 3];
  10448. }
  10449. cpx += p[off++];
  10450. cpy += p[off++];
  10451. cmd = CMD.Q;
  10452. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  10453. break;
  10454. case 'A':
  10455. rx = p[off++];
  10456. ry = p[off++];
  10457. psi = p[off++];
  10458. fa = p[off++];
  10459. fs = p[off++];
  10460. x1 = cpx, y1 = cpy;
  10461. cpx = p[off++];
  10462. cpy = p[off++];
  10463. cmd = CMD.A;
  10464. processArc(
  10465. x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path
  10466. );
  10467. break;
  10468. case 'a':
  10469. rx = p[off++];
  10470. ry = p[off++];
  10471. psi = p[off++];
  10472. fa = p[off++];
  10473. fs = p[off++];
  10474. x1 = cpx, y1 = cpy;
  10475. cpx += p[off++];
  10476. cpy += p[off++];
  10477. cmd = CMD.A;
  10478. processArc(
  10479. x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path
  10480. );
  10481. break;
  10482. }
  10483. }
  10484. if (c === 'z' || c === 'Z') {
  10485. cmd = CMD.Z;
  10486. path.addData(cmd);
  10487. }
  10488. prevCmd = cmd;
  10489. }
  10490. path.toStatic();
  10491. return path;
  10492. }
  10493. // TODO Optimize double memory cost problem
  10494. function createPathOptions(str, opts) {
  10495. var pathProxy = createPathProxyFromString(str);
  10496. var transform;
  10497. opts = opts || {};
  10498. opts.buildPath = function (path) {
  10499. path.setData(pathProxy.data);
  10500. transform && transformPath(path, transform);
  10501. // Svg and vml renderer don't have context
  10502. var ctx = path.getContext();
  10503. if (ctx) {
  10504. path.rebuildPath(ctx);
  10505. }
  10506. };
  10507. opts.applyTransform = function (m) {
  10508. if (!transform) {
  10509. transform = matrix.create();
  10510. }
  10511. matrix.mul(transform, m, transform);
  10512. this.dirty(true);
  10513. };
  10514. return opts;
  10515. }
  10516. module.exports = {
  10517. /**
  10518. * Create a Path object from path string data
  10519. * http://www.w3.org/TR/SVG/paths.html#PathData
  10520. * @param {Object} opts Other options
  10521. */
  10522. createFromString: function (str, opts) {
  10523. return new Path(createPathOptions(str, opts));
  10524. },
  10525. /**
  10526. * Create a Path class from path string data
  10527. * @param {string} str
  10528. * @param {Object} opts Other options
  10529. */
  10530. extendFromString: function (str, opts) {
  10531. return Path.extend(createPathOptions(str, opts));
  10532. },
  10533. /**
  10534. * Merge multiple paths
  10535. */
  10536. // TODO Apply transform
  10537. // TODO stroke dash
  10538. // TODO Optimize double memory cost problem
  10539. mergePath: function (pathEls, opts) {
  10540. var pathList = [];
  10541. var len = pathEls.length;
  10542. for (var i = 0; i < len; i++) {
  10543. var pathEl = pathEls[i];
  10544. if (pathEl.__dirty) {
  10545. pathEl.buildPath(pathEl.path, pathEl.shape, true);
  10546. }
  10547. pathList.push(pathEl.path);
  10548. }
  10549. var pathBundle = new Path(opts);
  10550. pathBundle.buildPath = function (path) {
  10551. path.appendPath(pathList);
  10552. // Svg and vml renderer don't have context
  10553. var ctx = path.getContext();
  10554. if (ctx) {
  10555. path.rebuildPath(ctx);
  10556. }
  10557. };
  10558. return pathBundle;
  10559. }
  10560. };
  10561. /***/ },
  10562. /* 45 */
  10563. /***/ function(module, exports, __webpack_require__) {
  10564. /**
  10565. * Path element
  10566. * @module zrender/graphic/Path
  10567. */
  10568. var Displayable = __webpack_require__(46);
  10569. var zrUtil = __webpack_require__(4);
  10570. var PathProxy = __webpack_require__(49);
  10571. var pathContain = __webpack_require__(52);
  10572. var Pattern = __webpack_require__(59);
  10573. var getCanvasPattern = Pattern.prototype.getCanvasPattern;
  10574. var abs = Math.abs;
  10575. /**
  10576. * @alias module:zrender/graphic/Path
  10577. * @extends module:zrender/graphic/Displayable
  10578. * @constructor
  10579. * @param {Object} opts
  10580. */
  10581. function Path(opts) {
  10582. Displayable.call(this, opts);
  10583. /**
  10584. * @type {module:zrender/core/PathProxy}
  10585. * @readOnly
  10586. */
  10587. this.path = new PathProxy();
  10588. }
  10589. Path.prototype = {
  10590. constructor: Path,
  10591. type: 'path',
  10592. __dirtyPath: true,
  10593. strokeContainThreshold: 5,
  10594. brush: function (ctx, prevEl) {
  10595. var style = this.style;
  10596. var path = this.path;
  10597. var hasStroke = style.hasStroke();
  10598. var hasFill = style.hasFill();
  10599. var fill = style.fill;
  10600. var stroke = style.stroke;
  10601. var hasFillGradient = hasFill && !!(fill.colorStops);
  10602. var hasStrokeGradient = hasStroke && !!(stroke.colorStops);
  10603. var hasFillPattern = hasFill && !!(fill.image);
  10604. var hasStrokePattern = hasStroke && !!(stroke.image);
  10605. style.bind(ctx, this, prevEl);
  10606. this.setTransform(ctx);
  10607. if (this.__dirty) {
  10608. var rect = this.getBoundingRect();
  10609. // Update gradient because bounding rect may changed
  10610. if (hasFillGradient) {
  10611. this._fillGradient = style.getGradient(ctx, fill, rect);
  10612. }
  10613. if (hasStrokeGradient) {
  10614. this._strokeGradient = style.getGradient(ctx, stroke, rect);
  10615. }
  10616. }
  10617. // Use the gradient or pattern
  10618. if (hasFillGradient) {
  10619. // PENDING If may have affect the state
  10620. ctx.fillStyle = this._fillGradient;
  10621. }
  10622. else if (hasFillPattern) {
  10623. ctx.fillStyle = getCanvasPattern.call(fill, ctx);
  10624. }
  10625. if (hasStrokeGradient) {
  10626. ctx.strokeStyle = this._strokeGradient;
  10627. }
  10628. else if (hasStrokePattern) {
  10629. ctx.strokeStyle = getCanvasPattern.call(stroke, ctx);
  10630. }
  10631. var lineDash = style.lineDash;
  10632. var lineDashOffset = style.lineDashOffset;
  10633. var ctxLineDash = !!ctx.setLineDash;
  10634. // Update path sx, sy
  10635. var scale = this.getGlobalScale();
  10636. path.setScale(scale[0], scale[1]);
  10637. // Proxy context
  10638. // Rebuild path in following 2 cases
  10639. // 1. Path is dirty
  10640. // 2. Path needs javascript implemented lineDash stroking.
  10641. // In this case, lineDash information will not be saved in PathProxy
  10642. if (this.__dirtyPath || (
  10643. lineDash && !ctxLineDash && hasStroke
  10644. )) {
  10645. path = this.path.beginPath(ctx);
  10646. // Setting line dash before build path
  10647. if (lineDash && !ctxLineDash) {
  10648. path.setLineDash(lineDash);
  10649. path.setLineDashOffset(lineDashOffset);
  10650. }
  10651. this.buildPath(path, this.shape, false);
  10652. // Clear path dirty flag
  10653. this.__dirtyPath = false;
  10654. }
  10655. else {
  10656. // Replay path building
  10657. ctx.beginPath();
  10658. this.path.rebuildPath(ctx);
  10659. }
  10660. hasFill && path.fill(ctx);
  10661. if (lineDash && ctxLineDash) {
  10662. ctx.setLineDash(lineDash);
  10663. ctx.lineDashOffset = lineDashOffset;
  10664. }
  10665. hasStroke && path.stroke(ctx);
  10666. if (lineDash && ctxLineDash) {
  10667. // PENDING
  10668. // Remove lineDash
  10669. ctx.setLineDash([]);
  10670. }
  10671. this.restoreTransform(ctx);
  10672. // Draw rect text
  10673. if (style.text != null) {
  10674. // var rect = this.getBoundingRect();
  10675. this.drawRectText(ctx, this.getBoundingRect());
  10676. }
  10677. },
  10678. // When bundling path, some shape may decide if use moveTo to begin a new subpath or closePath
  10679. // Like in circle
  10680. buildPath: function (ctx, shapeCfg, inBundle) {},
  10681. getBoundingRect: function () {
  10682. var rect = this._rect;
  10683. var style = this.style;
  10684. var needsUpdateRect = !rect;
  10685. if (needsUpdateRect) {
  10686. var path = this.path;
  10687. if (this.__dirtyPath) {
  10688. path.beginPath();
  10689. this.buildPath(path, this.shape, false);
  10690. }
  10691. rect = path.getBoundingRect();
  10692. }
  10693. this._rect = rect;
  10694. if (style.hasStroke()) {
  10695. // Needs update rect with stroke lineWidth when
  10696. // 1. Element changes scale or lineWidth
  10697. // 2. Shape is changed
  10698. var rectWithStroke = this._rectWithStroke || (this._rectWithStroke = rect.clone());
  10699. if (this.__dirty || needsUpdateRect) {
  10700. rectWithStroke.copy(rect);
  10701. // FIXME Must after updateTransform
  10702. var w = style.lineWidth;
  10703. // PENDING, Min line width is needed when line is horizontal or vertical
  10704. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  10705. // Only add extra hover lineWidth when there are no fill
  10706. if (!style.hasFill()) {
  10707. w = Math.max(w, this.strokeContainThreshold || 4);
  10708. }
  10709. // Consider line width
  10710. // Line scale can't be 0;
  10711. if (lineScale > 1e-10) {
  10712. rectWithStroke.width += w / lineScale;
  10713. rectWithStroke.height += w / lineScale;
  10714. rectWithStroke.x -= w / lineScale / 2;
  10715. rectWithStroke.y -= w / lineScale / 2;
  10716. }
  10717. }
  10718. // Return rect with stroke
  10719. return rectWithStroke;
  10720. }
  10721. return rect;
  10722. },
  10723. contain: function (x, y) {
  10724. var localPos = this.transformCoordToLocal(x, y);
  10725. var rect = this.getBoundingRect();
  10726. var style = this.style;
  10727. x = localPos[0];
  10728. y = localPos[1];
  10729. if (rect.contain(x, y)) {
  10730. var pathData = this.path.data;
  10731. if (style.hasStroke()) {
  10732. var lineWidth = style.lineWidth;
  10733. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  10734. // Line scale can't be 0;
  10735. if (lineScale > 1e-10) {
  10736. // Only add extra hover lineWidth when there are no fill
  10737. if (!style.hasFill()) {
  10738. lineWidth = Math.max(lineWidth, this.strokeContainThreshold);
  10739. }
  10740. if (pathContain.containStroke(
  10741. pathData, lineWidth / lineScale, x, y
  10742. )) {
  10743. return true;
  10744. }
  10745. }
  10746. }
  10747. if (style.hasFill()) {
  10748. return pathContain.contain(pathData, x, y);
  10749. }
  10750. }
  10751. return false;
  10752. },
  10753. /**
  10754. * @param {boolean} dirtyPath
  10755. */
  10756. dirty: function (dirtyPath) {
  10757. if (dirtyPath == null) {
  10758. dirtyPath = true;
  10759. }
  10760. // Only mark dirty, not mark clean
  10761. if (dirtyPath) {
  10762. this.__dirtyPath = dirtyPath;
  10763. this._rect = null;
  10764. }
  10765. this.__dirty = true;
  10766. this.__zr && this.__zr.refresh();
  10767. // Used as a clipping path
  10768. if (this.__clipTarget) {
  10769. this.__clipTarget.dirty();
  10770. }
  10771. },
  10772. /**
  10773. * Alias for animate('shape')
  10774. * @param {boolean} loop
  10775. */
  10776. animateShape: function (loop) {
  10777. return this.animate('shape', loop);
  10778. },
  10779. // Overwrite attrKV
  10780. attrKV: function (key, value) {
  10781. // FIXME
  10782. if (key === 'shape') {
  10783. this.setShape(value);
  10784. this.__dirtyPath = true;
  10785. this._rect = null;
  10786. }
  10787. else {
  10788. Displayable.prototype.attrKV.call(this, key, value);
  10789. }
  10790. },
  10791. /**
  10792. * @param {Object|string} key
  10793. * @param {*} value
  10794. */
  10795. setShape: function (key, value) {
  10796. var shape = this.shape;
  10797. // Path from string may not have shape
  10798. if (shape) {
  10799. if (zrUtil.isObject(key)) {
  10800. for (var name in key) {
  10801. if (key.hasOwnProperty(name)) {
  10802. shape[name] = key[name];
  10803. }
  10804. }
  10805. }
  10806. else {
  10807. shape[key] = value;
  10808. }
  10809. this.dirty(true);
  10810. }
  10811. return this;
  10812. },
  10813. getLineScale: function () {
  10814. var m = this.transform;
  10815. // Get the line scale.
  10816. // Determinant of `m` means how much the area is enlarged by the
  10817. // transformation. So its square root can be used as a scale factor
  10818. // for width.
  10819. return m && abs(m[0] - 1) > 1e-10 && abs(m[3] - 1) > 1e-10
  10820. ? Math.sqrt(abs(m[0] * m[3] - m[2] * m[1]))
  10821. : 1;
  10822. }
  10823. };
  10824. /**
  10825. * 扩展一个 Path element, 比如星形,圆等。
  10826. * Extend a path element
  10827. * @param {Object} props
  10828. * @param {string} props.type Path type
  10829. * @param {Function} props.init Initialize
  10830. * @param {Function} props.buildPath Overwrite buildPath method
  10831. * @param {Object} [props.style] Extended default style config
  10832. * @param {Object} [props.shape] Extended default shape config
  10833. */
  10834. Path.extend = function (defaults) {
  10835. var Sub = function (opts) {
  10836. Path.call(this, opts);
  10837. if (defaults.style) {
  10838. // Extend default style
  10839. this.style.extendFrom(defaults.style, false);
  10840. }
  10841. // Extend default shape
  10842. var defaultShape = defaults.shape;
  10843. if (defaultShape) {
  10844. this.shape = this.shape || {};
  10845. var thisShape = this.shape;
  10846. for (var name in defaultShape) {
  10847. if (
  10848. ! thisShape.hasOwnProperty(name)
  10849. && defaultShape.hasOwnProperty(name)
  10850. ) {
  10851. thisShape[name] = defaultShape[name];
  10852. }
  10853. }
  10854. }
  10855. defaults.init && defaults.init.call(this, opts);
  10856. };
  10857. zrUtil.inherits(Sub, Path);
  10858. // FIXME 不能 extend position, rotation 等引用对象
  10859. for (var name in defaults) {
  10860. // Extending prototype values and methods
  10861. if (name !== 'style' && name !== 'shape') {
  10862. Sub.prototype[name] = defaults[name];
  10863. }
  10864. }
  10865. return Sub;
  10866. };
  10867. zrUtil.inherits(Path, Displayable);
  10868. module.exports = Path;
  10869. /***/ },
  10870. /* 46 */
  10871. /***/ function(module, exports, __webpack_require__) {
  10872. /**
  10873. * 可绘制的图形基类
  10874. * Base class of all displayable graphic objects
  10875. * @module zrender/graphic/Displayable
  10876. */
  10877. var zrUtil = __webpack_require__(4);
  10878. var Style = __webpack_require__(47);
  10879. var Element = __webpack_require__(31);
  10880. var RectText = __webpack_require__(48);
  10881. // var Stateful = require('./mixin/Stateful');
  10882. /**
  10883. * @alias module:zrender/graphic/Displayable
  10884. * @extends module:zrender/Element
  10885. * @extends module:zrender/graphic/mixin/RectText
  10886. */
  10887. function Displayable(opts) {
  10888. opts = opts || {};
  10889. Element.call(this, opts);
  10890. // Extend properties
  10891. for (var name in opts) {
  10892. if (
  10893. opts.hasOwnProperty(name) &&
  10894. name !== 'style'
  10895. ) {
  10896. this[name] = opts[name];
  10897. }
  10898. }
  10899. /**
  10900. * @type {module:zrender/graphic/Style}
  10901. */
  10902. this.style = new Style(opts.style);
  10903. this._rect = null;
  10904. // Shapes for cascade clipping.
  10905. this.__clipPaths = [];
  10906. // FIXME Stateful must be mixined after style is setted
  10907. // Stateful.call(this, opts);
  10908. }
  10909. Displayable.prototype = {
  10910. constructor: Displayable,
  10911. type: 'displayable',
  10912. /**
  10913. * Displayable 是否为脏,Painter 中会根据该标记判断是否需要是否需要重新绘制
  10914. * Dirty flag. From which painter will determine if this displayable object needs brush
  10915. * @name module:zrender/graphic/Displayable#__dirty
  10916. * @type {boolean}
  10917. */
  10918. __dirty: true,
  10919. /**
  10920. * 图形是否可见,为true时不绘制图形,但是仍能触发鼠标事件
  10921. * If ignore drawing of the displayable object. Mouse event will still be triggered
  10922. * @name module:/zrender/graphic/Displayable#invisible
  10923. * @type {boolean}
  10924. * @default false
  10925. */
  10926. invisible: false,
  10927. /**
  10928. * @name module:/zrender/graphic/Displayable#z
  10929. * @type {number}
  10930. * @default 0
  10931. */
  10932. z: 0,
  10933. /**
  10934. * @name module:/zrender/graphic/Displayable#z
  10935. * @type {number}
  10936. * @default 0
  10937. */
  10938. z2: 0,
  10939. /**
  10940. * z层level,决定绘画在哪层canvas中
  10941. * @name module:/zrender/graphic/Displayable#zlevel
  10942. * @type {number}
  10943. * @default 0
  10944. */
  10945. zlevel: 0,
  10946. /**
  10947. * 是否可拖拽
  10948. * @name module:/zrender/graphic/Displayable#draggable
  10949. * @type {boolean}
  10950. * @default false
  10951. */
  10952. draggable: false,
  10953. /**
  10954. * 是否正在拖拽
  10955. * @name module:/zrender/graphic/Displayable#draggable
  10956. * @type {boolean}
  10957. * @default false
  10958. */
  10959. dragging: false,
  10960. /**
  10961. * 是否相应鼠标事件
  10962. * @name module:/zrender/graphic/Displayable#silent
  10963. * @type {boolean}
  10964. * @default false
  10965. */
  10966. silent: false,
  10967. /**
  10968. * If enable culling
  10969. * @type {boolean}
  10970. * @default false
  10971. */
  10972. culling: false,
  10973. /**
  10974. * Mouse cursor when hovered
  10975. * @name module:/zrender/graphic/Displayable#cursor
  10976. * @type {string}
  10977. */
  10978. cursor: 'pointer',
  10979. /**
  10980. * If hover area is bounding rect
  10981. * @name module:/zrender/graphic/Displayable#rectHover
  10982. * @type {string}
  10983. */
  10984. rectHover: false,
  10985. /**
  10986. * Render the element progressively when the value >= 0,
  10987. * usefull for large data.
  10988. * @type {number}
  10989. */
  10990. progressive: -1,
  10991. beforeBrush: function (ctx) {},
  10992. afterBrush: function (ctx) {},
  10993. /**
  10994. * 图形绘制方法
  10995. * @param {Canvas2DRenderingContext} ctx
  10996. */
  10997. // Interface
  10998. brush: function (ctx, prevEl) {},
  10999. /**
  11000. * 获取最小包围盒
  11001. * @return {module:zrender/core/BoundingRect}
  11002. */
  11003. // Interface
  11004. getBoundingRect: function () {},
  11005. /**
  11006. * 判断坐标 x, y 是否在图形上
  11007. * If displayable element contain coord x, y
  11008. * @param {number} x
  11009. * @param {number} y
  11010. * @return {boolean}
  11011. */
  11012. contain: function (x, y) {
  11013. return this.rectContain(x, y);
  11014. },
  11015. /**
  11016. * @param {Function} cb
  11017. * @param {} context
  11018. */
  11019. traverse: function (cb, context) {
  11020. cb.call(context, this);
  11021. },
  11022. /**
  11023. * 判断坐标 x, y 是否在图形的包围盒上
  11024. * If bounding rect of element contain coord x, y
  11025. * @param {number} x
  11026. * @param {number} y
  11027. * @return {boolean}
  11028. */
  11029. rectContain: function (x, y) {
  11030. var coord = this.transformCoordToLocal(x, y);
  11031. var rect = this.getBoundingRect();
  11032. return rect.contain(coord[0], coord[1]);
  11033. },
  11034. /**
  11035. * 标记图形元素为脏,并且在下一帧重绘
  11036. * Mark displayable element dirty and refresh next frame
  11037. */
  11038. dirty: function () {
  11039. this.__dirty = true;
  11040. this._rect = null;
  11041. this.__zr && this.__zr.refresh();
  11042. },
  11043. /**
  11044. * 图形是否会触发事件
  11045. * If displayable object binded any event
  11046. * @return {boolean}
  11047. */
  11048. // TODO, 通过 bind 绑定的事件
  11049. // isSilent: function () {
  11050. // return !(
  11051. // this.hoverable || this.draggable
  11052. // || this.onmousemove || this.onmouseover || this.onmouseout
  11053. // || this.onmousedown || this.onmouseup || this.onclick
  11054. // || this.ondragenter || this.ondragover || this.ondragleave
  11055. // || this.ondrop
  11056. // );
  11057. // },
  11058. /**
  11059. * Alias for animate('style')
  11060. * @param {boolean} loop
  11061. */
  11062. animateStyle: function (loop) {
  11063. return this.animate('style', loop);
  11064. },
  11065. attrKV: function (key, value) {
  11066. if (key !== 'style') {
  11067. Element.prototype.attrKV.call(this, key, value);
  11068. }
  11069. else {
  11070. this.style.set(value);
  11071. }
  11072. },
  11073. /**
  11074. * @param {Object|string} key
  11075. * @param {*} value
  11076. */
  11077. setStyle: function (key, value) {
  11078. this.style.set(key, value);
  11079. this.dirty(false);
  11080. return this;
  11081. },
  11082. /**
  11083. * Use given style object
  11084. * @param {Object} obj
  11085. */
  11086. useStyle: function (obj) {
  11087. this.style = new Style(obj);
  11088. this.dirty(false);
  11089. return this;
  11090. }
  11091. };
  11092. zrUtil.inherits(Displayable, Element);
  11093. zrUtil.mixin(Displayable, RectText);
  11094. // zrUtil.mixin(Displayable, Stateful);
  11095. module.exports = Displayable;
  11096. /***/ },
  11097. /* 47 */
  11098. /***/ function(module, exports) {
  11099. /**
  11100. * @module zrender/graphic/Style
  11101. */
  11102. var STYLE_COMMON_PROPS = [
  11103. ['shadowBlur', 0], ['shadowOffsetX', 0], ['shadowOffsetY', 0], ['shadowColor', '#000'],
  11104. ['lineCap', 'butt'], ['lineJoin', 'miter'], ['miterLimit', 10]
  11105. ];
  11106. // var SHADOW_PROPS = STYLE_COMMON_PROPS.slice(0, 4);
  11107. // var LINE_PROPS = STYLE_COMMON_PROPS.slice(4);
  11108. var Style = function (opts) {
  11109. this.extendFrom(opts);
  11110. };
  11111. function createLinearGradient(ctx, obj, rect) {
  11112. // var size =
  11113. var x = obj.x;
  11114. var x2 = obj.x2;
  11115. var y = obj.y;
  11116. var y2 = obj.y2;
  11117. if (!obj.global) {
  11118. x = x * rect.width + rect.x;
  11119. x2 = x2 * rect.width + rect.x;
  11120. y = y * rect.height + rect.y;
  11121. y2 = y2 * rect.height + rect.y;
  11122. }
  11123. var canvasGradient = ctx.createLinearGradient(x, y, x2, y2);
  11124. return canvasGradient;
  11125. }
  11126. function createRadialGradient(ctx, obj, rect) {
  11127. var width = rect.width;
  11128. var height = rect.height;
  11129. var min = Math.min(width, height);
  11130. var x = obj.x;
  11131. var y = obj.y;
  11132. var r = obj.r;
  11133. if (!obj.global) {
  11134. x = x * width + rect.x;
  11135. y = y * height + rect.y;
  11136. r = r * min;
  11137. }
  11138. var canvasGradient = ctx.createRadialGradient(x, y, 0, x, y, r);
  11139. return canvasGradient;
  11140. }
  11141. Style.prototype = {
  11142. constructor: Style,
  11143. /**
  11144. * @type {string}
  11145. */
  11146. fill: '#000000',
  11147. /**
  11148. * @type {string}
  11149. */
  11150. stroke: null,
  11151. /**
  11152. * @type {number}
  11153. */
  11154. opacity: 1,
  11155. /**
  11156. * @type {Array.<number>}
  11157. */
  11158. lineDash: null,
  11159. /**
  11160. * @type {number}
  11161. */
  11162. lineDashOffset: 0,
  11163. /**
  11164. * @type {number}
  11165. */
  11166. shadowBlur: 0,
  11167. /**
  11168. * @type {number}
  11169. */
  11170. shadowOffsetX: 0,
  11171. /**
  11172. * @type {number}
  11173. */
  11174. shadowOffsetY: 0,
  11175. /**
  11176. * @type {number}
  11177. */
  11178. lineWidth: 1,
  11179. /**
  11180. * If stroke ignore scale
  11181. * @type {Boolean}
  11182. */
  11183. strokeNoScale: false,
  11184. // Bounding rect text configuration
  11185. // Not affected by element transform
  11186. /**
  11187. * @type {string}
  11188. */
  11189. text: null,
  11190. /**
  11191. * @type {string}
  11192. */
  11193. textFill: '#000',
  11194. /**
  11195. * @type {string}
  11196. */
  11197. textStroke: null,
  11198. /**
  11199. * 'inside', 'left', 'right', 'top', 'bottom'
  11200. * [x, y]
  11201. * @type {string|Array.<number>}
  11202. * @default 'inside'
  11203. */
  11204. textPosition: 'inside',
  11205. /**
  11206. * [x, y]
  11207. * @type {Array.<number>}
  11208. */
  11209. textOffset: null,
  11210. /**
  11211. * @type {string}
  11212. */
  11213. textBaseline: null,
  11214. /**
  11215. * @type {string}
  11216. */
  11217. textAlign: null,
  11218. /**
  11219. * @type {string}
  11220. */
  11221. textVerticalAlign: null,
  11222. /**
  11223. * Only useful in Path and Image element
  11224. * @type {number}
  11225. */
  11226. textDistance: 5,
  11227. /**
  11228. * Only useful in Path and Image element
  11229. * @type {number}
  11230. */
  11231. textShadowBlur: 0,
  11232. /**
  11233. * Only useful in Path and Image element
  11234. * @type {number}
  11235. */
  11236. textShadowOffsetX: 0,
  11237. /**
  11238. * Only useful in Path and Image element
  11239. * @type {number}
  11240. */
  11241. textShadowOffsetY: 0,
  11242. /**
  11243. * If transform text
  11244. * Only useful in Path and Image element
  11245. * @type {boolean}
  11246. */
  11247. textTransform: false,
  11248. /**
  11249. * Text rotate around position of Path or Image
  11250. * Only useful in Path and Image element and textTransform is false.
  11251. */
  11252. textRotation: 0,
  11253. /**
  11254. * @type {string}
  11255. * https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
  11256. */
  11257. blend: null,
  11258. /**
  11259. * @param {CanvasRenderingContext2D} ctx
  11260. */
  11261. bind: function (ctx, el, prevEl) {
  11262. var style = this;
  11263. var prevStyle = prevEl && prevEl.style;
  11264. var firstDraw = !prevStyle;
  11265. for (var i = 0; i < STYLE_COMMON_PROPS.length; i++) {
  11266. var prop = STYLE_COMMON_PROPS[i];
  11267. var styleName = prop[0];
  11268. if (firstDraw || style[styleName] !== prevStyle[styleName]) {
  11269. // FIXME Invalid property value will cause style leak from previous element.
  11270. ctx[styleName] = style[styleName] || prop[1];
  11271. }
  11272. }
  11273. if ((firstDraw || style.fill !== prevStyle.fill)) {
  11274. ctx.fillStyle = style.fill;
  11275. }
  11276. if ((firstDraw || style.stroke !== prevStyle.stroke)) {
  11277. ctx.strokeStyle = style.stroke;
  11278. }
  11279. if ((firstDraw || style.opacity !== prevStyle.opacity)) {
  11280. ctx.globalAlpha = style.opacity == null ? 1 : style.opacity;
  11281. }
  11282. if ((firstDraw || style.blend !== prevStyle.blend)) {
  11283. ctx.globalCompositeOperation = style.blend || 'source-over';
  11284. }
  11285. if (this.hasStroke()) {
  11286. var lineWidth = style.lineWidth;
  11287. ctx.lineWidth = lineWidth / (
  11288. (this.strokeNoScale && el && el.getLineScale) ? el.getLineScale() : 1
  11289. );
  11290. }
  11291. },
  11292. hasFill: function () {
  11293. var fill = this.fill;
  11294. return fill != null && fill !== 'none';
  11295. },
  11296. hasStroke: function () {
  11297. var stroke = this.stroke;
  11298. return stroke != null && stroke !== 'none' && this.lineWidth > 0;
  11299. },
  11300. /**
  11301. * Extend from other style
  11302. * @param {zrender/graphic/Style} otherStyle
  11303. * @param {boolean} overwrite
  11304. */
  11305. extendFrom: function (otherStyle, overwrite) {
  11306. if (otherStyle) {
  11307. var target = this;
  11308. for (var name in otherStyle) {
  11309. if (otherStyle.hasOwnProperty(name)
  11310. && (overwrite || ! target.hasOwnProperty(name))
  11311. ) {
  11312. target[name] = otherStyle[name];
  11313. }
  11314. }
  11315. }
  11316. },
  11317. /**
  11318. * Batch setting style with a given object
  11319. * @param {Object|string} obj
  11320. * @param {*} [obj]
  11321. */
  11322. set: function (obj, value) {
  11323. if (typeof obj === 'string') {
  11324. this[obj] = value;
  11325. }
  11326. else {
  11327. this.extendFrom(obj, true);
  11328. }
  11329. },
  11330. /**
  11331. * Clone
  11332. * @return {zrender/graphic/Style} [description]
  11333. */
  11334. clone: function () {
  11335. var newStyle = new this.constructor();
  11336. newStyle.extendFrom(this, true);
  11337. return newStyle;
  11338. },
  11339. getGradient: function (ctx, obj, rect) {
  11340. var method = obj.type === 'radial' ? createRadialGradient : createLinearGradient;
  11341. var canvasGradient = method(ctx, obj, rect);
  11342. var colorStops = obj.colorStops;
  11343. for (var i = 0; i < colorStops.length; i++) {
  11344. canvasGradient.addColorStop(
  11345. colorStops[i].offset, colorStops[i].color
  11346. );
  11347. }
  11348. return canvasGradient;
  11349. }
  11350. };
  11351. var styleProto = Style.prototype;
  11352. for (var i = 0; i < STYLE_COMMON_PROPS.length; i++) {
  11353. var prop = STYLE_COMMON_PROPS[i];
  11354. if (!(prop[0] in styleProto)) {
  11355. styleProto[prop[0]] = prop[1];
  11356. }
  11357. }
  11358. // Provide for others
  11359. Style.getGradient = styleProto.getGradient;
  11360. module.exports = Style;
  11361. /***/ },
  11362. /* 48 */
  11363. /***/ function(module, exports, __webpack_require__) {
  11364. /**
  11365. * Mixin for drawing text in a element bounding rect
  11366. * @module zrender/mixin/RectText
  11367. */
  11368. var textContain = __webpack_require__(8);
  11369. var BoundingRect = __webpack_require__(9);
  11370. var tmpRect = new BoundingRect();
  11371. var RectText = function () {};
  11372. function parsePercent(value, maxValue) {
  11373. if (typeof value === 'string') {
  11374. if (value.lastIndexOf('%') >= 0) {
  11375. return parseFloat(value) / 100 * maxValue;
  11376. }
  11377. return parseFloat(value);
  11378. }
  11379. return value;
  11380. }
  11381. RectText.prototype = {
  11382. constructor: RectText,
  11383. /**
  11384. * Draw text in a rect with specified position.
  11385. * @param {CanvasRenderingContext} ctx
  11386. * @param {Object} rect Displayable rect
  11387. * @return {Object} textRect Alternative precalculated text bounding rect
  11388. */
  11389. drawRectText: function (ctx, rect, textRect) {
  11390. var style = this.style;
  11391. var text = style.text;
  11392. // Convert to string
  11393. text != null && (text += '');
  11394. if (!text) {
  11395. return;
  11396. }
  11397. // FIXME
  11398. ctx.save();
  11399. var x;
  11400. var y;
  11401. var textPosition = style.textPosition;
  11402. var textOffset = style.textOffset;
  11403. var distance = style.textDistance;
  11404. var align = style.textAlign;
  11405. var font = style.textFont || style.font;
  11406. var baseline = style.textBaseline;
  11407. var verticalAlign = style.textVerticalAlign;
  11408. textRect = textRect || textContain.getBoundingRect(text, font, align, baseline);
  11409. // Transform rect to view space
  11410. var transform = this.transform;
  11411. if (!style.textTransform) {
  11412. if (transform) {
  11413. tmpRect.copy(rect);
  11414. tmpRect.applyTransform(transform);
  11415. rect = tmpRect;
  11416. }
  11417. }
  11418. else {
  11419. this.setTransform(ctx);
  11420. }
  11421. // Text position represented by coord
  11422. if (textPosition instanceof Array) {
  11423. // Percent
  11424. x = rect.x + parsePercent(textPosition[0], rect.width);
  11425. y = rect.y + parsePercent(textPosition[1], rect.height);
  11426. align = align || 'left';
  11427. baseline = baseline || 'top';
  11428. if (verticalAlign) {
  11429. switch (verticalAlign) {
  11430. case 'middle':
  11431. y -= textRect.height / 2 - textRect.lineHeight / 2;
  11432. break;
  11433. case 'bottom':
  11434. y -= textRect.height - textRect.lineHeight / 2;
  11435. break;
  11436. default:
  11437. y += textRect.lineHeight / 2;
  11438. }
  11439. // Force bseline to be middle
  11440. baseline = 'middle';
  11441. }
  11442. }
  11443. else {
  11444. var res = textContain.adjustTextPositionOnRect(
  11445. textPosition, rect, textRect, distance
  11446. );
  11447. x = res.x;
  11448. y = res.y;
  11449. // Default align and baseline when has textPosition
  11450. align = align || res.textAlign;
  11451. baseline = baseline || res.textBaseline;
  11452. }
  11453. if (textOffset) {
  11454. x += textOffset[0];
  11455. y += textOffset[1];
  11456. }
  11457. // Use canvas default left textAlign. Giving invalid value will cause state not change
  11458. ctx.textAlign = align || 'left';
  11459. // Use canvas default alphabetic baseline
  11460. ctx.textBaseline = baseline || 'alphabetic';
  11461. var textFill = style.textFill;
  11462. var textStroke = style.textStroke;
  11463. textFill && (ctx.fillStyle = textFill);
  11464. textStroke && (ctx.strokeStyle = textStroke);
  11465. // TODO Invalid font
  11466. ctx.font = font || '12px sans-serif';
  11467. // Text shadow
  11468. // Always set shadowBlur and shadowOffset to avoid leak from displayable
  11469. ctx.shadowBlur = style.textShadowBlur;
  11470. ctx.shadowColor = style.textShadowColor || 'transparent';
  11471. ctx.shadowOffsetX = style.textShadowOffsetX;
  11472. ctx.shadowOffsetY = style.textShadowOffsetY;
  11473. var textLines = text.split('\n');
  11474. if (style.textRotation) {
  11475. transform && ctx.translate(transform[4], transform[5]);
  11476. ctx.rotate(style.textRotation);
  11477. transform && ctx.translate(-transform[4], -transform[5]);
  11478. }
  11479. for (var i = 0; i < textLines.length; i++) {
  11480. textFill && ctx.fillText(textLines[i], x, y);
  11481. textStroke && ctx.strokeText(textLines[i], x, y);
  11482. y += textRect.lineHeight;
  11483. }
  11484. ctx.restore();
  11485. }
  11486. };
  11487. module.exports = RectText;
  11488. /***/ },
  11489. /* 49 */
  11490. /***/ function(module, exports, __webpack_require__) {
  11491. 'use strict';
  11492. /**
  11493. * Path 代理,可以在`buildPath`中用于替代`ctx`, 会保存每个path操作的命令到pathCommands属性中
  11494. * 可以用于 isInsidePath 判断以及获取boundingRect
  11495. *
  11496. * @module zrender/core/PathProxy
  11497. * @author Yi Shen (http://www.github.com/pissang)
  11498. */
  11499. // TODO getTotalLength, getPointAtLength
  11500. var curve = __webpack_require__(50);
  11501. var vec2 = __webpack_require__(10);
  11502. var bbox = __webpack_require__(51);
  11503. var BoundingRect = __webpack_require__(9);
  11504. var dpr = __webpack_require__(41).devicePixelRatio;
  11505. var CMD = {
  11506. M: 1,
  11507. L: 2,
  11508. C: 3,
  11509. Q: 4,
  11510. A: 5,
  11511. Z: 6,
  11512. // Rect
  11513. R: 7
  11514. };
  11515. var min = [];
  11516. var max = [];
  11517. var min2 = [];
  11518. var max2 = [];
  11519. var mathMin = Math.min;
  11520. var mathMax = Math.max;
  11521. var mathCos = Math.cos;
  11522. var mathSin = Math.sin;
  11523. var mathSqrt = Math.sqrt;
  11524. var mathAbs = Math.abs;
  11525. var hasTypedArray = typeof Float32Array != 'undefined';
  11526. /**
  11527. * @alias module:zrender/core/PathProxy
  11528. * @constructor
  11529. */
  11530. var PathProxy = function () {
  11531. /**
  11532. * Path data. Stored as flat array
  11533. * @type {Array.<Object>}
  11534. */
  11535. this.data = [];
  11536. this._len = 0;
  11537. this._ctx = null;
  11538. this._xi = 0;
  11539. this._yi = 0;
  11540. this._x0 = 0;
  11541. this._y0 = 0;
  11542. // Unit x, Unit y. Provide for avoiding drawing that too short line segment
  11543. this._ux = 0;
  11544. this._uy = 0;
  11545. };
  11546. /**
  11547. * 快速计算Path包围盒(并不是最小包围盒)
  11548. * @return {Object}
  11549. */
  11550. PathProxy.prototype = {
  11551. constructor: PathProxy,
  11552. _lineDash: null,
  11553. _dashOffset: 0,
  11554. _dashIdx: 0,
  11555. _dashSum: 0,
  11556. /**
  11557. * @readOnly
  11558. */
  11559. setScale: function (sx, sy) {
  11560. this._ux = mathAbs(1 / dpr / sx) || 0;
  11561. this._uy = mathAbs(1 / dpr / sy) || 0;
  11562. },
  11563. getContext: function () {
  11564. return this._ctx;
  11565. },
  11566. /**
  11567. * @param {CanvasRenderingContext2D} ctx
  11568. * @return {module:zrender/core/PathProxy}
  11569. */
  11570. beginPath: function (ctx) {
  11571. this._ctx = ctx;
  11572. ctx && ctx.beginPath();
  11573. ctx && (this.dpr = ctx.dpr);
  11574. // Reset
  11575. this._len = 0;
  11576. if (this._lineDash) {
  11577. this._lineDash = null;
  11578. this._dashOffset = 0;
  11579. }
  11580. return this;
  11581. },
  11582. /**
  11583. * @param {number} x
  11584. * @param {number} y
  11585. * @return {module:zrender/core/PathProxy}
  11586. */
  11587. moveTo: function (x, y) {
  11588. this.addData(CMD.M, x, y);
  11589. this._ctx && this._ctx.moveTo(x, y);
  11590. // x0, y0, xi, yi 是记录在 _dashedXXXXTo 方法中使用
  11591. // xi, yi 记录当前点, x0, y0 在 closePath 的时候回到起始点。
  11592. // 有可能在 beginPath 之后直接调用 lineTo,这时候 x0, y0 需要
  11593. // 在 lineTo 方法中记录,这里先不考虑这种情况,dashed line 也只在 IE10- 中不支持
  11594. this._x0 = x;
  11595. this._y0 = y;
  11596. this._xi = x;
  11597. this._yi = y;
  11598. return this;
  11599. },
  11600. /**
  11601. * @param {number} x
  11602. * @param {number} y
  11603. * @return {module:zrender/core/PathProxy}
  11604. */
  11605. lineTo: function (x, y) {
  11606. var exceedUnit = mathAbs(x - this._xi) > this._ux
  11607. || mathAbs(y - this._yi) > this._uy
  11608. // Force draw the first segment
  11609. || this._len < 5;
  11610. this.addData(CMD.L, x, y);
  11611. if (this._ctx && exceedUnit) {
  11612. this._needsDash() ? this._dashedLineTo(x, y)
  11613. : this._ctx.lineTo(x, y);
  11614. }
  11615. if (exceedUnit) {
  11616. this._xi = x;
  11617. this._yi = y;
  11618. }
  11619. return this;
  11620. },
  11621. /**
  11622. * @param {number} x1
  11623. * @param {number} y1
  11624. * @param {number} x2
  11625. * @param {number} y2
  11626. * @param {number} x3
  11627. * @param {number} y3
  11628. * @return {module:zrender/core/PathProxy}
  11629. */
  11630. bezierCurveTo: function (x1, y1, x2, y2, x3, y3) {
  11631. this.addData(CMD.C, x1, y1, x2, y2, x3, y3);
  11632. if (this._ctx) {
  11633. this._needsDash() ? this._dashedBezierTo(x1, y1, x2, y2, x3, y3)
  11634. : this._ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  11635. }
  11636. this._xi = x3;
  11637. this._yi = y3;
  11638. return this;
  11639. },
  11640. /**
  11641. * @param {number} x1
  11642. * @param {number} y1
  11643. * @param {number} x2
  11644. * @param {number} y2
  11645. * @return {module:zrender/core/PathProxy}
  11646. */
  11647. quadraticCurveTo: function (x1, y1, x2, y2) {
  11648. this.addData(CMD.Q, x1, y1, x2, y2);
  11649. if (this._ctx) {
  11650. this._needsDash() ? this._dashedQuadraticTo(x1, y1, x2, y2)
  11651. : this._ctx.quadraticCurveTo(x1, y1, x2, y2);
  11652. }
  11653. this._xi = x2;
  11654. this._yi = y2;
  11655. return this;
  11656. },
  11657. /**
  11658. * @param {number} cx
  11659. * @param {number} cy
  11660. * @param {number} r
  11661. * @param {number} startAngle
  11662. * @param {number} endAngle
  11663. * @param {boolean} anticlockwise
  11664. * @return {module:zrender/core/PathProxy}
  11665. */
  11666. arc: function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  11667. this.addData(
  11668. CMD.A, cx, cy, r, r, startAngle, endAngle - startAngle, 0, anticlockwise ? 0 : 1
  11669. );
  11670. this._ctx && this._ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  11671. this._xi = mathCos(endAngle) * r + cx;
  11672. this._yi = mathSin(endAngle) * r + cx;
  11673. return this;
  11674. },
  11675. // TODO
  11676. arcTo: function (x1, y1, x2, y2, radius) {
  11677. if (this._ctx) {
  11678. this._ctx.arcTo(x1, y1, x2, y2, radius);
  11679. }
  11680. return this;
  11681. },
  11682. // TODO
  11683. rect: function (x, y, w, h) {
  11684. this._ctx && this._ctx.rect(x, y, w, h);
  11685. this.addData(CMD.R, x, y, w, h);
  11686. return this;
  11687. },
  11688. /**
  11689. * @return {module:zrender/core/PathProxy}
  11690. */
  11691. closePath: function () {
  11692. this.addData(CMD.Z);
  11693. var ctx = this._ctx;
  11694. var x0 = this._x0;
  11695. var y0 = this._y0;
  11696. if (ctx) {
  11697. this._needsDash() && this._dashedLineTo(x0, y0);
  11698. ctx.closePath();
  11699. }
  11700. this._xi = x0;
  11701. this._yi = y0;
  11702. return this;
  11703. },
  11704. /**
  11705. * Context 从外部传入,因为有可能是 rebuildPath 完之后再 fill。
  11706. * stroke 同样
  11707. * @param {CanvasRenderingContext2D} ctx
  11708. * @return {module:zrender/core/PathProxy}
  11709. */
  11710. fill: function (ctx) {
  11711. ctx && ctx.fill();
  11712. this.toStatic();
  11713. },
  11714. /**
  11715. * @param {CanvasRenderingContext2D} ctx
  11716. * @return {module:zrender/core/PathProxy}
  11717. */
  11718. stroke: function (ctx) {
  11719. ctx && ctx.stroke();
  11720. this.toStatic();
  11721. },
  11722. /**
  11723. * 必须在其它绘制命令前调用
  11724. * Must be invoked before all other path drawing methods
  11725. * @return {module:zrender/core/PathProxy}
  11726. */
  11727. setLineDash: function (lineDash) {
  11728. if (lineDash instanceof Array) {
  11729. this._lineDash = lineDash;
  11730. this._dashIdx = 0;
  11731. var lineDashSum = 0;
  11732. for (var i = 0; i < lineDash.length; i++) {
  11733. lineDashSum += lineDash[i];
  11734. }
  11735. this._dashSum = lineDashSum;
  11736. }
  11737. return this;
  11738. },
  11739. /**
  11740. * 必须在其它绘制命令前调用
  11741. * Must be invoked before all other path drawing methods
  11742. * @return {module:zrender/core/PathProxy}
  11743. */
  11744. setLineDashOffset: function (offset) {
  11745. this._dashOffset = offset;
  11746. return this;
  11747. },
  11748. /**
  11749. *
  11750. * @return {boolean}
  11751. */
  11752. len: function () {
  11753. return this._len;
  11754. },
  11755. /**
  11756. * 直接设置 Path 数据
  11757. */
  11758. setData: function (data) {
  11759. var len = data.length;
  11760. if (! (this.data && this.data.length == len) && hasTypedArray) {
  11761. this.data = new Float32Array(len);
  11762. }
  11763. for (var i = 0; i < len; i++) {
  11764. this.data[i] = data[i];
  11765. }
  11766. this._len = len;
  11767. },
  11768. /**
  11769. * 添加子路径
  11770. * @param {module:zrender/core/PathProxy|Array.<module:zrender/core/PathProxy>} path
  11771. */
  11772. appendPath: function (path) {
  11773. if (!(path instanceof Array)) {
  11774. path = [path];
  11775. }
  11776. var len = path.length;
  11777. var appendSize = 0;
  11778. var offset = this._len;
  11779. for (var i = 0; i < len; i++) {
  11780. appendSize += path[i].len();
  11781. }
  11782. if (hasTypedArray && (this.data instanceof Float32Array)) {
  11783. this.data = new Float32Array(offset + appendSize);
  11784. }
  11785. for (var i = 0; i < len; i++) {
  11786. var appendPathData = path[i].data;
  11787. for (var k = 0; k < appendPathData.length; k++) {
  11788. this.data[offset++] = appendPathData[k];
  11789. }
  11790. }
  11791. this._len = offset;
  11792. },
  11793. /**
  11794. * 填充 Path 数据。
  11795. * 尽量复用而不申明新的数组。大部分图形重绘的指令数据长度都是不变的。
  11796. */
  11797. addData: function (cmd) {
  11798. var data = this.data;
  11799. if (this._len + arguments.length > data.length) {
  11800. // 因为之前的数组已经转换成静态的 Float32Array
  11801. // 所以不够用时需要扩展一个新的动态数组
  11802. this._expandData();
  11803. data = this.data;
  11804. }
  11805. for (var i = 0; i < arguments.length; i++) {
  11806. data[this._len++] = arguments[i];
  11807. }
  11808. this._prevCmd = cmd;
  11809. },
  11810. _expandData: function () {
  11811. // Only if data is Float32Array
  11812. if (!(this.data instanceof Array)) {
  11813. var newData = [];
  11814. for (var i = 0; i < this._len; i++) {
  11815. newData[i] = this.data[i];
  11816. }
  11817. this.data = newData;
  11818. }
  11819. },
  11820. /**
  11821. * If needs js implemented dashed line
  11822. * @return {boolean}
  11823. * @private
  11824. */
  11825. _needsDash: function () {
  11826. return this._lineDash;
  11827. },
  11828. _dashedLineTo: function (x1, y1) {
  11829. var dashSum = this._dashSum;
  11830. var offset = this._dashOffset;
  11831. var lineDash = this._lineDash;
  11832. var ctx = this._ctx;
  11833. var x0 = this._xi;
  11834. var y0 = this._yi;
  11835. var dx = x1 - x0;
  11836. var dy = y1 - y0;
  11837. var dist = mathSqrt(dx * dx + dy * dy);
  11838. var x = x0;
  11839. var y = y0;
  11840. var dash;
  11841. var nDash = lineDash.length;
  11842. var idx;
  11843. dx /= dist;
  11844. dy /= dist;
  11845. if (offset < 0) {
  11846. // Convert to positive offset
  11847. offset = dashSum + offset;
  11848. }
  11849. offset %= dashSum;
  11850. x -= offset * dx;
  11851. y -= offset * dy;
  11852. while ((dx > 0 && x <= x1) || (dx < 0 && x >= x1)
  11853. || (dx == 0 && ((dy > 0 && y <= y1) || (dy < 0 && y >= y1)))) {
  11854. idx = this._dashIdx;
  11855. dash = lineDash[idx];
  11856. x += dx * dash;
  11857. y += dy * dash;
  11858. this._dashIdx = (idx + 1) % nDash;
  11859. // Skip positive offset
  11860. if ((dx > 0 && x < x0) || (dx < 0 && x > x0) || (dy > 0 && y < y0) || (dy < 0 && y > y0)) {
  11861. continue;
  11862. }
  11863. ctx[idx % 2 ? 'moveTo' : 'lineTo'](
  11864. dx >= 0 ? mathMin(x, x1) : mathMax(x, x1),
  11865. dy >= 0 ? mathMin(y, y1) : mathMax(y, y1)
  11866. );
  11867. }
  11868. // Offset for next lineTo
  11869. dx = x - x1;
  11870. dy = y - y1;
  11871. this._dashOffset = -mathSqrt(dx * dx + dy * dy);
  11872. },
  11873. // Not accurate dashed line to
  11874. _dashedBezierTo: function (x1, y1, x2, y2, x3, y3) {
  11875. var dashSum = this._dashSum;
  11876. var offset = this._dashOffset;
  11877. var lineDash = this._lineDash;
  11878. var ctx = this._ctx;
  11879. var x0 = this._xi;
  11880. var y0 = this._yi;
  11881. var t;
  11882. var dx;
  11883. var dy;
  11884. var cubicAt = curve.cubicAt;
  11885. var bezierLen = 0;
  11886. var idx = this._dashIdx;
  11887. var nDash = lineDash.length;
  11888. var x;
  11889. var y;
  11890. var tmpLen = 0;
  11891. if (offset < 0) {
  11892. // Convert to positive offset
  11893. offset = dashSum + offset;
  11894. }
  11895. offset %= dashSum;
  11896. // Bezier approx length
  11897. for (t = 0; t < 1; t += 0.1) {
  11898. dx = cubicAt(x0, x1, x2, x3, t + 0.1)
  11899. - cubicAt(x0, x1, x2, x3, t);
  11900. dy = cubicAt(y0, y1, y2, y3, t + 0.1)
  11901. - cubicAt(y0, y1, y2, y3, t);
  11902. bezierLen += mathSqrt(dx * dx + dy * dy);
  11903. }
  11904. // Find idx after add offset
  11905. for (; idx < nDash; idx++) {
  11906. tmpLen += lineDash[idx];
  11907. if (tmpLen > offset) {
  11908. break;
  11909. }
  11910. }
  11911. t = (tmpLen - offset) / bezierLen;
  11912. while (t <= 1) {
  11913. x = cubicAt(x0, x1, x2, x3, t);
  11914. y = cubicAt(y0, y1, y2, y3, t);
  11915. // Use line to approximate dashed bezier
  11916. // Bad result if dash is long
  11917. idx % 2 ? ctx.moveTo(x, y)
  11918. : ctx.lineTo(x, y);
  11919. t += lineDash[idx] / bezierLen;
  11920. idx = (idx + 1) % nDash;
  11921. }
  11922. // Finish the last segment and calculate the new offset
  11923. (idx % 2 !== 0) && ctx.lineTo(x3, y3);
  11924. dx = x3 - x;
  11925. dy = y3 - y;
  11926. this._dashOffset = -mathSqrt(dx * dx + dy * dy);
  11927. },
  11928. _dashedQuadraticTo: function (x1, y1, x2, y2) {
  11929. // Convert quadratic to cubic using degree elevation
  11930. var x3 = x2;
  11931. var y3 = y2;
  11932. x2 = (x2 + 2 * x1) / 3;
  11933. y2 = (y2 + 2 * y1) / 3;
  11934. x1 = (this._xi + 2 * x1) / 3;
  11935. y1 = (this._yi + 2 * y1) / 3;
  11936. this._dashedBezierTo(x1, y1, x2, y2, x3, y3);
  11937. },
  11938. /**
  11939. * 转成静态的 Float32Array 减少堆内存占用
  11940. * Convert dynamic array to static Float32Array
  11941. */
  11942. toStatic: function () {
  11943. var data = this.data;
  11944. if (data instanceof Array) {
  11945. data.length = this._len;
  11946. if (hasTypedArray) {
  11947. this.data = new Float32Array(data);
  11948. }
  11949. }
  11950. },
  11951. /**
  11952. * @return {module:zrender/core/BoundingRect}
  11953. */
  11954. getBoundingRect: function () {
  11955. min[0] = min[1] = min2[0] = min2[1] = Number.MAX_VALUE;
  11956. max[0] = max[1] = max2[0] = max2[1] = -Number.MAX_VALUE;
  11957. var data = this.data;
  11958. var xi = 0;
  11959. var yi = 0;
  11960. var x0 = 0;
  11961. var y0 = 0;
  11962. for (var i = 0; i < data.length;) {
  11963. var cmd = data[i++];
  11964. if (i == 1) {
  11965. // 如果第一个命令是 L, C, Q
  11966. // 则 previous point 同绘制命令的第一个 point
  11967. //
  11968. // 第一个命令为 Arc 的情况下会在后面特殊处理
  11969. xi = data[i];
  11970. yi = data[i + 1];
  11971. x0 = xi;
  11972. y0 = yi;
  11973. }
  11974. switch (cmd) {
  11975. case CMD.M:
  11976. // moveTo 命令重新创建一个新的 subpath, 并且更新新的起点
  11977. // 在 closePath 的时候使用
  11978. x0 = data[i++];
  11979. y0 = data[i++];
  11980. xi = x0;
  11981. yi = y0;
  11982. min2[0] = x0;
  11983. min2[1] = y0;
  11984. max2[0] = x0;
  11985. max2[1] = y0;
  11986. break;
  11987. case CMD.L:
  11988. bbox.fromLine(xi, yi, data[i], data[i + 1], min2, max2);
  11989. xi = data[i++];
  11990. yi = data[i++];
  11991. break;
  11992. case CMD.C:
  11993. bbox.fromCubic(
  11994. xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],
  11995. min2, max2
  11996. );
  11997. xi = data[i++];
  11998. yi = data[i++];
  11999. break;
  12000. case CMD.Q:
  12001. bbox.fromQuadratic(
  12002. xi, yi, data[i++], data[i++], data[i], data[i + 1],
  12003. min2, max2
  12004. );
  12005. xi = data[i++];
  12006. yi = data[i++];
  12007. break;
  12008. case CMD.A:
  12009. // TODO Arc 判断的开销比较大
  12010. var cx = data[i++];
  12011. var cy = data[i++];
  12012. var rx = data[i++];
  12013. var ry = data[i++];
  12014. var startAngle = data[i++];
  12015. var endAngle = data[i++] + startAngle;
  12016. // TODO Arc 旋转
  12017. var psi = data[i++];
  12018. var anticlockwise = 1 - data[i++];
  12019. if (i == 1) {
  12020. // 直接使用 arc 命令
  12021. // 第一个命令起点还未定义
  12022. x0 = mathCos(startAngle) * rx + cx;
  12023. y0 = mathSin(startAngle) * ry + cy;
  12024. }
  12025. bbox.fromArc(
  12026. cx, cy, rx, ry, startAngle, endAngle,
  12027. anticlockwise, min2, max2
  12028. );
  12029. xi = mathCos(endAngle) * rx + cx;
  12030. yi = mathSin(endAngle) * ry + cy;
  12031. break;
  12032. case CMD.R:
  12033. x0 = xi = data[i++];
  12034. y0 = yi = data[i++];
  12035. var width = data[i++];
  12036. var height = data[i++];
  12037. // Use fromLine
  12038. bbox.fromLine(x0, y0, x0 + width, y0 + height, min2, max2);
  12039. break;
  12040. case CMD.Z:
  12041. xi = x0;
  12042. yi = y0;
  12043. break;
  12044. }
  12045. // Union
  12046. vec2.min(min, min, min2);
  12047. vec2.max(max, max, max2);
  12048. }
  12049. // No data
  12050. if (i === 0) {
  12051. min[0] = min[1] = max[0] = max[1] = 0;
  12052. }
  12053. return new BoundingRect(
  12054. min[0], min[1], max[0] - min[0], max[1] - min[1]
  12055. );
  12056. },
  12057. /**
  12058. * Rebuild path from current data
  12059. * Rebuild path will not consider javascript implemented line dash.
  12060. * @param {CanvasRenderingContext} ctx
  12061. */
  12062. rebuildPath: function (ctx) {
  12063. var d = this.data;
  12064. var x0, y0;
  12065. var xi, yi;
  12066. var x, y;
  12067. var ux = this._ux;
  12068. var uy = this._uy;
  12069. var len = this._len;
  12070. for (var i = 0; i < len;) {
  12071. var cmd = d[i++];
  12072. if (i == 1) {
  12073. // 如果第一个命令是 L, C, Q
  12074. // 则 previous point 同绘制命令的第一个 point
  12075. //
  12076. // 第一个命令为 Arc 的情况下会在后面特殊处理
  12077. xi = d[i];
  12078. yi = d[i + 1];
  12079. x0 = xi;
  12080. y0 = yi;
  12081. }
  12082. switch (cmd) {
  12083. case CMD.M:
  12084. x0 = xi = d[i++];
  12085. y0 = yi = d[i++];
  12086. ctx.moveTo(xi, yi);
  12087. break;
  12088. case CMD.L:
  12089. x = d[i++];
  12090. y = d[i++];
  12091. // Not draw too small seg between
  12092. if (mathAbs(x - xi) > ux || mathAbs(y - yi) > uy || i === len - 1) {
  12093. ctx.lineTo(x, y);
  12094. xi = x;
  12095. yi = y;
  12096. }
  12097. break;
  12098. case CMD.C:
  12099. ctx.bezierCurveTo(
  12100. d[i++], d[i++], d[i++], d[i++], d[i++], d[i++]
  12101. );
  12102. xi = d[i - 2];
  12103. yi = d[i - 1];
  12104. break;
  12105. case CMD.Q:
  12106. ctx.quadraticCurveTo(d[i++], d[i++], d[i++], d[i++]);
  12107. xi = d[i - 2];
  12108. yi = d[i - 1];
  12109. break;
  12110. case CMD.A:
  12111. var cx = d[i++];
  12112. var cy = d[i++];
  12113. var rx = d[i++];
  12114. var ry = d[i++];
  12115. var theta = d[i++];
  12116. var dTheta = d[i++];
  12117. var psi = d[i++];
  12118. var fs = d[i++];
  12119. var r = (rx > ry) ? rx : ry;
  12120. var scaleX = (rx > ry) ? 1 : rx / ry;
  12121. var scaleY = (rx > ry) ? ry / rx : 1;
  12122. var isEllipse = Math.abs(rx - ry) > 1e-3;
  12123. var endAngle = theta + dTheta;
  12124. if (isEllipse) {
  12125. ctx.translate(cx, cy);
  12126. ctx.rotate(psi);
  12127. ctx.scale(scaleX, scaleY);
  12128. ctx.arc(0, 0, r, theta, endAngle, 1 - fs);
  12129. ctx.scale(1 / scaleX, 1 / scaleY);
  12130. ctx.rotate(-psi);
  12131. ctx.translate(-cx, -cy);
  12132. }
  12133. else {
  12134. ctx.arc(cx, cy, r, theta, endAngle, 1 - fs);
  12135. }
  12136. if (i == 1) {
  12137. // 直接使用 arc 命令
  12138. // 第一个命令起点还未定义
  12139. x0 = mathCos(theta) * rx + cx;
  12140. y0 = mathSin(theta) * ry + cy;
  12141. }
  12142. xi = mathCos(endAngle) * rx + cx;
  12143. yi = mathSin(endAngle) * ry + cy;
  12144. break;
  12145. case CMD.R:
  12146. x0 = xi = d[i];
  12147. y0 = yi = d[i + 1];
  12148. ctx.rect(d[i++], d[i++], d[i++], d[i++]);
  12149. break;
  12150. case CMD.Z:
  12151. ctx.closePath();
  12152. xi = x0;
  12153. yi = y0;
  12154. }
  12155. }
  12156. }
  12157. };
  12158. PathProxy.CMD = CMD;
  12159. module.exports = PathProxy;
  12160. /***/ },
  12161. /* 50 */
  12162. /***/ function(module, exports, __webpack_require__) {
  12163. 'use strict';
  12164. /**
  12165. * 曲线辅助模块
  12166. * @module zrender/core/curve
  12167. * @author pissang(https://www.github.com/pissang)
  12168. */
  12169. var vec2 = __webpack_require__(10);
  12170. var v2Create = vec2.create;
  12171. var v2DistSquare = vec2.distSquare;
  12172. var mathPow = Math.pow;
  12173. var mathSqrt = Math.sqrt;
  12174. var EPSILON = 1e-8;
  12175. var EPSILON_NUMERIC = 1e-4;
  12176. var THREE_SQRT = mathSqrt(3);
  12177. var ONE_THIRD = 1 / 3;
  12178. // 临时变量
  12179. var _v0 = v2Create();
  12180. var _v1 = v2Create();
  12181. var _v2 = v2Create();
  12182. // var _v3 = vec2.create();
  12183. function isAroundZero(val) {
  12184. return val > -EPSILON && val < EPSILON;
  12185. }
  12186. function isNotAroundZero(val) {
  12187. return val > EPSILON || val < -EPSILON;
  12188. }
  12189. /**
  12190. * 计算三次贝塞尔值
  12191. * @memberOf module:zrender/core/curve
  12192. * @param {number} p0
  12193. * @param {number} p1
  12194. * @param {number} p2
  12195. * @param {number} p3
  12196. * @param {number} t
  12197. * @return {number}
  12198. */
  12199. function cubicAt(p0, p1, p2, p3, t) {
  12200. var onet = 1 - t;
  12201. return onet * onet * (onet * p0 + 3 * t * p1)
  12202. + t * t * (t * p3 + 3 * onet * p2);
  12203. }
  12204. /**
  12205. * 计算三次贝塞尔导数值
  12206. * @memberOf module:zrender/core/curve
  12207. * @param {number} p0
  12208. * @param {number} p1
  12209. * @param {number} p2
  12210. * @param {number} p3
  12211. * @param {number} t
  12212. * @return {number}
  12213. */
  12214. function cubicDerivativeAt(p0, p1, p2, p3, t) {
  12215. var onet = 1 - t;
  12216. return 3 * (
  12217. ((p1 - p0) * onet + 2 * (p2 - p1) * t) * onet
  12218. + (p3 - p2) * t * t
  12219. );
  12220. }
  12221. /**
  12222. * 计算三次贝塞尔方程根,使用盛金公式
  12223. * @memberOf module:zrender/core/curve
  12224. * @param {number} p0
  12225. * @param {number} p1
  12226. * @param {number} p2
  12227. * @param {number} p3
  12228. * @param {number} val
  12229. * @param {Array.<number>} roots
  12230. * @return {number} 有效根数目
  12231. */
  12232. function cubicRootAt(p0, p1, p2, p3, val, roots) {
  12233. // Evaluate roots of cubic functions
  12234. var a = p3 + 3 * (p1 - p2) - p0;
  12235. var b = 3 * (p2 - p1 * 2 + p0);
  12236. var c = 3 * (p1 - p0);
  12237. var d = p0 - val;
  12238. var A = b * b - 3 * a * c;
  12239. var B = b * c - 9 * a * d;
  12240. var C = c * c - 3 * b * d;
  12241. var n = 0;
  12242. if (isAroundZero(A) && isAroundZero(B)) {
  12243. if (isAroundZero(b)) {
  12244. roots[0] = 0;
  12245. }
  12246. else {
  12247. var t1 = -c / b; //t1, t2, t3, b is not zero
  12248. if (t1 >= 0 && t1 <= 1) {
  12249. roots[n++] = t1;
  12250. }
  12251. }
  12252. }
  12253. else {
  12254. var disc = B * B - 4 * A * C;
  12255. if (isAroundZero(disc)) {
  12256. var K = B / A;
  12257. var t1 = -b / a + K; // t1, a is not zero
  12258. var t2 = -K / 2; // t2, t3
  12259. if (t1 >= 0 && t1 <= 1) {
  12260. roots[n++] = t1;
  12261. }
  12262. if (t2 >= 0 && t2 <= 1) {
  12263. roots[n++] = t2;
  12264. }
  12265. }
  12266. else if (disc > 0) {
  12267. var discSqrt = mathSqrt(disc);
  12268. var Y1 = A * b + 1.5 * a * (-B + discSqrt);
  12269. var Y2 = A * b + 1.5 * a * (-B - discSqrt);
  12270. if (Y1 < 0) {
  12271. Y1 = -mathPow(-Y1, ONE_THIRD);
  12272. }
  12273. else {
  12274. Y1 = mathPow(Y1, ONE_THIRD);
  12275. }
  12276. if (Y2 < 0) {
  12277. Y2 = -mathPow(-Y2, ONE_THIRD);
  12278. }
  12279. else {
  12280. Y2 = mathPow(Y2, ONE_THIRD);
  12281. }
  12282. var t1 = (-b - (Y1 + Y2)) / (3 * a);
  12283. if (t1 >= 0 && t1 <= 1) {
  12284. roots[n++] = t1;
  12285. }
  12286. }
  12287. else {
  12288. var T = (2 * A * b - 3 * a * B) / (2 * mathSqrt(A * A * A));
  12289. var theta = Math.acos(T) / 3;
  12290. var ASqrt = mathSqrt(A);
  12291. var tmp = Math.cos(theta);
  12292. var t1 = (-b - 2 * ASqrt * tmp) / (3 * a);
  12293. var t2 = (-b + ASqrt * (tmp + THREE_SQRT * Math.sin(theta))) / (3 * a);
  12294. var t3 = (-b + ASqrt * (tmp - THREE_SQRT * Math.sin(theta))) / (3 * a);
  12295. if (t1 >= 0 && t1 <= 1) {
  12296. roots[n++] = t1;
  12297. }
  12298. if (t2 >= 0 && t2 <= 1) {
  12299. roots[n++] = t2;
  12300. }
  12301. if (t3 >= 0 && t3 <= 1) {
  12302. roots[n++] = t3;
  12303. }
  12304. }
  12305. }
  12306. return n;
  12307. }
  12308. /**
  12309. * 计算三次贝塞尔方程极限值的位置
  12310. * @memberOf module:zrender/core/curve
  12311. * @param {number} p0
  12312. * @param {number} p1
  12313. * @param {number} p2
  12314. * @param {number} p3
  12315. * @param {Array.<number>} extrema
  12316. * @return {number} 有效数目
  12317. */
  12318. function cubicExtrema(p0, p1, p2, p3, extrema) {
  12319. var b = 6 * p2 - 12 * p1 + 6 * p0;
  12320. var a = 9 * p1 + 3 * p3 - 3 * p0 - 9 * p2;
  12321. var c = 3 * p1 - 3 * p0;
  12322. var n = 0;
  12323. if (isAroundZero(a)) {
  12324. if (isNotAroundZero(b)) {
  12325. var t1 = -c / b;
  12326. if (t1 >= 0 && t1 <=1) {
  12327. extrema[n++] = t1;
  12328. }
  12329. }
  12330. }
  12331. else {
  12332. var disc = b * b - 4 * a * c;
  12333. if (isAroundZero(disc)) {
  12334. extrema[0] = -b / (2 * a);
  12335. }
  12336. else if (disc > 0) {
  12337. var discSqrt = mathSqrt(disc);
  12338. var t1 = (-b + discSqrt) / (2 * a);
  12339. var t2 = (-b - discSqrt) / (2 * a);
  12340. if (t1 >= 0 && t1 <= 1) {
  12341. extrema[n++] = t1;
  12342. }
  12343. if (t2 >= 0 && t2 <= 1) {
  12344. extrema[n++] = t2;
  12345. }
  12346. }
  12347. }
  12348. return n;
  12349. }
  12350. /**
  12351. * 细分三次贝塞尔曲线
  12352. * @memberOf module:zrender/core/curve
  12353. * @param {number} p0
  12354. * @param {number} p1
  12355. * @param {number} p2
  12356. * @param {number} p3
  12357. * @param {number} t
  12358. * @param {Array.<number>} out
  12359. */
  12360. function cubicSubdivide(p0, p1, p2, p3, t, out) {
  12361. var p01 = (p1 - p0) * t + p0;
  12362. var p12 = (p2 - p1) * t + p1;
  12363. var p23 = (p3 - p2) * t + p2;
  12364. var p012 = (p12 - p01) * t + p01;
  12365. var p123 = (p23 - p12) * t + p12;
  12366. var p0123 = (p123 - p012) * t + p012;
  12367. // Seg0
  12368. out[0] = p0;
  12369. out[1] = p01;
  12370. out[2] = p012;
  12371. out[3] = p0123;
  12372. // Seg1
  12373. out[4] = p0123;
  12374. out[5] = p123;
  12375. out[6] = p23;
  12376. out[7] = p3;
  12377. }
  12378. /**
  12379. * 投射点到三次贝塞尔曲线上,返回投射距离。
  12380. * 投射点有可能会有一个或者多个,这里只返回其中距离最短的一个。
  12381. * @param {number} x0
  12382. * @param {number} y0
  12383. * @param {number} x1
  12384. * @param {number} y1
  12385. * @param {number} x2
  12386. * @param {number} y2
  12387. * @param {number} x3
  12388. * @param {number} y3
  12389. * @param {number} x
  12390. * @param {number} y
  12391. * @param {Array.<number>} [out] 投射点
  12392. * @return {number}
  12393. */
  12394. function cubicProjectPoint(
  12395. x0, y0, x1, y1, x2, y2, x3, y3,
  12396. x, y, out
  12397. ) {
  12398. // http://pomax.github.io/bezierinfo/#projections
  12399. var t;
  12400. var interval = 0.005;
  12401. var d = Infinity;
  12402. var prev;
  12403. var next;
  12404. var d1;
  12405. var d2;
  12406. _v0[0] = x;
  12407. _v0[1] = y;
  12408. // 先粗略估计一下可能的最小距离的 t 值
  12409. // PENDING
  12410. for (var _t = 0; _t < 1; _t += 0.05) {
  12411. _v1[0] = cubicAt(x0, x1, x2, x3, _t);
  12412. _v1[1] = cubicAt(y0, y1, y2, y3, _t);
  12413. d1 = v2DistSquare(_v0, _v1);
  12414. if (d1 < d) {
  12415. t = _t;
  12416. d = d1;
  12417. }
  12418. }
  12419. d = Infinity;
  12420. // At most 32 iteration
  12421. for (var i = 0; i < 32; i++) {
  12422. if (interval < EPSILON_NUMERIC) {
  12423. break;
  12424. }
  12425. prev = t - interval;
  12426. next = t + interval;
  12427. // t - interval
  12428. _v1[0] = cubicAt(x0, x1, x2, x3, prev);
  12429. _v1[1] = cubicAt(y0, y1, y2, y3, prev);
  12430. d1 = v2DistSquare(_v1, _v0);
  12431. if (prev >= 0 && d1 < d) {
  12432. t = prev;
  12433. d = d1;
  12434. }
  12435. else {
  12436. // t + interval
  12437. _v2[0] = cubicAt(x0, x1, x2, x3, next);
  12438. _v2[1] = cubicAt(y0, y1, y2, y3, next);
  12439. d2 = v2DistSquare(_v2, _v0);
  12440. if (next <= 1 && d2 < d) {
  12441. t = next;
  12442. d = d2;
  12443. }
  12444. else {
  12445. interval *= 0.5;
  12446. }
  12447. }
  12448. }
  12449. // t
  12450. if (out) {
  12451. out[0] = cubicAt(x0, x1, x2, x3, t);
  12452. out[1] = cubicAt(y0, y1, y2, y3, t);
  12453. }
  12454. // console.log(interval, i);
  12455. return mathSqrt(d);
  12456. }
  12457. /**
  12458. * 计算二次方贝塞尔值
  12459. * @param {number} p0
  12460. * @param {number} p1
  12461. * @param {number} p2
  12462. * @param {number} t
  12463. * @return {number}
  12464. */
  12465. function quadraticAt(p0, p1, p2, t) {
  12466. var onet = 1 - t;
  12467. return onet * (onet * p0 + 2 * t * p1) + t * t * p2;
  12468. }
  12469. /**
  12470. * 计算二次方贝塞尔导数值
  12471. * @param {number} p0
  12472. * @param {number} p1
  12473. * @param {number} p2
  12474. * @param {number} t
  12475. * @return {number}
  12476. */
  12477. function quadraticDerivativeAt(p0, p1, p2, t) {
  12478. return 2 * ((1 - t) * (p1 - p0) + t * (p2 - p1));
  12479. }
  12480. /**
  12481. * 计算二次方贝塞尔方程根
  12482. * @param {number} p0
  12483. * @param {number} p1
  12484. * @param {number} p2
  12485. * @param {number} t
  12486. * @param {Array.<number>} roots
  12487. * @return {number} 有效根数目
  12488. */
  12489. function quadraticRootAt(p0, p1, p2, val, roots) {
  12490. var a = p0 - 2 * p1 + p2;
  12491. var b = 2 * (p1 - p0);
  12492. var c = p0 - val;
  12493. var n = 0;
  12494. if (isAroundZero(a)) {
  12495. if (isNotAroundZero(b)) {
  12496. var t1 = -c / b;
  12497. if (t1 >= 0 && t1 <= 1) {
  12498. roots[n++] = t1;
  12499. }
  12500. }
  12501. }
  12502. else {
  12503. var disc = b * b - 4 * a * c;
  12504. if (isAroundZero(disc)) {
  12505. var t1 = -b / (2 * a);
  12506. if (t1 >= 0 && t1 <= 1) {
  12507. roots[n++] = t1;
  12508. }
  12509. }
  12510. else if (disc > 0) {
  12511. var discSqrt = mathSqrt(disc);
  12512. var t1 = (-b + discSqrt) / (2 * a);
  12513. var t2 = (-b - discSqrt) / (2 * a);
  12514. if (t1 >= 0 && t1 <= 1) {
  12515. roots[n++] = t1;
  12516. }
  12517. if (t2 >= 0 && t2 <= 1) {
  12518. roots[n++] = t2;
  12519. }
  12520. }
  12521. }
  12522. return n;
  12523. }
  12524. /**
  12525. * 计算二次贝塞尔方程极限值
  12526. * @memberOf module:zrender/core/curve
  12527. * @param {number} p0
  12528. * @param {number} p1
  12529. * @param {number} p2
  12530. * @return {number}
  12531. */
  12532. function quadraticExtremum(p0, p1, p2) {
  12533. var divider = p0 + p2 - 2 * p1;
  12534. if (divider === 0) {
  12535. // p1 is center of p0 and p2
  12536. return 0.5;
  12537. }
  12538. else {
  12539. return (p0 - p1) / divider;
  12540. }
  12541. }
  12542. /**
  12543. * 细分二次贝塞尔曲线
  12544. * @memberOf module:zrender/core/curve
  12545. * @param {number} p0
  12546. * @param {number} p1
  12547. * @param {number} p2
  12548. * @param {number} t
  12549. * @param {Array.<number>} out
  12550. */
  12551. function quadraticSubdivide(p0, p1, p2, t, out) {
  12552. var p01 = (p1 - p0) * t + p0;
  12553. var p12 = (p2 - p1) * t + p1;
  12554. var p012 = (p12 - p01) * t + p01;
  12555. // Seg0
  12556. out[0] = p0;
  12557. out[1] = p01;
  12558. out[2] = p012;
  12559. // Seg1
  12560. out[3] = p012;
  12561. out[4] = p12;
  12562. out[5] = p2;
  12563. }
  12564. /**
  12565. * 投射点到二次贝塞尔曲线上,返回投射距离。
  12566. * 投射点有可能会有一个或者多个,这里只返回其中距离最短的一个。
  12567. * @param {number} x0
  12568. * @param {number} y0
  12569. * @param {number} x1
  12570. * @param {number} y1
  12571. * @param {number} x2
  12572. * @param {number} y2
  12573. * @param {number} x
  12574. * @param {number} y
  12575. * @param {Array.<number>} out 投射点
  12576. * @return {number}
  12577. */
  12578. function quadraticProjectPoint(
  12579. x0, y0, x1, y1, x2, y2,
  12580. x, y, out
  12581. ) {
  12582. // http://pomax.github.io/bezierinfo/#projections
  12583. var t;
  12584. var interval = 0.005;
  12585. var d = Infinity;
  12586. _v0[0] = x;
  12587. _v0[1] = y;
  12588. // 先粗略估计一下可能的最小距离的 t 值
  12589. // PENDING
  12590. for (var _t = 0; _t < 1; _t += 0.05) {
  12591. _v1[0] = quadraticAt(x0, x1, x2, _t);
  12592. _v1[1] = quadraticAt(y0, y1, y2, _t);
  12593. var d1 = v2DistSquare(_v0, _v1);
  12594. if (d1 < d) {
  12595. t = _t;
  12596. d = d1;
  12597. }
  12598. }
  12599. d = Infinity;
  12600. // At most 32 iteration
  12601. for (var i = 0; i < 32; i++) {
  12602. if (interval < EPSILON_NUMERIC) {
  12603. break;
  12604. }
  12605. var prev = t - interval;
  12606. var next = t + interval;
  12607. // t - interval
  12608. _v1[0] = quadraticAt(x0, x1, x2, prev);
  12609. _v1[1] = quadraticAt(y0, y1, y2, prev);
  12610. var d1 = v2DistSquare(_v1, _v0);
  12611. if (prev >= 0 && d1 < d) {
  12612. t = prev;
  12613. d = d1;
  12614. }
  12615. else {
  12616. // t + interval
  12617. _v2[0] = quadraticAt(x0, x1, x2, next);
  12618. _v2[1] = quadraticAt(y0, y1, y2, next);
  12619. var d2 = v2DistSquare(_v2, _v0);
  12620. if (next <= 1 && d2 < d) {
  12621. t = next;
  12622. d = d2;
  12623. }
  12624. else {
  12625. interval *= 0.5;
  12626. }
  12627. }
  12628. }
  12629. // t
  12630. if (out) {
  12631. out[0] = quadraticAt(x0, x1, x2, t);
  12632. out[1] = quadraticAt(y0, y1, y2, t);
  12633. }
  12634. // console.log(interval, i);
  12635. return mathSqrt(d);
  12636. }
  12637. module.exports = {
  12638. cubicAt: cubicAt,
  12639. cubicDerivativeAt: cubicDerivativeAt,
  12640. cubicRootAt: cubicRootAt,
  12641. cubicExtrema: cubicExtrema,
  12642. cubicSubdivide: cubicSubdivide,
  12643. cubicProjectPoint: cubicProjectPoint,
  12644. quadraticAt: quadraticAt,
  12645. quadraticDerivativeAt: quadraticDerivativeAt,
  12646. quadraticRootAt: quadraticRootAt,
  12647. quadraticExtremum: quadraticExtremum,
  12648. quadraticSubdivide: quadraticSubdivide,
  12649. quadraticProjectPoint: quadraticProjectPoint
  12650. };
  12651. /***/ },
  12652. /* 51 */
  12653. /***/ function(module, exports, __webpack_require__) {
  12654. /**
  12655. * @author Yi Shen(https://github.com/pissang)
  12656. */
  12657. var vec2 = __webpack_require__(10);
  12658. var curve = __webpack_require__(50);
  12659. var bbox = {};
  12660. var mathMin = Math.min;
  12661. var mathMax = Math.max;
  12662. var mathSin = Math.sin;
  12663. var mathCos = Math.cos;
  12664. var start = vec2.create();
  12665. var end = vec2.create();
  12666. var extremity = vec2.create();
  12667. var PI2 = Math.PI * 2;
  12668. /**
  12669. * 从顶点数组中计算出最小包围盒,写入`min`和`max`中
  12670. * @module zrender/core/bbox
  12671. * @param {Array<Object>} points 顶点数组
  12672. * @param {number} min
  12673. * @param {number} max
  12674. */
  12675. bbox.fromPoints = function(points, min, max) {
  12676. if (points.length === 0) {
  12677. return;
  12678. }
  12679. var p = points[0];
  12680. var left = p[0];
  12681. var right = p[0];
  12682. var top = p[1];
  12683. var bottom = p[1];
  12684. var i;
  12685. for (i = 1; i < points.length; i++) {
  12686. p = points[i];
  12687. left = mathMin(left, p[0]);
  12688. right = mathMax(right, p[0]);
  12689. top = mathMin(top, p[1]);
  12690. bottom = mathMax(bottom, p[1]);
  12691. }
  12692. min[0] = left;
  12693. min[1] = top;
  12694. max[0] = right;
  12695. max[1] = bottom;
  12696. };
  12697. /**
  12698. * @memberOf module:zrender/core/bbox
  12699. * @param {number} x0
  12700. * @param {number} y0
  12701. * @param {number} x1
  12702. * @param {number} y1
  12703. * @param {Array.<number>} min
  12704. * @param {Array.<number>} max
  12705. */
  12706. bbox.fromLine = function (x0, y0, x1, y1, min, max) {
  12707. min[0] = mathMin(x0, x1);
  12708. min[1] = mathMin(y0, y1);
  12709. max[0] = mathMax(x0, x1);
  12710. max[1] = mathMax(y0, y1);
  12711. };
  12712. var xDim = [];
  12713. var yDim = [];
  12714. /**
  12715. * 从三阶贝塞尔曲线(p0, p1, p2, p3)中计算出最小包围盒,写入`min`和`max`中
  12716. * @memberOf module:zrender/core/bbox
  12717. * @param {number} x0
  12718. * @param {number} y0
  12719. * @param {number} x1
  12720. * @param {number} y1
  12721. * @param {number} x2
  12722. * @param {number} y2
  12723. * @param {number} x3
  12724. * @param {number} y3
  12725. * @param {Array.<number>} min
  12726. * @param {Array.<number>} max
  12727. */
  12728. bbox.fromCubic = function(
  12729. x0, y0, x1, y1, x2, y2, x3, y3, min, max
  12730. ) {
  12731. var cubicExtrema = curve.cubicExtrema;
  12732. var cubicAt = curve.cubicAt;
  12733. var i;
  12734. var n = cubicExtrema(x0, x1, x2, x3, xDim);
  12735. min[0] = Infinity;
  12736. min[1] = Infinity;
  12737. max[0] = -Infinity;
  12738. max[1] = -Infinity;
  12739. for (i = 0; i < n; i++) {
  12740. var x = cubicAt(x0, x1, x2, x3, xDim[i]);
  12741. min[0] = mathMin(x, min[0]);
  12742. max[0] = mathMax(x, max[0]);
  12743. }
  12744. n = cubicExtrema(y0, y1, y2, y3, yDim);
  12745. for (i = 0; i < n; i++) {
  12746. var y = cubicAt(y0, y1, y2, y3, yDim[i]);
  12747. min[1] = mathMin(y, min[1]);
  12748. max[1] = mathMax(y, max[1]);
  12749. }
  12750. min[0] = mathMin(x0, min[0]);
  12751. max[0] = mathMax(x0, max[0]);
  12752. min[0] = mathMin(x3, min[0]);
  12753. max[0] = mathMax(x3, max[0]);
  12754. min[1] = mathMin(y0, min[1]);
  12755. max[1] = mathMax(y0, max[1]);
  12756. min[1] = mathMin(y3, min[1]);
  12757. max[1] = mathMax(y3, max[1]);
  12758. };
  12759. /**
  12760. * 从二阶贝塞尔曲线(p0, p1, p2)中计算出最小包围盒,写入`min`和`max`中
  12761. * @memberOf module:zrender/core/bbox
  12762. * @param {number} x0
  12763. * @param {number} y0
  12764. * @param {number} x1
  12765. * @param {number} y1
  12766. * @param {number} x2
  12767. * @param {number} y2
  12768. * @param {Array.<number>} min
  12769. * @param {Array.<number>} max
  12770. */
  12771. bbox.fromQuadratic = function(x0, y0, x1, y1, x2, y2, min, max) {
  12772. var quadraticExtremum = curve.quadraticExtremum;
  12773. var quadraticAt = curve.quadraticAt;
  12774. // Find extremities, where derivative in x dim or y dim is zero
  12775. var tx =
  12776. mathMax(
  12777. mathMin(quadraticExtremum(x0, x1, x2), 1), 0
  12778. );
  12779. var ty =
  12780. mathMax(
  12781. mathMin(quadraticExtremum(y0, y1, y2), 1), 0
  12782. );
  12783. var x = quadraticAt(x0, x1, x2, tx);
  12784. var y = quadraticAt(y0, y1, y2, ty);
  12785. min[0] = mathMin(x0, x2, x);
  12786. min[1] = mathMin(y0, y2, y);
  12787. max[0] = mathMax(x0, x2, x);
  12788. max[1] = mathMax(y0, y2, y);
  12789. };
  12790. /**
  12791. * 从圆弧中计算出最小包围盒,写入`min`和`max`中
  12792. * @method
  12793. * @memberOf module:zrender/core/bbox
  12794. * @param {number} x
  12795. * @param {number} y
  12796. * @param {number} rx
  12797. * @param {number} ry
  12798. * @param {number} startAngle
  12799. * @param {number} endAngle
  12800. * @param {number} anticlockwise
  12801. * @param {Array.<number>} min
  12802. * @param {Array.<number>} max
  12803. */
  12804. bbox.fromArc = function (
  12805. x, y, rx, ry, startAngle, endAngle, anticlockwise, min, max
  12806. ) {
  12807. var vec2Min = vec2.min;
  12808. var vec2Max = vec2.max;
  12809. var diff = Math.abs(startAngle - endAngle);
  12810. if (diff % PI2 < 1e-4 && diff > 1e-4) {
  12811. // Is a circle
  12812. min[0] = x - rx;
  12813. min[1] = y - ry;
  12814. max[0] = x + rx;
  12815. max[1] = y + ry;
  12816. return;
  12817. }
  12818. start[0] = mathCos(startAngle) * rx + x;
  12819. start[1] = mathSin(startAngle) * ry + y;
  12820. end[0] = mathCos(endAngle) * rx + x;
  12821. end[1] = mathSin(endAngle) * ry + y;
  12822. vec2Min(min, start, end);
  12823. vec2Max(max, start, end);
  12824. // Thresh to [0, Math.PI * 2]
  12825. startAngle = startAngle % (PI2);
  12826. if (startAngle < 0) {
  12827. startAngle = startAngle + PI2;
  12828. }
  12829. endAngle = endAngle % (PI2);
  12830. if (endAngle < 0) {
  12831. endAngle = endAngle + PI2;
  12832. }
  12833. if (startAngle > endAngle && !anticlockwise) {
  12834. endAngle += PI2;
  12835. }
  12836. else if (startAngle < endAngle && anticlockwise) {
  12837. startAngle += PI2;
  12838. }
  12839. if (anticlockwise) {
  12840. var tmp = endAngle;
  12841. endAngle = startAngle;
  12842. startAngle = tmp;
  12843. }
  12844. // var number = 0;
  12845. // var step = (anticlockwise ? -Math.PI : Math.PI) / 2;
  12846. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  12847. if (angle > startAngle) {
  12848. extremity[0] = mathCos(angle) * rx + x;
  12849. extremity[1] = mathSin(angle) * ry + y;
  12850. vec2Min(min, extremity, min);
  12851. vec2Max(max, extremity, max);
  12852. }
  12853. }
  12854. };
  12855. module.exports = bbox;
  12856. /***/ },
  12857. /* 52 */
  12858. /***/ function(module, exports, __webpack_require__) {
  12859. 'use strict';
  12860. var CMD = __webpack_require__(49).CMD;
  12861. var line = __webpack_require__(53);
  12862. var cubic = __webpack_require__(54);
  12863. var quadratic = __webpack_require__(55);
  12864. var arc = __webpack_require__(56);
  12865. var normalizeRadian = __webpack_require__(57).normalizeRadian;
  12866. var curve = __webpack_require__(50);
  12867. var windingLine = __webpack_require__(58);
  12868. var containStroke = line.containStroke;
  12869. var PI2 = Math.PI * 2;
  12870. var EPSILON = 1e-4;
  12871. function isAroundEqual(a, b) {
  12872. return Math.abs(a - b) < EPSILON;
  12873. }
  12874. // 临时数组
  12875. var roots = [-1, -1, -1];
  12876. var extrema = [-1, -1];
  12877. function swapExtrema() {
  12878. var tmp = extrema[0];
  12879. extrema[0] = extrema[1];
  12880. extrema[1] = tmp;
  12881. }
  12882. function windingCubic(x0, y0, x1, y1, x2, y2, x3, y3, x, y) {
  12883. // Quick reject
  12884. if (
  12885. (y > y0 && y > y1 && y > y2 && y > y3)
  12886. || (y < y0 && y < y1 && y < y2 && y < y3)
  12887. ) {
  12888. return 0;
  12889. }
  12890. var nRoots = curve.cubicRootAt(y0, y1, y2, y3, y, roots);
  12891. if (nRoots === 0) {
  12892. return 0;
  12893. }
  12894. else {
  12895. var w = 0;
  12896. var nExtrema = -1;
  12897. var y0_, y1_;
  12898. for (var i = 0; i < nRoots; i++) {
  12899. var t = roots[i];
  12900. // Avoid winding error when intersection point is the connect point of two line of polygon
  12901. var unit = (t === 0 || t === 1) ? 0.5 : 1;
  12902. var x_ = curve.cubicAt(x0, x1, x2, x3, t);
  12903. if (x_ < x) { // Quick reject
  12904. continue;
  12905. }
  12906. if (nExtrema < 0) {
  12907. nExtrema = curve.cubicExtrema(y0, y1, y2, y3, extrema);
  12908. if (extrema[1] < extrema[0] && nExtrema > 1) {
  12909. swapExtrema();
  12910. }
  12911. y0_ = curve.cubicAt(y0, y1, y2, y3, extrema[0]);
  12912. if (nExtrema > 1) {
  12913. y1_ = curve.cubicAt(y0, y1, y2, y3, extrema[1]);
  12914. }
  12915. }
  12916. if (nExtrema == 2) {
  12917. // 分成三段单调函数
  12918. if (t < extrema[0]) {
  12919. w += y0_ < y0 ? unit : -unit;
  12920. }
  12921. else if (t < extrema[1]) {
  12922. w += y1_ < y0_ ? unit : -unit;
  12923. }
  12924. else {
  12925. w += y3 < y1_ ? unit : -unit;
  12926. }
  12927. }
  12928. else {
  12929. // 分成两段单调函数
  12930. if (t < extrema[0]) {
  12931. w += y0_ < y0 ? unit : -unit;
  12932. }
  12933. else {
  12934. w += y3 < y0_ ? unit : -unit;
  12935. }
  12936. }
  12937. }
  12938. return w;
  12939. }
  12940. }
  12941. function windingQuadratic(x0, y0, x1, y1, x2, y2, x, y) {
  12942. // Quick reject
  12943. if (
  12944. (y > y0 && y > y1 && y > y2)
  12945. || (y < y0 && y < y1 && y < y2)
  12946. ) {
  12947. return 0;
  12948. }
  12949. var nRoots = curve.quadraticRootAt(y0, y1, y2, y, roots);
  12950. if (nRoots === 0) {
  12951. return 0;
  12952. }
  12953. else {
  12954. var t = curve.quadraticExtremum(y0, y1, y2);
  12955. if (t >= 0 && t <= 1) {
  12956. var w = 0;
  12957. var y_ = curve.quadraticAt(y0, y1, y2, t);
  12958. for (var i = 0; i < nRoots; i++) {
  12959. // Remove one endpoint.
  12960. var unit = (roots[i] === 0 || roots[i] === 1) ? 0.5 : 1;
  12961. var x_ = curve.quadraticAt(x0, x1, x2, roots[i]);
  12962. if (x_ < x) { // Quick reject
  12963. continue;
  12964. }
  12965. if (roots[i] < t) {
  12966. w += y_ < y0 ? unit : -unit;
  12967. }
  12968. else {
  12969. w += y2 < y_ ? unit : -unit;
  12970. }
  12971. }
  12972. return w;
  12973. }
  12974. else {
  12975. // Remove one endpoint.
  12976. var unit = (roots[0] === 0 || roots[0] === 1) ? 0.5 : 1;
  12977. var x_ = curve.quadraticAt(x0, x1, x2, roots[0]);
  12978. if (x_ < x) { // Quick reject
  12979. return 0;
  12980. }
  12981. return y2 < y0 ? unit : -unit;
  12982. }
  12983. }
  12984. }
  12985. // TODO
  12986. // Arc 旋转
  12987. function windingArc(
  12988. cx, cy, r, startAngle, endAngle, anticlockwise, x, y
  12989. ) {
  12990. y -= cy;
  12991. if (y > r || y < -r) {
  12992. return 0;
  12993. }
  12994. var tmp = Math.sqrt(r * r - y * y);
  12995. roots[0] = -tmp;
  12996. roots[1] = tmp;
  12997. var diff = Math.abs(startAngle - endAngle);
  12998. if (diff < 1e-4) {
  12999. return 0;
  13000. }
  13001. if (diff % PI2 < 1e-4) {
  13002. // Is a circle
  13003. startAngle = 0;
  13004. endAngle = PI2;
  13005. var dir = anticlockwise ? 1 : -1;
  13006. if (x >= roots[0] + cx && x <= roots[1] + cx) {
  13007. return dir;
  13008. } else {
  13009. return 0;
  13010. }
  13011. }
  13012. if (anticlockwise) {
  13013. var tmp = startAngle;
  13014. startAngle = normalizeRadian(endAngle);
  13015. endAngle = normalizeRadian(tmp);
  13016. }
  13017. else {
  13018. startAngle = normalizeRadian(startAngle);
  13019. endAngle = normalizeRadian(endAngle);
  13020. }
  13021. if (startAngle > endAngle) {
  13022. endAngle += PI2;
  13023. }
  13024. var w = 0;
  13025. for (var i = 0; i < 2; i++) {
  13026. var x_ = roots[i];
  13027. if (x_ + cx > x) {
  13028. var angle = Math.atan2(y, x_);
  13029. var dir = anticlockwise ? 1 : -1;
  13030. if (angle < 0) {
  13031. angle = PI2 + angle;
  13032. }
  13033. if (
  13034. (angle >= startAngle && angle <= endAngle)
  13035. || (angle + PI2 >= startAngle && angle + PI2 <= endAngle)
  13036. ) {
  13037. if (angle > Math.PI / 2 && angle < Math.PI * 1.5) {
  13038. dir = -dir;
  13039. }
  13040. w += dir;
  13041. }
  13042. }
  13043. }
  13044. return w;
  13045. }
  13046. function containPath(data, lineWidth, isStroke, x, y) {
  13047. var w = 0;
  13048. var xi = 0;
  13049. var yi = 0;
  13050. var x0 = 0;
  13051. var y0 = 0;
  13052. for (var i = 0; i < data.length;) {
  13053. var cmd = data[i++];
  13054. // Begin a new subpath
  13055. if (cmd === CMD.M && i > 1) {
  13056. // Close previous subpath
  13057. if (!isStroke) {
  13058. w += windingLine(xi, yi, x0, y0, x, y);
  13059. }
  13060. // 如果被任何一个 subpath 包含
  13061. // if (w !== 0) {
  13062. // return true;
  13063. // }
  13064. }
  13065. if (i == 1) {
  13066. // 如果第一个命令是 L, C, Q
  13067. // 则 previous point 同绘制命令的第一个 point
  13068. //
  13069. // 第一个命令为 Arc 的情况下会在后面特殊处理
  13070. xi = data[i];
  13071. yi = data[i + 1];
  13072. x0 = xi;
  13073. y0 = yi;
  13074. }
  13075. switch (cmd) {
  13076. case CMD.M:
  13077. // moveTo 命令重新创建一个新的 subpath, 并且更新新的起点
  13078. // 在 closePath 的时候使用
  13079. x0 = data[i++];
  13080. y0 = data[i++];
  13081. xi = x0;
  13082. yi = y0;
  13083. break;
  13084. case CMD.L:
  13085. if (isStroke) {
  13086. if (containStroke(xi, yi, data[i], data[i + 1], lineWidth, x, y)) {
  13087. return true;
  13088. }
  13089. }
  13090. else {
  13091. // NOTE 在第一个命令为 L, C, Q 的时候会计算出 NaN
  13092. w += windingLine(xi, yi, data[i], data[i + 1], x, y) || 0;
  13093. }
  13094. xi = data[i++];
  13095. yi = data[i++];
  13096. break;
  13097. case CMD.C:
  13098. if (isStroke) {
  13099. if (cubic.containStroke(xi, yi,
  13100. data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],
  13101. lineWidth, x, y
  13102. )) {
  13103. return true;
  13104. }
  13105. }
  13106. else {
  13107. w += windingCubic(
  13108. xi, yi,
  13109. data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],
  13110. x, y
  13111. ) || 0;
  13112. }
  13113. xi = data[i++];
  13114. yi = data[i++];
  13115. break;
  13116. case CMD.Q:
  13117. if (isStroke) {
  13118. if (quadratic.containStroke(xi, yi,
  13119. data[i++], data[i++], data[i], data[i + 1],
  13120. lineWidth, x, y
  13121. )) {
  13122. return true;
  13123. }
  13124. }
  13125. else {
  13126. w += windingQuadratic(
  13127. xi, yi,
  13128. data[i++], data[i++], data[i], data[i + 1],
  13129. x, y
  13130. ) || 0;
  13131. }
  13132. xi = data[i++];
  13133. yi = data[i++];
  13134. break;
  13135. case CMD.A:
  13136. // TODO Arc 判断的开销比较大
  13137. var cx = data[i++];
  13138. var cy = data[i++];
  13139. var rx = data[i++];
  13140. var ry = data[i++];
  13141. var theta = data[i++];
  13142. var dTheta = data[i++];
  13143. // TODO Arc 旋转
  13144. var psi = data[i++];
  13145. var anticlockwise = 1 - data[i++];
  13146. var x1 = Math.cos(theta) * rx + cx;
  13147. var y1 = Math.sin(theta) * ry + cy;
  13148. // 不是直接使用 arc 命令
  13149. if (i > 1) {
  13150. w += windingLine(xi, yi, x1, y1, x, y);
  13151. }
  13152. else {
  13153. // 第一个命令起点还未定义
  13154. x0 = x1;
  13155. y0 = y1;
  13156. }
  13157. // zr 使用scale来模拟椭圆, 这里也对x做一定的缩放
  13158. var _x = (x - cx) * ry / rx + cx;
  13159. if (isStroke) {
  13160. if (arc.containStroke(
  13161. cx, cy, ry, theta, theta + dTheta, anticlockwise,
  13162. lineWidth, _x, y
  13163. )) {
  13164. return true;
  13165. }
  13166. }
  13167. else {
  13168. w += windingArc(
  13169. cx, cy, ry, theta, theta + dTheta, anticlockwise,
  13170. _x, y
  13171. );
  13172. }
  13173. xi = Math.cos(theta + dTheta) * rx + cx;
  13174. yi = Math.sin(theta + dTheta) * ry + cy;
  13175. break;
  13176. case CMD.R:
  13177. x0 = xi = data[i++];
  13178. y0 = yi = data[i++];
  13179. var width = data[i++];
  13180. var height = data[i++];
  13181. var x1 = x0 + width;
  13182. var y1 = y0 + height;
  13183. if (isStroke) {
  13184. if (containStroke(x0, y0, x1, y0, lineWidth, x, y)
  13185. || containStroke(x1, y0, x1, y1, lineWidth, x, y)
  13186. || containStroke(x1, y1, x0, y1, lineWidth, x, y)
  13187. || containStroke(x0, y1, x0, y0, lineWidth, x, y)
  13188. ) {
  13189. return true;
  13190. }
  13191. }
  13192. else {
  13193. // FIXME Clockwise ?
  13194. w += windingLine(x1, y0, x1, y1, x, y);
  13195. w += windingLine(x0, y1, x0, y0, x, y);
  13196. }
  13197. break;
  13198. case CMD.Z:
  13199. if (isStroke) {
  13200. if (containStroke(
  13201. xi, yi, x0, y0, lineWidth, x, y
  13202. )) {
  13203. return true;
  13204. }
  13205. }
  13206. else {
  13207. // Close a subpath
  13208. w += windingLine(xi, yi, x0, y0, x, y);
  13209. // 如果被任何一个 subpath 包含
  13210. // FIXME subpaths may overlap
  13211. // if (w !== 0) {
  13212. // return true;
  13213. // }
  13214. }
  13215. xi = x0;
  13216. yi = y0;
  13217. break;
  13218. }
  13219. }
  13220. if (!isStroke && !isAroundEqual(yi, y0)) {
  13221. w += windingLine(xi, yi, x0, y0, x, y) || 0;
  13222. }
  13223. return w !== 0;
  13224. }
  13225. module.exports = {
  13226. contain: function (pathData, x, y) {
  13227. return containPath(pathData, 0, false, x, y);
  13228. },
  13229. containStroke: function (pathData, lineWidth, x, y) {
  13230. return containPath(pathData, lineWidth, true, x, y);
  13231. }
  13232. };
  13233. /***/ },
  13234. /* 53 */
  13235. /***/ function(module, exports) {
  13236. module.exports = {
  13237. /**
  13238. * 线段包含判断
  13239. * @param {number} x0
  13240. * @param {number} y0
  13241. * @param {number} x1
  13242. * @param {number} y1
  13243. * @param {number} lineWidth
  13244. * @param {number} x
  13245. * @param {number} y
  13246. * @return {boolean}
  13247. */
  13248. containStroke: function (x0, y0, x1, y1, lineWidth, x, y) {
  13249. if (lineWidth === 0) {
  13250. return false;
  13251. }
  13252. var _l = lineWidth;
  13253. var _a = 0;
  13254. var _b = x0;
  13255. // Quick reject
  13256. if (
  13257. (y > y0 + _l && y > y1 + _l)
  13258. || (y < y0 - _l && y < y1 - _l)
  13259. || (x > x0 + _l && x > x1 + _l)
  13260. || (x < x0 - _l && x < x1 - _l)
  13261. ) {
  13262. return false;
  13263. }
  13264. if (x0 !== x1) {
  13265. _a = (y0 - y1) / (x0 - x1);
  13266. _b = (x0 * y1 - x1 * y0) / (x0 - x1) ;
  13267. }
  13268. else {
  13269. return Math.abs(x - x0) <= _l / 2;
  13270. }
  13271. var tmp = _a * x - y + _b;
  13272. var _s = tmp * tmp / (_a * _a + 1);
  13273. return _s <= _l / 2 * _l / 2;
  13274. }
  13275. };
  13276. /***/ },
  13277. /* 54 */
  13278. /***/ function(module, exports, __webpack_require__) {
  13279. var curve = __webpack_require__(50);
  13280. module.exports = {
  13281. /**
  13282. * 三次贝塞尔曲线描边包含判断
  13283. * @param {number} x0
  13284. * @param {number} y0
  13285. * @param {number} x1
  13286. * @param {number} y1
  13287. * @param {number} x2
  13288. * @param {number} y2
  13289. * @param {number} x3
  13290. * @param {number} y3
  13291. * @param {number} lineWidth
  13292. * @param {number} x
  13293. * @param {number} y
  13294. * @return {boolean}
  13295. */
  13296. containStroke: function(x0, y0, x1, y1, x2, y2, x3, y3, lineWidth, x, y) {
  13297. if (lineWidth === 0) {
  13298. return false;
  13299. }
  13300. var _l = lineWidth;
  13301. // Quick reject
  13302. if (
  13303. (y > y0 + _l && y > y1 + _l && y > y2 + _l && y > y3 + _l)
  13304. || (y < y0 - _l && y < y1 - _l && y < y2 - _l && y < y3 - _l)
  13305. || (x > x0 + _l && x > x1 + _l && x > x2 + _l && x > x3 + _l)
  13306. || (x < x0 - _l && x < x1 - _l && x < x2 - _l && x < x3 - _l)
  13307. ) {
  13308. return false;
  13309. }
  13310. var d = curve.cubicProjectPoint(
  13311. x0, y0, x1, y1, x2, y2, x3, y3,
  13312. x, y, null
  13313. );
  13314. return d <= _l / 2;
  13315. }
  13316. };
  13317. /***/ },
  13318. /* 55 */
  13319. /***/ function(module, exports, __webpack_require__) {
  13320. var curve = __webpack_require__(50);
  13321. module.exports = {
  13322. /**
  13323. * 二次贝塞尔曲线描边包含判断
  13324. * @param {number} x0
  13325. * @param {number} y0
  13326. * @param {number} x1
  13327. * @param {number} y1
  13328. * @param {number} x2
  13329. * @param {number} y2
  13330. * @param {number} lineWidth
  13331. * @param {number} x
  13332. * @param {number} y
  13333. * @return {boolean}
  13334. */
  13335. containStroke: function (x0, y0, x1, y1, x2, y2, lineWidth, x, y) {
  13336. if (lineWidth === 0) {
  13337. return false;
  13338. }
  13339. var _l = lineWidth;
  13340. // Quick reject
  13341. if (
  13342. (y > y0 + _l && y > y1 + _l && y > y2 + _l)
  13343. || (y < y0 - _l && y < y1 - _l && y < y2 - _l)
  13344. || (x > x0 + _l && x > x1 + _l && x > x2 + _l)
  13345. || (x < x0 - _l && x < x1 - _l && x < x2 - _l)
  13346. ) {
  13347. return false;
  13348. }
  13349. var d = curve.quadraticProjectPoint(
  13350. x0, y0, x1, y1, x2, y2,
  13351. x, y, null
  13352. );
  13353. return d <= _l / 2;
  13354. }
  13355. };
  13356. /***/ },
  13357. /* 56 */
  13358. /***/ function(module, exports, __webpack_require__) {
  13359. var normalizeRadian = __webpack_require__(57).normalizeRadian;
  13360. var PI2 = Math.PI * 2;
  13361. module.exports = {
  13362. /**
  13363. * 圆弧描边包含判断
  13364. * @param {number} cx
  13365. * @param {number} cy
  13366. * @param {number} r
  13367. * @param {number} startAngle
  13368. * @param {number} endAngle
  13369. * @param {boolean} anticlockwise
  13370. * @param {number} lineWidth
  13371. * @param {number} x
  13372. * @param {number} y
  13373. * @return {Boolean}
  13374. */
  13375. containStroke: function (
  13376. cx, cy, r, startAngle, endAngle, anticlockwise,
  13377. lineWidth, x, y
  13378. ) {
  13379. if (lineWidth === 0) {
  13380. return false;
  13381. }
  13382. var _l = lineWidth;
  13383. x -= cx;
  13384. y -= cy;
  13385. var d = Math.sqrt(x * x + y * y);
  13386. if ((d - _l > r) || (d + _l < r)) {
  13387. return false;
  13388. }
  13389. if (Math.abs(startAngle - endAngle) % PI2 < 1e-4) {
  13390. // Is a circle
  13391. return true;
  13392. }
  13393. if (anticlockwise) {
  13394. var tmp = startAngle;
  13395. startAngle = normalizeRadian(endAngle);
  13396. endAngle = normalizeRadian(tmp);
  13397. } else {
  13398. startAngle = normalizeRadian(startAngle);
  13399. endAngle = normalizeRadian(endAngle);
  13400. }
  13401. if (startAngle > endAngle) {
  13402. endAngle += PI2;
  13403. }
  13404. var angle = Math.atan2(y, x);
  13405. if (angle < 0) {
  13406. angle += PI2;
  13407. }
  13408. return (angle >= startAngle && angle <= endAngle)
  13409. || (angle + PI2 >= startAngle && angle + PI2 <= endAngle);
  13410. }
  13411. };
  13412. /***/ },
  13413. /* 57 */
  13414. /***/ function(module, exports) {
  13415. var PI2 = Math.PI * 2;
  13416. module.exports = {
  13417. normalizeRadian: function(angle) {
  13418. angle %= PI2;
  13419. if (angle < 0) {
  13420. angle += PI2;
  13421. }
  13422. return angle;
  13423. }
  13424. };
  13425. /***/ },
  13426. /* 58 */
  13427. /***/ function(module, exports) {
  13428. module.exports = function windingLine(x0, y0, x1, y1, x, y) {
  13429. if ((y > y0 && y > y1) || (y < y0 && y < y1)) {
  13430. return 0;
  13431. }
  13432. // Ignore horizontal line
  13433. if (y1 === y0) {
  13434. return 0;
  13435. }
  13436. var dir = y1 < y0 ? 1 : -1;
  13437. var t = (y - y0) / (y1 - y0);
  13438. // Avoid winding error when intersection point is the connect point of two line of polygon
  13439. if (t === 1 || t === 0) {
  13440. dir = y1 < y0 ? 0.5 : -0.5;
  13441. }
  13442. var x_ = t * (x1 - x0) + x0;
  13443. return x_ > x ? dir : 0;
  13444. };
  13445. /***/ },
  13446. /* 59 */
  13447. /***/ function(module, exports) {
  13448. var Pattern = function (image, repeat) {
  13449. this.image = image;
  13450. this.repeat = repeat;
  13451. // Can be cloned
  13452. this.type = 'pattern';
  13453. };
  13454. Pattern.prototype.getCanvasPattern = function (ctx) {
  13455. return this._canvasPattern
  13456. || (this._canvasPattern = ctx.createPattern(this.image, this.repeat));
  13457. };
  13458. module.exports = Pattern;
  13459. /***/ },
  13460. /* 60 */
  13461. /***/ function(module, exports, __webpack_require__) {
  13462. var CMD = __webpack_require__(49).CMD;
  13463. var vec2 = __webpack_require__(10);
  13464. var v2ApplyTransform = vec2.applyTransform;
  13465. var points = [[], [], []];
  13466. var mathSqrt = Math.sqrt;
  13467. var mathAtan2 = Math.atan2;
  13468. function transformPath(path, m) {
  13469. var data = path.data;
  13470. var cmd;
  13471. var nPoint;
  13472. var i;
  13473. var j;
  13474. var k;
  13475. var p;
  13476. var M = CMD.M;
  13477. var C = CMD.C;
  13478. var L = CMD.L;
  13479. var R = CMD.R;
  13480. var A = CMD.A;
  13481. var Q = CMD.Q;
  13482. for (i = 0, j = 0; i < data.length;) {
  13483. cmd = data[i++];
  13484. j = i;
  13485. nPoint = 0;
  13486. switch (cmd) {
  13487. case M:
  13488. nPoint = 1;
  13489. break;
  13490. case L:
  13491. nPoint = 1;
  13492. break;
  13493. case C:
  13494. nPoint = 3;
  13495. break;
  13496. case Q:
  13497. nPoint = 2;
  13498. break;
  13499. case A:
  13500. var x = m[4];
  13501. var y = m[5];
  13502. var sx = mathSqrt(m[0] * m[0] + m[1] * m[1]);
  13503. var sy = mathSqrt(m[2] * m[2] + m[3] * m[3]);
  13504. var angle = mathAtan2(-m[1] / sy, m[0] / sx);
  13505. // cx
  13506. data[i++] += x;
  13507. // cy
  13508. data[i++] += y;
  13509. // Scale rx and ry
  13510. // FIXME Assume psi is 0 here
  13511. data[i++] *= sx;
  13512. data[i++] *= sy;
  13513. // Start angle
  13514. data[i++] += angle;
  13515. // end angle
  13516. data[i++] += angle;
  13517. // FIXME psi
  13518. i += 2;
  13519. j = i;
  13520. break;
  13521. case R:
  13522. // x0, y0
  13523. p[0] = data[i++];
  13524. p[1] = data[i++];
  13525. v2ApplyTransform(p, p, m);
  13526. data[j++] = p[0];
  13527. data[j++] = p[1];
  13528. // x1, y1
  13529. p[0] += data[i++];
  13530. p[1] += data[i++];
  13531. v2ApplyTransform(p, p, m);
  13532. data[j++] = p[0];
  13533. data[j++] = p[1];
  13534. }
  13535. for (k = 0; k < nPoint; k++) {
  13536. var p = points[k];
  13537. p[0] = data[i++];
  13538. p[1] = data[i++];
  13539. v2ApplyTransform(p, p, m);
  13540. // Write back
  13541. data[j++] = p[0];
  13542. data[j++] = p[1];
  13543. }
  13544. }
  13545. }
  13546. module.exports = transformPath;
  13547. /***/ },
  13548. /* 61 */
  13549. /***/ function(module, exports, __webpack_require__) {
  13550. /**
  13551. * Image element
  13552. * @module zrender/graphic/Image
  13553. */
  13554. var Displayable = __webpack_require__(46);
  13555. var BoundingRect = __webpack_require__(9);
  13556. var zrUtil = __webpack_require__(4);
  13557. var LRU = __webpack_require__(62);
  13558. var globalImageCache = new LRU(50);
  13559. /**
  13560. * @alias zrender/graphic/Image
  13561. * @extends module:zrender/graphic/Displayable
  13562. * @constructor
  13563. * @param {Object} opts
  13564. */
  13565. function ZImage(opts) {
  13566. Displayable.call(this, opts);
  13567. }
  13568. ZImage.prototype = {
  13569. constructor: ZImage,
  13570. type: 'image',
  13571. brush: function (ctx, prevEl) {
  13572. var style = this.style;
  13573. var src = style.image;
  13574. var image;
  13575. // Must bind each time
  13576. style.bind(ctx, this, prevEl);
  13577. // style.image is a url string
  13578. if (typeof src === 'string') {
  13579. image = this._image;
  13580. }
  13581. // style.image is an HTMLImageElement or HTMLCanvasElement or Canvas
  13582. else {
  13583. image = src;
  13584. }
  13585. // FIXME Case create many images with src
  13586. if (!image && src) {
  13587. // Try get from global image cache
  13588. var cachedImgObj = globalImageCache.get(src);
  13589. if (!cachedImgObj) {
  13590. // Create a new image
  13591. image = new Image();
  13592. image.onload = function () {
  13593. image.onload = null;
  13594. for (var i = 0; i < cachedImgObj.pending.length; i++) {
  13595. cachedImgObj.pending[i].dirty();
  13596. }
  13597. };
  13598. cachedImgObj = {
  13599. image: image,
  13600. pending: [this]
  13601. };
  13602. image.src = src;
  13603. globalImageCache.put(src, cachedImgObj);
  13604. this._image = image;
  13605. return;
  13606. }
  13607. else {
  13608. image = cachedImgObj.image;
  13609. this._image = image;
  13610. // Image is not complete finish, add to pending list
  13611. if (!image.width || !image.height) {
  13612. cachedImgObj.pending.push(this);
  13613. return;
  13614. }
  13615. }
  13616. }
  13617. if (image) {
  13618. // 图片已经加载完成
  13619. // if (image.nodeName.toUpperCase() == 'IMG') {
  13620. // if (!image.complete) {
  13621. // return;
  13622. // }
  13623. // }
  13624. // Else is canvas
  13625. var width = style.width || image.width;
  13626. var height = style.height || image.height;
  13627. var x = style.x || 0;
  13628. var y = style.y || 0;
  13629. // 图片加载失败
  13630. if (!image.width || !image.height) {
  13631. return;
  13632. }
  13633. // 设置transform
  13634. this.setTransform(ctx);
  13635. if (style.sWidth && style.sHeight) {
  13636. var sx = style.sx || 0;
  13637. var sy = style.sy || 0;
  13638. ctx.drawImage(
  13639. image,
  13640. sx, sy, style.sWidth, style.sHeight,
  13641. x, y, width, height
  13642. );
  13643. }
  13644. else if (style.sx && style.sy) {
  13645. var sx = style.sx;
  13646. var sy = style.sy;
  13647. var sWidth = width - sx;
  13648. var sHeight = height - sy;
  13649. ctx.drawImage(
  13650. image,
  13651. sx, sy, sWidth, sHeight,
  13652. x, y, width, height
  13653. );
  13654. }
  13655. else {
  13656. ctx.drawImage(image, x, y, width, height);
  13657. }
  13658. // 如果没设置宽和高的话自动根据图片宽高设置
  13659. if (style.width == null) {
  13660. style.width = width;
  13661. }
  13662. if (style.height == null) {
  13663. style.height = height;
  13664. }
  13665. this.restoreTransform(ctx);
  13666. // Draw rect text
  13667. if (style.text != null) {
  13668. this.drawRectText(ctx, this.getBoundingRect());
  13669. }
  13670. }
  13671. },
  13672. getBoundingRect: function () {
  13673. var style = this.style;
  13674. if (! this._rect) {
  13675. this._rect = new BoundingRect(
  13676. style.x || 0, style.y || 0, style.width || 0, style.height || 0
  13677. );
  13678. }
  13679. return this._rect;
  13680. }
  13681. };
  13682. zrUtil.inherits(ZImage, Displayable);
  13683. module.exports = ZImage;
  13684. /***/ },
  13685. /* 62 */
  13686. /***/ function(module, exports) {
  13687. // Simple LRU cache use doubly linked list
  13688. // @module zrender/core/LRU
  13689. /**
  13690. * Simple double linked list. Compared with array, it has O(1) remove operation.
  13691. * @constructor
  13692. */
  13693. var LinkedList = function() {
  13694. /**
  13695. * @type {module:zrender/core/LRU~Entry}
  13696. */
  13697. this.head = null;
  13698. /**
  13699. * @type {module:zrender/core/LRU~Entry}
  13700. */
  13701. this.tail = null;
  13702. this._len = 0;
  13703. };
  13704. var linkedListProto = LinkedList.prototype;
  13705. /**
  13706. * Insert a new value at the tail
  13707. * @param {} val
  13708. * @return {module:zrender/core/LRU~Entry}
  13709. */
  13710. linkedListProto.insert = function(val) {
  13711. var entry = new Entry(val);
  13712. this.insertEntry(entry);
  13713. return entry;
  13714. };
  13715. /**
  13716. * Insert an entry at the tail
  13717. * @param {module:zrender/core/LRU~Entry} entry
  13718. */
  13719. linkedListProto.insertEntry = function(entry) {
  13720. if (!this.head) {
  13721. this.head = this.tail = entry;
  13722. }
  13723. else {
  13724. this.tail.next = entry;
  13725. entry.prev = this.tail;
  13726. this.tail = entry;
  13727. }
  13728. this._len++;
  13729. };
  13730. /**
  13731. * Remove entry.
  13732. * @param {module:zrender/core/LRU~Entry} entry
  13733. */
  13734. linkedListProto.remove = function(entry) {
  13735. var prev = entry.prev;
  13736. var next = entry.next;
  13737. if (prev) {
  13738. prev.next = next;
  13739. }
  13740. else {
  13741. // Is head
  13742. this.head = next;
  13743. }
  13744. if (next) {
  13745. next.prev = prev;
  13746. }
  13747. else {
  13748. // Is tail
  13749. this.tail = prev;
  13750. }
  13751. entry.next = entry.prev = null;
  13752. this._len--;
  13753. };
  13754. /**
  13755. * @return {number}
  13756. */
  13757. linkedListProto.len = function() {
  13758. return this._len;
  13759. };
  13760. /**
  13761. * @constructor
  13762. * @param {} val
  13763. */
  13764. var Entry = function(val) {
  13765. /**
  13766. * @type {}
  13767. */
  13768. this.value = val;
  13769. /**
  13770. * @type {module:zrender/core/LRU~Entry}
  13771. */
  13772. this.next;
  13773. /**
  13774. * @type {module:zrender/core/LRU~Entry}
  13775. */
  13776. this.prev;
  13777. };
  13778. /**
  13779. * LRU Cache
  13780. * @constructor
  13781. * @alias module:zrender/core/LRU
  13782. */
  13783. var LRU = function(maxSize) {
  13784. this._list = new LinkedList();
  13785. this._map = {};
  13786. this._maxSize = maxSize || 10;
  13787. };
  13788. var LRUProto = LRU.prototype;
  13789. /**
  13790. * @param {string} key
  13791. * @param {} value
  13792. */
  13793. LRUProto.put = function(key, value) {
  13794. var list = this._list;
  13795. var map = this._map;
  13796. if (map[key] == null) {
  13797. var len = list.len();
  13798. if (len >= this._maxSize && len > 0) {
  13799. // Remove the least recently used
  13800. var leastUsedEntry = list.head;
  13801. list.remove(leastUsedEntry);
  13802. delete map[leastUsedEntry.key];
  13803. }
  13804. var entry = list.insert(value);
  13805. entry.key = key;
  13806. map[key] = entry;
  13807. }
  13808. };
  13809. /**
  13810. * @param {string} key
  13811. * @return {}
  13812. */
  13813. LRUProto.get = function(key) {
  13814. var entry = this._map[key];
  13815. var list = this._list;
  13816. if (entry != null) {
  13817. // Put the latest used entry in the tail
  13818. if (entry !== list.tail) {
  13819. list.remove(entry);
  13820. list.insertEntry(entry);
  13821. }
  13822. return entry.value;
  13823. }
  13824. };
  13825. /**
  13826. * Clear the cache
  13827. */
  13828. LRUProto.clear = function() {
  13829. this._list.clear();
  13830. this._map = {};
  13831. };
  13832. module.exports = LRU;
  13833. /***/ },
  13834. /* 63 */
  13835. /***/ function(module, exports, __webpack_require__) {
  13836. /**
  13837. * Text element
  13838. * @module zrender/graphic/Text
  13839. *
  13840. * TODO Wrapping
  13841. *
  13842. * Text not support gradient
  13843. */
  13844. var Displayable = __webpack_require__(46);
  13845. var zrUtil = __webpack_require__(4);
  13846. var textContain = __webpack_require__(8);
  13847. /**
  13848. * @alias zrender/graphic/Text
  13849. * @extends module:zrender/graphic/Displayable
  13850. * @constructor
  13851. * @param {Object} opts
  13852. */
  13853. var Text = function (opts) {
  13854. Displayable.call(this, opts);
  13855. };
  13856. Text.prototype = {
  13857. constructor: Text,
  13858. type: 'text',
  13859. brush: function (ctx, prevEl) {
  13860. var style = this.style;
  13861. var x = style.x || 0;
  13862. var y = style.y || 0;
  13863. // Convert to string
  13864. var text = style.text;
  13865. // Convert to string
  13866. text != null && (text += '');
  13867. // Always bind style
  13868. style.bind(ctx, this, prevEl);
  13869. if (text) {
  13870. this.setTransform(ctx);
  13871. var textBaseline;
  13872. var textAlign = style.textAlign;
  13873. var font = style.textFont || style.font;
  13874. if (style.textVerticalAlign) {
  13875. var rect = textContain.getBoundingRect(
  13876. text, font, style.textAlign, 'top'
  13877. );
  13878. // Ignore textBaseline
  13879. textBaseline = 'middle';
  13880. switch (style.textVerticalAlign) {
  13881. case 'middle':
  13882. y -= rect.height / 2 - rect.lineHeight / 2;
  13883. break;
  13884. case 'bottom':
  13885. y -= rect.height - rect.lineHeight / 2;
  13886. break;
  13887. default:
  13888. y += rect.lineHeight / 2;
  13889. }
  13890. }
  13891. else {
  13892. textBaseline = style.textBaseline;
  13893. }
  13894. // TODO Invalid font
  13895. ctx.font = font || '12px sans-serif';
  13896. ctx.textAlign = textAlign || 'left';
  13897. // Use canvas default left textAlign. Giving invalid value will cause state not change
  13898. if (ctx.textAlign !== textAlign) {
  13899. ctx.textAlign = 'left';
  13900. }
  13901. ctx.textBaseline = textBaseline || 'alphabetic';
  13902. // Use canvas default alphabetic baseline
  13903. if (ctx.textBaseline !== textBaseline) {
  13904. ctx.textBaseline = 'alphabetic';
  13905. }
  13906. var lineHeight = textContain.measureText('国', ctx.font).width;
  13907. var textLines = text.split('\n');
  13908. for (var i = 0; i < textLines.length; i++) {
  13909. style.hasFill() && ctx.fillText(textLines[i], x, y);
  13910. style.hasStroke() && ctx.strokeText(textLines[i], x, y);
  13911. y += lineHeight;
  13912. }
  13913. this.restoreTransform(ctx);
  13914. }
  13915. },
  13916. getBoundingRect: function () {
  13917. if (!this._rect) {
  13918. var style = this.style;
  13919. var textVerticalAlign = style.textVerticalAlign;
  13920. var rect = textContain.getBoundingRect(
  13921. style.text + '', style.textFont || style.font, style.textAlign,
  13922. textVerticalAlign ? 'top' : style.textBaseline
  13923. );
  13924. switch (textVerticalAlign) {
  13925. case 'middle':
  13926. rect.y -= rect.height / 2;
  13927. break;
  13928. case 'bottom':
  13929. rect.y -= rect.height;
  13930. break;
  13931. }
  13932. rect.x += style.x || 0;
  13933. rect.y += style.y || 0;
  13934. this._rect = rect;
  13935. }
  13936. return this._rect;
  13937. }
  13938. };
  13939. zrUtil.inherits(Text, Displayable);
  13940. module.exports = Text;
  13941. /***/ },
  13942. /* 64 */
  13943. /***/ function(module, exports, __webpack_require__) {
  13944. 'use strict';
  13945. /**
  13946. * 圆形
  13947. * @module zrender/shape/Circle
  13948. */
  13949. module.exports = __webpack_require__(45).extend({
  13950. type: 'circle',
  13951. shape: {
  13952. cx: 0,
  13953. cy: 0,
  13954. r: 0
  13955. },
  13956. buildPath : function (ctx, shape, inBundle) {
  13957. // Better stroking in ShapeBundle
  13958. // Always do it may have performence issue ( fill may be 2x more cost)
  13959. if (inBundle) {
  13960. ctx.moveTo(shape.cx + shape.r, shape.cy);
  13961. }
  13962. // Better stroking in ShapeBundle
  13963. // ctx.moveTo(shape.cx + shape.r, shape.cy);
  13964. ctx.arc(shape.cx, shape.cy, shape.r, 0, Math.PI * 2, true);
  13965. }
  13966. });
  13967. /***/ },
  13968. /* 65 */
  13969. /***/ function(module, exports, __webpack_require__) {
  13970. /**
  13971. * 扇形
  13972. * @module zrender/graphic/shape/Sector
  13973. */
  13974. var env = __webpack_require__(2);
  13975. var Path = __webpack_require__(45);
  13976. var shadowTemp = [
  13977. ['shadowBlur', 0],
  13978. ['shadowColor', '#000'],
  13979. ['shadowOffsetX', 0],
  13980. ['shadowOffsetY', 0]
  13981. ];
  13982. module.exports = Path.extend({
  13983. type: 'sector',
  13984. shape: {
  13985. cx: 0,
  13986. cy: 0,
  13987. r0: 0,
  13988. r: 0,
  13989. startAngle: 0,
  13990. endAngle: Math.PI * 2,
  13991. clockwise: true
  13992. },
  13993. brush: (env.browser.ie && env.browser.version >= 11) // version: '11.0'
  13994. // Fix weird bug in some version of IE11 (like 11.0.9600.17801),
  13995. // where exception "unexpected call to method or property access"
  13996. // might be thrown when calling ctx.fill after a path whose area size
  13997. // is zero is drawn and ctx.clip() is called and shadowBlur is set.
  13998. // (e.g.,
  13999. // ctx.moveTo(10, 10);
  14000. // ctx.lineTo(20, 10);
  14001. // ctx.closePath();
  14002. // ctx.clip();
  14003. // ctx.shadowBlur = 10;
  14004. // ...
  14005. // ctx.fill();
  14006. // )
  14007. ? function () {
  14008. var clipPaths = this.__clipPaths;
  14009. var style = this.style;
  14010. var modified;
  14011. if (clipPaths) {
  14012. for (var i = 0; i < clipPaths.length; i++) {
  14013. var shape = clipPaths[i] && clipPaths[i].shape;
  14014. if (shape && shape.startAngle === shape.endAngle) {
  14015. for (var j = 0; j < shadowTemp.length; j++) {
  14016. shadowTemp[j][2] = style[shadowTemp[j][0]];
  14017. style[shadowTemp[j][0]] = shadowTemp[j][1];
  14018. }
  14019. modified = true;
  14020. break;
  14021. }
  14022. }
  14023. }
  14024. Path.prototype.brush.apply(this, arguments);
  14025. if (modified) {
  14026. for (var j = 0; j < shadowTemp.length; j++) {
  14027. style[shadowTemp[j][0]] = shadowTemp[j][2];
  14028. }
  14029. }
  14030. }
  14031. : Path.prototype.brush,
  14032. buildPath: function (ctx, shape) {
  14033. var x = shape.cx;
  14034. var y = shape.cy;
  14035. var r0 = Math.max(shape.r0 || 0, 0);
  14036. var r = Math.max(shape.r, 0);
  14037. var startAngle = shape.startAngle;
  14038. var endAngle = shape.endAngle;
  14039. var clockwise = shape.clockwise;
  14040. var unitX = Math.cos(startAngle);
  14041. var unitY = Math.sin(startAngle);
  14042. ctx.moveTo(unitX * r0 + x, unitY * r0 + y);
  14043. ctx.lineTo(unitX * r + x, unitY * r + y);
  14044. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  14045. ctx.lineTo(
  14046. Math.cos(endAngle) * r0 + x,
  14047. Math.sin(endAngle) * r0 + y
  14048. );
  14049. if (r0 !== 0) {
  14050. ctx.arc(x, y, r0, endAngle, startAngle, clockwise);
  14051. }
  14052. ctx.closePath();
  14053. }
  14054. });
  14055. /***/ },
  14056. /* 66 */
  14057. /***/ function(module, exports, __webpack_require__) {
  14058. /**
  14059. * 圆环
  14060. * @module zrender/graphic/shape/Ring
  14061. */
  14062. module.exports = __webpack_require__(45).extend({
  14063. type: 'ring',
  14064. shape: {
  14065. cx: 0,
  14066. cy: 0,
  14067. r: 0,
  14068. r0: 0
  14069. },
  14070. buildPath: function (ctx, shape) {
  14071. var x = shape.cx;
  14072. var y = shape.cy;
  14073. var PI2 = Math.PI * 2;
  14074. ctx.moveTo(x + shape.r, y);
  14075. ctx.arc(x, y, shape.r, 0, PI2, false);
  14076. ctx.moveTo(x + shape.r0, y);
  14077. ctx.arc(x, y, shape.r0, 0, PI2, true);
  14078. }
  14079. });
  14080. /***/ },
  14081. /* 67 */
  14082. /***/ function(module, exports, __webpack_require__) {
  14083. /**
  14084. * 多边形
  14085. * @module zrender/shape/Polygon
  14086. */
  14087. var polyHelper = __webpack_require__(68);
  14088. module.exports = __webpack_require__(45).extend({
  14089. type: 'polygon',
  14090. shape: {
  14091. points: null,
  14092. smooth: false,
  14093. smoothConstraint: null
  14094. },
  14095. buildPath: function (ctx, shape) {
  14096. polyHelper.buildPath(ctx, shape, true);
  14097. }
  14098. });
  14099. /***/ },
  14100. /* 68 */
  14101. /***/ function(module, exports, __webpack_require__) {
  14102. var smoothSpline = __webpack_require__(69);
  14103. var smoothBezier = __webpack_require__(70);
  14104. module.exports = {
  14105. buildPath: function (ctx, shape, closePath) {
  14106. var points = shape.points;
  14107. var smooth = shape.smooth;
  14108. if (points && points.length >= 2) {
  14109. if (smooth && smooth !== 'spline') {
  14110. var controlPoints = smoothBezier(
  14111. points, smooth, closePath, shape.smoothConstraint
  14112. );
  14113. ctx.moveTo(points[0][0], points[0][1]);
  14114. var len = points.length;
  14115. for (var i = 0; i < (closePath ? len : len - 1); i++) {
  14116. var cp1 = controlPoints[i * 2];
  14117. var cp2 = controlPoints[i * 2 + 1];
  14118. var p = points[(i + 1) % len];
  14119. ctx.bezierCurveTo(
  14120. cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]
  14121. );
  14122. }
  14123. }
  14124. else {
  14125. if (smooth === 'spline') {
  14126. points = smoothSpline(points, closePath);
  14127. }
  14128. ctx.moveTo(points[0][0], points[0][1]);
  14129. for (var i = 1, l = points.length; i < l; i++) {
  14130. ctx.lineTo(points[i][0], points[i][1]);
  14131. }
  14132. }
  14133. closePath && ctx.closePath();
  14134. }
  14135. }
  14136. };
  14137. /***/ },
  14138. /* 69 */
  14139. /***/ function(module, exports, __webpack_require__) {
  14140. /**
  14141. * Catmull-Rom spline 插值折线
  14142. * @module zrender/shape/util/smoothSpline
  14143. * @author pissang (https://www.github.com/pissang)
  14144. * Kener (@Kener-林峰, kener.linfeng@gmail.com)
  14145. * errorrik (errorrik@gmail.com)
  14146. */
  14147. var vec2 = __webpack_require__(10);
  14148. /**
  14149. * @inner
  14150. */
  14151. function interpolate(p0, p1, p2, p3, t, t2, t3) {
  14152. var v0 = (p2 - p0) * 0.5;
  14153. var v1 = (p3 - p1) * 0.5;
  14154. return (2 * (p1 - p2) + v0 + v1) * t3
  14155. + (-3 * (p1 - p2) - 2 * v0 - v1) * t2
  14156. + v0 * t + p1;
  14157. }
  14158. /**
  14159. * @alias module:zrender/shape/util/smoothSpline
  14160. * @param {Array} points 线段顶点数组
  14161. * @param {boolean} isLoop
  14162. * @return {Array}
  14163. */
  14164. module.exports = function (points, isLoop) {
  14165. var len = points.length;
  14166. var ret = [];
  14167. var distance = 0;
  14168. for (var i = 1; i < len; i++) {
  14169. distance += vec2.distance(points[i - 1], points[i]);
  14170. }
  14171. var segs = distance / 2;
  14172. segs = segs < len ? len : segs;
  14173. for (var i = 0; i < segs; i++) {
  14174. var pos = i / (segs - 1) * (isLoop ? len : len - 1);
  14175. var idx = Math.floor(pos);
  14176. var w = pos - idx;
  14177. var p0;
  14178. var p1 = points[idx % len];
  14179. var p2;
  14180. var p3;
  14181. if (!isLoop) {
  14182. p0 = points[idx === 0 ? idx : idx - 1];
  14183. p2 = points[idx > len - 2 ? len - 1 : idx + 1];
  14184. p3 = points[idx > len - 3 ? len - 1 : idx + 2];
  14185. }
  14186. else {
  14187. p0 = points[(idx - 1 + len) % len];
  14188. p2 = points[(idx + 1) % len];
  14189. p3 = points[(idx + 2) % len];
  14190. }
  14191. var w2 = w * w;
  14192. var w3 = w * w2;
  14193. ret.push([
  14194. interpolate(p0[0], p1[0], p2[0], p3[0], w, w2, w3),
  14195. interpolate(p0[1], p1[1], p2[1], p3[1], w, w2, w3)
  14196. ]);
  14197. }
  14198. return ret;
  14199. };
  14200. /***/ },
  14201. /* 70 */
  14202. /***/ function(module, exports, __webpack_require__) {
  14203. /**
  14204. * 贝塞尔平滑曲线
  14205. * @module zrender/shape/util/smoothBezier
  14206. * @author pissang (https://www.github.com/pissang)
  14207. * Kener (@Kener-林峰, kener.linfeng@gmail.com)
  14208. * errorrik (errorrik@gmail.com)
  14209. */
  14210. var vec2 = __webpack_require__(10);
  14211. var v2Min = vec2.min;
  14212. var v2Max = vec2.max;
  14213. var v2Scale = vec2.scale;
  14214. var v2Distance = vec2.distance;
  14215. var v2Add = vec2.add;
  14216. /**
  14217. * 贝塞尔平滑曲线
  14218. * @alias module:zrender/shape/util/smoothBezier
  14219. * @param {Array} points 线段顶点数组
  14220. * @param {number} smooth 平滑等级, 0-1
  14221. * @param {boolean} isLoop
  14222. * @param {Array} constraint 将计算出来的控制点约束在一个包围盒内
  14223. * 比如 [[0, 0], [100, 100]], 这个包围盒会与
  14224. * 整个折线的包围盒做一个并集用来约束控制点。
  14225. * @param {Array} 计算出来的控制点数组
  14226. */
  14227. module.exports = function (points, smooth, isLoop, constraint) {
  14228. var cps = [];
  14229. var v = [];
  14230. var v1 = [];
  14231. var v2 = [];
  14232. var prevPoint;
  14233. var nextPoint;
  14234. var min, max;
  14235. if (constraint) {
  14236. min = [Infinity, Infinity];
  14237. max = [-Infinity, -Infinity];
  14238. for (var i = 0, len = points.length; i < len; i++) {
  14239. v2Min(min, min, points[i]);
  14240. v2Max(max, max, points[i]);
  14241. }
  14242. // 与指定的包围盒做并集
  14243. v2Min(min, min, constraint[0]);
  14244. v2Max(max, max, constraint[1]);
  14245. }
  14246. for (var i = 0, len = points.length; i < len; i++) {
  14247. var point = points[i];
  14248. if (isLoop) {
  14249. prevPoint = points[i ? i - 1 : len - 1];
  14250. nextPoint = points[(i + 1) % len];
  14251. }
  14252. else {
  14253. if (i === 0 || i === len - 1) {
  14254. cps.push(vec2.clone(points[i]));
  14255. continue;
  14256. }
  14257. else {
  14258. prevPoint = points[i - 1];
  14259. nextPoint = points[i + 1];
  14260. }
  14261. }
  14262. vec2.sub(v, nextPoint, prevPoint);
  14263. // use degree to scale the handle length
  14264. v2Scale(v, v, smooth);
  14265. var d0 = v2Distance(point, prevPoint);
  14266. var d1 = v2Distance(point, nextPoint);
  14267. var sum = d0 + d1;
  14268. if (sum !== 0) {
  14269. d0 /= sum;
  14270. d1 /= sum;
  14271. }
  14272. v2Scale(v1, v, -d0);
  14273. v2Scale(v2, v, d1);
  14274. var cp0 = v2Add([], point, v1);
  14275. var cp1 = v2Add([], point, v2);
  14276. if (constraint) {
  14277. v2Max(cp0, cp0, min);
  14278. v2Min(cp0, cp0, max);
  14279. v2Max(cp1, cp1, min);
  14280. v2Min(cp1, cp1, max);
  14281. }
  14282. cps.push(cp0);
  14283. cps.push(cp1);
  14284. }
  14285. if (isLoop) {
  14286. cps.push(cps.shift());
  14287. }
  14288. return cps;
  14289. };
  14290. /***/ },
  14291. /* 71 */
  14292. /***/ function(module, exports, __webpack_require__) {
  14293. /**
  14294. * @module zrender/graphic/shape/Polyline
  14295. */
  14296. var polyHelper = __webpack_require__(68);
  14297. module.exports = __webpack_require__(45).extend({
  14298. type: 'polyline',
  14299. shape: {
  14300. points: null,
  14301. smooth: false,
  14302. smoothConstraint: null
  14303. },
  14304. style: {
  14305. stroke: '#000',
  14306. fill: null
  14307. },
  14308. buildPath: function (ctx, shape) {
  14309. polyHelper.buildPath(ctx, shape, false);
  14310. }
  14311. });
  14312. /***/ },
  14313. /* 72 */
  14314. /***/ function(module, exports, __webpack_require__) {
  14315. /**
  14316. * 矩形
  14317. * @module zrender/graphic/shape/Rect
  14318. */
  14319. var roundRectHelper = __webpack_require__(73);
  14320. module.exports = __webpack_require__(45).extend({
  14321. type: 'rect',
  14322. shape: {
  14323. // 左上、右上、右下、左下角的半径依次为r1、r2、r3、r4
  14324. // r缩写为1 相当于 [1, 1, 1, 1]
  14325. // r缩写为[1] 相当于 [1, 1, 1, 1]
  14326. // r缩写为[1, 2] 相当于 [1, 2, 1, 2]
  14327. // r缩写为[1, 2, 3] 相当于 [1, 2, 3, 2]
  14328. r: 0,
  14329. x: 0,
  14330. y: 0,
  14331. width: 0,
  14332. height: 0
  14333. },
  14334. buildPath: function (ctx, shape) {
  14335. var x = shape.x;
  14336. var y = shape.y;
  14337. var width = shape.width;
  14338. var height = shape.height;
  14339. if (!shape.r) {
  14340. ctx.rect(x, y, width, height);
  14341. }
  14342. else {
  14343. roundRectHelper.buildPath(ctx, shape);
  14344. }
  14345. ctx.closePath();
  14346. return;
  14347. }
  14348. });
  14349. /***/ },
  14350. /* 73 */
  14351. /***/ function(module, exports) {
  14352. module.exports = {
  14353. buildPath: function (ctx, shape) {
  14354. var x = shape.x;
  14355. var y = shape.y;
  14356. var width = shape.width;
  14357. var height = shape.height;
  14358. var r = shape.r;
  14359. var r1;
  14360. var r2;
  14361. var r3;
  14362. var r4;
  14363. // Convert width and height to positive for better borderRadius
  14364. if (width < 0) {
  14365. x = x + width;
  14366. width = -width;
  14367. }
  14368. if (height < 0) {
  14369. y = y + height;
  14370. height = -height;
  14371. }
  14372. if (typeof r === 'number') {
  14373. r1 = r2 = r3 = r4 = r;
  14374. }
  14375. else if (r instanceof Array) {
  14376. if (r.length === 1) {
  14377. r1 = r2 = r3 = r4 = r[0];
  14378. }
  14379. else if (r.length === 2) {
  14380. r1 = r3 = r[0];
  14381. r2 = r4 = r[1];
  14382. }
  14383. else if (r.length === 3) {
  14384. r1 = r[0];
  14385. r2 = r4 = r[1];
  14386. r3 = r[2];
  14387. }
  14388. else {
  14389. r1 = r[0];
  14390. r2 = r[1];
  14391. r3 = r[2];
  14392. r4 = r[3];
  14393. }
  14394. }
  14395. else {
  14396. r1 = r2 = r3 = r4 = 0;
  14397. }
  14398. var total;
  14399. if (r1 + r2 > width) {
  14400. total = r1 + r2;
  14401. r1 *= width / total;
  14402. r2 *= width / total;
  14403. }
  14404. if (r3 + r4 > width) {
  14405. total = r3 + r4;
  14406. r3 *= width / total;
  14407. r4 *= width / total;
  14408. }
  14409. if (r2 + r3 > height) {
  14410. total = r2 + r3;
  14411. r2 *= height / total;
  14412. r3 *= height / total;
  14413. }
  14414. if (r1 + r4 > height) {
  14415. total = r1 + r4;
  14416. r1 *= height / total;
  14417. r4 *= height / total;
  14418. }
  14419. ctx.moveTo(x + r1, y);
  14420. ctx.lineTo(x + width - r2, y);
  14421. r2 !== 0 && ctx.quadraticCurveTo(
  14422. x + width, y, x + width, y + r2
  14423. );
  14424. ctx.lineTo(x + width, y + height - r3);
  14425. r3 !== 0 && ctx.quadraticCurveTo(
  14426. x + width, y + height, x + width - r3, y + height
  14427. );
  14428. ctx.lineTo(x + r4, y + height);
  14429. r4 !== 0 && ctx.quadraticCurveTo(
  14430. x, y + height, x, y + height - r4
  14431. );
  14432. ctx.lineTo(x, y + r1);
  14433. r1 !== 0 && ctx.quadraticCurveTo(x, y, x + r1, y);
  14434. }
  14435. };
  14436. /***/ },
  14437. /* 74 */
  14438. /***/ function(module, exports, __webpack_require__) {
  14439. /**
  14440. * 直线
  14441. * @module zrender/graphic/shape/Line
  14442. */
  14443. module.exports = __webpack_require__(45).extend({
  14444. type: 'line',
  14445. shape: {
  14446. // Start point
  14447. x1: 0,
  14448. y1: 0,
  14449. // End point
  14450. x2: 0,
  14451. y2: 0,
  14452. percent: 1
  14453. },
  14454. style: {
  14455. stroke: '#000',
  14456. fill: null
  14457. },
  14458. buildPath: function (ctx, shape) {
  14459. var x1 = shape.x1;
  14460. var y1 = shape.y1;
  14461. var x2 = shape.x2;
  14462. var y2 = shape.y2;
  14463. var percent = shape.percent;
  14464. if (percent === 0) {
  14465. return;
  14466. }
  14467. ctx.moveTo(x1, y1);
  14468. if (percent < 1) {
  14469. x2 = x1 * (1 - percent) + x2 * percent;
  14470. y2 = y1 * (1 - percent) + y2 * percent;
  14471. }
  14472. ctx.lineTo(x2, y2);
  14473. },
  14474. /**
  14475. * Get point at percent
  14476. * @param {number} percent
  14477. * @return {Array.<number>}
  14478. */
  14479. pointAt: function (p) {
  14480. var shape = this.shape;
  14481. return [
  14482. shape.x1 * (1 - p) + shape.x2 * p,
  14483. shape.y1 * (1 - p) + shape.y2 * p
  14484. ];
  14485. }
  14486. });
  14487. /***/ },
  14488. /* 75 */
  14489. /***/ function(module, exports, __webpack_require__) {
  14490. 'use strict';
  14491. /**
  14492. * 贝塞尔曲线
  14493. * @module zrender/shape/BezierCurve
  14494. */
  14495. var curveTool = __webpack_require__(50);
  14496. var vec2 = __webpack_require__(10);
  14497. var quadraticSubdivide = curveTool.quadraticSubdivide;
  14498. var cubicSubdivide = curveTool.cubicSubdivide;
  14499. var quadraticAt = curveTool.quadraticAt;
  14500. var cubicAt = curveTool.cubicAt;
  14501. var quadraticDerivativeAt = curveTool.quadraticDerivativeAt;
  14502. var cubicDerivativeAt = curveTool.cubicDerivativeAt;
  14503. var out = [];
  14504. function someVectorAt(shape, t, isTangent) {
  14505. var cpx2 = shape.cpx2;
  14506. var cpy2 = shape.cpy2;
  14507. if (cpx2 === null || cpy2 === null) {
  14508. return [
  14509. (isTangent ? cubicDerivativeAt : cubicAt)(shape.x1, shape.cpx1, shape.cpx2, shape.x2, t),
  14510. (isTangent ? cubicDerivativeAt : cubicAt)(shape.y1, shape.cpy1, shape.cpy2, shape.y2, t)
  14511. ];
  14512. }
  14513. else {
  14514. return [
  14515. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.x1, shape.cpx1, shape.x2, t),
  14516. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.y1, shape.cpy1, shape.y2, t)
  14517. ];
  14518. }
  14519. }
  14520. module.exports = __webpack_require__(45).extend({
  14521. type: 'bezier-curve',
  14522. shape: {
  14523. x1: 0,
  14524. y1: 0,
  14525. x2: 0,
  14526. y2: 0,
  14527. cpx1: 0,
  14528. cpy1: 0,
  14529. // cpx2: 0,
  14530. // cpy2: 0
  14531. // Curve show percent, for animating
  14532. percent: 1
  14533. },
  14534. style: {
  14535. stroke: '#000',
  14536. fill: null
  14537. },
  14538. buildPath: function (ctx, shape) {
  14539. var x1 = shape.x1;
  14540. var y1 = shape.y1;
  14541. var x2 = shape.x2;
  14542. var y2 = shape.y2;
  14543. var cpx1 = shape.cpx1;
  14544. var cpy1 = shape.cpy1;
  14545. var cpx2 = shape.cpx2;
  14546. var cpy2 = shape.cpy2;
  14547. var percent = shape.percent;
  14548. if (percent === 0) {
  14549. return;
  14550. }
  14551. ctx.moveTo(x1, y1);
  14552. if (cpx2 == null || cpy2 == null) {
  14553. if (percent < 1) {
  14554. quadraticSubdivide(
  14555. x1, cpx1, x2, percent, out
  14556. );
  14557. cpx1 = out[1];
  14558. x2 = out[2];
  14559. quadraticSubdivide(
  14560. y1, cpy1, y2, percent, out
  14561. );
  14562. cpy1 = out[1];
  14563. y2 = out[2];
  14564. }
  14565. ctx.quadraticCurveTo(
  14566. cpx1, cpy1,
  14567. x2, y2
  14568. );
  14569. }
  14570. else {
  14571. if (percent < 1) {
  14572. cubicSubdivide(
  14573. x1, cpx1, cpx2, x2, percent, out
  14574. );
  14575. cpx1 = out[1];
  14576. cpx2 = out[2];
  14577. x2 = out[3];
  14578. cubicSubdivide(
  14579. y1, cpy1, cpy2, y2, percent, out
  14580. );
  14581. cpy1 = out[1];
  14582. cpy2 = out[2];
  14583. y2 = out[3];
  14584. }
  14585. ctx.bezierCurveTo(
  14586. cpx1, cpy1,
  14587. cpx2, cpy2,
  14588. x2, y2
  14589. );
  14590. }
  14591. },
  14592. /**
  14593. * Get point at percent
  14594. * @param {number} t
  14595. * @return {Array.<number>}
  14596. */
  14597. pointAt: function (t) {
  14598. return someVectorAt(this.shape, t, false);
  14599. },
  14600. /**
  14601. * Get tangent at percent
  14602. * @param {number} t
  14603. * @return {Array.<number>}
  14604. */
  14605. tangentAt: function (t) {
  14606. var p = someVectorAt(this.shape, t, true);
  14607. return vec2.normalize(p, p);
  14608. }
  14609. });
  14610. /***/ },
  14611. /* 76 */
  14612. /***/ function(module, exports, __webpack_require__) {
  14613. /**
  14614. * 圆弧
  14615. * @module zrender/graphic/shape/Arc
  14616. */
  14617. module.exports = __webpack_require__(45).extend({
  14618. type: 'arc',
  14619. shape: {
  14620. cx: 0,
  14621. cy: 0,
  14622. r: 0,
  14623. startAngle: 0,
  14624. endAngle: Math.PI * 2,
  14625. clockwise: true
  14626. },
  14627. style: {
  14628. stroke: '#000',
  14629. fill: null
  14630. },
  14631. buildPath: function (ctx, shape) {
  14632. var x = shape.cx;
  14633. var y = shape.cy;
  14634. var r = Math.max(shape.r, 0);
  14635. var startAngle = shape.startAngle;
  14636. var endAngle = shape.endAngle;
  14637. var clockwise = shape.clockwise;
  14638. var unitX = Math.cos(startAngle);
  14639. var unitY = Math.sin(startAngle);
  14640. ctx.moveTo(unitX * r + x, unitY * r + y);
  14641. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  14642. }
  14643. });
  14644. /***/ },
  14645. /* 77 */
  14646. /***/ function(module, exports, __webpack_require__) {
  14647. // CompoundPath to improve performance
  14648. var Path = __webpack_require__(45);
  14649. module.exports = Path.extend({
  14650. type: 'compound',
  14651. shape: {
  14652. paths: null
  14653. },
  14654. _updatePathDirty: function () {
  14655. var dirtyPath = this.__dirtyPath;
  14656. var paths = this.shape.paths;
  14657. for (var i = 0; i < paths.length; i++) {
  14658. // Mark as dirty if any subpath is dirty
  14659. dirtyPath = dirtyPath || paths[i].__dirtyPath;
  14660. }
  14661. this.__dirtyPath = dirtyPath;
  14662. this.__dirty = this.__dirty || dirtyPath;
  14663. },
  14664. beforeBrush: function () {
  14665. this._updatePathDirty();
  14666. var paths = this.shape.paths || [];
  14667. var scale = this.getGlobalScale();
  14668. // Update path scale
  14669. for (var i = 0; i < paths.length; i++) {
  14670. paths[i].path.setScale(scale[0], scale[1]);
  14671. }
  14672. },
  14673. buildPath: function (ctx, shape) {
  14674. var paths = shape.paths || [];
  14675. for (var i = 0; i < paths.length; i++) {
  14676. paths[i].buildPath(ctx, paths[i].shape, true);
  14677. }
  14678. },
  14679. afterBrush: function () {
  14680. var paths = this.shape.paths;
  14681. for (var i = 0; i < paths.length; i++) {
  14682. paths[i].__dirtyPath = false;
  14683. }
  14684. },
  14685. getBoundingRect: function () {
  14686. this._updatePathDirty();
  14687. return Path.prototype.getBoundingRect.call(this);
  14688. }
  14689. });
  14690. /***/ },
  14691. /* 78 */
  14692. /***/ function(module, exports, __webpack_require__) {
  14693. 'use strict';
  14694. var zrUtil = __webpack_require__(4);
  14695. var Gradient = __webpack_require__(79);
  14696. /**
  14697. * x, y, x2, y2 are all percent from 0 to 1
  14698. * @param {number} [x=0]
  14699. * @param {number} [y=0]
  14700. * @param {number} [x2=1]
  14701. * @param {number} [y2=0]
  14702. * @param {Array.<Object>} colorStops
  14703. * @param {boolean} [globalCoord=false]
  14704. */
  14705. var LinearGradient = function (x, y, x2, y2, colorStops, globalCoord) {
  14706. this.x = x == null ? 0 : x;
  14707. this.y = y == null ? 0 : y;
  14708. this.x2 = x2 == null ? 1 : x2;
  14709. this.y2 = y2 == null ? 0 : y2;
  14710. // Can be cloned
  14711. this.type = 'linear';
  14712. // If use global coord
  14713. this.global = globalCoord || false;
  14714. Gradient.call(this, colorStops);
  14715. };
  14716. LinearGradient.prototype = {
  14717. constructor: LinearGradient
  14718. };
  14719. zrUtil.inherits(LinearGradient, Gradient);
  14720. module.exports = LinearGradient;
  14721. /***/ },
  14722. /* 79 */
  14723. /***/ function(module, exports) {
  14724. /**
  14725. * @param {Array.<Object>} colorStops
  14726. */
  14727. var Gradient = function (colorStops) {
  14728. this.colorStops = colorStops || [];
  14729. };
  14730. Gradient.prototype = {
  14731. constructor: Gradient,
  14732. addColorStop: function (offset, color) {
  14733. this.colorStops.push({
  14734. offset: offset,
  14735. color: color
  14736. });
  14737. }
  14738. };
  14739. module.exports = Gradient;
  14740. /***/ },
  14741. /* 80 */
  14742. /***/ function(module, exports, __webpack_require__) {
  14743. 'use strict';
  14744. var zrUtil = __webpack_require__(4);
  14745. var Gradient = __webpack_require__(79);
  14746. /**
  14747. * x, y, r are all percent from 0 to 1
  14748. * @param {number} [x=0.5]
  14749. * @param {number} [y=0.5]
  14750. * @param {number} [r=0.5]
  14751. * @param {Array.<Object>} [colorStops]
  14752. * @param {boolean} [globalCoord=false]
  14753. */
  14754. var RadialGradient = function (x, y, r, colorStops, globalCoord) {
  14755. this.x = x == null ? 0.5 : x;
  14756. this.y = y == null ? 0.5 : y;
  14757. this.r = r == null ? 0.5 : r;
  14758. // Can be cloned
  14759. this.type = 'radial';
  14760. // If use global coord
  14761. this.global = globalCoord || false;
  14762. Gradient.call(this, colorStops);
  14763. };
  14764. RadialGradient.prototype = {
  14765. constructor: RadialGradient
  14766. };
  14767. zrUtil.inherits(RadialGradient, Gradient);
  14768. module.exports = RadialGradient;
  14769. /***/ },
  14770. /* 81 */
  14771. /***/ function(module, exports) {
  14772. var lib = {};
  14773. var ORIGIN_METHOD = '\0__throttleOriginMethod';
  14774. var RATE = '\0__throttleRate';
  14775. var THROTTLE_TYPE = '\0__throttleType';
  14776. /**
  14777. * @public
  14778. * @param {(Function)} fn
  14779. * @param {number} [delay=0] Unit: ms.
  14780. * @param {boolean} [debounce=false]
  14781. * true: If call interval less than `delay`, only the last call works.
  14782. * false: If call interval less than `delay, call works on fixed rate.
  14783. * @return {(Function)} throttled fn.
  14784. */
  14785. lib.throttle = function (fn, delay, debounce) {
  14786. var currCall;
  14787. var lastCall = 0;
  14788. var lastExec = 0;
  14789. var timer = null;
  14790. var diff;
  14791. var scope;
  14792. var args;
  14793. delay = delay || 0;
  14794. function exec() {
  14795. lastExec = (new Date()).getTime();
  14796. timer = null;
  14797. fn.apply(scope, args || []);
  14798. }
  14799. var cb = function () {
  14800. currCall = (new Date()).getTime();
  14801. scope = this;
  14802. args = arguments;
  14803. diff = currCall - (debounce ? lastCall : lastExec) - delay;
  14804. clearTimeout(timer);
  14805. if (debounce) {
  14806. timer = setTimeout(exec, delay);
  14807. }
  14808. else {
  14809. if (diff >= 0) {
  14810. exec();
  14811. }
  14812. else {
  14813. timer = setTimeout(exec, -diff);
  14814. }
  14815. }
  14816. lastCall = currCall;
  14817. };
  14818. /**
  14819. * Clear throttle.
  14820. * @public
  14821. */
  14822. cb.clear = function () {
  14823. if (timer) {
  14824. clearTimeout(timer);
  14825. timer = null;
  14826. }
  14827. };
  14828. return cb;
  14829. };
  14830. /**
  14831. * Create throttle method or update throttle rate.
  14832. *
  14833. * @example
  14834. * ComponentView.prototype.render = function () {
  14835. * ...
  14836. * throttle.createOrUpdate(
  14837. * this,
  14838. * '_dispatchAction',
  14839. * this.model.get('throttle'),
  14840. * 'fixRate'
  14841. * );
  14842. * };
  14843. * ComponentView.prototype.remove = function () {
  14844. * throttle.clear(this, '_dispatchAction');
  14845. * };
  14846. * ComponentView.prototype.dispose = function () {
  14847. * throttle.clear(this, '_dispatchAction');
  14848. * };
  14849. *
  14850. * @public
  14851. * @param {Object} obj
  14852. * @param {string} fnAttr
  14853. * @param {number} [rate]
  14854. * @param {string} [throttleType='fixRate'] 'fixRate' or 'debounce'
  14855. * @return {Function} throttled function.
  14856. */
  14857. lib.createOrUpdate = function (obj, fnAttr, rate, throttleType) {
  14858. var fn = obj[fnAttr];
  14859. if (!fn) {
  14860. return;
  14861. }
  14862. var originFn = fn[ORIGIN_METHOD] || fn;
  14863. var lastThrottleType = fn[THROTTLE_TYPE];
  14864. var lastRate = fn[RATE];
  14865. if (lastRate !== rate || lastThrottleType !== throttleType) {
  14866. if (rate == null || !throttleType) {
  14867. return (obj[fnAttr] = originFn);
  14868. }
  14869. fn = obj[fnAttr] = lib.throttle(
  14870. originFn, rate, throttleType === 'debounce'
  14871. );
  14872. fn[ORIGIN_METHOD] = originFn;
  14873. fn[THROTTLE_TYPE] = throttleType;
  14874. fn[RATE] = rate;
  14875. }
  14876. return fn;
  14877. };
  14878. /**
  14879. * Clear throttle. Example see throttle.createOrUpdate.
  14880. *
  14881. * @public
  14882. * @param {Object} obj
  14883. * @param {string} fnAttr
  14884. */
  14885. lib.clear = function (obj, fnAttr) {
  14886. var fn = obj[fnAttr];
  14887. if (fn && fn[ORIGIN_METHOD]) {
  14888. obj[fnAttr] = fn[ORIGIN_METHOD];
  14889. }
  14890. };
  14891. module.exports = lib;
  14892. /***/ },
  14893. /* 82 */
  14894. /***/ function(module, exports, __webpack_require__) {
  14895. /*!
  14896. * ZRender, a high performance 2d drawing library.
  14897. *
  14898. * Copyright (c) 2013, Baidu Inc.
  14899. * All rights reserved.
  14900. *
  14901. * LICENSE
  14902. * https://github.com/ecomfe/zrender/blob/master/LICENSE.txt
  14903. */
  14904. // Global defines
  14905. var guid = __webpack_require__(32);
  14906. var env = __webpack_require__(2);
  14907. var zrUtil = __webpack_require__(4);
  14908. var Handler = __webpack_require__(83);
  14909. var Storage = __webpack_require__(85);
  14910. var Animation = __webpack_require__(87);
  14911. var HandlerProxy = __webpack_require__(90);
  14912. var useVML = !env.canvasSupported;
  14913. var painterCtors = {
  14914. canvas: __webpack_require__(92)
  14915. };
  14916. var instances = {}; // ZRender实例map索引
  14917. var zrender = {};
  14918. /**
  14919. * @type {string}
  14920. */
  14921. zrender.version = '3.3.0';
  14922. /**
  14923. * Initializing a zrender instance
  14924. * @param {HTMLElement} dom
  14925. * @param {Object} opts
  14926. * @param {string} [opts.renderer='canvas'] 'canvas' or 'svg'
  14927. * @param {number} [opts.devicePixelRatio]
  14928. * @param {number|string} [opts.width] Can be 'auto' (the same as null/undefined)
  14929. * @param {number|string} [opts.height] Can be 'auto' (the same as null/undefined)
  14930. * @return {module:zrender/ZRender}
  14931. */
  14932. zrender.init = function(dom, opts) {
  14933. var zr = new ZRender(guid(), dom, opts);
  14934. instances[zr.id] = zr;
  14935. return zr;
  14936. };
  14937. /**
  14938. * Dispose zrender instance
  14939. * @param {module:zrender/ZRender} zr
  14940. */
  14941. zrender.dispose = function (zr) {
  14942. if (zr) {
  14943. zr.dispose();
  14944. }
  14945. else {
  14946. for (var key in instances) {
  14947. if (instances.hasOwnProperty(key)) {
  14948. instances[key].dispose();
  14949. }
  14950. }
  14951. instances = {};
  14952. }
  14953. return zrender;
  14954. };
  14955. /**
  14956. * Get zrender instance by id
  14957. * @param {string} id zrender instance id
  14958. * @return {module:zrender/ZRender}
  14959. */
  14960. zrender.getInstance = function (id) {
  14961. return instances[id];
  14962. };
  14963. zrender.registerPainter = function (name, Ctor) {
  14964. painterCtors[name] = Ctor;
  14965. };
  14966. function delInstance(id) {
  14967. delete instances[id];
  14968. }
  14969. /**
  14970. * @module zrender/ZRender
  14971. */
  14972. /**
  14973. * @constructor
  14974. * @alias module:zrender/ZRender
  14975. * @param {string} id
  14976. * @param {HTMLDomElement} dom
  14977. * @param {Object} opts
  14978. * @param {string} [opts.renderer='canvas'] 'canvas' or 'svg'
  14979. * @param {number} [opts.devicePixelRatio]
  14980. * @param {number} [opts.width] Can be 'auto' (the same as null/undefined)
  14981. * @param {number} [opts.height] Can be 'auto' (the same as null/undefined)
  14982. */
  14983. var ZRender = function(id, dom, opts) {
  14984. opts = opts || {};
  14985. /**
  14986. * @type {HTMLDomElement}
  14987. */
  14988. this.dom = dom;
  14989. /**
  14990. * @type {string}
  14991. */
  14992. this.id = id;
  14993. var self = this;
  14994. var storage = new Storage();
  14995. var rendererType = opts.renderer;
  14996. if (useVML) {
  14997. if (!painterCtors.vml) {
  14998. throw new Error('You need to require \'zrender/vml/vml\' to support IE8');
  14999. }
  15000. rendererType = 'vml';
  15001. }
  15002. else if (!rendererType || !painterCtors[rendererType]) {
  15003. rendererType = 'canvas';
  15004. }
  15005. var painter = new painterCtors[rendererType](dom, storage, opts);
  15006. this.storage = storage;
  15007. this.painter = painter;
  15008. var handerProxy = !env.node ? new HandlerProxy(painter.getViewportRoot()) : null;
  15009. this.handler = new Handler(storage, painter, handerProxy, painter.root);
  15010. /**
  15011. * @type {module:zrender/animation/Animation}
  15012. */
  15013. this.animation = new Animation({
  15014. stage: {
  15015. update: zrUtil.bind(this.flush, this)
  15016. }
  15017. });
  15018. this.animation.start();
  15019. /**
  15020. * @type {boolean}
  15021. * @private
  15022. */
  15023. this._needsRefresh;
  15024. // 修改 storage.delFromMap, 每次删除元素之前删除动画
  15025. // FIXME 有点ugly
  15026. var oldDelFromMap = storage.delFromMap;
  15027. var oldAddToMap = storage.addToMap;
  15028. storage.delFromMap = function (elId) {
  15029. var el = storage.get(elId);
  15030. oldDelFromMap.call(storage, elId);
  15031. el && el.removeSelfFromZr(self);
  15032. };
  15033. storage.addToMap = function (el) {
  15034. oldAddToMap.call(storage, el);
  15035. el.addSelfToZr(self);
  15036. };
  15037. };
  15038. ZRender.prototype = {
  15039. constructor: ZRender,
  15040. /**
  15041. * 获取实例唯一标识
  15042. * @return {string}
  15043. */
  15044. getId: function () {
  15045. return this.id;
  15046. },
  15047. /**
  15048. * 添加元素
  15049. * @param {module:zrender/Element} el
  15050. */
  15051. add: function (el) {
  15052. this.storage.addRoot(el);
  15053. this._needsRefresh = true;
  15054. },
  15055. /**
  15056. * 删除元素
  15057. * @param {module:zrender/Element} el
  15058. */
  15059. remove: function (el) {
  15060. this.storage.delRoot(el);
  15061. this._needsRefresh = true;
  15062. },
  15063. /**
  15064. * Change configuration of layer
  15065. * @param {string} zLevel
  15066. * @param {Object} config
  15067. * @param {string} [config.clearColor=0] Clear color
  15068. * @param {string} [config.motionBlur=false] If enable motion blur
  15069. * @param {number} [config.lastFrameAlpha=0.7] Motion blur factor. Larger value cause longer trailer
  15070. */
  15071. configLayer: function (zLevel, config) {
  15072. this.painter.configLayer(zLevel, config);
  15073. this._needsRefresh = true;
  15074. },
  15075. /**
  15076. * Repaint the canvas immediately
  15077. */
  15078. refreshImmediately: function () {
  15079. // Clear needsRefresh ahead to avoid something wrong happens in refresh
  15080. // Or it will cause zrender refreshes again and again.
  15081. this._needsRefresh = false;
  15082. this.painter.refresh();
  15083. /**
  15084. * Avoid trigger zr.refresh in Element#beforeUpdate hook
  15085. */
  15086. this._needsRefresh = false;
  15087. },
  15088. /**
  15089. * Mark and repaint the canvas in the next frame of browser
  15090. */
  15091. refresh: function() {
  15092. this._needsRefresh = true;
  15093. },
  15094. /**
  15095. * Perform all refresh
  15096. */
  15097. flush: function () {
  15098. if (this._needsRefresh) {
  15099. this.refreshImmediately();
  15100. }
  15101. if (this._needsRefreshHover) {
  15102. this.refreshHoverImmediately();
  15103. }
  15104. },
  15105. /**
  15106. * Add element to hover layer
  15107. * @param {module:zrender/Element} el
  15108. * @param {Object} style
  15109. */
  15110. addHover: function (el, style) {
  15111. if (this.painter.addHover) {
  15112. this.painter.addHover(el, style);
  15113. this.refreshHover();
  15114. }
  15115. },
  15116. /**
  15117. * Add element from hover layer
  15118. * @param {module:zrender/Element} el
  15119. */
  15120. removeHover: function (el) {
  15121. if (this.painter.removeHover) {
  15122. this.painter.removeHover(el);
  15123. this.refreshHover();
  15124. }
  15125. },
  15126. /**
  15127. * Clear all hover elements in hover layer
  15128. * @param {module:zrender/Element} el
  15129. */
  15130. clearHover: function () {
  15131. if (this.painter.clearHover) {
  15132. this.painter.clearHover();
  15133. this.refreshHover();
  15134. }
  15135. },
  15136. /**
  15137. * Refresh hover in next frame
  15138. */
  15139. refreshHover: function () {
  15140. this._needsRefreshHover = true;
  15141. },
  15142. /**
  15143. * Refresh hover immediately
  15144. */
  15145. refreshHoverImmediately: function () {
  15146. this._needsRefreshHover = false;
  15147. this.painter.refreshHover && this.painter.refreshHover();
  15148. },
  15149. /**
  15150. * Resize the canvas.
  15151. * Should be invoked when container size is changed
  15152. * @param {Object} [opts]
  15153. * @param {number|string} [opts.width] Can be 'auto' (the same as null/undefined)
  15154. * @param {number|string} [opts.height] Can be 'auto' (the same as null/undefined)
  15155. */
  15156. resize: function(opts) {
  15157. opts = opts || {};
  15158. this.painter.resize(opts.width, opts.height);
  15159. this.handler.resize();
  15160. },
  15161. /**
  15162. * Stop and clear all animation immediately
  15163. */
  15164. clearAnimation: function () {
  15165. this.animation.clear();
  15166. },
  15167. /**
  15168. * Get container width
  15169. */
  15170. getWidth: function() {
  15171. return this.painter.getWidth();
  15172. },
  15173. /**
  15174. * Get container height
  15175. */
  15176. getHeight: function() {
  15177. return this.painter.getHeight();
  15178. },
  15179. /**
  15180. * Export the canvas as Base64 URL
  15181. * @param {string} type
  15182. * @param {string} [backgroundColor='#fff']
  15183. * @return {string} Base64 URL
  15184. */
  15185. // toDataURL: function(type, backgroundColor) {
  15186. // return this.painter.getRenderedCanvas({
  15187. // backgroundColor: backgroundColor
  15188. // }).toDataURL(type);
  15189. // },
  15190. /**
  15191. * Converting a path to image.
  15192. * It has much better performance of drawing image rather than drawing a vector path.
  15193. * @param {module:zrender/graphic/Path} e
  15194. * @param {number} width
  15195. * @param {number} height
  15196. */
  15197. pathToImage: function(e, width, height) {
  15198. var id = guid();
  15199. return this.painter.pathToImage(id, e, width, height);
  15200. },
  15201. /**
  15202. * Set default cursor
  15203. * @param {string} [cursorStyle='default'] 例如 crosshair
  15204. */
  15205. setCursorStyle: function (cursorStyle) {
  15206. this.handler.setCursorStyle(cursorStyle);
  15207. },
  15208. /**
  15209. * Bind event
  15210. *
  15211. * @param {string} eventName Event name
  15212. * @param {Function} eventHandler Handler function
  15213. * @param {Object} [context] Context object
  15214. */
  15215. on: function(eventName, eventHandler, context) {
  15216. this.handler.on(eventName, eventHandler, context);
  15217. },
  15218. /**
  15219. * Unbind event
  15220. * @param {string} eventName Event name
  15221. * @param {Function} [eventHandler] Handler function
  15222. */
  15223. off: function(eventName, eventHandler) {
  15224. this.handler.off(eventName, eventHandler);
  15225. },
  15226. /**
  15227. * Trigger event manually
  15228. *
  15229. * @param {string} eventName Event name
  15230. * @param {event=} event Event object
  15231. */
  15232. trigger: function (eventName, event) {
  15233. this.handler.trigger(eventName, event);
  15234. },
  15235. /**
  15236. * Clear all objects and the canvas.
  15237. */
  15238. clear: function () {
  15239. this.storage.delRoot();
  15240. this.painter.clear();
  15241. },
  15242. /**
  15243. * Dispose self.
  15244. */
  15245. dispose: function () {
  15246. this.animation.stop();
  15247. this.clear();
  15248. this.storage.dispose();
  15249. this.painter.dispose();
  15250. this.handler.dispose();
  15251. this.animation =
  15252. this.storage =
  15253. this.painter =
  15254. this.handler = null;
  15255. delInstance(this.id);
  15256. }
  15257. };
  15258. module.exports = zrender;
  15259. /***/ },
  15260. /* 83 */
  15261. /***/ function(module, exports, __webpack_require__) {
  15262. 'use strict';
  15263. /**
  15264. * Handler
  15265. * @module zrender/Handler
  15266. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  15267. * errorrik (errorrik@gmail.com)
  15268. * pissang (shenyi.914@gmail.com)
  15269. */
  15270. var util = __webpack_require__(4);
  15271. var Draggable = __webpack_require__(84);
  15272. var Eventful = __webpack_require__(33);
  15273. function makeEventPacket(eveType, target, event) {
  15274. return {
  15275. type: eveType,
  15276. event: event,
  15277. target: target,
  15278. cancelBubble: false,
  15279. offsetX: event.zrX,
  15280. offsetY: event.zrY,
  15281. gestureEvent: event.gestureEvent,
  15282. pinchX: event.pinchX,
  15283. pinchY: event.pinchY,
  15284. pinchScale: event.pinchScale,
  15285. wheelDelta: event.zrDelta,
  15286. zrByTouch: event.zrByTouch
  15287. };
  15288. }
  15289. function EmptyProxy () {}
  15290. EmptyProxy.prototype.dispose = function () {};
  15291. var handlerNames = [
  15292. 'click', 'dblclick', 'mousewheel', 'mouseout',
  15293. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  15294. ];
  15295. /**
  15296. * @alias module:zrender/Handler
  15297. * @constructor
  15298. * @extends module:zrender/mixin/Eventful
  15299. * @param {module:zrender/Storage} storage Storage instance.
  15300. * @param {module:zrender/Painter} painter Painter instance.
  15301. * @param {module:zrender/dom/HandlerProxy} proxy HandlerProxy instance.
  15302. * @param {HTMLElement} painterRoot painter.root (not painter.getViewportRoot()).
  15303. */
  15304. var Handler = function(storage, painter, proxy, painterRoot) {
  15305. Eventful.call(this);
  15306. this.storage = storage;
  15307. this.painter = painter;
  15308. this.painterRoot = painterRoot;
  15309. proxy = proxy || new EmptyProxy();
  15310. /**
  15311. * Proxy of event. can be Dom, WebGLSurface, etc.
  15312. */
  15313. this.proxy = proxy;
  15314. // Attach handler
  15315. proxy.handler = this;
  15316. /**
  15317. * @private
  15318. * @type {boolean}
  15319. */
  15320. this._hovered;
  15321. /**
  15322. * @private
  15323. * @type {Date}
  15324. */
  15325. this._lastTouchMoment;
  15326. /**
  15327. * @private
  15328. * @type {number}
  15329. */
  15330. this._lastX;
  15331. /**
  15332. * @private
  15333. * @type {number}
  15334. */
  15335. this._lastY;
  15336. Draggable.call(this);
  15337. util.each(handlerNames, function (name) {
  15338. proxy.on && proxy.on(name, this[name], this);
  15339. }, this);
  15340. };
  15341. Handler.prototype = {
  15342. constructor: Handler,
  15343. mousemove: function (event) {
  15344. var x = event.zrX;
  15345. var y = event.zrY;
  15346. var hovered = this.findHover(x, y, null);
  15347. var lastHovered = this._hovered;
  15348. var proxy = this.proxy;
  15349. this._hovered = hovered;
  15350. proxy.setCursor && proxy.setCursor(hovered ? hovered.cursor : 'default');
  15351. // Mouse out on previous hovered element
  15352. if (lastHovered && hovered !== lastHovered && lastHovered.__zr) {
  15353. this.dispatchToElement(lastHovered, 'mouseout', event);
  15354. }
  15355. // Mouse moving on one element
  15356. this.dispatchToElement(hovered, 'mousemove', event);
  15357. // Mouse over on a new element
  15358. if (hovered && hovered !== lastHovered) {
  15359. this.dispatchToElement(hovered, 'mouseover', event);
  15360. }
  15361. },
  15362. mouseout: function (event) {
  15363. this.dispatchToElement(this._hovered, 'mouseout', event);
  15364. // There might be some doms created by upper layer application
  15365. // at the same level of painter.getViewportRoot() (e.g., tooltip
  15366. // dom created by echarts), where 'globalout' event should not
  15367. // be triggered when mouse enters these doms. (But 'mouseout'
  15368. // should be triggered at the original hovered element as usual).
  15369. var element = event.toElement || event.relatedTarget;
  15370. var innerDom;
  15371. do {
  15372. element = element && element.parentNode;
  15373. }
  15374. while (element && element.nodeType != 9 && !(
  15375. innerDom = element === this.painterRoot
  15376. ));
  15377. !innerDom && this.trigger('globalout', {event: event});
  15378. },
  15379. /**
  15380. * Resize
  15381. */
  15382. resize: function (event) {
  15383. this._hovered = null;
  15384. },
  15385. /**
  15386. * Dispatch event
  15387. * @param {string} eventName
  15388. * @param {event=} eventArgs
  15389. */
  15390. dispatch: function (eventName, eventArgs) {
  15391. var handler = this[eventName];
  15392. handler && handler.call(this, eventArgs);
  15393. },
  15394. /**
  15395. * Dispose
  15396. */
  15397. dispose: function () {
  15398. this.proxy.dispose();
  15399. this.storage =
  15400. this.proxy =
  15401. this.painter = null;
  15402. },
  15403. /**
  15404. * 设置默认的cursor style
  15405. * @param {string} [cursorStyle='default'] 例如 crosshair
  15406. */
  15407. setCursorStyle: function (cursorStyle) {
  15408. var proxy = this.proxy;
  15409. proxy.setCursor && proxy.setCursor(cursorStyle);
  15410. },
  15411. /**
  15412. * 事件分发代理
  15413. *
  15414. * @private
  15415. * @param {Object} targetEl 目标图形元素
  15416. * @param {string} eventName 事件名称
  15417. * @param {Object} event 事件对象
  15418. */
  15419. dispatchToElement: function (targetEl, eventName, event) {
  15420. var eventHandler = 'on' + eventName;
  15421. var eventPacket = makeEventPacket(eventName, targetEl, event);
  15422. var el = targetEl;
  15423. while (el) {
  15424. el[eventHandler]
  15425. && (eventPacket.cancelBubble = el[eventHandler].call(el, eventPacket));
  15426. el.trigger(eventName, eventPacket);
  15427. el = el.parent;
  15428. if (eventPacket.cancelBubble) {
  15429. break;
  15430. }
  15431. }
  15432. if (!eventPacket.cancelBubble) {
  15433. // 冒泡到顶级 zrender 对象
  15434. this.trigger(eventName, eventPacket);
  15435. // 分发事件到用户自定义层
  15436. // 用户有可能在全局 click 事件中 dispose,所以需要判断下 painter 是否存在
  15437. this.painter && this.painter.eachOtherLayer(function (layer) {
  15438. if (typeof(layer[eventHandler]) == 'function') {
  15439. layer[eventHandler].call(layer, eventPacket);
  15440. }
  15441. if (layer.trigger) {
  15442. layer.trigger(eventName, eventPacket);
  15443. }
  15444. });
  15445. }
  15446. },
  15447. /**
  15448. * @private
  15449. * @param {number} x
  15450. * @param {number} y
  15451. * @param {module:zrender/graphic/Displayable} exclude
  15452. * @method
  15453. */
  15454. findHover: function(x, y, exclude) {
  15455. var list = this.storage.getDisplayList();
  15456. for (var i = list.length - 1; i >= 0 ; i--) {
  15457. if (!list[i].silent
  15458. && list[i] !== exclude
  15459. // getDisplayList may include ignored item in VML mode
  15460. && !list[i].ignore
  15461. && isHover(list[i], x, y)) {
  15462. return list[i];
  15463. }
  15464. }
  15465. }
  15466. };
  15467. // Common handlers
  15468. util.each(['click', 'mousedown', 'mouseup', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  15469. Handler.prototype[name] = function (event) {
  15470. // Find hover again to avoid click event is dispatched manually. Or click is triggered without mouseover
  15471. var hovered = this.findHover(event.zrX, event.zrY, null);
  15472. if (name === 'mousedown') {
  15473. this._downel = hovered;
  15474. // In case click triggered before mouseup
  15475. this._upel = hovered;
  15476. }
  15477. else if (name === 'mosueup') {
  15478. this._upel = hovered;
  15479. }
  15480. else if (name === 'click') {
  15481. if (this._downel !== this._upel) {
  15482. return;
  15483. }
  15484. }
  15485. this.dispatchToElement(hovered, name, event);
  15486. };
  15487. });
  15488. function isHover(displayable, x, y) {
  15489. if (displayable[displayable.rectHover ? 'rectContain' : 'contain'](x, y)) {
  15490. var el = displayable;
  15491. while (el) {
  15492. // If ancestor is silent or clipped by ancestor
  15493. if (el.silent || (el.clipPath && !el.clipPath.contain(x, y))) {
  15494. return false;
  15495. }
  15496. el = el.parent;
  15497. }
  15498. return true;
  15499. }
  15500. return false;
  15501. }
  15502. util.mixin(Handler, Eventful);
  15503. util.mixin(Handler, Draggable);
  15504. module.exports = Handler;
  15505. /***/ },
  15506. /* 84 */
  15507. /***/ function(module, exports) {
  15508. // TODO Draggable for group
  15509. // FIXME Draggable on element which has parent rotation or scale
  15510. function Draggable() {
  15511. this.on('mousedown', this._dragStart, this);
  15512. this.on('mousemove', this._drag, this);
  15513. this.on('mouseup', this._dragEnd, this);
  15514. this.on('globalout', this._dragEnd, this);
  15515. // this._dropTarget = null;
  15516. // this._draggingTarget = null;
  15517. // this._x = 0;
  15518. // this._y = 0;
  15519. }
  15520. Draggable.prototype = {
  15521. constructor: Draggable,
  15522. _dragStart: function (e) {
  15523. var draggingTarget = e.target;
  15524. if (draggingTarget && draggingTarget.draggable) {
  15525. this._draggingTarget = draggingTarget;
  15526. draggingTarget.dragging = true;
  15527. this._x = e.offsetX;
  15528. this._y = e.offsetY;
  15529. this.dispatchToElement(draggingTarget, 'dragstart', e.event);
  15530. }
  15531. },
  15532. _drag: function (e) {
  15533. var draggingTarget = this._draggingTarget;
  15534. if (draggingTarget) {
  15535. var x = e.offsetX;
  15536. var y = e.offsetY;
  15537. var dx = x - this._x;
  15538. var dy = y - this._y;
  15539. this._x = x;
  15540. this._y = y;
  15541. draggingTarget.drift(dx, dy, e);
  15542. this.dispatchToElement(draggingTarget, 'drag', e.event);
  15543. var dropTarget = this.findHover(x, y, draggingTarget);
  15544. var lastDropTarget = this._dropTarget;
  15545. this._dropTarget = dropTarget;
  15546. if (draggingTarget !== dropTarget) {
  15547. if (lastDropTarget && dropTarget !== lastDropTarget) {
  15548. this.dispatchToElement(lastDropTarget, 'dragleave', e.event);
  15549. }
  15550. if (dropTarget && dropTarget !== lastDropTarget) {
  15551. this.dispatchToElement(dropTarget, 'dragenter', e.event);
  15552. }
  15553. }
  15554. }
  15555. },
  15556. _dragEnd: function (e) {
  15557. var draggingTarget = this._draggingTarget;
  15558. if (draggingTarget) {
  15559. draggingTarget.dragging = false;
  15560. }
  15561. this.dispatchToElement(draggingTarget, 'dragend', e.event);
  15562. if (this._dropTarget) {
  15563. this.dispatchToElement(this._dropTarget, 'drop', e.event);
  15564. }
  15565. this._draggingTarget = null;
  15566. this._dropTarget = null;
  15567. }
  15568. };
  15569. module.exports = Draggable;
  15570. /***/ },
  15571. /* 85 */
  15572. /***/ function(module, exports, __webpack_require__) {
  15573. 'use strict';
  15574. /**
  15575. * Storage内容仓库模块
  15576. * @module zrender/Storage
  15577. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  15578. * @author errorrik (errorrik@gmail.com)
  15579. * @author pissang (https://github.com/pissang/)
  15580. */
  15581. var util = __webpack_require__(4);
  15582. var env = __webpack_require__(2);
  15583. var Group = __webpack_require__(30);
  15584. // Use timsort because in most case elements are partially sorted
  15585. // https://jsfiddle.net/pissang/jr4x7mdm/8/
  15586. var timsort = __webpack_require__(86);
  15587. function shapeCompareFunc(a, b) {
  15588. if (a.zlevel === b.zlevel) {
  15589. if (a.z === b.z) {
  15590. // if (a.z2 === b.z2) {
  15591. // // FIXME Slow has renderidx compare
  15592. // // http://stackoverflow.com/questions/20883421/sorting-in-javascript-should-every-compare-function-have-a-return-0-statement
  15593. // // https://github.com/v8/v8/blob/47cce544a31ed5577ffe2963f67acb4144ee0232/src/js/array.js#L1012
  15594. // return a.__renderidx - b.__renderidx;
  15595. // }
  15596. return a.z2 - b.z2;
  15597. }
  15598. return a.z - b.z;
  15599. }
  15600. return a.zlevel - b.zlevel;
  15601. }
  15602. /**
  15603. * 内容仓库 (M)
  15604. * @alias module:zrender/Storage
  15605. * @constructor
  15606. */
  15607. var Storage = function () {
  15608. // 所有常规形状,id索引的map
  15609. this._elements = {};
  15610. this._roots = [];
  15611. this._displayList = [];
  15612. this._displayListLen = 0;
  15613. };
  15614. Storage.prototype = {
  15615. constructor: Storage,
  15616. /**
  15617. * @param {Function} cb
  15618. *
  15619. */
  15620. traverse: function (cb, context) {
  15621. for (var i = 0; i < this._roots.length; i++) {
  15622. this._roots[i].traverse(cb, context);
  15623. }
  15624. },
  15625. /**
  15626. * 返回所有图形的绘制队列
  15627. * @param {boolean} [update=false] 是否在返回前更新该数组
  15628. * @param {boolean} [includeIgnore=false] 是否包含 ignore 的数组, 在 update 为 true 的时候有效
  15629. *
  15630. * 详见{@link module:zrender/graphic/Displayable.prototype.updateDisplayList}
  15631. * @return {Array.<module:zrender/graphic/Displayable>}
  15632. */
  15633. getDisplayList: function (update, includeIgnore) {
  15634. includeIgnore = includeIgnore || false;
  15635. if (update) {
  15636. this.updateDisplayList(includeIgnore);
  15637. }
  15638. return this._displayList;
  15639. },
  15640. /**
  15641. * 更新图形的绘制队列。
  15642. * 每次绘制前都会调用,该方法会先深度优先遍历整个树,更新所有Group和Shape的变换并且把所有可见的Shape保存到数组中,
  15643. * 最后根据绘制的优先级(zlevel > z > 插入顺序)排序得到绘制队列
  15644. * @param {boolean} [includeIgnore=false] 是否包含 ignore 的数组
  15645. */
  15646. updateDisplayList: function (includeIgnore) {
  15647. this._displayListLen = 0;
  15648. var roots = this._roots;
  15649. var displayList = this._displayList;
  15650. for (var i = 0, len = roots.length; i < len; i++) {
  15651. this._updateAndAddDisplayable(roots[i], null, includeIgnore);
  15652. }
  15653. displayList.length = this._displayListLen;
  15654. // for (var i = 0, len = displayList.length; i < len; i++) {
  15655. // displayList[i].__renderidx = i;
  15656. // }
  15657. // displayList.sort(shapeCompareFunc);
  15658. env.canvasSupported && timsort(displayList, shapeCompareFunc);
  15659. },
  15660. _updateAndAddDisplayable: function (el, clipPaths, includeIgnore) {
  15661. if (el.ignore && !includeIgnore) {
  15662. return;
  15663. }
  15664. el.beforeUpdate();
  15665. if (el.__dirty) {
  15666. el.update();
  15667. }
  15668. el.afterUpdate();
  15669. var userSetClipPath = el.clipPath;
  15670. if (userSetClipPath) {
  15671. // FIXME 效率影响
  15672. if (clipPaths) {
  15673. clipPaths = clipPaths.slice();
  15674. }
  15675. else {
  15676. clipPaths = [];
  15677. }
  15678. var currentClipPath = userSetClipPath;
  15679. var parentClipPath = el;
  15680. // Recursively add clip path
  15681. while (currentClipPath) {
  15682. // clipPath 的变换是基于使用这个 clipPath 的元素
  15683. currentClipPath.parent = parentClipPath;
  15684. currentClipPath.updateTransform();
  15685. clipPaths.push(currentClipPath);
  15686. parentClipPath = currentClipPath;
  15687. currentClipPath = currentClipPath.clipPath;
  15688. }
  15689. }
  15690. if (el.isGroup) {
  15691. var children = el._children;
  15692. for (var i = 0; i < children.length; i++) {
  15693. var child = children[i];
  15694. // Force to mark as dirty if group is dirty
  15695. // FIXME __dirtyPath ?
  15696. if (el.__dirty) {
  15697. child.__dirty = true;
  15698. }
  15699. this._updateAndAddDisplayable(child, clipPaths, includeIgnore);
  15700. }
  15701. // Mark group clean here
  15702. el.__dirty = false;
  15703. }
  15704. else {
  15705. el.__clipPaths = clipPaths;
  15706. this._displayList[this._displayListLen++] = el;
  15707. }
  15708. },
  15709. /**
  15710. * 添加图形(Shape)或者组(Group)到根节点
  15711. * @param {module:zrender/Element} el
  15712. */
  15713. addRoot: function (el) {
  15714. // Element has been added
  15715. if (this._elements[el.id]) {
  15716. return;
  15717. }
  15718. if (el instanceof Group) {
  15719. el.addChildrenToStorage(this);
  15720. }
  15721. this.addToMap(el);
  15722. this._roots.push(el);
  15723. },
  15724. /**
  15725. * 删除指定的图形(Shape)或者组(Group)
  15726. * @param {string|Array.<string>} [elId] 如果为空清空整个Storage
  15727. */
  15728. delRoot: function (elId) {
  15729. if (elId == null) {
  15730. // 不指定elId清空
  15731. for (var i = 0; i < this._roots.length; i++) {
  15732. var root = this._roots[i];
  15733. if (root instanceof Group) {
  15734. root.delChildrenFromStorage(this);
  15735. }
  15736. }
  15737. this._elements = {};
  15738. this._roots = [];
  15739. this._displayList = [];
  15740. this._displayListLen = 0;
  15741. return;
  15742. }
  15743. if (elId instanceof Array) {
  15744. for (var i = 0, l = elId.length; i < l; i++) {
  15745. this.delRoot(elId[i]);
  15746. }
  15747. return;
  15748. }
  15749. var el;
  15750. if (typeof(elId) == 'string') {
  15751. el = this._elements[elId];
  15752. }
  15753. else {
  15754. el = elId;
  15755. }
  15756. var idx = util.indexOf(this._roots, el);
  15757. if (idx >= 0) {
  15758. this.delFromMap(el.id);
  15759. this._roots.splice(idx, 1);
  15760. if (el instanceof Group) {
  15761. el.delChildrenFromStorage(this);
  15762. }
  15763. }
  15764. },
  15765. addToMap: function (el) {
  15766. if (el instanceof Group) {
  15767. el.__storage = this;
  15768. }
  15769. el.dirty(false);
  15770. this._elements[el.id] = el;
  15771. return this;
  15772. },
  15773. get: function (elId) {
  15774. return this._elements[elId];
  15775. },
  15776. delFromMap: function (elId) {
  15777. var elements = this._elements;
  15778. var el = elements[elId];
  15779. if (el) {
  15780. delete elements[elId];
  15781. if (el instanceof Group) {
  15782. el.__storage = null;
  15783. }
  15784. }
  15785. return this;
  15786. },
  15787. /**
  15788. * 清空并且释放Storage
  15789. */
  15790. dispose: function () {
  15791. this._elements =
  15792. this._renderList =
  15793. this._roots = null;
  15794. },
  15795. displayableSortFunc: shapeCompareFunc
  15796. };
  15797. module.exports = Storage;
  15798. /***/ },
  15799. /* 86 */
  15800. /***/ function(module, exports) {
  15801. // https://github.com/mziccard/node-timsort
  15802. var DEFAULT_MIN_MERGE = 32;
  15803. var DEFAULT_MIN_GALLOPING = 7;
  15804. var DEFAULT_TMP_STORAGE_LENGTH = 256;
  15805. function minRunLength(n) {
  15806. var r = 0;
  15807. while (n >= DEFAULT_MIN_MERGE) {
  15808. r |= n & 1;
  15809. n >>= 1;
  15810. }
  15811. return n + r;
  15812. }
  15813. function makeAscendingRun(array, lo, hi, compare) {
  15814. var runHi = lo + 1;
  15815. if (runHi === hi) {
  15816. return 1;
  15817. }
  15818. if (compare(array[runHi++], array[lo]) < 0) {
  15819. while (runHi < hi && compare(array[runHi], array[runHi - 1]) < 0) {
  15820. runHi++;
  15821. }
  15822. reverseRun(array, lo, runHi);
  15823. }
  15824. else {
  15825. while (runHi < hi && compare(array[runHi], array[runHi - 1]) >= 0) {
  15826. runHi++;
  15827. }
  15828. }
  15829. return runHi - lo;
  15830. }
  15831. function reverseRun(array, lo, hi) {
  15832. hi--;
  15833. while (lo < hi) {
  15834. var t = array[lo];
  15835. array[lo++] = array[hi];
  15836. array[hi--] = t;
  15837. }
  15838. }
  15839. function binaryInsertionSort(array, lo, hi, start, compare) {
  15840. if (start === lo) {
  15841. start++;
  15842. }
  15843. for (; start < hi; start++) {
  15844. var pivot = array[start];
  15845. var left = lo;
  15846. var right = start;
  15847. var mid;
  15848. while (left < right) {
  15849. mid = left + right >>> 1;
  15850. if (compare(pivot, array[mid]) < 0) {
  15851. right = mid;
  15852. }
  15853. else {
  15854. left = mid + 1;
  15855. }
  15856. }
  15857. var n = start - left;
  15858. switch (n) {
  15859. case 3:
  15860. array[left + 3] = array[left + 2];
  15861. case 2:
  15862. array[left + 2] = array[left + 1];
  15863. case 1:
  15864. array[left + 1] = array[left];
  15865. break;
  15866. default:
  15867. while (n > 0) {
  15868. array[left + n] = array[left + n - 1];
  15869. n--;
  15870. }
  15871. }
  15872. array[left] = pivot;
  15873. }
  15874. }
  15875. function gallopLeft(value, array, start, length, hint, compare) {
  15876. var lastOffset = 0;
  15877. var maxOffset = 0;
  15878. var offset = 1;
  15879. if (compare(value, array[start + hint]) > 0) {
  15880. maxOffset = length - hint;
  15881. while (offset < maxOffset && compare(value, array[start + hint + offset]) > 0) {
  15882. lastOffset = offset;
  15883. offset = (offset << 1) + 1;
  15884. if (offset <= 0) {
  15885. offset = maxOffset;
  15886. }
  15887. }
  15888. if (offset > maxOffset) {
  15889. offset = maxOffset;
  15890. }
  15891. lastOffset += hint;
  15892. offset += hint;
  15893. }
  15894. else {
  15895. maxOffset = hint + 1;
  15896. while (offset < maxOffset && compare(value, array[start + hint - offset]) <= 0) {
  15897. lastOffset = offset;
  15898. offset = (offset << 1) + 1;
  15899. if (offset <= 0) {
  15900. offset = maxOffset;
  15901. }
  15902. }
  15903. if (offset > maxOffset) {
  15904. offset = maxOffset;
  15905. }
  15906. var tmp = lastOffset;
  15907. lastOffset = hint - offset;
  15908. offset = hint - tmp;
  15909. }
  15910. lastOffset++;
  15911. while (lastOffset < offset) {
  15912. var m = lastOffset + (offset - lastOffset >>> 1);
  15913. if (compare(value, array[start + m]) > 0) {
  15914. lastOffset = m + 1;
  15915. }
  15916. else {
  15917. offset = m;
  15918. }
  15919. }
  15920. return offset;
  15921. }
  15922. function gallopRight(value, array, start, length, hint, compare) {
  15923. var lastOffset = 0;
  15924. var maxOffset = 0;
  15925. var offset = 1;
  15926. if (compare(value, array[start + hint]) < 0) {
  15927. maxOffset = hint + 1;
  15928. while (offset < maxOffset && compare(value, array[start + hint - offset]) < 0) {
  15929. lastOffset = offset;
  15930. offset = (offset << 1) + 1;
  15931. if (offset <= 0) {
  15932. offset = maxOffset;
  15933. }
  15934. }
  15935. if (offset > maxOffset) {
  15936. offset = maxOffset;
  15937. }
  15938. var tmp = lastOffset;
  15939. lastOffset = hint - offset;
  15940. offset = hint - tmp;
  15941. }
  15942. else {
  15943. maxOffset = length - hint;
  15944. while (offset < maxOffset && compare(value, array[start + hint + offset]) >= 0) {
  15945. lastOffset = offset;
  15946. offset = (offset << 1) + 1;
  15947. if (offset <= 0) {
  15948. offset = maxOffset;
  15949. }
  15950. }
  15951. if (offset > maxOffset) {
  15952. offset = maxOffset;
  15953. }
  15954. lastOffset += hint;
  15955. offset += hint;
  15956. }
  15957. lastOffset++;
  15958. while (lastOffset < offset) {
  15959. var m = lastOffset + (offset - lastOffset >>> 1);
  15960. if (compare(value, array[start + m]) < 0) {
  15961. offset = m;
  15962. }
  15963. else {
  15964. lastOffset = m + 1;
  15965. }
  15966. }
  15967. return offset;
  15968. }
  15969. function TimSort(array, compare) {
  15970. var minGallop = DEFAULT_MIN_GALLOPING;
  15971. var length = 0;
  15972. var tmpStorageLength = DEFAULT_TMP_STORAGE_LENGTH;
  15973. var stackLength = 0;
  15974. var runStart;
  15975. var runLength;
  15976. var stackSize = 0;
  15977. length = array.length;
  15978. if (length < 2 * DEFAULT_TMP_STORAGE_LENGTH) {
  15979. tmpStorageLength = length >>> 1;
  15980. }
  15981. var tmp = [];
  15982. stackLength = length < 120 ? 5 : length < 1542 ? 10 : length < 119151 ? 19 : 40;
  15983. runStart = [];
  15984. runLength = [];
  15985. function pushRun(_runStart, _runLength) {
  15986. runStart[stackSize] = _runStart;
  15987. runLength[stackSize] = _runLength;
  15988. stackSize += 1;
  15989. }
  15990. function mergeRuns() {
  15991. while (stackSize > 1) {
  15992. var n = stackSize - 2;
  15993. if (n >= 1 && runLength[n - 1] <= runLength[n] + runLength[n + 1] || n >= 2 && runLength[n - 2] <= runLength[n] + runLength[n - 1]) {
  15994. if (runLength[n - 1] < runLength[n + 1]) {
  15995. n--;
  15996. }
  15997. }
  15998. else if (runLength[n] > runLength[n + 1]) {
  15999. break;
  16000. }
  16001. mergeAt(n);
  16002. }
  16003. }
  16004. function forceMergeRuns() {
  16005. while (stackSize > 1) {
  16006. var n = stackSize - 2;
  16007. if (n > 0 && runLength[n - 1] < runLength[n + 1]) {
  16008. n--;
  16009. }
  16010. mergeAt(n);
  16011. }
  16012. }
  16013. function mergeAt(i) {
  16014. var start1 = runStart[i];
  16015. var length1 = runLength[i];
  16016. var start2 = runStart[i + 1];
  16017. var length2 = runLength[i + 1];
  16018. runLength[i] = length1 + length2;
  16019. if (i === stackSize - 3) {
  16020. runStart[i + 1] = runStart[i + 2];
  16021. runLength[i + 1] = runLength[i + 2];
  16022. }
  16023. stackSize--;
  16024. var k = gallopRight(array[start2], array, start1, length1, 0, compare);
  16025. start1 += k;
  16026. length1 -= k;
  16027. if (length1 === 0) {
  16028. return;
  16029. }
  16030. length2 = gallopLeft(array[start1 + length1 - 1], array, start2, length2, length2 - 1, compare);
  16031. if (length2 === 0) {
  16032. return;
  16033. }
  16034. if (length1 <= length2) {
  16035. mergeLow(start1, length1, start2, length2);
  16036. }
  16037. else {
  16038. mergeHigh(start1, length1, start2, length2);
  16039. }
  16040. }
  16041. function mergeLow(start1, length1, start2, length2) {
  16042. var i = 0;
  16043. for (i = 0; i < length1; i++) {
  16044. tmp[i] = array[start1 + i];
  16045. }
  16046. var cursor1 = 0;
  16047. var cursor2 = start2;
  16048. var dest = start1;
  16049. array[dest++] = array[cursor2++];
  16050. if (--length2 === 0) {
  16051. for (i = 0; i < length1; i++) {
  16052. array[dest + i] = tmp[cursor1 + i];
  16053. }
  16054. return;
  16055. }
  16056. if (length1 === 1) {
  16057. for (i = 0; i < length2; i++) {
  16058. array[dest + i] = array[cursor2 + i];
  16059. }
  16060. array[dest + length2] = tmp[cursor1];
  16061. return;
  16062. }
  16063. var _minGallop = minGallop;
  16064. var count1, count2, exit;
  16065. while (1) {
  16066. count1 = 0;
  16067. count2 = 0;
  16068. exit = false;
  16069. do {
  16070. if (compare(array[cursor2], tmp[cursor1]) < 0) {
  16071. array[dest++] = array[cursor2++];
  16072. count2++;
  16073. count1 = 0;
  16074. if (--length2 === 0) {
  16075. exit = true;
  16076. break;
  16077. }
  16078. }
  16079. else {
  16080. array[dest++] = tmp[cursor1++];
  16081. count1++;
  16082. count2 = 0;
  16083. if (--length1 === 1) {
  16084. exit = true;
  16085. break;
  16086. }
  16087. }
  16088. } while ((count1 | count2) < _minGallop);
  16089. if (exit) {
  16090. break;
  16091. }
  16092. do {
  16093. count1 = gallopRight(array[cursor2], tmp, cursor1, length1, 0, compare);
  16094. if (count1 !== 0) {
  16095. for (i = 0; i < count1; i++) {
  16096. array[dest + i] = tmp[cursor1 + i];
  16097. }
  16098. dest += count1;
  16099. cursor1 += count1;
  16100. length1 -= count1;
  16101. if (length1 <= 1) {
  16102. exit = true;
  16103. break;
  16104. }
  16105. }
  16106. array[dest++] = array[cursor2++];
  16107. if (--length2 === 0) {
  16108. exit = true;
  16109. break;
  16110. }
  16111. count2 = gallopLeft(tmp[cursor1], array, cursor2, length2, 0, compare);
  16112. if (count2 !== 0) {
  16113. for (i = 0; i < count2; i++) {
  16114. array[dest + i] = array[cursor2 + i];
  16115. }
  16116. dest += count2;
  16117. cursor2 += count2;
  16118. length2 -= count2;
  16119. if (length2 === 0) {
  16120. exit = true;
  16121. break;
  16122. }
  16123. }
  16124. array[dest++] = tmp[cursor1++];
  16125. if (--length1 === 1) {
  16126. exit = true;
  16127. break;
  16128. }
  16129. _minGallop--;
  16130. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  16131. if (exit) {
  16132. break;
  16133. }
  16134. if (_minGallop < 0) {
  16135. _minGallop = 0;
  16136. }
  16137. _minGallop += 2;
  16138. }
  16139. minGallop = _minGallop;
  16140. minGallop < 1 && (minGallop = 1);
  16141. if (length1 === 1) {
  16142. for (i = 0; i < length2; i++) {
  16143. array[dest + i] = array[cursor2 + i];
  16144. }
  16145. array[dest + length2] = tmp[cursor1];
  16146. }
  16147. else if (length1 === 0) {
  16148. throw new Error();
  16149. // throw new Error('mergeLow preconditions were not respected');
  16150. }
  16151. else {
  16152. for (i = 0; i < length1; i++) {
  16153. array[dest + i] = tmp[cursor1 + i];
  16154. }
  16155. }
  16156. }
  16157. function mergeHigh (start1, length1, start2, length2) {
  16158. var i = 0;
  16159. for (i = 0; i < length2; i++) {
  16160. tmp[i] = array[start2 + i];
  16161. }
  16162. var cursor1 = start1 + length1 - 1;
  16163. var cursor2 = length2 - 1;
  16164. var dest = start2 + length2 - 1;
  16165. var customCursor = 0;
  16166. var customDest = 0;
  16167. array[dest--] = array[cursor1--];
  16168. if (--length1 === 0) {
  16169. customCursor = dest - (length2 - 1);
  16170. for (i = 0; i < length2; i++) {
  16171. array[customCursor + i] = tmp[i];
  16172. }
  16173. return;
  16174. }
  16175. if (length2 === 1) {
  16176. dest -= length1;
  16177. cursor1 -= length1;
  16178. customDest = dest + 1;
  16179. customCursor = cursor1 + 1;
  16180. for (i = length1 - 1; i >= 0; i--) {
  16181. array[customDest + i] = array[customCursor + i];
  16182. }
  16183. array[dest] = tmp[cursor2];
  16184. return;
  16185. }
  16186. var _minGallop = minGallop;
  16187. while (true) {
  16188. var count1 = 0;
  16189. var count2 = 0;
  16190. var exit = false;
  16191. do {
  16192. if (compare(tmp[cursor2], array[cursor1]) < 0) {
  16193. array[dest--] = array[cursor1--];
  16194. count1++;
  16195. count2 = 0;
  16196. if (--length1 === 0) {
  16197. exit = true;
  16198. break;
  16199. }
  16200. }
  16201. else {
  16202. array[dest--] = tmp[cursor2--];
  16203. count2++;
  16204. count1 = 0;
  16205. if (--length2 === 1) {
  16206. exit = true;
  16207. break;
  16208. }
  16209. }
  16210. } while ((count1 | count2) < _minGallop);
  16211. if (exit) {
  16212. break;
  16213. }
  16214. do {
  16215. count1 = length1 - gallopRight(tmp[cursor2], array, start1, length1, length1 - 1, compare);
  16216. if (count1 !== 0) {
  16217. dest -= count1;
  16218. cursor1 -= count1;
  16219. length1 -= count1;
  16220. customDest = dest + 1;
  16221. customCursor = cursor1 + 1;
  16222. for (i = count1 - 1; i >= 0; i--) {
  16223. array[customDest + i] = array[customCursor + i];
  16224. }
  16225. if (length1 === 0) {
  16226. exit = true;
  16227. break;
  16228. }
  16229. }
  16230. array[dest--] = tmp[cursor2--];
  16231. if (--length2 === 1) {
  16232. exit = true;
  16233. break;
  16234. }
  16235. count2 = length2 - gallopLeft(array[cursor1], tmp, 0, length2, length2 - 1, compare);
  16236. if (count2 !== 0) {
  16237. dest -= count2;
  16238. cursor2 -= count2;
  16239. length2 -= count2;
  16240. customDest = dest + 1;
  16241. customCursor = cursor2 + 1;
  16242. for (i = 0; i < count2; i++) {
  16243. array[customDest + i] = tmp[customCursor + i];
  16244. }
  16245. if (length2 <= 1) {
  16246. exit = true;
  16247. break;
  16248. }
  16249. }
  16250. array[dest--] = array[cursor1--];
  16251. if (--length1 === 0) {
  16252. exit = true;
  16253. break;
  16254. }
  16255. _minGallop--;
  16256. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  16257. if (exit) {
  16258. break;
  16259. }
  16260. if (_minGallop < 0) {
  16261. _minGallop = 0;
  16262. }
  16263. _minGallop += 2;
  16264. }
  16265. minGallop = _minGallop;
  16266. if (minGallop < 1) {
  16267. minGallop = 1;
  16268. }
  16269. if (length2 === 1) {
  16270. dest -= length1;
  16271. cursor1 -= length1;
  16272. customDest = dest + 1;
  16273. customCursor = cursor1 + 1;
  16274. for (i = length1 - 1; i >= 0; i--) {
  16275. array[customDest + i] = array[customCursor + i];
  16276. }
  16277. array[dest] = tmp[cursor2];
  16278. }
  16279. else if (length2 === 0) {
  16280. throw new Error();
  16281. // throw new Error('mergeHigh preconditions were not respected');
  16282. }
  16283. else {
  16284. customCursor = dest - (length2 - 1);
  16285. for (i = 0; i < length2; i++) {
  16286. array[customCursor + i] = tmp[i];
  16287. }
  16288. }
  16289. }
  16290. this.mergeRuns = mergeRuns;
  16291. this.forceMergeRuns = forceMergeRuns;
  16292. this.pushRun = pushRun;
  16293. }
  16294. function sort(array, compare, lo, hi) {
  16295. if (!lo) {
  16296. lo = 0;
  16297. }
  16298. if (!hi) {
  16299. hi = array.length;
  16300. }
  16301. var remaining = hi - lo;
  16302. if (remaining < 2) {
  16303. return;
  16304. }
  16305. var runLength = 0;
  16306. if (remaining < DEFAULT_MIN_MERGE) {
  16307. runLength = makeAscendingRun(array, lo, hi, compare);
  16308. binaryInsertionSort(array, lo, hi, lo + runLength, compare);
  16309. return;
  16310. }
  16311. var ts = new TimSort(array, compare);
  16312. var minRun = minRunLength(remaining);
  16313. do {
  16314. runLength = makeAscendingRun(array, lo, hi, compare);
  16315. if (runLength < minRun) {
  16316. var force = remaining;
  16317. if (force > minRun) {
  16318. force = minRun;
  16319. }
  16320. binaryInsertionSort(array, lo, lo + force, lo + runLength, compare);
  16321. runLength = force;
  16322. }
  16323. ts.pushRun(lo, runLength);
  16324. ts.mergeRuns();
  16325. remaining -= runLength;
  16326. lo += runLength;
  16327. } while (remaining !== 0);
  16328. ts.forceMergeRuns();
  16329. }
  16330. module.exports = sort;
  16331. /***/ },
  16332. /* 87 */
  16333. /***/ function(module, exports, __webpack_require__) {
  16334. 'use strict';
  16335. /**
  16336. * 动画主类, 调度和管理所有动画控制器
  16337. *
  16338. * @module zrender/animation/Animation
  16339. * @author pissang(https://github.com/pissang)
  16340. */
  16341. // TODO Additive animation
  16342. // http://iosoteric.com/additive-animations-animatewithduration-in-ios-8/
  16343. // https://developer.apple.com/videos/wwdc2014/#236
  16344. var util = __webpack_require__(4);
  16345. var Dispatcher = __webpack_require__(88).Dispatcher;
  16346. var requestAnimationFrame = __webpack_require__(89);
  16347. var Animator = __webpack_require__(36);
  16348. /**
  16349. * @typedef {Object} IZRenderStage
  16350. * @property {Function} update
  16351. */
  16352. /**
  16353. * @alias module:zrender/animation/Animation
  16354. * @constructor
  16355. * @param {Object} [options]
  16356. * @param {Function} [options.onframe]
  16357. * @param {IZRenderStage} [options.stage]
  16358. * @example
  16359. * var animation = new Animation();
  16360. * var obj = {
  16361. * x: 100,
  16362. * y: 100
  16363. * };
  16364. * animation.animate(node.position)
  16365. * .when(1000, {
  16366. * x: 500,
  16367. * y: 500
  16368. * })
  16369. * .when(2000, {
  16370. * x: 100,
  16371. * y: 100
  16372. * })
  16373. * .start('spline');
  16374. */
  16375. var Animation = function (options) {
  16376. options = options || {};
  16377. this.stage = options.stage || {};
  16378. this.onframe = options.onframe || function() {};
  16379. // private properties
  16380. this._clips = [];
  16381. this._running = false;
  16382. this._time;
  16383. this._pausedTime;
  16384. this._pauseStart;
  16385. this._paused = false;
  16386. Dispatcher.call(this);
  16387. };
  16388. Animation.prototype = {
  16389. constructor: Animation,
  16390. /**
  16391. * 添加 clip
  16392. * @param {module:zrender/animation/Clip} clip
  16393. */
  16394. addClip: function (clip) {
  16395. this._clips.push(clip);
  16396. },
  16397. /**
  16398. * 添加 animator
  16399. * @param {module:zrender/animation/Animator} animator
  16400. */
  16401. addAnimator: function (animator) {
  16402. animator.animation = this;
  16403. var clips = animator.getClips();
  16404. for (var i = 0; i < clips.length; i++) {
  16405. this.addClip(clips[i]);
  16406. }
  16407. },
  16408. /**
  16409. * 删除动画片段
  16410. * @param {module:zrender/animation/Clip} clip
  16411. */
  16412. removeClip: function(clip) {
  16413. var idx = util.indexOf(this._clips, clip);
  16414. if (idx >= 0) {
  16415. this._clips.splice(idx, 1);
  16416. }
  16417. },
  16418. /**
  16419. * 删除动画片段
  16420. * @param {module:zrender/animation/Animator} animator
  16421. */
  16422. removeAnimator: function (animator) {
  16423. var clips = animator.getClips();
  16424. for (var i = 0; i < clips.length; i++) {
  16425. this.removeClip(clips[i]);
  16426. }
  16427. animator.animation = null;
  16428. },
  16429. _update: function() {
  16430. var time = new Date().getTime() - this._pausedTime;
  16431. var delta = time - this._time;
  16432. var clips = this._clips;
  16433. var len = clips.length;
  16434. var deferredEvents = [];
  16435. var deferredClips = [];
  16436. for (var i = 0; i < len; i++) {
  16437. var clip = clips[i];
  16438. var e = clip.step(time);
  16439. // Throw out the events need to be called after
  16440. // stage.update, like destroy
  16441. if (e) {
  16442. deferredEvents.push(e);
  16443. deferredClips.push(clip);
  16444. }
  16445. }
  16446. // Remove the finished clip
  16447. for (var i = 0; i < len;) {
  16448. if (clips[i]._needsRemove) {
  16449. clips[i] = clips[len - 1];
  16450. clips.pop();
  16451. len--;
  16452. }
  16453. else {
  16454. i++;
  16455. }
  16456. }
  16457. len = deferredEvents.length;
  16458. for (var i = 0; i < len; i++) {
  16459. deferredClips[i].fire(deferredEvents[i]);
  16460. }
  16461. this._time = time;
  16462. this.onframe(delta);
  16463. this.trigger('frame', delta);
  16464. if (this.stage.update) {
  16465. this.stage.update();
  16466. }
  16467. },
  16468. _startLoop: function () {
  16469. var self = this;
  16470. this._running = true;
  16471. function step() {
  16472. if (self._running) {
  16473. requestAnimationFrame(step);
  16474. !self._paused && self._update();
  16475. }
  16476. }
  16477. requestAnimationFrame(step);
  16478. },
  16479. /**
  16480. * 开始运行动画
  16481. */
  16482. start: function () {
  16483. this._time = new Date().getTime();
  16484. this._pausedTime = 0;
  16485. this._startLoop();
  16486. },
  16487. /**
  16488. * 停止运行动画
  16489. */
  16490. stop: function () {
  16491. this._running = false;
  16492. },
  16493. /**
  16494. * Pause
  16495. */
  16496. pause: function () {
  16497. if (!this._paused) {
  16498. this._pauseStart = new Date().getTime();
  16499. this._paused = true;
  16500. }
  16501. },
  16502. /**
  16503. * Resume
  16504. */
  16505. resume: function () {
  16506. if (this._paused) {
  16507. this._pausedTime += (new Date().getTime()) - this._pauseStart;
  16508. this._paused = false;
  16509. }
  16510. },
  16511. /**
  16512. * 清除所有动画片段
  16513. */
  16514. clear: function () {
  16515. this._clips = [];
  16516. },
  16517. /**
  16518. * 对一个目标创建一个animator对象,可以指定目标中的属性使用动画
  16519. * @param {Object} target
  16520. * @param {Object} options
  16521. * @param {boolean} [options.loop=false] 是否循环播放动画
  16522. * @param {Function} [options.getter=null]
  16523. * 如果指定getter函数,会通过getter函数取属性值
  16524. * @param {Function} [options.setter=null]
  16525. * 如果指定setter函数,会通过setter函数设置属性值
  16526. * @return {module:zrender/animation/Animation~Animator}
  16527. */
  16528. // TODO Gap
  16529. animate: function (target, options) {
  16530. options = options || {};
  16531. var animator = new Animator(
  16532. target,
  16533. options.loop,
  16534. options.getter,
  16535. options.setter
  16536. );
  16537. this.addAnimator(animator);
  16538. return animator;
  16539. }
  16540. };
  16541. util.mixin(Animation, Dispatcher);
  16542. module.exports = Animation;
  16543. /***/ },
  16544. /* 88 */
  16545. /***/ function(module, exports, __webpack_require__) {
  16546. 'use strict';
  16547. /**
  16548. * 事件辅助类
  16549. * @module zrender/core/event
  16550. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  16551. */
  16552. var Eventful = __webpack_require__(33);
  16553. var env = __webpack_require__(2);
  16554. var isDomLevel2 = (typeof window !== 'undefined') && !!window.addEventListener;
  16555. function getBoundingClientRect(el) {
  16556. // BlackBerry 5, iOS 3 (original iPhone) don't have getBoundingRect
  16557. return el.getBoundingClientRect ? el.getBoundingClientRect() : {left: 0, top: 0};
  16558. }
  16559. // `calculate` is optional, default false
  16560. function clientToLocal(el, e, out, calculate) {
  16561. out = out || {};
  16562. // According to the W3C Working Draft, offsetX and offsetY should be relative
  16563. // to the padding edge of the target element. The only browser using this convention
  16564. // is IE. Webkit uses the border edge, Opera uses the content edge, and FireFox does
  16565. // not support the properties.
  16566. // (see http://www.jacklmoore.com/notes/mouse-position/)
  16567. // In zr painter.dom, padding edge equals to border edge.
  16568. // FIXME
  16569. // When mousemove event triggered on ec tooltip, target is not zr painter.dom, and
  16570. // offsetX/Y is relative to e.target, where the calculation of zrX/Y via offsetX/Y
  16571. // is too complex. So css-transfrom dont support in this case temporarily.
  16572. if (calculate || !env.canvasSupported) {
  16573. defaultGetZrXY(el, e, out);
  16574. }
  16575. // Caution: In FireFox, layerX/layerY Mouse position relative to the closest positioned
  16576. // ancestor element, so we should make sure el is positioned (e.g., not position:static).
  16577. // BTW1, Webkit don't return the same results as FF in non-simple cases (like add
  16578. // zoom-factor, overflow / opacity layers, transforms ...)
  16579. // BTW2, (ev.offsetY || ev.pageY - $(ev.target).offset().top) is not correct in preserve-3d.
  16580. // <https://bugs.jquery.com/ticket/8523#comment:14>
  16581. // BTW3, In ff, offsetX/offsetY is always 0.
  16582. else if (env.browser.firefox && e.layerX != null && e.layerX !== e.offsetX) {
  16583. out.zrX = e.layerX;
  16584. out.zrY = e.layerY;
  16585. }
  16586. // For IE6+, chrome, safari, opera. (When will ff support offsetX?)
  16587. else if (e.offsetX != null) {
  16588. out.zrX = e.offsetX;
  16589. out.zrY = e.offsetY;
  16590. }
  16591. // For some other device, e.g., IOS safari.
  16592. else {
  16593. defaultGetZrXY(el, e, out);
  16594. }
  16595. return out;
  16596. }
  16597. function defaultGetZrXY(el, e, out) {
  16598. // This well-known method below does not support css transform.
  16599. var box = getBoundingClientRect(el);
  16600. out.zrX = e.clientX - box.left;
  16601. out.zrY = e.clientY - box.top;
  16602. }
  16603. /**
  16604. * 如果存在第三方嵌入的一些dom触发的事件,或touch事件,需要转换一下事件坐标.
  16605. * `calculate` is optional, default false.
  16606. */
  16607. function normalizeEvent(el, e, calculate) {
  16608. e = e || window.event;
  16609. if (e.zrX != null) {
  16610. return e;
  16611. }
  16612. var eventType = e.type;
  16613. var isTouch = eventType && eventType.indexOf('touch') >= 0;
  16614. if (!isTouch) {
  16615. clientToLocal(el, e, e, calculate);
  16616. e.zrDelta = (e.wheelDelta) ? e.wheelDelta / 120 : -(e.detail || 0) / 3;
  16617. }
  16618. else {
  16619. var touch = eventType != 'touchend'
  16620. ? e.targetTouches[0]
  16621. : e.changedTouches[0];
  16622. touch && clientToLocal(el, touch, e, calculate);
  16623. }
  16624. return e;
  16625. }
  16626. function addEventListener(el, name, handler) {
  16627. if (isDomLevel2) {
  16628. el.addEventListener(name, handler);
  16629. }
  16630. else {
  16631. el.attachEvent('on' + name, handler);
  16632. }
  16633. }
  16634. function removeEventListener(el, name, handler) {
  16635. if (isDomLevel2) {
  16636. el.removeEventListener(name, handler);
  16637. }
  16638. else {
  16639. el.detachEvent('on' + name, handler);
  16640. }
  16641. }
  16642. /**
  16643. * preventDefault and stopPropagation.
  16644. * Notice: do not do that in zrender. Upper application
  16645. * do that if necessary.
  16646. *
  16647. * @memberOf module:zrender/core/event
  16648. * @method
  16649. * @param {Event} e : event对象
  16650. */
  16651. var stop = isDomLevel2
  16652. ? function (e) {
  16653. e.preventDefault();
  16654. e.stopPropagation();
  16655. e.cancelBubble = true;
  16656. }
  16657. : function (e) {
  16658. e.returnValue = false;
  16659. e.cancelBubble = true;
  16660. };
  16661. module.exports = {
  16662. clientToLocal: clientToLocal,
  16663. normalizeEvent: normalizeEvent,
  16664. addEventListener: addEventListener,
  16665. removeEventListener: removeEventListener,
  16666. stop: stop,
  16667. // 做向上兼容
  16668. Dispatcher: Eventful
  16669. };
  16670. /***/ },
  16671. /* 89 */
  16672. /***/ function(module, exports) {
  16673. module.exports = (typeof window !== 'undefined' &&
  16674. (window.requestAnimationFrame
  16675. || window.msRequestAnimationFrame
  16676. || window.mozRequestAnimationFrame
  16677. || window.webkitRequestAnimationFrame))
  16678. || function (func) {
  16679. setTimeout(func, 16);
  16680. };
  16681. /***/ },
  16682. /* 90 */
  16683. /***/ function(module, exports, __webpack_require__) {
  16684. var eventTool = __webpack_require__(88);
  16685. var zrUtil = __webpack_require__(4);
  16686. var Eventful = __webpack_require__(33);
  16687. var env = __webpack_require__(2);
  16688. var GestureMgr = __webpack_require__(91);
  16689. var addEventListener = eventTool.addEventListener;
  16690. var removeEventListener = eventTool.removeEventListener;
  16691. var normalizeEvent = eventTool.normalizeEvent;
  16692. var TOUCH_CLICK_DELAY = 300;
  16693. var mouseHandlerNames = [
  16694. 'click', 'dblclick', 'mousewheel', 'mouseout',
  16695. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  16696. ];
  16697. var touchHandlerNames = [
  16698. 'touchstart', 'touchend', 'touchmove'
  16699. ];
  16700. var pointerEventNames = {
  16701. pointerdown: 1, pointerup: 1, pointermove: 1, pointerout: 1
  16702. };
  16703. var pointerHandlerNames = zrUtil.map(mouseHandlerNames, function (name) {
  16704. var nm = name.replace('mouse', 'pointer');
  16705. return pointerEventNames[nm] ? nm : name;
  16706. });
  16707. function eventNameFix(name) {
  16708. return (name === 'mousewheel' && env.browser.firefox) ? 'DOMMouseScroll' : name;
  16709. }
  16710. function processGesture(proxy, event, stage) {
  16711. var gestureMgr = proxy._gestureMgr;
  16712. stage === 'start' && gestureMgr.clear();
  16713. var gestureInfo = gestureMgr.recognize(
  16714. event,
  16715. proxy.handler.findHover(event.zrX, event.zrY, null),
  16716. proxy.dom
  16717. );
  16718. stage === 'end' && gestureMgr.clear();
  16719. // Do not do any preventDefault here. Upper application do that if necessary.
  16720. if (gestureInfo) {
  16721. var type = gestureInfo.type;
  16722. event.gestureEvent = type;
  16723. proxy.handler.dispatchToElement(gestureInfo.target, type, gestureInfo.event);
  16724. }
  16725. }
  16726. // function onMSGestureChange(proxy, event) {
  16727. // if (event.translationX || event.translationY) {
  16728. // // mousemove is carried by MSGesture to reduce the sensitivity.
  16729. // proxy.handler.dispatchToElement(event.target, 'mousemove', event);
  16730. // }
  16731. // if (event.scale !== 1) {
  16732. // event.pinchX = event.offsetX;
  16733. // event.pinchY = event.offsetY;
  16734. // event.pinchScale = event.scale;
  16735. // proxy.handler.dispatchToElement(event.target, 'pinch', event);
  16736. // }
  16737. // }
  16738. /**
  16739. * Prevent mouse event from being dispatched after Touch Events action
  16740. * @see <https://github.com/deltakosh/handjs/blob/master/src/hand.base.js>
  16741. * 1. Mobile browsers dispatch mouse events 300ms after touchend.
  16742. * 2. Chrome for Android dispatch mousedown for long-touch about 650ms
  16743. * Result: Blocking Mouse Events for 700ms.
  16744. */
  16745. function setTouchTimer(instance) {
  16746. instance._touching = true;
  16747. clearTimeout(instance._touchTimer);
  16748. instance._touchTimer = setTimeout(function () {
  16749. instance._touching = false;
  16750. }, 700);
  16751. }
  16752. var domHandlers = {
  16753. /**
  16754. * Mouse move handler
  16755. * @inner
  16756. * @param {Event} event
  16757. */
  16758. mousemove: function (event) {
  16759. event = normalizeEvent(this.dom, event);
  16760. this.trigger('mousemove', event);
  16761. },
  16762. /**
  16763. * Mouse out handler
  16764. * @inner
  16765. * @param {Event} event
  16766. */
  16767. mouseout: function (event) {
  16768. event = normalizeEvent(this.dom, event);
  16769. var element = event.toElement || event.relatedTarget;
  16770. if (element != this.dom) {
  16771. while (element && element.nodeType != 9) {
  16772. // 忽略包含在root中的dom引起的mouseOut
  16773. if (element === this.dom) {
  16774. return;
  16775. }
  16776. element = element.parentNode;
  16777. }
  16778. }
  16779. this.trigger('mouseout', event);
  16780. },
  16781. /**
  16782. * Touch开始响应函数
  16783. * @inner
  16784. * @param {Event} event
  16785. */
  16786. touchstart: function (event) {
  16787. // Default mouse behaviour should not be disabled here.
  16788. // For example, page may needs to be slided.
  16789. event = normalizeEvent(this.dom, event);
  16790. // Mark touch, which is useful in distinguish touch and
  16791. // mouse event in upper applicatoin.
  16792. event.zrByTouch = true;
  16793. this._lastTouchMoment = new Date();
  16794. processGesture(this, event, 'start');
  16795. // In touch device, trigger `mousemove`(`mouseover`) should
  16796. // be triggered, and must before `mousedown` triggered.
  16797. domHandlers.mousemove.call(this, event);
  16798. domHandlers.mousedown.call(this, event);
  16799. setTouchTimer(this);
  16800. },
  16801. /**
  16802. * Touch移动响应函数
  16803. * @inner
  16804. * @param {Event} event
  16805. */
  16806. touchmove: function (event) {
  16807. event = normalizeEvent(this.dom, event);
  16808. // Mark touch, which is useful in distinguish touch and
  16809. // mouse event in upper applicatoin.
  16810. event.zrByTouch = true;
  16811. processGesture(this, event, 'change');
  16812. // Mouse move should always be triggered no matter whether
  16813. // there is gestrue event, because mouse move and pinch may
  16814. // be used at the same time.
  16815. domHandlers.mousemove.call(this, event);
  16816. setTouchTimer(this);
  16817. },
  16818. /**
  16819. * Touch结束响应函数
  16820. * @inner
  16821. * @param {Event} event
  16822. */
  16823. touchend: function (event) {
  16824. event = normalizeEvent(this.dom, event);
  16825. // Mark touch, which is useful in distinguish touch and
  16826. // mouse event in upper applicatoin.
  16827. event.zrByTouch = true;
  16828. processGesture(this, event, 'end');
  16829. domHandlers.mouseup.call(this, event);
  16830. // Do not trigger `mouseout` here, in spite of `mousemove`(`mouseover`) is
  16831. // triggered in `touchstart`. This seems to be illogical, but by this mechanism,
  16832. // we can conveniently implement "hover style" in both PC and touch device just
  16833. // by listening to `mouseover` to add "hover style" and listening to `mouseout`
  16834. // to remove "hover style" on an element, without any additional code for
  16835. // compatibility. (`mouseout` will not be triggered in `touchend`, so "hover
  16836. // style" will remain for user view)
  16837. // click event should always be triggered no matter whether
  16838. // there is gestrue event. System click can not be prevented.
  16839. if (+new Date() - this._lastTouchMoment < TOUCH_CLICK_DELAY) {
  16840. domHandlers.click.call(this, event);
  16841. }
  16842. setTouchTimer(this);
  16843. },
  16844. pointerdown: function (event) {
  16845. domHandlers.mousedown.call(this, event);
  16846. // if (useMSGuesture(this, event)) {
  16847. // this._msGesture.addPointer(event.pointerId);
  16848. // }
  16849. },
  16850. pointermove: function (event) {
  16851. // FIXME
  16852. // pointermove is so sensitive that it always triggered when
  16853. // tap(click) on touch screen, which affect some judgement in
  16854. // upper application. So, we dont support mousemove on MS touch
  16855. // device yet.
  16856. if (!isPointerFromTouch(event)) {
  16857. domHandlers.mousemove.call(this, event);
  16858. }
  16859. },
  16860. pointerup: function (event) {
  16861. domHandlers.mouseup.call(this, event);
  16862. },
  16863. pointerout: function (event) {
  16864. // pointerout will be triggered when tap on touch screen
  16865. // (IE11+/Edge on MS Surface) after click event triggered,
  16866. // which is inconsistent with the mousout behavior we defined
  16867. // in touchend. So we unify them.
  16868. // (check domHandlers.touchend for detailed explanation)
  16869. if (!isPointerFromTouch(event)) {
  16870. domHandlers.mouseout.call(this, event);
  16871. }
  16872. }
  16873. };
  16874. function isPointerFromTouch(event) {
  16875. var pointerType = event.pointerType;
  16876. return pointerType === 'pen' || pointerType === 'touch';
  16877. }
  16878. // function useMSGuesture(handlerProxy, event) {
  16879. // return isPointerFromTouch(event) && !!handlerProxy._msGesture;
  16880. // }
  16881. // Common handlers
  16882. zrUtil.each(['click', 'mousedown', 'mouseup', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  16883. domHandlers[name] = function (event) {
  16884. event = normalizeEvent(this.dom, event);
  16885. this.trigger(name, event);
  16886. };
  16887. });
  16888. /**
  16889. * 为控制类实例初始化dom 事件处理函数
  16890. *
  16891. * @inner
  16892. * @param {module:zrender/Handler} instance 控制类实例
  16893. */
  16894. function initDomHandler(instance) {
  16895. zrUtil.each(touchHandlerNames, function (name) {
  16896. instance._handlers[name] = zrUtil.bind(domHandlers[name], instance);
  16897. });
  16898. zrUtil.each(pointerHandlerNames, function (name) {
  16899. instance._handlers[name] = zrUtil.bind(domHandlers[name], instance);
  16900. });
  16901. zrUtil.each(mouseHandlerNames, function (name) {
  16902. instance._handlers[name] = makeMouseHandler(domHandlers[name], instance);
  16903. });
  16904. function makeMouseHandler(fn, instance) {
  16905. return function () {
  16906. if (instance._touching) {
  16907. return;
  16908. }
  16909. return fn.apply(instance, arguments);
  16910. };
  16911. }
  16912. }
  16913. function HandlerDomProxy(dom) {
  16914. Eventful.call(this);
  16915. this.dom = dom;
  16916. /**
  16917. * @private
  16918. * @type {boolean}
  16919. */
  16920. this._touching = false;
  16921. /**
  16922. * @private
  16923. * @type {number}
  16924. */
  16925. this._touchTimer;
  16926. /**
  16927. * @private
  16928. * @type {module:zrender/core/GestureMgr}
  16929. */
  16930. this._gestureMgr = new GestureMgr();
  16931. this._handlers = {};
  16932. initDomHandler(this);
  16933. if (env.pointerEventsSupported) { // Only IE11+/Edge
  16934. // 1. On devices that both enable touch and mouse (e.g., MS Surface and lenovo X240),
  16935. // IE11+/Edge do not trigger touch event, but trigger pointer event and mouse event
  16936. // at the same time.
  16937. // 2. On MS Surface, it probablely only trigger mousedown but no mouseup when tap on
  16938. // screen, which do not occurs in pointer event.
  16939. // So we use pointer event to both detect touch gesture and mouse behavior.
  16940. mountHandlers(pointerHandlerNames, this);
  16941. // FIXME
  16942. // Note: MS Gesture require CSS touch-action set. But touch-action is not reliable,
  16943. // which does not prevent defuault behavior occasionally (which may cause view port
  16944. // zoomed in but use can not zoom it back). And event.preventDefault() does not work.
  16945. // So we have to not to use MSGesture and not to support touchmove and pinch on MS
  16946. // touch screen. And we only support click behavior on MS touch screen now.
  16947. // MS Gesture Event is only supported on IE11+/Edge and on Windows 8+.
  16948. // We dont support touch on IE on win7.
  16949. // See <https://msdn.microsoft.com/en-us/library/dn433243(v=vs.85).aspx>
  16950. // if (typeof MSGesture === 'function') {
  16951. // (this._msGesture = new MSGesture()).target = dom; // jshint ignore:line
  16952. // dom.addEventListener('MSGestureChange', onMSGestureChange);
  16953. // }
  16954. }
  16955. else {
  16956. if (env.touchEventsSupported) {
  16957. mountHandlers(touchHandlerNames, this);
  16958. // Handler of 'mouseout' event is needed in touch mode, which will be mounted below.
  16959. // addEventListener(root, 'mouseout', this._mouseoutHandler);
  16960. }
  16961. // 1. Considering some devices that both enable touch and mouse event (like on MS Surface
  16962. // and lenovo X240, @see #2350), we make mouse event be always listened, otherwise
  16963. // mouse event can not be handle in those devices.
  16964. // 2. On MS Surface, Chrome will trigger both touch event and mouse event. How to prevent
  16965. // mouseevent after touch event triggered, see `setTouchTimer`.
  16966. mountHandlers(mouseHandlerNames, this);
  16967. }
  16968. function mountHandlers(handlerNames, instance) {
  16969. zrUtil.each(handlerNames, function (name) {
  16970. addEventListener(dom, eventNameFix(name), instance._handlers[name]);
  16971. }, instance);
  16972. }
  16973. }
  16974. var handlerDomProxyProto = HandlerDomProxy.prototype;
  16975. handlerDomProxyProto.dispose = function () {
  16976. var handlerNames = mouseHandlerNames.concat(touchHandlerNames);
  16977. for (var i = 0; i < handlerNames.length; i++) {
  16978. var name = handlerNames[i];
  16979. removeEventListener(this.dom, eventNameFix(name), this._handlers[name]);
  16980. }
  16981. };
  16982. handlerDomProxyProto.setCursor = function (cursorStyle) {
  16983. this.dom.style.cursor = cursorStyle || 'default';
  16984. };
  16985. zrUtil.mixin(HandlerDomProxy, Eventful);
  16986. module.exports = HandlerDomProxy;
  16987. /***/ },
  16988. /* 91 */
  16989. /***/ function(module, exports, __webpack_require__) {
  16990. 'use strict';
  16991. /**
  16992. * Only implements needed gestures for mobile.
  16993. */
  16994. var eventUtil = __webpack_require__(88);
  16995. var GestureMgr = function () {
  16996. /**
  16997. * @private
  16998. * @type {Array.<Object>}
  16999. */
  17000. this._track = [];
  17001. };
  17002. GestureMgr.prototype = {
  17003. constructor: GestureMgr,
  17004. recognize: function (event, target, root) {
  17005. this._doTrack(event, target, root);
  17006. return this._recognize(event);
  17007. },
  17008. clear: function () {
  17009. this._track.length = 0;
  17010. return this;
  17011. },
  17012. _doTrack: function (event, target, root) {
  17013. var touches = event.touches;
  17014. if (!touches) {
  17015. return;
  17016. }
  17017. var trackItem = {
  17018. points: [],
  17019. touches: [],
  17020. target: target,
  17021. event: event
  17022. };
  17023. for (var i = 0, len = touches.length; i < len; i++) {
  17024. var touch = touches[i];
  17025. var pos = eventUtil.clientToLocal(root, touch, {});
  17026. trackItem.points.push([pos.zrX, pos.zrY]);
  17027. trackItem.touches.push(touch);
  17028. }
  17029. this._track.push(trackItem);
  17030. },
  17031. _recognize: function (event) {
  17032. for (var eventName in recognizers) {
  17033. if (recognizers.hasOwnProperty(eventName)) {
  17034. var gestureInfo = recognizers[eventName](this._track, event);
  17035. if (gestureInfo) {
  17036. return gestureInfo;
  17037. }
  17038. }
  17039. }
  17040. }
  17041. };
  17042. function dist(pointPair) {
  17043. var dx = pointPair[1][0] - pointPair[0][0];
  17044. var dy = pointPair[1][1] - pointPair[0][1];
  17045. return Math.sqrt(dx * dx + dy * dy);
  17046. }
  17047. function center(pointPair) {
  17048. return [
  17049. (pointPair[0][0] + pointPair[1][0]) / 2,
  17050. (pointPair[0][1] + pointPair[1][1]) / 2
  17051. ];
  17052. }
  17053. var recognizers = {
  17054. pinch: function (track, event) {
  17055. var trackLen = track.length;
  17056. if (!trackLen) {
  17057. return;
  17058. }
  17059. var pinchEnd = (track[trackLen - 1] || {}).points;
  17060. var pinchPre = (track[trackLen - 2] || {}).points || pinchEnd;
  17061. if (pinchPre
  17062. && pinchPre.length > 1
  17063. && pinchEnd
  17064. && pinchEnd.length > 1
  17065. ) {
  17066. var pinchScale = dist(pinchEnd) / dist(pinchPre);
  17067. !isFinite(pinchScale) && (pinchScale = 1);
  17068. event.pinchScale = pinchScale;
  17069. var pinchCenter = center(pinchEnd);
  17070. event.pinchX = pinchCenter[0];
  17071. event.pinchY = pinchCenter[1];
  17072. return {
  17073. type: 'pinch',
  17074. target: track[0].target,
  17075. event: event
  17076. };
  17077. }
  17078. }
  17079. // Only pinch currently.
  17080. };
  17081. module.exports = GestureMgr;
  17082. /***/ },
  17083. /* 92 */
  17084. /***/ function(module, exports, __webpack_require__) {
  17085. 'use strict';
  17086. /**
  17087. * Default canvas painter
  17088. * @module zrender/Painter
  17089. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  17090. * errorrik (errorrik@gmail.com)
  17091. * pissang (https://www.github.com/pissang)
  17092. */
  17093. var config = __webpack_require__(41);
  17094. var util = __webpack_require__(4);
  17095. var log = __webpack_require__(40);
  17096. var BoundingRect = __webpack_require__(9);
  17097. var timsort = __webpack_require__(86);
  17098. var Layer = __webpack_require__(93);
  17099. var requestAnimationFrame = __webpack_require__(89);
  17100. // PENDIGN
  17101. // Layer exceeds MAX_PROGRESSIVE_LAYER_NUMBER may have some problem when flush directly second time.
  17102. //
  17103. // Maximum progressive layer. When exceeding this number. All elements will be drawed in the last layer.
  17104. var MAX_PROGRESSIVE_LAYER_NUMBER = 5;
  17105. function parseInt10(val) {
  17106. return parseInt(val, 10);
  17107. }
  17108. function isLayerValid(layer) {
  17109. if (!layer) {
  17110. return false;
  17111. }
  17112. if (layer.isBuildin) {
  17113. return true;
  17114. }
  17115. if (typeof(layer.resize) !== 'function'
  17116. || typeof(layer.refresh) !== 'function'
  17117. ) {
  17118. return false;
  17119. }
  17120. return true;
  17121. }
  17122. function preProcessLayer(layer) {
  17123. layer.__unusedCount++;
  17124. }
  17125. function postProcessLayer(layer) {
  17126. if (layer.__unusedCount == 1) {
  17127. layer.clear();
  17128. }
  17129. }
  17130. var tmpRect = new BoundingRect(0, 0, 0, 0);
  17131. var viewRect = new BoundingRect(0, 0, 0, 0);
  17132. function isDisplayableCulled(el, width, height) {
  17133. tmpRect.copy(el.getBoundingRect());
  17134. if (el.transform) {
  17135. tmpRect.applyTransform(el.transform);
  17136. }
  17137. viewRect.width = width;
  17138. viewRect.height = height;
  17139. return !tmpRect.intersect(viewRect);
  17140. }
  17141. function isClipPathChanged(clipPaths, prevClipPaths) {
  17142. if (clipPaths == prevClipPaths) { // Can both be null or undefined
  17143. return false;
  17144. }
  17145. if (!clipPaths || !prevClipPaths || (clipPaths.length !== prevClipPaths.length)) {
  17146. return true;
  17147. }
  17148. for (var i = 0; i < clipPaths.length; i++) {
  17149. if (clipPaths[i] !== prevClipPaths[i]) {
  17150. return true;
  17151. }
  17152. }
  17153. }
  17154. function doClip(clipPaths, ctx) {
  17155. for (var i = 0; i < clipPaths.length; i++) {
  17156. var clipPath = clipPaths[i];
  17157. var path = clipPath.path;
  17158. clipPath.setTransform(ctx);
  17159. path.beginPath(ctx);
  17160. clipPath.buildPath(path, clipPath.shape);
  17161. ctx.clip();
  17162. // Transform back
  17163. clipPath.restoreTransform(ctx);
  17164. }
  17165. }
  17166. function createRoot(width, height) {
  17167. var domRoot = document.createElement('div');
  17168. // domRoot.onselectstart = returnFalse; // 避免页面选中的尴尬
  17169. domRoot.style.cssText = [
  17170. 'position:relative',
  17171. 'overflow:hidden',
  17172. 'width:' + width + 'px',
  17173. 'height:' + height + 'px',
  17174. 'padding:0',
  17175. 'margin:0',
  17176. 'border-width:0'
  17177. ].join(';') + ';';
  17178. return domRoot;
  17179. }
  17180. /**
  17181. * @alias module:zrender/Painter
  17182. * @constructor
  17183. * @param {HTMLElement} root 绘图容器
  17184. * @param {module:zrender/Storage} storage
  17185. * @param {Ojbect} opts
  17186. */
  17187. var Painter = function (root, storage, opts) {
  17188. // In node environment using node-canvas
  17189. var singleCanvas = !root.nodeName // In node ?
  17190. || root.nodeName.toUpperCase() === 'CANVAS';
  17191. this._opts = opts = util.extend({}, opts || {});
  17192. /**
  17193. * @type {number}
  17194. */
  17195. this.dpr = opts.devicePixelRatio || config.devicePixelRatio;
  17196. /**
  17197. * @type {boolean}
  17198. * @private
  17199. */
  17200. this._singleCanvas = singleCanvas;
  17201. /**
  17202. * 绘图容器
  17203. * @type {HTMLElement}
  17204. */
  17205. this.root = root;
  17206. var rootStyle = root.style;
  17207. if (rootStyle) {
  17208. rootStyle['-webkit-tap-highlight-color'] = 'transparent';
  17209. rootStyle['-webkit-user-select'] =
  17210. rootStyle['user-select'] =
  17211. rootStyle['-webkit-touch-callout'] = 'none';
  17212. root.innerHTML = '';
  17213. }
  17214. /**
  17215. * @type {module:zrender/Storage}
  17216. */
  17217. this.storage = storage;
  17218. /**
  17219. * @type {Array.<number>}
  17220. * @private
  17221. */
  17222. var zlevelList = this._zlevelList = [];
  17223. /**
  17224. * @type {Object.<string, module:zrender/Layer>}
  17225. * @private
  17226. */
  17227. var layers = this._layers = {};
  17228. /**
  17229. * @type {Object.<string, Object>}
  17230. * @type {private}
  17231. */
  17232. this._layerConfig = {};
  17233. if (!singleCanvas) {
  17234. this._width = this._getSize(0);
  17235. this._height = this._getSize(1);
  17236. var domRoot = this._domRoot = createRoot(
  17237. this._width, this._height
  17238. );
  17239. root.appendChild(domRoot);
  17240. }
  17241. else {
  17242. // Use canvas width and height directly
  17243. var width = root.width;
  17244. var height = root.height;
  17245. this._width = width;
  17246. this._height = height;
  17247. // Create layer if only one given canvas
  17248. // Device pixel ratio is fixed to 1 because given canvas has its specified width and height
  17249. var mainLayer = new Layer(root, this, 1);
  17250. mainLayer.initContext();
  17251. // FIXME Use canvas width and height
  17252. // mainLayer.resize(width, height);
  17253. layers[0] = mainLayer;
  17254. zlevelList.push(0);
  17255. this._domRoot = root;
  17256. }
  17257. this.pathToImage = this._createPathToImage();
  17258. // Layers for progressive rendering
  17259. this._progressiveLayers = [];
  17260. /**
  17261. * @type {module:zrender/Layer}
  17262. * @private
  17263. */
  17264. this._hoverlayer;
  17265. this._hoverElements = [];
  17266. };
  17267. Painter.prototype = {
  17268. constructor: Painter,
  17269. /**
  17270. * If painter use a single canvas
  17271. * @return {boolean}
  17272. */
  17273. isSingleCanvas: function () {
  17274. return this._singleCanvas;
  17275. },
  17276. /**
  17277. * @return {HTMLDivElement}
  17278. */
  17279. getViewportRoot: function () {
  17280. return this._domRoot;
  17281. },
  17282. /**
  17283. * 刷新
  17284. * @param {boolean} [paintAll=false] 强制绘制所有displayable
  17285. */
  17286. refresh: function (paintAll) {
  17287. var list = this.storage.getDisplayList(true);
  17288. var zlevelList = this._zlevelList;
  17289. this._paintList(list, paintAll);
  17290. // Paint custum layers
  17291. for (var i = 0; i < zlevelList.length; i++) {
  17292. var z = zlevelList[i];
  17293. var layer = this._layers[z];
  17294. if (!layer.isBuildin && layer.refresh) {
  17295. layer.refresh();
  17296. }
  17297. }
  17298. this.refreshHover();
  17299. if (this._progressiveLayers.length) {
  17300. this._startProgessive();
  17301. }
  17302. return this;
  17303. },
  17304. addHover: function (el, hoverStyle) {
  17305. if (el.__hoverMir) {
  17306. return;
  17307. }
  17308. var elMirror = new el.constructor({
  17309. style: el.style,
  17310. shape: el.shape
  17311. });
  17312. elMirror.__from = el;
  17313. el.__hoverMir = elMirror;
  17314. elMirror.setStyle(hoverStyle);
  17315. this._hoverElements.push(elMirror);
  17316. },
  17317. removeHover: function (el) {
  17318. var elMirror = el.__hoverMir;
  17319. var hoverElements = this._hoverElements;
  17320. var idx = util.indexOf(hoverElements, elMirror);
  17321. if (idx >= 0) {
  17322. hoverElements.splice(idx, 1);
  17323. }
  17324. el.__hoverMir = null;
  17325. },
  17326. clearHover: function (el) {
  17327. var hoverElements = this._hoverElements;
  17328. for (var i = 0; i < hoverElements.length; i++) {
  17329. var from = hoverElements[i].__from;
  17330. if (from) {
  17331. from.__hoverMir = null;
  17332. }
  17333. }
  17334. hoverElements.length = 0;
  17335. },
  17336. refreshHover: function () {
  17337. var hoverElements = this._hoverElements;
  17338. var len = hoverElements.length;
  17339. var hoverLayer = this._hoverlayer;
  17340. hoverLayer && hoverLayer.clear();
  17341. if (!len) {
  17342. return;
  17343. }
  17344. timsort(hoverElements, this.storage.displayableSortFunc);
  17345. // Use a extream large zlevel
  17346. // FIXME?
  17347. if (!hoverLayer) {
  17348. hoverLayer = this._hoverlayer = this.getLayer(1e5);
  17349. }
  17350. var scope = {};
  17351. hoverLayer.ctx.save();
  17352. for (var i = 0; i < len;) {
  17353. var el = hoverElements[i];
  17354. var originalEl = el.__from;
  17355. // Original el is removed
  17356. // PENDING
  17357. if (!(originalEl && originalEl.__zr)) {
  17358. hoverElements.splice(i, 1);
  17359. originalEl.__hoverMir = null;
  17360. len--;
  17361. continue;
  17362. }
  17363. i++;
  17364. // Use transform
  17365. // FIXME style and shape ?
  17366. if (!originalEl.invisible) {
  17367. el.transform = originalEl.transform;
  17368. el.invTransform = originalEl.invTransform;
  17369. el.__clipPaths = originalEl.__clipPaths;
  17370. // el.
  17371. this._doPaintEl(el, hoverLayer, true, scope);
  17372. }
  17373. }
  17374. hoverLayer.ctx.restore();
  17375. },
  17376. _startProgessive: function () {
  17377. var self = this;
  17378. if (!self._furtherProgressive) {
  17379. return;
  17380. }
  17381. // Use a token to stop progress steps triggered by
  17382. // previous zr.refresh calling.
  17383. var token = self._progressiveToken = +new Date();
  17384. self._progress++;
  17385. requestAnimationFrame(step);
  17386. function step() {
  17387. // In case refreshed or disposed
  17388. if (token === self._progressiveToken && self.storage) {
  17389. self._doPaintList(self.storage.getDisplayList());
  17390. if (self._furtherProgressive) {
  17391. self._progress++;
  17392. requestAnimationFrame(step);
  17393. }
  17394. else {
  17395. self._progressiveToken = -1;
  17396. }
  17397. }
  17398. }
  17399. },
  17400. _clearProgressive: function () {
  17401. this._progressiveToken = -1;
  17402. this._progress = 0;
  17403. util.each(this._progressiveLayers, function (layer) {
  17404. layer.__dirty && layer.clear();
  17405. });
  17406. },
  17407. _paintList: function (list, paintAll) {
  17408. if (paintAll == null) {
  17409. paintAll = false;
  17410. }
  17411. this._updateLayerStatus(list);
  17412. this._clearProgressive();
  17413. this.eachBuildinLayer(preProcessLayer);
  17414. this._doPaintList(list, paintAll);
  17415. this.eachBuildinLayer(postProcessLayer);
  17416. },
  17417. _doPaintList: function (list, paintAll) {
  17418. var currentLayer;
  17419. var currentZLevel;
  17420. var ctx;
  17421. // var invTransform = [];
  17422. var scope;
  17423. var progressiveLayerIdx = 0;
  17424. var currentProgressiveLayer;
  17425. var width = this._width;
  17426. var height = this._height;
  17427. var layerProgress;
  17428. var frame = this._progress;
  17429. function flushProgressiveLayer(layer) {
  17430. var dpr = ctx.dpr || 1;
  17431. ctx.save();
  17432. ctx.globalAlpha = 1;
  17433. ctx.shadowBlur = 0;
  17434. // Avoid layer don't clear in next progressive frame
  17435. currentLayer.__dirty = true;
  17436. ctx.setTransform(1, 0, 0, 1, 0, 0);
  17437. ctx.drawImage(layer.dom, 0, 0, width * dpr, height * dpr);
  17438. ctx.restore();
  17439. }
  17440. for (var i = 0, l = list.length; i < l; i++) {
  17441. var el = list[i];
  17442. var elZLevel = this._singleCanvas ? 0 : el.zlevel;
  17443. var elFrame = el.__frame;
  17444. // Flush at current context
  17445. // PENDING
  17446. if (elFrame < 0 && currentProgressiveLayer) {
  17447. flushProgressiveLayer(currentProgressiveLayer);
  17448. currentProgressiveLayer = null;
  17449. }
  17450. // Change draw layer
  17451. if (currentZLevel !== elZLevel) {
  17452. if (ctx) {
  17453. ctx.restore();
  17454. }
  17455. // Reset scope
  17456. scope = {};
  17457. // Only 0 zlevel if only has one canvas
  17458. currentZLevel = elZLevel;
  17459. currentLayer = this.getLayer(currentZLevel);
  17460. if (!currentLayer.isBuildin) {
  17461. log(
  17462. 'ZLevel ' + currentZLevel
  17463. + ' has been used by unkown layer ' + currentLayer.id
  17464. );
  17465. }
  17466. ctx = currentLayer.ctx;
  17467. ctx.save();
  17468. // Reset the count
  17469. currentLayer.__unusedCount = 0;
  17470. if (currentLayer.__dirty || paintAll) {
  17471. currentLayer.clear();
  17472. }
  17473. }
  17474. if (!(currentLayer.__dirty || paintAll)) {
  17475. continue;
  17476. }
  17477. if (elFrame >= 0) {
  17478. // Progressive layer changed
  17479. if (!currentProgressiveLayer) {
  17480. currentProgressiveLayer = this._progressiveLayers[
  17481. Math.min(progressiveLayerIdx++, MAX_PROGRESSIVE_LAYER_NUMBER - 1)
  17482. ];
  17483. currentProgressiveLayer.ctx.save();
  17484. currentProgressiveLayer.renderScope = {};
  17485. if (currentProgressiveLayer
  17486. && (currentProgressiveLayer.__progress > currentProgressiveLayer.__maxProgress)
  17487. ) {
  17488. // flushProgressiveLayer(currentProgressiveLayer);
  17489. // Quick jump all progressive elements
  17490. // All progressive element are not dirty, jump over and flush directly
  17491. i = currentProgressiveLayer.__nextIdxNotProg - 1;
  17492. // currentProgressiveLayer = null;
  17493. continue;
  17494. }
  17495. layerProgress = currentProgressiveLayer.__progress;
  17496. if (!currentProgressiveLayer.__dirty) {
  17497. // Keep rendering
  17498. frame = layerProgress;
  17499. }
  17500. currentProgressiveLayer.__progress = frame + 1;
  17501. }
  17502. if (elFrame === frame) {
  17503. this._doPaintEl(el, currentProgressiveLayer, true, currentProgressiveLayer.renderScope);
  17504. }
  17505. }
  17506. else {
  17507. this._doPaintEl(el, currentLayer, paintAll, scope);
  17508. }
  17509. el.__dirty = false;
  17510. }
  17511. if (currentProgressiveLayer) {
  17512. flushProgressiveLayer(currentProgressiveLayer);
  17513. }
  17514. // Restore the lastLayer ctx
  17515. ctx && ctx.restore();
  17516. // If still has clipping state
  17517. // if (scope.prevElClipPaths) {
  17518. // ctx.restore();
  17519. // }
  17520. this._furtherProgressive = false;
  17521. util.each(this._progressiveLayers, function (layer) {
  17522. if (layer.__maxProgress >= layer.__progress) {
  17523. this._furtherProgressive = true;
  17524. }
  17525. }, this);
  17526. },
  17527. _doPaintEl: function (el, currentLayer, forcePaint, scope) {
  17528. var ctx = currentLayer.ctx;
  17529. var m = el.transform;
  17530. if (
  17531. (currentLayer.__dirty || forcePaint)
  17532. // Ignore invisible element
  17533. && !el.invisible
  17534. // Ignore transparent element
  17535. && el.style.opacity !== 0
  17536. // Ignore scale 0 element, in some environment like node-canvas
  17537. // Draw a scale 0 element can cause all following draw wrong
  17538. // And setTransform with scale 0 will cause set back transform failed.
  17539. && !(m && !m[0] && !m[3])
  17540. // Ignore culled element
  17541. && !(el.culling && isDisplayableCulled(el, this._width, this._height))
  17542. ) {
  17543. var clipPaths = el.__clipPaths;
  17544. // Optimize when clipping on group with several elements
  17545. if (scope.prevClipLayer !== currentLayer
  17546. || isClipPathChanged(clipPaths, scope.prevElClipPaths)
  17547. ) {
  17548. // If has previous clipping state, restore from it
  17549. if (scope.prevElClipPaths) {
  17550. scope.prevClipLayer.ctx.restore();
  17551. scope.prevClipLayer = scope.prevElClipPaths = null;
  17552. // Reset prevEl since context has been restored
  17553. scope.prevEl = null;
  17554. }
  17555. // New clipping state
  17556. if (clipPaths) {
  17557. ctx.save();
  17558. doClip(clipPaths, ctx);
  17559. scope.prevClipLayer = currentLayer;
  17560. scope.prevElClipPaths = clipPaths;
  17561. }
  17562. }
  17563. el.beforeBrush && el.beforeBrush(ctx);
  17564. el.brush(ctx, scope.prevEl || null);
  17565. scope.prevEl = el;
  17566. el.afterBrush && el.afterBrush(ctx);
  17567. }
  17568. },
  17569. /**
  17570. * 获取 zlevel 所在层,如果不存在则会创建一个新的层
  17571. * @param {number} zlevel
  17572. * @return {module:zrender/Layer}
  17573. */
  17574. getLayer: function (zlevel) {
  17575. if (this._singleCanvas) {
  17576. return this._layers[0];
  17577. }
  17578. var layer = this._layers[zlevel];
  17579. if (!layer) {
  17580. // Create a new layer
  17581. layer = new Layer('zr_' + zlevel, this, this.dpr);
  17582. layer.isBuildin = true;
  17583. if (this._layerConfig[zlevel]) {
  17584. util.merge(layer, this._layerConfig[zlevel], true);
  17585. }
  17586. this.insertLayer(zlevel, layer);
  17587. // Context is created after dom inserted to document
  17588. // Or excanvas will get 0px clientWidth and clientHeight
  17589. layer.initContext();
  17590. }
  17591. return layer;
  17592. },
  17593. insertLayer: function (zlevel, layer) {
  17594. var layersMap = this._layers;
  17595. var zlevelList = this._zlevelList;
  17596. var len = zlevelList.length;
  17597. var prevLayer = null;
  17598. var i = -1;
  17599. var domRoot = this._domRoot;
  17600. if (layersMap[zlevel]) {
  17601. log('ZLevel ' + zlevel + ' has been used already');
  17602. return;
  17603. }
  17604. // Check if is a valid layer
  17605. if (!isLayerValid(layer)) {
  17606. log('Layer of zlevel ' + zlevel + ' is not valid');
  17607. return;
  17608. }
  17609. if (len > 0 && zlevel > zlevelList[0]) {
  17610. for (i = 0; i < len - 1; i++) {
  17611. if (
  17612. zlevelList[i] < zlevel
  17613. && zlevelList[i + 1] > zlevel
  17614. ) {
  17615. break;
  17616. }
  17617. }
  17618. prevLayer = layersMap[zlevelList[i]];
  17619. }
  17620. zlevelList.splice(i + 1, 0, zlevel);
  17621. if (prevLayer) {
  17622. var prevDom = prevLayer.dom;
  17623. if (prevDom.nextSibling) {
  17624. domRoot.insertBefore(
  17625. layer.dom,
  17626. prevDom.nextSibling
  17627. );
  17628. }
  17629. else {
  17630. domRoot.appendChild(layer.dom);
  17631. }
  17632. }
  17633. else {
  17634. if (domRoot.firstChild) {
  17635. domRoot.insertBefore(layer.dom, domRoot.firstChild);
  17636. }
  17637. else {
  17638. domRoot.appendChild(layer.dom);
  17639. }
  17640. }
  17641. layersMap[zlevel] = layer;
  17642. },
  17643. // Iterate each layer
  17644. eachLayer: function (cb, context) {
  17645. var zlevelList = this._zlevelList;
  17646. var z;
  17647. var i;
  17648. for (i = 0; i < zlevelList.length; i++) {
  17649. z = zlevelList[i];
  17650. cb.call(context, this._layers[z], z);
  17651. }
  17652. },
  17653. // Iterate each buildin layer
  17654. eachBuildinLayer: function (cb, context) {
  17655. var zlevelList = this._zlevelList;
  17656. var layer;
  17657. var z;
  17658. var i;
  17659. for (i = 0; i < zlevelList.length; i++) {
  17660. z = zlevelList[i];
  17661. layer = this._layers[z];
  17662. if (layer.isBuildin) {
  17663. cb.call(context, layer, z);
  17664. }
  17665. }
  17666. },
  17667. // Iterate each other layer except buildin layer
  17668. eachOtherLayer: function (cb, context) {
  17669. var zlevelList = this._zlevelList;
  17670. var layer;
  17671. var z;
  17672. var i;
  17673. for (i = 0; i < zlevelList.length; i++) {
  17674. z = zlevelList[i];
  17675. layer = this._layers[z];
  17676. if (! layer.isBuildin) {
  17677. cb.call(context, layer, z);
  17678. }
  17679. }
  17680. },
  17681. /**
  17682. * 获取所有已创建的层
  17683. * @param {Array.<module:zrender/Layer>} [prevLayer]
  17684. */
  17685. getLayers: function () {
  17686. return this._layers;
  17687. },
  17688. _updateLayerStatus: function (list) {
  17689. var layers = this._layers;
  17690. var progressiveLayers = this._progressiveLayers;
  17691. var elCountsLastFrame = {};
  17692. var progressiveElCountsLastFrame = {};
  17693. this.eachBuildinLayer(function (layer, z) {
  17694. elCountsLastFrame[z] = layer.elCount;
  17695. layer.elCount = 0;
  17696. layer.__dirty = false;
  17697. });
  17698. util.each(progressiveLayers, function (layer, idx) {
  17699. progressiveElCountsLastFrame[idx] = layer.elCount;
  17700. layer.elCount = 0;
  17701. layer.__dirty = false;
  17702. });
  17703. var progressiveLayerCount = 0;
  17704. var currentProgressiveLayer;
  17705. var lastProgressiveKey;
  17706. var frameCount = 0;
  17707. for (var i = 0, l = list.length; i < l; i++) {
  17708. var el = list[i];
  17709. var zlevel = this._singleCanvas ? 0 : el.zlevel;
  17710. var layer = layers[zlevel];
  17711. var elProgress = el.progressive;
  17712. if (layer) {
  17713. layer.elCount++;
  17714. layer.__dirty = layer.__dirty || el.__dirty;
  17715. }
  17716. /////// Update progressive
  17717. if (elProgress >= 0) {
  17718. // Fix wrong progressive sequence problem.
  17719. if (lastProgressiveKey !== elProgress) {
  17720. lastProgressiveKey = elProgress;
  17721. frameCount++;
  17722. }
  17723. var elFrame = el.__frame = frameCount - 1;
  17724. if (!currentProgressiveLayer) {
  17725. var idx = Math.min(progressiveLayerCount, MAX_PROGRESSIVE_LAYER_NUMBER - 1);
  17726. currentProgressiveLayer = progressiveLayers[idx];
  17727. if (!currentProgressiveLayer) {
  17728. currentProgressiveLayer = progressiveLayers[idx] = new Layer(
  17729. 'progressive', this, this.dpr
  17730. );
  17731. currentProgressiveLayer.initContext();
  17732. }
  17733. currentProgressiveLayer.__maxProgress = 0;
  17734. }
  17735. currentProgressiveLayer.__dirty = currentProgressiveLayer.__dirty || el.__dirty;
  17736. currentProgressiveLayer.elCount++;
  17737. currentProgressiveLayer.__maxProgress = Math.max(
  17738. currentProgressiveLayer.__maxProgress, elFrame
  17739. );
  17740. if (currentProgressiveLayer.__maxProgress >= currentProgressiveLayer.__progress) {
  17741. // Should keep rendering this layer because progressive rendering is not finished yet
  17742. layer.__dirty = true;
  17743. }
  17744. }
  17745. else {
  17746. el.__frame = -1;
  17747. if (currentProgressiveLayer) {
  17748. currentProgressiveLayer.__nextIdxNotProg = i;
  17749. progressiveLayerCount++;
  17750. currentProgressiveLayer = null;
  17751. }
  17752. }
  17753. }
  17754. if (currentProgressiveLayer) {
  17755. progressiveLayerCount++;
  17756. currentProgressiveLayer.__nextIdxNotProg = i;
  17757. }
  17758. // 层中的元素数量有发生变化
  17759. this.eachBuildinLayer(function (layer, z) {
  17760. if (elCountsLastFrame[z] !== layer.elCount) {
  17761. layer.__dirty = true;
  17762. }
  17763. });
  17764. progressiveLayers.length = Math.min(progressiveLayerCount, MAX_PROGRESSIVE_LAYER_NUMBER);
  17765. util.each(progressiveLayers, function (layer, idx) {
  17766. if (progressiveElCountsLastFrame[idx] !== layer.elCount) {
  17767. el.__dirty = true;
  17768. }
  17769. if (layer.__dirty) {
  17770. layer.__progress = 0;
  17771. }
  17772. });
  17773. },
  17774. /**
  17775. * 清除hover层外所有内容
  17776. */
  17777. clear: function () {
  17778. this.eachBuildinLayer(this._clearLayer);
  17779. return this;
  17780. },
  17781. _clearLayer: function (layer) {
  17782. layer.clear();
  17783. },
  17784. /**
  17785. * 修改指定zlevel的绘制参数
  17786. *
  17787. * @param {string} zlevel
  17788. * @param {Object} config 配置对象
  17789. * @param {string} [config.clearColor=0] 每次清空画布的颜色
  17790. * @param {string} [config.motionBlur=false] 是否开启动态模糊
  17791. * @param {number} [config.lastFrameAlpha=0.7]
  17792. * 在开启动态模糊的时候使用,与上一帧混合的alpha值,值越大尾迹越明显
  17793. */
  17794. configLayer: function (zlevel, config) {
  17795. if (config) {
  17796. var layerConfig = this._layerConfig;
  17797. if (!layerConfig[zlevel]) {
  17798. layerConfig[zlevel] = config;
  17799. }
  17800. else {
  17801. util.merge(layerConfig[zlevel], config, true);
  17802. }
  17803. var layer = this._layers[zlevel];
  17804. if (layer) {
  17805. util.merge(layer, layerConfig[zlevel], true);
  17806. }
  17807. }
  17808. },
  17809. /**
  17810. * 删除指定层
  17811. * @param {number} zlevel 层所在的zlevel
  17812. */
  17813. delLayer: function (zlevel) {
  17814. var layers = this._layers;
  17815. var zlevelList = this._zlevelList;
  17816. var layer = layers[zlevel];
  17817. if (!layer) {
  17818. return;
  17819. }
  17820. layer.dom.parentNode.removeChild(layer.dom);
  17821. delete layers[zlevel];
  17822. zlevelList.splice(util.indexOf(zlevelList, zlevel), 1);
  17823. },
  17824. /**
  17825. * 区域大小变化后重绘
  17826. */
  17827. resize: function (width, height) {
  17828. var domRoot = this._domRoot;
  17829. // FIXME Why ?
  17830. domRoot.style.display = 'none';
  17831. // Save input w/h
  17832. var opts = this._opts;
  17833. width != null && (opts.width = width);
  17834. height != null && (opts.height = height);
  17835. width = this._getSize(0);
  17836. height = this._getSize(1);
  17837. domRoot.style.display = '';
  17838. // 优化没有实际改变的resize
  17839. if (this._width != width || height != this._height) {
  17840. domRoot.style.width = width + 'px';
  17841. domRoot.style.height = height + 'px';
  17842. for (var id in this._layers) {
  17843. if (this._layers.hasOwnProperty(id)) {
  17844. this._layers[id].resize(width, height);
  17845. }
  17846. }
  17847. util.each(this._progressiveLayers, function (layer) {
  17848. layer.resize(width, height);
  17849. });
  17850. this.refresh(true);
  17851. }
  17852. this._width = width;
  17853. this._height = height;
  17854. return this;
  17855. },
  17856. /**
  17857. * 清除单独的一个层
  17858. * @param {number} zlevel
  17859. */
  17860. clearLayer: function (zlevel) {
  17861. var layer = this._layers[zlevel];
  17862. if (layer) {
  17863. layer.clear();
  17864. }
  17865. },
  17866. /**
  17867. * 释放
  17868. */
  17869. dispose: function () {
  17870. this.root.innerHTML = '';
  17871. this.root =
  17872. this.storage =
  17873. this._domRoot =
  17874. this._layers = null;
  17875. },
  17876. /**
  17877. * Get canvas which has all thing rendered
  17878. * @param {Object} opts
  17879. * @param {string} [opts.backgroundColor]
  17880. */
  17881. getRenderedCanvas: function (opts) {
  17882. opts = opts || {};
  17883. if (this._singleCanvas) {
  17884. return this._layers[0].dom;
  17885. }
  17886. var imageLayer = new Layer('image', this, opts.pixelRatio || this.dpr);
  17887. imageLayer.initContext();
  17888. imageLayer.clearColor = opts.backgroundColor;
  17889. imageLayer.clear();
  17890. var displayList = this.storage.getDisplayList(true);
  17891. var scope = {};
  17892. for (var i = 0; i < displayList.length; i++) {
  17893. var el = displayList[i];
  17894. this._doPaintEl(el, imageLayer, true, scope);
  17895. }
  17896. return imageLayer.dom;
  17897. },
  17898. /**
  17899. * 获取绘图区域宽度
  17900. */
  17901. getWidth: function () {
  17902. return this._width;
  17903. },
  17904. /**
  17905. * 获取绘图区域高度
  17906. */
  17907. getHeight: function () {
  17908. return this._height;
  17909. },
  17910. _getSize: function (whIdx) {
  17911. var opts = this._opts;
  17912. var wh = ['width', 'height'][whIdx];
  17913. var cwh = ['clientWidth', 'clientHeight'][whIdx];
  17914. var plt = ['paddingLeft', 'paddingTop'][whIdx];
  17915. var prb = ['paddingRight', 'paddingBottom'][whIdx];
  17916. if (opts[wh] != null && opts[wh] !== 'auto') {
  17917. return parseFloat(opts[wh]);
  17918. }
  17919. var root = this.root;
  17920. var stl = document.defaultView.getComputedStyle(root);
  17921. return (
  17922. (root[cwh] || parseInt10(stl[wh]) || parseInt10(root.style[wh]))
  17923. - (parseInt10(stl[plt]) || 0)
  17924. - (parseInt10(stl[prb]) || 0)
  17925. ) | 0;
  17926. },
  17927. _pathToImage: function (id, path, width, height, dpr) {
  17928. var canvas = document.createElement('canvas');
  17929. var ctx = canvas.getContext('2d');
  17930. canvas.width = width * dpr;
  17931. canvas.height = height * dpr;
  17932. ctx.clearRect(0, 0, width * dpr, height * dpr);
  17933. var pathTransform = {
  17934. position: path.position,
  17935. rotation: path.rotation,
  17936. scale: path.scale
  17937. };
  17938. path.position = [0, 0, 0];
  17939. path.rotation = 0;
  17940. path.scale = [1, 1];
  17941. if (path) {
  17942. path.brush(ctx);
  17943. }
  17944. var ImageShape = __webpack_require__(61);
  17945. var imgShape = new ImageShape({
  17946. id: id,
  17947. style: {
  17948. x: 0,
  17949. y: 0,
  17950. image: canvas
  17951. }
  17952. });
  17953. if (pathTransform.position != null) {
  17954. imgShape.position = path.position = pathTransform.position;
  17955. }
  17956. if (pathTransform.rotation != null) {
  17957. imgShape.rotation = path.rotation = pathTransform.rotation;
  17958. }
  17959. if (pathTransform.scale != null) {
  17960. imgShape.scale = path.scale = pathTransform.scale;
  17961. }
  17962. return imgShape;
  17963. },
  17964. _createPathToImage: function () {
  17965. var me = this;
  17966. return function (id, e, width, height) {
  17967. return me._pathToImage(
  17968. id, e, width, height, me.dpr
  17969. );
  17970. };
  17971. }
  17972. };
  17973. module.exports = Painter;
  17974. /***/ },
  17975. /* 93 */
  17976. /***/ function(module, exports, __webpack_require__) {
  17977. /**
  17978. * @module zrender/Layer
  17979. * @author pissang(https://www.github.com/pissang)
  17980. */
  17981. var util = __webpack_require__(4);
  17982. var config = __webpack_require__(41);
  17983. var Style = __webpack_require__(47);
  17984. var Pattern = __webpack_require__(59);
  17985. function returnFalse() {
  17986. return false;
  17987. }
  17988. /**
  17989. * 创建dom
  17990. *
  17991. * @inner
  17992. * @param {string} id dom id 待用
  17993. * @param {string} type dom type,such as canvas, div etc.
  17994. * @param {Painter} painter painter instance
  17995. * @param {number} number
  17996. */
  17997. function createDom(id, type, painter, dpr) {
  17998. var newDom = document.createElement(type);
  17999. var width = painter.getWidth();
  18000. var height = painter.getHeight();
  18001. var newDomStyle = newDom.style;
  18002. // 没append呢,请原谅我这样写,清晰~
  18003. newDomStyle.position = 'absolute';
  18004. newDomStyle.left = 0;
  18005. newDomStyle.top = 0;
  18006. newDomStyle.width = width + 'px';
  18007. newDomStyle.height = height + 'px';
  18008. newDom.width = width * dpr;
  18009. newDom.height = height * dpr;
  18010. // id不作为索引用,避免可能造成的重名,定义为私有属性
  18011. newDom.setAttribute('data-zr-dom-id', id);
  18012. return newDom;
  18013. }
  18014. /**
  18015. * @alias module:zrender/Layer
  18016. * @constructor
  18017. * @extends module:zrender/mixin/Transformable
  18018. * @param {string} id
  18019. * @param {module:zrender/Painter} painter
  18020. * @param {number} [dpr]
  18021. */
  18022. var Layer = function(id, painter, dpr) {
  18023. var dom;
  18024. dpr = dpr || config.devicePixelRatio;
  18025. if (typeof id === 'string') {
  18026. dom = createDom(id, 'canvas', painter, dpr);
  18027. }
  18028. // Not using isDom because in node it will return false
  18029. else if (util.isObject(id)) {
  18030. dom = id;
  18031. id = dom.id;
  18032. }
  18033. this.id = id;
  18034. this.dom = dom;
  18035. var domStyle = dom.style;
  18036. if (domStyle) { // Not in node
  18037. dom.onselectstart = returnFalse; // 避免页面选中的尴尬
  18038. domStyle['-webkit-user-select'] = 'none';
  18039. domStyle['user-select'] = 'none';
  18040. domStyle['-webkit-touch-callout'] = 'none';
  18041. domStyle['-webkit-tap-highlight-color'] = 'rgba(0,0,0,0)';
  18042. domStyle['padding'] = 0;
  18043. domStyle['margin'] = 0;
  18044. domStyle['border-width'] = 0;
  18045. }
  18046. this.domBack = null;
  18047. this.ctxBack = null;
  18048. this.painter = painter;
  18049. this.config = null;
  18050. // Configs
  18051. /**
  18052. * 每次清空画布的颜色
  18053. * @type {string}
  18054. * @default 0
  18055. */
  18056. this.clearColor = 0;
  18057. /**
  18058. * 是否开启动态模糊
  18059. * @type {boolean}
  18060. * @default false
  18061. */
  18062. this.motionBlur = false;
  18063. /**
  18064. * 在开启动态模糊的时候使用,与上一帧混合的alpha值,值越大尾迹越明显
  18065. * @type {number}
  18066. * @default 0.7
  18067. */
  18068. this.lastFrameAlpha = 0.7;
  18069. /**
  18070. * Layer dpr
  18071. * @type {number}
  18072. */
  18073. this.dpr = dpr;
  18074. };
  18075. Layer.prototype = {
  18076. constructor: Layer,
  18077. elCount: 0,
  18078. __dirty: true,
  18079. initContext: function () {
  18080. this.ctx = this.dom.getContext('2d');
  18081. this.ctx.dpr = this.dpr;
  18082. },
  18083. createBackBuffer: function () {
  18084. var dpr = this.dpr;
  18085. this.domBack = createDom('back-' + this.id, 'canvas', this.painter, dpr);
  18086. this.ctxBack = this.domBack.getContext('2d');
  18087. if (dpr != 1) {
  18088. this.ctxBack.scale(dpr, dpr);
  18089. }
  18090. },
  18091. /**
  18092. * @param {number} width
  18093. * @param {number} height
  18094. */
  18095. resize: function (width, height) {
  18096. var dpr = this.dpr;
  18097. var dom = this.dom;
  18098. var domStyle = dom.style;
  18099. var domBack = this.domBack;
  18100. domStyle.width = width + 'px';
  18101. domStyle.height = height + 'px';
  18102. dom.width = width * dpr;
  18103. dom.height = height * dpr;
  18104. if (domBack) {
  18105. domBack.width = width * dpr;
  18106. domBack.height = height * dpr;
  18107. if (dpr != 1) {
  18108. this.ctxBack.scale(dpr, dpr);
  18109. }
  18110. }
  18111. },
  18112. /**
  18113. * 清空该层画布
  18114. * @param {boolean} clearAll Clear all with out motion blur
  18115. */
  18116. clear: function (clearAll) {
  18117. var dom = this.dom;
  18118. var ctx = this.ctx;
  18119. var width = dom.width;
  18120. var height = dom.height;
  18121. var clearColor = this.clearColor;
  18122. var haveMotionBLur = this.motionBlur && !clearAll;
  18123. var lastFrameAlpha = this.lastFrameAlpha;
  18124. var dpr = this.dpr;
  18125. if (haveMotionBLur) {
  18126. if (!this.domBack) {
  18127. this.createBackBuffer();
  18128. }
  18129. this.ctxBack.globalCompositeOperation = 'copy';
  18130. this.ctxBack.drawImage(
  18131. dom, 0, 0,
  18132. width / dpr,
  18133. height / dpr
  18134. );
  18135. }
  18136. ctx.clearRect(0, 0, width, height);
  18137. if (clearColor) {
  18138. var clearColorGradientOrPattern;
  18139. // Gradient
  18140. if (clearColor.colorStops) {
  18141. // Cache canvas gradient
  18142. clearColorGradientOrPattern = clearColor.__canvasGradient || Style.getGradient(ctx, clearColor, {
  18143. x: 0,
  18144. y: 0,
  18145. width: width,
  18146. height: height
  18147. });
  18148. clearColor.__canvasGradient = clearColorGradientOrPattern;
  18149. }
  18150. // Pattern
  18151. else if (clearColor.image) {
  18152. clearColorGradientOrPattern = Pattern.prototype.getCanvasPattern.call(clearColor, ctx);
  18153. }
  18154. ctx.save();
  18155. ctx.fillStyle = clearColorGradientOrPattern || clearColor;
  18156. ctx.fillRect(0, 0, width, height);
  18157. ctx.restore();
  18158. }
  18159. if (haveMotionBLur) {
  18160. var domBack = this.domBack;
  18161. ctx.save();
  18162. ctx.globalAlpha = lastFrameAlpha;
  18163. ctx.drawImage(domBack, 0, 0, width, height);
  18164. ctx.restore();
  18165. }
  18166. }
  18167. };
  18168. module.exports = Layer;
  18169. /***/ },
  18170. /* 94 */
  18171. /***/ function(module, exports, __webpack_require__) {
  18172. var Gradient = __webpack_require__(79);
  18173. module.exports = function (ecModel) {
  18174. function encodeColor(seriesModel) {
  18175. var colorAccessPath = (seriesModel.visualColorAccessPath || 'itemStyle.normal.color').split('.');
  18176. var data = seriesModel.getData();
  18177. var color = seriesModel.get(colorAccessPath) // Set in itemStyle
  18178. || seriesModel.getColorFromPalette(seriesModel.get('name')); // Default color
  18179. // FIXME Set color function or use the platte color
  18180. data.setVisual('color', color);
  18181. // Only visible series has each data be visual encoded
  18182. if (!ecModel.isSeriesFiltered(seriesModel)) {
  18183. if (typeof color === 'function' && !(color instanceof Gradient)) {
  18184. data.each(function (idx) {
  18185. data.setItemVisual(
  18186. idx, 'color', color(seriesModel.getDataParams(idx))
  18187. );
  18188. });
  18189. }
  18190. // itemStyle in each data item
  18191. data.each(function (idx) {
  18192. var itemModel = data.getItemModel(idx);
  18193. var color = itemModel.get(colorAccessPath, true);
  18194. if (color != null) {
  18195. data.setItemVisual(idx, 'color', color);
  18196. }
  18197. });
  18198. }
  18199. }
  18200. ecModel.eachRawSeries(encodeColor);
  18201. };
  18202. /***/ },
  18203. /* 95 */
  18204. /***/ function(module, exports, __webpack_require__) {
  18205. // Compatitable with 2.0
  18206. var zrUtil = __webpack_require__(4);
  18207. var compatStyle = __webpack_require__(96);
  18208. function get(opt, path) {
  18209. path = path.split(',');
  18210. var obj = opt;
  18211. for (var i = 0; i < path.length; i++) {
  18212. obj = obj && obj[path[i]];
  18213. if (obj == null) {
  18214. break;
  18215. }
  18216. }
  18217. return obj;
  18218. }
  18219. function set(opt, path, val, overwrite) {
  18220. path = path.split(',');
  18221. var obj = opt;
  18222. var key;
  18223. for (var i = 0; i < path.length - 1; i++) {
  18224. key = path[i];
  18225. if (obj[key] == null) {
  18226. obj[key] = {};
  18227. }
  18228. obj = obj[key];
  18229. }
  18230. if (overwrite || obj[path[i]] == null) {
  18231. obj[path[i]] = val;
  18232. }
  18233. }
  18234. function compatLayoutProperties(option) {
  18235. each(LAYOUT_PROPERTIES, function (prop) {
  18236. if (prop[0] in option && !(prop[1] in option)) {
  18237. option[prop[1]] = option[prop[0]];
  18238. }
  18239. });
  18240. }
  18241. var LAYOUT_PROPERTIES = [
  18242. ['x', 'left'], ['y', 'top'], ['x2', 'right'], ['y2', 'bottom']
  18243. ];
  18244. var COMPATITABLE_COMPONENTS = [
  18245. 'grid', 'geo', 'parallel', 'legend', 'toolbox', 'title', 'visualMap', 'dataZoom', 'timeline'
  18246. ];
  18247. var COMPATITABLE_SERIES = [
  18248. 'bar', 'boxplot', 'candlestick', 'chord', 'effectScatter',
  18249. 'funnel', 'gauge', 'lines', 'graph', 'heatmap', 'line', 'map', 'parallel',
  18250. 'pie', 'radar', 'sankey', 'scatter', 'treemap'
  18251. ];
  18252. var each = zrUtil.each;
  18253. module.exports = function (option) {
  18254. each(option.series, function (seriesOpt) {
  18255. if (!zrUtil.isObject(seriesOpt)) {
  18256. return;
  18257. }
  18258. var seriesType = seriesOpt.type;
  18259. compatStyle(seriesOpt);
  18260. if (seriesType === 'pie' || seriesType === 'gauge') {
  18261. if (seriesOpt.clockWise != null) {
  18262. seriesOpt.clockwise = seriesOpt.clockWise;
  18263. }
  18264. }
  18265. if (seriesType === 'gauge') {
  18266. var pointerColor = get(seriesOpt, 'pointer.color');
  18267. pointerColor != null
  18268. && set(seriesOpt, 'itemStyle.normal.color', pointerColor);
  18269. }
  18270. for (var i = 0; i < COMPATITABLE_SERIES.length; i++) {
  18271. if (COMPATITABLE_SERIES[i] === seriesOpt.type) {
  18272. compatLayoutProperties(seriesOpt);
  18273. break;
  18274. }
  18275. }
  18276. });
  18277. // dataRange has changed to visualMap
  18278. if (option.dataRange) {
  18279. option.visualMap = option.dataRange;
  18280. }
  18281. each(COMPATITABLE_COMPONENTS, function (componentName) {
  18282. var options = option[componentName];
  18283. if (options) {
  18284. if (!zrUtil.isArray(options)) {
  18285. options = [options];
  18286. }
  18287. each(options, function (option) {
  18288. compatLayoutProperties(option);
  18289. });
  18290. }
  18291. });
  18292. };
  18293. /***/ },
  18294. /* 96 */
  18295. /***/ function(module, exports, __webpack_require__) {
  18296. var zrUtil = __webpack_require__(4);
  18297. var POSSIBLE_STYLES = [
  18298. 'areaStyle', 'lineStyle', 'nodeStyle', 'linkStyle',
  18299. 'chordStyle', 'label', 'labelLine'
  18300. ];
  18301. function compatItemStyle(opt) {
  18302. var itemStyleOpt = opt && opt.itemStyle;
  18303. if (itemStyleOpt) {
  18304. zrUtil.each(POSSIBLE_STYLES, function (styleName) {
  18305. var normalItemStyleOpt = itemStyleOpt.normal;
  18306. var emphasisItemStyleOpt = itemStyleOpt.emphasis;
  18307. if (normalItemStyleOpt && normalItemStyleOpt[styleName]) {
  18308. opt[styleName] = opt[styleName] || {};
  18309. if (!opt[styleName].normal) {
  18310. opt[styleName].normal = normalItemStyleOpt[styleName];
  18311. }
  18312. else {
  18313. zrUtil.merge(opt[styleName].normal, normalItemStyleOpt[styleName]);
  18314. }
  18315. normalItemStyleOpt[styleName] = null;
  18316. }
  18317. if (emphasisItemStyleOpt && emphasisItemStyleOpt[styleName]) {
  18318. opt[styleName] = opt[styleName] || {};
  18319. if (!opt[styleName].emphasis) {
  18320. opt[styleName].emphasis = emphasisItemStyleOpt[styleName];
  18321. }
  18322. else {
  18323. zrUtil.merge(opt[styleName].emphasis, emphasisItemStyleOpt[styleName]);
  18324. }
  18325. emphasisItemStyleOpt[styleName] = null;
  18326. }
  18327. });
  18328. }
  18329. }
  18330. module.exports = function (seriesOpt) {
  18331. if (!seriesOpt) {
  18332. return;
  18333. }
  18334. compatItemStyle(seriesOpt);
  18335. compatItemStyle(seriesOpt.markPoint);
  18336. compatItemStyle(seriesOpt.markLine);
  18337. var data = seriesOpt.data;
  18338. if (data) {
  18339. for (var i = 0; i < data.length; i++) {
  18340. compatItemStyle(data[i]);
  18341. }
  18342. // mark point data
  18343. var markPoint = seriesOpt.markPoint;
  18344. if (markPoint && markPoint.data) {
  18345. var mpData = markPoint.data;
  18346. for (var i = 0; i < mpData.length; i++) {
  18347. compatItemStyle(mpData[i]);
  18348. }
  18349. }
  18350. // mark line data
  18351. var markLine = seriesOpt.markLine;
  18352. if (markLine && markLine.data) {
  18353. var mlData = markLine.data;
  18354. for (var i = 0; i < mlData.length; i++) {
  18355. if (zrUtil.isArray(mlData[i])) {
  18356. compatItemStyle(mlData[i][0]);
  18357. compatItemStyle(mlData[i][1]);
  18358. }
  18359. else {
  18360. compatItemStyle(mlData[i]);
  18361. }
  18362. }
  18363. }
  18364. }
  18365. };
  18366. /***/ },
  18367. /* 97 */
  18368. /***/ function(module, exports, __webpack_require__) {
  18369. var graphic = __webpack_require__(43);
  18370. var zrUtil = __webpack_require__(4);
  18371. var PI = Math.PI;
  18372. /**
  18373. * @param {module:echarts/ExtensionAPI} api
  18374. * @param {Object} [opts]
  18375. * @param {string} [opts.text]
  18376. * @param {string} [opts.color]
  18377. * @param {string} [opts.textColor]
  18378. * @return {module:zrender/Element}
  18379. */
  18380. module.exports = function (api, opts) {
  18381. opts = opts || {};
  18382. zrUtil.defaults(opts, {
  18383. text: 'loading',
  18384. color: '#c23531',
  18385. textColor: '#000',
  18386. maskColor: 'rgba(255, 255, 255, 0.8)',
  18387. zlevel: 0
  18388. });
  18389. var mask = new graphic.Rect({
  18390. style: {
  18391. fill: opts.maskColor
  18392. },
  18393. zlevel: opts.zlevel,
  18394. z: 10000
  18395. });
  18396. var arc = new graphic.Arc({
  18397. shape: {
  18398. startAngle: -PI / 2,
  18399. endAngle: -PI / 2 + 0.1,
  18400. r: 10
  18401. },
  18402. style: {
  18403. stroke: opts.color,
  18404. lineCap: 'round',
  18405. lineWidth: 5
  18406. },
  18407. zlevel: opts.zlevel,
  18408. z: 10001
  18409. });
  18410. var labelRect = new graphic.Rect({
  18411. style: {
  18412. fill: 'none',
  18413. text: opts.text,
  18414. textPosition: 'right',
  18415. textDistance: 10,
  18416. textFill: opts.textColor
  18417. },
  18418. zlevel: opts.zlevel,
  18419. z: 10001
  18420. });
  18421. arc.animateShape(true)
  18422. .when(1000, {
  18423. endAngle: PI * 3 / 2
  18424. })
  18425. .start('circularInOut');
  18426. arc.animateShape(true)
  18427. .when(1000, {
  18428. startAngle: PI * 3 / 2
  18429. })
  18430. .delay(300)
  18431. .start('circularInOut');
  18432. var group = new graphic.Group();
  18433. group.add(arc);
  18434. group.add(labelRect);
  18435. group.add(mask);
  18436. // Inject resize
  18437. group.resize = function () {
  18438. var cx = api.getWidth() / 2;
  18439. var cy = api.getHeight() / 2;
  18440. arc.setShape({
  18441. cx: cx,
  18442. cy: cy
  18443. });
  18444. var r = arc.shape.r;
  18445. labelRect.setShape({
  18446. x: cx - r,
  18447. y: cy - r,
  18448. width: r * 2,
  18449. height: r * 2
  18450. });
  18451. mask.setShape({
  18452. x: 0,
  18453. y: 0,
  18454. width: api.getWidth(),
  18455. height: api.getHeight()
  18456. });
  18457. };
  18458. group.resize();
  18459. return group;
  18460. };
  18461. /***/ },
  18462. /* 98 */
  18463. /***/ function(module, exports, __webpack_require__) {
  18464. /* WEBPACK VAR INJECTION */(function(global) {/**
  18465. * List for data storage
  18466. * @module echarts/data/List
  18467. */
  18468. var UNDEFINED = 'undefined';
  18469. var globalObj = typeof window === 'undefined' ? global : window;
  18470. var Float64Array = typeof globalObj.Float64Array === UNDEFINED
  18471. ? Array : globalObj.Float64Array;
  18472. var Int32Array = typeof globalObj.Int32Array === UNDEFINED
  18473. ? Array : globalObj.Int32Array;
  18474. var dataCtors = {
  18475. 'float': Float64Array,
  18476. 'int': Int32Array,
  18477. // Ordinal data type can be string or int
  18478. 'ordinal': Array,
  18479. 'number': Array,
  18480. 'time': Array
  18481. };
  18482. var Model = __webpack_require__(12);
  18483. var DataDiffer = __webpack_require__(99);
  18484. var zrUtil = __webpack_require__(4);
  18485. var modelUtil = __webpack_require__(5);
  18486. var isObject = zrUtil.isObject;
  18487. var TRANSFERABLE_PROPERTIES = [
  18488. 'stackedOn', 'hasItemOption', '_nameList', '_idList', '_rawData'
  18489. ];
  18490. var transferProperties = function (a, b) {
  18491. zrUtil.each(TRANSFERABLE_PROPERTIES.concat(b.__wrappedMethods || []), function (propName) {
  18492. if (b.hasOwnProperty(propName)) {
  18493. a[propName] = b[propName];
  18494. }
  18495. });
  18496. a.__wrappedMethods = b.__wrappedMethods;
  18497. };
  18498. /**
  18499. * @constructor
  18500. * @alias module:echarts/data/List
  18501. *
  18502. * @param {Array.<string>} dimensions
  18503. * Dimensions should be concrete names like x, y, z, lng, lat, angle, radius
  18504. * @param {module:echarts/model/Model} hostModel
  18505. */
  18506. var List = function (dimensions, hostModel) {
  18507. dimensions = dimensions || ['x', 'y'];
  18508. var dimensionInfos = {};
  18509. var dimensionNames = [];
  18510. for (var i = 0; i < dimensions.length; i++) {
  18511. var dimensionName;
  18512. var dimensionInfo = {};
  18513. if (typeof dimensions[i] === 'string') {
  18514. dimensionName = dimensions[i];
  18515. dimensionInfo = {
  18516. name: dimensionName,
  18517. stackable: false,
  18518. // Type can be 'float', 'int', 'number'
  18519. // Default is number, Precision of float may not enough
  18520. type: 'number'
  18521. };
  18522. }
  18523. else {
  18524. dimensionInfo = dimensions[i];
  18525. dimensionName = dimensionInfo.name;
  18526. dimensionInfo.type = dimensionInfo.type || 'number';
  18527. }
  18528. dimensionNames.push(dimensionName);
  18529. dimensionInfos[dimensionName] = dimensionInfo;
  18530. }
  18531. /**
  18532. * @readOnly
  18533. * @type {Array.<string>}
  18534. */
  18535. this.dimensions = dimensionNames;
  18536. /**
  18537. * Infomation of each data dimension, like data type.
  18538. * @type {Object}
  18539. */
  18540. this._dimensionInfos = dimensionInfos;
  18541. /**
  18542. * @type {module:echarts/model/Model}
  18543. */
  18544. this.hostModel = hostModel;
  18545. /**
  18546. * @type {module:echarts/model/Model}
  18547. */
  18548. this.dataType;
  18549. /**
  18550. * Indices stores the indices of data subset after filtered.
  18551. * This data subset will be used in chart.
  18552. * @type {Array.<number>}
  18553. * @readOnly
  18554. */
  18555. this.indices = [];
  18556. /**
  18557. * Data storage
  18558. * @type {Object.<key, TypedArray|Array>}
  18559. * @private
  18560. */
  18561. this._storage = {};
  18562. /**
  18563. * @type {Array.<string>}
  18564. */
  18565. this._nameList = [];
  18566. /**
  18567. * @type {Array.<string>}
  18568. */
  18569. this._idList = [];
  18570. /**
  18571. * Models of data option is stored sparse for optimizing memory cost
  18572. * @type {Array.<module:echarts/model/Model>}
  18573. * @private
  18574. */
  18575. this._optionModels = [];
  18576. /**
  18577. * @param {module:echarts/data/List}
  18578. */
  18579. this.stackedOn = null;
  18580. /**
  18581. * Global visual properties after visual coding
  18582. * @type {Object}
  18583. * @private
  18584. */
  18585. this._visual = {};
  18586. /**
  18587. * Globel layout properties.
  18588. * @type {Object}
  18589. * @private
  18590. */
  18591. this._layout = {};
  18592. /**
  18593. * Item visual properties after visual coding
  18594. * @type {Array.<Object>}
  18595. * @private
  18596. */
  18597. this._itemVisuals = [];
  18598. /**
  18599. * Item layout properties after layout
  18600. * @type {Array.<Object>}
  18601. * @private
  18602. */
  18603. this._itemLayouts = [];
  18604. /**
  18605. * Graphic elemnents
  18606. * @type {Array.<module:zrender/Element>}
  18607. * @private
  18608. */
  18609. this._graphicEls = [];
  18610. /**
  18611. * @type {Array.<Array|Object>}
  18612. * @private
  18613. */
  18614. this._rawData;
  18615. /**
  18616. * @type {Object}
  18617. * @private
  18618. */
  18619. this._extent;
  18620. };
  18621. var listProto = List.prototype;
  18622. listProto.type = 'list';
  18623. /**
  18624. * If each data item has it's own option
  18625. * @type {boolean}
  18626. */
  18627. listProto.hasItemOption = true;
  18628. /**
  18629. * Get dimension name
  18630. * @param {string|number} dim
  18631. * Dimension can be concrete names like x, y, z, lng, lat, angle, radius
  18632. * Or a ordinal number. For example getDimensionInfo(0) will return 'x' or 'lng' or 'radius'
  18633. * @return {string} Concrete dim name.
  18634. */
  18635. listProto.getDimension = function (dim) {
  18636. if (!isNaN(dim)) {
  18637. dim = this.dimensions[dim] || dim;
  18638. }
  18639. return dim;
  18640. };
  18641. /**
  18642. * Get type and stackable info of particular dimension
  18643. * @param {string|number} dim
  18644. * Dimension can be concrete names like x, y, z, lng, lat, angle, radius
  18645. * Or a ordinal number. For example getDimensionInfo(0) will return 'x' or 'lng' or 'radius'
  18646. */
  18647. listProto.getDimensionInfo = function (dim) {
  18648. return zrUtil.clone(this._dimensionInfos[this.getDimension(dim)]);
  18649. };
  18650. /**
  18651. * Initialize from data
  18652. * @param {Array.<Object|number|Array>} data
  18653. * @param {Array.<string>} [nameList]
  18654. * @param {Function} [dimValueGetter] (dataItem, dimName, dataIndex, dimIndex) => number
  18655. */
  18656. listProto.initData = function (data, nameList, dimValueGetter) {
  18657. data = data || [];
  18658. if (true) {
  18659. if (!zrUtil.isArray(data)) {
  18660. throw new Error('Invalid data.');
  18661. }
  18662. }
  18663. this._rawData = data;
  18664. // Clear
  18665. var storage = this._storage = {};
  18666. var indices = this.indices = [];
  18667. var dimensions = this.dimensions;
  18668. var size = data.length;
  18669. var dimensionInfoMap = this._dimensionInfos;
  18670. var idList = [];
  18671. var nameRepeatCount = {};
  18672. nameList = nameList || [];
  18673. // Init storage
  18674. for (var i = 0; i < dimensions.length; i++) {
  18675. var dimInfo = dimensionInfoMap[dimensions[i]];
  18676. var DataCtor = dataCtors[dimInfo.type];
  18677. storage[dimensions[i]] = new DataCtor(size);
  18678. }
  18679. var self = this;
  18680. if (!dimValueGetter) {
  18681. self.hasItemOption = false;
  18682. }
  18683. // Default dim value getter
  18684. dimValueGetter = dimValueGetter || function (dataItem, dimName, dataIndex, dimIndex) {
  18685. var value = modelUtil.getDataItemValue(dataItem);
  18686. // If any dataItem is like { value: 10 }
  18687. if (modelUtil.isDataItemOption(dataItem)) {
  18688. self.hasItemOption = true;
  18689. }
  18690. return modelUtil.converDataValue(
  18691. (value instanceof Array)
  18692. ? value[dimIndex]
  18693. // If value is a single number or something else not array.
  18694. : value,
  18695. dimensionInfoMap[dimName]
  18696. );
  18697. };
  18698. for (var idx = 0; idx < data.length; idx++) {
  18699. var dataItem = data[idx];
  18700. // Each data item is value
  18701. // [1, 2]
  18702. // 2
  18703. // Bar chart, line chart which uses category axis
  18704. // only gives the 'y' value. 'x' value is the indices of cateogry
  18705. // Use a tempValue to normalize the value to be a (x, y) value
  18706. // Store the data by dimensions
  18707. for (var k = 0; k < dimensions.length; k++) {
  18708. var dim = dimensions[k];
  18709. var dimStorage = storage[dim];
  18710. // PENDING NULL is empty or zero
  18711. dimStorage[idx] = dimValueGetter(dataItem, dim, idx, k);
  18712. }
  18713. indices.push(idx);
  18714. }
  18715. // Use the name in option and create id
  18716. for (var i = 0; i < data.length; i++) {
  18717. if (!nameList[i]) {
  18718. if (data[i] && data[i].name != null) {
  18719. nameList[i] = data[i].name;
  18720. }
  18721. }
  18722. var name = nameList[i] || '';
  18723. // Try using the id in option
  18724. var id = data[i] && data[i].id;
  18725. if (!id && name) {
  18726. // Use name as id and add counter to avoid same name
  18727. nameRepeatCount[name] = nameRepeatCount[name] || 0;
  18728. id = name;
  18729. if (nameRepeatCount[name] > 0) {
  18730. id += '__ec__' + nameRepeatCount[name];
  18731. }
  18732. nameRepeatCount[name]++;
  18733. }
  18734. id && (idList[i] = id);
  18735. }
  18736. this._nameList = nameList;
  18737. this._idList = idList;
  18738. };
  18739. /**
  18740. * @return {number}
  18741. */
  18742. listProto.count = function () {
  18743. return this.indices.length;
  18744. };
  18745. /**
  18746. * Get value. Return NaN if idx is out of range.
  18747. * @param {string} dim Dim must be concrete name.
  18748. * @param {number} idx
  18749. * @param {boolean} stack
  18750. * @return {number}
  18751. */
  18752. listProto.get = function (dim, idx, stack) {
  18753. var storage = this._storage;
  18754. var dataIndex = this.indices[idx];
  18755. // If value not exists
  18756. if (dataIndex == null) {
  18757. return NaN;
  18758. }
  18759. var value = storage[dim] && storage[dim][dataIndex];
  18760. // FIXME ordinal data type is not stackable
  18761. if (stack) {
  18762. var dimensionInfo = this._dimensionInfos[dim];
  18763. if (dimensionInfo && dimensionInfo.stackable) {
  18764. var stackedOn = this.stackedOn;
  18765. while (stackedOn) {
  18766. // Get no stacked data of stacked on
  18767. var stackedValue = stackedOn.get(dim, idx);
  18768. // Considering positive stack, negative stack and empty data
  18769. if ((value >= 0 && stackedValue > 0) // Positive stack
  18770. || (value <= 0 && stackedValue < 0) // Negative stack
  18771. ) {
  18772. value += stackedValue;
  18773. }
  18774. stackedOn = stackedOn.stackedOn;
  18775. }
  18776. }
  18777. }
  18778. return value;
  18779. };
  18780. /**
  18781. * Get value for multi dimensions.
  18782. * @param {Array.<string>} [dimensions] If ignored, using all dimensions.
  18783. * @param {number} idx
  18784. * @param {boolean} stack
  18785. * @return {number}
  18786. */
  18787. listProto.getValues = function (dimensions, idx, stack) {
  18788. var values = [];
  18789. if (!zrUtil.isArray(dimensions)) {
  18790. stack = idx;
  18791. idx = dimensions;
  18792. dimensions = this.dimensions;
  18793. }
  18794. for (var i = 0, len = dimensions.length; i < len; i++) {
  18795. values.push(this.get(dimensions[i], idx, stack));
  18796. }
  18797. return values;
  18798. };
  18799. /**
  18800. * If value is NaN. Inlcuding '-'
  18801. * @param {string} dim
  18802. * @param {number} idx
  18803. * @return {number}
  18804. */
  18805. listProto.hasValue = function (idx) {
  18806. var dimensions = this.dimensions;
  18807. var dimensionInfos = this._dimensionInfos;
  18808. for (var i = 0, len = dimensions.length; i < len; i++) {
  18809. if (
  18810. // Ordinal type can be string or number
  18811. dimensionInfos[dimensions[i]].type !== 'ordinal'
  18812. && isNaN(this.get(dimensions[i], idx))
  18813. ) {
  18814. return false;
  18815. }
  18816. }
  18817. return true;
  18818. };
  18819. /**
  18820. * Get extent of data in one dimension
  18821. * @param {string} dim
  18822. * @param {boolean} stack
  18823. * @param {Function} filter
  18824. */
  18825. listProto.getDataExtent = function (dim, stack, filter) {
  18826. dim = this.getDimension(dim);
  18827. var dimData = this._storage[dim];
  18828. var dimInfo = this.getDimensionInfo(dim);
  18829. stack = (dimInfo && dimInfo.stackable) && stack;
  18830. var dimExtent = (this._extent || (this._extent = {}))[dim + (!!stack)];
  18831. var value;
  18832. if (dimExtent) {
  18833. return dimExtent;
  18834. }
  18835. // var dimInfo = this._dimensionInfos[dim];
  18836. if (dimData) {
  18837. var min = Infinity;
  18838. var max = -Infinity;
  18839. // var isOrdinal = dimInfo.type === 'ordinal';
  18840. for (var i = 0, len = this.count(); i < len; i++) {
  18841. value = this.get(dim, i, stack);
  18842. // FIXME
  18843. // if (isOrdinal && typeof value === 'string') {
  18844. // value = zrUtil.indexOf(dimData, value);
  18845. // }
  18846. if (!filter || filter(value, dim, i)) {
  18847. value < min && (min = value);
  18848. value > max && (max = value);
  18849. }
  18850. }
  18851. return (this._extent[dim + !!stack] = [min, max]);
  18852. }
  18853. else {
  18854. return [Infinity, -Infinity];
  18855. }
  18856. };
  18857. /**
  18858. * Get sum of data in one dimension
  18859. * @param {string} dim
  18860. * @param {boolean} stack
  18861. */
  18862. listProto.getSum = function (dim, stack) {
  18863. var dimData = this._storage[dim];
  18864. var sum = 0;
  18865. if (dimData) {
  18866. for (var i = 0, len = this.count(); i < len; i++) {
  18867. var value = this.get(dim, i, stack);
  18868. if (!isNaN(value)) {
  18869. sum += value;
  18870. }
  18871. }
  18872. }
  18873. return sum;
  18874. };
  18875. /**
  18876. * Retreive the index with given value
  18877. * @param {number} idx
  18878. * @param {number} value
  18879. * @return {number}
  18880. */
  18881. // FIXME Precision of float value
  18882. listProto.indexOf = function (dim, value) {
  18883. var storage = this._storage;
  18884. var dimData = storage[dim];
  18885. var indices = this.indices;
  18886. if (dimData) {
  18887. for (var i = 0, len = indices.length; i < len; i++) {
  18888. var rawIndex = indices[i];
  18889. if (dimData[rawIndex] === value) {
  18890. return i;
  18891. }
  18892. }
  18893. }
  18894. return -1;
  18895. };
  18896. /**
  18897. * Retreive the index with given name
  18898. * @param {number} idx
  18899. * @param {number} name
  18900. * @return {number}
  18901. */
  18902. listProto.indexOfName = function (name) {
  18903. var indices = this.indices;
  18904. var nameList = this._nameList;
  18905. for (var i = 0, len = indices.length; i < len; i++) {
  18906. var rawIndex = indices[i];
  18907. if (nameList[rawIndex] === name) {
  18908. return i;
  18909. }
  18910. }
  18911. return -1;
  18912. };
  18913. /**
  18914. * Retreive the index with given raw data index
  18915. * @param {number} idx
  18916. * @param {number} name
  18917. * @return {number}
  18918. */
  18919. listProto.indexOfRawIndex = function (rawIndex) {
  18920. // Indices are ascending
  18921. var indices = this.indices;
  18922. // If rawIndex === dataIndex
  18923. var rawDataIndex = indices[rawIndex];
  18924. if (rawDataIndex != null && rawDataIndex === rawIndex) {
  18925. return rawIndex;
  18926. }
  18927. var left = 0;
  18928. var right = indices.length - 1;
  18929. while (left <= right) {
  18930. var mid = (left + right) / 2 | 0;
  18931. if (indices[mid] < rawIndex) {
  18932. left = mid + 1;
  18933. }
  18934. else if (indices[mid] > rawIndex) {
  18935. right = mid - 1;
  18936. }
  18937. else {
  18938. return mid;
  18939. }
  18940. }
  18941. return -1;
  18942. };
  18943. /**
  18944. * Retreive the index of nearest value
  18945. * @param {string} dim
  18946. * @param {number} value
  18947. * @param {boolean} stack If given value is after stacked
  18948. * @param {number} [maxDistance=Infinity]
  18949. * @return {number}
  18950. */
  18951. listProto.indexOfNearest = function (dim, value, stack, maxDistance) {
  18952. var storage = this._storage;
  18953. var dimData = storage[dim];
  18954. if (maxDistance == null) {
  18955. maxDistance = Infinity;
  18956. }
  18957. var nearestIdx = -1;
  18958. if (dimData) {
  18959. var minDist = Number.MAX_VALUE;
  18960. for (var i = 0, len = this.count(); i < len; i++) {
  18961. var diff = value - this.get(dim, i, stack);
  18962. var dist = Math.abs(diff);
  18963. if (
  18964. diff <= maxDistance
  18965. && (dist < minDist
  18966. // For the case of two data are same on xAxis, which has sequence data.
  18967. // Show the nearest index
  18968. // https://github.com/ecomfe/echarts/issues/2869
  18969. || (dist === minDist && diff > 0)
  18970. )
  18971. ) {
  18972. minDist = dist;
  18973. nearestIdx = i;
  18974. }
  18975. }
  18976. }
  18977. return nearestIdx;
  18978. };
  18979. /**
  18980. * Get raw data index
  18981. * @param {number} idx
  18982. * @return {number}
  18983. */
  18984. listProto.getRawIndex = function (idx) {
  18985. var rawIdx = this.indices[idx];
  18986. return rawIdx == null ? -1 : rawIdx;
  18987. };
  18988. /**
  18989. * Get raw data item
  18990. * @param {number} idx
  18991. * @return {number}
  18992. */
  18993. listProto.getRawDataItem = function (idx) {
  18994. return this._rawData[this.getRawIndex(idx)];
  18995. };
  18996. /**
  18997. * @param {number} idx
  18998. * @param {boolean} [notDefaultIdx=false]
  18999. * @return {string}
  19000. */
  19001. listProto.getName = function (idx) {
  19002. return this._nameList[this.indices[idx]] || '';
  19003. };
  19004. /**
  19005. * @param {number} idx
  19006. * @param {boolean} [notDefaultIdx=false]
  19007. * @return {string}
  19008. */
  19009. listProto.getId = function (idx) {
  19010. return this._idList[this.indices[idx]] || (this.getRawIndex(idx) + '');
  19011. };
  19012. function normalizeDimensions(dimensions) {
  19013. if (!zrUtil.isArray(dimensions)) {
  19014. dimensions = [dimensions];
  19015. }
  19016. return dimensions;
  19017. }
  19018. /**
  19019. * Data iteration
  19020. * @param {string|Array.<string>}
  19021. * @param {Function} cb
  19022. * @param {boolean} [stack=false]
  19023. * @param {*} [context=this]
  19024. *
  19025. * @example
  19026. * list.each('x', function (x, idx) {});
  19027. * list.each(['x', 'y'], function (x, y, idx) {});
  19028. * list.each(function (idx) {})
  19029. */
  19030. listProto.each = function (dims, cb, stack, context) {
  19031. if (typeof dims === 'function') {
  19032. context = stack;
  19033. stack = cb;
  19034. cb = dims;
  19035. dims = [];
  19036. }
  19037. dims = zrUtil.map(normalizeDimensions(dims), this.getDimension, this);
  19038. var value = [];
  19039. var dimSize = dims.length;
  19040. var indices = this.indices;
  19041. context = context || this;
  19042. for (var i = 0; i < indices.length; i++) {
  19043. // Simple optimization
  19044. switch (dimSize) {
  19045. case 0:
  19046. cb.call(context, i);
  19047. break;
  19048. case 1:
  19049. cb.call(context, this.get(dims[0], i, stack), i);
  19050. break;
  19051. case 2:
  19052. cb.call(context, this.get(dims[0], i, stack), this.get(dims[1], i, stack), i);
  19053. break;
  19054. default:
  19055. for (var k = 0; k < dimSize; k++) {
  19056. value[k] = this.get(dims[k], i, stack);
  19057. }
  19058. // Index
  19059. value[k] = i;
  19060. cb.apply(context, value);
  19061. }
  19062. }
  19063. };
  19064. /**
  19065. * Data filter
  19066. * @param {string|Array.<string>}
  19067. * @param {Function} cb
  19068. * @param {boolean} [stack=false]
  19069. * @param {*} [context=this]
  19070. */
  19071. listProto.filterSelf = function (dimensions, cb, stack, context) {
  19072. if (typeof dimensions === 'function') {
  19073. context = stack;
  19074. stack = cb;
  19075. cb = dimensions;
  19076. dimensions = [];
  19077. }
  19078. dimensions = zrUtil.map(
  19079. normalizeDimensions(dimensions), this.getDimension, this
  19080. );
  19081. var newIndices = [];
  19082. var value = [];
  19083. var dimSize = dimensions.length;
  19084. var indices = this.indices;
  19085. context = context || this;
  19086. for (var i = 0; i < indices.length; i++) {
  19087. var keep;
  19088. // Simple optimization
  19089. if (dimSize === 1) {
  19090. keep = cb.call(
  19091. context, this.get(dimensions[0], i, stack), i
  19092. );
  19093. }
  19094. else {
  19095. for (var k = 0; k < dimSize; k++) {
  19096. value[k] = this.get(dimensions[k], i, stack);
  19097. }
  19098. value[k] = i;
  19099. keep = cb.apply(context, value);
  19100. }
  19101. if (keep) {
  19102. newIndices.push(indices[i]);
  19103. }
  19104. }
  19105. this.indices = newIndices;
  19106. // Reset data extent
  19107. this._extent = {};
  19108. return this;
  19109. };
  19110. /**
  19111. * Data mapping to a plain array
  19112. * @param {string|Array.<string>} [dimensions]
  19113. * @param {Function} cb
  19114. * @param {boolean} [stack=false]
  19115. * @param {*} [context=this]
  19116. * @return {Array}
  19117. */
  19118. listProto.mapArray = function (dimensions, cb, stack, context) {
  19119. if (typeof dimensions === 'function') {
  19120. context = stack;
  19121. stack = cb;
  19122. cb = dimensions;
  19123. dimensions = [];
  19124. }
  19125. var result = [];
  19126. this.each(dimensions, function () {
  19127. result.push(cb && cb.apply(this, arguments));
  19128. }, stack, context);
  19129. return result;
  19130. };
  19131. function cloneListForMapAndSample(original, excludeDimensions) {
  19132. var allDimensions = original.dimensions;
  19133. var list = new List(
  19134. zrUtil.map(allDimensions, original.getDimensionInfo, original),
  19135. original.hostModel
  19136. );
  19137. // FIXME If needs stackedOn, value may already been stacked
  19138. transferProperties(list, original);
  19139. var storage = list._storage = {};
  19140. var originalStorage = original._storage;
  19141. // Init storage
  19142. for (var i = 0; i < allDimensions.length; i++) {
  19143. var dim = allDimensions[i];
  19144. var dimStore = originalStorage[dim];
  19145. if (zrUtil.indexOf(excludeDimensions, dim) >= 0) {
  19146. storage[dim] = new dimStore.constructor(
  19147. originalStorage[dim].length
  19148. );
  19149. }
  19150. else {
  19151. // Direct reference for other dimensions
  19152. storage[dim] = originalStorage[dim];
  19153. }
  19154. }
  19155. return list;
  19156. }
  19157. /**
  19158. * Data mapping to a new List with given dimensions
  19159. * @param {string|Array.<string>} dimensions
  19160. * @param {Function} cb
  19161. * @param {boolean} [stack=false]
  19162. * @param {*} [context=this]
  19163. * @return {Array}
  19164. */
  19165. listProto.map = function (dimensions, cb, stack, context) {
  19166. dimensions = zrUtil.map(
  19167. normalizeDimensions(dimensions), this.getDimension, this
  19168. );
  19169. var list = cloneListForMapAndSample(this, dimensions);
  19170. // Following properties are all immutable.
  19171. // So we can reference to the same value
  19172. var indices = list.indices = this.indices;
  19173. var storage = list._storage;
  19174. var tmpRetValue = [];
  19175. this.each(dimensions, function () {
  19176. var idx = arguments[arguments.length - 1];
  19177. var retValue = cb && cb.apply(this, arguments);
  19178. if (retValue != null) {
  19179. // a number
  19180. if (typeof retValue === 'number') {
  19181. tmpRetValue[0] = retValue;
  19182. retValue = tmpRetValue;
  19183. }
  19184. for (var i = 0; i < retValue.length; i++) {
  19185. var dim = dimensions[i];
  19186. var dimStore = storage[dim];
  19187. var rawIdx = indices[idx];
  19188. if (dimStore) {
  19189. dimStore[rawIdx] = retValue[i];
  19190. }
  19191. }
  19192. }
  19193. }, stack, context);
  19194. return list;
  19195. };
  19196. /**
  19197. * Large data down sampling on given dimension
  19198. * @param {string} dimension
  19199. * @param {number} rate
  19200. * @param {Function} sampleValue
  19201. * @param {Function} sampleIndex Sample index for name and id
  19202. */
  19203. listProto.downSample = function (dimension, rate, sampleValue, sampleIndex) {
  19204. var list = cloneListForMapAndSample(this, [dimension]);
  19205. var storage = this._storage;
  19206. var targetStorage = list._storage;
  19207. var originalIndices = this.indices;
  19208. var indices = list.indices = [];
  19209. var frameValues = [];
  19210. var frameIndices = [];
  19211. var frameSize = Math.floor(1 / rate);
  19212. var dimStore = targetStorage[dimension];
  19213. var len = this.count();
  19214. // Copy data from original data
  19215. for (var i = 0; i < storage[dimension].length; i++) {
  19216. targetStorage[dimension][i] = storage[dimension][i];
  19217. }
  19218. for (var i = 0; i < len; i += frameSize) {
  19219. // Last frame
  19220. if (frameSize > len - i) {
  19221. frameSize = len - i;
  19222. frameValues.length = frameSize;
  19223. }
  19224. for (var k = 0; k < frameSize; k++) {
  19225. var idx = originalIndices[i + k];
  19226. frameValues[k] = dimStore[idx];
  19227. frameIndices[k] = idx;
  19228. }
  19229. var value = sampleValue(frameValues);
  19230. var idx = frameIndices[sampleIndex(frameValues, value) || 0];
  19231. // Only write value on the filtered data
  19232. dimStore[idx] = value;
  19233. indices.push(idx);
  19234. }
  19235. return list;
  19236. };
  19237. /**
  19238. * Get model of one data item.
  19239. *
  19240. * @param {number} idx
  19241. */
  19242. // FIXME Model proxy ?
  19243. listProto.getItemModel = function (idx) {
  19244. var hostModel = this.hostModel;
  19245. idx = this.indices[idx];
  19246. return new Model(this._rawData[idx], hostModel, hostModel && hostModel.ecModel);
  19247. };
  19248. /**
  19249. * Create a data differ
  19250. * @param {module:echarts/data/List} otherList
  19251. * @return {module:echarts/data/DataDiffer}
  19252. */
  19253. listProto.diff = function (otherList) {
  19254. var idList = this._idList;
  19255. var otherIdList = otherList && otherList._idList;
  19256. var val;
  19257. // Use prefix to avoid index to be the same as otherIdList[idx],
  19258. // which will cause weird udpate animation.
  19259. var prefix = 'e\0\0';
  19260. return new DataDiffer(
  19261. otherList ? otherList.indices : [],
  19262. this.indices,
  19263. function (idx) {
  19264. return (val = otherIdList[idx]) != null ? val : prefix + idx;
  19265. },
  19266. function (idx) {
  19267. return (val = idList[idx]) != null ? val : prefix + idx;
  19268. }
  19269. );
  19270. };
  19271. /**
  19272. * Get visual property.
  19273. * @param {string} key
  19274. */
  19275. listProto.getVisual = function (key) {
  19276. var visual = this._visual;
  19277. return visual && visual[key];
  19278. };
  19279. /**
  19280. * Set visual property
  19281. * @param {string|Object} key
  19282. * @param {*} [value]
  19283. *
  19284. * @example
  19285. * setVisual('color', color);
  19286. * setVisual({
  19287. * 'color': color
  19288. * });
  19289. */
  19290. listProto.setVisual = function (key, val) {
  19291. if (isObject(key)) {
  19292. for (var name in key) {
  19293. if (key.hasOwnProperty(name)) {
  19294. this.setVisual(name, key[name]);
  19295. }
  19296. }
  19297. return;
  19298. }
  19299. this._visual = this._visual || {};
  19300. this._visual[key] = val;
  19301. };
  19302. /**
  19303. * Set layout property.
  19304. * @param {string} key
  19305. * @param {*} [val]
  19306. */
  19307. listProto.setLayout = function (key, val) {
  19308. if (isObject(key)) {
  19309. for (var name in key) {
  19310. if (key.hasOwnProperty(name)) {
  19311. this.setLayout(name, key[name]);
  19312. }
  19313. }
  19314. return;
  19315. }
  19316. this._layout[key] = val;
  19317. };
  19318. /**
  19319. * Get layout property.
  19320. * @param {string} key.
  19321. * @return {*}
  19322. */
  19323. listProto.getLayout = function (key) {
  19324. return this._layout[key];
  19325. };
  19326. /**
  19327. * Get layout of single data item
  19328. * @param {number} idx
  19329. */
  19330. listProto.getItemLayout = function (idx) {
  19331. return this._itemLayouts[idx];
  19332. };
  19333. /**
  19334. * Set layout of single data item
  19335. * @param {number} idx
  19336. * @param {Object} layout
  19337. * @param {boolean=} [merge=false]
  19338. */
  19339. listProto.setItemLayout = function (idx, layout, merge) {
  19340. this._itemLayouts[idx] = merge
  19341. ? zrUtil.extend(this._itemLayouts[idx] || {}, layout)
  19342. : layout;
  19343. };
  19344. /**
  19345. * Clear all layout of single data item
  19346. */
  19347. listProto.clearItemLayouts = function () {
  19348. this._itemLayouts.length = 0;
  19349. };
  19350. /**
  19351. * Get visual property of single data item
  19352. * @param {number} idx
  19353. * @param {string} key
  19354. * @param {boolean} ignoreParent
  19355. */
  19356. listProto.getItemVisual = function (idx, key, ignoreParent) {
  19357. var itemVisual = this._itemVisuals[idx];
  19358. var val = itemVisual && itemVisual[key];
  19359. if (val == null && !ignoreParent) {
  19360. // Use global visual property
  19361. return this.getVisual(key);
  19362. }
  19363. return val;
  19364. };
  19365. /**
  19366. * Set visual property of single data item
  19367. *
  19368. * @param {number} idx
  19369. * @param {string|Object} key
  19370. * @param {*} [value]
  19371. *
  19372. * @example
  19373. * setItemVisual(0, 'color', color);
  19374. * setItemVisual(0, {
  19375. * 'color': color
  19376. * });
  19377. */
  19378. listProto.setItemVisual = function (idx, key, value) {
  19379. var itemVisual = this._itemVisuals[idx] || {};
  19380. this._itemVisuals[idx] = itemVisual;
  19381. if (isObject(key)) {
  19382. for (var name in key) {
  19383. if (key.hasOwnProperty(name)) {
  19384. itemVisual[name] = key[name];
  19385. }
  19386. }
  19387. return;
  19388. }
  19389. itemVisual[key] = value;
  19390. };
  19391. /**
  19392. * Clear itemVisuals and list visual.
  19393. */
  19394. listProto.clearAllVisual = function () {
  19395. this._visual = {};
  19396. this._itemVisuals = [];
  19397. };
  19398. var setItemDataAndSeriesIndex = function (child) {
  19399. child.seriesIndex = this.seriesIndex;
  19400. child.dataIndex = this.dataIndex;
  19401. child.dataType = this.dataType;
  19402. };
  19403. /**
  19404. * Set graphic element relative to data. It can be set as null
  19405. * @param {number} idx
  19406. * @param {module:zrender/Element} [el]
  19407. */
  19408. listProto.setItemGraphicEl = function (idx, el) {
  19409. var hostModel = this.hostModel;
  19410. if (el) {
  19411. // Add data index and series index for indexing the data by element
  19412. // Useful in tooltip
  19413. el.dataIndex = idx;
  19414. el.dataType = this.dataType;
  19415. el.seriesIndex = hostModel && hostModel.seriesIndex;
  19416. if (el.type === 'group') {
  19417. el.traverse(setItemDataAndSeriesIndex, el);
  19418. }
  19419. }
  19420. this._graphicEls[idx] = el;
  19421. };
  19422. /**
  19423. * @param {number} idx
  19424. * @return {module:zrender/Element}
  19425. */
  19426. listProto.getItemGraphicEl = function (idx) {
  19427. return this._graphicEls[idx];
  19428. };
  19429. /**
  19430. * @param {Function} cb
  19431. * @param {*} context
  19432. */
  19433. listProto.eachItemGraphicEl = function (cb, context) {
  19434. zrUtil.each(this._graphicEls, function (el, idx) {
  19435. if (el) {
  19436. cb && cb.call(context, el, idx);
  19437. }
  19438. });
  19439. };
  19440. /**
  19441. * Shallow clone a new list except visual and layout properties, and graph elements.
  19442. * New list only change the indices.
  19443. */
  19444. listProto.cloneShallow = function () {
  19445. var dimensionInfoList = zrUtil.map(this.dimensions, this.getDimensionInfo, this);
  19446. var list = new List(dimensionInfoList, this.hostModel);
  19447. // FIXME
  19448. list._storage = this._storage;
  19449. transferProperties(list, this);
  19450. // Clone will not change the data extent and indices
  19451. list.indices = this.indices.slice();
  19452. if (this._extent) {
  19453. list._extent = zrUtil.extend({}, this._extent);
  19454. }
  19455. return list;
  19456. };
  19457. /**
  19458. * Wrap some method to add more feature
  19459. * @param {string} methodName
  19460. * @param {Function} injectFunction
  19461. */
  19462. listProto.wrapMethod = function (methodName, injectFunction) {
  19463. var originalMethod = this[methodName];
  19464. if (typeof originalMethod !== 'function') {
  19465. return;
  19466. }
  19467. this.__wrappedMethods = this.__wrappedMethods || [];
  19468. this.__wrappedMethods.push(methodName);
  19469. this[methodName] = function () {
  19470. var res = originalMethod.apply(this, arguments);
  19471. return injectFunction.apply(this, [res].concat(zrUtil.slice(arguments)));
  19472. };
  19473. };
  19474. // Methods that create a new list based on this list should be listed here.
  19475. // Notice that those method should `RETURN` the new list.
  19476. listProto.TRANSFERABLE_METHODS = ['cloneShallow', 'downSample', 'map'];
  19477. // Methods that change indices of this list should be listed here.
  19478. listProto.CHANGABLE_METHODS = ['filterSelf'];
  19479. module.exports = List;
  19480. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  19481. /***/ },
  19482. /* 99 */
  19483. /***/ function(module, exports) {
  19484. 'use strict';
  19485. function defaultKeyGetter(item) {
  19486. return item;
  19487. }
  19488. function DataDiffer(oldArr, newArr, oldKeyGetter, newKeyGetter) {
  19489. this._old = oldArr;
  19490. this._new = newArr;
  19491. this._oldKeyGetter = oldKeyGetter || defaultKeyGetter;
  19492. this._newKeyGetter = newKeyGetter || defaultKeyGetter;
  19493. }
  19494. DataDiffer.prototype = {
  19495. constructor: DataDiffer,
  19496. /**
  19497. * Callback function when add a data
  19498. */
  19499. add: function (func) {
  19500. this._add = func;
  19501. return this;
  19502. },
  19503. /**
  19504. * Callback function when update a data
  19505. */
  19506. update: function (func) {
  19507. this._update = func;
  19508. return this;
  19509. },
  19510. /**
  19511. * Callback function when remove a data
  19512. */
  19513. remove: function (func) {
  19514. this._remove = func;
  19515. return this;
  19516. },
  19517. execute: function () {
  19518. var oldArr = this._old;
  19519. var newArr = this._new;
  19520. var oldKeyGetter = this._oldKeyGetter;
  19521. var newKeyGetter = this._newKeyGetter;
  19522. var oldDataIndexMap = {};
  19523. var newDataIndexMap = {};
  19524. var oldDataKeyArr = [];
  19525. var newDataKeyArr = [];
  19526. var i;
  19527. initIndexMap(oldArr, oldDataIndexMap, oldDataKeyArr, oldKeyGetter);
  19528. initIndexMap(newArr, newDataIndexMap, newDataKeyArr, newKeyGetter);
  19529. // Travel by inverted order to make sure order consistency
  19530. // when duplicate keys exists (consider newDataIndex.pop() below).
  19531. // For performance consideration, these code below do not look neat.
  19532. for (i = 0; i < oldArr.length; i++) {
  19533. var key = oldDataKeyArr[i];
  19534. var idx = newDataIndexMap[key];
  19535. // idx can never be empty array here. see 'set null' logic below.
  19536. if (idx != null) {
  19537. // Consider there is duplicate key (for example, use dataItem.name as key).
  19538. // We should make sure every item in newArr and oldArr can be visited.
  19539. var len = idx.length;
  19540. if (len) {
  19541. len === 1 && (newDataIndexMap[key] = null);
  19542. idx = idx.unshift();
  19543. }
  19544. else {
  19545. newDataIndexMap[key] = null;
  19546. }
  19547. this._update && this._update(idx, i);
  19548. }
  19549. else {
  19550. this._remove && this._remove(i);
  19551. }
  19552. }
  19553. for (var i = 0; i < newDataKeyArr.length; i++) {
  19554. var key = newDataKeyArr[i];
  19555. if (newDataIndexMap.hasOwnProperty(key)) {
  19556. var idx = newDataIndexMap[key];
  19557. if (idx == null) {
  19558. continue;
  19559. }
  19560. // idx can never be empty array here. see 'set null' logic above.
  19561. if (!idx.length) {
  19562. this._add && this._add(idx);
  19563. }
  19564. else {
  19565. for (var j = 0, len = idx.length; j < len; j++) {
  19566. this._add && this._add(idx[j]);
  19567. }
  19568. }
  19569. }
  19570. }
  19571. }
  19572. };
  19573. function initIndexMap(arr, map, keyArr, keyGetter) {
  19574. for (var i = 0; i < arr.length; i++) {
  19575. var key = keyGetter(arr[i], i);
  19576. var existence = map[key];
  19577. if (existence == null) {
  19578. keyArr.push(key);
  19579. map[key] = i;
  19580. }
  19581. else {
  19582. if (!existence.length) {
  19583. map[key] = existence = [existence];
  19584. }
  19585. existence.push(i);
  19586. }
  19587. }
  19588. }
  19589. module.exports = DataDiffer;
  19590. /***/ },
  19591. /* 100 */
  19592. /***/ function(module, exports, __webpack_require__) {
  19593. var zrUtil = __webpack_require__(4);
  19594. var echarts = __webpack_require__(1);
  19595. var PRIORITY = echarts.PRIORITY;
  19596. __webpack_require__(101);
  19597. __webpack_require__(104);
  19598. echarts.registerVisual(zrUtil.curry(
  19599. __webpack_require__(110), 'line', 'circle', 'line'
  19600. ));
  19601. echarts.registerLayout(zrUtil.curry(
  19602. __webpack_require__(111), 'line'
  19603. ));
  19604. // Down sample after filter
  19605. echarts.registerProcessor(PRIORITY.PROCESSOR.STATISTIC, zrUtil.curry(
  19606. __webpack_require__(112), 'line'
  19607. ));
  19608. // In case developer forget to include grid component
  19609. __webpack_require__(113);
  19610. /***/ },
  19611. /* 101 */
  19612. /***/ function(module, exports, __webpack_require__) {
  19613. 'use strict';
  19614. var createListFromArray = __webpack_require__(102);
  19615. var SeriesModel = __webpack_require__(28);
  19616. module.exports = SeriesModel.extend({
  19617. type: 'series.line',
  19618. dependencies: ['grid', 'polar'],
  19619. getInitialData: function (option, ecModel) {
  19620. if (true) {
  19621. var coordSys = option.coordinateSystem;
  19622. if (coordSys !== 'polar' && coordSys !== 'cartesian2d') {
  19623. throw new Error('Line not support coordinateSystem besides cartesian and polar');
  19624. }
  19625. }
  19626. return createListFromArray(option.data, this, ecModel);
  19627. },
  19628. defaultOption: {
  19629. zlevel: 0, // 一级层叠
  19630. z: 2, // 二级层叠
  19631. coordinateSystem: 'cartesian2d',
  19632. legendHoverLink: true,
  19633. hoverAnimation: true,
  19634. // stack: null
  19635. // xAxisIndex: 0,
  19636. // yAxisIndex: 0,
  19637. // polarIndex: 0,
  19638. // If clip the overflow value
  19639. clipOverflow: true,
  19640. label: {
  19641. normal: {
  19642. position: 'top'
  19643. }
  19644. },
  19645. // itemStyle: {
  19646. // normal: {},
  19647. // emphasis: {}
  19648. // },
  19649. lineStyle: {
  19650. normal: {
  19651. width: 2,
  19652. type: 'solid'
  19653. }
  19654. },
  19655. // areaStyle: {},
  19656. // false, 'start', 'end', 'middle'
  19657. step: false,
  19658. // Disabled if step is true
  19659. smooth: false,
  19660. smoothMonotone: null,
  19661. // 拐点图形类型
  19662. symbol: 'emptyCircle',
  19663. // 拐点图形大小
  19664. symbolSize: 4,
  19665. // 拐点图形旋转控制
  19666. symbolRotate: null,
  19667. // 是否显示 symbol, 只有在 tooltip hover 的时候显示
  19668. showSymbol: true,
  19669. // 标志图形默认只有主轴显示(随主轴标签间隔隐藏策略)
  19670. showAllSymbol: false,
  19671. // 是否连接断点
  19672. connectNulls: false,
  19673. // 数据过滤,'average', 'max', 'min', 'sum'
  19674. sampling: 'none',
  19675. animationEasing: 'linear',
  19676. // Disable progressive
  19677. progressive: 0,
  19678. hoverLayerThreshold: Infinity
  19679. }
  19680. });
  19681. /***/ },
  19682. /* 102 */
  19683. /***/ function(module, exports, __webpack_require__) {
  19684. 'use strict';
  19685. var List = __webpack_require__(98);
  19686. var completeDimensions = __webpack_require__(103);
  19687. var zrUtil = __webpack_require__(4);
  19688. var modelUtil = __webpack_require__(5);
  19689. var CoordinateSystem = __webpack_require__(26);
  19690. var getDataItemValue = modelUtil.getDataItemValue;
  19691. var converDataValue = modelUtil.converDataValue;
  19692. function firstDataNotNull(data) {
  19693. var i = 0;
  19694. while (i < data.length && data[i] == null) {
  19695. i++;
  19696. }
  19697. return data[i];
  19698. }
  19699. function ifNeedCompleteOrdinalData(data) {
  19700. var sampleItem = firstDataNotNull(data);
  19701. return sampleItem != null
  19702. && !zrUtil.isArray(getDataItemValue(sampleItem));
  19703. }
  19704. /**
  19705. * Helper function to create a list from option data
  19706. */
  19707. function createListFromArray(data, seriesModel, ecModel) {
  19708. // If data is undefined
  19709. data = data || [];
  19710. if (true) {
  19711. if (!zrUtil.isArray(data)) {
  19712. throw new Error('Invalid data.');
  19713. }
  19714. }
  19715. var coordSysName = seriesModel.get('coordinateSystem');
  19716. var creator = creators[coordSysName];
  19717. var registeredCoordSys = CoordinateSystem.get(coordSysName);
  19718. // FIXME
  19719. var axesInfo = creator && creator(data, seriesModel, ecModel);
  19720. var dimensions = axesInfo && axesInfo.dimensions;
  19721. if (!dimensions) {
  19722. // Get dimensions from registered coordinate system
  19723. dimensions = (registeredCoordSys && registeredCoordSys.dimensions) || ['x', 'y'];
  19724. dimensions = completeDimensions(dimensions, data, dimensions.concat(['value']));
  19725. }
  19726. var categoryIndex = axesInfo ? axesInfo.categoryIndex : -1;
  19727. var list = new List(dimensions, seriesModel);
  19728. var nameList = createNameList(axesInfo, data);
  19729. var categories = {};
  19730. var dimValueGetter = (categoryIndex >= 0 && ifNeedCompleteOrdinalData(data))
  19731. ? function (itemOpt, dimName, dataIndex, dimIndex) {
  19732. // If any dataItem is like { value: 10 }
  19733. if (modelUtil.isDataItemOption(itemOpt)) {
  19734. list.hasItemOption = true;
  19735. }
  19736. // Use dataIndex as ordinal value in categoryAxis
  19737. return dimIndex === categoryIndex
  19738. ? dataIndex
  19739. : converDataValue(getDataItemValue(itemOpt), dimensions[dimIndex]);
  19740. }
  19741. : function (itemOpt, dimName, dataIndex, dimIndex) {
  19742. var value = getDataItemValue(itemOpt);
  19743. var val = converDataValue(value && value[dimIndex], dimensions[dimIndex]);
  19744. // If any dataItem is like { value: 10 }
  19745. if (modelUtil.isDataItemOption(itemOpt)) {
  19746. list.hasItemOption = true;
  19747. }
  19748. var categoryAxesModels = axesInfo && axesInfo.categoryAxesModels;
  19749. if (categoryAxesModels && categoryAxesModels[dimName]) {
  19750. // If given value is a category string
  19751. if (typeof val === 'string') {
  19752. // Lazy get categories
  19753. categories[dimName] = categories[dimName]
  19754. || categoryAxesModels[dimName].getCategories();
  19755. val = zrUtil.indexOf(categories[dimName], val);
  19756. if (val < 0 && !isNaN(val)) {
  19757. // In case some one write '1', '2' istead of 1, 2
  19758. val = +val;
  19759. }
  19760. }
  19761. }
  19762. return val;
  19763. };
  19764. list.hasItemOption = false;
  19765. list.initData(data, nameList, dimValueGetter);
  19766. return list;
  19767. }
  19768. function isStackable(axisType) {
  19769. return axisType !== 'category' && axisType !== 'time';
  19770. }
  19771. function getDimTypeByAxis(axisType) {
  19772. return axisType === 'category'
  19773. ? 'ordinal'
  19774. : axisType === 'time'
  19775. ? 'time'
  19776. : 'float';
  19777. }
  19778. /**
  19779. * Creaters for each coord system.
  19780. */
  19781. var creators = {
  19782. cartesian2d: function (data, seriesModel, ecModel) {
  19783. var axesModels = zrUtil.map(['xAxis', 'yAxis'], function (name) {
  19784. return ecModel.queryComponents({
  19785. mainType: name,
  19786. index: seriesModel.get(name + 'Index'),
  19787. id: seriesModel.get(name + 'Id')
  19788. })[0];
  19789. });
  19790. var xAxisModel = axesModels[0];
  19791. var yAxisModel = axesModels[1];
  19792. if (true) {
  19793. if (!xAxisModel) {
  19794. throw new Error('xAxis "' + zrUtil.retrieve(
  19795. seriesModel.get('xAxisIndex'),
  19796. seriesModel.get('xAxisId'),
  19797. 0
  19798. ) + '" not found');
  19799. }
  19800. if (!yAxisModel) {
  19801. throw new Error('yAxis "' + zrUtil.retrieve(
  19802. seriesModel.get('xAxisIndex'),
  19803. seriesModel.get('yAxisId'),
  19804. 0
  19805. ) + '" not found');
  19806. }
  19807. }
  19808. var xAxisType = xAxisModel.get('type');
  19809. var yAxisType = yAxisModel.get('type');
  19810. var dimensions = [
  19811. {
  19812. name: 'x',
  19813. type: getDimTypeByAxis(xAxisType),
  19814. stackable: isStackable(xAxisType)
  19815. },
  19816. {
  19817. name: 'y',
  19818. // If two category axes
  19819. type: getDimTypeByAxis(yAxisType),
  19820. stackable: isStackable(yAxisType)
  19821. }
  19822. ];
  19823. var isXAxisCateogry = xAxisType === 'category';
  19824. var isYAxisCategory = yAxisType === 'category';
  19825. completeDimensions(dimensions, data, ['x', 'y', 'z']);
  19826. var categoryAxesModels = {};
  19827. if (isXAxisCateogry) {
  19828. categoryAxesModels.x = xAxisModel;
  19829. }
  19830. if (isYAxisCategory) {
  19831. categoryAxesModels.y = yAxisModel;
  19832. }
  19833. return {
  19834. dimensions: dimensions,
  19835. categoryIndex: isXAxisCateogry ? 0 : (isYAxisCategory ? 1 : -1),
  19836. categoryAxesModels: categoryAxesModels
  19837. };
  19838. },
  19839. singleAxis: function (data, seriesModel, ecModel) {
  19840. var singleAxisModel = ecModel.queryComponents({
  19841. mainType: 'singleAxis',
  19842. index: seriesModel.get('singleAxisIndex'),
  19843. id: seriesModel.get('singleAxisId')
  19844. })[0];
  19845. if (true) {
  19846. if (!singleAxisModel) {
  19847. throw new Error('singleAxis should be specified.');
  19848. }
  19849. }
  19850. var singleAxisType = singleAxisModel.get('type');
  19851. var isCategory = singleAxisType === 'category';
  19852. var dimensions = [{
  19853. name: 'single',
  19854. type: getDimTypeByAxis(singleAxisType),
  19855. stackable: isStackable(singleAxisType)
  19856. }];
  19857. completeDimensions(dimensions, data);
  19858. var categoryAxesModels = {};
  19859. if (isCategory) {
  19860. categoryAxesModels.single = singleAxisModel;
  19861. }
  19862. return {
  19863. dimensions: dimensions,
  19864. categoryIndex: isCategory ? 0 : -1,
  19865. categoryAxesModels: categoryAxesModels
  19866. };
  19867. },
  19868. polar: function (data, seriesModel, ecModel) {
  19869. var polarModel = ecModel.queryComponents({
  19870. mainType: 'polar',
  19871. index: seriesModel.get('polarIndex'),
  19872. id: seriesModel.get('polarId')
  19873. })[0];
  19874. var angleAxisModel = polarModel.findAxisModel('angleAxis');
  19875. var radiusAxisModel = polarModel.findAxisModel('radiusAxis');
  19876. if (true) {
  19877. if (!angleAxisModel) {
  19878. throw new Error('angleAxis option not found');
  19879. }
  19880. if (!radiusAxisModel) {
  19881. throw new Error('radiusAxis option not found');
  19882. }
  19883. }
  19884. var radiusAxisType = radiusAxisModel.get('type');
  19885. var angleAxisType = angleAxisModel.get('type');
  19886. var dimensions = [
  19887. {
  19888. name: 'radius',
  19889. type: getDimTypeByAxis(radiusAxisType),
  19890. stackable: isStackable(radiusAxisType)
  19891. },
  19892. {
  19893. name: 'angle',
  19894. type: getDimTypeByAxis(angleAxisType),
  19895. stackable: isStackable(angleAxisType)
  19896. }
  19897. ];
  19898. var isAngleAxisCateogry = angleAxisType === 'category';
  19899. var isRadiusAxisCateogry = radiusAxisType === 'category';
  19900. completeDimensions(dimensions, data, ['radius', 'angle', 'value']);
  19901. var categoryAxesModels = {};
  19902. if (isRadiusAxisCateogry) {
  19903. categoryAxesModels.radius = radiusAxisModel;
  19904. }
  19905. if (isAngleAxisCateogry) {
  19906. categoryAxesModels.angle = angleAxisModel;
  19907. }
  19908. return {
  19909. dimensions: dimensions,
  19910. categoryIndex: isAngleAxisCateogry ? 1 : (isRadiusAxisCateogry ? 0 : -1),
  19911. categoryAxesModels: categoryAxesModels
  19912. };
  19913. },
  19914. geo: function (data, seriesModel, ecModel) {
  19915. // TODO Region
  19916. // 多个散点图系列在同一个地区的时候
  19917. return {
  19918. dimensions: completeDimensions([
  19919. {name: 'lng'},
  19920. {name: 'lat'}
  19921. ], data, ['lng', 'lat', 'value'])
  19922. };
  19923. }
  19924. };
  19925. function createNameList(result, data) {
  19926. var nameList = [];
  19927. var categoryDim = result && result.dimensions[result.categoryIndex];
  19928. var categoryAxisModel;
  19929. if (categoryDim) {
  19930. categoryAxisModel = result.categoryAxesModels[categoryDim.name];
  19931. }
  19932. if (categoryAxisModel) {
  19933. // FIXME Two category axis
  19934. var categories = categoryAxisModel.getCategories();
  19935. if (categories) {
  19936. var dataLen = data.length;
  19937. // Ordered data is given explicitly like
  19938. // [[3, 0.2], [1, 0.3], [2, 0.15]]
  19939. // or given scatter data,
  19940. // pick the category
  19941. if (zrUtil.isArray(data[0]) && data[0].length > 1) {
  19942. nameList = [];
  19943. for (var i = 0; i < dataLen; i++) {
  19944. nameList[i] = categories[data[i][result.categoryIndex || 0]];
  19945. }
  19946. }
  19947. else {
  19948. nameList = categories.slice(0);
  19949. }
  19950. }
  19951. }
  19952. return nameList;
  19953. }
  19954. module.exports = createListFromArray;
  19955. /***/ },
  19956. /* 103 */
  19957. /***/ function(module, exports, __webpack_require__) {
  19958. /**
  19959. * Complete dimensions by data (guess dimension).
  19960. */
  19961. var zrUtil = __webpack_require__(4);
  19962. /**
  19963. * Complete the dimensions array guessed from the data structure.
  19964. * @param {Array.<string>} dimensions Necessary dimensions, like ['x', 'y']
  19965. * @param {Array} data Data list. [[1, 2, 3], [2, 3, 4]]
  19966. * @param {Array.<string>} [defaultNames] Default names to fill not necessary dimensions, like ['value']
  19967. * @param {string} [extraPrefix] Prefix of name when filling the left dimensions.
  19968. * @return {Array.<string>}
  19969. */
  19970. function completeDimensions(dimensions, data, defaultNames, extraPrefix) {
  19971. if (!data) {
  19972. return dimensions;
  19973. }
  19974. var value0 = retrieveValue(data[0]);
  19975. var dimSize = zrUtil.isArray(value0) && value0.length || 1;
  19976. defaultNames = defaultNames || [];
  19977. extraPrefix = extraPrefix || 'extra';
  19978. for (var i = 0; i < dimSize; i++) {
  19979. if (!dimensions[i]) {
  19980. var name = defaultNames[i] || (extraPrefix + (i - defaultNames.length));
  19981. dimensions[i] = guessOrdinal(data, i)
  19982. ? {type: 'ordinal', name: name}
  19983. : name;
  19984. }
  19985. }
  19986. return dimensions;
  19987. }
  19988. // The rule should not be complex, otherwise user might not
  19989. // be able to known where the data is wrong.
  19990. var guessOrdinal = completeDimensions.guessOrdinal = function (data, dimIndex) {
  19991. for (var i = 0, len = data.length; i < len; i++) {
  19992. var value = retrieveValue(data[i]);
  19993. if (!zrUtil.isArray(value)) {
  19994. return false;
  19995. }
  19996. var value = value[dimIndex];
  19997. if (value != null && isFinite(value)) {
  19998. return false;
  19999. }
  20000. else if (zrUtil.isString(value) && value !== '-') {
  20001. return true;
  20002. }
  20003. }
  20004. return false;
  20005. };
  20006. function retrieveValue(o) {
  20007. return zrUtil.isArray(o) ? o : zrUtil.isObject(o) ? o.value: o;
  20008. }
  20009. module.exports = completeDimensions;
  20010. /***/ },
  20011. /* 104 */
  20012. /***/ function(module, exports, __webpack_require__) {
  20013. 'use strict';
  20014. // FIXME step not support polar
  20015. var zrUtil = __webpack_require__(4);
  20016. var SymbolDraw = __webpack_require__(105);
  20017. var Symbol = __webpack_require__(106);
  20018. var lineAnimationDiff = __webpack_require__(108);
  20019. var graphic = __webpack_require__(43);
  20020. var modelUtil = __webpack_require__(5);
  20021. var polyHelper = __webpack_require__(109);
  20022. var ChartView = __webpack_require__(42);
  20023. function isPointsSame(points1, points2) {
  20024. if (points1.length !== points2.length) {
  20025. return;
  20026. }
  20027. for (var i = 0; i < points1.length; i++) {
  20028. var p1 = points1[i];
  20029. var p2 = points2[i];
  20030. if (p1[0] !== p2[0] || p1[1] !== p2[1]) {
  20031. return;
  20032. }
  20033. }
  20034. return true;
  20035. }
  20036. function getSmooth(smooth) {
  20037. return typeof (smooth) === 'number' ? smooth : (smooth ? 0.3 : 0);
  20038. }
  20039. function getAxisExtentWithGap(axis) {
  20040. var extent = axis.getGlobalExtent();
  20041. if (axis.onBand) {
  20042. // Remove extra 1px to avoid line miter in clipped edge
  20043. var halfBandWidth = axis.getBandWidth() / 2 - 1;
  20044. var dir = extent[1] > extent[0] ? 1 : -1;
  20045. extent[0] += dir * halfBandWidth;
  20046. extent[1] -= dir * halfBandWidth;
  20047. }
  20048. return extent;
  20049. }
  20050. function sign(val) {
  20051. return val >= 0 ? 1 : -1;
  20052. }
  20053. /**
  20054. * @param {module:echarts/coord/cartesian/Cartesian2D|module:echarts/coord/polar/Polar} coordSys
  20055. * @param {module:echarts/data/List} data
  20056. * @param {Array.<Array.<number>>} points
  20057. * @private
  20058. */
  20059. function getStackedOnPoints(coordSys, data) {
  20060. var baseAxis = coordSys.getBaseAxis();
  20061. var valueAxis = coordSys.getOtherAxis(baseAxis);
  20062. var valueStart = baseAxis.onZero
  20063. ? 0 : valueAxis.scale.getExtent()[0];
  20064. var valueDim = valueAxis.dim;
  20065. var baseDataOffset = valueDim === 'x' || valueDim === 'radius' ? 1 : 0;
  20066. return data.mapArray([valueDim], function (val, idx) {
  20067. var stackedOnSameSign;
  20068. var stackedOn = data.stackedOn;
  20069. // Find first stacked value with same sign
  20070. while (stackedOn &&
  20071. sign(stackedOn.get(valueDim, idx)) === sign(val)
  20072. ) {
  20073. stackedOnSameSign = stackedOn;
  20074. break;
  20075. }
  20076. var stackedData = [];
  20077. stackedData[baseDataOffset] = data.get(baseAxis.dim, idx);
  20078. stackedData[1 - baseDataOffset] = stackedOnSameSign
  20079. ? stackedOnSameSign.get(valueDim, idx, true) : valueStart;
  20080. return coordSys.dataToPoint(stackedData);
  20081. }, true);
  20082. }
  20083. function createGridClipShape(cartesian, hasAnimation, seriesModel) {
  20084. var xExtent = getAxisExtentWithGap(cartesian.getAxis('x'));
  20085. var yExtent = getAxisExtentWithGap(cartesian.getAxis('y'));
  20086. var isHorizontal = cartesian.getBaseAxis().isHorizontal();
  20087. var x = Math.min(xExtent[0], xExtent[1]);
  20088. var y = Math.min(yExtent[0], yExtent[1]);
  20089. var width = Math.max(xExtent[0], xExtent[1]) - x;
  20090. var height = Math.max(yExtent[0], yExtent[1]) - y;
  20091. var lineWidth = seriesModel.get('lineStyle.normal.width') || 2;
  20092. // Expand clip shape to avoid clipping when line value exceeds axis
  20093. var expandSize = seriesModel.get('clipOverflow') ? lineWidth / 2 : Math.max(width, height);
  20094. if (isHorizontal) {
  20095. y -= expandSize;
  20096. height += expandSize * 2;
  20097. }
  20098. else {
  20099. x -= expandSize;
  20100. width += expandSize * 2;
  20101. }
  20102. var clipPath = new graphic.Rect({
  20103. shape: {
  20104. x: x,
  20105. y: y,
  20106. width: width,
  20107. height: height
  20108. }
  20109. });
  20110. if (hasAnimation) {
  20111. clipPath.shape[isHorizontal ? 'width' : 'height'] = 0;
  20112. graphic.initProps(clipPath, {
  20113. shape: {
  20114. width: width,
  20115. height: height
  20116. }
  20117. }, seriesModel);
  20118. }
  20119. return clipPath;
  20120. }
  20121. function createPolarClipShape(polar, hasAnimation, seriesModel) {
  20122. var angleAxis = polar.getAngleAxis();
  20123. var radiusAxis = polar.getRadiusAxis();
  20124. var radiusExtent = radiusAxis.getExtent();
  20125. var angleExtent = angleAxis.getExtent();
  20126. var RADIAN = Math.PI / 180;
  20127. var clipPath = new graphic.Sector({
  20128. shape: {
  20129. cx: polar.cx,
  20130. cy: polar.cy,
  20131. r0: radiusExtent[0],
  20132. r: radiusExtent[1],
  20133. startAngle: -angleExtent[0] * RADIAN,
  20134. endAngle: -angleExtent[1] * RADIAN,
  20135. clockwise: angleAxis.inverse
  20136. }
  20137. });
  20138. if (hasAnimation) {
  20139. clipPath.shape.endAngle = -angleExtent[0] * RADIAN;
  20140. graphic.initProps(clipPath, {
  20141. shape: {
  20142. endAngle: -angleExtent[1] * RADIAN
  20143. }
  20144. }, seriesModel);
  20145. }
  20146. return clipPath;
  20147. }
  20148. function createClipShape(coordSys, hasAnimation, seriesModel) {
  20149. return coordSys.type === 'polar'
  20150. ? createPolarClipShape(coordSys, hasAnimation, seriesModel)
  20151. : createGridClipShape(coordSys, hasAnimation, seriesModel);
  20152. }
  20153. function turnPointsIntoStep(points, coordSys, stepTurnAt) {
  20154. var baseAxis = coordSys.getBaseAxis();
  20155. var baseIndex = baseAxis.dim === 'x' || baseAxis.dim === 'radius' ? 0 : 1;
  20156. var stepPoints = [];
  20157. for (var i = 0; i < points.length - 1; i++) {
  20158. var nextPt = points[i + 1];
  20159. var pt = points[i];
  20160. stepPoints.push(pt);
  20161. var stepPt = [];
  20162. switch (stepTurnAt) {
  20163. case 'end':
  20164. stepPt[baseIndex] = nextPt[baseIndex];
  20165. stepPt[1 - baseIndex] = pt[1 - baseIndex];
  20166. // default is start
  20167. stepPoints.push(stepPt);
  20168. break;
  20169. case 'middle':
  20170. // default is start
  20171. var middle = (pt[baseIndex] + nextPt[baseIndex]) / 2;
  20172. var stepPt2 = [];
  20173. stepPt[baseIndex] = stepPt2[baseIndex] = middle;
  20174. stepPt[1 - baseIndex] = pt[1 - baseIndex];
  20175. stepPt2[1 - baseIndex] = nextPt[1 - baseIndex];
  20176. stepPoints.push(stepPt);
  20177. stepPoints.push(stepPt2);
  20178. break;
  20179. default:
  20180. stepPt[baseIndex] = pt[baseIndex];
  20181. stepPt[1 - baseIndex] = nextPt[1 - baseIndex];
  20182. // default is start
  20183. stepPoints.push(stepPt);
  20184. }
  20185. }
  20186. // Last points
  20187. points[i] && stepPoints.push(points[i]);
  20188. return stepPoints;
  20189. }
  20190. function getVisualGradient(data, coordSys) {
  20191. var visualMetaList = data.getVisual('visualMeta');
  20192. if (!visualMetaList || !visualMetaList.length || !data.count()) {
  20193. // When data.count() is 0, gradient range can not be calculated.
  20194. return;
  20195. }
  20196. var visualMeta;
  20197. for (var i = visualMetaList.length - 1; i >= 0; i--) {
  20198. // Can only be x or y
  20199. if (visualMetaList[i].dimension < 2) {
  20200. visualMeta = visualMetaList[i];
  20201. break;
  20202. }
  20203. }
  20204. if (!visualMeta || coordSys.type !== 'cartesian2d') {
  20205. if (true) {
  20206. console.warn('Visual map on line style only support x or y dimension.');
  20207. }
  20208. return;
  20209. }
  20210. // If the area to be rendered is bigger than area defined by LinearGradient,
  20211. // the canvas spec prescribes that the color of the first stop and the last
  20212. // stop should be used. But if two stops are added at offset 0, in effect
  20213. // browsers use the color of the second stop to render area outside
  20214. // LinearGradient. So we can only infinitesimally extend area defined in
  20215. // LinearGradient to render `outerColors`.
  20216. var dimension = visualMeta.dimension;
  20217. var dimName = data.dimensions[dimension];
  20218. var axis = coordSys.getAxis(dimName);
  20219. // dataToCoor mapping may not be linear, but must be monotonic.
  20220. var colorStops = zrUtil.map(visualMeta.stops, function (stop) {
  20221. return {
  20222. coord: axis.toGlobalCoord(axis.dataToCoord(stop.value)),
  20223. color: stop.color
  20224. };
  20225. });
  20226. var stopLen = colorStops.length;
  20227. var outerColors = visualMeta.outerColors.slice();
  20228. if (stopLen && colorStops[0].coord > colorStops[stopLen - 1].coord) {
  20229. colorStops.reverse();
  20230. outerColors.reverse();
  20231. }
  20232. var tinyExtent = 10; // Arbitrary value: 10px
  20233. var minCoord = colorStops[0].coord - tinyExtent;
  20234. var maxCoord = colorStops[stopLen - 1].coord + tinyExtent;
  20235. var coordSpan = maxCoord - minCoord;
  20236. if (coordSpan < 1e-3) {
  20237. return 'transparent';
  20238. }
  20239. zrUtil.each(colorStops, function (stop) {
  20240. stop.offset = (stop.coord - minCoord) / coordSpan;
  20241. });
  20242. colorStops.push({
  20243. offset: stopLen ? colorStops[stopLen - 1].offset : 0.5,
  20244. color: outerColors[1] || 'transparent'
  20245. });
  20246. colorStops.unshift({ // notice colorStops.length have been changed.
  20247. offset: stopLen ? colorStops[0].offset : 0.5,
  20248. color: outerColors[0] || 'transparent'
  20249. });
  20250. // zrUtil.each(colorStops, function (colorStop) {
  20251. // // Make sure each offset has rounded px to avoid not sharp edge
  20252. // colorStop.offset = (Math.round(colorStop.offset * (end - start) + start) - start) / (end - start);
  20253. // });
  20254. var gradient = new graphic.LinearGradient(0, 0, 0, 0, colorStops, true);
  20255. gradient[dimName] = minCoord;
  20256. gradient[dimName + '2'] = maxCoord;
  20257. return gradient;
  20258. }
  20259. module.exports = ChartView.extend({
  20260. type: 'line',
  20261. init: function () {
  20262. var lineGroup = new graphic.Group();
  20263. var symbolDraw = new SymbolDraw();
  20264. this.group.add(symbolDraw.group);
  20265. this._symbolDraw = symbolDraw;
  20266. this._lineGroup = lineGroup;
  20267. },
  20268. render: function (seriesModel, ecModel, api) {
  20269. var coordSys = seriesModel.coordinateSystem;
  20270. var group = this.group;
  20271. var data = seriesModel.getData();
  20272. var lineStyleModel = seriesModel.getModel('lineStyle.normal');
  20273. var areaStyleModel = seriesModel.getModel('areaStyle.normal');
  20274. var points = data.mapArray(data.getItemLayout, true);
  20275. var isCoordSysPolar = coordSys.type === 'polar';
  20276. var prevCoordSys = this._coordSys;
  20277. var symbolDraw = this._symbolDraw;
  20278. var polyline = this._polyline;
  20279. var polygon = this._polygon;
  20280. var lineGroup = this._lineGroup;
  20281. var hasAnimation = seriesModel.get('animation');
  20282. var isAreaChart = !areaStyleModel.isEmpty();
  20283. var stackedOnPoints = getStackedOnPoints(coordSys, data);
  20284. var showSymbol = seriesModel.get('showSymbol');
  20285. var isSymbolIgnore = showSymbol && !isCoordSysPolar && !seriesModel.get('showAllSymbol')
  20286. && this._getSymbolIgnoreFunc(data, coordSys);
  20287. // Remove temporary symbols
  20288. var oldData = this._data;
  20289. oldData && oldData.eachItemGraphicEl(function (el, idx) {
  20290. if (el.__temp) {
  20291. group.remove(el);
  20292. oldData.setItemGraphicEl(idx, null);
  20293. }
  20294. });
  20295. // Remove previous created symbols if showSymbol changed to false
  20296. if (!showSymbol) {
  20297. symbolDraw.remove();
  20298. }
  20299. group.add(lineGroup);
  20300. // FIXME step not support polar
  20301. var step = !isCoordSysPolar && seriesModel.get('step');
  20302. // Initialization animation or coordinate system changed
  20303. if (
  20304. !(polyline && prevCoordSys.type === coordSys.type && step === this._step)
  20305. ) {
  20306. showSymbol && symbolDraw.updateData(data, isSymbolIgnore);
  20307. if (step) {
  20308. // TODO If stacked series is not step
  20309. points = turnPointsIntoStep(points, coordSys, step);
  20310. stackedOnPoints = turnPointsIntoStep(stackedOnPoints, coordSys, step);
  20311. }
  20312. polyline = this._newPolyline(points, coordSys, hasAnimation);
  20313. if (isAreaChart) {
  20314. polygon = this._newPolygon(
  20315. points, stackedOnPoints,
  20316. coordSys, hasAnimation
  20317. );
  20318. }
  20319. lineGroup.setClipPath(createClipShape(coordSys, true, seriesModel));
  20320. }
  20321. else {
  20322. if (isAreaChart && !polygon) {
  20323. // If areaStyle is added
  20324. polygon = this._newPolygon(
  20325. points, stackedOnPoints,
  20326. coordSys, hasAnimation
  20327. );
  20328. }
  20329. else if (polygon && !isAreaChart) {
  20330. // If areaStyle is removed
  20331. lineGroup.remove(polygon);
  20332. polygon = this._polygon = null;
  20333. }
  20334. // Update clipPath
  20335. lineGroup.setClipPath(createClipShape(coordSys, false, seriesModel));
  20336. // Always update, or it is wrong in the case turning on legend
  20337. // because points are not changed
  20338. showSymbol && symbolDraw.updateData(data, isSymbolIgnore);
  20339. // Stop symbol animation and sync with line points
  20340. // FIXME performance?
  20341. data.eachItemGraphicEl(function (el) {
  20342. el.stopAnimation(true);
  20343. });
  20344. // In the case data zoom triggerred refreshing frequently
  20345. // Data may not change if line has a category axis. So it should animate nothing
  20346. if (!isPointsSame(this._stackedOnPoints, stackedOnPoints)
  20347. || !isPointsSame(this._points, points)
  20348. ) {
  20349. if (hasAnimation) {
  20350. this._updateAnimation(
  20351. data, stackedOnPoints, coordSys, api, step
  20352. );
  20353. }
  20354. else {
  20355. // Not do it in update with animation
  20356. if (step) {
  20357. // TODO If stacked series is not step
  20358. points = turnPointsIntoStep(points, coordSys, step);
  20359. stackedOnPoints = turnPointsIntoStep(stackedOnPoints, coordSys, step);
  20360. }
  20361. polyline.setShape({
  20362. points: points
  20363. });
  20364. polygon && polygon.setShape({
  20365. points: points,
  20366. stackedOnPoints: stackedOnPoints
  20367. });
  20368. }
  20369. }
  20370. }
  20371. var visualColor = getVisualGradient(data, coordSys) || data.getVisual('color');
  20372. polyline.useStyle(zrUtil.defaults(
  20373. // Use color in lineStyle first
  20374. lineStyleModel.getLineStyle(),
  20375. {
  20376. fill: 'none',
  20377. stroke: visualColor,
  20378. lineJoin: 'bevel'
  20379. }
  20380. ));
  20381. var smooth = seriesModel.get('smooth');
  20382. smooth = getSmooth(seriesModel.get('smooth'));
  20383. polyline.setShape({
  20384. smooth: smooth,
  20385. smoothMonotone: seriesModel.get('smoothMonotone'),
  20386. connectNulls: seriesModel.get('connectNulls')
  20387. });
  20388. if (polygon) {
  20389. var stackedOn = data.stackedOn;
  20390. var stackedOnSmooth = 0;
  20391. polygon.useStyle(zrUtil.defaults(
  20392. areaStyleModel.getAreaStyle(),
  20393. {
  20394. fill: visualColor,
  20395. opacity: 0.7,
  20396. lineJoin: 'bevel'
  20397. }
  20398. ));
  20399. if (stackedOn) {
  20400. var stackedOnSeries = stackedOn.hostModel;
  20401. stackedOnSmooth = getSmooth(stackedOnSeries.get('smooth'));
  20402. }
  20403. polygon.setShape({
  20404. smooth: smooth,
  20405. stackedOnSmooth: stackedOnSmooth,
  20406. smoothMonotone: seriesModel.get('smoothMonotone'),
  20407. connectNulls: seriesModel.get('connectNulls')
  20408. });
  20409. }
  20410. this._data = data;
  20411. // Save the coordinate system for transition animation when data changed
  20412. this._coordSys = coordSys;
  20413. this._stackedOnPoints = stackedOnPoints;
  20414. this._points = points;
  20415. this._step = step;
  20416. },
  20417. dispose: function () {},
  20418. highlight: function (seriesModel, ecModel, api, payload) {
  20419. var data = seriesModel.getData();
  20420. var dataIndex = modelUtil.queryDataIndex(data, payload);
  20421. if (!(dataIndex instanceof Array) && dataIndex != null && dataIndex >= 0) {
  20422. var symbol = data.getItemGraphicEl(dataIndex);
  20423. if (!symbol) {
  20424. // Create a temporary symbol if it is not exists
  20425. var pt = data.getItemLayout(dataIndex);
  20426. if (!pt) {
  20427. // Null data
  20428. return;
  20429. }
  20430. symbol = new Symbol(data, dataIndex);
  20431. symbol.position = pt;
  20432. symbol.setZ(
  20433. seriesModel.get('zlevel'),
  20434. seriesModel.get('z')
  20435. );
  20436. symbol.ignore = isNaN(pt[0]) || isNaN(pt[1]);
  20437. symbol.__temp = true;
  20438. data.setItemGraphicEl(dataIndex, symbol);
  20439. // Stop scale animation
  20440. symbol.stopSymbolAnimation(true);
  20441. this.group.add(symbol);
  20442. }
  20443. symbol.highlight();
  20444. }
  20445. else {
  20446. // Highlight whole series
  20447. ChartView.prototype.highlight.call(
  20448. this, seriesModel, ecModel, api, payload
  20449. );
  20450. }
  20451. },
  20452. downplay: function (seriesModel, ecModel, api, payload) {
  20453. var data = seriesModel.getData();
  20454. var dataIndex = modelUtil.queryDataIndex(data, payload);
  20455. if (dataIndex != null && dataIndex >= 0) {
  20456. var symbol = data.getItemGraphicEl(dataIndex);
  20457. if (symbol) {
  20458. if (symbol.__temp) {
  20459. data.setItemGraphicEl(dataIndex, null);
  20460. this.group.remove(symbol);
  20461. }
  20462. else {
  20463. symbol.downplay();
  20464. }
  20465. }
  20466. }
  20467. else {
  20468. // Downplay whole series
  20469. ChartView.prototype.downplay.call(
  20470. this, seriesModel, ecModel, api, payload
  20471. );
  20472. }
  20473. },
  20474. /**
  20475. * @param {module:zrender/container/Group} group
  20476. * @param {Array.<Array.<number>>} points
  20477. * @private
  20478. */
  20479. _newPolyline: function (points) {
  20480. var polyline = this._polyline;
  20481. // Remove previous created polyline
  20482. if (polyline) {
  20483. this._lineGroup.remove(polyline);
  20484. }
  20485. polyline = new polyHelper.Polyline({
  20486. shape: {
  20487. points: points
  20488. },
  20489. silent: true,
  20490. z2: 10
  20491. });
  20492. this._lineGroup.add(polyline);
  20493. this._polyline = polyline;
  20494. return polyline;
  20495. },
  20496. /**
  20497. * @param {module:zrender/container/Group} group
  20498. * @param {Array.<Array.<number>>} stackedOnPoints
  20499. * @param {Array.<Array.<number>>} points
  20500. * @private
  20501. */
  20502. _newPolygon: function (points, stackedOnPoints) {
  20503. var polygon = this._polygon;
  20504. // Remove previous created polygon
  20505. if (polygon) {
  20506. this._lineGroup.remove(polygon);
  20507. }
  20508. polygon = new polyHelper.Polygon({
  20509. shape: {
  20510. points: points,
  20511. stackedOnPoints: stackedOnPoints
  20512. },
  20513. silent: true
  20514. });
  20515. this._lineGroup.add(polygon);
  20516. this._polygon = polygon;
  20517. return polygon;
  20518. },
  20519. /**
  20520. * @private
  20521. */
  20522. _getSymbolIgnoreFunc: function (data, coordSys) {
  20523. var categoryAxis = coordSys.getAxesByScale('ordinal')[0];
  20524. // `getLabelInterval` is provided by echarts/component/axis
  20525. if (categoryAxis && categoryAxis.isLabelIgnored) {
  20526. return zrUtil.bind(categoryAxis.isLabelIgnored, categoryAxis);
  20527. }
  20528. },
  20529. /**
  20530. * @private
  20531. */
  20532. // FIXME Two value axis
  20533. _updateAnimation: function (data, stackedOnPoints, coordSys, api, step) {
  20534. var polyline = this._polyline;
  20535. var polygon = this._polygon;
  20536. var seriesModel = data.hostModel;
  20537. var diff = lineAnimationDiff(
  20538. this._data, data,
  20539. this._stackedOnPoints, stackedOnPoints,
  20540. this._coordSys, coordSys
  20541. );
  20542. var current = diff.current;
  20543. var stackedOnCurrent = diff.stackedOnCurrent;
  20544. var next = diff.next;
  20545. var stackedOnNext = diff.stackedOnNext;
  20546. if (step) {
  20547. // TODO If stacked series is not step
  20548. current = turnPointsIntoStep(diff.current, coordSys, step);
  20549. stackedOnCurrent = turnPointsIntoStep(diff.stackedOnCurrent, coordSys, step);
  20550. next = turnPointsIntoStep(diff.next, coordSys, step);
  20551. stackedOnNext = turnPointsIntoStep(diff.stackedOnNext, coordSys, step);
  20552. }
  20553. // `diff.current` is subset of `current` (which should be ensured by
  20554. // turnPointsIntoStep), so points in `__points` can be updated when
  20555. // points in `current` are update during animation.
  20556. polyline.shape.__points = diff.current;
  20557. polyline.shape.points = current;
  20558. graphic.updateProps(polyline, {
  20559. shape: {
  20560. points: next
  20561. }
  20562. }, seriesModel);
  20563. if (polygon) {
  20564. polygon.setShape({
  20565. points: current,
  20566. stackedOnPoints: stackedOnCurrent
  20567. });
  20568. graphic.updateProps(polygon, {
  20569. shape: {
  20570. points: next,
  20571. stackedOnPoints: stackedOnNext
  20572. }
  20573. }, seriesModel);
  20574. }
  20575. var updatedDataInfo = [];
  20576. var diffStatus = diff.status;
  20577. for (var i = 0; i < diffStatus.length; i++) {
  20578. var cmd = diffStatus[i].cmd;
  20579. if (cmd === '=') {
  20580. var el = data.getItemGraphicEl(diffStatus[i].idx1);
  20581. if (el) {
  20582. updatedDataInfo.push({
  20583. el: el,
  20584. ptIdx: i // Index of points
  20585. });
  20586. }
  20587. }
  20588. }
  20589. if (polyline.animators && polyline.animators.length) {
  20590. polyline.animators[0].during(function () {
  20591. for (var i = 0; i < updatedDataInfo.length; i++) {
  20592. var el = updatedDataInfo[i].el;
  20593. el.attr('position', polyline.shape.__points[updatedDataInfo[i].ptIdx]);
  20594. }
  20595. });
  20596. }
  20597. },
  20598. remove: function (ecModel) {
  20599. var group = this.group;
  20600. var oldData = this._data;
  20601. this._lineGroup.removeAll();
  20602. this._symbolDraw.remove(true);
  20603. // Remove temporary created elements when highlighting
  20604. oldData && oldData.eachItemGraphicEl(function (el, idx) {
  20605. if (el.__temp) {
  20606. group.remove(el);
  20607. oldData.setItemGraphicEl(idx, null);
  20608. }
  20609. });
  20610. this._polyline =
  20611. this._polygon =
  20612. this._coordSys =
  20613. this._points =
  20614. this._stackedOnPoints =
  20615. this._data = null;
  20616. }
  20617. });
  20618. /***/ },
  20619. /* 105 */
  20620. /***/ function(module, exports, __webpack_require__) {
  20621. /**
  20622. * @module echarts/chart/helper/SymbolDraw
  20623. */
  20624. var graphic = __webpack_require__(43);
  20625. var Symbol = __webpack_require__(106);
  20626. /**
  20627. * @constructor
  20628. * @alias module:echarts/chart/helper/SymbolDraw
  20629. * @param {module:zrender/graphic/Group} [symbolCtor]
  20630. */
  20631. function SymbolDraw(symbolCtor) {
  20632. this.group = new graphic.Group();
  20633. this._symbolCtor = symbolCtor || Symbol;
  20634. }
  20635. var symbolDrawProto = SymbolDraw.prototype;
  20636. function symbolNeedsDraw(data, idx, isIgnore) {
  20637. var point = data.getItemLayout(idx);
  20638. // Is an object
  20639. // if (point && point.hasOwnProperty('point')) {
  20640. // point = point.point;
  20641. // }
  20642. return point && !isNaN(point[0]) && !isNaN(point[1]) && !(isIgnore && isIgnore(idx))
  20643. && data.getItemVisual(idx, 'symbol') !== 'none';
  20644. }
  20645. /**
  20646. * Update symbols draw by new data
  20647. * @param {module:echarts/data/List} data
  20648. * @param {Array.<boolean>} [isIgnore]
  20649. */
  20650. symbolDrawProto.updateData = function (data, isIgnore) {
  20651. var group = this.group;
  20652. var seriesModel = data.hostModel;
  20653. var oldData = this._data;
  20654. var SymbolCtor = this._symbolCtor;
  20655. var seriesScope = {
  20656. itemStyle: seriesModel.getModel('itemStyle.normal').getItemStyle(['color']),
  20657. hoverItemStyle: seriesModel.getModel('itemStyle.emphasis').getItemStyle(),
  20658. symbolRotate: seriesModel.get('symbolRotate'),
  20659. symbolOffset: seriesModel.get('symbolOffset'),
  20660. hoverAnimation: seriesModel.get('hoverAnimation'),
  20661. labelModel: seriesModel.getModel('label.normal'),
  20662. hoverLabelModel: seriesModel.getModel('label.emphasis')
  20663. };
  20664. data.diff(oldData)
  20665. .add(function (newIdx) {
  20666. var point = data.getItemLayout(newIdx);
  20667. if (symbolNeedsDraw(data, newIdx, isIgnore)) {
  20668. var symbolEl = new SymbolCtor(data, newIdx, seriesScope);
  20669. symbolEl.attr('position', point);
  20670. data.setItemGraphicEl(newIdx, symbolEl);
  20671. group.add(symbolEl);
  20672. }
  20673. })
  20674. .update(function (newIdx, oldIdx) {
  20675. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  20676. var point = data.getItemLayout(newIdx);
  20677. if (!symbolNeedsDraw(data, newIdx, isIgnore)) {
  20678. group.remove(symbolEl);
  20679. return;
  20680. }
  20681. if (!symbolEl) {
  20682. symbolEl = new SymbolCtor(data, newIdx);
  20683. symbolEl.attr('position', point);
  20684. }
  20685. else {
  20686. symbolEl.updateData(data, newIdx, seriesScope);
  20687. graphic.updateProps(symbolEl, {
  20688. position: point
  20689. }, seriesModel);
  20690. }
  20691. // Add back
  20692. group.add(symbolEl);
  20693. data.setItemGraphicEl(newIdx, symbolEl);
  20694. })
  20695. .remove(function (oldIdx) {
  20696. var el = oldData.getItemGraphicEl(oldIdx);
  20697. el && el.fadeOut(function () {
  20698. group.remove(el);
  20699. });
  20700. })
  20701. .execute();
  20702. this._data = data;
  20703. };
  20704. symbolDrawProto.updateLayout = function () {
  20705. var data = this._data;
  20706. if (data) {
  20707. // Not use animation
  20708. data.eachItemGraphicEl(function (el, idx) {
  20709. var point = data.getItemLayout(idx);
  20710. el.attr('position', point);
  20711. });
  20712. }
  20713. };
  20714. symbolDrawProto.remove = function (enableAnimation) {
  20715. var group = this.group;
  20716. var data = this._data;
  20717. if (data) {
  20718. if (enableAnimation) {
  20719. data.eachItemGraphicEl(function (el) {
  20720. el.fadeOut(function () {
  20721. group.remove(el);
  20722. });
  20723. });
  20724. }
  20725. else {
  20726. group.removeAll();
  20727. }
  20728. }
  20729. };
  20730. module.exports = SymbolDraw;
  20731. /***/ },
  20732. /* 106 */
  20733. /***/ function(module, exports, __webpack_require__) {
  20734. /**
  20735. * @module echarts/chart/helper/Symbol
  20736. */
  20737. var zrUtil = __webpack_require__(4);
  20738. var symbolUtil = __webpack_require__(107);
  20739. var graphic = __webpack_require__(43);
  20740. var numberUtil = __webpack_require__(7);
  20741. function getSymbolSize(data, idx) {
  20742. var symbolSize = data.getItemVisual(idx, 'symbolSize');
  20743. return symbolSize instanceof Array
  20744. ? symbolSize.slice()
  20745. : [+symbolSize, +symbolSize];
  20746. }
  20747. function getScale(symbolSize) {
  20748. return [symbolSize[0] / 2, symbolSize[1] / 2];
  20749. }
  20750. /**
  20751. * @constructor
  20752. * @alias {module:echarts/chart/helper/Symbol}
  20753. * @param {module:echarts/data/List} data
  20754. * @param {number} idx
  20755. * @extends {module:zrender/graphic/Group}
  20756. */
  20757. function Symbol(data, idx, seriesScope) {
  20758. graphic.Group.call(this);
  20759. this.updateData(data, idx, seriesScope);
  20760. }
  20761. var symbolProto = Symbol.prototype;
  20762. function driftSymbol(dx, dy) {
  20763. this.parent.drift(dx, dy);
  20764. }
  20765. symbolProto._createSymbol = function (symbolType, data, idx, symbolSize) {
  20766. // Remove paths created before
  20767. this.removeAll();
  20768. var seriesModel = data.hostModel;
  20769. var color = data.getItemVisual(idx, 'color');
  20770. // var symbolPath = symbolUtil.createSymbol(
  20771. // symbolType, -0.5, -0.5, 1, 1, color
  20772. // );
  20773. // If width/height are set too small (e.g., set to 1) on ios10
  20774. // and macOS Sierra, a circle stroke become a rect, no matter what
  20775. // the scale is set. So we set width/height as 2. See #4150.
  20776. var symbolPath = symbolUtil.createSymbol(
  20777. symbolType, -1, -1, 2, 2, color
  20778. );
  20779. symbolPath.attr({
  20780. z2: 100,
  20781. culling: true,
  20782. scale: [0, 0]
  20783. });
  20784. // Rewrite drift method
  20785. symbolPath.drift = driftSymbol;
  20786. graphic.initProps(symbolPath, {
  20787. scale: getScale(symbolSize)
  20788. }, seriesModel, idx);
  20789. this._symbolType = symbolType;
  20790. this.add(symbolPath);
  20791. };
  20792. /**
  20793. * Stop animation
  20794. * @param {boolean} toLastFrame
  20795. */
  20796. symbolProto.stopSymbolAnimation = function (toLastFrame) {
  20797. this.childAt(0).stopAnimation(toLastFrame);
  20798. };
  20799. /**
  20800. * Get symbol path element
  20801. */
  20802. symbolProto.getSymbolPath = function () {
  20803. return this.childAt(0);
  20804. };
  20805. /**
  20806. * Get scale(aka, current symbol size).
  20807. * Including the change caused by animation
  20808. */
  20809. symbolProto.getScale = function () {
  20810. return this.childAt(0).scale;
  20811. };
  20812. /**
  20813. * Highlight symbol
  20814. */
  20815. symbolProto.highlight = function () {
  20816. this.childAt(0).trigger('emphasis');
  20817. };
  20818. /**
  20819. * Downplay symbol
  20820. */
  20821. symbolProto.downplay = function () {
  20822. this.childAt(0).trigger('normal');
  20823. };
  20824. /**
  20825. * @param {number} zlevel
  20826. * @param {number} z
  20827. */
  20828. symbolProto.setZ = function (zlevel, z) {
  20829. var symbolPath = this.childAt(0);
  20830. symbolPath.zlevel = zlevel;
  20831. symbolPath.z = z;
  20832. };
  20833. symbolProto.setDraggable = function (draggable) {
  20834. var symbolPath = this.childAt(0);
  20835. symbolPath.draggable = draggable;
  20836. symbolPath.cursor = draggable ? 'move' : 'pointer';
  20837. };
  20838. /**
  20839. * Update symbol properties
  20840. * @param {module:echarts/data/List} data
  20841. * @param {number} idx
  20842. */
  20843. symbolProto.updateData = function (data, idx, seriesScope) {
  20844. this.silent = false;
  20845. var symbolType = data.getItemVisual(idx, 'symbol') || 'circle';
  20846. var seriesModel = data.hostModel;
  20847. var symbolSize = getSymbolSize(data, idx);
  20848. if (symbolType !== this._symbolType) {
  20849. this._createSymbol(symbolType, data, idx, symbolSize);
  20850. }
  20851. else {
  20852. var symbolPath = this.childAt(0);
  20853. graphic.updateProps(symbolPath, {
  20854. scale: getScale(symbolSize)
  20855. }, seriesModel, idx);
  20856. }
  20857. this._updateCommon(data, idx, symbolSize, seriesScope);
  20858. this._seriesModel = seriesModel;
  20859. };
  20860. // Update common properties
  20861. var normalStyleAccessPath = ['itemStyle', 'normal'];
  20862. var emphasisStyleAccessPath = ['itemStyle', 'emphasis'];
  20863. var normalLabelAccessPath = ['label', 'normal'];
  20864. var emphasisLabelAccessPath = ['label', 'emphasis'];
  20865. symbolProto._updateCommon = function (data, idx, symbolSize, seriesScope) {
  20866. var symbolPath = this.childAt(0);
  20867. var seriesModel = data.hostModel;
  20868. var color = data.getItemVisual(idx, 'color');
  20869. // Reset style
  20870. if (symbolPath.type !== 'image') {
  20871. symbolPath.useStyle({
  20872. strokeNoScale: true
  20873. });
  20874. }
  20875. seriesScope = seriesScope || null;
  20876. var itemStyle = seriesScope && seriesScope.itemStyle;
  20877. var hoverItemStyle = seriesScope && seriesScope.hoverItemStyle;
  20878. var symbolRotate = seriesScope && seriesScope.symbolRotate;
  20879. var symbolOffset = seriesScope && seriesScope.symbolOffset;
  20880. var labelModel = seriesScope && seriesScope.labelModel;
  20881. var hoverLabelModel = seriesScope && seriesScope.hoverLabelModel;
  20882. var hoverAnimation = seriesScope && seriesScope.hoverAnimation;
  20883. if (!seriesScope || data.hasItemOption) {
  20884. var itemModel = data.getItemModel(idx);
  20885. // Color must be excluded.
  20886. // Because symbol provide setColor individually to set fill and stroke
  20887. itemStyle = itemModel.getModel(normalStyleAccessPath).getItemStyle(['color']);
  20888. hoverItemStyle = itemModel.getModel(emphasisStyleAccessPath).getItemStyle();
  20889. symbolRotate = itemModel.getShallow('symbolRotate');
  20890. symbolOffset = itemModel.getShallow('symbolOffset');
  20891. labelModel = itemModel.getModel(normalLabelAccessPath);
  20892. hoverLabelModel = itemModel.getModel(emphasisLabelAccessPath);
  20893. hoverAnimation = itemModel.getShallow('hoverAnimation');
  20894. }
  20895. else {
  20896. hoverItemStyle = zrUtil.extend({}, hoverItemStyle);
  20897. }
  20898. var elStyle = symbolPath.style;
  20899. symbolPath.attr('rotation', (symbolRotate || 0) * Math.PI / 180 || 0);
  20900. if (symbolOffset) {
  20901. symbolPath.attr('position', [
  20902. numberUtil.parsePercent(symbolOffset[0], symbolSize[0]),
  20903. numberUtil.parsePercent(symbolOffset[1], symbolSize[1])
  20904. ]);
  20905. }
  20906. // PENDING setColor before setStyle!!!
  20907. symbolPath.setColor(color);
  20908. symbolPath.setStyle(itemStyle);
  20909. var opacity = data.getItemVisual(idx, 'opacity');
  20910. if (opacity != null) {
  20911. elStyle.opacity = opacity;
  20912. }
  20913. // Get last value dim
  20914. var dimensions = data.dimensions.slice();
  20915. var valueDim;
  20916. var dataType;
  20917. while (dimensions.length && (
  20918. valueDim = dimensions.pop(),
  20919. dataType = data.getDimensionInfo(valueDim).type,
  20920. dataType === 'ordinal' || dataType === 'time'
  20921. )) {} // jshint ignore:line
  20922. if (valueDim != null && labelModel.getShallow('show')) {
  20923. graphic.setText(elStyle, labelModel, color);
  20924. elStyle.text = zrUtil.retrieve(
  20925. seriesModel.getFormattedLabel(idx, 'normal'),
  20926. data.get(valueDim, idx)
  20927. );
  20928. }
  20929. else {
  20930. elStyle.text = '';
  20931. }
  20932. if (valueDim != null && hoverLabelModel.getShallow('show')) {
  20933. graphic.setText(hoverItemStyle, hoverLabelModel, color);
  20934. hoverItemStyle.text = zrUtil.retrieve(
  20935. seriesModel.getFormattedLabel(idx, 'emphasis'),
  20936. data.get(valueDim, idx)
  20937. );
  20938. }
  20939. else {
  20940. hoverItemStyle.text = '';
  20941. }
  20942. symbolPath.off('mouseover')
  20943. .off('mouseout')
  20944. .off('emphasis')
  20945. .off('normal');
  20946. symbolPath.hoverStyle = hoverItemStyle;
  20947. graphic.setHoverStyle(symbolPath);
  20948. var scale = getScale(symbolSize);
  20949. if (hoverAnimation && seriesModel.isAnimationEnabled()) {
  20950. var onEmphasis = function() {
  20951. var ratio = scale[1] / scale[0];
  20952. this.animateTo({
  20953. scale: [
  20954. Math.max(scale[0] * 1.1, scale[0] + 3),
  20955. Math.max(scale[1] * 1.1, scale[1] + 3 * ratio)
  20956. ]
  20957. }, 400, 'elasticOut');
  20958. };
  20959. var onNormal = function() {
  20960. this.animateTo({
  20961. scale: scale
  20962. }, 400, 'elasticOut');
  20963. };
  20964. symbolPath.on('mouseover', onEmphasis)
  20965. .on('mouseout', onNormal)
  20966. .on('emphasis', onEmphasis)
  20967. .on('normal', onNormal);
  20968. }
  20969. };
  20970. symbolProto.fadeOut = function (cb) {
  20971. var symbolPath = this.childAt(0);
  20972. // Avoid mistaken hover when fading out
  20973. this.silent = true;
  20974. // Not show text when animating
  20975. symbolPath.style.text = '';
  20976. graphic.updateProps(symbolPath, {
  20977. scale: [0, 0]
  20978. }, this._seriesModel, this.dataIndex, cb);
  20979. };
  20980. zrUtil.inherits(Symbol, graphic.Group);
  20981. module.exports = Symbol;
  20982. /***/ },
  20983. /* 107 */
  20984. /***/ function(module, exports, __webpack_require__) {
  20985. 'use strict';
  20986. // Symbol factory
  20987. var graphic = __webpack_require__(43);
  20988. var BoundingRect = __webpack_require__(9);
  20989. /**
  20990. * Triangle shape
  20991. * @inner
  20992. */
  20993. var Triangle = graphic.extendShape({
  20994. type: 'triangle',
  20995. shape: {
  20996. cx: 0,
  20997. cy: 0,
  20998. width: 0,
  20999. height: 0
  21000. },
  21001. buildPath: function (path, shape) {
  21002. var cx = shape.cx;
  21003. var cy = shape.cy;
  21004. var width = shape.width / 2;
  21005. var height = shape.height / 2;
  21006. path.moveTo(cx, cy - height);
  21007. path.lineTo(cx + width, cy + height);
  21008. path.lineTo(cx - width, cy + height);
  21009. path.closePath();
  21010. }
  21011. });
  21012. /**
  21013. * Diamond shape
  21014. * @inner
  21015. */
  21016. var Diamond = graphic.extendShape({
  21017. type: 'diamond',
  21018. shape: {
  21019. cx: 0,
  21020. cy: 0,
  21021. width: 0,
  21022. height: 0
  21023. },
  21024. buildPath: function (path, shape) {
  21025. var cx = shape.cx;
  21026. var cy = shape.cy;
  21027. var width = shape.width / 2;
  21028. var height = shape.height / 2;
  21029. path.moveTo(cx, cy - height);
  21030. path.lineTo(cx + width, cy);
  21031. path.lineTo(cx, cy + height);
  21032. path.lineTo(cx - width, cy);
  21033. path.closePath();
  21034. }
  21035. });
  21036. /**
  21037. * Pin shape
  21038. * @inner
  21039. */
  21040. var Pin = graphic.extendShape({
  21041. type: 'pin',
  21042. shape: {
  21043. // x, y on the cusp
  21044. x: 0,
  21045. y: 0,
  21046. width: 0,
  21047. height: 0
  21048. },
  21049. buildPath: function (path, shape) {
  21050. var x = shape.x;
  21051. var y = shape.y;
  21052. var w = shape.width / 5 * 3;
  21053. // Height must be larger than width
  21054. var h = Math.max(w, shape.height);
  21055. var r = w / 2;
  21056. // Dist on y with tangent point and circle center
  21057. var dy = r * r / (h - r);
  21058. var cy = y - h + r + dy;
  21059. var angle = Math.asin(dy / r);
  21060. // Dist on x with tangent point and circle center
  21061. var dx = Math.cos(angle) * r;
  21062. var tanX = Math.sin(angle);
  21063. var tanY = Math.cos(angle);
  21064. path.arc(
  21065. x, cy, r,
  21066. Math.PI - angle,
  21067. Math.PI * 2 + angle
  21068. );
  21069. var cpLen = r * 0.6;
  21070. var cpLen2 = r * 0.7;
  21071. path.bezierCurveTo(
  21072. x + dx - tanX * cpLen, cy + dy + tanY * cpLen,
  21073. x, y - cpLen2,
  21074. x, y
  21075. );
  21076. path.bezierCurveTo(
  21077. x, y - cpLen2,
  21078. x - dx + tanX * cpLen, cy + dy + tanY * cpLen,
  21079. x - dx, cy + dy
  21080. );
  21081. path.closePath();
  21082. }
  21083. });
  21084. /**
  21085. * Arrow shape
  21086. * @inner
  21087. */
  21088. var Arrow = graphic.extendShape({
  21089. type: 'arrow',
  21090. shape: {
  21091. x: 0,
  21092. y: 0,
  21093. width: 0,
  21094. height: 0
  21095. },
  21096. buildPath: function (ctx, shape) {
  21097. var height = shape.height;
  21098. var width = shape.width;
  21099. var x = shape.x;
  21100. var y = shape.y;
  21101. var dx = width / 3 * 2;
  21102. ctx.moveTo(x, y);
  21103. ctx.lineTo(x + dx, y + height);
  21104. ctx.lineTo(x, y + height / 4 * 3);
  21105. ctx.lineTo(x - dx, y + height);
  21106. ctx.lineTo(x, y);
  21107. ctx.closePath();
  21108. }
  21109. });
  21110. /**
  21111. * Map of path contructors
  21112. * @type {Object.<string, module:zrender/graphic/Path>}
  21113. */
  21114. var symbolCtors = {
  21115. line: graphic.Line,
  21116. rect: graphic.Rect,
  21117. roundRect: graphic.Rect,
  21118. square: graphic.Rect,
  21119. circle: graphic.Circle,
  21120. diamond: Diamond,
  21121. pin: Pin,
  21122. arrow: Arrow,
  21123. triangle: Triangle
  21124. };
  21125. var symbolShapeMakers = {
  21126. line: function (x, y, w, h, shape) {
  21127. // FIXME
  21128. shape.x1 = x;
  21129. shape.y1 = y + h / 2;
  21130. shape.x2 = x + w;
  21131. shape.y2 = y + h / 2;
  21132. },
  21133. rect: function (x, y, w, h, shape) {
  21134. shape.x = x;
  21135. shape.y = y;
  21136. shape.width = w;
  21137. shape.height = h;
  21138. },
  21139. roundRect: function (x, y, w, h, shape) {
  21140. shape.x = x;
  21141. shape.y = y;
  21142. shape.width = w;
  21143. shape.height = h;
  21144. shape.r = Math.min(w, h) / 4;
  21145. },
  21146. square: function (x, y, w, h, shape) {
  21147. var size = Math.min(w, h);
  21148. shape.x = x;
  21149. shape.y = y;
  21150. shape.width = size;
  21151. shape.height = size;
  21152. },
  21153. circle: function (x, y, w, h, shape) {
  21154. // Put circle in the center of square
  21155. shape.cx = x + w / 2;
  21156. shape.cy = y + h / 2;
  21157. shape.r = Math.min(w, h) / 2;
  21158. },
  21159. diamond: function (x, y, w, h, shape) {
  21160. shape.cx = x + w / 2;
  21161. shape.cy = y + h / 2;
  21162. shape.width = w;
  21163. shape.height = h;
  21164. },
  21165. pin: function (x, y, w, h, shape) {
  21166. shape.x = x + w / 2;
  21167. shape.y = y + h / 2;
  21168. shape.width = w;
  21169. shape.height = h;
  21170. },
  21171. arrow: function (x, y, w, h, shape) {
  21172. shape.x = x + w / 2;
  21173. shape.y = y + h / 2;
  21174. shape.width = w;
  21175. shape.height = h;
  21176. },
  21177. triangle: function (x, y, w, h, shape) {
  21178. shape.cx = x + w / 2;
  21179. shape.cy = y + h / 2;
  21180. shape.width = w;
  21181. shape.height = h;
  21182. }
  21183. };
  21184. var symbolBuildProxies = {};
  21185. for (var name in symbolCtors) {
  21186. if (symbolCtors.hasOwnProperty(name)) {
  21187. symbolBuildProxies[name] = new symbolCtors[name]();
  21188. }
  21189. }
  21190. var Symbol = graphic.extendShape({
  21191. type: 'symbol',
  21192. shape: {
  21193. symbolType: '',
  21194. x: 0,
  21195. y: 0,
  21196. width: 0,
  21197. height: 0
  21198. },
  21199. beforeBrush: function () {
  21200. var style = this.style;
  21201. var shape = this.shape;
  21202. // FIXME
  21203. if (shape.symbolType === 'pin' && style.textPosition === 'inside') {
  21204. style.textPosition = ['50%', '40%'];
  21205. style.textAlign = 'center';
  21206. style.textVerticalAlign = 'middle';
  21207. }
  21208. },
  21209. buildPath: function (ctx, shape, inBundle) {
  21210. var symbolType = shape.symbolType;
  21211. var proxySymbol = symbolBuildProxies[symbolType];
  21212. if (shape.symbolType !== 'none') {
  21213. if (!proxySymbol) {
  21214. // Default rect
  21215. symbolType = 'rect';
  21216. proxySymbol = symbolBuildProxies[symbolType];
  21217. }
  21218. symbolShapeMakers[symbolType](
  21219. shape.x, shape.y, shape.width, shape.height, proxySymbol.shape
  21220. );
  21221. proxySymbol.buildPath(ctx, proxySymbol.shape, inBundle);
  21222. }
  21223. }
  21224. });
  21225. // Provide setColor helper method to avoid determine if set the fill or stroke outside
  21226. var symbolPathSetColor = function (color) {
  21227. if (this.type !== 'image') {
  21228. var symbolStyle = this.style;
  21229. var symbolShape = this.shape;
  21230. if (symbolShape && symbolShape.symbolType === 'line') {
  21231. symbolStyle.stroke = color;
  21232. }
  21233. else if (this.__isEmptyBrush) {
  21234. symbolStyle.stroke = color;
  21235. symbolStyle.fill = '#fff';
  21236. }
  21237. else {
  21238. // FIXME 判断图形默认是填充还是描边,使用 onlyStroke ?
  21239. symbolStyle.fill && (symbolStyle.fill = color);
  21240. symbolStyle.stroke && (symbolStyle.stroke = color);
  21241. }
  21242. this.dirty(false);
  21243. }
  21244. };
  21245. var symbolUtil = {
  21246. /**
  21247. * Create a symbol element with given symbol configuration: shape, x, y, width, height, color
  21248. * @param {string} symbolType
  21249. * @param {number} x
  21250. * @param {number} y
  21251. * @param {number} w
  21252. * @param {number} h
  21253. * @param {string} color
  21254. */
  21255. createSymbol: function (symbolType, x, y, w, h, color) {
  21256. var isEmpty = symbolType.indexOf('empty') === 0;
  21257. if (isEmpty) {
  21258. symbolType = symbolType.substr(5, 1).toLowerCase() + symbolType.substr(6);
  21259. }
  21260. var symbolPath;
  21261. if (symbolType.indexOf('image://') === 0) {
  21262. symbolPath = new graphic.Image({
  21263. style: {
  21264. image: symbolType.slice(8),
  21265. x: x,
  21266. y: y,
  21267. width: w,
  21268. height: h
  21269. }
  21270. });
  21271. }
  21272. else if (symbolType.indexOf('path://') === 0) {
  21273. symbolPath = graphic.makePath(symbolType.slice(7), {}, new BoundingRect(x, y, w, h));
  21274. }
  21275. else {
  21276. symbolPath = new Symbol({
  21277. shape: {
  21278. symbolType: symbolType,
  21279. x: x,
  21280. y: y,
  21281. width: w,
  21282. height: h
  21283. }
  21284. });
  21285. }
  21286. symbolPath.__isEmptyBrush = isEmpty;
  21287. symbolPath.setColor = symbolPathSetColor;
  21288. symbolPath.setColor(color);
  21289. return symbolPath;
  21290. }
  21291. };
  21292. module.exports = symbolUtil;
  21293. /***/ },
  21294. /* 108 */
  21295. /***/ function(module, exports) {
  21296. // var arrayDiff = require('zrender/lib/core/arrayDiff');
  21297. // 'zrender/core/arrayDiff' has been used before, but it did
  21298. // not do well in performance when roam with fixed dataZoom window.
  21299. function sign(val) {
  21300. return val >= 0 ? 1 : -1;
  21301. }
  21302. function getStackedOnPoint(coordSys, data, idx) {
  21303. var baseAxis = coordSys.getBaseAxis();
  21304. var valueAxis = coordSys.getOtherAxis(baseAxis);
  21305. var valueStart = baseAxis.onZero
  21306. ? 0 : valueAxis.scale.getExtent()[0];
  21307. var valueDim = valueAxis.dim;
  21308. var baseDataOffset = valueDim === 'x' || valueDim === 'radius' ? 1 : 0;
  21309. var stackedOnSameSign;
  21310. var stackedOn = data.stackedOn;
  21311. var val = data.get(valueDim, idx);
  21312. // Find first stacked value with same sign
  21313. while (stackedOn &&
  21314. sign(stackedOn.get(valueDim, idx)) === sign(val)
  21315. ) {
  21316. stackedOnSameSign = stackedOn;
  21317. break;
  21318. }
  21319. var stackedData = [];
  21320. stackedData[baseDataOffset] = data.get(baseAxis.dim, idx);
  21321. stackedData[1 - baseDataOffset] = stackedOnSameSign
  21322. ? stackedOnSameSign.get(valueDim, idx, true) : valueStart;
  21323. return coordSys.dataToPoint(stackedData);
  21324. }
  21325. // function convertToIntId(newIdList, oldIdList) {
  21326. // // Generate int id instead of string id.
  21327. // // Compare string maybe slow in score function of arrDiff
  21328. // // Assume id in idList are all unique
  21329. // var idIndicesMap = {};
  21330. // var idx = 0;
  21331. // for (var i = 0; i < newIdList.length; i++) {
  21332. // idIndicesMap[newIdList[i]] = idx;
  21333. // newIdList[i] = idx++;
  21334. // }
  21335. // for (var i = 0; i < oldIdList.length; i++) {
  21336. // var oldId = oldIdList[i];
  21337. // // Same with newIdList
  21338. // if (idIndicesMap[oldId]) {
  21339. // oldIdList[i] = idIndicesMap[oldId];
  21340. // }
  21341. // else {
  21342. // oldIdList[i] = idx++;
  21343. // }
  21344. // }
  21345. // }
  21346. function diffData(oldData, newData) {
  21347. var diffResult = [];
  21348. newData.diff(oldData)
  21349. .add(function (idx) {
  21350. diffResult.push({cmd: '+', idx: idx});
  21351. })
  21352. .update(function (newIdx, oldIdx) {
  21353. diffResult.push({cmd: '=', idx: oldIdx, idx1: newIdx});
  21354. })
  21355. .remove(function (idx) {
  21356. diffResult.push({cmd: '-', idx: idx});
  21357. })
  21358. .execute();
  21359. return diffResult;
  21360. }
  21361. module.exports = function (
  21362. oldData, newData,
  21363. oldStackedOnPoints, newStackedOnPoints,
  21364. oldCoordSys, newCoordSys
  21365. ) {
  21366. var diff = diffData(oldData, newData);
  21367. // var newIdList = newData.mapArray(newData.getId);
  21368. // var oldIdList = oldData.mapArray(oldData.getId);
  21369. // convertToIntId(newIdList, oldIdList);
  21370. // // FIXME One data ?
  21371. // diff = arrayDiff(oldIdList, newIdList);
  21372. var currPoints = [];
  21373. var nextPoints = [];
  21374. // Points for stacking base line
  21375. var currStackedPoints = [];
  21376. var nextStackedPoints = [];
  21377. var status = [];
  21378. var sortedIndices = [];
  21379. var rawIndices = [];
  21380. var dims = newCoordSys.dimensions;
  21381. for (var i = 0; i < diff.length; i++) {
  21382. var diffItem = diff[i];
  21383. var pointAdded = true;
  21384. // FIXME, animation is not so perfect when dataZoom window moves fast
  21385. // Which is in case remvoing or add more than one data in the tail or head
  21386. switch (diffItem.cmd) {
  21387. case '=':
  21388. var currentPt = oldData.getItemLayout(diffItem.idx);
  21389. var nextPt = newData.getItemLayout(diffItem.idx1);
  21390. // If previous data is NaN, use next point directly
  21391. if (isNaN(currentPt[0]) || isNaN(currentPt[1])) {
  21392. currentPt = nextPt.slice();
  21393. }
  21394. currPoints.push(currentPt);
  21395. nextPoints.push(nextPt);
  21396. currStackedPoints.push(oldStackedOnPoints[diffItem.idx]);
  21397. nextStackedPoints.push(newStackedOnPoints[diffItem.idx1]);
  21398. rawIndices.push(newData.getRawIndex(diffItem.idx1));
  21399. break;
  21400. case '+':
  21401. var idx = diffItem.idx;
  21402. currPoints.push(
  21403. oldCoordSys.dataToPoint([
  21404. newData.get(dims[0], idx, true), newData.get(dims[1], idx, true)
  21405. ])
  21406. );
  21407. nextPoints.push(newData.getItemLayout(idx).slice());
  21408. currStackedPoints.push(
  21409. getStackedOnPoint(oldCoordSys, newData, idx)
  21410. );
  21411. nextStackedPoints.push(newStackedOnPoints[idx]);
  21412. rawIndices.push(newData.getRawIndex(idx));
  21413. break;
  21414. case '-':
  21415. var idx = diffItem.idx;
  21416. var rawIndex = oldData.getRawIndex(idx);
  21417. // Data is replaced. In the case of dynamic data queue
  21418. // FIXME FIXME FIXME
  21419. if (rawIndex !== idx) {
  21420. currPoints.push(oldData.getItemLayout(idx));
  21421. nextPoints.push(newCoordSys.dataToPoint([
  21422. oldData.get(dims[0], idx, true), oldData.get(dims[1], idx, true)
  21423. ]));
  21424. currStackedPoints.push(oldStackedOnPoints[idx]);
  21425. nextStackedPoints.push(
  21426. getStackedOnPoint(
  21427. newCoordSys, oldData, idx
  21428. )
  21429. );
  21430. rawIndices.push(rawIndex);
  21431. }
  21432. else {
  21433. pointAdded = false;
  21434. }
  21435. }
  21436. // Original indices
  21437. if (pointAdded) {
  21438. status.push(diffItem);
  21439. sortedIndices.push(sortedIndices.length);
  21440. }
  21441. }
  21442. // Diff result may be crossed if all items are changed
  21443. // Sort by data index
  21444. sortedIndices.sort(function (a, b) {
  21445. return rawIndices[a] - rawIndices[b];
  21446. });
  21447. var sortedCurrPoints = [];
  21448. var sortedNextPoints = [];
  21449. var sortedCurrStackedPoints = [];
  21450. var sortedNextStackedPoints = [];
  21451. var sortedStatus = [];
  21452. for (var i = 0; i < sortedIndices.length; i++) {
  21453. var idx = sortedIndices[i];
  21454. sortedCurrPoints[i] = currPoints[idx];
  21455. sortedNextPoints[i] = nextPoints[idx];
  21456. sortedCurrStackedPoints[i] = currStackedPoints[idx];
  21457. sortedNextStackedPoints[i] = nextStackedPoints[idx];
  21458. sortedStatus[i] = status[idx];
  21459. }
  21460. return {
  21461. current: sortedCurrPoints,
  21462. next: sortedNextPoints,
  21463. stackedOnCurrent: sortedCurrStackedPoints,
  21464. stackedOnNext: sortedNextStackedPoints,
  21465. status: sortedStatus
  21466. };
  21467. };
  21468. /***/ },
  21469. /* 109 */
  21470. /***/ function(module, exports, __webpack_require__) {
  21471. // Poly path support NaN point
  21472. var Path = __webpack_require__(45);
  21473. var vec2 = __webpack_require__(10);
  21474. var vec2Min = vec2.min;
  21475. var vec2Max = vec2.max;
  21476. var scaleAndAdd = vec2.scaleAndAdd;
  21477. var v2Copy = vec2.copy;
  21478. // Temporary variable
  21479. var v = [];
  21480. var cp0 = [];
  21481. var cp1 = [];
  21482. function isPointNull(p) {
  21483. return isNaN(p[0]) || isNaN(p[1]);
  21484. }
  21485. function drawSegment(
  21486. ctx, points, start, segLen, allLen,
  21487. dir, smoothMin, smoothMax, smooth, smoothMonotone, connectNulls
  21488. ) {
  21489. var prevIdx = 0;
  21490. var idx = start;
  21491. for (var k = 0; k < segLen; k++) {
  21492. var p = points[idx];
  21493. if (idx >= allLen || idx < 0) {
  21494. break;
  21495. }
  21496. if (isPointNull(p)) {
  21497. if (connectNulls) {
  21498. idx += dir;
  21499. continue;
  21500. }
  21501. break;
  21502. }
  21503. if (idx === start) {
  21504. ctx[dir > 0 ? 'moveTo' : 'lineTo'](p[0], p[1]);
  21505. v2Copy(cp0, p);
  21506. }
  21507. else {
  21508. if (smooth > 0) {
  21509. var nextIdx = idx + dir;
  21510. var nextP = points[nextIdx];
  21511. if (connectNulls) {
  21512. // Find next point not null
  21513. while (nextP && isPointNull(points[nextIdx])) {
  21514. nextIdx += dir;
  21515. nextP = points[nextIdx];
  21516. }
  21517. }
  21518. var ratioNextSeg = 0.5;
  21519. var prevP = points[prevIdx];
  21520. var nextP = points[nextIdx];
  21521. // Last point
  21522. if (!nextP || isPointNull(nextP)) {
  21523. v2Copy(cp1, p);
  21524. }
  21525. else {
  21526. // If next data is null in not connect case
  21527. if (isPointNull(nextP) && !connectNulls) {
  21528. nextP = p;
  21529. }
  21530. vec2.sub(v, nextP, prevP);
  21531. var lenPrevSeg;
  21532. var lenNextSeg;
  21533. if (smoothMonotone === 'x' || smoothMonotone === 'y') {
  21534. var dim = smoothMonotone === 'x' ? 0 : 1;
  21535. lenPrevSeg = Math.abs(p[dim] - prevP[dim]);
  21536. lenNextSeg = Math.abs(p[dim] - nextP[dim]);
  21537. }
  21538. else {
  21539. lenPrevSeg = vec2.dist(p, prevP);
  21540. lenNextSeg = vec2.dist(p, nextP);
  21541. }
  21542. // Use ratio of seg length
  21543. ratioNextSeg = lenNextSeg / (lenNextSeg + lenPrevSeg);
  21544. scaleAndAdd(cp1, p, v, -smooth * (1 - ratioNextSeg));
  21545. }
  21546. // Smooth constraint
  21547. vec2Min(cp0, cp0, smoothMax);
  21548. vec2Max(cp0, cp0, smoothMin);
  21549. vec2Min(cp1, cp1, smoothMax);
  21550. vec2Max(cp1, cp1, smoothMin);
  21551. ctx.bezierCurveTo(
  21552. cp0[0], cp0[1],
  21553. cp1[0], cp1[1],
  21554. p[0], p[1]
  21555. );
  21556. // cp0 of next segment
  21557. scaleAndAdd(cp0, p, v, smooth * ratioNextSeg);
  21558. }
  21559. else {
  21560. ctx.lineTo(p[0], p[1]);
  21561. }
  21562. }
  21563. prevIdx = idx;
  21564. idx += dir;
  21565. }
  21566. return k;
  21567. }
  21568. function getBoundingBox(points, smoothConstraint) {
  21569. var ptMin = [Infinity, Infinity];
  21570. var ptMax = [-Infinity, -Infinity];
  21571. if (smoothConstraint) {
  21572. for (var i = 0; i < points.length; i++) {
  21573. var pt = points[i];
  21574. if (pt[0] < ptMin[0]) { ptMin[0] = pt[0]; }
  21575. if (pt[1] < ptMin[1]) { ptMin[1] = pt[1]; }
  21576. if (pt[0] > ptMax[0]) { ptMax[0] = pt[0]; }
  21577. if (pt[1] > ptMax[1]) { ptMax[1] = pt[1]; }
  21578. }
  21579. }
  21580. return {
  21581. min: smoothConstraint ? ptMin : ptMax,
  21582. max: smoothConstraint ? ptMax : ptMin
  21583. };
  21584. }
  21585. module.exports = {
  21586. Polyline: Path.extend({
  21587. type: 'ec-polyline',
  21588. shape: {
  21589. points: [],
  21590. smooth: 0,
  21591. smoothConstraint: true,
  21592. smoothMonotone: null,
  21593. connectNulls: false
  21594. },
  21595. style: {
  21596. fill: null,
  21597. stroke: '#000'
  21598. },
  21599. buildPath: function (ctx, shape) {
  21600. var points = shape.points;
  21601. var i = 0;
  21602. var len = points.length;
  21603. var result = getBoundingBox(points, shape.smoothConstraint);
  21604. if (shape.connectNulls) {
  21605. // Must remove first and last null values avoid draw error in polygon
  21606. for (; len > 0; len--) {
  21607. if (!isPointNull(points[len - 1])) {
  21608. break;
  21609. }
  21610. }
  21611. for (; i < len; i++) {
  21612. if (!isPointNull(points[i])) {
  21613. break;
  21614. }
  21615. }
  21616. }
  21617. while (i < len) {
  21618. i += drawSegment(
  21619. ctx, points, i, len, len,
  21620. 1, result.min, result.max, shape.smooth,
  21621. shape.smoothMonotone, shape.connectNulls
  21622. ) + 1;
  21623. }
  21624. }
  21625. }),
  21626. Polygon: Path.extend({
  21627. type: 'ec-polygon',
  21628. shape: {
  21629. points: [],
  21630. // Offset between stacked base points and points
  21631. stackedOnPoints: [],
  21632. smooth: 0,
  21633. stackedOnSmooth: 0,
  21634. smoothConstraint: true,
  21635. smoothMonotone: null,
  21636. connectNulls: false
  21637. },
  21638. buildPath: function (ctx, shape) {
  21639. var points = shape.points;
  21640. var stackedOnPoints = shape.stackedOnPoints;
  21641. var i = 0;
  21642. var len = points.length;
  21643. var smoothMonotone = shape.smoothMonotone;
  21644. var bbox = getBoundingBox(points, shape.smoothConstraint);
  21645. var stackedOnBBox = getBoundingBox(stackedOnPoints, shape.smoothConstraint);
  21646. if (shape.connectNulls) {
  21647. // Must remove first and last null values avoid draw error in polygon
  21648. for (; len > 0; len--) {
  21649. if (!isPointNull(points[len - 1])) {
  21650. break;
  21651. }
  21652. }
  21653. for (; i < len; i++) {
  21654. if (!isPointNull(points[i])) {
  21655. break;
  21656. }
  21657. }
  21658. }
  21659. while (i < len) {
  21660. var k = drawSegment(
  21661. ctx, points, i, len, len,
  21662. 1, bbox.min, bbox.max, shape.smooth,
  21663. smoothMonotone, shape.connectNulls
  21664. );
  21665. drawSegment(
  21666. ctx, stackedOnPoints, i + k - 1, k, len,
  21667. -1, stackedOnBBox.min, stackedOnBBox.max, shape.stackedOnSmooth,
  21668. smoothMonotone, shape.connectNulls
  21669. );
  21670. i += k + 1;
  21671. ctx.closePath();
  21672. }
  21673. }
  21674. })
  21675. };
  21676. /***/ },
  21677. /* 110 */
  21678. /***/ function(module, exports) {
  21679. module.exports = function (seriesType, defaultSymbolType, legendSymbol, ecModel, api) {
  21680. // Encoding visual for all series include which is filtered for legend drawing
  21681. ecModel.eachRawSeriesByType(seriesType, function (seriesModel) {
  21682. var data = seriesModel.getData();
  21683. var symbolType = seriesModel.get('symbol') || defaultSymbolType;
  21684. var symbolSize = seriesModel.get('symbolSize');
  21685. data.setVisual({
  21686. legendSymbol: legendSymbol || symbolType,
  21687. symbol: symbolType,
  21688. symbolSize: symbolSize
  21689. });
  21690. // Only visible series has each data be visual encoded
  21691. if (!ecModel.isSeriesFiltered(seriesModel)) {
  21692. if (typeof symbolSize === 'function') {
  21693. data.each(function (idx) {
  21694. var rawValue = seriesModel.getRawValue(idx);
  21695. // FIXME
  21696. var params = seriesModel.getDataParams(idx);
  21697. data.setItemVisual(idx, 'symbolSize', symbolSize(rawValue, params));
  21698. });
  21699. }
  21700. data.each(function (idx) {
  21701. var itemModel = data.getItemModel(idx);
  21702. var itemSymbolType = itemModel.getShallow('symbol', true);
  21703. var itemSymbolSize = itemModel.getShallow('symbolSize', true);
  21704. // If has item symbol
  21705. if (itemSymbolType != null) {
  21706. data.setItemVisual(idx, 'symbol', itemSymbolType);
  21707. }
  21708. if (itemSymbolSize != null) {
  21709. // PENDING Transform symbolSize ?
  21710. data.setItemVisual(idx, 'symbolSize', itemSymbolSize);
  21711. }
  21712. });
  21713. }
  21714. });
  21715. };
  21716. /***/ },
  21717. /* 111 */
  21718. /***/ function(module, exports) {
  21719. module.exports = function (seriesType, ecModel) {
  21720. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  21721. var data = seriesModel.getData();
  21722. var coordSys = seriesModel.coordinateSystem;
  21723. if (coordSys) {
  21724. var dims = coordSys.dimensions;
  21725. if (coordSys.type === 'singleAxis') {
  21726. data.each(dims[0], function (x, idx) {
  21727. // Also {Array.<number>}, not undefined to avoid if...else... statement
  21728. data.setItemLayout(idx, isNaN(x) ? [NaN, NaN] : coordSys.dataToPoint(x));
  21729. });
  21730. }
  21731. else {
  21732. data.each(dims, function (x, y, idx) {
  21733. // Also {Array.<number>}, not undefined to avoid if...else... statement
  21734. data.setItemLayout(
  21735. idx, (isNaN(x) || isNaN(y)) ? [NaN, NaN] : coordSys.dataToPoint([x, y])
  21736. );
  21737. }, true);
  21738. }
  21739. }
  21740. });
  21741. };
  21742. /***/ },
  21743. /* 112 */
  21744. /***/ function(module, exports) {
  21745. var samplers = {
  21746. average: function (frame) {
  21747. var sum = 0;
  21748. var count = 0;
  21749. for (var i = 0; i < frame.length; i++) {
  21750. if (!isNaN(frame[i])) {
  21751. sum += frame[i];
  21752. count++;
  21753. }
  21754. }
  21755. // Return NaN if count is 0
  21756. return count === 0 ? NaN : sum / count;
  21757. },
  21758. sum: function (frame) {
  21759. var sum = 0;
  21760. for (var i = 0; i < frame.length; i++) {
  21761. // Ignore NaN
  21762. sum += frame[i] || 0;
  21763. }
  21764. return sum;
  21765. },
  21766. max: function (frame) {
  21767. var max = -Infinity;
  21768. for (var i = 0; i < frame.length; i++) {
  21769. frame[i] > max && (max = frame[i]);
  21770. }
  21771. return max;
  21772. },
  21773. min: function (frame) {
  21774. var min = Infinity;
  21775. for (var i = 0; i < frame.length; i++) {
  21776. frame[i] < min && (min = frame[i]);
  21777. }
  21778. return min;
  21779. },
  21780. // TODO
  21781. // Median
  21782. nearest: function (frame) {
  21783. return frame[0];
  21784. }
  21785. };
  21786. var indexSampler = function (frame, value) {
  21787. return Math.round(frame.length / 2);
  21788. };
  21789. module.exports = function (seriesType, ecModel, api) {
  21790. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  21791. var data = seriesModel.getData();
  21792. var sampling = seriesModel.get('sampling');
  21793. var coordSys = seriesModel.coordinateSystem;
  21794. // Only cartesian2d support down sampling
  21795. if (coordSys.type === 'cartesian2d' && sampling) {
  21796. var baseAxis = coordSys.getBaseAxis();
  21797. var valueAxis = coordSys.getOtherAxis(baseAxis);
  21798. var extent = baseAxis.getExtent();
  21799. // Coordinste system has been resized
  21800. var size = extent[1] - extent[0];
  21801. var rate = Math.round(data.count() / size);
  21802. if (rate > 1) {
  21803. var sampler;
  21804. if (typeof sampling === 'string') {
  21805. sampler = samplers[sampling];
  21806. }
  21807. else if (typeof sampling === 'function') {
  21808. sampler = sampling;
  21809. }
  21810. if (sampler) {
  21811. data = data.downSample(
  21812. valueAxis.dim, 1 / rate, sampler, indexSampler
  21813. );
  21814. seriesModel.setData(data);
  21815. }
  21816. }
  21817. }
  21818. }, this);
  21819. };
  21820. /***/ },
  21821. /* 113 */
  21822. /***/ function(module, exports, __webpack_require__) {
  21823. 'use strict';
  21824. var graphic = __webpack_require__(43);
  21825. var zrUtil = __webpack_require__(4);
  21826. var echarts = __webpack_require__(1);
  21827. __webpack_require__(114);
  21828. __webpack_require__(131);
  21829. // Grid view
  21830. echarts.extendComponentView({
  21831. type: 'grid',
  21832. render: function (gridModel, ecModel) {
  21833. this.group.removeAll();
  21834. if (gridModel.get('show')) {
  21835. this.group.add(new graphic.Rect({
  21836. shape: gridModel.coordinateSystem.getRect(),
  21837. style: zrUtil.defaults({
  21838. fill: gridModel.get('backgroundColor')
  21839. }, gridModel.getItemStyle()),
  21840. silent: true,
  21841. z2: -1
  21842. }));
  21843. }
  21844. }
  21845. });
  21846. echarts.registerPreprocessor(function (option) {
  21847. // Only create grid when need
  21848. if (option.xAxis && option.yAxis && !option.grid) {
  21849. option.grid = {};
  21850. }
  21851. });
  21852. /***/ },
  21853. /* 114 */
  21854. /***/ function(module, exports, __webpack_require__) {
  21855. /**
  21856. * Grid is a region which contains at most 4 cartesian systems
  21857. *
  21858. * TODO Default cartesian
  21859. */
  21860. var factory = exports;
  21861. var layout = __webpack_require__(21);
  21862. var axisHelper = __webpack_require__(115);
  21863. var zrUtil = __webpack_require__(4);
  21864. var Cartesian2D = __webpack_require__(121);
  21865. var Axis2D = __webpack_require__(123);
  21866. var each = zrUtil.each;
  21867. var ifAxisCrossZero = axisHelper.ifAxisCrossZero;
  21868. var niceScaleExtent = axisHelper.niceScaleExtent;
  21869. // 依赖 GridModel, AxisModel 做预处理
  21870. __webpack_require__(126);
  21871. /**
  21872. * Check if the axis is used in the specified grid
  21873. * @inner
  21874. */
  21875. function isAxisUsedInTheGrid(axisModel, gridModel, ecModel) {
  21876. return axisModel.getCoordSysModel() === gridModel;
  21877. }
  21878. function getLabelUnionRect(axis) {
  21879. var axisModel = axis.model;
  21880. var labels = axisModel.getFormattedLabels();
  21881. var textStyleModel = axisModel.getModel('axisLabel.textStyle');
  21882. var rect;
  21883. var step = 1;
  21884. var labelCount = labels.length;
  21885. if (labelCount > 40) {
  21886. // Simple optimization for large amount of labels
  21887. step = Math.ceil(labelCount / 40);
  21888. }
  21889. for (var i = 0; i < labelCount; i += step) {
  21890. if (!axis.isLabelIgnored(i)) {
  21891. var singleRect = textStyleModel.getTextRect(labels[i]);
  21892. // FIXME consider label rotate
  21893. rect ? rect.union(singleRect) : (rect = singleRect);
  21894. }
  21895. }
  21896. return rect;
  21897. }
  21898. function Grid(gridModel, ecModel, api) {
  21899. /**
  21900. * @type {Object.<string, module:echarts/coord/cartesian/Cartesian2D>}
  21901. * @private
  21902. */
  21903. this._coordsMap = {};
  21904. /**
  21905. * @type {Array.<module:echarts/coord/cartesian/Cartesian>}
  21906. * @private
  21907. */
  21908. this._coordsList = [];
  21909. /**
  21910. * @type {Object.<string, module:echarts/coord/cartesian/Axis2D>}
  21911. * @private
  21912. */
  21913. this._axesMap = {};
  21914. /**
  21915. * @type {Array.<module:echarts/coord/cartesian/Axis2D>}
  21916. * @private
  21917. */
  21918. this._axesList = [];
  21919. this._initCartesian(gridModel, ecModel, api);
  21920. this._model = gridModel;
  21921. }
  21922. var gridProto = Grid.prototype;
  21923. gridProto.type = 'grid';
  21924. gridProto.getRect = function () {
  21925. return this._rect;
  21926. };
  21927. gridProto.update = function (ecModel, api) {
  21928. var axesMap = this._axesMap;
  21929. this._updateScale(ecModel, this._model);
  21930. function ifAxisCanNotOnZero(otherAxisDim) {
  21931. var axes = axesMap[otherAxisDim];
  21932. for (var idx in axes) {
  21933. if (axes.hasOwnProperty(idx)) {
  21934. var axis = axes[idx];
  21935. if (axis && (axis.type === 'category' || !ifAxisCrossZero(axis))) {
  21936. return true;
  21937. }
  21938. }
  21939. }
  21940. return false;
  21941. }
  21942. each(axesMap.x, function (xAxis) {
  21943. niceScaleExtent(xAxis, xAxis.model);
  21944. });
  21945. each(axesMap.y, function (yAxis) {
  21946. niceScaleExtent(yAxis, yAxis.model);
  21947. });
  21948. // Fix configuration
  21949. each(axesMap.x, function (xAxis) {
  21950. // onZero can not be enabled in these two situations
  21951. // 1. When any other axis is a category axis
  21952. // 2. When any other axis not across 0 point
  21953. if (ifAxisCanNotOnZero('y')) {
  21954. xAxis.onZero = false;
  21955. }
  21956. });
  21957. each(axesMap.y, function (yAxis) {
  21958. if (ifAxisCanNotOnZero('x')) {
  21959. yAxis.onZero = false;
  21960. }
  21961. });
  21962. // Resize again if containLabel is enabled
  21963. // FIXME It may cause getting wrong grid size in data processing stage
  21964. this.resize(this._model, api);
  21965. };
  21966. /**
  21967. * Resize the grid
  21968. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  21969. * @param {module:echarts/ExtensionAPI} api
  21970. */
  21971. gridProto.resize = function (gridModel, api) {
  21972. var gridRect = layout.getLayoutRect(
  21973. gridModel.getBoxLayoutParams(), {
  21974. width: api.getWidth(),
  21975. height: api.getHeight()
  21976. });
  21977. this._rect = gridRect;
  21978. var axesList = this._axesList;
  21979. adjustAxes();
  21980. // Minus label size
  21981. if (gridModel.get('containLabel')) {
  21982. each(axesList, function (axis) {
  21983. if (!axis.model.get('axisLabel.inside')) {
  21984. var labelUnionRect = getLabelUnionRect(axis);
  21985. if (labelUnionRect) {
  21986. var dim = axis.isHorizontal() ? 'height' : 'width';
  21987. var margin = axis.model.get('axisLabel.margin');
  21988. gridRect[dim] -= labelUnionRect[dim] + margin;
  21989. if (axis.position === 'top') {
  21990. gridRect.y += labelUnionRect.height + margin;
  21991. }
  21992. else if (axis.position === 'left') {
  21993. gridRect.x += labelUnionRect.width + margin;
  21994. }
  21995. }
  21996. }
  21997. });
  21998. adjustAxes();
  21999. }
  22000. function adjustAxes() {
  22001. each(axesList, function (axis) {
  22002. var isHorizontal = axis.isHorizontal();
  22003. var extent = isHorizontal ? [0, gridRect.width] : [0, gridRect.height];
  22004. var idx = axis.inverse ? 1 : 0;
  22005. axis.setExtent(extent[idx], extent[1 - idx]);
  22006. updateAxisTransfrom(axis, isHorizontal ? gridRect.x : gridRect.y);
  22007. });
  22008. }
  22009. };
  22010. /**
  22011. * @param {string} axisType
  22012. * @param {ndumber} [axisIndex]
  22013. */
  22014. gridProto.getAxis = function (axisType, axisIndex) {
  22015. var axesMapOnDim = this._axesMap[axisType];
  22016. if (axesMapOnDim != null) {
  22017. if (axisIndex == null) {
  22018. // Find first axis
  22019. for (var name in axesMapOnDim) {
  22020. if (axesMapOnDim.hasOwnProperty(name)) {
  22021. return axesMapOnDim[name];
  22022. }
  22023. }
  22024. }
  22025. return axesMapOnDim[axisIndex];
  22026. }
  22027. };
  22028. gridProto.getCartesian = function (xAxisIndex, yAxisIndex) {
  22029. if (xAxisIndex != null && yAxisIndex != null) {
  22030. var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
  22031. return this._coordsMap[key];
  22032. }
  22033. else {
  22034. // When only xAxisIndex or yAxisIndex given, find its first cartesian.
  22035. for (var i = 0, coordList = this._coordsList; i < coordList.length; i++) {
  22036. if (coordList[i].getAxis('x').index === xAxisIndex
  22037. || coordList[i].getAxis('y').index === yAxisIndex
  22038. ) {
  22039. return coordList[i];
  22040. }
  22041. }
  22042. }
  22043. };
  22044. /**
  22045. * @implements
  22046. * see {module:echarts/CoodinateSystem}
  22047. */
  22048. gridProto.convertToPixel = function (ecModel, finder, value) {
  22049. var target = this._findConvertTarget(ecModel, finder);
  22050. return target.cartesian
  22051. ? target.cartesian.dataToPoint(value)
  22052. : target.axis
  22053. ? target.axis.toGlobalCoord(target.axis.dataToCoord(value))
  22054. : null;
  22055. };
  22056. /**
  22057. * @implements
  22058. * see {module:echarts/CoodinateSystem}
  22059. */
  22060. gridProto.convertFromPixel = function (ecModel, finder, value) {
  22061. var target = this._findConvertTarget(ecModel, finder);
  22062. return target.cartesian
  22063. ? target.cartesian.pointToData(value)
  22064. : target.axis
  22065. ? target.axis.coordToData(target.axis.toLocalCoord(value))
  22066. : null;
  22067. };
  22068. /**
  22069. * @inner
  22070. */
  22071. gridProto._findConvertTarget = function (ecModel, finder) {
  22072. var seriesModel = finder.seriesModel;
  22073. var xAxisModel = finder.xAxisModel
  22074. || (seriesModel && seriesModel.getReferringComponents('xAxis')[0]);
  22075. var yAxisModel = finder.yAxisModel
  22076. || (seriesModel && seriesModel.getReferringComponents('yAxis')[0]);
  22077. var gridModel = finder.gridModel;
  22078. var coordsList = this._coordsList;
  22079. var cartesian;
  22080. var axis;
  22081. if (seriesModel) {
  22082. cartesian = seriesModel.coordinateSystem;
  22083. zrUtil.indexOf(coordsList, cartesian) < 0 && (cartesian = null);
  22084. }
  22085. else if (xAxisModel && yAxisModel) {
  22086. cartesian = this.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
  22087. }
  22088. else if (xAxisModel) {
  22089. axis = this.getAxis('x', xAxisModel.componentIndex);
  22090. }
  22091. else if (yAxisModel) {
  22092. axis = this.getAxis('y', yAxisModel.componentIndex);
  22093. }
  22094. // Lowest priority.
  22095. else if (gridModel) {
  22096. var grid = gridModel.coordinateSystem;
  22097. if (grid === this) {
  22098. cartesian = this._coordsList[0];
  22099. }
  22100. }
  22101. return {cartesian: cartesian, axis: axis};
  22102. };
  22103. /**
  22104. * @implements
  22105. * see {module:echarts/CoodinateSystem}
  22106. */
  22107. gridProto.containPoint = function (point) {
  22108. var coord = this._coordsList[0];
  22109. if (coord) {
  22110. return coord.containPoint(point);
  22111. }
  22112. };
  22113. /**
  22114. * Initialize cartesian coordinate systems
  22115. * @private
  22116. */
  22117. gridProto._initCartesian = function (gridModel, ecModel, api) {
  22118. var axisPositionUsed = {
  22119. left: false,
  22120. right: false,
  22121. top: false,
  22122. bottom: false
  22123. };
  22124. var axesMap = {
  22125. x: {},
  22126. y: {}
  22127. };
  22128. var axesCount = {
  22129. x: 0,
  22130. y: 0
  22131. };
  22132. /// Create axis
  22133. ecModel.eachComponent('xAxis', createAxisCreator('x'), this);
  22134. ecModel.eachComponent('yAxis', createAxisCreator('y'), this);
  22135. if (!axesCount.x || !axesCount.y) {
  22136. // Roll back when there no either x or y axis
  22137. this._axesMap = {};
  22138. this._axesList = [];
  22139. return;
  22140. }
  22141. this._axesMap = axesMap;
  22142. /// Create cartesian2d
  22143. each(axesMap.x, function (xAxis, xAxisIndex) {
  22144. each(axesMap.y, function (yAxis, yAxisIndex) {
  22145. var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
  22146. var cartesian = new Cartesian2D(key);
  22147. cartesian.grid = this;
  22148. this._coordsMap[key] = cartesian;
  22149. this._coordsList.push(cartesian);
  22150. cartesian.addAxis(xAxis);
  22151. cartesian.addAxis(yAxis);
  22152. }, this);
  22153. }, this);
  22154. function createAxisCreator(axisType) {
  22155. return function (axisModel, idx) {
  22156. if (!isAxisUsedInTheGrid(axisModel, gridModel, ecModel)) {
  22157. return;
  22158. }
  22159. var axisPosition = axisModel.get('position');
  22160. if (axisType === 'x') {
  22161. // Fix position
  22162. if (axisPosition !== 'top' && axisPosition !== 'bottom') {
  22163. // Default bottom of X
  22164. axisPosition = 'bottom';
  22165. if (axisPositionUsed[axisPosition]) {
  22166. axisPosition = axisPosition === 'top' ? 'bottom' : 'top';
  22167. }
  22168. }
  22169. }
  22170. else {
  22171. // Fix position
  22172. if (axisPosition !== 'left' && axisPosition !== 'right') {
  22173. // Default left of Y
  22174. axisPosition = 'left';
  22175. if (axisPositionUsed[axisPosition]) {
  22176. axisPosition = axisPosition === 'left' ? 'right' : 'left';
  22177. }
  22178. }
  22179. }
  22180. axisPositionUsed[axisPosition] = true;
  22181. var axis = new Axis2D(
  22182. axisType, axisHelper.createScaleByModel(axisModel),
  22183. [0, 0],
  22184. axisModel.get('type'),
  22185. axisPosition
  22186. );
  22187. var isCategory = axis.type === 'category';
  22188. axis.onBand = isCategory && axisModel.get('boundaryGap');
  22189. axis.inverse = axisModel.get('inverse');
  22190. axis.onZero = axisModel.get('axisLine.onZero');
  22191. // Inject axis into axisModel
  22192. axisModel.axis = axis;
  22193. // Inject axisModel into axis
  22194. axis.model = axisModel;
  22195. // Inject grid info axis
  22196. axis.grid = this;
  22197. // Index of axis, can be used as key
  22198. axis.index = idx;
  22199. this._axesList.push(axis);
  22200. axesMap[axisType][idx] = axis;
  22201. axesCount[axisType]++;
  22202. };
  22203. }
  22204. };
  22205. /**
  22206. * Update cartesian properties from series
  22207. * @param {module:echarts/model/Option} option
  22208. * @private
  22209. */
  22210. gridProto._updateScale = function (ecModel, gridModel) {
  22211. // Reset scale
  22212. zrUtil.each(this._axesList, function (axis) {
  22213. axis.scale.setExtent(Infinity, -Infinity);
  22214. });
  22215. ecModel.eachSeries(function (seriesModel) {
  22216. if (isCartesian2D(seriesModel)) {
  22217. var axesModels = findAxesModels(seriesModel, ecModel);
  22218. var xAxisModel = axesModels[0];
  22219. var yAxisModel = axesModels[1];
  22220. if (!isAxisUsedInTheGrid(xAxisModel, gridModel, ecModel)
  22221. || !isAxisUsedInTheGrid(yAxisModel, gridModel, ecModel)
  22222. ) {
  22223. return;
  22224. }
  22225. var cartesian = this.getCartesian(
  22226. xAxisModel.componentIndex, yAxisModel.componentIndex
  22227. );
  22228. var data = seriesModel.getData();
  22229. var xAxis = cartesian.getAxis('x');
  22230. var yAxis = cartesian.getAxis('y');
  22231. if (data.type === 'list') {
  22232. unionExtent(data, xAxis, seriesModel);
  22233. unionExtent(data, yAxis, seriesModel);
  22234. }
  22235. }
  22236. }, this);
  22237. function unionExtent(data, axis, seriesModel) {
  22238. each(seriesModel.coordDimToDataDim(axis.dim), function (dim) {
  22239. axis.scale.unionExtentFromData(data, dim);
  22240. });
  22241. }
  22242. };
  22243. /**
  22244. * @inner
  22245. */
  22246. function updateAxisTransfrom(axis, coordBase) {
  22247. var axisExtent = axis.getExtent();
  22248. var axisExtentSum = axisExtent[0] + axisExtent[1];
  22249. // Fast transform
  22250. axis.toGlobalCoord = axis.dim === 'x'
  22251. ? function (coord) {
  22252. return coord + coordBase;
  22253. }
  22254. : function (coord) {
  22255. return axisExtentSum - coord + coordBase;
  22256. };
  22257. axis.toLocalCoord = axis.dim === 'x'
  22258. ? function (coord) {
  22259. return coord - coordBase;
  22260. }
  22261. : function (coord) {
  22262. return axisExtentSum - coord + coordBase;
  22263. };
  22264. }
  22265. var axesTypes = ['xAxis', 'yAxis'];
  22266. /**
  22267. * @inner
  22268. */
  22269. function findAxesModels(seriesModel, ecModel) {
  22270. return zrUtil.map(axesTypes, function (axisType) {
  22271. var axisModel = seriesModel.getReferringComponents(axisType)[0];
  22272. if (true) {
  22273. if (!axisModel) {
  22274. throw new Error(axisType + ' "' + zrUtil.retrieve(
  22275. seriesModel.get(axisType + 'Index'),
  22276. seriesModel.get(axisType + 'Id'),
  22277. 0
  22278. ) + '" not found');
  22279. }
  22280. }
  22281. return axisModel;
  22282. });
  22283. }
  22284. /**
  22285. * @inner
  22286. */
  22287. function isCartesian2D(seriesModel) {
  22288. return seriesModel.get('coordinateSystem') === 'cartesian2d';
  22289. }
  22290. Grid.create = function (ecModel, api) {
  22291. var grids = [];
  22292. ecModel.eachComponent('grid', function (gridModel, idx) {
  22293. var grid = new Grid(gridModel, ecModel, api);
  22294. grid.name = 'grid_' + idx;
  22295. grid.resize(gridModel, api);
  22296. gridModel.coordinateSystem = grid;
  22297. grids.push(grid);
  22298. });
  22299. // Inject the coordinateSystems into seriesModel
  22300. ecModel.eachSeries(function (seriesModel) {
  22301. if (!isCartesian2D(seriesModel)) {
  22302. return;
  22303. }
  22304. var axesModels = findAxesModels(seriesModel, ecModel);
  22305. var xAxisModel = axesModels[0];
  22306. var yAxisModel = axesModels[1];
  22307. var gridModel = xAxisModel.getCoordSysModel();
  22308. if (true) {
  22309. if (!gridModel) {
  22310. throw new Error(
  22311. 'Grid "' + zrUtil.retrieve(
  22312. xAxisModel.get('gridIndex'),
  22313. xAxisModel.get('gridId'),
  22314. 0
  22315. ) + '" not found'
  22316. );
  22317. }
  22318. if (xAxisModel.getCoordSysModel() !== yAxisModel.getCoordSysModel()) {
  22319. throw new Error('xAxis and yAxis must use the same grid');
  22320. }
  22321. }
  22322. var grid = gridModel.coordinateSystem;
  22323. seriesModel.coordinateSystem = grid.getCartesian(
  22324. xAxisModel.componentIndex, yAxisModel.componentIndex
  22325. );
  22326. });
  22327. return grids;
  22328. };
  22329. // For deciding which dimensions to use when creating list data
  22330. Grid.dimensions = Cartesian2D.prototype.dimensions;
  22331. __webpack_require__(26).register('cartesian2d', Grid);
  22332. module.exports = Grid;
  22333. /***/ },
  22334. /* 115 */
  22335. /***/ function(module, exports, __webpack_require__) {
  22336. var OrdinalScale = __webpack_require__(116);
  22337. var IntervalScale = __webpack_require__(118);
  22338. __webpack_require__(119);
  22339. __webpack_require__(120);
  22340. var Scale = __webpack_require__(117);
  22341. var numberUtil = __webpack_require__(7);
  22342. var zrUtil = __webpack_require__(4);
  22343. var textContain = __webpack_require__(8);
  22344. var axisHelper = {};
  22345. /**
  22346. * Get axis scale extent before niced.
  22347. * Item of returned array can only be number (including Infinity and NaN).
  22348. */
  22349. axisHelper.getScaleExtent = function (axis, model) {
  22350. var scale = axis.scale;
  22351. var scaleType = scale.type;
  22352. var min = model.getMin();
  22353. var max = model.getMax();
  22354. var fixMin = min != null;
  22355. var fixMax = max != null;
  22356. var originalExtent = scale.getExtent();
  22357. var axisDataLen;
  22358. var boundaryGap;
  22359. var span;
  22360. if (scaleType === 'ordinal') {
  22361. axisDataLen = (model.get('data') || []).length;
  22362. }
  22363. else {
  22364. boundaryGap = model.get('boundaryGap');
  22365. if (!zrUtil.isArray(boundaryGap)) {
  22366. boundaryGap = [boundaryGap || 0, boundaryGap || 0];
  22367. }
  22368. boundaryGap[0] = numberUtil.parsePercent(boundaryGap[0], 1);
  22369. boundaryGap[1] = numberUtil.parsePercent(boundaryGap[1], 1);
  22370. span = originalExtent[1] - originalExtent[0];
  22371. }
  22372. if (min == null) {
  22373. min = scaleType === 'ordinal'
  22374. ? (axisDataLen ? 0 : NaN)
  22375. : originalExtent[0] - boundaryGap[0] * span;
  22376. }
  22377. if (max == null) {
  22378. max = scaleType === 'ordinal'
  22379. ? (axisDataLen ? axisDataLen - 1 : NaN)
  22380. : originalExtent[1] + boundaryGap[1] * span;
  22381. }
  22382. if (min === 'dataMin') {
  22383. min = originalExtent[0];
  22384. }
  22385. if (max === 'dataMax') {
  22386. max = originalExtent[1];
  22387. }
  22388. (min == null || !isFinite(min)) && (min = NaN);
  22389. (max == null || !isFinite(max)) && (max = NaN);
  22390. axis.setBlank(zrUtil.eqNaN(min) || zrUtil.eqNaN(max));
  22391. // Evaluate if axis needs cross zero
  22392. if (model.getNeedCrossZero()) {
  22393. // Axis is over zero and min is not set
  22394. if (min > 0 && max > 0 && !fixMin) {
  22395. min = 0;
  22396. }
  22397. // Axis is under zero and max is not set
  22398. if (min < 0 && max < 0 && !fixMax) {
  22399. max = 0;
  22400. }
  22401. }
  22402. return [min, max];
  22403. };
  22404. axisHelper.niceScaleExtent = function (axis, model) {
  22405. var scale = axis.scale;
  22406. var extent = axisHelper.getScaleExtent(axis, model);
  22407. var fixMin = model.getMin() != null;
  22408. var fixMax = model.getMax() != null;
  22409. var splitNumber = model.get('splitNumber');
  22410. if (scale.type === 'log') {
  22411. scale.base = model.get('logBase');
  22412. }
  22413. scale.setExtent(extent[0], extent[1]);
  22414. scale.niceExtent(splitNumber, fixMin, fixMax);
  22415. // Use minInterval to constraint the calculated interval.
  22416. // If calculated interval is less than minInterval. increase the interval quantity until
  22417. // it is larger than minInterval.
  22418. // For example:
  22419. // minInterval is 1, calculated interval is 0.2, so increase it to be 1. In this way we can get
  22420. // an integer axis.
  22421. var minInterval = model.get('minInterval');
  22422. if (isFinite(minInterval) && !fixMin && !fixMax && scale.type === 'interval') {
  22423. var interval = scale.getInterval();
  22424. var intervalScale = Math.max(Math.abs(interval), minInterval) / interval;
  22425. // while (interval < minInterval) {
  22426. // var quantity = numberUtil.quantity(interval);
  22427. // interval = quantity * 10;
  22428. // scaleQuantity *= 10;
  22429. // }
  22430. extent = scale.getExtent();
  22431. var origin = (extent[1] + extent[0]) / 2;
  22432. scale.setExtent(
  22433. intervalScale * (extent[0] - origin) + origin,
  22434. intervalScale * (extent[1] - origin) + origin
  22435. );
  22436. scale.niceExtent(splitNumber);
  22437. }
  22438. // If some one specified the min, max. And the default calculated interval
  22439. // is not good enough. He can specify the interval. It is often appeared
  22440. // in angle axis with angle 0 - 360. Interval calculated in interval scale is hard
  22441. // to be 60.
  22442. // FIXME
  22443. var interval = model.get('interval');
  22444. if (interval != null) {
  22445. scale.setInterval && scale.setInterval(interval);
  22446. }
  22447. };
  22448. /**
  22449. * @param {module:echarts/model/Model} model
  22450. * @param {string} [axisType] Default retrieve from model.type
  22451. * @return {module:echarts/scale/*}
  22452. */
  22453. axisHelper.createScaleByModel = function(model, axisType) {
  22454. axisType = axisType || model.get('type');
  22455. if (axisType) {
  22456. switch (axisType) {
  22457. // Buildin scale
  22458. case 'category':
  22459. return new OrdinalScale(
  22460. model.getCategories(), [Infinity, -Infinity]
  22461. );
  22462. case 'value':
  22463. return new IntervalScale();
  22464. // Extended scale, like time and log
  22465. default:
  22466. return (Scale.getClass(axisType) || IntervalScale).create(model);
  22467. }
  22468. }
  22469. };
  22470. /**
  22471. * Check if the axis corss 0
  22472. */
  22473. axisHelper.ifAxisCrossZero = function (axis) {
  22474. var dataExtent = axis.scale.getExtent();
  22475. var min = dataExtent[0];
  22476. var max = dataExtent[1];
  22477. return !((min > 0 && max > 0) || (min < 0 && max < 0));
  22478. };
  22479. /**
  22480. * @param {Array.<number>} tickCoords In axis self coordinate.
  22481. * @param {Array.<string>} labels
  22482. * @param {string} font
  22483. * @param {boolean} isAxisHorizontal
  22484. * @return {number}
  22485. */
  22486. axisHelper.getAxisLabelInterval = function (tickCoords, labels, font, isAxisHorizontal) {
  22487. // FIXME
  22488. // 不同角的axis和label,不只是horizontal和vertical.
  22489. var textSpaceTakenRect;
  22490. var autoLabelInterval = 0;
  22491. var accumulatedLabelInterval = 0;
  22492. var step = 1;
  22493. if (labels.length > 40) {
  22494. // Simple optimization for large amount of labels
  22495. step = Math.floor(labels.length / 40);
  22496. }
  22497. for (var i = 0; i < tickCoords.length; i += step) {
  22498. var tickCoord = tickCoords[i];
  22499. var rect = textContain.getBoundingRect(
  22500. labels[i], font, 'center', 'top'
  22501. );
  22502. rect[isAxisHorizontal ? 'x' : 'y'] += tickCoord;
  22503. // FIXME Magic number 1.5
  22504. rect[isAxisHorizontal ? 'width' : 'height'] *= 1.3;
  22505. if (!textSpaceTakenRect) {
  22506. textSpaceTakenRect = rect.clone();
  22507. }
  22508. // There is no space for current label;
  22509. else if (textSpaceTakenRect.intersect(rect)) {
  22510. accumulatedLabelInterval++;
  22511. autoLabelInterval = Math.max(autoLabelInterval, accumulatedLabelInterval);
  22512. }
  22513. else {
  22514. textSpaceTakenRect.union(rect);
  22515. // Reset
  22516. accumulatedLabelInterval = 0;
  22517. }
  22518. }
  22519. if (autoLabelInterval === 0 && step > 1) {
  22520. return step;
  22521. }
  22522. return (autoLabelInterval + 1) * step - 1;
  22523. };
  22524. /**
  22525. * @param {Object} axis
  22526. * @param {Function} labelFormatter
  22527. * @return {Array.<string>}
  22528. */
  22529. axisHelper.getFormattedLabels = function (axis, labelFormatter) {
  22530. var scale = axis.scale;
  22531. var labels = scale.getTicksLabels();
  22532. var ticks = scale.getTicks();
  22533. if (typeof labelFormatter === 'string') {
  22534. labelFormatter = (function (tpl) {
  22535. return function (val) {
  22536. return tpl.replace('{value}', val != null ? val : '');
  22537. };
  22538. })(labelFormatter);
  22539. // Consider empty array
  22540. return zrUtil.map(labels, labelFormatter);
  22541. }
  22542. else if (typeof labelFormatter === 'function') {
  22543. return zrUtil.map(ticks, function (tick, idx) {
  22544. return labelFormatter(
  22545. axis.type === 'category' ? scale.getLabel(tick) : tick,
  22546. idx
  22547. );
  22548. }, this);
  22549. }
  22550. else {
  22551. return labels;
  22552. }
  22553. };
  22554. module.exports = axisHelper;
  22555. /***/ },
  22556. /* 116 */
  22557. /***/ function(module, exports, __webpack_require__) {
  22558. /**
  22559. * Linear continuous scale
  22560. * @module echarts/coord/scale/Ordinal
  22561. *
  22562. * http://en.wikipedia.org/wiki/Level_of_measurement
  22563. */
  22564. // FIXME only one data
  22565. var zrUtil = __webpack_require__(4);
  22566. var Scale = __webpack_require__(117);
  22567. var scaleProto = Scale.prototype;
  22568. var OrdinalScale = Scale.extend({
  22569. type: 'ordinal',
  22570. init: function (data, extent) {
  22571. this._data = data;
  22572. this._extent = extent || [0, data.length - 1];
  22573. },
  22574. parse: function (val) {
  22575. return typeof val === 'string'
  22576. ? zrUtil.indexOf(this._data, val)
  22577. // val might be float.
  22578. : Math.round(val);
  22579. },
  22580. contain: function (rank) {
  22581. rank = this.parse(rank);
  22582. return scaleProto.contain.call(this, rank)
  22583. && this._data[rank] != null;
  22584. },
  22585. /**
  22586. * Normalize given rank or name to linear [0, 1]
  22587. * @param {number|string} [val]
  22588. * @return {number}
  22589. */
  22590. normalize: function (val) {
  22591. return scaleProto.normalize.call(this, this.parse(val));
  22592. },
  22593. scale: function (val) {
  22594. return Math.round(scaleProto.scale.call(this, val));
  22595. },
  22596. /**
  22597. * @return {Array}
  22598. */
  22599. getTicks: function () {
  22600. var ticks = [];
  22601. var extent = this._extent;
  22602. var rank = extent[0];
  22603. while (rank <= extent[1]) {
  22604. ticks.push(rank);
  22605. rank++;
  22606. }
  22607. return ticks;
  22608. },
  22609. /**
  22610. * Get item on rank n
  22611. * @param {number} n
  22612. * @return {string}
  22613. */
  22614. getLabel: function (n) {
  22615. return this._data[n];
  22616. },
  22617. /**
  22618. * @return {number}
  22619. */
  22620. count: function () {
  22621. return this._extent[1] - this._extent[0] + 1;
  22622. },
  22623. /**
  22624. * @override
  22625. */
  22626. unionExtentFromData: function (data, dim) {
  22627. this.unionExtent(data.getDataExtent(dim, false));
  22628. },
  22629. niceTicks: zrUtil.noop,
  22630. niceExtent: zrUtil.noop
  22631. });
  22632. /**
  22633. * @return {module:echarts/scale/Time}
  22634. */
  22635. OrdinalScale.create = function () {
  22636. return new OrdinalScale();
  22637. };
  22638. module.exports = OrdinalScale;
  22639. /***/ },
  22640. /* 117 */
  22641. /***/ function(module, exports, __webpack_require__) {
  22642. /**
  22643. * // Scale class management
  22644. * @module echarts/scale/Scale
  22645. */
  22646. var clazzUtil = __webpack_require__(13);
  22647. function Scale() {
  22648. /**
  22649. * Extent
  22650. * @type {Array.<number>}
  22651. * @protected
  22652. */
  22653. this._extent = [Infinity, -Infinity];
  22654. /**
  22655. * Step is calculated in adjustExtent
  22656. * @type {Array.<number>}
  22657. * @protected
  22658. */
  22659. this._interval = 0;
  22660. this.init && this.init.apply(this, arguments);
  22661. }
  22662. var scaleProto = Scale.prototype;
  22663. /**
  22664. * Parse input val to valid inner number.
  22665. * @param {*} val
  22666. * @return {number}
  22667. */
  22668. scaleProto.parse = function (val) {
  22669. // Notice: This would be a trap here, If the implementation
  22670. // of this method depends on extent, and this method is used
  22671. // before extent set (like in dataZoom), it would be wrong.
  22672. // Nevertheless, parse does not depend on extent generally.
  22673. return val;
  22674. };
  22675. scaleProto.contain = function (val) {
  22676. var extent = this._extent;
  22677. return val >= extent[0] && val <= extent[1];
  22678. };
  22679. /**
  22680. * Normalize value to linear [0, 1], return 0.5 if extent span is 0
  22681. * @param {number} val
  22682. * @return {number}
  22683. */
  22684. scaleProto.normalize = function (val) {
  22685. var extent = this._extent;
  22686. if (extent[1] === extent[0]) {
  22687. return 0.5;
  22688. }
  22689. return (val - extent[0]) / (extent[1] - extent[0]);
  22690. };
  22691. /**
  22692. * Scale normalized value
  22693. * @param {number} val
  22694. * @return {number}
  22695. */
  22696. scaleProto.scale = function (val) {
  22697. var extent = this._extent;
  22698. return val * (extent[1] - extent[0]) + extent[0];
  22699. };
  22700. /**
  22701. * Set extent from data
  22702. * @param {Array.<number>} other
  22703. */
  22704. scaleProto.unionExtent = function (other) {
  22705. var extent = this._extent;
  22706. other[0] < extent[0] && (extent[0] = other[0]);
  22707. other[1] > extent[1] && (extent[1] = other[1]);
  22708. // not setExtent because in log axis it may transformed to power
  22709. // this.setExtent(extent[0], extent[1]);
  22710. };
  22711. /**
  22712. * Set extent from data
  22713. * @param {module:echarts/data/List} data
  22714. * @param {string} dim
  22715. */
  22716. scaleProto.unionExtentFromData = function (data, dim) {
  22717. this.unionExtent(data.getDataExtent(dim, true));
  22718. };
  22719. /**
  22720. * Get extent
  22721. * @return {Array.<number>}
  22722. */
  22723. scaleProto.getExtent = function () {
  22724. return this._extent.slice();
  22725. };
  22726. /**
  22727. * Set extent
  22728. * @param {number} start
  22729. * @param {number} end
  22730. */
  22731. scaleProto.setExtent = function (start, end) {
  22732. var thisExtent = this._extent;
  22733. if (!isNaN(start)) {
  22734. thisExtent[0] = start;
  22735. }
  22736. if (!isNaN(end)) {
  22737. thisExtent[1] = end;
  22738. }
  22739. };
  22740. /**
  22741. * @return {Array.<string>}
  22742. */
  22743. scaleProto.getTicksLabels = function () {
  22744. var labels = [];
  22745. var ticks = this.getTicks();
  22746. for (var i = 0; i < ticks.length; i++) {
  22747. labels.push(this.getLabel(ticks[i]));
  22748. }
  22749. return labels;
  22750. };
  22751. clazzUtil.enableClassExtend(Scale);
  22752. clazzUtil.enableClassManagement(Scale, {
  22753. registerWhenExtend: true
  22754. });
  22755. module.exports = Scale;
  22756. /***/ },
  22757. /* 118 */
  22758. /***/ function(module, exports, __webpack_require__) {
  22759. /**
  22760. * Interval scale
  22761. * @module echarts/scale/Interval
  22762. */
  22763. var numberUtil = __webpack_require__(7);
  22764. var formatUtil = __webpack_require__(6);
  22765. var Scale = __webpack_require__(117);
  22766. var mathFloor = Math.floor;
  22767. var mathCeil = Math.ceil;
  22768. var getPrecisionSafe = numberUtil.getPrecisionSafe;
  22769. var roundingErrorFix = numberUtil.round;
  22770. /**
  22771. * @alias module:echarts/coord/scale/Interval
  22772. * @constructor
  22773. */
  22774. var IntervalScale = Scale.extend({
  22775. type: 'interval',
  22776. _interval: 0,
  22777. setExtent: function (start, end) {
  22778. var thisExtent = this._extent;
  22779. //start,end may be a Number like '25',so...
  22780. if (!isNaN(start)) {
  22781. thisExtent[0] = parseFloat(start);
  22782. }
  22783. if (!isNaN(end)) {
  22784. thisExtent[1] = parseFloat(end);
  22785. }
  22786. },
  22787. unionExtent: function (other) {
  22788. var extent = this._extent;
  22789. other[0] < extent[0] && (extent[0] = other[0]);
  22790. other[1] > extent[1] && (extent[1] = other[1]);
  22791. // unionExtent may called by it's sub classes
  22792. IntervalScale.prototype.setExtent.call(this, extent[0], extent[1]);
  22793. },
  22794. /**
  22795. * Get interval
  22796. */
  22797. getInterval: function () {
  22798. if (!this._interval) {
  22799. this.niceTicks();
  22800. }
  22801. return this._interval;
  22802. },
  22803. /**
  22804. * Set interval
  22805. */
  22806. setInterval: function (interval) {
  22807. this._interval = interval;
  22808. // Dropped auto calculated niceExtent and use user setted extent
  22809. // We assume user wan't to set both interval, min, max to get a better result
  22810. this._niceExtent = this._extent.slice();
  22811. },
  22812. /**
  22813. * @return {Array.<number>}
  22814. */
  22815. getTicks: function () {
  22816. if (!this._interval) {
  22817. this.niceTicks();
  22818. }
  22819. var interval = this._interval;
  22820. var extent = this._extent;
  22821. var ticks = [];
  22822. // Consider this case: using dataZoom toolbox, zoom and zoom.
  22823. var safeLimit = 10000;
  22824. if (interval) {
  22825. var niceExtent = this._niceExtent;
  22826. var precision = getPrecisionSafe(interval) + 2;
  22827. if (extent[0] < niceExtent[0]) {
  22828. ticks.push(extent[0]);
  22829. }
  22830. var tick = niceExtent[0];
  22831. while (tick <= niceExtent[1]) {
  22832. ticks.push(tick);
  22833. // Avoid rounding error
  22834. tick = roundingErrorFix(tick + interval, precision);
  22835. if (ticks.length > safeLimit) {
  22836. return [];
  22837. }
  22838. }
  22839. // Consider this case: the last item of ticks is smaller
  22840. // than niceExtent[1] and niceExtent[1] === extent[1].
  22841. if (extent[1] > (ticks.length ? ticks[ticks.length - 1] : niceExtent[1])) {
  22842. ticks.push(extent[1]);
  22843. }
  22844. }
  22845. return ticks;
  22846. },
  22847. /**
  22848. * @return {Array.<string>}
  22849. */
  22850. getTicksLabels: function () {
  22851. var labels = [];
  22852. var ticks = this.getTicks();
  22853. for (var i = 0; i < ticks.length; i++) {
  22854. labels.push(this.getLabel(ticks[i]));
  22855. }
  22856. return labels;
  22857. },
  22858. /**
  22859. * @param {number} n
  22860. * @return {number}
  22861. */
  22862. getLabel: function (data) {
  22863. return formatUtil.addCommas(data);
  22864. },
  22865. /**
  22866. * Update interval and extent of intervals for nice ticks
  22867. *
  22868. * @param {number} [splitNumber = 5] Desired number of ticks
  22869. */
  22870. niceTicks: function (splitNumber) {
  22871. splitNumber = splitNumber || 5;
  22872. var extent = this._extent;
  22873. var span = extent[1] - extent[0];
  22874. if (!isFinite(span)) {
  22875. return;
  22876. }
  22877. // User may set axis min 0 and data are all negative
  22878. // FIXME If it needs to reverse ?
  22879. if (span < 0) {
  22880. span = -span;
  22881. extent.reverse();
  22882. }
  22883. // From "Nice Numbers for Graph Labels" of Graphic Gems
  22884. // var niceSpan = numberUtil.nice(span, false);
  22885. var step = roundingErrorFix(
  22886. numberUtil.nice(span / splitNumber, true),
  22887. Math.max(
  22888. getPrecisionSafe(extent[0]),
  22889. getPrecisionSafe(extent[1])
  22890. // extent may be [0, 1], and step should have 1 more digits.
  22891. // To make it safe we add 2 more digits
  22892. ) + 2
  22893. );
  22894. var precision = getPrecisionSafe(step) + 2;
  22895. // Niced extent inside original extent
  22896. var niceExtent = [
  22897. roundingErrorFix(mathCeil(extent[0] / step) * step, precision),
  22898. roundingErrorFix(mathFloor(extent[1] / step) * step, precision)
  22899. ];
  22900. this._interval = step;
  22901. this._niceExtent = niceExtent;
  22902. },
  22903. /**
  22904. * Nice extent.
  22905. * @param {number} [splitNumber = 5] Given approx tick number
  22906. * @param {boolean} [fixMin=false]
  22907. * @param {boolean} [fixMax=false]
  22908. */
  22909. niceExtent: function (splitNumber, fixMin, fixMax) {
  22910. var extent = this._extent;
  22911. // If extent start and end are same, expand them
  22912. if (extent[0] === extent[1]) {
  22913. if (extent[0] !== 0) {
  22914. // Expand extent
  22915. var expandSize = extent[0];
  22916. // In the fowllowing case
  22917. // Axis has been fixed max 100
  22918. // Plus data are all 100 and axis extent are [100, 100].
  22919. // Extend to the both side will cause expanded max is larger than fixed max.
  22920. // So only expand to the smaller side.
  22921. if (!fixMax) {
  22922. extent[1] += expandSize / 2;
  22923. extent[0] -= expandSize / 2;
  22924. }
  22925. else {
  22926. extent[0] -= expandSize / 2;
  22927. }
  22928. }
  22929. else {
  22930. extent[1] = 1;
  22931. }
  22932. }
  22933. var span = extent[1] - extent[0];
  22934. // If there are no data and extent are [Infinity, -Infinity]
  22935. if (!isFinite(span)) {
  22936. extent[0] = 0;
  22937. extent[1] = 1;
  22938. }
  22939. this.niceTicks(splitNumber);
  22940. // var extent = this._extent;
  22941. var interval = this._interval;
  22942. if (!fixMin) {
  22943. extent[0] = roundingErrorFix(mathFloor(extent[0] / interval) * interval);
  22944. }
  22945. if (!fixMax) {
  22946. extent[1] = roundingErrorFix(mathCeil(extent[1] / interval) * interval);
  22947. }
  22948. }
  22949. });
  22950. /**
  22951. * @return {module:echarts/scale/Time}
  22952. */
  22953. IntervalScale.create = function () {
  22954. return new IntervalScale();
  22955. };
  22956. module.exports = IntervalScale;
  22957. /***/ },
  22958. /* 119 */
  22959. /***/ function(module, exports, __webpack_require__) {
  22960. /**
  22961. * Interval scale
  22962. * @module echarts/coord/scale/Time
  22963. */
  22964. var zrUtil = __webpack_require__(4);
  22965. var numberUtil = __webpack_require__(7);
  22966. var formatUtil = __webpack_require__(6);
  22967. var IntervalScale = __webpack_require__(118);
  22968. var intervalScaleProto = IntervalScale.prototype;
  22969. var mathCeil = Math.ceil;
  22970. var mathFloor = Math.floor;
  22971. var ONE_SECOND = 1000;
  22972. var ONE_MINUTE = ONE_SECOND * 60;
  22973. var ONE_HOUR = ONE_MINUTE * 60;
  22974. var ONE_DAY = ONE_HOUR * 24;
  22975. // FIXME 公用?
  22976. var bisect = function (a, x, lo, hi) {
  22977. while (lo < hi) {
  22978. var mid = lo + hi >>> 1;
  22979. if (a[mid][2] < x) {
  22980. lo = mid + 1;
  22981. }
  22982. else {
  22983. hi = mid;
  22984. }
  22985. }
  22986. return lo;
  22987. };
  22988. /**
  22989. * @alias module:echarts/coord/scale/Time
  22990. * @constructor
  22991. */
  22992. var TimeScale = IntervalScale.extend({
  22993. type: 'time',
  22994. // Overwrite
  22995. getLabel: function (val) {
  22996. var stepLvl = this._stepLvl;
  22997. var date = new Date(val);
  22998. return formatUtil.formatTime(stepLvl[0], date);
  22999. },
  23000. // Overwrite
  23001. niceExtent: function (approxTickNum, fixMin, fixMax) {
  23002. var extent = this._extent;
  23003. // If extent start and end are same, expand them
  23004. if (extent[0] === extent[1]) {
  23005. // Expand extent
  23006. extent[0] -= ONE_DAY;
  23007. extent[1] += ONE_DAY;
  23008. }
  23009. // If there are no data and extent are [Infinity, -Infinity]
  23010. if (extent[1] === -Infinity && extent[0] === Infinity) {
  23011. var d = new Date();
  23012. extent[1] = new Date(d.getFullYear(), d.getMonth(), d.getDate());
  23013. extent[0] = extent[1] - ONE_DAY;
  23014. }
  23015. this.niceTicks(approxTickNum);
  23016. // var extent = this._extent;
  23017. var interval = this._interval;
  23018. if (!fixMin) {
  23019. extent[0] = numberUtil.round(mathFloor(extent[0] / interval) * interval);
  23020. }
  23021. if (!fixMax) {
  23022. extent[1] = numberUtil.round(mathCeil(extent[1] / interval) * interval);
  23023. }
  23024. },
  23025. // Overwrite
  23026. niceTicks: function (approxTickNum) {
  23027. approxTickNum = approxTickNum || 10;
  23028. var extent = this._extent;
  23029. var span = extent[1] - extent[0];
  23030. var approxInterval = span / approxTickNum;
  23031. var scaleLevelsLen = scaleLevels.length;
  23032. var idx = bisect(scaleLevels, approxInterval, 0, scaleLevelsLen);
  23033. var level = scaleLevels[Math.min(idx, scaleLevelsLen - 1)];
  23034. var interval = level[2];
  23035. // Same with interval scale if span is much larger than 1 year
  23036. if (level[0] === 'year') {
  23037. var yearSpan = span / interval;
  23038. // From "Nice Numbers for Graph Labels" of Graphic Gems
  23039. // var niceYearSpan = numberUtil.nice(yearSpan, false);
  23040. var yearStep = numberUtil.nice(yearSpan / approxTickNum, true);
  23041. interval *= yearStep;
  23042. }
  23043. var niceExtent = [
  23044. mathCeil(extent[0] / interval) * interval,
  23045. mathFloor(extent[1] / interval) * interval
  23046. ];
  23047. this._stepLvl = level;
  23048. // Interval will be used in getTicks
  23049. this._interval = interval;
  23050. this._niceExtent = niceExtent;
  23051. },
  23052. parse: function (val) {
  23053. // val might be float.
  23054. return +numberUtil.parseDate(val);
  23055. }
  23056. });
  23057. zrUtil.each(['contain', 'normalize'], function (methodName) {
  23058. TimeScale.prototype[methodName] = function (val) {
  23059. return intervalScaleProto[methodName].call(this, this.parse(val));
  23060. };
  23061. });
  23062. // Steps from d3
  23063. var scaleLevels = [
  23064. // Format step interval
  23065. ['hh:mm:ss', 1, ONE_SECOND], // 1s
  23066. ['hh:mm:ss', 5, ONE_SECOND * 5], // 5s
  23067. ['hh:mm:ss', 10, ONE_SECOND * 10], // 10s
  23068. ['hh:mm:ss', 15, ONE_SECOND * 15], // 15s
  23069. ['hh:mm:ss', 30, ONE_SECOND * 30], // 30s
  23070. ['hh:mm\nMM-dd',1, ONE_MINUTE], // 1m
  23071. ['hh:mm\nMM-dd',5, ONE_MINUTE * 5], // 5m
  23072. ['hh:mm\nMM-dd',10, ONE_MINUTE * 10], // 10m
  23073. ['hh:mm\nMM-dd',15, ONE_MINUTE * 15], // 15m
  23074. ['hh:mm\nMM-dd',30, ONE_MINUTE * 30], // 30m
  23075. ['hh:mm\nMM-dd',1, ONE_HOUR], // 1h
  23076. ['hh:mm\nMM-dd',2, ONE_HOUR * 2], // 2h
  23077. ['hh:mm\nMM-dd',6, ONE_HOUR * 6], // 6h
  23078. ['hh:mm\nMM-dd',12, ONE_HOUR * 12], // 12h
  23079. ['MM-dd\nyyyy', 1, ONE_DAY], // 1d
  23080. ['week', 7, ONE_DAY * 7], // 7d
  23081. ['month', 1, ONE_DAY * 31], // 1M
  23082. ['quarter', 3, ONE_DAY * 380 / 4], // 3M
  23083. ['half-year', 6, ONE_DAY * 380 / 2], // 6M
  23084. ['year', 1, ONE_DAY * 380] // 1Y
  23085. ];
  23086. /**
  23087. * @return {module:echarts/scale/Time}
  23088. */
  23089. TimeScale.create = function () {
  23090. return new TimeScale();
  23091. };
  23092. module.exports = TimeScale;
  23093. /***/ },
  23094. /* 120 */
  23095. /***/ function(module, exports, __webpack_require__) {
  23096. /**
  23097. * Log scale
  23098. * @module echarts/scale/Log
  23099. */
  23100. var zrUtil = __webpack_require__(4);
  23101. var Scale = __webpack_require__(117);
  23102. var numberUtil = __webpack_require__(7);
  23103. // Use some method of IntervalScale
  23104. var IntervalScale = __webpack_require__(118);
  23105. var scaleProto = Scale.prototype;
  23106. var intervalScaleProto = IntervalScale.prototype;
  23107. var getPrecisionSafe = numberUtil.getPrecisionSafe;
  23108. var roundingErrorFix = numberUtil.round;
  23109. var mathFloor = Math.floor;
  23110. var mathCeil = Math.ceil;
  23111. var mathPow = Math.pow;
  23112. var mathLog = Math.log;
  23113. var LogScale = Scale.extend({
  23114. type: 'log',
  23115. base: 10,
  23116. $constructor: function () {
  23117. Scale.apply(this, arguments);
  23118. this._originalScale = new IntervalScale();
  23119. },
  23120. /**
  23121. * @return {Array.<number>}
  23122. */
  23123. getTicks: function () {
  23124. var originalScale = this._originalScale;
  23125. var extent = this._extent;
  23126. var originalExtent = originalScale.getExtent();
  23127. return zrUtil.map(intervalScaleProto.getTicks.call(this), function (val) {
  23128. var powVal = numberUtil.round(mathPow(this.base, val));
  23129. // Fix #4158
  23130. powVal = (val === extent[0] && originalScale.__fixMin)
  23131. ? fixRoundingError(powVal, originalExtent[0])
  23132. : powVal;
  23133. powVal = (val === extent[1] && originalScale.__fixMax)
  23134. ? fixRoundingError(powVal, originalExtent[1])
  23135. : powVal;
  23136. return powVal;
  23137. }, this);
  23138. },
  23139. /**
  23140. * @param {number} val
  23141. * @return {string}
  23142. */
  23143. getLabel: intervalScaleProto.getLabel,
  23144. /**
  23145. * @param {number} val
  23146. * @return {number}
  23147. */
  23148. scale: function (val) {
  23149. val = scaleProto.scale.call(this, val);
  23150. return mathPow(this.base, val);
  23151. },
  23152. /**
  23153. * @param {number} start
  23154. * @param {number} end
  23155. */
  23156. setExtent: function (start, end) {
  23157. var base = this.base;
  23158. start = mathLog(start) / mathLog(base);
  23159. end = mathLog(end) / mathLog(base);
  23160. intervalScaleProto.setExtent.call(this, start, end);
  23161. },
  23162. /**
  23163. * @return {number} end
  23164. */
  23165. getExtent: function () {
  23166. var base = this.base;
  23167. var extent = scaleProto.getExtent.call(this);
  23168. extent[0] = mathPow(base, extent[0]);
  23169. extent[1] = mathPow(base, extent[1]);
  23170. // Fix #4158
  23171. var originalScale = this._originalScale;
  23172. var originalExtent = originalScale.getExtent();
  23173. originalScale.__fixMin && (extent[0] = fixRoundingError(extent[0], originalExtent[0]));
  23174. originalScale.__fixMax && (extent[1] = fixRoundingError(extent[1], originalExtent[1]));
  23175. return extent;
  23176. },
  23177. /**
  23178. * @param {Array.<number>} extent
  23179. */
  23180. unionExtent: function (extent) {
  23181. this._originalScale.unionExtent(extent);
  23182. var base = this.base;
  23183. extent[0] = mathLog(extent[0]) / mathLog(base);
  23184. extent[1] = mathLog(extent[1]) / mathLog(base);
  23185. scaleProto.unionExtent.call(this, extent);
  23186. },
  23187. /**
  23188. * @override
  23189. */
  23190. unionExtentFromData: function (data, dim) {
  23191. this.unionExtent(data.getDataExtent(dim, true, function (val) {
  23192. return val > 0;
  23193. }));
  23194. },
  23195. /**
  23196. * Update interval and extent of intervals for nice ticks
  23197. * @param {number} [approxTickNum = 10] Given approx tick number
  23198. */
  23199. niceTicks: function (approxTickNum) {
  23200. approxTickNum = approxTickNum || 10;
  23201. var extent = this._extent;
  23202. var span = extent[1] - extent[0];
  23203. if (span === Infinity || span <= 0) {
  23204. return;
  23205. }
  23206. var interval = numberUtil.quantity(span);
  23207. var err = approxTickNum / span * interval;
  23208. // Filter ticks to get closer to the desired count.
  23209. if (err <= 0.5) {
  23210. interval *= 10;
  23211. }
  23212. // Interval should be integer
  23213. while (!isNaN(interval) && Math.abs(interval) < 1 && Math.abs(interval) > 0) {
  23214. interval *= 10;
  23215. }
  23216. var niceExtent = [
  23217. numberUtil.round(mathCeil(extent[0] / interval) * interval),
  23218. numberUtil.round(mathFloor(extent[1] / interval) * interval)
  23219. ];
  23220. this._interval = interval;
  23221. this._niceExtent = niceExtent;
  23222. },
  23223. /**
  23224. * Nice extent.
  23225. * @param {number} [approxTickNum = 10] Given approx tick number
  23226. * @param {boolean} [fixMin=false]
  23227. * @param {boolean} [fixMax=false]
  23228. */
  23229. niceExtent: function (splitNumber, fixMin, fixMax) {
  23230. intervalScaleProto.niceExtent.call(this, splitNumber, fixMin, fixMax);
  23231. var originalScale = this._originalScale;
  23232. originalScale.__fixMin = fixMin;
  23233. originalScale.__fixMax = fixMax;
  23234. }
  23235. });
  23236. zrUtil.each(['contain', 'normalize'], function (methodName) {
  23237. LogScale.prototype[methodName] = function (val) {
  23238. val = mathLog(val) / mathLog(this.base);
  23239. return scaleProto[methodName].call(this, val);
  23240. };
  23241. });
  23242. LogScale.create = function () {
  23243. return new LogScale();
  23244. };
  23245. function fixRoundingError(val, originalVal) {
  23246. return roundingErrorFix(val, getPrecisionSafe(originalVal));
  23247. }
  23248. module.exports = LogScale;
  23249. /***/ },
  23250. /* 121 */
  23251. /***/ function(module, exports, __webpack_require__) {
  23252. 'use strict';
  23253. var zrUtil = __webpack_require__(4);
  23254. var Cartesian = __webpack_require__(122);
  23255. function Cartesian2D(name) {
  23256. Cartesian.call(this, name);
  23257. }
  23258. Cartesian2D.prototype = {
  23259. constructor: Cartesian2D,
  23260. type: 'cartesian2d',
  23261. /**
  23262. * @type {Array.<string>}
  23263. * @readOnly
  23264. */
  23265. dimensions: ['x', 'y'],
  23266. /**
  23267. * Base axis will be used on stacking.
  23268. *
  23269. * @return {module:echarts/coord/cartesian/Axis2D}
  23270. */
  23271. getBaseAxis: function () {
  23272. return this.getAxesByScale('ordinal')[0]
  23273. || this.getAxesByScale('time')[0]
  23274. || this.getAxis('x');
  23275. },
  23276. /**
  23277. * If contain point
  23278. * @param {Array.<number>} point
  23279. * @return {boolean}
  23280. */
  23281. containPoint: function (point) {
  23282. var axisX = this.getAxis('x');
  23283. var axisY = this.getAxis('y');
  23284. return axisX.contain(axisX.toLocalCoord(point[0]))
  23285. && axisY.contain(axisY.toLocalCoord(point[1]));
  23286. },
  23287. /**
  23288. * If contain data
  23289. * @param {Array.<number>} data
  23290. * @return {boolean}
  23291. */
  23292. containData: function (data) {
  23293. return this.getAxis('x').containData(data[0])
  23294. && this.getAxis('y').containData(data[1]);
  23295. },
  23296. /**
  23297. * Convert series data to an array of points
  23298. * @param {module:echarts/data/List} data
  23299. * @param {boolean} stack
  23300. * @return {Array}
  23301. * Return array of points. For example:
  23302. * `[[10, 10], [20, 20], [30, 30]]`
  23303. */
  23304. dataToPoints: function (data, stack) {
  23305. return data.mapArray(['x', 'y'], function (x, y) {
  23306. return this.dataToPoint([x, y]);
  23307. }, stack, this);
  23308. },
  23309. /**
  23310. * @param {Array.<number>} data
  23311. * @param {boolean} [clamp=false]
  23312. * @return {Array.<number>}
  23313. */
  23314. dataToPoint: function (data, clamp) {
  23315. var xAxis = this.getAxis('x');
  23316. var yAxis = this.getAxis('y');
  23317. return [
  23318. xAxis.toGlobalCoord(xAxis.dataToCoord(data[0], clamp)),
  23319. yAxis.toGlobalCoord(yAxis.dataToCoord(data[1], clamp))
  23320. ];
  23321. },
  23322. /**
  23323. * @param {Array.<number>} point
  23324. * @param {boolean} [clamp=false]
  23325. * @return {Array.<number>}
  23326. */
  23327. pointToData: function (point, clamp) {
  23328. var xAxis = this.getAxis('x');
  23329. var yAxis = this.getAxis('y');
  23330. return [
  23331. xAxis.coordToData(xAxis.toLocalCoord(point[0]), clamp),
  23332. yAxis.coordToData(yAxis.toLocalCoord(point[1]), clamp)
  23333. ];
  23334. },
  23335. /**
  23336. * Get other axis
  23337. * @param {module:echarts/coord/cartesian/Axis2D} axis
  23338. */
  23339. getOtherAxis: function (axis) {
  23340. return this.getAxis(axis.dim === 'x' ? 'y' : 'x');
  23341. }
  23342. };
  23343. zrUtil.inherits(Cartesian2D, Cartesian);
  23344. module.exports = Cartesian2D;
  23345. /***/ },
  23346. /* 122 */
  23347. /***/ function(module, exports, __webpack_require__) {
  23348. 'use strict';
  23349. /**
  23350. * Cartesian coordinate system
  23351. * @module echarts/coord/Cartesian
  23352. *
  23353. */
  23354. var zrUtil = __webpack_require__(4);
  23355. function dimAxisMapper(dim) {
  23356. return this._axes[dim];
  23357. }
  23358. /**
  23359. * @alias module:echarts/coord/Cartesian
  23360. * @constructor
  23361. */
  23362. var Cartesian = function (name) {
  23363. this._axes = {};
  23364. this._dimList = [];
  23365. /**
  23366. * @type {string}
  23367. */
  23368. this.name = name || '';
  23369. };
  23370. Cartesian.prototype = {
  23371. constructor: Cartesian,
  23372. type: 'cartesian',
  23373. /**
  23374. * Get axis
  23375. * @param {number|string} dim
  23376. * @return {module:echarts/coord/Cartesian~Axis}
  23377. */
  23378. getAxis: function (dim) {
  23379. return this._axes[dim];
  23380. },
  23381. /**
  23382. * Get axes list
  23383. * @return {Array.<module:echarts/coord/Cartesian~Axis>}
  23384. */
  23385. getAxes: function () {
  23386. return zrUtil.map(this._dimList, dimAxisMapper, this);
  23387. },
  23388. /**
  23389. * Get axes list by given scale type
  23390. */
  23391. getAxesByScale: function (scaleType) {
  23392. scaleType = scaleType.toLowerCase();
  23393. return zrUtil.filter(
  23394. this.getAxes(),
  23395. function (axis) {
  23396. return axis.scale.type === scaleType;
  23397. }
  23398. );
  23399. },
  23400. /**
  23401. * Add axis
  23402. * @param {module:echarts/coord/Cartesian.Axis}
  23403. */
  23404. addAxis: function (axis) {
  23405. var dim = axis.dim;
  23406. this._axes[dim] = axis;
  23407. this._dimList.push(dim);
  23408. },
  23409. /**
  23410. * Convert data to coord in nd space
  23411. * @param {Array.<number>|Object.<string, number>} val
  23412. * @return {Array.<number>|Object.<string, number>}
  23413. */
  23414. dataToCoord: function (val) {
  23415. return this._dataCoordConvert(val, 'dataToCoord');
  23416. },
  23417. /**
  23418. * Convert coord in nd space to data
  23419. * @param {Array.<number>|Object.<string, number>} val
  23420. * @return {Array.<number>|Object.<string, number>}
  23421. */
  23422. coordToData: function (val) {
  23423. return this._dataCoordConvert(val, 'coordToData');
  23424. },
  23425. _dataCoordConvert: function (input, method) {
  23426. var dimList = this._dimList;
  23427. var output = input instanceof Array ? [] : {};
  23428. for (var i = 0; i < dimList.length; i++) {
  23429. var dim = dimList[i];
  23430. var axis = this._axes[dim];
  23431. output[dim] = axis[method](input[dim]);
  23432. }
  23433. return output;
  23434. }
  23435. };
  23436. module.exports = Cartesian;
  23437. /***/ },
  23438. /* 123 */
  23439. /***/ function(module, exports, __webpack_require__) {
  23440. var zrUtil = __webpack_require__(4);
  23441. var Axis = __webpack_require__(124);
  23442. var axisLabelInterval = __webpack_require__(125);
  23443. /**
  23444. * Extend axis 2d
  23445. * @constructor module:echarts/coord/cartesian/Axis2D
  23446. * @extends {module:echarts/coord/cartesian/Axis}
  23447. * @param {string} dim
  23448. * @param {*} scale
  23449. * @param {Array.<number>} coordExtent
  23450. * @param {string} axisType
  23451. * @param {string} position
  23452. */
  23453. var Axis2D = function (dim, scale, coordExtent, axisType, position) {
  23454. Axis.call(this, dim, scale, coordExtent);
  23455. /**
  23456. * Axis type
  23457. * - 'category'
  23458. * - 'value'
  23459. * - 'time'
  23460. * - 'log'
  23461. * @type {string}
  23462. */
  23463. this.type = axisType || 'value';
  23464. /**
  23465. * Axis position
  23466. * - 'top'
  23467. * - 'bottom'
  23468. * - 'left'
  23469. * - 'right'
  23470. */
  23471. this.position = position || 'bottom';
  23472. };
  23473. Axis2D.prototype = {
  23474. constructor: Axis2D,
  23475. /**
  23476. * Index of axis, can be used as key
  23477. */
  23478. index: 0,
  23479. /**
  23480. * If axis is on the zero position of the other axis
  23481. * @type {boolean}
  23482. */
  23483. onZero: false,
  23484. /**
  23485. * Axis model
  23486. * @param {module:echarts/coord/cartesian/AxisModel}
  23487. */
  23488. model: null,
  23489. isHorizontal: function () {
  23490. var position = this.position;
  23491. return position === 'top' || position === 'bottom';
  23492. },
  23493. getGlobalExtent: function () {
  23494. var ret = this.getExtent();
  23495. ret[0] = this.toGlobalCoord(ret[0]);
  23496. ret[1] = this.toGlobalCoord(ret[1]);
  23497. return ret;
  23498. },
  23499. /**
  23500. * @return {number}
  23501. */
  23502. getLabelInterval: function () {
  23503. var labelInterval = this._labelInterval;
  23504. if (!labelInterval) {
  23505. labelInterval = this._labelInterval = axisLabelInterval(this);
  23506. }
  23507. return labelInterval;
  23508. },
  23509. /**
  23510. * If label is ignored.
  23511. * Automatically used when axis is category and label can not be all shown
  23512. * @param {number} idx
  23513. * @return {boolean}
  23514. */
  23515. isLabelIgnored: function (idx) {
  23516. if (this.type === 'category') {
  23517. var labelInterval = this.getLabelInterval();
  23518. return ((typeof labelInterval === 'function')
  23519. && !labelInterval(idx, this.scale.getLabel(idx)))
  23520. || idx % (labelInterval + 1);
  23521. }
  23522. },
  23523. /**
  23524. * Transform global coord to local coord,
  23525. * i.e. var localCoord = axis.toLocalCoord(80);
  23526. * designate by module:echarts/coord/cartesian/Grid.
  23527. * @type {Function}
  23528. */
  23529. toLocalCoord: null,
  23530. /**
  23531. * Transform global coord to local coord,
  23532. * i.e. var globalCoord = axis.toLocalCoord(40);
  23533. * designate by module:echarts/coord/cartesian/Grid.
  23534. * @type {Function}
  23535. */
  23536. toGlobalCoord: null
  23537. };
  23538. zrUtil.inherits(Axis2D, Axis);
  23539. module.exports = Axis2D;
  23540. /***/ },
  23541. /* 124 */
  23542. /***/ function(module, exports, __webpack_require__) {
  23543. var numberUtil = __webpack_require__(7);
  23544. var linearMap = numberUtil.linearMap;
  23545. var zrUtil = __webpack_require__(4);
  23546. function fixExtentWithBands(extent, nTick) {
  23547. var size = extent[1] - extent[0];
  23548. var len = nTick;
  23549. var margin = size / len / 2;
  23550. extent[0] += margin;
  23551. extent[1] -= margin;
  23552. }
  23553. var normalizedExtent = [0, 1];
  23554. /**
  23555. * @name module:echarts/coord/CartesianAxis
  23556. * @constructor
  23557. */
  23558. var Axis = function (dim, scale, extent) {
  23559. /**
  23560. * Axis dimension. Such as 'x', 'y', 'z', 'angle', 'radius'
  23561. * @type {string}
  23562. */
  23563. this.dim = dim;
  23564. /**
  23565. * Axis scale
  23566. * @type {module:echarts/coord/scale/*}
  23567. */
  23568. this.scale = scale;
  23569. /**
  23570. * @type {Array.<number>}
  23571. * @private
  23572. */
  23573. this._extent = extent || [0, 0];
  23574. /**
  23575. * @type {boolean}
  23576. */
  23577. this.inverse = false;
  23578. /**
  23579. * Usually true when axis has a ordinal scale
  23580. * @type {boolean}
  23581. */
  23582. this.onBand = false;
  23583. };
  23584. Axis.prototype = {
  23585. constructor: Axis,
  23586. /**
  23587. * If axis extent contain given coord
  23588. * @param {number} coord
  23589. * @return {boolean}
  23590. */
  23591. contain: function (coord) {
  23592. var extent = this._extent;
  23593. var min = Math.min(extent[0], extent[1]);
  23594. var max = Math.max(extent[0], extent[1]);
  23595. return coord >= min && coord <= max;
  23596. },
  23597. /**
  23598. * If axis extent contain given data
  23599. * @param {number} data
  23600. * @return {boolean}
  23601. */
  23602. containData: function (data) {
  23603. return this.contain(this.dataToCoord(data));
  23604. },
  23605. /**
  23606. * Get coord extent.
  23607. * @return {Array.<number>}
  23608. */
  23609. getExtent: function () {
  23610. var ret = this._extent.slice();
  23611. return ret;
  23612. },
  23613. /**
  23614. * Get precision used for formatting
  23615. * @param {Array.<number>} [dataExtent]
  23616. * @return {number}
  23617. */
  23618. getPixelPrecision: function (dataExtent) {
  23619. return numberUtil.getPixelPrecision(
  23620. dataExtent || this.scale.getExtent(),
  23621. this._extent
  23622. );
  23623. },
  23624. /**
  23625. * Set coord extent
  23626. * @param {number} start
  23627. * @param {number} end
  23628. */
  23629. setExtent: function (start, end) {
  23630. var extent = this._extent;
  23631. extent[0] = start;
  23632. extent[1] = end;
  23633. },
  23634. /**
  23635. * Convert data to coord. Data is the rank if it has a ordinal scale
  23636. * @param {number} data
  23637. * @param {boolean} clamp
  23638. * @return {number}
  23639. */
  23640. dataToCoord: function (data, clamp) {
  23641. var extent = this._extent;
  23642. var scale = this.scale;
  23643. data = scale.normalize(data);
  23644. if (this.onBand && scale.type === 'ordinal') {
  23645. extent = extent.slice();
  23646. fixExtentWithBands(extent, scale.count());
  23647. }
  23648. return linearMap(data, normalizedExtent, extent, clamp);
  23649. },
  23650. /**
  23651. * Convert coord to data. Data is the rank if it has a ordinal scale
  23652. * @param {number} coord
  23653. * @param {boolean} clamp
  23654. * @return {number}
  23655. */
  23656. coordToData: function (coord, clamp) {
  23657. var extent = this._extent;
  23658. var scale = this.scale;
  23659. if (this.onBand && scale.type === 'ordinal') {
  23660. extent = extent.slice();
  23661. fixExtentWithBands(extent, scale.count());
  23662. }
  23663. var t = linearMap(coord, extent, normalizedExtent, clamp);
  23664. return this.scale.scale(t);
  23665. },
  23666. /**
  23667. * @return {Array.<number>}
  23668. */
  23669. getTicksCoords: function (alignWithLabel) {
  23670. if (this.onBand && !alignWithLabel) {
  23671. var bands = this.getBands();
  23672. var coords = [];
  23673. for (var i = 0; i < bands.length; i++) {
  23674. coords.push(bands[i][0]);
  23675. }
  23676. if (bands[i - 1]) {
  23677. coords.push(bands[i - 1][1]);
  23678. }
  23679. return coords;
  23680. }
  23681. else {
  23682. return zrUtil.map(this.scale.getTicks(), this.dataToCoord, this);
  23683. }
  23684. },
  23685. /**
  23686. * Coords of labels are on the ticks or on the middle of bands
  23687. * @return {Array.<number>}
  23688. */
  23689. getLabelsCoords: function () {
  23690. return zrUtil.map(this.scale.getTicks(), this.dataToCoord, this);
  23691. },
  23692. /**
  23693. * Get bands.
  23694. *
  23695. * If axis has labels [1, 2, 3, 4]. Bands on the axis are
  23696. * |---1---|---2---|---3---|---4---|.
  23697. *
  23698. * @return {Array}
  23699. */
  23700. // FIXME Situation when labels is on ticks
  23701. getBands: function () {
  23702. var extent = this.getExtent();
  23703. var bands = [];
  23704. var len = this.scale.count();
  23705. var start = extent[0];
  23706. var end = extent[1];
  23707. var span = end - start;
  23708. for (var i = 0; i < len; i++) {
  23709. bands.push([
  23710. span * i / len + start,
  23711. span * (i + 1) / len + start
  23712. ]);
  23713. }
  23714. return bands;
  23715. },
  23716. /**
  23717. * Get width of band
  23718. * @return {number}
  23719. */
  23720. getBandWidth: function () {
  23721. var axisExtent = this._extent;
  23722. var dataExtent = this.scale.getExtent();
  23723. var len = dataExtent[1] - dataExtent[0] + (this.onBand ? 1 : 0);
  23724. // Fix #2728, avoid NaN when only one data.
  23725. len === 0 && (len = 1);
  23726. var size = Math.abs(axisExtent[1] - axisExtent[0]);
  23727. return Math.abs(size) / len;
  23728. },
  23729. /**
  23730. * When axis extent depends on data and no data exists,
  23731. * axis ticks should not be drawn, which is named 'blank'.
  23732. */
  23733. isBlank: function () {
  23734. return this._isBlank;
  23735. },
  23736. /**
  23737. * When axis extent depends on data and no data exists,
  23738. * axis ticks should not be drawn, which is named 'blank'.
  23739. */
  23740. setBlank: function (isBlank) {
  23741. this._isBlank = isBlank;
  23742. }
  23743. };
  23744. module.exports = Axis;
  23745. /***/ },
  23746. /* 125 */
  23747. /***/ function(module, exports, __webpack_require__) {
  23748. 'use strict';
  23749. /**
  23750. * Helper function for axisLabelInterval calculation
  23751. */
  23752. var zrUtil = __webpack_require__(4);
  23753. var axisHelper = __webpack_require__(115);
  23754. module.exports = function (axis) {
  23755. var axisModel = axis.model;
  23756. var labelModel = axisModel.getModel('axisLabel');
  23757. var labelInterval = labelModel.get('interval');
  23758. if (!(axis.type === 'category' && labelInterval === 'auto')) {
  23759. return labelInterval === 'auto' ? 0 : labelInterval;
  23760. }
  23761. return axisHelper.getAxisLabelInterval(
  23762. zrUtil.map(axis.scale.getTicks(), axis.dataToCoord, axis),
  23763. axisModel.getFormattedLabels(),
  23764. labelModel.getModel('textStyle').getFont(),
  23765. axis.isHorizontal()
  23766. );
  23767. };
  23768. /***/ },
  23769. /* 126 */
  23770. /***/ function(module, exports, __webpack_require__) {
  23771. 'use strict';
  23772. // Grid 是在有直角坐标系的时候必须要存在的
  23773. // 所以这里也要被 Cartesian2D 依赖
  23774. __webpack_require__(127);
  23775. var ComponentModel = __webpack_require__(19);
  23776. module.exports = ComponentModel.extend({
  23777. type: 'grid',
  23778. dependencies: ['xAxis', 'yAxis'],
  23779. layoutMode: 'box',
  23780. /**
  23781. * @type {module:echarts/coord/cartesian/Grid}
  23782. */
  23783. coordinateSystem: null,
  23784. defaultOption: {
  23785. show: false,
  23786. zlevel: 0,
  23787. z: 0,
  23788. left: '10%',
  23789. top: 60,
  23790. right: '10%',
  23791. bottom: 60,
  23792. // If grid size contain label
  23793. containLabel: false,
  23794. // width: {totalWidth} - left - right,
  23795. // height: {totalHeight} - top - bottom,
  23796. backgroundColor: 'rgba(0,0,0,0)',
  23797. borderWidth: 1,
  23798. borderColor: '#ccc'
  23799. }
  23800. });
  23801. /***/ },
  23802. /* 127 */
  23803. /***/ function(module, exports, __webpack_require__) {
  23804. 'use strict';
  23805. var ComponentModel = __webpack_require__(19);
  23806. var zrUtil = __webpack_require__(4);
  23807. var axisModelCreator = __webpack_require__(128);
  23808. var AxisModel = ComponentModel.extend({
  23809. type: 'cartesian2dAxis',
  23810. /**
  23811. * @type {module:echarts/coord/cartesian/Axis2D}
  23812. */
  23813. axis: null,
  23814. /**
  23815. * @override
  23816. */
  23817. init: function () {
  23818. AxisModel.superApply(this, 'init', arguments);
  23819. this.resetRange();
  23820. },
  23821. /**
  23822. * @override
  23823. */
  23824. mergeOption: function () {
  23825. AxisModel.superApply(this, 'mergeOption', arguments);
  23826. this.resetRange();
  23827. },
  23828. /**
  23829. * @override
  23830. */
  23831. restoreData: function () {
  23832. AxisModel.superApply(this, 'restoreData', arguments);
  23833. this.resetRange();
  23834. },
  23835. /**
  23836. * @override
  23837. * @return {module:echarts/model/Component}
  23838. */
  23839. getCoordSysModel: function () {
  23840. return this.ecModel.queryComponents({
  23841. mainType: 'grid',
  23842. index: this.option.gridIndex,
  23843. id: this.option.gridId
  23844. })[0];
  23845. }
  23846. });
  23847. function getAxisType(axisDim, option) {
  23848. // Default axis with data is category axis
  23849. return option.type || (option.data ? 'category' : 'value');
  23850. }
  23851. zrUtil.merge(AxisModel.prototype, __webpack_require__(130));
  23852. var extraOption = {
  23853. // gridIndex: 0,
  23854. // gridId: '',
  23855. // Offset is for multiple axis on the same position
  23856. offset: 0
  23857. };
  23858. axisModelCreator('x', AxisModel, getAxisType, extraOption);
  23859. axisModelCreator('y', AxisModel, getAxisType, extraOption);
  23860. module.exports = AxisModel;
  23861. /***/ },
  23862. /* 128 */
  23863. /***/ function(module, exports, __webpack_require__) {
  23864. var axisDefault = __webpack_require__(129);
  23865. var zrUtil = __webpack_require__(4);
  23866. var ComponentModel = __webpack_require__(19);
  23867. var layout = __webpack_require__(21);
  23868. // FIXME axisType is fixed ?
  23869. var AXIS_TYPES = ['value', 'category', 'time', 'log'];
  23870. /**
  23871. * Generate sub axis model class
  23872. * @param {string} axisName 'x' 'y' 'radius' 'angle' 'parallel'
  23873. * @param {module:echarts/model/Component} BaseAxisModelClass
  23874. * @param {Function} axisTypeDefaulter
  23875. * @param {Object} [extraDefaultOption]
  23876. */
  23877. module.exports = function (axisName, BaseAxisModelClass, axisTypeDefaulter, extraDefaultOption) {
  23878. zrUtil.each(AXIS_TYPES, function (axisType) {
  23879. BaseAxisModelClass.extend({
  23880. type: axisName + 'Axis.' + axisType,
  23881. mergeDefaultAndTheme: function (option, ecModel) {
  23882. var layoutMode = this.layoutMode;
  23883. var inputPositionParams = layoutMode
  23884. ? layout.getLayoutParams(option) : {};
  23885. var themeModel = ecModel.getTheme();
  23886. zrUtil.merge(option, themeModel.get(axisType + 'Axis'));
  23887. zrUtil.merge(option, this.getDefaultOption());
  23888. option.type = axisTypeDefaulter(axisName, option);
  23889. if (layoutMode) {
  23890. layout.mergeLayoutParam(option, inputPositionParams, layoutMode);
  23891. }
  23892. },
  23893. defaultOption: zrUtil.mergeAll(
  23894. [
  23895. {},
  23896. axisDefault[axisType + 'Axis'],
  23897. extraDefaultOption
  23898. ],
  23899. true
  23900. )
  23901. });
  23902. });
  23903. ComponentModel.registerSubTypeDefaulter(
  23904. axisName + 'Axis',
  23905. zrUtil.curry(axisTypeDefaulter, axisName)
  23906. );
  23907. };
  23908. /***/ },
  23909. /* 129 */
  23910. /***/ function(module, exports, __webpack_require__) {
  23911. var zrUtil = __webpack_require__(4);
  23912. var defaultOption = {
  23913. show: true,
  23914. zlevel: 0, // 一级层叠
  23915. z: 0, // 二级层叠
  23916. // 反向坐标轴
  23917. inverse: false,
  23918. // 坐标轴名字,默认为空
  23919. name: '',
  23920. // 坐标轴名字位置,支持'start' | 'middle' | 'end'
  23921. nameLocation: 'end',
  23922. // 坐标轴名字旋转,degree。
  23923. nameRotate: null, // Adapt to axis rotate, when nameLocation is 'middle'.
  23924. nameTruncate: {
  23925. maxWidth: null,
  23926. ellipsis: '...',
  23927. placeholder: '.'
  23928. },
  23929. // 坐标轴文字样式,默认取全局样式
  23930. nameTextStyle: {},
  23931. // 文字与轴线距离
  23932. nameGap: 15,
  23933. silent: false, // Default false to support tooltip.
  23934. triggerEvent: false, // Default false to avoid legacy user event listener fail.
  23935. tooltip: {
  23936. show: false
  23937. },
  23938. // 坐标轴线
  23939. axisLine: {
  23940. // 默认显示,属性show控制显示与否
  23941. show: true,
  23942. onZero: true,
  23943. // 属性lineStyle控制线条样式
  23944. lineStyle: {
  23945. color: '#333',
  23946. width: 1,
  23947. type: 'solid'
  23948. }
  23949. },
  23950. // 坐标轴小标记
  23951. axisTick: {
  23952. // 属性show控制显示与否,默认显示
  23953. show: true,
  23954. // 控制小标记是否在grid里
  23955. inside: false,
  23956. // 属性length控制线长
  23957. length: 5,
  23958. // 属性lineStyle控制线条样式
  23959. lineStyle: {
  23960. width: 1
  23961. }
  23962. },
  23963. // 坐标轴文本标签,详见axis.axisLabel
  23964. axisLabel: {
  23965. show: true,
  23966. // 控制文本标签是否在grid里
  23967. inside: false,
  23968. rotate: 0,
  23969. margin: 8,
  23970. // formatter: null,
  23971. // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  23972. textStyle: {
  23973. fontSize: 12
  23974. }
  23975. },
  23976. // 分隔线
  23977. splitLine: {
  23978. // 默认显示,属性show控制显示与否
  23979. show: true,
  23980. // 属性lineStyle(详见lineStyle)控制线条样式
  23981. lineStyle: {
  23982. color: ['#ccc'],
  23983. width: 1,
  23984. type: 'solid'
  23985. }
  23986. },
  23987. // 分隔区域
  23988. splitArea: {
  23989. // 默认不显示,属性show控制显示与否
  23990. show: false,
  23991. // 属性areaStyle(详见areaStyle)控制区域样式
  23992. areaStyle: {
  23993. color: ['rgba(250,250,250,0.3)','rgba(200,200,200,0.3)']
  23994. }
  23995. }
  23996. };
  23997. var categoryAxis = zrUtil.merge({
  23998. // 类目起始和结束两端空白策略
  23999. boundaryGap: true,
  24000. // splitArea: {
  24001. // show: false
  24002. // },
  24003. splitLine: {
  24004. show: false
  24005. },
  24006. // 坐标轴小标记
  24007. axisTick: {
  24008. // If tick is align with label when boundaryGap is true
  24009. // Default with axisTick
  24010. alignWithLabel: false,
  24011. interval: 'auto'
  24012. },
  24013. // 坐标轴文本标签,详见axis.axisLabel
  24014. axisLabel: {
  24015. interval: 'auto'
  24016. }
  24017. }, defaultOption);
  24018. var valueAxis = zrUtil.merge({
  24019. // 数值起始和结束两端空白策略
  24020. boundaryGap: [0, 0],
  24021. // 最小值, 设置成 'dataMin' 则从数据中计算最小值
  24022. // min: null,
  24023. // 最大值,设置成 'dataMax' 则从数据中计算最大值
  24024. // max: null,
  24025. // Readonly prop, specifies start value of the range when using data zoom.
  24026. // rangeStart: null
  24027. // Readonly prop, specifies end value of the range when using data zoom.
  24028. // rangeEnd: null
  24029. // 脱离0值比例,放大聚焦到最终_min,_max区间
  24030. // scale: false,
  24031. // 分割段数,默认为5
  24032. splitNumber: 5
  24033. // Minimum interval
  24034. // minInterval: null
  24035. }, defaultOption);
  24036. // FIXME
  24037. var timeAxis = zrUtil.defaults({
  24038. scale: true,
  24039. min: 'dataMin',
  24040. max: 'dataMax'
  24041. }, valueAxis);
  24042. var logAxis = zrUtil.defaults({
  24043. logBase: 10
  24044. }, valueAxis);
  24045. logAxis.scale = true;
  24046. module.exports = {
  24047. categoryAxis: categoryAxis,
  24048. valueAxis: valueAxis,
  24049. timeAxis: timeAxis,
  24050. logAxis: logAxis
  24051. };
  24052. /***/ },
  24053. /* 130 */
  24054. /***/ function(module, exports, __webpack_require__) {
  24055. var zrUtil = __webpack_require__(4);
  24056. var axisHelper = __webpack_require__(115);
  24057. function getName(obj) {
  24058. if (zrUtil.isObject(obj) && obj.value != null) {
  24059. return obj.value;
  24060. }
  24061. else {
  24062. return obj;
  24063. }
  24064. }
  24065. module.exports = {
  24066. /**
  24067. * Format labels
  24068. * @return {Array.<string>}
  24069. */
  24070. getFormattedLabels: function () {
  24071. return axisHelper.getFormattedLabels(
  24072. this.axis,
  24073. this.get('axisLabel.formatter')
  24074. );
  24075. },
  24076. /**
  24077. * Get categories
  24078. */
  24079. getCategories: function () {
  24080. return this.get('type') === 'category'
  24081. && zrUtil.map(this.get('data'), getName);
  24082. },
  24083. /**
  24084. * @param {boolean} origin
  24085. * @return {number|string} min value or 'dataMin' or null/undefined (means auto) or NaN
  24086. */
  24087. getMin: function (origin) {
  24088. var option = this.option;
  24089. var min = (!origin && option.rangeStart != null)
  24090. ? option.rangeStart : option.min;
  24091. if (min != null && min !== 'dataMin' && !zrUtil.eqNaN(min)) {
  24092. min = this.axis.scale.parse(min);
  24093. }
  24094. return min;
  24095. },
  24096. /**
  24097. * @param {boolean} origin
  24098. * @return {number|string} max value or 'dataMax' or null/undefined (means auto) or NaN
  24099. */
  24100. getMax: function (origin) {
  24101. var option = this.option;
  24102. var max = (!origin && option.rangeEnd != null)
  24103. ? option.rangeEnd : option.max;
  24104. if (max != null && max !== 'dataMax' && !zrUtil.eqNaN(max)) {
  24105. max = this.axis.scale.parse(max);
  24106. }
  24107. return max;
  24108. },
  24109. /**
  24110. * @return {boolean}
  24111. */
  24112. getNeedCrossZero: function () {
  24113. var option = this.option;
  24114. return (option.rangeStart != null || option.rangeEnd != null)
  24115. ? false : !option.scale;
  24116. },
  24117. /**
  24118. * Should be implemented by each axis model if necessary.
  24119. * @return {module:echarts/model/Component} coordinate system model
  24120. */
  24121. getCoordSysModel: zrUtil.noop,
  24122. /**
  24123. * @param {number} rangeStart Can only be finite number or null/undefined or NaN.
  24124. * @param {number} rangeEnd Can only be finite number or null/undefined or NaN.
  24125. */
  24126. setRange: function (rangeStart, rangeEnd) {
  24127. this.option.rangeStart = rangeStart;
  24128. this.option.rangeEnd = rangeEnd;
  24129. },
  24130. /**
  24131. * Reset range
  24132. */
  24133. resetRange: function () {
  24134. // rangeStart and rangeEnd is readonly.
  24135. this.option.rangeStart = this.option.rangeEnd = null;
  24136. }
  24137. };
  24138. /***/ },
  24139. /* 131 */
  24140. /***/ function(module, exports, __webpack_require__) {
  24141. 'use strict';
  24142. // TODO boundaryGap
  24143. __webpack_require__(127);
  24144. __webpack_require__(132);
  24145. /***/ },
  24146. /* 132 */
  24147. /***/ function(module, exports, __webpack_require__) {
  24148. var zrUtil = __webpack_require__(4);
  24149. var graphic = __webpack_require__(43);
  24150. var AxisBuilder = __webpack_require__(133);
  24151. var ifIgnoreOnTick = AxisBuilder.ifIgnoreOnTick;
  24152. var getInterval = AxisBuilder.getInterval;
  24153. var axisBuilderAttrs = [
  24154. 'axisLine', 'axisLabel', 'axisTick', 'axisName'
  24155. ];
  24156. var selfBuilderAttrs = [
  24157. 'splitArea', 'splitLine'
  24158. ];
  24159. // function getAlignWithLabel(model, axisModel) {
  24160. // var alignWithLabel = model.get('alignWithLabel');
  24161. // if (alignWithLabel === 'auto') {
  24162. // alignWithLabel = axisModel.get('axisTick.alignWithLabel');
  24163. // }
  24164. // return alignWithLabel;
  24165. // }
  24166. var AxisView = __webpack_require__(1).extendComponentView({
  24167. type: 'axis',
  24168. render: function (axisModel, ecModel) {
  24169. this.group.removeAll();
  24170. var oldAxisGroup = this._axisGroup;
  24171. this._axisGroup = new graphic.Group();
  24172. this.group.add(this._axisGroup);
  24173. if (!axisModel.get('show')) {
  24174. return;
  24175. }
  24176. var gridModel = axisModel.getCoordSysModel();
  24177. var layout = layoutAxis(gridModel, axisModel);
  24178. var axisBuilder = new AxisBuilder(axisModel, layout);
  24179. zrUtil.each(axisBuilderAttrs, axisBuilder.add, axisBuilder);
  24180. this._axisGroup.add(axisBuilder.getGroup());
  24181. zrUtil.each(selfBuilderAttrs, function (name) {
  24182. if (axisModel.get(name + '.show')) {
  24183. this['_' + name](axisModel, gridModel, layout.labelInterval);
  24184. }
  24185. }, this);
  24186. graphic.groupTransition(oldAxisGroup, this._axisGroup, axisModel);
  24187. },
  24188. /**
  24189. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  24190. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  24191. * @param {number|Function} labelInterval
  24192. * @private
  24193. */
  24194. _splitLine: function (axisModel, gridModel, labelInterval) {
  24195. var axis = axisModel.axis;
  24196. if (axis.isBlank()) {
  24197. return;
  24198. }
  24199. var splitLineModel = axisModel.getModel('splitLine');
  24200. var lineStyleModel = splitLineModel.getModel('lineStyle');
  24201. var lineColors = lineStyleModel.get('color');
  24202. var lineInterval = getInterval(splitLineModel, labelInterval);
  24203. lineColors = zrUtil.isArray(lineColors) ? lineColors : [lineColors];
  24204. var gridRect = gridModel.coordinateSystem.getRect();
  24205. var isHorizontal = axis.isHorizontal();
  24206. var lineCount = 0;
  24207. var ticksCoords = axis.getTicksCoords(
  24208. // splitLineModel.get('alignWithLabel')
  24209. );
  24210. var ticks = axis.scale.getTicks();
  24211. var p1 = [];
  24212. var p2 = [];
  24213. // Simple optimization
  24214. // Batching the lines if color are the same
  24215. var lineStyle = lineStyleModel.getLineStyle();
  24216. for (var i = 0; i < ticksCoords.length; i++) {
  24217. if (ifIgnoreOnTick(axis, i, lineInterval)) {
  24218. continue;
  24219. }
  24220. var tickCoord = axis.toGlobalCoord(ticksCoords[i]);
  24221. if (isHorizontal) {
  24222. p1[0] = tickCoord;
  24223. p1[1] = gridRect.y;
  24224. p2[0] = tickCoord;
  24225. p2[1] = gridRect.y + gridRect.height;
  24226. }
  24227. else {
  24228. p1[0] = gridRect.x;
  24229. p1[1] = tickCoord;
  24230. p2[0] = gridRect.x + gridRect.width;
  24231. p2[1] = tickCoord;
  24232. }
  24233. var colorIndex = (lineCount++) % lineColors.length;
  24234. this._axisGroup.add(new graphic.Line(graphic.subPixelOptimizeLine({
  24235. anid: 'line_' + ticks[i],
  24236. shape: {
  24237. x1: p1[0],
  24238. y1: p1[1],
  24239. x2: p2[0],
  24240. y2: p2[1]
  24241. },
  24242. style: zrUtil.defaults({
  24243. stroke: lineColors[colorIndex]
  24244. }, lineStyle),
  24245. silent: true
  24246. })));
  24247. }
  24248. },
  24249. /**
  24250. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  24251. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  24252. * @param {number|Function} labelInterval
  24253. * @private
  24254. */
  24255. _splitArea: function (axisModel, gridModel, labelInterval) {
  24256. var axis = axisModel.axis;
  24257. if (axis.isBlank()) {
  24258. return;
  24259. }
  24260. var splitAreaModel = axisModel.getModel('splitArea');
  24261. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  24262. var areaColors = areaStyleModel.get('color');
  24263. var gridRect = gridModel.coordinateSystem.getRect();
  24264. var ticksCoords = axis.getTicksCoords(
  24265. // splitAreaModel.get('alignWithLabel')
  24266. );
  24267. var ticks = axis.scale.getTicks();
  24268. var prevX = axis.toGlobalCoord(ticksCoords[0]);
  24269. var prevY = axis.toGlobalCoord(ticksCoords[0]);
  24270. var count = 0;
  24271. var areaInterval = getInterval(splitAreaModel, labelInterval);
  24272. var areaStyle = areaStyleModel.getAreaStyle();
  24273. areaColors = zrUtil.isArray(areaColors) ? areaColors : [areaColors];
  24274. for (var i = 1; i < ticksCoords.length; i++) {
  24275. if (ifIgnoreOnTick(axis, i, areaInterval)) {
  24276. continue;
  24277. }
  24278. var tickCoord = axis.toGlobalCoord(ticksCoords[i]);
  24279. var x;
  24280. var y;
  24281. var width;
  24282. var height;
  24283. if (axis.isHorizontal()) {
  24284. x = prevX;
  24285. y = gridRect.y;
  24286. width = tickCoord - x;
  24287. height = gridRect.height;
  24288. }
  24289. else {
  24290. x = gridRect.x;
  24291. y = prevY;
  24292. width = gridRect.width;
  24293. height = tickCoord - y;
  24294. }
  24295. var colorIndex = (count++) % areaColors.length;
  24296. this._axisGroup.add(new graphic.Rect({
  24297. anid: 'area_' + ticks[i],
  24298. shape: {
  24299. x: x,
  24300. y: y,
  24301. width: width,
  24302. height: height
  24303. },
  24304. style: zrUtil.defaults({
  24305. fill: areaColors[colorIndex]
  24306. }, areaStyle),
  24307. silent: true
  24308. }));
  24309. prevX = x + width;
  24310. prevY = y + height;
  24311. }
  24312. }
  24313. });
  24314. AxisView.extend({
  24315. type: 'xAxis'
  24316. });
  24317. AxisView.extend({
  24318. type: 'yAxis'
  24319. });
  24320. /**
  24321. * @inner
  24322. */
  24323. function layoutAxis(gridModel, axisModel) {
  24324. var grid = gridModel.coordinateSystem;
  24325. var axis = axisModel.axis;
  24326. var layout = {};
  24327. var rawAxisPosition = axis.position;
  24328. var axisPosition = axis.onZero ? 'onZero' : rawAxisPosition;
  24329. var axisDim = axis.dim;
  24330. // [left, right, top, bottom]
  24331. var rect = grid.getRect();
  24332. var rectBound = [rect.x, rect.x + rect.width, rect.y, rect.y + rect.height];
  24333. var axisOffset = axisModel.get('offset') || 0;
  24334. var posMap = {
  24335. x: { top: rectBound[2] - axisOffset, bottom: rectBound[3] + axisOffset },
  24336. y: { left: rectBound[0] - axisOffset, right: rectBound[1] + axisOffset }
  24337. };
  24338. posMap.x.onZero = Math.max(Math.min(getZero('y'), posMap.x.bottom), posMap.x.top);
  24339. posMap.y.onZero = Math.max(Math.min(getZero('x'), posMap.y.right), posMap.y.left);
  24340. function getZero(dim, val) {
  24341. var theAxis = grid.getAxis(dim);
  24342. return theAxis.toGlobalCoord(theAxis.dataToCoord(0));
  24343. }
  24344. // Axis position
  24345. layout.position = [
  24346. axisDim === 'y' ? posMap.y[axisPosition] : rectBound[0],
  24347. axisDim === 'x' ? posMap.x[axisPosition] : rectBound[3]
  24348. ];
  24349. // Axis rotation
  24350. layout.rotation = Math.PI / 2 * (axisDim === 'x' ? 0 : 1);
  24351. // Tick and label direction, x y is axisDim
  24352. var dirMap = {top: -1, bottom: 1, left: -1, right: 1};
  24353. layout.labelDirection = layout.tickDirection = layout.nameDirection = dirMap[rawAxisPosition];
  24354. if (axis.onZero) {
  24355. layout.labelOffset = posMap[axisDim][rawAxisPosition] - posMap[axisDim].onZero;
  24356. }
  24357. if (axisModel.getModel('axisTick').get('inside')) {
  24358. layout.tickDirection = -layout.tickDirection;
  24359. }
  24360. if (axisModel.getModel('axisLabel').get('inside')) {
  24361. layout.labelDirection = -layout.labelDirection;
  24362. }
  24363. // Special label rotation
  24364. var labelRotation = axisModel.getModel('axisLabel').get('rotate');
  24365. layout.labelRotation = axisPosition === 'top' ? -labelRotation : labelRotation;
  24366. // label interval when auto mode.
  24367. layout.labelInterval = axis.getLabelInterval();
  24368. // Over splitLine and splitArea
  24369. layout.z2 = 1;
  24370. return layout;
  24371. }
  24372. /***/ },
  24373. /* 133 */
  24374. /***/ function(module, exports, __webpack_require__) {
  24375. var zrUtil = __webpack_require__(4);
  24376. var formatUtil = __webpack_require__(6);
  24377. var graphic = __webpack_require__(43);
  24378. var Model = __webpack_require__(12);
  24379. var numberUtil = __webpack_require__(7);
  24380. var remRadian = numberUtil.remRadian;
  24381. var isRadianAroundZero = numberUtil.isRadianAroundZero;
  24382. var vec2 = __webpack_require__(10);
  24383. var v2ApplyTransform = vec2.applyTransform;
  24384. var retrieve = zrUtil.retrieve;
  24385. var PI = Math.PI;
  24386. function makeAxisEventDataBase(axisModel) {
  24387. var eventData = {
  24388. componentType: axisModel.mainType
  24389. };
  24390. eventData[axisModel.mainType + 'Index'] = axisModel.componentIndex;
  24391. return eventData;
  24392. }
  24393. /**
  24394. * A final axis is translated and rotated from a "standard axis".
  24395. * So opt.position and opt.rotation is required.
  24396. *
  24397. * A standard axis is and axis from [0, 0] to [0, axisExtent[1]],
  24398. * for example: (0, 0) ------------> (0, 50)
  24399. *
  24400. * nameDirection or tickDirection or labelDirection is 1 means tick
  24401. * or label is below the standard axis, whereas is -1 means above
  24402. * the standard axis. labelOffset means offset between label and axis,
  24403. * which is useful when 'onZero', where axisLabel is in the grid and
  24404. * label in outside grid.
  24405. *
  24406. * Tips: like always,
  24407. * positive rotation represents anticlockwise, and negative rotation
  24408. * represents clockwise.
  24409. * The direction of position coordinate is the same as the direction
  24410. * of screen coordinate.
  24411. *
  24412. * Do not need to consider axis 'inverse', which is auto processed by
  24413. * axis extent.
  24414. *
  24415. * @param {module:zrender/container/Group} group
  24416. * @param {Object} axisModel
  24417. * @param {Object} opt Standard axis parameters.
  24418. * @param {Array.<number>} opt.position [x, y]
  24419. * @param {number} opt.rotation by radian
  24420. * @param {number} [opt.nameDirection=1] 1 or -1 Used when nameLocation is 'middle'.
  24421. * @param {number} [opt.tickDirection=1] 1 or -1
  24422. * @param {number} [opt.labelDirection=1] 1 or -1
  24423. * @param {number} [opt.labelOffset=0] Usefull when onZero.
  24424. * @param {string} [opt.axisLabelShow] default get from axisModel.
  24425. * @param {string} [opt.axisName] default get from axisModel.
  24426. * @param {number} [opt.axisNameAvailableWidth]
  24427. * @param {number} [opt.labelRotation] by degree, default get from axisModel.
  24428. * @param {number} [opt.labelInterval] Default label interval when label
  24429. * interval from model is null or 'auto'.
  24430. * @param {number} [opt.strokeContainThreshold] Default label interval when label
  24431. */
  24432. var AxisBuilder = function (axisModel, opt) {
  24433. /**
  24434. * @readOnly
  24435. */
  24436. this.opt = opt;
  24437. /**
  24438. * @readOnly
  24439. */
  24440. this.axisModel = axisModel;
  24441. // Default value
  24442. zrUtil.defaults(
  24443. opt,
  24444. {
  24445. labelOffset: 0,
  24446. nameDirection: 1,
  24447. tickDirection: 1,
  24448. labelDirection: 1,
  24449. silent: true
  24450. }
  24451. );
  24452. /**
  24453. * @readOnly
  24454. */
  24455. this.group = new graphic.Group();
  24456. // FIXME Not use a seperate text group?
  24457. var dumbGroup = new graphic.Group({
  24458. position: opt.position.slice(),
  24459. rotation: opt.rotation
  24460. });
  24461. // this.group.add(dumbGroup);
  24462. // this._dumbGroup = dumbGroup;
  24463. dumbGroup.updateTransform();
  24464. this._transform = dumbGroup.transform;
  24465. this._dumbGroup = dumbGroup;
  24466. };
  24467. AxisBuilder.prototype = {
  24468. constructor: AxisBuilder,
  24469. hasBuilder: function (name) {
  24470. return !!builders[name];
  24471. },
  24472. add: function (name) {
  24473. builders[name].call(this);
  24474. },
  24475. getGroup: function () {
  24476. return this.group;
  24477. }
  24478. };
  24479. var builders = {
  24480. /**
  24481. * @private
  24482. */
  24483. axisLine: function () {
  24484. var opt = this.opt;
  24485. var axisModel = this.axisModel;
  24486. if (!axisModel.get('axisLine.show')) {
  24487. return;
  24488. }
  24489. var extent = this.axisModel.axis.getExtent();
  24490. var matrix = this._transform;
  24491. var pt1 = [extent[0], 0];
  24492. var pt2 = [extent[1], 0];
  24493. if (matrix) {
  24494. v2ApplyTransform(pt1, pt1, matrix);
  24495. v2ApplyTransform(pt2, pt2, matrix);
  24496. }
  24497. this.group.add(new graphic.Line(graphic.subPixelOptimizeLine({
  24498. // Id for animation
  24499. anid: 'line',
  24500. shape: {
  24501. x1: pt1[0],
  24502. y1: pt1[1],
  24503. x2: pt2[0],
  24504. y2: pt2[1]
  24505. },
  24506. style: zrUtil.extend(
  24507. {lineCap: 'round'},
  24508. axisModel.getModel('axisLine.lineStyle').getLineStyle()
  24509. ),
  24510. strokeContainThreshold: opt.strokeContainThreshold || 5,
  24511. silent: true,
  24512. z2: 1
  24513. })));
  24514. },
  24515. /**
  24516. * @private
  24517. */
  24518. axisTick: function () {
  24519. var axisModel = this.axisModel;
  24520. var axis = axisModel.axis;
  24521. if (!axisModel.get('axisTick.show') || axis.isBlank()) {
  24522. return;
  24523. }
  24524. var tickModel = axisModel.getModel('axisTick');
  24525. var opt = this.opt;
  24526. var lineStyleModel = tickModel.getModel('lineStyle');
  24527. var tickLen = tickModel.get('length');
  24528. var tickInterval = getInterval(tickModel, opt.labelInterval);
  24529. var ticksCoords = axis.getTicksCoords(tickModel.get('alignWithLabel'));
  24530. var ticks = axis.scale.getTicks();
  24531. var pt1 = [];
  24532. var pt2 = [];
  24533. var matrix = this._transform;
  24534. for (var i = 0; i < ticksCoords.length; i++) {
  24535. // Only ordinal scale support tick interval
  24536. if (ifIgnoreOnTick(axis, i, tickInterval)) {
  24537. continue;
  24538. }
  24539. var tickCoord = ticksCoords[i];
  24540. pt1[0] = tickCoord;
  24541. pt1[1] = 0;
  24542. pt2[0] = tickCoord;
  24543. pt2[1] = opt.tickDirection * tickLen;
  24544. if (matrix) {
  24545. v2ApplyTransform(pt1, pt1, matrix);
  24546. v2ApplyTransform(pt2, pt2, matrix);
  24547. }
  24548. // Tick line, Not use group transform to have better line draw
  24549. this.group.add(new graphic.Line(graphic.subPixelOptimizeLine({
  24550. // Id for animation
  24551. anid: 'tick_' + ticks[i],
  24552. shape: {
  24553. x1: pt1[0],
  24554. y1: pt1[1],
  24555. x2: pt2[0],
  24556. y2: pt2[1]
  24557. },
  24558. style: zrUtil.defaults(
  24559. lineStyleModel.getLineStyle(),
  24560. {
  24561. stroke: axisModel.get('axisLine.lineStyle.color')
  24562. }
  24563. ),
  24564. z2: 2,
  24565. silent: true
  24566. })));
  24567. }
  24568. },
  24569. /**
  24570. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  24571. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  24572. * @private
  24573. */
  24574. axisLabel: function () {
  24575. var opt = this.opt;
  24576. var axisModel = this.axisModel;
  24577. var axis = axisModel.axis;
  24578. var show = retrieve(opt.axisLabelShow, axisModel.get('axisLabel.show'));
  24579. if (!show || axis.isBlank()) {
  24580. return;
  24581. }
  24582. var labelModel = axisModel.getModel('axisLabel');
  24583. var textStyleModel = labelModel.getModel('textStyle');
  24584. var labelMargin = labelModel.get('margin');
  24585. var ticks = axis.scale.getTicks();
  24586. var labels = axisModel.getFormattedLabels();
  24587. // Special label rotate.
  24588. var labelRotation = retrieve(opt.labelRotation, labelModel.get('rotate')) || 0;
  24589. // To radian.
  24590. labelRotation = labelRotation * PI / 180;
  24591. var labelLayout = innerTextLayout(opt, labelRotation, opt.labelDirection);
  24592. var categoryData = axisModel.get('data');
  24593. var textEls = [];
  24594. var silent = isSilent(axisModel);
  24595. var triggerEvent = axisModel.get('triggerEvent');
  24596. zrUtil.each(ticks, function (tickVal, index) {
  24597. if (ifIgnoreOnTick(axis, index, opt.labelInterval)) {
  24598. return;
  24599. }
  24600. var itemTextStyleModel = textStyleModel;
  24601. if (categoryData && categoryData[tickVal] && categoryData[tickVal].textStyle) {
  24602. itemTextStyleModel = new Model(
  24603. categoryData[tickVal].textStyle, textStyleModel, axisModel.ecModel
  24604. );
  24605. }
  24606. var textColor = itemTextStyleModel.getTextColor()
  24607. || axisModel.get('axisLine.lineStyle.color');
  24608. var tickCoord = axis.dataToCoord(tickVal);
  24609. var pos = [
  24610. tickCoord,
  24611. opt.labelOffset + opt.labelDirection * labelMargin
  24612. ];
  24613. var labelBeforeFormat = axis.scale.getLabel(tickVal);
  24614. var textEl = new graphic.Text({
  24615. // Id for animation
  24616. anid: 'label_' + tickVal,
  24617. style: {
  24618. text: labels[index],
  24619. textAlign: itemTextStyleModel.get('align', true) || labelLayout.textAlign,
  24620. textVerticalAlign: itemTextStyleModel.get('baseline', true) || labelLayout.verticalAlign,
  24621. textFont: itemTextStyleModel.getFont(),
  24622. fill: typeof textColor === 'function' ? textColor(labelBeforeFormat) : textColor
  24623. },
  24624. position: pos,
  24625. rotation: labelLayout.rotation,
  24626. silent: silent,
  24627. z2: 10
  24628. });
  24629. // Pack data for mouse event
  24630. if (triggerEvent) {
  24631. textEl.eventData = makeAxisEventDataBase(axisModel);
  24632. textEl.eventData.targetType = 'axisLabel';
  24633. textEl.eventData.value = labelBeforeFormat;
  24634. }
  24635. // FIXME
  24636. this._dumbGroup.add(textEl);
  24637. textEl.updateTransform();
  24638. textEls.push(textEl);
  24639. this.group.add(textEl);
  24640. textEl.decomposeTransform();
  24641. }, this);
  24642. function isTwoLabelOverlapped(current, next) {
  24643. var firstRect = current && current.getBoundingRect().clone();
  24644. var nextRect = next && next.getBoundingRect().clone();
  24645. if (firstRect && nextRect) {
  24646. firstRect.applyTransform(current.getLocalTransform());
  24647. nextRect.applyTransform(next.getLocalTransform());
  24648. return firstRect.intersect(nextRect);
  24649. }
  24650. }
  24651. // If min or max are user set, we need to check
  24652. // If the tick on min(max) are overlap on their neighbour tick
  24653. // If they are overlapped, we need to hide the min(max) tick label
  24654. if (axisModel.getMin() != null) {
  24655. var firstLabel = textEls[0];
  24656. var nextLabel = textEls[1];
  24657. if (isTwoLabelOverlapped(firstLabel, nextLabel)) {
  24658. firstLabel.ignore = true;
  24659. }
  24660. }
  24661. if (axisModel.getMax() != null) {
  24662. var lastLabel = textEls[textEls.length - 1];
  24663. var prevLabel = textEls[textEls.length - 2];
  24664. if (isTwoLabelOverlapped(prevLabel, lastLabel)) {
  24665. lastLabel.ignore = true;
  24666. }
  24667. }
  24668. },
  24669. /**
  24670. * @private
  24671. */
  24672. axisName: function () {
  24673. var opt = this.opt;
  24674. var axisModel = this.axisModel;
  24675. var name = retrieve(opt.axisName, axisModel.get('name'));
  24676. if (!name) {
  24677. return;
  24678. }
  24679. var nameLocation = axisModel.get('nameLocation');
  24680. var nameDirection = opt.nameDirection;
  24681. var textStyleModel = axisModel.getModel('nameTextStyle');
  24682. var gap = axisModel.get('nameGap') || 0;
  24683. var extent = this.axisModel.axis.getExtent();
  24684. var gapSignal = extent[0] > extent[1] ? -1 : 1;
  24685. var pos = [
  24686. nameLocation === 'start'
  24687. ? extent[0] - gapSignal * gap
  24688. : nameLocation === 'end'
  24689. ? extent[1] + gapSignal * gap
  24690. : (extent[0] + extent[1]) / 2, // 'middle'
  24691. // Reuse labelOffset.
  24692. nameLocation === 'middle' ? opt.labelOffset + nameDirection * gap : 0
  24693. ];
  24694. var labelLayout;
  24695. var nameRotation = axisModel.get('nameRotate');
  24696. if (nameRotation != null) {
  24697. nameRotation = nameRotation * PI / 180; // To radian.
  24698. }
  24699. var axisNameAvailableWidth;
  24700. if (nameLocation === 'middle') {
  24701. labelLayout = innerTextLayout(
  24702. opt,
  24703. nameRotation != null ? nameRotation : opt.rotation, // Adapt to axis.
  24704. nameDirection
  24705. );
  24706. }
  24707. else {
  24708. labelLayout = endTextLayout(
  24709. opt, nameLocation, nameRotation || 0, extent
  24710. );
  24711. axisNameAvailableWidth = opt.axisNameAvailableWidth;
  24712. if (axisNameAvailableWidth != null) {
  24713. axisNameAvailableWidth = Math.abs(
  24714. axisNameAvailableWidth / Math.sin(labelLayout.rotation)
  24715. );
  24716. !isFinite(axisNameAvailableWidth) && (axisNameAvailableWidth = null);
  24717. }
  24718. }
  24719. var textFont = textStyleModel.getFont();
  24720. var truncateOpt = axisModel.get('nameTruncate', true) || {};
  24721. var ellipsis = truncateOpt.ellipsis;
  24722. var maxWidth = retrieve(truncateOpt.maxWidth, axisNameAvailableWidth);
  24723. var truncatedText = (ellipsis != null && maxWidth != null)
  24724. ? formatUtil.truncateText(
  24725. name, maxWidth, textFont, ellipsis,
  24726. {minChar: 2, placeholder: truncateOpt.placeholder}
  24727. )
  24728. : name;
  24729. var tooltipOpt = axisModel.get('tooltip', true);
  24730. var mainType = axisModel.mainType;
  24731. var formatterParams = {
  24732. componentType: mainType,
  24733. name: name,
  24734. $vars: ['name']
  24735. };
  24736. formatterParams[mainType + 'Index'] = axisModel.componentIndex;
  24737. var textEl = new graphic.Text({
  24738. // Id for animation
  24739. anid: 'name',
  24740. __fullText: name,
  24741. __truncatedText: truncatedText,
  24742. style: {
  24743. text: truncatedText,
  24744. textFont: textFont,
  24745. fill: textStyleModel.getTextColor()
  24746. || axisModel.get('axisLine.lineStyle.color'),
  24747. textAlign: labelLayout.textAlign,
  24748. textVerticalAlign: labelLayout.verticalAlign
  24749. },
  24750. position: pos,
  24751. rotation: labelLayout.rotation,
  24752. silent: isSilent(axisModel),
  24753. z2: 1,
  24754. tooltip: (tooltipOpt && tooltipOpt.show)
  24755. ? zrUtil.extend({
  24756. content: name,
  24757. formatter: function () {
  24758. return name;
  24759. },
  24760. formatterParams: formatterParams
  24761. }, tooltipOpt)
  24762. : null
  24763. });
  24764. if (axisModel.get('triggerEvent')) {
  24765. textEl.eventData = makeAxisEventDataBase(axisModel);
  24766. textEl.eventData.targetType = 'axisName';
  24767. textEl.eventData.name = name;
  24768. }
  24769. // FIXME
  24770. this._dumbGroup.add(textEl);
  24771. textEl.updateTransform();
  24772. this.group.add(textEl);
  24773. textEl.decomposeTransform();
  24774. }
  24775. };
  24776. /**
  24777. * @inner
  24778. */
  24779. function innerTextLayout(opt, textRotation, direction) {
  24780. var rotationDiff = remRadian(textRotation - opt.rotation);
  24781. var textAlign;
  24782. var verticalAlign;
  24783. if (isRadianAroundZero(rotationDiff)) { // Label is parallel with axis line.
  24784. verticalAlign = direction > 0 ? 'top' : 'bottom';
  24785. textAlign = 'center';
  24786. }
  24787. else if (isRadianAroundZero(rotationDiff - PI)) { // Label is inverse parallel with axis line.
  24788. verticalAlign = direction > 0 ? 'bottom' : 'top';
  24789. textAlign = 'center';
  24790. }
  24791. else {
  24792. verticalAlign = 'middle';
  24793. if (rotationDiff > 0 && rotationDiff < PI) {
  24794. textAlign = direction > 0 ? 'right' : 'left';
  24795. }
  24796. else {
  24797. textAlign = direction > 0 ? 'left' : 'right';
  24798. }
  24799. }
  24800. return {
  24801. rotation: rotationDiff,
  24802. textAlign: textAlign,
  24803. verticalAlign: verticalAlign
  24804. };
  24805. }
  24806. /**
  24807. * @inner
  24808. */
  24809. function endTextLayout(opt, textPosition, textRotate, extent) {
  24810. var rotationDiff = remRadian(textRotate - opt.rotation);
  24811. var textAlign;
  24812. var verticalAlign;
  24813. var inverse = extent[0] > extent[1];
  24814. var onLeft = (textPosition === 'start' && !inverse)
  24815. || (textPosition !== 'start' && inverse);
  24816. if (isRadianAroundZero(rotationDiff - PI / 2)) {
  24817. verticalAlign = onLeft ? 'bottom' : 'top';
  24818. textAlign = 'center';
  24819. }
  24820. else if (isRadianAroundZero(rotationDiff - PI * 1.5)) {
  24821. verticalAlign = onLeft ? 'top' : 'bottom';
  24822. textAlign = 'center';
  24823. }
  24824. else {
  24825. verticalAlign = 'middle';
  24826. if (rotationDiff < PI * 1.5 && rotationDiff > PI / 2) {
  24827. textAlign = onLeft ? 'left' : 'right';
  24828. }
  24829. else {
  24830. textAlign = onLeft ? 'right' : 'left';
  24831. }
  24832. }
  24833. return {
  24834. rotation: rotationDiff,
  24835. textAlign: textAlign,
  24836. verticalAlign: verticalAlign
  24837. };
  24838. }
  24839. /**
  24840. * @inner
  24841. */
  24842. function isSilent(axisModel) {
  24843. var tooltipOpt = axisModel.get('tooltip');
  24844. return axisModel.get('silent')
  24845. // Consider mouse cursor, add these restrictions.
  24846. || !(
  24847. axisModel.get('triggerEvent') || (tooltipOpt && tooltipOpt.show)
  24848. );
  24849. }
  24850. /**
  24851. * @static
  24852. */
  24853. var ifIgnoreOnTick = AxisBuilder.ifIgnoreOnTick = function (axis, i, interval) {
  24854. var rawTick;
  24855. var scale = axis.scale;
  24856. return scale.type === 'ordinal'
  24857. && (
  24858. typeof interval === 'function'
  24859. ? (
  24860. rawTick = scale.getTicks()[i],
  24861. !interval(rawTick, scale.getLabel(rawTick))
  24862. )
  24863. : i % (interval + 1)
  24864. );
  24865. };
  24866. /**
  24867. * @static
  24868. */
  24869. var getInterval = AxisBuilder.getInterval = function (model, labelInterval) {
  24870. var interval = model.get('interval');
  24871. if (interval == null || interval == 'auto') {
  24872. interval = labelInterval;
  24873. }
  24874. return interval;
  24875. };
  24876. module.exports = AxisBuilder;
  24877. /***/ },
  24878. /* 134 */
  24879. /***/ function(module, exports, __webpack_require__) {
  24880. var zrUtil = __webpack_require__(4);
  24881. __webpack_require__(114);
  24882. __webpack_require__(135);
  24883. __webpack_require__(137);
  24884. var barLayoutGrid = __webpack_require__(140);
  24885. var echarts = __webpack_require__(1);
  24886. echarts.registerLayout(zrUtil.curry(barLayoutGrid, 'bar'));
  24887. // Visual coding for legend
  24888. echarts.registerVisual(function (ecModel) {
  24889. ecModel.eachSeriesByType('bar', function (seriesModel) {
  24890. var data = seriesModel.getData();
  24891. data.setVisual('legendSymbol', 'roundRect');
  24892. });
  24893. });
  24894. // In case developer forget to include grid component
  24895. __webpack_require__(113);
  24896. /***/ },
  24897. /* 135 */
  24898. /***/ function(module, exports, __webpack_require__) {
  24899. module.exports = __webpack_require__(136).extend({
  24900. type: 'series.bar',
  24901. dependencies: ['grid', 'polar'],
  24902. brushSelector: 'rect'
  24903. });
  24904. /***/ },
  24905. /* 136 */
  24906. /***/ function(module, exports, __webpack_require__) {
  24907. 'use strict';
  24908. var SeriesModel = __webpack_require__(28);
  24909. var createListFromArray = __webpack_require__(102);
  24910. module.exports = SeriesModel.extend({
  24911. type: 'series.__base_bar__',
  24912. getInitialData: function (option, ecModel) {
  24913. if (true) {
  24914. var coordSys = option.coordinateSystem;
  24915. if (coordSys !== 'cartesian2d') {
  24916. throw new Error('Bar only support cartesian2d coordinateSystem');
  24917. }
  24918. }
  24919. return createListFromArray(option.data, this, ecModel);
  24920. },
  24921. getMarkerPosition: function (value) {
  24922. var coordSys = this.coordinateSystem;
  24923. if (coordSys) {
  24924. // PENDING if clamp ?
  24925. var pt = coordSys.dataToPoint(value, true);
  24926. var data = this.getData();
  24927. var offset = data.getLayout('offset');
  24928. var size = data.getLayout('size');
  24929. var offsetIndex = coordSys.getBaseAxis().isHorizontal() ? 0 : 1;
  24930. pt[offsetIndex] += offset + size / 2;
  24931. return pt;
  24932. }
  24933. return [NaN, NaN];
  24934. },
  24935. defaultOption: {
  24936. zlevel: 0, // 一级层叠
  24937. z: 2, // 二级层叠
  24938. coordinateSystem: 'cartesian2d',
  24939. legendHoverLink: true,
  24940. // stack: null
  24941. // Cartesian coordinate system
  24942. // xAxisIndex: 0,
  24943. // yAxisIndex: 0,
  24944. // 最小高度改为0
  24945. barMinHeight: 0,
  24946. // barMaxWidth: null,
  24947. // 默认自适应
  24948. // barWidth: null,
  24949. // 柱间距离,默认为柱形宽度的30%,可设固定值
  24950. // barGap: '30%',
  24951. // 类目间柱形距离,默认为类目间距的20%,可设固定值
  24952. // barCategoryGap: '20%',
  24953. // label: {
  24954. // normal: {
  24955. // show: false
  24956. // }
  24957. // },
  24958. itemStyle: {
  24959. normal: {
  24960. // color: '各异'
  24961. },
  24962. emphasis: {}
  24963. }
  24964. }
  24965. });
  24966. /***/ },
  24967. /* 137 */
  24968. /***/ function(module, exports, __webpack_require__) {
  24969. 'use strict';
  24970. var zrUtil = __webpack_require__(4);
  24971. var graphic = __webpack_require__(43);
  24972. var helper = __webpack_require__(138);
  24973. var BAR_BORDER_WIDTH_QUERY = ['itemStyle', 'normal', 'barBorderWidth'];
  24974. // FIXME
  24975. // Just for compatible with ec2.
  24976. zrUtil.extend(__webpack_require__(12).prototype, __webpack_require__(139));
  24977. var BarView = __webpack_require__(1).extendChartView({
  24978. type: 'bar',
  24979. render: function (seriesModel, ecModel, api) {
  24980. var coordinateSystemType = seriesModel.get('coordinateSystem');
  24981. if (coordinateSystemType === 'cartesian2d') {
  24982. this._renderOnCartesian(seriesModel, ecModel, api);
  24983. }
  24984. return this.group;
  24985. },
  24986. dispose: zrUtil.noop,
  24987. _renderOnCartesian: function (seriesModel, ecModel, api) {
  24988. var group = this.group;
  24989. var data = seriesModel.getData();
  24990. var oldData = this._data;
  24991. var cartesian = seriesModel.coordinateSystem;
  24992. var baseAxis = cartesian.getBaseAxis();
  24993. var isHorizontal = baseAxis.isHorizontal();
  24994. var animationModel = seriesModel.isAnimationEnabled() ? seriesModel : null;
  24995. data.diff(oldData)
  24996. .add(function (dataIndex) {
  24997. if (!data.hasValue(dataIndex)) {
  24998. return;
  24999. }
  25000. var itemModel = data.getItemModel(dataIndex);
  25001. var layout = getRectItemLayout(data, dataIndex, itemModel);
  25002. var el = createRect(data, dataIndex, itemModel, layout, isHorizontal, animationModel);
  25003. data.setItemGraphicEl(dataIndex, el);
  25004. group.add(el);
  25005. updateStyle(el, data, dataIndex, itemModel, layout, seriesModel, isHorizontal);
  25006. })
  25007. .update(function (newIndex, oldIndex) {
  25008. var el = oldData.getItemGraphicEl(oldIndex);
  25009. if (!data.hasValue(newIndex)) {
  25010. group.remove(el);
  25011. return;
  25012. }
  25013. var itemModel = data.getItemModel(newIndex);
  25014. var layout = getRectItemLayout(data, newIndex, itemModel);
  25015. if (el) {
  25016. graphic.updateProps(el, {shape: layout}, animationModel, newIndex);
  25017. }
  25018. else {
  25019. el = createRect(data, newIndex, itemModel, layout, isHorizontal, animationModel, true);
  25020. }
  25021. data.setItemGraphicEl(newIndex, el);
  25022. // Add back
  25023. group.add(el);
  25024. updateStyle(el, data, newIndex, itemModel, layout, seriesModel, isHorizontal);
  25025. })
  25026. .remove(function (dataIndex) {
  25027. var el = oldData.getItemGraphicEl(dataIndex);
  25028. el && removeRect(dataIndex, animationModel, el);
  25029. })
  25030. .execute();
  25031. this._data = data;
  25032. },
  25033. remove: function (ecModel, api) {
  25034. var group = this.group;
  25035. var data = this._data;
  25036. if (ecModel.get('animation')) {
  25037. if (data) {
  25038. data.eachItemGraphicEl(function (el) {
  25039. removeRect(el.dataIndex, ecModel, el);
  25040. });
  25041. }
  25042. }
  25043. else {
  25044. group.removeAll();
  25045. }
  25046. }
  25047. });
  25048. function createRect(data, dataIndex, itemModel, layout, isHorizontal, animationModel, isUpdate) {
  25049. var rect = new graphic.Rect({shape: zrUtil.extend({}, layout)});
  25050. // Animation
  25051. if (animationModel) {
  25052. var rectShape = rect.shape;
  25053. var animateProperty = isHorizontal ? 'height' : 'width';
  25054. var animateTarget = {};
  25055. rectShape[animateProperty] = 0;
  25056. animateTarget[animateProperty] = layout[animateProperty];
  25057. graphic[isUpdate ? 'updateProps' : 'initProps'](rect, {
  25058. shape: animateTarget
  25059. }, animationModel, dataIndex);
  25060. }
  25061. return rect;
  25062. }
  25063. function removeRect(dataIndex, animationModel, el) {
  25064. // Not show text when animating
  25065. el.style.text = '';
  25066. graphic.updateProps(el, {
  25067. shape: {
  25068. width: 0
  25069. }
  25070. }, animationModel, dataIndex, function () {
  25071. el.parent && el.parent.remove(el);
  25072. });
  25073. }
  25074. function getRectItemLayout(data, dataIndex, itemModel) {
  25075. var layout = data.getItemLayout(dataIndex);
  25076. var fixedLineWidth = getLineWidth(itemModel, layout);
  25077. // fix layout with lineWidth
  25078. var signX = layout.width > 0 ? 1 : -1;
  25079. var signY = layout.height > 0 ? 1 : -1;
  25080. return {
  25081. x: layout.x + signX * fixedLineWidth / 2,
  25082. y: layout.y + signY * fixedLineWidth / 2,
  25083. width: layout.width - signX * fixedLineWidth,
  25084. height: layout.height - signY * fixedLineWidth
  25085. };
  25086. }
  25087. function updateStyle(el, data, dataIndex, itemModel, layout, seriesModel, isHorizontal) {
  25088. var color = data.getItemVisual(dataIndex, 'color');
  25089. var opacity = data.getItemVisual(dataIndex, 'opacity');
  25090. var itemStyleModel = itemModel.getModel('itemStyle.normal');
  25091. var hoverStyle = itemModel.getModel('itemStyle.emphasis').getBarItemStyle();
  25092. el.setShape('r', itemStyleModel.get('barBorderRadius') || 0);
  25093. el.useStyle(zrUtil.defaults(
  25094. {
  25095. fill: color,
  25096. opacity: opacity
  25097. },
  25098. itemStyleModel.getBarItemStyle()
  25099. ));
  25100. var labelPositionOutside = isHorizontal
  25101. ? (layout.height > 0 ? 'bottom' : 'top')
  25102. : (layout.width > 0 ? 'left' : 'right');
  25103. helper.setLabel(
  25104. el.style, hoverStyle, itemModel, color,
  25105. seriesModel, dataIndex, labelPositionOutside
  25106. );
  25107. graphic.setHoverStyle(el, hoverStyle);
  25108. }
  25109. // In case width or height are too small.
  25110. function getLineWidth(itemModel, rawLayout) {
  25111. var lineWidth = itemModel.get(BAR_BORDER_WIDTH_QUERY) || 0;
  25112. return Math.min(lineWidth, Math.abs(rawLayout.width), Math.abs(rawLayout.height));
  25113. }
  25114. module.exports = BarView;
  25115. /***/ },
  25116. /* 138 */
  25117. /***/ function(module, exports, __webpack_require__) {
  25118. var zrUtil = __webpack_require__(4);
  25119. var graphic = __webpack_require__(43);
  25120. var helper = {};
  25121. helper.setLabel = function (
  25122. normalStyle, hoverStyle, itemModel, color, seriesModel, dataIndex, labelPositionOutside
  25123. ) {
  25124. var labelModel = itemModel.getModel('label.normal');
  25125. var hoverLabelModel = itemModel.getModel('label.emphasis');
  25126. if (labelModel.get('show')) {
  25127. setLabel(
  25128. normalStyle, labelModel, color,
  25129. zrUtil.retrieve(
  25130. seriesModel.getFormattedLabel(dataIndex, 'normal'),
  25131. seriesModel.getRawValue(dataIndex)
  25132. ),
  25133. labelPositionOutside
  25134. );
  25135. }
  25136. else {
  25137. normalStyle.text = '';
  25138. }
  25139. if (hoverLabelModel.get('show')) {
  25140. setLabel(
  25141. hoverStyle, hoverLabelModel, color,
  25142. zrUtil.retrieve(
  25143. seriesModel.getFormattedLabel(dataIndex, 'emphasis'),
  25144. seriesModel.getRawValue(dataIndex)
  25145. ),
  25146. labelPositionOutside
  25147. );
  25148. }
  25149. else {
  25150. hoverStyle.text = '';
  25151. }
  25152. };
  25153. function setLabel(style, model, color, labelText, labelPositionOutside) {
  25154. graphic.setText(style, model, color);
  25155. style.text = labelText;
  25156. if (style.textPosition === 'outside') {
  25157. style.textPosition = labelPositionOutside;
  25158. }
  25159. }
  25160. module.exports = helper;
  25161. /***/ },
  25162. /* 139 */
  25163. /***/ function(module, exports, __webpack_require__) {
  25164. var getBarItemStyle = __webpack_require__(15)(
  25165. [
  25166. ['fill', 'color'],
  25167. ['stroke', 'borderColor'],
  25168. ['lineWidth', 'borderWidth'],
  25169. // Compatitable with 2
  25170. ['stroke', 'barBorderColor'],
  25171. ['lineWidth', 'barBorderWidth'],
  25172. ['opacity'],
  25173. ['shadowBlur'],
  25174. ['shadowOffsetX'],
  25175. ['shadowOffsetY'],
  25176. ['shadowColor']
  25177. ]
  25178. );
  25179. module.exports = {
  25180. getBarItemStyle: function (excludes) {
  25181. var style = getBarItemStyle.call(this, excludes);
  25182. if (this.getBorderLineDash) {
  25183. var lineDash = this.getBorderLineDash();
  25184. lineDash && (style.lineDash = lineDash);
  25185. }
  25186. return style;
  25187. }
  25188. };
  25189. /***/ },
  25190. /* 140 */
  25191. /***/ function(module, exports, __webpack_require__) {
  25192. 'use strict';
  25193. var zrUtil = __webpack_require__(4);
  25194. var numberUtil = __webpack_require__(7);
  25195. var parsePercent = numberUtil.parsePercent;
  25196. function getSeriesStackId(seriesModel) {
  25197. return seriesModel.get('stack') || '__ec_stack_' + seriesModel.seriesIndex;
  25198. }
  25199. function getAxisKey(axis) {
  25200. return axis.dim + axis.index;
  25201. }
  25202. function calBarWidthAndOffset(barSeries, api) {
  25203. // Columns info on each category axis. Key is cartesian name
  25204. var columnsMap = {};
  25205. zrUtil.each(barSeries, function (seriesModel, idx) {
  25206. var data = seriesModel.getData();
  25207. var cartesian = seriesModel.coordinateSystem;
  25208. var baseAxis = cartesian.getBaseAxis();
  25209. var axisExtent = baseAxis.getExtent();
  25210. var bandWidth = baseAxis.type === 'category'
  25211. ? baseAxis.getBandWidth()
  25212. : (Math.abs(axisExtent[1] - axisExtent[0]) / data.count());
  25213. var columnsOnAxis = columnsMap[getAxisKey(baseAxis)] || {
  25214. bandWidth: bandWidth,
  25215. remainedWidth: bandWidth,
  25216. autoWidthCount: 0,
  25217. categoryGap: '20%',
  25218. gap: '30%',
  25219. stacks: {}
  25220. };
  25221. var stacks = columnsOnAxis.stacks;
  25222. columnsMap[getAxisKey(baseAxis)] = columnsOnAxis;
  25223. var stackId = getSeriesStackId(seriesModel);
  25224. if (!stacks[stackId]) {
  25225. columnsOnAxis.autoWidthCount++;
  25226. }
  25227. stacks[stackId] = stacks[stackId] || {
  25228. width: 0,
  25229. maxWidth: 0
  25230. };
  25231. var barWidth = parsePercent(
  25232. seriesModel.get('barWidth'), bandWidth
  25233. );
  25234. var barMaxWidth = parsePercent(
  25235. seriesModel.get('barMaxWidth'), bandWidth
  25236. );
  25237. var barGap = seriesModel.get('barGap');
  25238. var barCategoryGap = seriesModel.get('barCategoryGap');
  25239. // Caution: In a single coordinate system, these barGrid attributes
  25240. // will be shared by series. Consider that they have default values,
  25241. // only the attributes set on the last series will work.
  25242. // Do not change this fact unless there will be a break change.
  25243. // TODO
  25244. if (barWidth && !stacks[stackId].width) {
  25245. barWidth = Math.min(columnsOnAxis.remainedWidth, barWidth);
  25246. stacks[stackId].width = barWidth;
  25247. columnsOnAxis.remainedWidth -= barWidth;
  25248. }
  25249. barMaxWidth && (stacks[stackId].maxWidth = barMaxWidth);
  25250. (barGap != null) && (columnsOnAxis.gap = barGap);
  25251. (barCategoryGap != null) && (columnsOnAxis.categoryGap = barCategoryGap);
  25252. });
  25253. var result = {};
  25254. zrUtil.each(columnsMap, function (columnsOnAxis, coordSysName) {
  25255. result[coordSysName] = {};
  25256. var stacks = columnsOnAxis.stacks;
  25257. var bandWidth = columnsOnAxis.bandWidth;
  25258. var categoryGap = parsePercent(columnsOnAxis.categoryGap, bandWidth);
  25259. var barGapPercent = parsePercent(columnsOnAxis.gap, 1);
  25260. var remainedWidth = columnsOnAxis.remainedWidth;
  25261. var autoWidthCount = columnsOnAxis.autoWidthCount;
  25262. var autoWidth = (remainedWidth - categoryGap)
  25263. / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  25264. autoWidth = Math.max(autoWidth, 0);
  25265. // Find if any auto calculated bar exceeded maxBarWidth
  25266. zrUtil.each(stacks, function (column, stack) {
  25267. var maxWidth = column.maxWidth;
  25268. if (!column.width && maxWidth && maxWidth < autoWidth) {
  25269. maxWidth = Math.min(maxWidth, remainedWidth);
  25270. remainedWidth -= maxWidth;
  25271. column.width = maxWidth;
  25272. autoWidthCount--;
  25273. }
  25274. });
  25275. // Recalculate width again
  25276. autoWidth = (remainedWidth - categoryGap)
  25277. / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  25278. autoWidth = Math.max(autoWidth, 0);
  25279. var widthSum = 0;
  25280. var lastColumn;
  25281. zrUtil.each(stacks, function (column, idx) {
  25282. if (!column.width) {
  25283. column.width = autoWidth;
  25284. }
  25285. lastColumn = column;
  25286. widthSum += column.width * (1 + barGapPercent);
  25287. });
  25288. if (lastColumn) {
  25289. widthSum -= lastColumn.width * barGapPercent;
  25290. }
  25291. var offset = -widthSum / 2;
  25292. zrUtil.each(stacks, function (column, stackId) {
  25293. result[coordSysName][stackId] = result[coordSysName][stackId] || {
  25294. offset: offset,
  25295. width: column.width
  25296. };
  25297. offset += column.width * (1 + barGapPercent);
  25298. });
  25299. });
  25300. return result;
  25301. }
  25302. /**
  25303. * @param {string} seriesType
  25304. * @param {module:echarts/model/Global} ecModel
  25305. * @param {module:echarts/ExtensionAPI} api
  25306. */
  25307. function barLayoutGrid(seriesType, ecModel, api) {
  25308. var barWidthAndOffset = calBarWidthAndOffset(
  25309. zrUtil.filter(
  25310. ecModel.getSeriesByType(seriesType),
  25311. function (seriesModel) {
  25312. return !ecModel.isSeriesFiltered(seriesModel)
  25313. && seriesModel.coordinateSystem
  25314. && seriesModel.coordinateSystem.type === 'cartesian2d';
  25315. }
  25316. )
  25317. );
  25318. var lastStackCoords = {};
  25319. var lastStackCoordsOrigin = {};
  25320. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  25321. var data = seriesModel.getData();
  25322. var cartesian = seriesModel.coordinateSystem;
  25323. var baseAxis = cartesian.getBaseAxis();
  25324. var stackId = getSeriesStackId(seriesModel);
  25325. var columnLayoutInfo = barWidthAndOffset[getAxisKey(baseAxis)][stackId];
  25326. var columnOffset = columnLayoutInfo.offset;
  25327. var columnWidth = columnLayoutInfo.width;
  25328. var valueAxis = cartesian.getOtherAxis(baseAxis);
  25329. var barMinHeight = seriesModel.get('barMinHeight') || 0;
  25330. var valueAxisStart = baseAxis.onZero
  25331. ? valueAxis.toGlobalCoord(valueAxis.dataToCoord(0))
  25332. : valueAxis.getGlobalExtent()[0];
  25333. var coords = cartesian.dataToPoints(data, true);
  25334. lastStackCoords[stackId] = lastStackCoords[stackId] || [];
  25335. lastStackCoordsOrigin[stackId] = lastStackCoordsOrigin[stackId] || []; // Fix #4243
  25336. data.setLayout({
  25337. offset: columnOffset,
  25338. size: columnWidth
  25339. });
  25340. data.each(valueAxis.dim, function (value, idx) {
  25341. if (isNaN(value)) {
  25342. return;
  25343. }
  25344. if (!lastStackCoords[stackId][idx]) {
  25345. lastStackCoords[stackId][idx] = {
  25346. p: valueAxisStart, // Positive stack
  25347. n: valueAxisStart // Negative stack
  25348. };
  25349. lastStackCoordsOrigin[stackId][idx] = {
  25350. p: valueAxisStart, // Positive stack
  25351. n: valueAxisStart // Negative stack
  25352. };
  25353. }
  25354. var sign = value >= 0 ? 'p' : 'n';
  25355. var coord = coords[idx];
  25356. var lastCoord = lastStackCoords[stackId][idx][sign];
  25357. var lastCoordOrigin = lastStackCoordsOrigin[stackId][idx][sign];
  25358. var x;
  25359. var y;
  25360. var width;
  25361. var height;
  25362. if (valueAxis.isHorizontal()) {
  25363. x = lastCoord;
  25364. y = coord[1] + columnOffset;
  25365. width = coord[0] - lastCoordOrigin;
  25366. height = columnWidth;
  25367. lastStackCoordsOrigin[stackId][idx][sign] += width;
  25368. if (Math.abs(width) < barMinHeight) {
  25369. width = (width < 0 ? -1 : 1) * barMinHeight;
  25370. }
  25371. lastStackCoords[stackId][idx][sign] += width;
  25372. }
  25373. else {
  25374. x = coord[0] + columnOffset;
  25375. y = lastCoord;
  25376. width = columnWidth;
  25377. height = coord[1] - lastCoordOrigin;
  25378. lastStackCoordsOrigin[stackId][idx][sign] += height;
  25379. if (Math.abs(height) < barMinHeight) {
  25380. // Include zero to has a positive bar
  25381. height = (height <= 0 ? -1 : 1) * barMinHeight;
  25382. }
  25383. lastStackCoords[stackId][idx][sign] += height;
  25384. }
  25385. data.setItemLayout(idx, {
  25386. x: x,
  25387. y: y,
  25388. width: width,
  25389. height: height
  25390. });
  25391. }, true);
  25392. }, this);
  25393. }
  25394. module.exports = barLayoutGrid;
  25395. /***/ },
  25396. /* 141 */
  25397. /***/ function(module, exports, __webpack_require__) {
  25398. var zrUtil = __webpack_require__(4);
  25399. var echarts = __webpack_require__(1);
  25400. __webpack_require__(142);
  25401. __webpack_require__(144);
  25402. __webpack_require__(145)('pie', [{
  25403. type: 'pieToggleSelect',
  25404. event: 'pieselectchanged',
  25405. method: 'toggleSelected'
  25406. }, {
  25407. type: 'pieSelect',
  25408. event: 'pieselected',
  25409. method: 'select'
  25410. }, {
  25411. type: 'pieUnSelect',
  25412. event: 'pieunselected',
  25413. method: 'unSelect'
  25414. }]);
  25415. echarts.registerVisual(zrUtil.curry(__webpack_require__(146), 'pie'));
  25416. echarts.registerLayout(zrUtil.curry(
  25417. __webpack_require__(147), 'pie'
  25418. ));
  25419. echarts.registerProcessor(zrUtil.curry(__webpack_require__(149), 'pie'));
  25420. /***/ },
  25421. /* 142 */
  25422. /***/ function(module, exports, __webpack_require__) {
  25423. 'use strict';
  25424. var List = __webpack_require__(98);
  25425. var zrUtil = __webpack_require__(4);
  25426. var modelUtil = __webpack_require__(5);
  25427. var completeDimensions = __webpack_require__(103);
  25428. var dataSelectableMixin = __webpack_require__(143);
  25429. var PieSeries = __webpack_require__(1).extendSeriesModel({
  25430. type: 'series.pie',
  25431. // Overwrite
  25432. init: function (option) {
  25433. PieSeries.superApply(this, 'init', arguments);
  25434. // Enable legend selection for each data item
  25435. // Use a function instead of direct access because data reference may changed
  25436. this.legendDataProvider = function () {
  25437. return this.getRawData();
  25438. };
  25439. this.updateSelectedMap(option.data);
  25440. this._defaultLabelLine(option);
  25441. },
  25442. // Overwrite
  25443. mergeOption: function (newOption) {
  25444. PieSeries.superCall(this, 'mergeOption', newOption);
  25445. this.updateSelectedMap(this.option.data);
  25446. },
  25447. getInitialData: function (option, ecModel) {
  25448. var dimensions = completeDimensions(['value'], option.data);
  25449. var list = new List(dimensions, this);
  25450. list.initData(option.data);
  25451. return list;
  25452. },
  25453. // Overwrite
  25454. getDataParams: function (dataIndex) {
  25455. var data = this.getData();
  25456. var params = PieSeries.superCall(this, 'getDataParams', dataIndex);
  25457. var sum = data.getSum('value');
  25458. // FIXME toFixed?
  25459. //
  25460. // Percent is 0 if sum is 0
  25461. params.percent = !sum ? 0 : +(data.get('value', dataIndex) / sum * 100).toFixed(2);
  25462. params.$vars.push('percent');
  25463. return params;
  25464. },
  25465. _defaultLabelLine: function (option) {
  25466. // Extend labelLine emphasis
  25467. modelUtil.defaultEmphasis(option.labelLine, ['show']);
  25468. var labelLineNormalOpt = option.labelLine.normal;
  25469. var labelLineEmphasisOpt = option.labelLine.emphasis;
  25470. // Not show label line if `label.normal.show = false`
  25471. labelLineNormalOpt.show = labelLineNormalOpt.show
  25472. && option.label.normal.show;
  25473. labelLineEmphasisOpt.show = labelLineEmphasisOpt.show
  25474. && option.label.emphasis.show;
  25475. },
  25476. defaultOption: {
  25477. zlevel: 0,
  25478. z: 2,
  25479. legendHoverLink: true,
  25480. hoverAnimation: true,
  25481. // 默认全局居中
  25482. center: ['50%', '50%'],
  25483. radius: [0, '75%'],
  25484. // 默认顺时针
  25485. clockwise: true,
  25486. startAngle: 90,
  25487. // 最小角度改为0
  25488. minAngle: 0,
  25489. // 选中是扇区偏移量
  25490. selectedOffset: 10,
  25491. // If use strategy to avoid label overlapping
  25492. avoidLabelOverlap: true,
  25493. // 选择模式,默认关闭,可选single,multiple
  25494. // selectedMode: false,
  25495. // 南丁格尔玫瑰图模式,'radius'(半径) | 'area'(面积)
  25496. // roseType: null,
  25497. // If still show when all data zero.
  25498. stillShowZeroSum: true,
  25499. label: {
  25500. normal: {
  25501. // If rotate around circle
  25502. rotate: false,
  25503. show: true,
  25504. // 'outer', 'inside', 'center'
  25505. position: 'outer'
  25506. // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  25507. // textStyle: null // 默认使用全局文本样式,详见TEXTSTYLE
  25508. // distance: 当position为inner时有效,为label位置到圆心的距离与圆半径(环状图为内外半径和)的比例系数
  25509. },
  25510. emphasis: {}
  25511. },
  25512. // Enabled when label.normal.position is 'outer'
  25513. labelLine: {
  25514. normal: {
  25515. show: true,
  25516. // 引导线两段中的第一段长度
  25517. length: 15,
  25518. // 引导线两段中的第二段长度
  25519. length2: 15,
  25520. smooth: false,
  25521. lineStyle: {
  25522. // color: 各异,
  25523. width: 1,
  25524. type: 'solid'
  25525. }
  25526. }
  25527. },
  25528. itemStyle: {
  25529. normal: {
  25530. borderWidth: 1
  25531. },
  25532. emphasis: {}
  25533. },
  25534. // Animation type canbe expansion, scale
  25535. animationType: 'expansion',
  25536. animationEasing: 'cubicOut',
  25537. data: []
  25538. }
  25539. });
  25540. zrUtil.mixin(PieSeries, dataSelectableMixin);
  25541. module.exports = PieSeries;
  25542. /***/ },
  25543. /* 143 */
  25544. /***/ function(module, exports, __webpack_require__) {
  25545. /**
  25546. * Data selectable mixin for chart series.
  25547. * To eanble data select, option of series must have `selectedMode`.
  25548. * And each data item will use `selected` to toggle itself selected status
  25549. *
  25550. * @module echarts/chart/helper/DataSelectable
  25551. */
  25552. var zrUtil = __webpack_require__(4);
  25553. module.exports = {
  25554. updateSelectedMap: function (targetList) {
  25555. this._selectTargetMap = zrUtil.reduce(targetList || [], function (targetMap, target) {
  25556. targetMap[target.name] = target;
  25557. return targetMap;
  25558. }, {});
  25559. },
  25560. /**
  25561. * @param {string} name
  25562. */
  25563. // PENGING If selectedMode is null ?
  25564. select: function (name) {
  25565. var targetMap = this._selectTargetMap;
  25566. var target = targetMap[name];
  25567. var selectedMode = this.get('selectedMode');
  25568. if (selectedMode === 'single') {
  25569. zrUtil.each(targetMap, function (target) {
  25570. target.selected = false;
  25571. });
  25572. }
  25573. target && (target.selected = true);
  25574. },
  25575. /**
  25576. * @param {string} name
  25577. */
  25578. unSelect: function (name) {
  25579. var target = this._selectTargetMap[name];
  25580. // var selectedMode = this.get('selectedMode');
  25581. // selectedMode !== 'single' && target && (target.selected = false);
  25582. target && (target.selected = false);
  25583. },
  25584. /**
  25585. * @param {string} name
  25586. */
  25587. toggleSelected: function (name) {
  25588. var target = this._selectTargetMap[name];
  25589. if (target != null) {
  25590. this[target.selected ? 'unSelect' : 'select'](name);
  25591. return target.selected;
  25592. }
  25593. },
  25594. /**
  25595. * @param {string} name
  25596. */
  25597. isSelected: function (name) {
  25598. var target = this._selectTargetMap[name];
  25599. return target && target.selected;
  25600. }
  25601. };
  25602. /***/ },
  25603. /* 144 */
  25604. /***/ function(module, exports, __webpack_require__) {
  25605. var graphic = __webpack_require__(43);
  25606. var zrUtil = __webpack_require__(4);
  25607. /**
  25608. * @param {module:echarts/model/Series} seriesModel
  25609. * @param {boolean} hasAnimation
  25610. * @inner
  25611. */
  25612. function updateDataSelected(uid, seriesModel, hasAnimation, api) {
  25613. var data = seriesModel.getData();
  25614. var dataIndex = this.dataIndex;
  25615. var name = data.getName(dataIndex);
  25616. var selectedOffset = seriesModel.get('selectedOffset');
  25617. api.dispatchAction({
  25618. type: 'pieToggleSelect',
  25619. from: uid,
  25620. name: name,
  25621. seriesId: seriesModel.id
  25622. });
  25623. data.each(function (idx) {
  25624. toggleItemSelected(
  25625. data.getItemGraphicEl(idx),
  25626. data.getItemLayout(idx),
  25627. seriesModel.isSelected(data.getName(idx)),
  25628. selectedOffset,
  25629. hasAnimation
  25630. );
  25631. });
  25632. }
  25633. /**
  25634. * @param {module:zrender/graphic/Sector} el
  25635. * @param {Object} layout
  25636. * @param {boolean} isSelected
  25637. * @param {number} selectedOffset
  25638. * @param {boolean} hasAnimation
  25639. * @inner
  25640. */
  25641. function toggleItemSelected(el, layout, isSelected, selectedOffset, hasAnimation) {
  25642. var midAngle = (layout.startAngle + layout.endAngle) / 2;
  25643. var dx = Math.cos(midAngle);
  25644. var dy = Math.sin(midAngle);
  25645. var offset = isSelected ? selectedOffset : 0;
  25646. var position = [dx * offset, dy * offset];
  25647. hasAnimation
  25648. // animateTo will stop revious animation like update transition
  25649. ? el.animate()
  25650. .when(200, {
  25651. position: position
  25652. })
  25653. .start('bounceOut')
  25654. : el.attr('position', position);
  25655. }
  25656. /**
  25657. * Piece of pie including Sector, Label, LabelLine
  25658. * @constructor
  25659. * @extends {module:zrender/graphic/Group}
  25660. */
  25661. function PiePiece(data, idx) {
  25662. graphic.Group.call(this);
  25663. var sector = new graphic.Sector({
  25664. z2: 2
  25665. });
  25666. var polyline = new graphic.Polyline();
  25667. var text = new graphic.Text();
  25668. this.add(sector);
  25669. this.add(polyline);
  25670. this.add(text);
  25671. this.updateData(data, idx, true);
  25672. // Hover to change label and labelLine
  25673. function onEmphasis() {
  25674. polyline.ignore = polyline.hoverIgnore;
  25675. text.ignore = text.hoverIgnore;
  25676. }
  25677. function onNormal() {
  25678. polyline.ignore = polyline.normalIgnore;
  25679. text.ignore = text.normalIgnore;
  25680. }
  25681. this.on('emphasis', onEmphasis)
  25682. .on('normal', onNormal)
  25683. .on('mouseover', onEmphasis)
  25684. .on('mouseout', onNormal);
  25685. }
  25686. var piePieceProto = PiePiece.prototype;
  25687. function getLabelStyle(data, idx, state, labelModel, labelPosition) {
  25688. var textStyleModel = labelModel.getModel('textStyle');
  25689. var isLabelInside = labelPosition === 'inside' || labelPosition === 'inner';
  25690. return {
  25691. fill: textStyleModel.getTextColor()
  25692. || (isLabelInside ? '#fff' : data.getItemVisual(idx, 'color')),
  25693. opacity: data.getItemVisual(idx, 'opacity'),
  25694. textFont: textStyleModel.getFont(),
  25695. text: zrUtil.retrieve(
  25696. data.hostModel.getFormattedLabel(idx, state), data.getName(idx)
  25697. )
  25698. };
  25699. }
  25700. piePieceProto.updateData = function (data, idx, firstCreate) {
  25701. var sector = this.childAt(0);
  25702. var seriesModel = data.hostModel;
  25703. var itemModel = data.getItemModel(idx);
  25704. var layout = data.getItemLayout(idx);
  25705. var sectorShape = zrUtil.extend({}, layout);
  25706. sectorShape.label = null;
  25707. if (firstCreate) {
  25708. sector.setShape(sectorShape);
  25709. var animationType = seriesModel.getShallow('animationType');
  25710. if (animationType === 'scale') {
  25711. sector.shape.r = layout.r0;
  25712. graphic.initProps(sector, {
  25713. shape: {
  25714. r: layout.r
  25715. }
  25716. }, seriesModel, idx);
  25717. }
  25718. // Expansion
  25719. else {
  25720. sector.shape.endAngle = layout.startAngle;
  25721. graphic.updateProps(sector, {
  25722. shape: {
  25723. endAngle: layout.endAngle
  25724. }
  25725. }, seriesModel, idx);
  25726. }
  25727. }
  25728. else {
  25729. graphic.updateProps(sector, {
  25730. shape: sectorShape
  25731. }, seriesModel, idx);
  25732. }
  25733. // Update common style
  25734. var itemStyleModel = itemModel.getModel('itemStyle');
  25735. var visualColor = data.getItemVisual(idx, 'color');
  25736. sector.useStyle(
  25737. zrUtil.defaults(
  25738. {
  25739. lineJoin: 'bevel',
  25740. fill: visualColor
  25741. },
  25742. itemStyleModel.getModel('normal').getItemStyle()
  25743. )
  25744. );
  25745. sector.hoverStyle = itemStyleModel.getModel('emphasis').getItemStyle();
  25746. // Toggle selected
  25747. toggleItemSelected(
  25748. this,
  25749. data.getItemLayout(idx),
  25750. itemModel.get('selected'),
  25751. seriesModel.get('selectedOffset'),
  25752. seriesModel.get('animation')
  25753. );
  25754. function onEmphasis() {
  25755. // Sector may has animation of updating data. Force to move to the last frame
  25756. // Or it may stopped on the wrong shape
  25757. sector.stopAnimation(true);
  25758. sector.animateTo({
  25759. shape: {
  25760. r: layout.r + 10
  25761. }
  25762. }, 300, 'elasticOut');
  25763. }
  25764. function onNormal() {
  25765. sector.stopAnimation(true);
  25766. sector.animateTo({
  25767. shape: {
  25768. r: layout.r
  25769. }
  25770. }, 300, 'elasticOut');
  25771. }
  25772. sector.off('mouseover').off('mouseout').off('emphasis').off('normal');
  25773. if (itemModel.get('hoverAnimation') && seriesModel.isAnimationEnabled()) {
  25774. sector
  25775. .on('mouseover', onEmphasis)
  25776. .on('mouseout', onNormal)
  25777. .on('emphasis', onEmphasis)
  25778. .on('normal', onNormal);
  25779. }
  25780. this._updateLabel(data, idx);
  25781. graphic.setHoverStyle(this);
  25782. };
  25783. piePieceProto._updateLabel = function (data, idx) {
  25784. var labelLine = this.childAt(1);
  25785. var labelText = this.childAt(2);
  25786. var seriesModel = data.hostModel;
  25787. var itemModel = data.getItemModel(idx);
  25788. var layout = data.getItemLayout(idx);
  25789. var labelLayout = layout.label;
  25790. var visualColor = data.getItemVisual(idx, 'color');
  25791. graphic.updateProps(labelLine, {
  25792. shape: {
  25793. points: labelLayout.linePoints || [
  25794. [labelLayout.x, labelLayout.y], [labelLayout.x, labelLayout.y], [labelLayout.x, labelLayout.y]
  25795. ]
  25796. }
  25797. }, seriesModel, idx);
  25798. graphic.updateProps(labelText, {
  25799. style: {
  25800. x: labelLayout.x,
  25801. y: labelLayout.y
  25802. }
  25803. }, seriesModel, idx);
  25804. labelText.attr({
  25805. style: {
  25806. textVerticalAlign: labelLayout.verticalAlign,
  25807. textAlign: labelLayout.textAlign,
  25808. textFont: labelLayout.font
  25809. },
  25810. rotation: labelLayout.rotation,
  25811. origin: [labelLayout.x, labelLayout.y],
  25812. z2: 10
  25813. });
  25814. var labelModel = itemModel.getModel('label.normal');
  25815. var labelHoverModel = itemModel.getModel('label.emphasis');
  25816. var labelLineModel = itemModel.getModel('labelLine.normal');
  25817. var labelLineHoverModel = itemModel.getModel('labelLine.emphasis');
  25818. var labelPosition = labelModel.get('position') || labelHoverModel.get('position');
  25819. labelText.setStyle(getLabelStyle(data, idx, 'normal', labelModel, labelPosition));
  25820. labelText.ignore = labelText.normalIgnore = !labelModel.get('show');
  25821. labelText.hoverIgnore = !labelHoverModel.get('show');
  25822. labelLine.ignore = labelLine.normalIgnore = !labelLineModel.get('show');
  25823. labelLine.hoverIgnore = !labelLineHoverModel.get('show');
  25824. // Default use item visual color
  25825. labelLine.setStyle({
  25826. stroke: visualColor,
  25827. opacity: data.getItemVisual(idx, 'opacity')
  25828. });
  25829. labelLine.setStyle(labelLineModel.getModel('lineStyle').getLineStyle());
  25830. labelText.hoverStyle = getLabelStyle(data, idx, 'emphasis', labelHoverModel, labelPosition);
  25831. labelLine.hoverStyle = labelLineHoverModel.getModel('lineStyle').getLineStyle();
  25832. var smooth = labelLineModel.get('smooth');
  25833. if (smooth && smooth === true) {
  25834. smooth = 0.4;
  25835. }
  25836. labelLine.setShape({
  25837. smooth: smooth
  25838. });
  25839. };
  25840. zrUtil.inherits(PiePiece, graphic.Group);
  25841. // Pie view
  25842. var Pie = __webpack_require__(42).extend({
  25843. type: 'pie',
  25844. init: function () {
  25845. var sectorGroup = new graphic.Group();
  25846. this._sectorGroup = sectorGroup;
  25847. },
  25848. render: function (seriesModel, ecModel, api, payload) {
  25849. if (payload && (payload.from === this.uid)) {
  25850. return;
  25851. }
  25852. var data = seriesModel.getData();
  25853. var oldData = this._data;
  25854. var group = this.group;
  25855. var hasAnimation = ecModel.get('animation');
  25856. var isFirstRender = !oldData;
  25857. var animationType = seriesModel.get('animationType');
  25858. var onSectorClick = zrUtil.curry(
  25859. updateDataSelected, this.uid, seriesModel, hasAnimation, api
  25860. );
  25861. var selectedMode = seriesModel.get('selectedMode');
  25862. data.diff(oldData)
  25863. .add(function (idx) {
  25864. var piePiece = new PiePiece(data, idx);
  25865. // Default expansion animation
  25866. if (isFirstRender && animationType !== 'scale') {
  25867. piePiece.eachChild(function (child) {
  25868. child.stopAnimation(true);
  25869. });
  25870. }
  25871. selectedMode && piePiece.on('click', onSectorClick);
  25872. data.setItemGraphicEl(idx, piePiece);
  25873. group.add(piePiece);
  25874. })
  25875. .update(function (newIdx, oldIdx) {
  25876. var piePiece = oldData.getItemGraphicEl(oldIdx);
  25877. piePiece.updateData(data, newIdx);
  25878. piePiece.off('click');
  25879. selectedMode && piePiece.on('click', onSectorClick);
  25880. group.add(piePiece);
  25881. data.setItemGraphicEl(newIdx, piePiece);
  25882. })
  25883. .remove(function (idx) {
  25884. var piePiece = oldData.getItemGraphicEl(idx);
  25885. group.remove(piePiece);
  25886. })
  25887. .execute();
  25888. if (
  25889. hasAnimation && isFirstRender && data.count() > 0
  25890. // Default expansion animation
  25891. && animationType !== 'scale'
  25892. ) {
  25893. var shape = data.getItemLayout(0);
  25894. var r = Math.max(api.getWidth(), api.getHeight()) / 2;
  25895. var removeClipPath = zrUtil.bind(group.removeClipPath, group);
  25896. group.setClipPath(this._createClipPath(
  25897. shape.cx, shape.cy, r, shape.startAngle, shape.clockwise, removeClipPath, seriesModel
  25898. ));
  25899. }
  25900. this._data = data;
  25901. },
  25902. dispose: function () {},
  25903. _createClipPath: function (
  25904. cx, cy, r, startAngle, clockwise, cb, seriesModel
  25905. ) {
  25906. var clipPath = new graphic.Sector({
  25907. shape: {
  25908. cx: cx,
  25909. cy: cy,
  25910. r0: 0,
  25911. r: r,
  25912. startAngle: startAngle,
  25913. endAngle: startAngle,
  25914. clockwise: clockwise
  25915. }
  25916. });
  25917. graphic.initProps(clipPath, {
  25918. shape: {
  25919. endAngle: startAngle + (clockwise ? 1 : -1) * Math.PI * 2
  25920. }
  25921. }, seriesModel, cb);
  25922. return clipPath;
  25923. },
  25924. /**
  25925. * @implement
  25926. */
  25927. containPoint: function (point, seriesModel) {
  25928. var data = seriesModel.getData();
  25929. var itemLayout = data.getItemLayout(0);
  25930. if (itemLayout) {
  25931. var dx = point[0] - itemLayout.cx;
  25932. var dy = point[1] - itemLayout.cy;
  25933. var radius = Math.sqrt(dx * dx + dy * dy);
  25934. return radius <= itemLayout.r && radius >= itemLayout.r0;
  25935. }
  25936. }
  25937. });
  25938. module.exports = Pie;
  25939. /***/ },
  25940. /* 145 */
  25941. /***/ function(module, exports, __webpack_require__) {
  25942. var echarts = __webpack_require__(1);
  25943. var zrUtil = __webpack_require__(4);
  25944. module.exports = function (seriesType, actionInfos) {
  25945. zrUtil.each(actionInfos, function (actionInfo) {
  25946. actionInfo.update = 'updateView';
  25947. /**
  25948. * @payload
  25949. * @property {string} seriesName
  25950. * @property {string} name
  25951. */
  25952. echarts.registerAction(actionInfo, function (payload, ecModel) {
  25953. var selected = {};
  25954. ecModel.eachComponent(
  25955. {mainType: 'series', subType: seriesType, query: payload},
  25956. function (seriesModel) {
  25957. if (seriesModel[actionInfo.method]) {
  25958. seriesModel[actionInfo.method](payload.name);
  25959. }
  25960. var data = seriesModel.getData();
  25961. // Create selected map
  25962. data.each(function (idx) {
  25963. var name = data.getName(idx);
  25964. selected[name] = seriesModel.isSelected(name) || false;
  25965. });
  25966. }
  25967. );
  25968. return {
  25969. name: payload.name,
  25970. selected: selected
  25971. };
  25972. });
  25973. });
  25974. };
  25975. /***/ },
  25976. /* 146 */
  25977. /***/ function(module, exports) {
  25978. // Pick color from palette for each data item.
  25979. // Applicable for charts that require applying color palette
  25980. // in data level (like pie, funnel, chord).
  25981. module.exports = function (seriesType, ecModel) {
  25982. // Pie and funnel may use diferrent scope
  25983. var paletteScope = {};
  25984. ecModel.eachRawSeriesByType(seriesType, function (seriesModel) {
  25985. var dataAll = seriesModel.getRawData();
  25986. var idxMap = {};
  25987. if (!ecModel.isSeriesFiltered(seriesModel)) {
  25988. var data = seriesModel.getData();
  25989. data.each(function (idx) {
  25990. var rawIdx = data.getRawIndex(idx);
  25991. idxMap[rawIdx] = idx;
  25992. });
  25993. dataAll.each(function (rawIdx) {
  25994. var filteredIdx = idxMap[rawIdx];
  25995. // If series.itemStyle.normal.color is a function. itemVisual may be encoded
  25996. var singleDataColor = filteredIdx != null
  25997. && data.getItemVisual(filteredIdx, 'color', true);
  25998. if (!singleDataColor) {
  25999. // FIXME Performance
  26000. var itemModel = dataAll.getItemModel(rawIdx);
  26001. var color = itemModel.get('itemStyle.normal.color')
  26002. || seriesModel.getColorFromPalette(dataAll.getName(rawIdx), paletteScope);
  26003. // Legend may use the visual info in data before processed
  26004. dataAll.setItemVisual(rawIdx, 'color', color);
  26005. // Data is not filtered
  26006. if (filteredIdx != null) {
  26007. data.setItemVisual(filteredIdx, 'color', color);
  26008. }
  26009. }
  26010. else {
  26011. // Set data all color for legend
  26012. dataAll.setItemVisual(rawIdx, 'color', singleDataColor);
  26013. }
  26014. });
  26015. }
  26016. });
  26017. };
  26018. /***/ },
  26019. /* 147 */
  26020. /***/ function(module, exports, __webpack_require__) {
  26021. // TODO minAngle
  26022. var numberUtil = __webpack_require__(7);
  26023. var parsePercent = numberUtil.parsePercent;
  26024. var labelLayout = __webpack_require__(148);
  26025. var zrUtil = __webpack_require__(4);
  26026. var PI2 = Math.PI * 2;
  26027. var RADIAN = Math.PI / 180;
  26028. module.exports = function (seriesType, ecModel, api, payload) {
  26029. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  26030. var center = seriesModel.get('center');
  26031. var radius = seriesModel.get('radius');
  26032. if (!zrUtil.isArray(radius)) {
  26033. radius = [0, radius];
  26034. }
  26035. if (!zrUtil.isArray(center)) {
  26036. center = [center, center];
  26037. }
  26038. var width = api.getWidth();
  26039. var height = api.getHeight();
  26040. var size = Math.min(width, height);
  26041. var cx = parsePercent(center[0], width);
  26042. var cy = parsePercent(center[1], height);
  26043. var r0 = parsePercent(radius[0], size / 2);
  26044. var r = parsePercent(radius[1], size / 2);
  26045. var data = seriesModel.getData();
  26046. var startAngle = -seriesModel.get('startAngle') * RADIAN;
  26047. var minAngle = seriesModel.get('minAngle') * RADIAN;
  26048. var sum = data.getSum('value');
  26049. // Sum may be 0
  26050. var unitRadian = Math.PI / (sum || data.count()) * 2;
  26051. var clockwise = seriesModel.get('clockwise');
  26052. var roseType = seriesModel.get('roseType');
  26053. var stillShowZeroSum = seriesModel.get('stillShowZeroSum');
  26054. // [0...max]
  26055. var extent = data.getDataExtent('value');
  26056. extent[0] = 0;
  26057. // In the case some sector angle is smaller than minAngle
  26058. var restAngle = PI2;
  26059. var valueSumLargerThanMinAngle = 0;
  26060. var currentAngle = startAngle;
  26061. var dir = clockwise ? 1 : -1;
  26062. data.each('value', function (value, idx) {
  26063. var angle;
  26064. if (isNaN(value)) {
  26065. data.setItemLayout(idx, {
  26066. angle: NaN,
  26067. startAngle: NaN,
  26068. endAngle: NaN,
  26069. clockwise: clockwise,
  26070. cx: cx,
  26071. cy: cy,
  26072. r0: r0,
  26073. r: roseType
  26074. ? NaN
  26075. : r
  26076. });
  26077. return;
  26078. }
  26079. // FIXME 兼容 2.0 但是 roseType 是 area 的时候才是这样?
  26080. if (roseType !== 'area') {
  26081. angle = (sum === 0 && stillShowZeroSum)
  26082. ? unitRadian : (value * unitRadian);
  26083. }
  26084. else {
  26085. angle = PI2 / (data.count() || 1);
  26086. }
  26087. if (angle < minAngle) {
  26088. angle = minAngle;
  26089. restAngle -= minAngle;
  26090. }
  26091. else {
  26092. valueSumLargerThanMinAngle += value;
  26093. }
  26094. var endAngle = currentAngle + dir * angle;
  26095. data.setItemLayout(idx, {
  26096. angle: angle,
  26097. startAngle: currentAngle,
  26098. endAngle: endAngle,
  26099. clockwise: clockwise,
  26100. cx: cx,
  26101. cy: cy,
  26102. r0: r0,
  26103. r: roseType
  26104. ? numberUtil.linearMap(value, extent, [r0, r])
  26105. : r
  26106. });
  26107. currentAngle = endAngle;
  26108. }, true);
  26109. // Some sector is constrained by minAngle
  26110. // Rest sectors needs recalculate angle
  26111. if (restAngle < PI2) {
  26112. // Average the angle if rest angle is not enough after all angles is
  26113. // Constrained by minAngle
  26114. if (restAngle <= 1e-3) {
  26115. var angle = PI2 / data.count();
  26116. data.each(function (idx) {
  26117. var layout = data.getItemLayout(idx);
  26118. layout.startAngle = startAngle + dir * idx * angle;
  26119. layout.endAngle = startAngle + dir * (idx + 1) * angle;
  26120. });
  26121. }
  26122. else {
  26123. unitRadian = restAngle / valueSumLargerThanMinAngle;
  26124. currentAngle = startAngle;
  26125. data.each('value', function (value, idx) {
  26126. var layout = data.getItemLayout(idx);
  26127. var angle = layout.angle === minAngle
  26128. ? minAngle : value * unitRadian;
  26129. layout.startAngle = currentAngle;
  26130. layout.endAngle = currentAngle + dir * angle;
  26131. currentAngle += dir * angle;
  26132. });
  26133. }
  26134. }
  26135. labelLayout(seriesModel, r, width, height);
  26136. });
  26137. };
  26138. /***/ },
  26139. /* 148 */
  26140. /***/ function(module, exports, __webpack_require__) {
  26141. 'use strict';
  26142. // FIXME emphasis label position is not same with normal label position
  26143. var textContain = __webpack_require__(8);
  26144. function adjustSingleSide(list, cx, cy, r, dir, viewWidth, viewHeight) {
  26145. list.sort(function (a, b) {
  26146. return a.y - b.y;
  26147. });
  26148. // 压
  26149. function shiftDown(start, end, delta, dir) {
  26150. for (var j = start; j < end; j++) {
  26151. list[j].y += delta;
  26152. if (j > start
  26153. && j + 1 < end
  26154. && list[j + 1].y > list[j].y + list[j].height
  26155. ) {
  26156. shiftUp(j, delta / 2);
  26157. return;
  26158. }
  26159. }
  26160. shiftUp(end - 1, delta / 2);
  26161. }
  26162. // 弹
  26163. function shiftUp(end, delta) {
  26164. for (var j = end; j >= 0; j--) {
  26165. list[j].y -= delta;
  26166. if (j > 0
  26167. && list[j].y > list[j - 1].y + list[j - 1].height
  26168. ) {
  26169. break;
  26170. }
  26171. }
  26172. }
  26173. function changeX(list, isDownList, cx, cy, r, dir) {
  26174. var lastDeltaX = dir > 0
  26175. ? isDownList // 右侧
  26176. ? Number.MAX_VALUE // 下
  26177. : 0 // 上
  26178. : isDownList // 左侧
  26179. ? Number.MAX_VALUE // 下
  26180. : 0; // 上
  26181. for (var i = 0, l = list.length; i < l; i++) {
  26182. // Not change x for center label
  26183. if (list[i].position === 'center') {
  26184. continue;
  26185. }
  26186. var deltaY = Math.abs(list[i].y - cy);
  26187. var length = list[i].len;
  26188. var length2 = list[i].len2;
  26189. var deltaX = (deltaY < r + length)
  26190. ? Math.sqrt(
  26191. (r + length + length2) * (r + length + length2)
  26192. - deltaY * deltaY
  26193. )
  26194. : Math.abs(list[i].x - cx);
  26195. if (isDownList && deltaX >= lastDeltaX) {
  26196. // 右下,左下
  26197. deltaX = lastDeltaX - 10;
  26198. }
  26199. if (!isDownList && deltaX <= lastDeltaX) {
  26200. // 右上,左上
  26201. deltaX = lastDeltaX + 10;
  26202. }
  26203. list[i].x = cx + deltaX * dir;
  26204. lastDeltaX = deltaX;
  26205. }
  26206. }
  26207. var lastY = 0;
  26208. var delta;
  26209. var len = list.length;
  26210. var upList = [];
  26211. var downList = [];
  26212. for (var i = 0; i < len; i++) {
  26213. delta = list[i].y - lastY;
  26214. if (delta < 0) {
  26215. shiftDown(i, len, -delta, dir);
  26216. }
  26217. lastY = list[i].y + list[i].height;
  26218. }
  26219. if (viewHeight - lastY < 0) {
  26220. shiftUp(len - 1, lastY - viewHeight);
  26221. }
  26222. for (var i = 0; i < len; i++) {
  26223. if (list[i].y >= cy) {
  26224. downList.push(list[i]);
  26225. }
  26226. else {
  26227. upList.push(list[i]);
  26228. }
  26229. }
  26230. changeX(upList, false, cx, cy, r, dir);
  26231. changeX(downList, true, cx, cy, r, dir);
  26232. }
  26233. function avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight) {
  26234. var leftList = [];
  26235. var rightList = [];
  26236. for (var i = 0; i < labelLayoutList.length; i++) {
  26237. if (labelLayoutList[i].x < cx) {
  26238. leftList.push(labelLayoutList[i]);
  26239. }
  26240. else {
  26241. rightList.push(labelLayoutList[i]);
  26242. }
  26243. }
  26244. adjustSingleSide(rightList, cx, cy, r, 1, viewWidth, viewHeight);
  26245. adjustSingleSide(leftList, cx, cy, r, -1, viewWidth, viewHeight);
  26246. for (var i = 0; i < labelLayoutList.length; i++) {
  26247. var linePoints = labelLayoutList[i].linePoints;
  26248. if (linePoints) {
  26249. var dist = linePoints[1][0] - linePoints[2][0];
  26250. if (labelLayoutList[i].x < cx) {
  26251. linePoints[2][0] = labelLayoutList[i].x + 3;
  26252. }
  26253. else {
  26254. linePoints[2][0] = labelLayoutList[i].x - 3;
  26255. }
  26256. linePoints[1][1] = linePoints[2][1] = labelLayoutList[i].y;
  26257. linePoints[1][0] = linePoints[2][0] + dist;
  26258. }
  26259. }
  26260. }
  26261. module.exports = function (seriesModel, r, viewWidth, viewHeight) {
  26262. var data = seriesModel.getData();
  26263. var labelLayoutList = [];
  26264. var cx;
  26265. var cy;
  26266. var hasLabelRotate = false;
  26267. data.each(function (idx) {
  26268. var layout = data.getItemLayout(idx);
  26269. var itemModel = data.getItemModel(idx);
  26270. var labelModel = itemModel.getModel('label.normal');
  26271. // Use position in normal or emphasis
  26272. var labelPosition = labelModel.get('position') || itemModel.get('label.emphasis.position');
  26273. var labelLineModel = itemModel.getModel('labelLine.normal');
  26274. var labelLineLen = labelLineModel.get('length');
  26275. var labelLineLen2 = labelLineModel.get('length2');
  26276. var midAngle = (layout.startAngle + layout.endAngle) / 2;
  26277. var dx = Math.cos(midAngle);
  26278. var dy = Math.sin(midAngle);
  26279. var textX;
  26280. var textY;
  26281. var linePoints;
  26282. var textAlign;
  26283. cx = layout.cx;
  26284. cy = layout.cy;
  26285. var isLabelInside = labelPosition === 'inside' || labelPosition === 'inner';
  26286. if (labelPosition === 'center') {
  26287. textX = layout.cx;
  26288. textY = layout.cy;
  26289. textAlign = 'center';
  26290. }
  26291. else {
  26292. var x1 = (isLabelInside ? (layout.r + layout.r0) / 2 * dx : layout.r * dx) + cx;
  26293. var y1 = (isLabelInside ? (layout.r + layout.r0) / 2 * dy : layout.r * dy) + cy;
  26294. textX = x1 + dx * 3;
  26295. textY = y1 + dy * 3;
  26296. if (!isLabelInside) {
  26297. // For roseType
  26298. var x2 = x1 + dx * (labelLineLen + r - layout.r);
  26299. var y2 = y1 + dy * (labelLineLen + r - layout.r);
  26300. var x3 = x2 + ((dx < 0 ? -1 : 1) * labelLineLen2);
  26301. var y3 = y2;
  26302. textX = x3 + (dx < 0 ? -5 : 5);
  26303. textY = y3;
  26304. linePoints = [[x1, y1], [x2, y2], [x3, y3]];
  26305. }
  26306. textAlign = isLabelInside ? 'center' : (dx > 0 ? 'left' : 'right');
  26307. }
  26308. var font = labelModel.getModel('textStyle').getFont();
  26309. var labelRotate = labelModel.get('rotate')
  26310. ? (dx < 0 ? -midAngle + Math.PI : -midAngle) : 0;
  26311. var text = seriesModel.getFormattedLabel(idx, 'normal')
  26312. || data.getName(idx);
  26313. var textRect = textContain.getBoundingRect(
  26314. text, font, textAlign, 'top'
  26315. );
  26316. hasLabelRotate = !!labelRotate;
  26317. layout.label = {
  26318. x: textX,
  26319. y: textY,
  26320. position: labelPosition,
  26321. height: textRect.height,
  26322. len: labelLineLen,
  26323. len2: labelLineLen2,
  26324. linePoints: linePoints,
  26325. textAlign: textAlign,
  26326. verticalAlign: 'middle',
  26327. font: font,
  26328. rotation: labelRotate
  26329. };
  26330. // Not layout the inside label
  26331. if (!isLabelInside) {
  26332. labelLayoutList.push(layout.label);
  26333. }
  26334. });
  26335. if (!hasLabelRotate && seriesModel.get('avoidLabelOverlap')) {
  26336. avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight);
  26337. }
  26338. };
  26339. /***/ },
  26340. /* 149 */
  26341. /***/ function(module, exports) {
  26342. module.exports = function (seriesType, ecModel) {
  26343. var legendModels = ecModel.findComponents({
  26344. mainType: 'legend'
  26345. });
  26346. if (!legendModels || !legendModels.length) {
  26347. return;
  26348. }
  26349. ecModel.eachSeriesByType(seriesType, function (series) {
  26350. var data = series.getData();
  26351. data.filterSelf(function (idx) {
  26352. var name = data.getName(idx);
  26353. // If in any legend component the status is not selected.
  26354. for (var i = 0; i < legendModels.length; i++) {
  26355. if (!legendModels[i].isSelected(name)) {
  26356. return false;
  26357. }
  26358. }
  26359. return true;
  26360. }, this);
  26361. }, this);
  26362. };
  26363. /***/ },
  26364. /* 150 */
  26365. /***/ function(module, exports, __webpack_require__) {
  26366. var zrUtil = __webpack_require__(4);
  26367. var echarts = __webpack_require__(1);
  26368. __webpack_require__(151);
  26369. __webpack_require__(152);
  26370. echarts.registerVisual(zrUtil.curry(
  26371. __webpack_require__(110), 'scatter', 'circle', null
  26372. ));
  26373. echarts.registerLayout(zrUtil.curry(
  26374. __webpack_require__(111), 'scatter'
  26375. ));
  26376. // In case developer forget to include grid component
  26377. __webpack_require__(113);
  26378. /***/ },
  26379. /* 151 */
  26380. /***/ function(module, exports, __webpack_require__) {
  26381. 'use strict';
  26382. var createListFromArray = __webpack_require__(102);
  26383. var SeriesModel = __webpack_require__(28);
  26384. module.exports = SeriesModel.extend({
  26385. type: 'series.scatter',
  26386. dependencies: ['grid', 'polar'],
  26387. getInitialData: function (option, ecModel) {
  26388. var list = createListFromArray(option.data, this, ecModel);
  26389. return list;
  26390. },
  26391. brushSelector: 'point',
  26392. defaultOption: {
  26393. coordinateSystem: 'cartesian2d',
  26394. zlevel: 0,
  26395. z: 2,
  26396. legendHoverLink: true,
  26397. hoverAnimation: true,
  26398. // Cartesian coordinate system
  26399. // xAxisIndex: 0,
  26400. // yAxisIndex: 0,
  26401. // Polar coordinate system
  26402. // polarIndex: 0,
  26403. // Geo coordinate system
  26404. // geoIndex: 0,
  26405. // symbol: null, // 图形类型
  26406. symbolSize: 10, // 图形大小,半宽(半径)参数,当图形为方向或菱形则总宽度为symbolSize * 2
  26407. // symbolRotate: null, // 图形旋转控制
  26408. large: false,
  26409. // Available when large is true
  26410. largeThreshold: 2000,
  26411. // label: {
  26412. // normal: {
  26413. // show: false
  26414. // distance: 5,
  26415. // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  26416. // position: 默认自适应,水平布局为'top',垂直布局为'right',可选为
  26417. // 'inside'|'left'|'right'|'top'|'bottom'
  26418. // textStyle: null // 默认使用全局文本样式,详见TEXTSTYLE
  26419. // }
  26420. // },
  26421. itemStyle: {
  26422. normal: {
  26423. opacity: 0.8
  26424. // color: 各异
  26425. }
  26426. }
  26427. }
  26428. });
  26429. /***/ },
  26430. /* 152 */
  26431. /***/ function(module, exports, __webpack_require__) {
  26432. var SymbolDraw = __webpack_require__(105);
  26433. var LargeSymbolDraw = __webpack_require__(153);
  26434. __webpack_require__(1).extendChartView({
  26435. type: 'scatter',
  26436. init: function () {
  26437. this._normalSymbolDraw = new SymbolDraw();
  26438. this._largeSymbolDraw = new LargeSymbolDraw();
  26439. },
  26440. render: function (seriesModel, ecModel, api) {
  26441. var data = seriesModel.getData();
  26442. var largeSymbolDraw = this._largeSymbolDraw;
  26443. var normalSymbolDraw = this._normalSymbolDraw;
  26444. var group = this.group;
  26445. var symbolDraw = seriesModel.get('large') && data.count() > seriesModel.get('largeThreshold')
  26446. ? largeSymbolDraw : normalSymbolDraw;
  26447. this._symbolDraw = symbolDraw;
  26448. symbolDraw.updateData(data);
  26449. group.add(symbolDraw.group);
  26450. group.remove(
  26451. symbolDraw === largeSymbolDraw
  26452. ? normalSymbolDraw.group : largeSymbolDraw.group
  26453. );
  26454. },
  26455. updateLayout: function (seriesModel) {
  26456. this._symbolDraw.updateLayout(seriesModel);
  26457. },
  26458. remove: function (ecModel, api) {
  26459. this._symbolDraw && this._symbolDraw.remove(api, true);
  26460. },
  26461. dispose: function () {}
  26462. });
  26463. /***/ },
  26464. /* 153 */
  26465. /***/ function(module, exports, __webpack_require__) {
  26466. // TODO Batch by color
  26467. var graphic = __webpack_require__(43);
  26468. var symbolUtil = __webpack_require__(107);
  26469. var LargeSymbolPath = graphic.extendShape({
  26470. shape: {
  26471. points: null,
  26472. sizes: null
  26473. },
  26474. symbolProxy: null,
  26475. buildPath: function (path, shape) {
  26476. var points = shape.points;
  26477. var sizes = shape.sizes;
  26478. var symbolProxy = this.symbolProxy;
  26479. var symbolProxyShape = symbolProxy.shape;
  26480. for (var i = 0; i < points.length; i++) {
  26481. var pt = points[i];
  26482. var size = sizes[i];
  26483. if (size[0] < 4) {
  26484. // Optimize for small symbol
  26485. path.rect(
  26486. pt[0] - size[0] / 2, pt[1] - size[1] / 2,
  26487. size[0], size[1]
  26488. );
  26489. }
  26490. else {
  26491. symbolProxyShape.x = pt[0] - size[0] / 2;
  26492. symbolProxyShape.y = pt[1] - size[1] / 2;
  26493. symbolProxyShape.width = size[0];
  26494. symbolProxyShape.height = size[1];
  26495. symbolProxy.buildPath(path, symbolProxyShape, true);
  26496. }
  26497. }
  26498. },
  26499. findDataIndex: function (x, y) {
  26500. var shape = this.shape;
  26501. var points = shape.points;
  26502. var sizes = shape.sizes;
  26503. // Not consider transform
  26504. // Treat each element as a rect
  26505. // top down traverse
  26506. for (var i = points.length - 1; i >= 0; i--) {
  26507. var pt = points[i];
  26508. var size = sizes[i];
  26509. var x0 = pt[0] - size[0] / 2;
  26510. var y0 = pt[1] - size[1] / 2;
  26511. if (x >= x0 && y >= y0 && x <= x0 + size[0] && y <= y0 + size[1]) {
  26512. // i is dataIndex
  26513. return i;
  26514. }
  26515. }
  26516. return -1;
  26517. }
  26518. });
  26519. function LargeSymbolDraw() {
  26520. this.group = new graphic.Group();
  26521. this._symbolEl = new LargeSymbolPath({
  26522. // rectHover: true,
  26523. // cursor: 'default'
  26524. });
  26525. }
  26526. var largeSymbolProto = LargeSymbolDraw.prototype;
  26527. /**
  26528. * Update symbols draw by new data
  26529. * @param {module:echarts/data/List} data
  26530. */
  26531. largeSymbolProto.updateData = function (data) {
  26532. this.group.removeAll();
  26533. var symbolEl = this._symbolEl;
  26534. var seriesModel = data.hostModel;
  26535. symbolEl.setShape({
  26536. points: data.mapArray(data.getItemLayout),
  26537. sizes: data.mapArray(
  26538. function (idx) {
  26539. var size = data.getItemVisual(idx, 'symbolSize');
  26540. if (!(size instanceof Array)) {
  26541. size = [size, size];
  26542. }
  26543. return size;
  26544. }
  26545. )
  26546. });
  26547. // Create symbolProxy to build path for each data
  26548. symbolEl.symbolProxy = symbolUtil.createSymbol(
  26549. data.getVisual('symbol'), 0, 0, 0, 0
  26550. );
  26551. // Use symbolProxy setColor method
  26552. symbolEl.setColor = symbolEl.symbolProxy.setColor;
  26553. symbolEl.useStyle(
  26554. seriesModel.getModel('itemStyle.normal').getItemStyle(['color'])
  26555. );
  26556. var visualColor = data.getVisual('color');
  26557. if (visualColor) {
  26558. symbolEl.setColor(visualColor);
  26559. }
  26560. // Enable tooltip
  26561. // PENDING May have performance issue when path is extremely large
  26562. symbolEl.seriesIndex = seriesModel.seriesIndex;
  26563. symbolEl.on('mousemove', function (e) {
  26564. symbolEl.dataIndex = null;
  26565. var dataIndex = symbolEl.findDataIndex(e.offsetX, e.offsetY);
  26566. if (dataIndex > 0) {
  26567. // Provide dataIndex for tooltip
  26568. symbolEl.dataIndex = dataIndex;
  26569. }
  26570. });
  26571. // Add back
  26572. this.group.add(symbolEl);
  26573. };
  26574. largeSymbolProto.updateLayout = function (seriesModel) {
  26575. var data = seriesModel.getData();
  26576. this._symbolEl.setShape({
  26577. points: data.mapArray(data.getItemLayout)
  26578. });
  26579. };
  26580. largeSymbolProto.remove = function () {
  26581. this.group.removeAll();
  26582. };
  26583. module.exports = LargeSymbolDraw;
  26584. /***/ },
  26585. /* 154 */,
  26586. /* 155 */,
  26587. /* 156 */,
  26588. /* 157 */,
  26589. /* 158 */,
  26590. /* 159 */,
  26591. /* 160 */,
  26592. /* 161 */,
  26593. /* 162 */,
  26594. /* 163 */,
  26595. /* 164 */,
  26596. /* 165 */,
  26597. /* 166 */,
  26598. /* 167 */,
  26599. /* 168 */,
  26600. /* 169 */,
  26601. /* 170 */,
  26602. /* 171 */,
  26603. /* 172 */,
  26604. /* 173 */,
  26605. /* 174 */,
  26606. /* 175 */,
  26607. /* 176 */,
  26608. /* 177 */
  26609. /***/ function(module, exports, __webpack_require__) {
  26610. /**
  26611. * @module echarts/component/helper/RoamController
  26612. */
  26613. var Eventful = __webpack_require__(33);
  26614. var zrUtil = __webpack_require__(4);
  26615. var eventTool = __webpack_require__(88);
  26616. var interactionMutex = __webpack_require__(178);
  26617. function mousedown(e) {
  26618. if (e.target && e.target.draggable) {
  26619. return;
  26620. }
  26621. var x = e.offsetX;
  26622. var y = e.offsetY;
  26623. if (this.containsPoint && this.containsPoint(x, y)) {
  26624. this._x = x;
  26625. this._y = y;
  26626. this._dragging = true;
  26627. }
  26628. }
  26629. function mousemove(e) {
  26630. if (!this._dragging) {
  26631. return;
  26632. }
  26633. eventTool.stop(e.event);
  26634. if (e.gestureEvent !== 'pinch') {
  26635. if (interactionMutex.isTaken(this._zr, 'globalPan')) {
  26636. return;
  26637. }
  26638. var x = e.offsetX;
  26639. var y = e.offsetY;
  26640. var oldX = this._x;
  26641. var oldY = this._y;
  26642. var dx = x - oldX;
  26643. var dy = y - oldY;
  26644. this._x = x;
  26645. this._y = y;
  26646. var target = this.target;
  26647. if (target) {
  26648. var pos = target.position;
  26649. pos[0] += dx;
  26650. pos[1] += dy;
  26651. target.dirty();
  26652. }
  26653. eventTool.stop(e.event);
  26654. this.trigger('pan', dx, dy, oldX, oldY, x, y);
  26655. }
  26656. }
  26657. function mouseup(e) {
  26658. this._dragging = false;
  26659. }
  26660. function mousewheel(e) {
  26661. // Convenience:
  26662. // Mac and VM Windows on Mac: scroll up: zoom out.
  26663. // Windows: scroll up: zoom in.
  26664. var zoomDelta = e.wheelDelta > 0 ? 1.1 : 1 / 1.1;
  26665. zoom.call(this, e, zoomDelta, e.offsetX, e.offsetY);
  26666. }
  26667. function pinch(e) {
  26668. if (interactionMutex.isTaken(this._zr, 'globalPan')) {
  26669. return;
  26670. }
  26671. var zoomDelta = e.pinchScale > 1 ? 1.1 : 1 / 1.1;
  26672. zoom.call(this, e, zoomDelta, e.pinchX, e.pinchY);
  26673. }
  26674. function zoom(e, zoomDelta, zoomX, zoomY) {
  26675. if (this.containsPoint && this.containsPoint(zoomX, zoomY)) {
  26676. // When mouse is out of roamController rect,
  26677. // default befavoius should be be disabled, otherwise
  26678. // page sliding is disabled, contrary to expectation.
  26679. eventTool.stop(e.event);
  26680. var target = this.target;
  26681. var zoomLimit = this.zoomLimit;
  26682. if (target) {
  26683. var pos = target.position;
  26684. var scale = target.scale;
  26685. var newZoom = this.zoom = this.zoom || 1;
  26686. newZoom *= zoomDelta;
  26687. if (zoomLimit) {
  26688. var zoomMin = zoomLimit.min || 0;
  26689. var zoomMax = zoomLimit.max || Infinity;
  26690. newZoom = Math.max(
  26691. Math.min(zoomMax, newZoom),
  26692. zoomMin
  26693. );
  26694. }
  26695. var zoomScale = newZoom / this.zoom;
  26696. this.zoom = newZoom;
  26697. // Keep the mouse center when scaling
  26698. pos[0] -= (zoomX - pos[0]) * (zoomScale - 1);
  26699. pos[1] -= (zoomY - pos[1]) * (zoomScale - 1);
  26700. scale[0] *= zoomScale;
  26701. scale[1] *= zoomScale;
  26702. target.dirty();
  26703. }
  26704. this.trigger('zoom', zoomDelta, zoomX, zoomY);
  26705. }
  26706. }
  26707. /**
  26708. * @alias module:echarts/component/helper/RoamController
  26709. * @constructor
  26710. * @mixin {module:zrender/mixin/Eventful}
  26711. *
  26712. * @param {module:zrender/zrender~ZRender} zr
  26713. * @param {module:zrender/Element} target
  26714. */
  26715. function RoamController(zr, target) {
  26716. /**
  26717. * @type {module:zrender/Element}
  26718. */
  26719. this.target = target;
  26720. /**
  26721. * @type {Function}
  26722. */
  26723. this.containsPoint;
  26724. /**
  26725. * { min: 1, max: 2 }
  26726. * @type {Object}
  26727. */
  26728. this.zoomLimit;
  26729. /**
  26730. * @type {number}
  26731. */
  26732. this.zoom;
  26733. /**
  26734. * @type {module:zrender}
  26735. */
  26736. this._zr = zr;
  26737. // Avoid two roamController bind the same handler
  26738. var bind = zrUtil.bind;
  26739. var mousedownHandler = bind(mousedown, this);
  26740. var mousemoveHandler = bind(mousemove, this);
  26741. var mouseupHandler = bind(mouseup, this);
  26742. var mousewheelHandler = bind(mousewheel, this);
  26743. var pinchHandler = bind(pinch, this);
  26744. Eventful.call(this);
  26745. /**
  26746. * @param {Function} containsPoint
  26747. * input: x, y
  26748. * output: boolean
  26749. */
  26750. this.setContainsPoint = function (containsPoint) {
  26751. this.containsPoint = containsPoint;
  26752. };
  26753. /**
  26754. * Notice: only enable needed types. For example, if 'zoom'
  26755. * is not needed, 'zoom' should not be enabled, otherwise
  26756. * default mousewheel behaviour (scroll page) will be disabled.
  26757. *
  26758. * @param {boolean|string} [controlType=true] Specify the control type,
  26759. * which can be null/undefined or true/false
  26760. * or 'pan/move' or 'zoom'/'scale'
  26761. */
  26762. this.enable = function (controlType) {
  26763. // Disable previous first
  26764. this.disable();
  26765. if (controlType == null) {
  26766. controlType = true;
  26767. }
  26768. if (controlType === true || (controlType === 'move' || controlType === 'pan')) {
  26769. zr.on('mousedown', mousedownHandler);
  26770. zr.on('mousemove', mousemoveHandler);
  26771. zr.on('mouseup', mouseupHandler);
  26772. }
  26773. if (controlType === true || (controlType === 'scale' || controlType === 'zoom')) {
  26774. zr.on('mousewheel', mousewheelHandler);
  26775. zr.on('pinch', pinchHandler);
  26776. }
  26777. };
  26778. this.disable = function () {
  26779. zr.off('mousedown', mousedownHandler);
  26780. zr.off('mousemove', mousemoveHandler);
  26781. zr.off('mouseup', mouseupHandler);
  26782. zr.off('mousewheel', mousewheelHandler);
  26783. zr.off('pinch', pinchHandler);
  26784. };
  26785. this.dispose = this.disable;
  26786. this.isDragging = function () {
  26787. return this._dragging;
  26788. };
  26789. this.isPinching = function () {
  26790. return this._pinching;
  26791. };
  26792. }
  26793. zrUtil.mixin(RoamController, Eventful);
  26794. module.exports = RoamController;
  26795. /***/ },
  26796. /* 178 */
  26797. /***/ function(module, exports, __webpack_require__) {
  26798. var ATTR = '\0_ec_interaction_mutex';
  26799. var interactionMutex = {
  26800. take: function (zr, resourceKey, userKey) {
  26801. var store = getStore(zr);
  26802. store[resourceKey] = userKey;
  26803. },
  26804. release: function (zr, resourceKey, userKey) {
  26805. var store = getStore(zr);
  26806. var uKey = store[resourceKey];
  26807. if (uKey === userKey) {
  26808. store[resourceKey] = null;
  26809. }
  26810. },
  26811. isTaken: function (zr, resourceKey) {
  26812. return !!getStore(zr)[resourceKey];
  26813. }
  26814. };
  26815. function getStore(zr) {
  26816. return zr[ATTR] || (zr[ATTR] = {});
  26817. }
  26818. /**
  26819. * payload: {
  26820. * type: 'takeGlobalCursor',
  26821. * key: 'dataZoomSelect', or 'brush', or ...,
  26822. * If no userKey, release global cursor.
  26823. * }
  26824. */
  26825. __webpack_require__(1).registerAction(
  26826. {type: 'takeGlobalCursor', event: 'globalCursorTaken', update: 'update'},
  26827. function () {}
  26828. );
  26829. module.exports = interactionMutex;
  26830. /***/ },
  26831. /* 179 */,
  26832. /* 180 */,
  26833. /* 181 */,
  26834. /* 182 */,
  26835. /* 183 */,
  26836. /* 184 */,
  26837. /* 185 */,
  26838. /* 186 */,
  26839. /* 187 */,
  26840. /* 188 */,
  26841. /* 189 */,
  26842. /* 190 */,
  26843. /* 191 */,
  26844. /* 192 */,
  26845. /* 193 */,
  26846. /* 194 */,
  26847. /* 195 */,
  26848. /* 196 */,
  26849. /* 197 */,
  26850. /* 198 */,
  26851. /* 199 */,
  26852. /* 200 */,
  26853. /* 201 */,
  26854. /* 202 */
  26855. /***/ function(module, exports, __webpack_require__) {
  26856. /**
  26857. * @module echarts/chart/helper/LineDraw
  26858. */
  26859. var graphic = __webpack_require__(43);
  26860. var LineGroup = __webpack_require__(203);
  26861. function isPointNaN(pt) {
  26862. return isNaN(pt[0]) || isNaN(pt[1]);
  26863. }
  26864. function lineNeedsDraw(pts) {
  26865. return !isPointNaN(pts[0]) && !isPointNaN(pts[1]);
  26866. }
  26867. /**
  26868. * @alias module:echarts/component/marker/LineDraw
  26869. * @constructor
  26870. */
  26871. function LineDraw(ctor) {
  26872. this._ctor = ctor || LineGroup;
  26873. this.group = new graphic.Group();
  26874. }
  26875. var lineDrawProto = LineDraw.prototype;
  26876. /**
  26877. * @param {module:echarts/data/List} lineData
  26878. */
  26879. lineDrawProto.updateData = function (lineData) {
  26880. var oldLineData = this._lineData;
  26881. var group = this.group;
  26882. var LineCtor = this._ctor;
  26883. var hostModel = lineData.hostModel;
  26884. var seriesScope = {
  26885. lineStyle: hostModel.getModel('lineStyle.normal').getLineStyle(),
  26886. hoverLineStyle: hostModel.getModel('lineStyle.emphasis').getLineStyle(),
  26887. labelModel: hostModel.getModel('label.normal'),
  26888. hoverLabelModel: hostModel.getModel('label.emphasis')
  26889. };
  26890. lineData.diff(oldLineData)
  26891. .add(function (idx) {
  26892. if (!lineNeedsDraw(lineData.getItemLayout(idx))) {
  26893. return;
  26894. }
  26895. var lineGroup = new LineCtor(lineData, idx, seriesScope);
  26896. lineData.setItemGraphicEl(idx, lineGroup);
  26897. group.add(lineGroup);
  26898. })
  26899. .update(function (newIdx, oldIdx) {
  26900. var lineGroup = oldLineData.getItemGraphicEl(oldIdx);
  26901. if (!lineNeedsDraw(lineData.getItemLayout(newIdx))) {
  26902. group.remove(lineGroup);
  26903. return;
  26904. }
  26905. if (!lineGroup) {
  26906. lineGroup = new LineCtor(lineData, newIdx, seriesScope);
  26907. }
  26908. else {
  26909. lineGroup.updateData(lineData, newIdx, seriesScope);
  26910. }
  26911. lineData.setItemGraphicEl(newIdx, lineGroup);
  26912. group.add(lineGroup);
  26913. })
  26914. .remove(function (idx) {
  26915. group.remove(oldLineData.getItemGraphicEl(idx));
  26916. })
  26917. .execute();
  26918. this._lineData = lineData;
  26919. };
  26920. lineDrawProto.updateLayout = function () {
  26921. var lineData = this._lineData;
  26922. lineData.eachItemGraphicEl(function (el, idx) {
  26923. el.updateLayout(lineData, idx);
  26924. }, this);
  26925. };
  26926. lineDrawProto.remove = function () {
  26927. this.group.removeAll();
  26928. };
  26929. module.exports = LineDraw;
  26930. /***/ },
  26931. /* 203 */
  26932. /***/ function(module, exports, __webpack_require__) {
  26933. /**
  26934. * @module echarts/chart/helper/Line
  26935. */
  26936. var symbolUtil = __webpack_require__(107);
  26937. var vector = __webpack_require__(10);
  26938. // var matrix = require('zrender/lib/core/matrix');
  26939. var LinePath = __webpack_require__(204);
  26940. var graphic = __webpack_require__(43);
  26941. var zrUtil = __webpack_require__(4);
  26942. var numberUtil = __webpack_require__(7);
  26943. var SYMBOL_CATEGORIES = ['fromSymbol', 'toSymbol'];
  26944. function makeSymbolTypeKey(symbolCategory) {
  26945. return '_' + symbolCategory + 'Type';
  26946. }
  26947. /**
  26948. * @inner
  26949. */
  26950. function createSymbol(name, lineData, idx) {
  26951. var color = lineData.getItemVisual(idx, 'color');
  26952. var symbolType = lineData.getItemVisual(idx, name);
  26953. var symbolSize = lineData.getItemVisual(idx, name + 'Size');
  26954. if (!symbolType || symbolType === 'none') {
  26955. return;
  26956. }
  26957. if (!zrUtil.isArray(symbolSize)) {
  26958. symbolSize = [symbolSize, symbolSize];
  26959. }
  26960. var symbolPath = symbolUtil.createSymbol(
  26961. symbolType, -symbolSize[0] / 2, -symbolSize[1] / 2,
  26962. symbolSize[0], symbolSize[1], color
  26963. );
  26964. symbolPath.name = name;
  26965. return symbolPath;
  26966. }
  26967. function createLine(points) {
  26968. var line = new LinePath({
  26969. name: 'line'
  26970. });
  26971. setLinePoints(line.shape, points);
  26972. return line;
  26973. }
  26974. function setLinePoints(targetShape, points) {
  26975. var p1 = points[0];
  26976. var p2 = points[1];
  26977. var cp1 = points[2];
  26978. targetShape.x1 = p1[0];
  26979. targetShape.y1 = p1[1];
  26980. targetShape.x2 = p2[0];
  26981. targetShape.y2 = p2[1];
  26982. targetShape.percent = 1;
  26983. if (cp1) {
  26984. targetShape.cpx1 = cp1[0];
  26985. targetShape.cpy1 = cp1[1];
  26986. }
  26987. else {
  26988. targetShape.cpx1 = NaN;
  26989. targetShape.cpy1 = NaN;
  26990. }
  26991. }
  26992. function updateSymbolAndLabelBeforeLineUpdate () {
  26993. var lineGroup = this;
  26994. var symbolFrom = lineGroup.childOfName('fromSymbol');
  26995. var symbolTo = lineGroup.childOfName('toSymbol');
  26996. var label = lineGroup.childOfName('label');
  26997. // Quick reject
  26998. if (!symbolFrom && !symbolTo && label.ignore) {
  26999. return;
  27000. }
  27001. var invScale = 1;
  27002. var parentNode = this.parent;
  27003. while (parentNode) {
  27004. if (parentNode.scale) {
  27005. invScale /= parentNode.scale[0];
  27006. }
  27007. parentNode = parentNode.parent;
  27008. }
  27009. var line = lineGroup.childOfName('line');
  27010. // If line not changed
  27011. // FIXME Parent scale changed
  27012. if (!this.__dirty && !line.__dirty) {
  27013. return;
  27014. }
  27015. var percent = line.shape.percent;
  27016. var fromPos = line.pointAt(0);
  27017. var toPos = line.pointAt(percent);
  27018. var d = vector.sub([], toPos, fromPos);
  27019. vector.normalize(d, d);
  27020. if (symbolFrom) {
  27021. symbolFrom.attr('position', fromPos);
  27022. var tangent = line.tangentAt(0);
  27023. symbolFrom.attr('rotation', Math.PI / 2 - Math.atan2(
  27024. tangent[1], tangent[0]
  27025. ));
  27026. symbolFrom.attr('scale', [invScale * percent, invScale * percent]);
  27027. }
  27028. if (symbolTo) {
  27029. symbolTo.attr('position', toPos);
  27030. var tangent = line.tangentAt(1);
  27031. symbolTo.attr('rotation', -Math.PI / 2 - Math.atan2(
  27032. tangent[1], tangent[0]
  27033. ));
  27034. symbolTo.attr('scale', [invScale * percent, invScale * percent]);
  27035. }
  27036. if (!label.ignore) {
  27037. label.attr('position', toPos);
  27038. var textPosition;
  27039. var textAlign;
  27040. var textVerticalAlign;
  27041. var distance = 5 * invScale;
  27042. // End
  27043. if (label.__position === 'end') {
  27044. textPosition = [d[0] * distance + toPos[0], d[1] * distance + toPos[1]];
  27045. textAlign = d[0] > 0.8 ? 'left' : (d[0] < -0.8 ? 'right' : 'center');
  27046. textVerticalAlign = d[1] > 0.8 ? 'top' : (d[1] < -0.8 ? 'bottom' : 'middle');
  27047. }
  27048. // Middle
  27049. else if (label.__position === 'middle') {
  27050. var halfPercent = percent / 2;
  27051. var tangent = line.tangentAt(halfPercent);
  27052. var n = [tangent[1], -tangent[0]];
  27053. var cp = line.pointAt(halfPercent);
  27054. if (n[1] > 0) {
  27055. n[0] = -n[0];
  27056. n[1] = -n[1];
  27057. }
  27058. textPosition = [cp[0] + n[0] * distance, cp[1] + n[1] * distance];
  27059. textAlign = 'center';
  27060. textVerticalAlign = 'bottom';
  27061. var rotation = -Math.atan2(tangent[1], tangent[0]);
  27062. if (toPos[0] < fromPos[0]) {
  27063. rotation = Math.PI + rotation;
  27064. }
  27065. label.attr('rotation', rotation);
  27066. }
  27067. // Start
  27068. else {
  27069. textPosition = [-d[0] * distance + fromPos[0], -d[1] * distance + fromPos[1]];
  27070. textAlign = d[0] > 0.8 ? 'right' : (d[0] < -0.8 ? 'left' : 'center');
  27071. textVerticalAlign = d[1] > 0.8 ? 'bottom' : (d[1] < -0.8 ? 'top' : 'middle');
  27072. }
  27073. label.attr({
  27074. style: {
  27075. // Use the user specified text align and baseline first
  27076. textVerticalAlign: label.__verticalAlign || textVerticalAlign,
  27077. textAlign: label.__textAlign || textAlign
  27078. },
  27079. position: textPosition,
  27080. scale: [invScale, invScale]
  27081. });
  27082. }
  27083. }
  27084. /**
  27085. * @constructor
  27086. * @extends {module:zrender/graphic/Group}
  27087. * @alias {module:echarts/chart/helper/Line}
  27088. */
  27089. function Line(lineData, idx, seriesScope) {
  27090. graphic.Group.call(this);
  27091. this._createLine(lineData, idx, seriesScope);
  27092. }
  27093. var lineProto = Line.prototype;
  27094. // Update symbol position and rotation
  27095. lineProto.beforeUpdate = updateSymbolAndLabelBeforeLineUpdate;
  27096. lineProto._createLine = function (lineData, idx, seriesScope) {
  27097. var seriesModel = lineData.hostModel;
  27098. var linePoints = lineData.getItemLayout(idx);
  27099. var line = createLine(linePoints);
  27100. line.shape.percent = 0;
  27101. graphic.initProps(line, {
  27102. shape: {
  27103. percent: 1
  27104. }
  27105. }, seriesModel, idx);
  27106. this.add(line);
  27107. var label = new graphic.Text({
  27108. name: 'label'
  27109. });
  27110. this.add(label);
  27111. zrUtil.each(SYMBOL_CATEGORIES, function (symbolCategory) {
  27112. var symbol = createSymbol(symbolCategory, lineData, idx);
  27113. // symbols must added after line to make sure
  27114. // it will be updated after line#update.
  27115. // Or symbol position and rotation update in line#beforeUpdate will be one frame slow
  27116. this.add(symbol);
  27117. this[makeSymbolTypeKey(symbolCategory)] = lineData.getItemVisual(idx, symbolCategory);
  27118. }, this);
  27119. this._updateCommonStl(lineData, idx, seriesScope);
  27120. };
  27121. lineProto.updateData = function (lineData, idx, seriesScope) {
  27122. var seriesModel = lineData.hostModel;
  27123. var line = this.childOfName('line');
  27124. var linePoints = lineData.getItemLayout(idx);
  27125. var target = {
  27126. shape: {}
  27127. };
  27128. setLinePoints(target.shape, linePoints);
  27129. graphic.updateProps(line, target, seriesModel, idx);
  27130. zrUtil.each(SYMBOL_CATEGORIES, function (symbolCategory) {
  27131. var symbolType = lineData.getItemVisual(idx, symbolCategory);
  27132. var key = makeSymbolTypeKey(symbolCategory);
  27133. // Symbol changed
  27134. if (this[key] !== symbolType) {
  27135. this.remove(this.childOfName(symbolCategory));
  27136. var symbol = createSymbol(symbolCategory, lineData, idx);
  27137. this.add(symbol);
  27138. }
  27139. this[key] = symbolType;
  27140. }, this);
  27141. this._updateCommonStl(lineData, idx, seriesScope);
  27142. };
  27143. lineProto._updateCommonStl = function (lineData, idx, seriesScope) {
  27144. var seriesModel = lineData.hostModel;
  27145. var line = this.childOfName('line');
  27146. var lineStyle = seriesScope && seriesScope.lineStyle;
  27147. var hoverLineStyle = seriesScope && seriesScope.hoverLineStyle;
  27148. var labelModel = seriesScope && seriesScope.labelModel;
  27149. var hoverLabelModel = seriesScope && seriesScope.hoverLabelModel;
  27150. // Optimization for large dataset
  27151. if (!seriesScope || lineData.hasItemOption) {
  27152. var itemModel = lineData.getItemModel(idx);
  27153. lineStyle = itemModel.getModel('lineStyle.normal').getLineStyle();
  27154. hoverLineStyle = itemModel.getModel('lineStyle.emphasis').getLineStyle();
  27155. labelModel = itemModel.getModel('label.normal');
  27156. hoverLabelModel = itemModel.getModel('label.emphasis');
  27157. }
  27158. var visualColor = lineData.getItemVisual(idx, 'color');
  27159. var visualOpacity = zrUtil.retrieve(
  27160. lineData.getItemVisual(idx, 'opacity'),
  27161. lineStyle.opacity,
  27162. 1
  27163. );
  27164. line.useStyle(zrUtil.defaults(
  27165. {
  27166. strokeNoScale: true,
  27167. fill: 'none',
  27168. stroke: visualColor,
  27169. opacity: visualOpacity
  27170. },
  27171. lineStyle
  27172. ));
  27173. line.hoverStyle = hoverLineStyle;
  27174. // Update symbol
  27175. zrUtil.each(SYMBOL_CATEGORIES, function (symbolCategory) {
  27176. var symbol = this.childOfName(symbolCategory);
  27177. if (symbol) {
  27178. symbol.setColor(visualColor);
  27179. symbol.setStyle({
  27180. opacity: visualOpacity
  27181. });
  27182. }
  27183. }, this);
  27184. var showLabel = labelModel.getShallow('show');
  27185. var hoverShowLabel = hoverLabelModel.getShallow('show');
  27186. var label = this.childOfName('label');
  27187. var defaultLabelColor;
  27188. var defaultText;
  27189. if (showLabel || hoverShowLabel) {
  27190. var rawVal = seriesModel.getRawValue(idx);
  27191. defaultText = rawVal == null
  27192. ? defaultText = lineData.getName(idx)
  27193. : isFinite(rawVal)
  27194. ? numberUtil.round(rawVal)
  27195. : rawVal;
  27196. defaultLabelColor = visualColor || '#000';
  27197. }
  27198. // label.afterUpdate = lineAfterUpdate;
  27199. if (showLabel) {
  27200. var textStyleModel = labelModel.getModel('textStyle');
  27201. label.setStyle({
  27202. text: zrUtil.retrieve(
  27203. seriesModel.getFormattedLabel(idx, 'normal', lineData.dataType),
  27204. defaultText
  27205. ),
  27206. textFont: textStyleModel.getFont(),
  27207. fill: textStyleModel.getTextColor() || defaultLabelColor
  27208. });
  27209. label.__textAlign = textStyleModel.get('align');
  27210. label.__verticalAlign = textStyleModel.get('baseline');
  27211. label.__position = labelModel.get('position');
  27212. }
  27213. else {
  27214. label.setStyle('text', '');
  27215. }
  27216. if (hoverShowLabel) {
  27217. var textStyleHoverModel = hoverLabelModel.getModel('textStyle');
  27218. label.hoverStyle = {
  27219. text: zrUtil.retrieve(
  27220. seriesModel.getFormattedLabel(idx, 'emphasis', lineData.dataType),
  27221. defaultText
  27222. ),
  27223. textFont: textStyleHoverModel.getFont(),
  27224. fill: textStyleHoverModel.getTextColor() || defaultLabelColor
  27225. };
  27226. }
  27227. else {
  27228. label.hoverStyle = {
  27229. text: ''
  27230. };
  27231. }
  27232. label.ignore = !showLabel && !hoverShowLabel;
  27233. graphic.setHoverStyle(this);
  27234. };
  27235. lineProto.updateLayout = function (lineData, idx) {
  27236. this.setLinePoints(lineData.getItemLayout(idx));
  27237. };
  27238. lineProto.setLinePoints = function (points) {
  27239. var linePath = this.childOfName('line');
  27240. setLinePoints(linePath.shape, points);
  27241. linePath.dirty();
  27242. };
  27243. zrUtil.inherits(Line, graphic.Group);
  27244. module.exports = Line;
  27245. /***/ },
  27246. /* 204 */
  27247. /***/ function(module, exports, __webpack_require__) {
  27248. /**
  27249. * Line path for bezier and straight line draw
  27250. */
  27251. var graphic = __webpack_require__(43);
  27252. var vec2 = __webpack_require__(10);
  27253. var straightLineProto = graphic.Line.prototype;
  27254. var bezierCurveProto = graphic.BezierCurve.prototype;
  27255. function isLine(shape) {
  27256. return isNaN(+shape.cpx1) || isNaN(+shape.cpy1);
  27257. }
  27258. module.exports = graphic.extendShape({
  27259. type: 'ec-line',
  27260. style: {
  27261. stroke: '#000',
  27262. fill: null
  27263. },
  27264. shape: {
  27265. x1: 0,
  27266. y1: 0,
  27267. x2: 0,
  27268. y2: 0,
  27269. percent: 1,
  27270. cpx1: null,
  27271. cpy1: null
  27272. },
  27273. buildPath: function (ctx, shape) {
  27274. (isLine(shape) ? straightLineProto : bezierCurveProto).buildPath(ctx, shape);
  27275. },
  27276. pointAt: function (t) {
  27277. return isLine(this.shape)
  27278. ? straightLineProto.pointAt.call(this, t)
  27279. : bezierCurveProto.pointAt.call(this, t);
  27280. },
  27281. tangentAt: function (t) {
  27282. var shape = this.shape;
  27283. var p = isLine(shape)
  27284. ? [shape.x2 - shape.x1, shape.y2 - shape.y1]
  27285. : bezierCurveProto.tangentAt.call(this, t);
  27286. return vec2.normalize(p, p);
  27287. }
  27288. });
  27289. /***/ },
  27290. /* 205 */,
  27291. /* 206 */,
  27292. /* 207 */,
  27293. /* 208 */,
  27294. /* 209 */,
  27295. /* 210 */,
  27296. /* 211 */,
  27297. /* 212 */,
  27298. /* 213 */,
  27299. /* 214 */,
  27300. /* 215 */,
  27301. /* 216 */,
  27302. /* 217 */,
  27303. /* 218 */,
  27304. /* 219 */,
  27305. /* 220 */,
  27306. /* 221 */,
  27307. /* 222 */,
  27308. /* 223 */,
  27309. /* 224 */,
  27310. /* 225 */,
  27311. /* 226 */,
  27312. /* 227 */,
  27313. /* 228 */,
  27314. /* 229 */,
  27315. /* 230 */,
  27316. /* 231 */,
  27317. /* 232 */,
  27318. /* 233 */,
  27319. /* 234 */,
  27320. /* 235 */,
  27321. /* 236 */
  27322. /***/ function(module, exports, __webpack_require__) {
  27323. /**
  27324. * Box selection tool.
  27325. *
  27326. * @module echarts/component/helper/BrushController
  27327. */
  27328. var Eventful = __webpack_require__(33);
  27329. var zrUtil = __webpack_require__(4);
  27330. var BoundingRect = __webpack_require__(9);
  27331. var graphic = __webpack_require__(43);
  27332. var interactionMutex = __webpack_require__(178);
  27333. var DataDiffer = __webpack_require__(99);
  27334. var curry = zrUtil.curry;
  27335. var each = zrUtil.each;
  27336. var map = zrUtil.map;
  27337. var mathMin = Math.min;
  27338. var mathMax = Math.max;
  27339. var mathPow = Math.pow;
  27340. var COVER_Z = 10000;
  27341. var UNSELECT_THRESHOLD = 6;
  27342. var MIN_RESIZE_LINE_WIDTH = 6;
  27343. var MUTEX_RESOURCE_KEY = 'globalPan';
  27344. var DIRECTION_MAP = {
  27345. w: [0, 0],
  27346. e: [0, 1],
  27347. n: [1, 0],
  27348. s: [1, 1]
  27349. };
  27350. var CURSOR_MAP = {
  27351. w: 'ew',
  27352. e: 'ew',
  27353. n: 'ns',
  27354. s: 'ns',
  27355. ne: 'nesw',
  27356. sw: 'nesw',
  27357. nw: 'nwse',
  27358. se: 'nwse'
  27359. };
  27360. var DEFAULT_BRUSH_OPT = {
  27361. brushStyle: {
  27362. lineWidth: 2,
  27363. stroke: 'rgba(0,0,0,0.3)',
  27364. fill: 'rgba(0,0,0,0.1)'
  27365. },
  27366. transformable: true,
  27367. brushMode: 'single',
  27368. removeOnClick: false
  27369. };
  27370. var baseUID = 0;
  27371. /**
  27372. * @alias module:echarts/component/helper/BrushController
  27373. * @constructor
  27374. * @mixin {module:zrender/mixin/Eventful}
  27375. * @event module:echarts/component/helper/BrushController#brush
  27376. * params:
  27377. * areas: Array.<Array>, coord relates to container group,
  27378. * If no container specified, to global.
  27379. * opt {
  27380. * isEnd: boolean,
  27381. * removeOnClick: boolean
  27382. * }
  27383. *
  27384. * @param {module:zrender/zrender~ZRender} zr
  27385. */
  27386. function BrushController(zr) {
  27387. if (true) {
  27388. zrUtil.assert(zr);
  27389. }
  27390. Eventful.call(this);
  27391. /**
  27392. * @type {module:zrender/zrender~ZRender}
  27393. * @private
  27394. */
  27395. this._zr = zr;
  27396. /**
  27397. * @type {module:zrender/container/Group}
  27398. * @readOnly
  27399. */
  27400. this.group = new graphic.Group();
  27401. /**
  27402. * Only for drawing (after enabledBrush).
  27403. * @private
  27404. * @type {string}
  27405. */
  27406. this._brushType;
  27407. /**
  27408. * Only for drawing (after enabledBrush).
  27409. * @private
  27410. * @type {Object}
  27411. */
  27412. this._brushOption;
  27413. /**
  27414. * @private
  27415. * @type {Object}
  27416. */
  27417. this._panels;
  27418. /**
  27419. * @private
  27420. * @type {Array.<nubmer>}
  27421. */
  27422. this._track = [];
  27423. /**
  27424. * @private
  27425. * @type {boolean}
  27426. */
  27427. this._dragging;
  27428. /**
  27429. * @private
  27430. * @type {Array}
  27431. */
  27432. this._covers = [];
  27433. /**
  27434. * @private
  27435. * @type {moudule:zrender/container/Group}
  27436. */
  27437. this._creatingCover;
  27438. /**
  27439. * true means global panel
  27440. * @private
  27441. * @type {module:zrender/container/Group|boolean}
  27442. */
  27443. this._creatingPanel;
  27444. /**
  27445. * @private
  27446. * @type {boolean}
  27447. */
  27448. this._enableGlobalPan;
  27449. /**
  27450. * @private
  27451. * @type {boolean}
  27452. */
  27453. if (true) {
  27454. this._mounted;
  27455. }
  27456. /**
  27457. * @private
  27458. * @type {string}
  27459. */
  27460. this._uid = 'brushController_' + baseUID++;
  27461. /**
  27462. * @private
  27463. * @type {Object}
  27464. */
  27465. this._handlers = {};
  27466. each(mouseHandlers, function (handler, eventName) {
  27467. this._handlers[eventName] = zrUtil.bind(handler, this);
  27468. }, this);
  27469. }
  27470. BrushController.prototype = {
  27471. constructor: BrushController,
  27472. /**
  27473. * If set to null/undefined/false, select disabled.
  27474. * @param {Object} brushOption
  27475. * @param {string|boolean} brushOption.brushType 'line', 'rect', 'polygon' or false
  27476. * If pass false/null/undefined, disable brush.
  27477. * @param {number} [brushOption.brushMode='single'] 'single' or 'multiple'
  27478. * @param {boolean} [brushOption.transformable=true]
  27479. * @param {boolean} [brushOption.removeOnClick=false]
  27480. * @param {Object} [brushOption.brushStyle]
  27481. * @param {number} [brushOption.brushStyle.width]
  27482. * @param {number} [brushOption.brushStyle.lineWidth]
  27483. * @param {string} [brushOption.brushStyle.stroke]
  27484. * @param {string} [brushOption.brushStyle.fill]
  27485. */
  27486. enableBrush: function (brushOption) {
  27487. if (true) {
  27488. zrUtil.assert(this._mounted);
  27489. }
  27490. this._brushType && doDisableBrush(this);
  27491. brushOption.brushType && doEnableBrush(this, brushOption);
  27492. return this;
  27493. },
  27494. /**
  27495. * @param {Array.<Object>} panelOpts If not pass, it is global brush.
  27496. * Each items: {panelId, rect}
  27497. */
  27498. setPanels: function (panelOpts) {
  27499. var oldPanels = this._panels || {};
  27500. var newPanels = this._panels = panelOpts && panelOpts.length && {};
  27501. var thisGroup = this.group;
  27502. newPanels && each(panelOpts, function (panelOpt) {
  27503. var panelId = panelOpt.panelId;
  27504. var panel = oldPanels[panelId];
  27505. if (!panel) {
  27506. panel = new graphic.Rect({
  27507. silent: true,
  27508. invisible: true
  27509. });
  27510. thisGroup.add(panel);
  27511. }
  27512. var rect = panelOpt.rect;
  27513. // Using BoundingRect to normalize negative width/height.
  27514. if (!(rect instanceof BoundingRect)) {
  27515. rect = BoundingRect.create(rect);
  27516. }
  27517. panel.attr('shape', rect.plain());
  27518. panel.__brushPanelId = panelId;
  27519. newPanels[panelId] = panel;
  27520. oldPanels[panelId] = null;
  27521. });
  27522. each(oldPanels, function (panel) {
  27523. panel && thisGroup.remove(panel);
  27524. });
  27525. return this;
  27526. },
  27527. /**
  27528. * @param {Object} [opt]
  27529. * @return {boolean} [opt.enableGlobalPan=false]
  27530. * @return {boolean} [opt.position=[0, 0]]
  27531. * @return {boolean} [opt.rotation=0]
  27532. * @return {boolean} [opt.scale=[1, 1]]
  27533. */
  27534. mount: function (opt) {
  27535. opt = opt || {};
  27536. if (true) {
  27537. this._mounted = true; // should be at first.
  27538. }
  27539. this._enableGlobalPan = opt.enableGlobalPan;
  27540. var thisGroup = this.group;
  27541. this._zr.add(thisGroup);
  27542. thisGroup.attr({
  27543. position: opt.position || [0, 0],
  27544. rotation: opt.rotation || 0,
  27545. scale: opt.scale || [1, 1]
  27546. });
  27547. return this;
  27548. },
  27549. eachCover: function (cb, context) {
  27550. each(this._covers, cb, context);
  27551. },
  27552. /**
  27553. * Update covers.
  27554. * @param {Array.<Object>} brushOptionList Like:
  27555. * [
  27556. * {id: 'xx', brushType: 'line', range: [23, 44], brushStyle, transformable},
  27557. * {id: 'yy', brushType: 'rect', range: [[23, 44], [23, 54]]},
  27558. * ...
  27559. * ]
  27560. * `brushType` is required in each cover info.
  27561. * `id` is not mandatory.
  27562. * `brushStyle`, `transformable` is not mandatory, use DEFAULT_BRUSH_OPT by default.
  27563. * If brushOptionList is null/undefined, all covers removed.
  27564. */
  27565. updateCovers: function (brushOptionList) {
  27566. if (true) {
  27567. zrUtil.assert(this._mounted);
  27568. }
  27569. brushOptionList = zrUtil.map(brushOptionList, function (brushOption) {
  27570. return zrUtil.merge(zrUtil.clone(DEFAULT_BRUSH_OPT), brushOption, true);
  27571. });
  27572. var tmpIdPrefix = '\0-brush-index-';
  27573. var oldCovers = this._covers;
  27574. var newCovers = this._covers = [];
  27575. var controller = this;
  27576. var creatingCover = this._creatingCover;
  27577. (new DataDiffer(oldCovers, brushOptionList, oldGetKey, getKey))
  27578. .add(addOrUpdate)
  27579. .update(addOrUpdate)
  27580. .remove(remove)
  27581. .execute();
  27582. return this;
  27583. function getKey(brushOption, index) {
  27584. return (brushOption.id != null ? brushOption.id : tmpIdPrefix + index)
  27585. + '-' + brushOption.brushType;
  27586. }
  27587. function oldGetKey(cover, index) {
  27588. return getKey(cover.__brushOption, index);
  27589. }
  27590. function addOrUpdate(newIndex, oldIndex) {
  27591. var newBrushOption = brushOptionList[newIndex];
  27592. // Consider setOption in event listener of brushSelect,
  27593. // where updating cover when creating should be forbiden.
  27594. if (oldIndex != null && oldCovers[oldIndex] === creatingCover) {
  27595. newCovers[newIndex] = oldCovers[oldIndex];
  27596. }
  27597. else {
  27598. var cover = newCovers[newIndex] = oldIndex != null
  27599. ? (
  27600. oldCovers[oldIndex].__brushOption = newBrushOption,
  27601. oldCovers[oldIndex]
  27602. )
  27603. : endCreating(controller, createCover(controller, newBrushOption));
  27604. updateCoverAfterCreation(controller, cover);
  27605. }
  27606. }
  27607. function remove(oldIndex) {
  27608. if (oldCovers[oldIndex] !== creatingCover) {
  27609. controller.group.remove(oldCovers[oldIndex]);
  27610. }
  27611. }
  27612. },
  27613. unmount: function () {
  27614. this.enableBrush(false);
  27615. // container may 'removeAll' outside.
  27616. clearCovers(this);
  27617. this._zr.remove(this.group);
  27618. if (true) {
  27619. this._mounted = false; // should be at last.
  27620. }
  27621. return this;
  27622. },
  27623. dispose: function () {
  27624. this.unmount();
  27625. this.off();
  27626. }
  27627. };
  27628. zrUtil.mixin(BrushController, Eventful);
  27629. function doEnableBrush(controller, brushOption) {
  27630. var zr = controller._zr;
  27631. // Consider roam, which takes globalPan too.
  27632. if (!controller._enableGlobalPan) {
  27633. interactionMutex.take(zr, MUTEX_RESOURCE_KEY, controller._uid);
  27634. }
  27635. each(controller._handlers, function (handler, eventName) {
  27636. zr.on(eventName, handler);
  27637. });
  27638. controller._brushType = brushOption.brushType;
  27639. controller._brushOption = zrUtil.merge(zrUtil.clone(DEFAULT_BRUSH_OPT), brushOption, true);
  27640. }
  27641. function doDisableBrush(controller) {
  27642. var zr = controller._zr;
  27643. interactionMutex.release(zr, MUTEX_RESOURCE_KEY, controller._uid);
  27644. each(controller._handlers, function (handler, eventName) {
  27645. zr.off(eventName, handler);
  27646. });
  27647. controller._brushType = controller._brushOption = null;
  27648. }
  27649. function createCover(controller, brushOption) {
  27650. var cover = coverRenderers[brushOption.brushType].createCover(controller, brushOption);
  27651. updateZ(cover);
  27652. cover.__brushOption = brushOption;
  27653. controller.group.add(cover);
  27654. return cover;
  27655. }
  27656. function endCreating(controller, creatingCover) {
  27657. var coverRenderer = getCoverRenderer(creatingCover);
  27658. if (coverRenderer.endCreating) {
  27659. coverRenderer.endCreating(controller, creatingCover);
  27660. updateZ(creatingCover);
  27661. }
  27662. return creatingCover;
  27663. }
  27664. function updateCoverShape(controller, cover) {
  27665. var brushOption = cover.__brushOption;
  27666. getCoverRenderer(cover).updateCoverShape(
  27667. controller, cover, brushOption.range, brushOption
  27668. );
  27669. }
  27670. function updateZ(group) {
  27671. group.traverse(function (el) {
  27672. el.z = COVER_Z;
  27673. el.z2 = COVER_Z; // Consider in given container.
  27674. });
  27675. }
  27676. function updateCoverAfterCreation(controller, cover) {
  27677. getCoverRenderer(cover).updateCommon(controller, cover);
  27678. updateCoverShape(controller, cover);
  27679. }
  27680. function getCoverRenderer(cover) {
  27681. return coverRenderers[cover.__brushOption.brushType];
  27682. }
  27683. function getPanelByPoint(controller, x, y) {
  27684. var panels = controller._panels;
  27685. if (!panels) {
  27686. return true; // Global panel
  27687. }
  27688. var panel;
  27689. each(panels, function (pn) {
  27690. pn.contain(x, y) && (panel = pn);
  27691. });
  27692. return panel;
  27693. }
  27694. function getPanelByCover(controller, cover) {
  27695. var panels = controller._panels;
  27696. if (!panels) {
  27697. return true; // Global panel
  27698. }
  27699. var panelId = cover.__brushOption.panelId;
  27700. // User may give cover without coord sys info,
  27701. // which is then treated as global panel.
  27702. return panelId != null ? panels[panelId] : true;
  27703. }
  27704. function clearCovers(controller) {
  27705. var covers = controller._covers;
  27706. var originalLength = covers.length;
  27707. each(covers, function (cover) {
  27708. controller.group.remove(cover);
  27709. }, controller);
  27710. covers.length = 0;
  27711. return !!originalLength;
  27712. }
  27713. function trigger(controller, opt) {
  27714. var areas = map(controller._covers, function (cover) {
  27715. var brushOption = cover.__brushOption;
  27716. var range = zrUtil.clone(brushOption.range);
  27717. return {
  27718. brushType: brushOption.brushType,
  27719. panelId: brushOption.panelId,
  27720. range: range
  27721. };
  27722. });
  27723. controller.trigger('brush', areas, {
  27724. isEnd: !!opt.isEnd,
  27725. removeOnClick: !!opt.removeOnClick
  27726. });
  27727. }
  27728. function shouldShowCover(controller) {
  27729. var track = controller._track;
  27730. if (!track.length) {
  27731. return false;
  27732. }
  27733. var p2 = track[track.length - 1];
  27734. var p1 = track[0];
  27735. var dx = p2[0] - p1[0];
  27736. var dy = p2[1] - p1[1];
  27737. var dist = mathPow(dx * dx + dy * dy, 0.5);
  27738. return dist > UNSELECT_THRESHOLD;
  27739. }
  27740. function getTrackEnds(track) {
  27741. var tail = track.length - 1;
  27742. tail < 0 && (tail = 0);
  27743. return [track[0], track[tail]];
  27744. }
  27745. function createBaseRectCover(doDrift, controller, brushOption, edgeNames) {
  27746. var cover = new graphic.Group();
  27747. cover.add(new graphic.Rect({
  27748. name: 'main',
  27749. style: makeStyle(brushOption),
  27750. silent: true,
  27751. draggable: true,
  27752. cursor: 'move',
  27753. drift: curry(doDrift, controller, cover, 'nswe'),
  27754. ondragend: curry(trigger, controller, {isEnd: true})
  27755. }));
  27756. each(
  27757. edgeNames,
  27758. function (name) {
  27759. cover.add(new graphic.Rect({
  27760. name: name,
  27761. style: {opacity: 0},
  27762. draggable: true,
  27763. silent: true,
  27764. invisible: true,
  27765. drift: curry(doDrift, controller, cover, name),
  27766. ondragend: curry(trigger, controller, {isEnd: true})
  27767. }));
  27768. }
  27769. );
  27770. return cover;
  27771. }
  27772. function updateBaseRect(controller, cover, localRange, brushOption) {
  27773. var lineWidth = brushOption.brushStyle.lineWidth || 0;
  27774. var handleSize = mathMax(lineWidth, MIN_RESIZE_LINE_WIDTH);
  27775. var x = localRange[0][0];
  27776. var y = localRange[1][0];
  27777. var xa = x - lineWidth / 2;
  27778. var ya = y - lineWidth / 2;
  27779. var x2 = localRange[0][1];
  27780. var y2 = localRange[1][1];
  27781. var x2a = x2 - handleSize + lineWidth / 2;
  27782. var y2a = y2 - handleSize + lineWidth / 2;
  27783. var width = x2 - x;
  27784. var height = y2 - y;
  27785. var widtha = width + lineWidth;
  27786. var heighta = height + lineWidth;
  27787. updateRectShape(controller, cover, 'main', x, y, width, height);
  27788. if (brushOption.transformable) {
  27789. updateRectShape(controller, cover, 'w', xa, ya, handleSize, heighta);
  27790. updateRectShape(controller, cover, 'e', x2a, ya, handleSize, heighta);
  27791. updateRectShape(controller, cover, 'n', xa, ya, widtha, handleSize);
  27792. updateRectShape(controller, cover, 's', xa, y2a, widtha, handleSize);
  27793. updateRectShape(controller, cover, 'nw', xa, ya, handleSize, handleSize);
  27794. updateRectShape(controller, cover, 'ne', x2a, ya, handleSize, handleSize);
  27795. updateRectShape(controller, cover, 'sw', xa, y2a, handleSize, handleSize);
  27796. updateRectShape(controller, cover, 'se', x2a, y2a, handleSize, handleSize);
  27797. }
  27798. }
  27799. function updateCommon(controller, cover) {
  27800. var brushOption = cover.__brushOption;
  27801. var transformable = brushOption.transformable;
  27802. var mainEl = cover.childAt(0);
  27803. mainEl.useStyle(makeStyle(brushOption));
  27804. mainEl.attr({
  27805. silent: !transformable,
  27806. cursor: transformable ? 'move' : 'default'
  27807. });
  27808. each(
  27809. ['w', 'e', 'n', 's', 'se', 'sw', 'ne', 'nw'],
  27810. function (name) {
  27811. var el = cover.childOfName(name);
  27812. var globalDir = getGlobalDirection(controller, name);
  27813. el && el.attr({
  27814. silent: !transformable,
  27815. invisible: !transformable,
  27816. cursor: transformable ? CURSOR_MAP[globalDir] + '-resize' : null
  27817. });
  27818. }
  27819. );
  27820. }
  27821. function updateRectShape(controller, cover, name, x, y, w, h) {
  27822. var el = cover.childOfName(name);
  27823. el && el.setShape(pointsToRect(
  27824. clipByPanel(controller, cover, [[x, y], [x + w, y + h]])
  27825. ));
  27826. }
  27827. function makeStyle(brushOption) {
  27828. return zrUtil.defaults({strokeNoScale: true}, brushOption.brushStyle);
  27829. }
  27830. function formatRectRange(x, y, x2, y2) {
  27831. var min = [mathMin(x, x2), mathMin(y, y2)];
  27832. var max = [mathMax(x, x2), mathMax(y, y2)];
  27833. return [
  27834. [min[0], max[0]], // x range
  27835. [min[1], max[1]] // y range
  27836. ];
  27837. }
  27838. function getTransform(controller) {
  27839. return graphic.getTransform(controller.group);
  27840. }
  27841. function getGlobalDirection(controller, localDirection) {
  27842. if (localDirection.length > 1) {
  27843. localDirection = localDirection.split('');
  27844. var globalDir = [
  27845. getGlobalDirection(controller, localDirection[0]),
  27846. getGlobalDirection(controller, localDirection[1])
  27847. ];
  27848. (globalDir[0] === 'e' || globalDir[0] === 'w') && globalDir.reverse();
  27849. return globalDir.join('');
  27850. }
  27851. else {
  27852. var map = {w: 'left', e: 'right', n: 'top', s: 'bottom'};
  27853. var inverseMap = {left: 'w', right: 'e', top: 'n', bottom: 's'};
  27854. var globalDir = graphic.transformDirection(
  27855. map[localDirection], getTransform(controller)
  27856. );
  27857. return inverseMap[globalDir];
  27858. }
  27859. }
  27860. function driftRect(toRectRange, fromRectRange, controller, cover, name, dx, dy, e) {
  27861. var brushOption = cover.__brushOption;
  27862. var rectRange = toRectRange(brushOption.range);
  27863. var localDelta = toLocalDelta(controller, dx, dy);
  27864. each(name.split(''), function (namePart) {
  27865. var ind = DIRECTION_MAP[namePart];
  27866. rectRange[ind[0]][ind[1]] += localDelta[ind[0]];
  27867. });
  27868. brushOption.range = fromRectRange(formatRectRange(
  27869. rectRange[0][0], rectRange[1][0], rectRange[0][1], rectRange[1][1]
  27870. ));
  27871. updateCoverAfterCreation(controller, cover);
  27872. trigger(controller, {isEnd: false});
  27873. }
  27874. function driftPolygon(controller, cover, dx, dy, e) {
  27875. var range = cover.__brushOption.range;
  27876. var localDelta = toLocalDelta(controller, dx, dy);
  27877. each(range, function (point) {
  27878. point[0] += localDelta[0];
  27879. point[1] += localDelta[1];
  27880. });
  27881. updateCoverAfterCreation(controller, cover);
  27882. trigger(controller, {isEnd: false});
  27883. }
  27884. function toLocalDelta(controller, dx, dy) {
  27885. var thisGroup = controller.group;
  27886. var localD = thisGroup.transformCoordToLocal(dx, dy);
  27887. var localZero = thisGroup.transformCoordToLocal(0, 0);
  27888. return [localD[0] - localZero[0], localD[1] - localZero[1]];
  27889. }
  27890. function clipByPanel(controller, cover, data) {
  27891. var panel = getPanelByCover(controller, cover);
  27892. if (panel === true) { // Global panel
  27893. return zrUtil.clone(data);
  27894. }
  27895. var panelRect = panel.getBoundingRect();
  27896. return zrUtil.map(data, function (point) {
  27897. var x = point[0];
  27898. x = mathMax(x, panelRect.x);
  27899. x = mathMin(x, panelRect.x + panelRect.width);
  27900. var y = point[1];
  27901. y = mathMax(y, panelRect.y);
  27902. y = mathMin(y, panelRect.y + panelRect.height);
  27903. return [x, y];
  27904. });
  27905. }
  27906. function pointsToRect(points) {
  27907. var xmin = mathMin(points[0][0], points[1][0]);
  27908. var ymin = mathMin(points[0][1], points[1][1]);
  27909. var xmax = mathMax(points[0][0], points[1][0]);
  27910. var ymax = mathMax(points[0][1], points[1][1]);
  27911. return {
  27912. x: xmin,
  27913. y: ymin,
  27914. width: xmax - xmin,
  27915. height: ymax - ymin
  27916. };
  27917. }
  27918. function resetCursor(controller, e) {
  27919. var x = e.offsetX;
  27920. var y = e.offsetY;
  27921. var zr = controller._zr;
  27922. if (controller._brushType) { // If active
  27923. var panels = controller._panels;
  27924. var covers = controller._covers;
  27925. var inCover;
  27926. for (var i = 0; i < covers.length; i++) {
  27927. if (coverRenderers[covers[i].__brushOption.brushType].contain(covers[i], x, y)) {
  27928. inCover = true;
  27929. break;
  27930. }
  27931. }
  27932. if (!inCover) {
  27933. if (panels) { // Brush on panels
  27934. each(panels, function (panel) {
  27935. panel.contain(x, y) && zr.setCursorStyle('crosshair');
  27936. });
  27937. }
  27938. else { // Global brush
  27939. zr.setCursorStyle('crosshair');
  27940. }
  27941. }
  27942. }
  27943. }
  27944. function preventDefault(e) {
  27945. var rawE = e.event;
  27946. rawE.preventDefault && rawE.preventDefault();
  27947. }
  27948. function mainShapeContain(cover, x, y) {
  27949. return cover.childOfName('main').contain(x, y);
  27950. }
  27951. function updateCoverByMouse(controller, e, isEnd) {
  27952. var x = e.offsetX;
  27953. var y = e.offsetY;
  27954. var creatingCover = controller._creatingCover;
  27955. var panel = controller._creatingPanel;
  27956. var thisBrushOption = controller._brushOption;
  27957. var eventParams;
  27958. controller._track.push(controller.group.transformCoordToLocal(x, y));
  27959. if (shouldShowCover(controller) || creatingCover) {
  27960. if (panel && !creatingCover) {
  27961. thisBrushOption.brushMode === 'single' && clearCovers(controller);
  27962. var brushOption = zrUtil.clone(thisBrushOption);
  27963. brushOption.panelId = panel === true ? null : panel.__brushPanelId;
  27964. creatingCover = controller._creatingCover = createCover(controller, brushOption);
  27965. controller._covers.push(creatingCover);
  27966. }
  27967. if (creatingCover) {
  27968. var coverRenderer = coverRenderers[controller._brushType];
  27969. var coverBrushOption = creatingCover.__brushOption;
  27970. coverBrushOption.range = coverRenderer.getCreatingRange(
  27971. clipByPanel(controller, creatingCover, controller._track)
  27972. );
  27973. if (isEnd) {
  27974. endCreating(controller, creatingCover);
  27975. coverRenderer.updateCommon(controller, creatingCover);
  27976. }
  27977. updateCoverShape(controller, creatingCover);
  27978. eventParams = {isEnd: isEnd};
  27979. }
  27980. }
  27981. else if (
  27982. isEnd
  27983. && thisBrushOption.brushMode === 'single'
  27984. && thisBrushOption.removeOnClick
  27985. ) {
  27986. // Help user to remove covers easily, only by a tiny drag, in 'single' mode.
  27987. // But a single click do not clear covers, because user may have casual
  27988. // clicks (for example, click on other component and do not expect covers
  27989. // disappear).
  27990. // Only some cover removed, trigger action, but not every click trigger action.
  27991. if (getPanelByPoint(controller, x, y) && clearCovers(controller)) {
  27992. eventParams = {isEnd: isEnd, removeOnClick: true};
  27993. }
  27994. }
  27995. return eventParams;
  27996. }
  27997. var mouseHandlers = {
  27998. mousedown: function (e) {
  27999. if (this._dragging) {
  28000. // In case some browser do not support globalOut,
  28001. // and release mose out side the browser.
  28002. handleDragEnd.call(this, e);
  28003. }
  28004. else if (!e.target || !e.target.draggable) {
  28005. preventDefault(e);
  28006. var x = e.offsetX;
  28007. var y = e.offsetY;
  28008. this._creatingCover = null;
  28009. var panel = this._creatingPanel = getPanelByPoint(this, x, y);
  28010. if (panel) {
  28011. this._dragging = true;
  28012. this._track = [this.group.transformCoordToLocal(x, y)];
  28013. }
  28014. }
  28015. },
  28016. mousemove: function (e) {
  28017. // set Cursor
  28018. resetCursor(this, e);
  28019. if (this._dragging) {
  28020. preventDefault(e);
  28021. var eventParams = updateCoverByMouse(this, e, false);
  28022. eventParams && trigger(this, eventParams);
  28023. }
  28024. },
  28025. mouseup: handleDragEnd //,
  28026. // FIXME
  28027. // in tooltip, globalout should not be triggered.
  28028. // globalout: handleDragEnd
  28029. };
  28030. function handleDragEnd(e) {
  28031. if (this._dragging) {
  28032. preventDefault(e);
  28033. var eventParams = updateCoverByMouse(this, e, true);
  28034. this._dragging = false;
  28035. this._track = [];
  28036. this._creatingCover = null;
  28037. // trigger event shoule be at final, after procedure will be nested.
  28038. eventParams && trigger(this, eventParams);
  28039. }
  28040. }
  28041. /**
  28042. * key: brushType
  28043. * @type {Object}
  28044. */
  28045. var coverRenderers = {
  28046. lineX: getLineRenderer(0),
  28047. lineY: getLineRenderer(1),
  28048. rect: {
  28049. createCover: function (controller, brushOption) {
  28050. return createBaseRectCover(
  28051. curry(
  28052. driftRect,
  28053. function (range) {
  28054. return range;
  28055. },
  28056. function (range) {
  28057. return range;
  28058. }
  28059. ),
  28060. controller,
  28061. brushOption,
  28062. ['w', 'e', 'n', 's', 'se', 'sw', 'ne', 'nw']
  28063. );
  28064. },
  28065. getCreatingRange: function (localTrack) {
  28066. var ends = getTrackEnds(localTrack);
  28067. return formatRectRange(ends[1][0], ends[1][1], ends[0][0], ends[0][1]);
  28068. },
  28069. updateCoverShape: function (controller, cover, localRange, brushOption) {
  28070. updateBaseRect(controller, cover, localRange, brushOption);
  28071. },
  28072. updateCommon: updateCommon,
  28073. contain: mainShapeContain
  28074. },
  28075. polygon: {
  28076. createCover: function (controller, brushOption) {
  28077. var cover = new graphic.Group();
  28078. // Do not use graphic.Polygon because graphic.Polyline do not close the
  28079. // border of the shape when drawing, which is a better experience for user.
  28080. cover.add(new graphic.Polyline({
  28081. name: 'main',
  28082. style: makeStyle(brushOption),
  28083. silent: true
  28084. }));
  28085. return cover;
  28086. },
  28087. getCreatingRange: function (localTrack) {
  28088. return localTrack;
  28089. },
  28090. endCreating: function (controller, cover) {
  28091. cover.remove(cover.childAt(0));
  28092. // Use graphic.Polygon close the shape.
  28093. cover.add(new graphic.Polygon({
  28094. name: 'main',
  28095. draggable: true,
  28096. drift: curry(driftPolygon, controller, cover),
  28097. ondragend: curry(trigger, controller, {isEnd: true})
  28098. }));
  28099. },
  28100. updateCoverShape: function (controller, cover, localRange, brushOption) {
  28101. cover.childAt(0).setShape({
  28102. points: clipByPanel(controller, cover, localRange)
  28103. });
  28104. },
  28105. updateCommon: updateCommon,
  28106. contain: mainShapeContain
  28107. }
  28108. };
  28109. function getLineRenderer(xyIndex) {
  28110. return {
  28111. createCover: function (controller, brushOption) {
  28112. return createBaseRectCover(
  28113. curry(
  28114. driftRect,
  28115. function (range) {
  28116. var rectRange = [range, [0, 100]];
  28117. xyIndex && rectRange.reverse();
  28118. return rectRange;
  28119. },
  28120. function (rectRange) {
  28121. return rectRange[xyIndex];
  28122. }
  28123. ),
  28124. controller,
  28125. brushOption,
  28126. [['w', 'e'], ['n', 's']][xyIndex]
  28127. );
  28128. },
  28129. getCreatingRange: function (localTrack) {
  28130. var ends = getTrackEnds(localTrack);
  28131. var min = mathMin(ends[0][xyIndex], ends[1][xyIndex]);
  28132. var max = mathMax(ends[0][xyIndex], ends[1][xyIndex]);
  28133. return [min, max];
  28134. },
  28135. updateCoverShape: function (controller, cover, localRange, brushOption) {
  28136. var brushWidth = brushOption.brushStyle.width;
  28137. var otherExtent;
  28138. // If brushWidth not specified, fit the panel.
  28139. if (brushWidth == null) {
  28140. var panel = getPanelByCover(controller, cover);
  28141. var base = 0;
  28142. if (panel !== true) {
  28143. var rect = panel.getBoundingRect();
  28144. brushWidth = xyIndex ? rect.width : rect.height;
  28145. base = xyIndex ? rect.x : rect.y;
  28146. }
  28147. // FIXME
  28148. // do not support global panel yet.
  28149. otherExtent = [base, base + (brushWidth || 0)];
  28150. }
  28151. else {
  28152. otherExtent = [-brushWidth / 2, brushWidth / 2];
  28153. }
  28154. var rectRange = [localRange, otherExtent];
  28155. xyIndex && rectRange.reverse();
  28156. updateBaseRect(controller, cover, rectRange, brushOption);
  28157. },
  28158. updateCommon: updateCommon,
  28159. contain: mainShapeContain
  28160. };
  28161. }
  28162. module.exports = BrushController;
  28163. /***/ },
  28164. /* 237 */,
  28165. /* 238 */,
  28166. /* 239 */,
  28167. /* 240 */,
  28168. /* 241 */,
  28169. /* 242 */,
  28170. /* 243 */,
  28171. /* 244 */,
  28172. /* 245 */,
  28173. /* 246 */,
  28174. /* 247 */,
  28175. /* 248 */,
  28176. /* 249 */,
  28177. /* 250 */,
  28178. /* 251 */,
  28179. /* 252 */,
  28180. /* 253 */,
  28181. /* 254 */,
  28182. /* 255 */,
  28183. /* 256 */,
  28184. /* 257 */,
  28185. /* 258 */,
  28186. /* 259 */,
  28187. /* 260 */,
  28188. /* 261 */,
  28189. /* 262 */,
  28190. /* 263 */,
  28191. /* 264 */,
  28192. /* 265 */,
  28193. /* 266 */,
  28194. /* 267 */,
  28195. /* 268 */,
  28196. /* 269 */,
  28197. /* 270 */,
  28198. /* 271 */,
  28199. /* 272 */,
  28200. /* 273 */,
  28201. /* 274 */,
  28202. /* 275 */,
  28203. /* 276 */,
  28204. /* 277 */,
  28205. /* 278 */,
  28206. /* 279 */,
  28207. /* 280 */,
  28208. /* 281 */,
  28209. /* 282 */,
  28210. /* 283 */,
  28211. /* 284 */,
  28212. /* 285 */,
  28213. /* 286 */,
  28214. /* 287 */,
  28215. /* 288 */,
  28216. /* 289 */
  28217. /***/ function(module, exports) {
  28218. // shim for using process in browser
  28219. var process = module.exports = {};
  28220. // cached from whatever global is present so that test runners that stub it
  28221. // don't break things. But we need to wrap it in a try catch in case it is
  28222. // wrapped in strict mode code which doesn't define any globals. It's inside a
  28223. // function because try/catches deoptimize in certain engines.
  28224. var cachedSetTimeout;
  28225. var cachedClearTimeout;
  28226. function defaultSetTimout() {
  28227. throw new Error('setTimeout has not been defined');
  28228. }
  28229. function defaultClearTimeout () {
  28230. throw new Error('clearTimeout has not been defined');
  28231. }
  28232. (function () {
  28233. try {
  28234. if (typeof setTimeout === 'function') {
  28235. cachedSetTimeout = setTimeout;
  28236. } else {
  28237. cachedSetTimeout = defaultSetTimout;
  28238. }
  28239. } catch (e) {
  28240. cachedSetTimeout = defaultSetTimout;
  28241. }
  28242. try {
  28243. if (typeof clearTimeout === 'function') {
  28244. cachedClearTimeout = clearTimeout;
  28245. } else {
  28246. cachedClearTimeout = defaultClearTimeout;
  28247. }
  28248. } catch (e) {
  28249. cachedClearTimeout = defaultClearTimeout;
  28250. }
  28251. } ())
  28252. function runTimeout(fun) {
  28253. if (cachedSetTimeout === setTimeout) {
  28254. //normal enviroments in sane situations
  28255. return setTimeout(fun, 0);
  28256. }
  28257. // if setTimeout wasn't available but was latter defined
  28258. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  28259. cachedSetTimeout = setTimeout;
  28260. return setTimeout(fun, 0);
  28261. }
  28262. try {
  28263. // when when somebody has screwed with setTimeout but no I.E. maddness
  28264. return cachedSetTimeout(fun, 0);
  28265. } catch(e){
  28266. try {
  28267. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  28268. return cachedSetTimeout.call(null, fun, 0);
  28269. } catch(e){
  28270. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  28271. return cachedSetTimeout.call(this, fun, 0);
  28272. }
  28273. }
  28274. }
  28275. function runClearTimeout(marker) {
  28276. if (cachedClearTimeout === clearTimeout) {
  28277. //normal enviroments in sane situations
  28278. return clearTimeout(marker);
  28279. }
  28280. // if clearTimeout wasn't available but was latter defined
  28281. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  28282. cachedClearTimeout = clearTimeout;
  28283. return clearTimeout(marker);
  28284. }
  28285. try {
  28286. // when when somebody has screwed with setTimeout but no I.E. maddness
  28287. return cachedClearTimeout(marker);
  28288. } catch (e){
  28289. try {
  28290. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  28291. return cachedClearTimeout.call(null, marker);
  28292. } catch (e){
  28293. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  28294. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  28295. return cachedClearTimeout.call(this, marker);
  28296. }
  28297. }
  28298. }
  28299. var queue = [];
  28300. var draining = false;
  28301. var currentQueue;
  28302. var queueIndex = -1;
  28303. function cleanUpNextTick() {
  28304. if (!draining || !currentQueue) {
  28305. return;
  28306. }
  28307. draining = false;
  28308. if (currentQueue.length) {
  28309. queue = currentQueue.concat(queue);
  28310. } else {
  28311. queueIndex = -1;
  28312. }
  28313. if (queue.length) {
  28314. drainQueue();
  28315. }
  28316. }
  28317. function drainQueue() {
  28318. if (draining) {
  28319. return;
  28320. }
  28321. var timeout = runTimeout(cleanUpNextTick);
  28322. draining = true;
  28323. var len = queue.length;
  28324. while(len) {
  28325. currentQueue = queue;
  28326. queue = [];
  28327. while (++queueIndex < len) {
  28328. if (currentQueue) {
  28329. currentQueue[queueIndex].run();
  28330. }
  28331. }
  28332. queueIndex = -1;
  28333. len = queue.length;
  28334. }
  28335. currentQueue = null;
  28336. draining = false;
  28337. runClearTimeout(timeout);
  28338. }
  28339. process.nextTick = function (fun) {
  28340. var args = new Array(arguments.length - 1);
  28341. if (arguments.length > 1) {
  28342. for (var i = 1; i < arguments.length; i++) {
  28343. args[i - 1] = arguments[i];
  28344. }
  28345. }
  28346. queue.push(new Item(fun, args));
  28347. if (queue.length === 1 && !draining) {
  28348. runTimeout(drainQueue);
  28349. }
  28350. };
  28351. // v8 likes predictible objects
  28352. function Item(fun, array) {
  28353. this.fun = fun;
  28354. this.array = array;
  28355. }
  28356. Item.prototype.run = function () {
  28357. this.fun.apply(null, this.array);
  28358. };
  28359. process.title = 'browser';
  28360. process.browser = true;
  28361. process.env = {};
  28362. process.argv = [];
  28363. process.version = ''; // empty string to avoid regexp issues
  28364. process.versions = {};
  28365. function noop() {}
  28366. process.on = noop;
  28367. process.addListener = noop;
  28368. process.once = noop;
  28369. process.off = noop;
  28370. process.removeListener = noop;
  28371. process.removeAllListeners = noop;
  28372. process.emit = noop;
  28373. process.binding = function (name) {
  28374. throw new Error('process.binding is not supported');
  28375. };
  28376. process.cwd = function () { return '/' };
  28377. process.chdir = function (dir) {
  28378. throw new Error('process.chdir is not supported');
  28379. };
  28380. process.umask = function() { return 0; };
  28381. /***/ },
  28382. /* 290 */,
  28383. /* 291 */,
  28384. /* 292 */
  28385. /***/ function(module, exports, __webpack_require__) {
  28386. var echarts = __webpack_require__(1);
  28387. var zrUtil = __webpack_require__(4);
  28388. var modelUtil = __webpack_require__(5);
  28389. var graphicUtil = __webpack_require__(43);
  28390. var layoutUtil = __webpack_require__(21);
  28391. // -------------
  28392. // Preprocessor
  28393. // -------------
  28394. echarts.registerPreprocessor(function (option) {
  28395. var graphicOption = option && option.graphic;
  28396. // Convert
  28397. // {graphic: [{left: 10, type: 'circle'}, ...]}
  28398. // or
  28399. // {graphic: {left: 10, type: 'circle'}}
  28400. // to
  28401. // {graphic: [{elements: [{left: 10, type: 'circle'}, ...]}]}
  28402. if (zrUtil.isArray(graphicOption)) {
  28403. if (!graphicOption[0] || !graphicOption[0].elements) {
  28404. option.graphic = [{elements: graphicOption}];
  28405. }
  28406. else {
  28407. // Only one graphic instance can be instantiated. (We dont
  28408. // want that too many views are created in echarts._viewMap)
  28409. option.graphic = [option.graphic[0]];
  28410. }
  28411. }
  28412. else if (graphicOption && !graphicOption.elements) {
  28413. option.graphic = [{elements: [graphicOption]}];
  28414. }
  28415. });
  28416. // ------
  28417. // Model
  28418. // ------
  28419. var GraphicModel = echarts.extendComponentModel({
  28420. type: 'graphic',
  28421. defaultOption: {
  28422. // Extra properties for each elements:
  28423. //
  28424. // left/right/top/bottom: (like 12, '22%', 'center', default undefined)
  28425. // If left/rigth is set, shape.x/shape.cx/position will not be used.
  28426. // If top/bottom is set, shape.y/shape.cy/position will not be used.
  28427. // This mechanism is useful when you want to position a group/element
  28428. // against the right side or the center of this container.
  28429. //
  28430. // width/height: (can only be pixel value, default 0)
  28431. // Only be used to specify contianer(group) size, if needed. And
  28432. // can not be percentage value (like '33%'). See the reason in the
  28433. // layout algorithm below.
  28434. //
  28435. // bounding: (enum: 'all' (default) | 'raw')
  28436. // Specify how to calculate boundingRect when locating.
  28437. // 'all': Get uioned and transformed boundingRect
  28438. // from both itself and its descendants.
  28439. // This mode simplies confining a group of elements in the bounding
  28440. // of their ancester container (e.g., using 'right: 0').
  28441. // 'raw': Only use the boundingRect of itself and before transformed.
  28442. // This mode is similar to css behavior, which is useful when you
  28443. // want an element to be able to overflow its container. (Consider
  28444. // a rotated circle needs to be located in a corner.)
  28445. // Note: elements is always behind its ancestors in this elements array.
  28446. elements: [],
  28447. parentId: null
  28448. },
  28449. /**
  28450. * Save el options for the sake of the performance (only update modified graphics).
  28451. * The order is the same as those in option. (ancesters -> descendants)
  28452. *
  28453. * @private
  28454. * @type {Array.<Object>}
  28455. */
  28456. _elOptionsToUpdate: null,
  28457. /**
  28458. * @override
  28459. */
  28460. mergeOption: function (option) {
  28461. // Prevent default merge to elements
  28462. var elements = this.option.elements;
  28463. this.option.elements = null;
  28464. GraphicModel.superApply(this, 'mergeOption', arguments);
  28465. this.option.elements = elements;
  28466. },
  28467. /**
  28468. * @override
  28469. */
  28470. optionUpdated: function (newOption, isInit) {
  28471. var thisOption = this.option;
  28472. var newList = (isInit ? thisOption : newOption).elements;
  28473. var existList = thisOption.elements = isInit ? [] : thisOption.elements;
  28474. var flattenedList = [];
  28475. this._flatten(newList, flattenedList);
  28476. var mappingResult = modelUtil.mappingToExists(existList, flattenedList);
  28477. modelUtil.makeIdAndName(mappingResult);
  28478. // Clear elOptionsToUpdate
  28479. var elOptionsToUpdate = this._elOptionsToUpdate = [];
  28480. zrUtil.each(mappingResult, function (resultItem, index) {
  28481. var existElOption = resultItem.exist;
  28482. var newElOption = resultItem.option;
  28483. if (true) {
  28484. zrUtil.assert(
  28485. zrUtil.isObject(newElOption) || existElOption,
  28486. 'Empty graphic option definition'
  28487. );
  28488. }
  28489. if (!newElOption) {
  28490. return;
  28491. }
  28492. // Set id and parent id after id assigned.
  28493. newElOption.id = resultItem.keyInfo.id;
  28494. var newElParentId = newElOption.parentId;
  28495. var newElParentOption = newElOption.parentOption;
  28496. var existElParentId = existElOption && existElOption.parentId;
  28497. !newElOption.type && existElOption && (newElOption.type = existElOption.type);
  28498. newElOption.parentId = newElParentId // parent id specified
  28499. ? newElParentId
  28500. : newElParentOption
  28501. ? newElParentOption.id
  28502. : existElParentId // parent not specified
  28503. ? existElParentId
  28504. : null;
  28505. newElOption.parentOption = null; // Clear
  28506. elOptionsToUpdate.push(newElOption);
  28507. // Update existing options, for `getOption` feature.
  28508. var newElOptCopy = zrUtil.extend({}, newElOption);
  28509. var $action = newElOption.$action;
  28510. if (!$action || $action === 'merge') {
  28511. if (existElOption) {
  28512. if (true) {
  28513. var newType = newElOption.type;
  28514. zrUtil.assert(
  28515. !newType || existElOption.type === newType,
  28516. 'Please set $action: "replace" to change `type`'
  28517. );
  28518. }
  28519. // We can ensure that newElOptCopy and existElOption are not
  28520. // the same object, so `merge` will not change newElOptCopy.
  28521. zrUtil.merge(existElOption, newElOptCopy, true);
  28522. // Rigid body, use ignoreSize.
  28523. layoutUtil.mergeLayoutParam(existElOption, newElOptCopy, {ignoreSize: true});
  28524. // Will be used in render.
  28525. layoutUtil.copyLayoutParams(newElOption, existElOption);
  28526. }
  28527. else {
  28528. existList[index] = newElOptCopy;
  28529. }
  28530. }
  28531. else if ($action === 'replace') {
  28532. existList[index] = newElOptCopy;
  28533. }
  28534. else if ($action === 'remove') {
  28535. // null will be cleaned later.
  28536. existElOption && (existList[index] = null);
  28537. }
  28538. if (existList[index]) {
  28539. existList[index].hv = newElOption.hv = [
  28540. // Rigid body, dont care `width`.
  28541. isSetLoc(newElOption, ['left', 'right']),
  28542. // Rigid body, dont care `height`.
  28543. isSetLoc(newElOption, ['top', 'bottom'])
  28544. ];
  28545. // Give default group size. Otherwise layout error may occur.
  28546. if (existList[index].type === 'group') {
  28547. existList[index].width == null && (existList[index].width = newElOption.width = 0);
  28548. existList[index].height == null && (existList[index].height = newElOption.height = 0);
  28549. }
  28550. }
  28551. }, this);
  28552. // Clean
  28553. for (var i = existList.length - 1; i >= 0; i--) {
  28554. if (existList[i] == null) {
  28555. existList.splice(i, 1);
  28556. }
  28557. else {
  28558. // $action should be volatile, otherwise option gotten from
  28559. // `getOption` will contain unexpected $action.
  28560. delete existList[i].$action;
  28561. }
  28562. }
  28563. },
  28564. /**
  28565. * Convert
  28566. * [{
  28567. * type: 'group',
  28568. * id: 'xx',
  28569. * children: [{type: 'circle'}, {type: 'polygon'}]
  28570. * }]
  28571. * to
  28572. * [
  28573. * {type: 'group', id: 'xx'},
  28574. * {type: 'circle', parentId: 'xx'},
  28575. * {type: 'polygon', parentId: 'xx'}
  28576. * ]
  28577. *
  28578. * @private
  28579. * @param {Array.<Object>} optionList option list
  28580. * @param {Array.<Object>} result result of flatten
  28581. * @param {Object} parentOption parent option
  28582. */
  28583. _flatten: function (optionList, result, parentOption) {
  28584. zrUtil.each(optionList, function (option) {
  28585. if (option) {
  28586. if (parentOption) {
  28587. option.parentOption = parentOption;
  28588. }
  28589. result.push(option);
  28590. var children = option.children;
  28591. if (option.type === 'group' && children) {
  28592. this._flatten(children, result, option);
  28593. }
  28594. // Deleting for JSON output, and for not affecting group creation.
  28595. delete option.children;
  28596. }
  28597. }, this);
  28598. },
  28599. // FIXME
  28600. // Pass to view using payload? setOption has a payload?
  28601. useElOptionsToUpdate: function () {
  28602. var els = this._elOptionsToUpdate;
  28603. // Clear to avoid render duplicately when zooming.
  28604. this._elOptionsToUpdate = null;
  28605. return els;
  28606. }
  28607. });
  28608. // -----
  28609. // View
  28610. // -----
  28611. echarts.extendComponentView({
  28612. type: 'graphic',
  28613. /**
  28614. * @override
  28615. */
  28616. init: function (ecModel, api) {
  28617. /**
  28618. * @private
  28619. * @type {Object}
  28620. */
  28621. this._elMap = {};
  28622. /**
  28623. * @private
  28624. * @type {module:echarts/graphic/GraphicModel}
  28625. */
  28626. this._lastGraphicModel;
  28627. },
  28628. /**
  28629. * @override
  28630. */
  28631. render: function (graphicModel, ecModel, api) {
  28632. // Having leveraged between use cases and algorithm complexity, a very
  28633. // simple layout mechanism is used:
  28634. // The size(width/height) can be determined by itself or its parent (not
  28635. // implemented yet), but can not by its children. (Top-down travel)
  28636. // The location(x/y) can be determined by the bounding rect of itself
  28637. // (can including its descendants or not) and the size of its parent.
  28638. // (Bottom-up travel)
  28639. // When `chart.clear()` or `chart.setOption({...}, true)` with the same id,
  28640. // view will be reused.
  28641. if (graphicModel !== this._lastGraphicModel) {
  28642. this._clear();
  28643. }
  28644. this._lastGraphicModel = graphicModel;
  28645. this._updateElements(graphicModel, api);
  28646. this._relocate(graphicModel, api);
  28647. },
  28648. /**
  28649. * Update graphic elements.
  28650. *
  28651. * @private
  28652. * @param {Object} graphicModel graphic model
  28653. * @param {module:echarts/ExtensionAPI} api extension API
  28654. */
  28655. _updateElements: function (graphicModel, api) {
  28656. var elOptionsToUpdate = graphicModel.useElOptionsToUpdate();
  28657. if (!elOptionsToUpdate) {
  28658. return;
  28659. }
  28660. var elMap = this._elMap;
  28661. var rootGroup = this.group;
  28662. // Top-down tranverse to assign graphic settings to each elements.
  28663. zrUtil.each(elOptionsToUpdate, function (elOption) {
  28664. var $action = elOption.$action;
  28665. var id = elOption.id;
  28666. var existEl = elMap[id];
  28667. var parentId = elOption.parentId;
  28668. var targetElParent = parentId != null ? elMap[parentId] : rootGroup;
  28669. // In top/bottom mode, textVertical should not be used. And textBaseline
  28670. // should not be 'alphabetic', which cause inaccurately locating.
  28671. if (elOption.hv && elOption.hv[1] && elOption.type === 'text') {
  28672. elOption.style = zrUtil.defaults({textBaseline: 'middle'}, elOption.style);
  28673. elOption.style.textVerticalAlign = null;
  28674. }
  28675. // Remove unnecessary props to avoid potential problems.
  28676. var elOptionCleaned = getCleanedElOption(elOption);
  28677. // For simple, do not support parent change, otherwise reorder is needed.
  28678. if (true) {
  28679. existEl && zrUtil.assert(
  28680. targetElParent === existEl.parent,
  28681. 'Changing parent is not supported.'
  28682. );
  28683. }
  28684. if (!$action || $action === 'merge') {
  28685. existEl
  28686. ? existEl.attr(elOptionCleaned)
  28687. : createEl(id, targetElParent, elOptionCleaned, elMap);
  28688. }
  28689. else if ($action === 'replace') {
  28690. removeEl(existEl, elMap);
  28691. createEl(id, targetElParent, elOptionCleaned, elMap);
  28692. }
  28693. else if ($action === 'remove') {
  28694. removeEl(existEl, elMap);
  28695. }
  28696. if (elMap[id]) {
  28697. elMap[id].__ecGraphicWidth = elOption.width;
  28698. elMap[id].__ecGraphicHeight = elOption.height;
  28699. }
  28700. });
  28701. },
  28702. /**
  28703. * Locate graphic elements.
  28704. *
  28705. * @private
  28706. * @param {Object} graphicModel graphic model
  28707. * @param {module:echarts/ExtensionAPI} api extension API
  28708. */
  28709. _relocate: function (graphicModel, api) {
  28710. var elOptions = graphicModel.option.elements;
  28711. var rootGroup = this.group;
  28712. var elMap = this._elMap;
  28713. // Bottom-up tranvese all elements (consider ec resize) to locate elements.
  28714. for (var i = elOptions.length - 1; i >= 0; i--) {
  28715. var elOption = elOptions[i];
  28716. var el = elMap[elOption.id];
  28717. if (!el) {
  28718. continue;
  28719. }
  28720. var parentEl = el.parent;
  28721. var containerInfo = parentEl === rootGroup
  28722. ? {
  28723. width: api.getWidth(),
  28724. height: api.getHeight()
  28725. }
  28726. : { // Like 'position:absolut' in css, default 0.
  28727. width: parentEl.__ecGraphicWidth || 0,
  28728. height: parentEl.__ecGraphicHeight || 0
  28729. };
  28730. layoutUtil.positionElement(
  28731. el, elOption, containerInfo, null,
  28732. {hv: elOption.hv, boundingMode: elOption.bounding}
  28733. );
  28734. }
  28735. },
  28736. /**
  28737. * Clear all elements.
  28738. *
  28739. * @private
  28740. */
  28741. _clear: function () {
  28742. var elMap = this._elMap;
  28743. zrUtil.each(elMap, function (el) {
  28744. removeEl(el, elMap);
  28745. });
  28746. this._elMap = {};
  28747. },
  28748. /**
  28749. * @override
  28750. */
  28751. dispose: function () {
  28752. this._clear();
  28753. }
  28754. });
  28755. function createEl(id, targetElParent, elOption, elMap) {
  28756. var graphicType = elOption.type;
  28757. if (true) {
  28758. zrUtil.assert(graphicType, 'graphic type MUST be set');
  28759. }
  28760. var Clz = graphicUtil[graphicType.charAt(0).toUpperCase() + graphicType.slice(1)];
  28761. if (true) {
  28762. zrUtil.assert(Clz, 'graphic type can not be found');
  28763. }
  28764. var el = new Clz(elOption);
  28765. targetElParent.add(el);
  28766. elMap[id] = el;
  28767. el.__ecGraphicId = id;
  28768. }
  28769. function removeEl(existEl, elMap) {
  28770. var existElParent = existEl && existEl.parent;
  28771. if (existElParent) {
  28772. existEl.type === 'group' && existEl.traverse(function (el) {
  28773. removeEl(el, elMap);
  28774. });
  28775. delete elMap[existEl.__ecGraphicId];
  28776. existElParent.remove(existEl);
  28777. }
  28778. }
  28779. // Remove unnecessary props to avoid potential problems.
  28780. function getCleanedElOption(elOption) {
  28781. elOption = zrUtil.extend({}, elOption);
  28782. zrUtil.each(
  28783. ['id', 'parentId', '$action', 'hv', 'bounding'].concat(layoutUtil.LOCATION_PARAMS),
  28784. function (name) {
  28785. delete elOption[name];
  28786. }
  28787. );
  28788. return elOption;
  28789. }
  28790. function isSetLoc(obj, props) {
  28791. var isSet;
  28792. zrUtil.each(props, function (prop) {
  28793. obj[prop] != null && obj[prop] !== 'auto' && (isSet = true);
  28794. });
  28795. return isSet;
  28796. }
  28797. /***/ },
  28798. /* 293 */
  28799. /***/ function(module, exports, __webpack_require__) {
  28800. /**
  28801. * Legend component entry file8
  28802. */
  28803. __webpack_require__(294);
  28804. __webpack_require__(295);
  28805. __webpack_require__(296);
  28806. var echarts = __webpack_require__(1);
  28807. // Series Filter
  28808. echarts.registerProcessor(__webpack_require__(298));
  28809. /***/ },
  28810. /* 294 */
  28811. /***/ function(module, exports, __webpack_require__) {
  28812. 'use strict';
  28813. var zrUtil = __webpack_require__(4);
  28814. var Model = __webpack_require__(12);
  28815. var LegendModel = __webpack_require__(1).extendComponentModel({
  28816. type: 'legend',
  28817. dependencies: ['series'],
  28818. layoutMode: {
  28819. type: 'box',
  28820. ignoreSize: true
  28821. },
  28822. init: function (option, parentModel, ecModel) {
  28823. this.mergeDefaultAndTheme(option, ecModel);
  28824. option.selected = option.selected || {};
  28825. },
  28826. mergeOption: function (option) {
  28827. LegendModel.superCall(this, 'mergeOption', option);
  28828. },
  28829. optionUpdated: function () {
  28830. this._updateData(this.ecModel);
  28831. var legendData = this._data;
  28832. // If selectedMode is single, try to select one
  28833. if (legendData[0] && this.get('selectedMode') === 'single') {
  28834. var hasSelected = false;
  28835. // If has any selected in option.selected
  28836. for (var i = 0; i < legendData.length; i++) {
  28837. var name = legendData[i].get('name');
  28838. if (this.isSelected(name)) {
  28839. // Force to unselect others
  28840. this.select(name);
  28841. hasSelected = true;
  28842. break;
  28843. }
  28844. }
  28845. // Try select the first if selectedMode is single
  28846. !hasSelected && this.select(legendData[0].get('name'));
  28847. }
  28848. },
  28849. _updateData: function (ecModel) {
  28850. var legendData = zrUtil.map(this.get('data') || [], function (dataItem) {
  28851. // Can be string or number
  28852. if (typeof dataItem === 'string' || typeof dataItem === 'number') {
  28853. dataItem = {
  28854. name: dataItem
  28855. };
  28856. }
  28857. return new Model(dataItem, this, this.ecModel);
  28858. }, this);
  28859. this._data = legendData;
  28860. var availableNames = zrUtil.map(ecModel.getSeries(), function (series) {
  28861. return series.name;
  28862. });
  28863. ecModel.eachSeries(function (seriesModel) {
  28864. if (seriesModel.legendDataProvider) {
  28865. var data = seriesModel.legendDataProvider();
  28866. availableNames = availableNames.concat(data.mapArray(data.getName));
  28867. }
  28868. });
  28869. /**
  28870. * @type {Array.<string>}
  28871. * @private
  28872. */
  28873. this._availableNames = availableNames;
  28874. },
  28875. /**
  28876. * @return {Array.<module:echarts/model/Model>}
  28877. */
  28878. getData: function () {
  28879. return this._data;
  28880. },
  28881. /**
  28882. * @param {string} name
  28883. */
  28884. select: function (name) {
  28885. var selected = this.option.selected;
  28886. var selectedMode = this.get('selectedMode');
  28887. if (selectedMode === 'single') {
  28888. var data = this._data;
  28889. zrUtil.each(data, function (dataItem) {
  28890. selected[dataItem.get('name')] = false;
  28891. });
  28892. }
  28893. selected[name] = true;
  28894. },
  28895. /**
  28896. * @param {string} name
  28897. */
  28898. unSelect: function (name) {
  28899. if (this.get('selectedMode') !== 'single') {
  28900. this.option.selected[name] = false;
  28901. }
  28902. },
  28903. /**
  28904. * @param {string} name
  28905. */
  28906. toggleSelected: function (name) {
  28907. var selected = this.option.selected;
  28908. // Default is true
  28909. if (!selected.hasOwnProperty(name)) {
  28910. selected[name] = true;
  28911. }
  28912. this[selected[name] ? 'unSelect' : 'select'](name);
  28913. },
  28914. /**
  28915. * @param {string} name
  28916. */
  28917. isSelected: function (name) {
  28918. var selected = this.option.selected;
  28919. return !(selected.hasOwnProperty(name) && !selected[name])
  28920. && zrUtil.indexOf(this._availableNames, name) >= 0;
  28921. },
  28922. defaultOption: {
  28923. // 一级层叠
  28924. zlevel: 0,
  28925. // 二级层叠
  28926. z: 4,
  28927. show: true,
  28928. // 布局方式,默认为水平布局,可选为:
  28929. // 'horizontal' | 'vertical'
  28930. orient: 'horizontal',
  28931. left: 'center',
  28932. // right: 'center',
  28933. top: 'top',
  28934. // bottom: 'top',
  28935. // 水平对齐
  28936. // 'auto' | 'left' | 'right'
  28937. // 默认为 'auto', 根据 x 的位置判断是左对齐还是右对齐
  28938. align: 'auto',
  28939. backgroundColor: 'rgba(0,0,0,0)',
  28940. // 图例边框颜色
  28941. borderColor: '#ccc',
  28942. // 图例边框线宽,单位px,默认为0(无边框)
  28943. borderWidth: 0,
  28944. // 图例内边距,单位px,默认各方向内边距为5,
  28945. // 接受数组分别设定上右下左边距,同css
  28946. padding: 5,
  28947. // 各个item之间的间隔,单位px,默认为10,
  28948. // 横向布局时为水平间隔,纵向布局时为纵向间隔
  28949. itemGap: 10,
  28950. // 图例图形宽度
  28951. itemWidth: 25,
  28952. // 图例图形高度
  28953. itemHeight: 14,
  28954. // 图例关闭时候的颜色
  28955. inactiveColor: '#ccc',
  28956. textStyle: {
  28957. // 图例文字颜色
  28958. color: '#333'
  28959. },
  28960. // formatter: '',
  28961. // 选择模式,默认开启图例开关
  28962. selectedMode: true,
  28963. // 配置默认选中状态,可配合LEGEND.SELECTED事件做动态数据载入
  28964. // selected: null,
  28965. // 图例内容(详见legend.data,数组中每一项代表一个item
  28966. // data: [],
  28967. // Tooltip 相关配置
  28968. tooltip: {
  28969. show: false
  28970. }
  28971. }
  28972. });
  28973. module.exports = LegendModel;
  28974. /***/ },
  28975. /* 295 */
  28976. /***/ function(module, exports, __webpack_require__) {
  28977. /**
  28978. * @file Legend action
  28979. */
  28980. var echarts = __webpack_require__(1);
  28981. var zrUtil = __webpack_require__(4);
  28982. function legendSelectActionHandler(methodName, payload, ecModel) {
  28983. var selectedMap = {};
  28984. var isToggleSelect = methodName === 'toggleSelected';
  28985. var isSelected;
  28986. // Update all legend components
  28987. ecModel.eachComponent('legend', function (legendModel) {
  28988. if (isToggleSelect && isSelected != null) {
  28989. // Force other legend has same selected status
  28990. // Or the first is toggled to true and other are toggled to false
  28991. // In the case one legend has some item unSelected in option. And if other legend
  28992. // doesn't has the item, they will assume it is selected.
  28993. legendModel[isSelected ? 'select' : 'unSelect'](payload.name);
  28994. }
  28995. else {
  28996. legendModel[methodName](payload.name);
  28997. isSelected = legendModel.isSelected(payload.name);
  28998. }
  28999. var legendData = legendModel.getData();
  29000. zrUtil.each(legendData, function (model) {
  29001. var name = model.get('name');
  29002. // Wrap element
  29003. if (name === '\n' || name === '') {
  29004. return;
  29005. }
  29006. var isItemSelected = legendModel.isSelected(name);
  29007. if (name in selectedMap) {
  29008. // Unselected if any legend is unselected
  29009. selectedMap[name] = selectedMap[name] && isItemSelected;
  29010. }
  29011. else {
  29012. selectedMap[name] = isItemSelected;
  29013. }
  29014. });
  29015. });
  29016. // Return the event explicitly
  29017. return {
  29018. name: payload.name,
  29019. selected: selectedMap
  29020. };
  29021. }
  29022. /**
  29023. * @event legendToggleSelect
  29024. * @type {Object}
  29025. * @property {string} type 'legendToggleSelect'
  29026. * @property {string} [from]
  29027. * @property {string} name Series name or data item name
  29028. */
  29029. echarts.registerAction(
  29030. 'legendToggleSelect', 'legendselectchanged',
  29031. zrUtil.curry(legendSelectActionHandler, 'toggleSelected')
  29032. );
  29033. /**
  29034. * @event legendSelect
  29035. * @type {Object}
  29036. * @property {string} type 'legendSelect'
  29037. * @property {string} name Series name or data item name
  29038. */
  29039. echarts.registerAction(
  29040. 'legendSelect', 'legendselected',
  29041. zrUtil.curry(legendSelectActionHandler, 'select')
  29042. );
  29043. /**
  29044. * @event legendUnSelect
  29045. * @type {Object}
  29046. * @property {string} type 'legendUnSelect'
  29047. * @property {string} name Series name or data item name
  29048. */
  29049. echarts.registerAction(
  29050. 'legendUnSelect', 'legendunselected',
  29051. zrUtil.curry(legendSelectActionHandler, 'unSelect')
  29052. );
  29053. /***/ },
  29054. /* 296 */
  29055. /***/ function(module, exports, __webpack_require__) {
  29056. var zrUtil = __webpack_require__(4);
  29057. var symbolCreator = __webpack_require__(107);
  29058. var graphic = __webpack_require__(43);
  29059. var listComponentHelper = __webpack_require__(297);
  29060. var curry = zrUtil.curry;
  29061. function dispatchSelectAction(name, api) {
  29062. api.dispatchAction({
  29063. type: 'legendToggleSelect',
  29064. name: name
  29065. });
  29066. }
  29067. function dispatchHighlightAction(seriesModel, dataName, api) {
  29068. // If element hover will move to a hoverLayer.
  29069. var el = api.getZr().storage.getDisplayList()[0];
  29070. if (!(el && el.useHoverLayer)) {
  29071. seriesModel.get('legendHoverLink') && api.dispatchAction({
  29072. type: 'highlight',
  29073. seriesName: seriesModel.name,
  29074. name: dataName
  29075. });
  29076. }
  29077. }
  29078. function dispatchDownplayAction(seriesModel, dataName, api) {
  29079. // If element hover will move to a hoverLayer.
  29080. var el = api.getZr().storage.getDisplayList()[0];
  29081. if (!(el && el.useHoverLayer)) {
  29082. seriesModel.get('legendHoverLink') && api.dispatchAction({
  29083. type: 'downplay',
  29084. seriesName: seriesModel.name,
  29085. name: dataName
  29086. });
  29087. }
  29088. }
  29089. module.exports = __webpack_require__(1).extendComponentView({
  29090. type: 'legend',
  29091. init: function () {
  29092. this._symbolTypeStore = {};
  29093. },
  29094. render: function (legendModel, ecModel, api) {
  29095. var group = this.group;
  29096. group.removeAll();
  29097. if (!legendModel.get('show')) {
  29098. return;
  29099. }
  29100. var selectMode = legendModel.get('selectedMode');
  29101. var itemAlign = legendModel.get('align');
  29102. if (itemAlign === 'auto') {
  29103. itemAlign = (legendModel.get('left') === 'right'
  29104. && legendModel.get('orient') === 'vertical')
  29105. ? 'right' : 'left';
  29106. }
  29107. var legendDrawedMap = {};
  29108. zrUtil.each(legendModel.getData(), function (itemModel) {
  29109. var name = itemModel.get('name');
  29110. // Use empty string or \n as a newline string
  29111. if (name === '' || name === '\n') {
  29112. group.add(new graphic.Group({
  29113. newline: true
  29114. }));
  29115. return;
  29116. }
  29117. var seriesModel = ecModel.getSeriesByName(name)[0];
  29118. if (legendDrawedMap[name]) {
  29119. // Have been drawed
  29120. return;
  29121. }
  29122. // Series legend
  29123. if (seriesModel) {
  29124. var data = seriesModel.getData();
  29125. var color = data.getVisual('color');
  29126. // If color is a callback function
  29127. if (typeof color === 'function') {
  29128. // Use the first data
  29129. color = color(seriesModel.getDataParams(0));
  29130. }
  29131. // Using rect symbol defaultly
  29132. var legendSymbolType = data.getVisual('legendSymbol') || 'roundRect';
  29133. var symbolType = data.getVisual('symbol');
  29134. var itemGroup = this._createItem(
  29135. name, itemModel, legendModel,
  29136. legendSymbolType, symbolType,
  29137. itemAlign, color,
  29138. selectMode
  29139. );
  29140. itemGroup.on('click', curry(dispatchSelectAction, name, api))
  29141. .on('mouseover', curry(dispatchHighlightAction, seriesModel, null, api))
  29142. .on('mouseout', curry(dispatchDownplayAction, seriesModel, null, api));
  29143. legendDrawedMap[name] = true;
  29144. }
  29145. else {
  29146. // Data legend of pie, funnel
  29147. ecModel.eachRawSeries(function (seriesModel) {
  29148. // In case multiple series has same data name
  29149. if (legendDrawedMap[name]) {
  29150. return;
  29151. }
  29152. if (seriesModel.legendDataProvider) {
  29153. var data = seriesModel.legendDataProvider();
  29154. var idx = data.indexOfName(name);
  29155. if (idx < 0) {
  29156. return;
  29157. }
  29158. var color = data.getItemVisual(idx, 'color');
  29159. var legendSymbolType = 'roundRect';
  29160. var itemGroup = this._createItem(
  29161. name, itemModel, legendModel,
  29162. legendSymbolType, null,
  29163. itemAlign, color,
  29164. selectMode
  29165. );
  29166. itemGroup.on('click', curry(dispatchSelectAction, name, api))
  29167. // FIXME Should not specify the series name
  29168. .on('mouseover', curry(dispatchHighlightAction, seriesModel, name, api))
  29169. .on('mouseout', curry(dispatchDownplayAction, seriesModel, name, api));
  29170. legendDrawedMap[name] = true;
  29171. }
  29172. }, this);
  29173. }
  29174. if (true) {
  29175. if (!legendDrawedMap[name]) {
  29176. console.warn(name + ' series not exists. Legend data should be same with series name or data name.');
  29177. }
  29178. }
  29179. }, this);
  29180. listComponentHelper.layout(group, legendModel, api);
  29181. // Render background after group is layout
  29182. // FIXME
  29183. listComponentHelper.addBackground(group, legendModel);
  29184. },
  29185. _createItem: function (
  29186. name, itemModel, legendModel,
  29187. legendSymbolType, symbolType,
  29188. itemAlign, color, selectMode
  29189. ) {
  29190. var itemWidth = legendModel.get('itemWidth');
  29191. var itemHeight = legendModel.get('itemHeight');
  29192. var inactiveColor = legendModel.get('inactiveColor');
  29193. var isSelected = legendModel.isSelected(name);
  29194. var itemGroup = new graphic.Group();
  29195. var textStyleModel = itemModel.getModel('textStyle');
  29196. var itemIcon = itemModel.get('icon');
  29197. var tooltipModel = itemModel.getModel('tooltip');
  29198. var legendGlobalTooltipModel = tooltipModel.parentModel;
  29199. // Use user given icon first
  29200. legendSymbolType = itemIcon || legendSymbolType;
  29201. itemGroup.add(symbolCreator.createSymbol(
  29202. legendSymbolType, 0, 0, itemWidth, itemHeight, isSelected ? color : inactiveColor
  29203. ));
  29204. // Compose symbols
  29205. // PENDING
  29206. if (!itemIcon && symbolType
  29207. // At least show one symbol, can't be all none
  29208. && ((symbolType !== legendSymbolType) || symbolType == 'none')
  29209. ) {
  29210. var size = itemHeight * 0.8;
  29211. if (symbolType === 'none') {
  29212. symbolType = 'circle';
  29213. }
  29214. // Put symbol in the center
  29215. itemGroup.add(symbolCreator.createSymbol(
  29216. symbolType, (itemWidth - size) / 2, (itemHeight - size) / 2, size, size,
  29217. isSelected ? color : inactiveColor
  29218. ));
  29219. }
  29220. // Text
  29221. var textX = itemAlign === 'left' ? itemWidth + 5 : -5;
  29222. var textAlign = itemAlign;
  29223. var formatter = legendModel.get('formatter');
  29224. var content = name;
  29225. if (typeof formatter === 'string' && formatter) {
  29226. content = formatter.replace('{name}', name != null ? name : '');
  29227. }
  29228. else if (typeof formatter === 'function') {
  29229. content = formatter(name);
  29230. }
  29231. var text = new graphic.Text({
  29232. style: {
  29233. text: content,
  29234. x: textX,
  29235. y: itemHeight / 2,
  29236. fill: isSelected ? textStyleModel.getTextColor() : inactiveColor,
  29237. textFont: textStyleModel.getFont(),
  29238. textAlign: textAlign,
  29239. textVerticalAlign: 'middle'
  29240. }
  29241. });
  29242. itemGroup.add(text);
  29243. // Add a invisible rect to increase the area of mouse hover
  29244. var hitRect = new graphic.Rect({
  29245. shape: itemGroup.getBoundingRect(),
  29246. invisible: true,
  29247. tooltip: tooltipModel.get('show') ? zrUtil.extend({
  29248. content: name,
  29249. // Defaul formatter
  29250. formatter: legendGlobalTooltipModel.get('formatter', true) || function () {
  29251. return name;
  29252. },
  29253. formatterParams: {
  29254. componentType: 'legend',
  29255. legendIndex: legendModel.componentIndex,
  29256. name: name,
  29257. $vars: ['name']
  29258. }
  29259. }, tooltipModel.option) : null
  29260. });
  29261. itemGroup.add(hitRect);
  29262. itemGroup.eachChild(function (child) {
  29263. child.silent = true;
  29264. });
  29265. hitRect.silent = !selectMode;
  29266. this.group.add(itemGroup);
  29267. graphic.setHoverStyle(itemGroup);
  29268. return itemGroup;
  29269. }
  29270. });
  29271. /***/ },
  29272. /* 297 */
  29273. /***/ function(module, exports, __webpack_require__) {
  29274. // List layout
  29275. var layout = __webpack_require__(21);
  29276. var formatUtil = __webpack_require__(6);
  29277. var graphic = __webpack_require__(43);
  29278. function positionGroup(group, model, api) {
  29279. layout.positionElement(
  29280. group, model.getBoxLayoutParams(),
  29281. {
  29282. width: api.getWidth(),
  29283. height: api.getHeight()
  29284. },
  29285. model.get('padding')
  29286. );
  29287. }
  29288. module.exports = {
  29289. /**
  29290. * Layout list like component.
  29291. * It will box layout each items in group of component and then position the whole group in the viewport
  29292. * @param {module:zrender/group/Group} group
  29293. * @param {module:echarts/model/Component} componentModel
  29294. * @param {module:echarts/ExtensionAPI}
  29295. */
  29296. layout: function (group, componentModel, api) {
  29297. var rect = layout.getLayoutRect(componentModel.getBoxLayoutParams(), {
  29298. width: api.getWidth(),
  29299. height: api.getHeight()
  29300. }, componentModel.get('padding'));
  29301. layout.box(
  29302. componentModel.get('orient'),
  29303. group,
  29304. componentModel.get('itemGap'),
  29305. rect.width,
  29306. rect.height
  29307. );
  29308. positionGroup(group, componentModel, api);
  29309. },
  29310. addBackground: function (group, componentModel) {
  29311. var padding = formatUtil.normalizeCssArray(
  29312. componentModel.get('padding')
  29313. );
  29314. var boundingRect = group.getBoundingRect();
  29315. var style = componentModel.getItemStyle(['color', 'opacity']);
  29316. style.fill = componentModel.get('backgroundColor');
  29317. var rect = new graphic.Rect({
  29318. shape: {
  29319. x: boundingRect.x - padding[3],
  29320. y: boundingRect.y - padding[0],
  29321. width: boundingRect.width + padding[1] + padding[3],
  29322. height: boundingRect.height + padding[0] + padding[2]
  29323. },
  29324. style: style,
  29325. silent: true,
  29326. z2: -1
  29327. });
  29328. graphic.subPixelOptimizeRect(rect);
  29329. group.add(rect);
  29330. }
  29331. };
  29332. /***/ },
  29333. /* 298 */
  29334. /***/ function(module, exports) {
  29335. module.exports = function (ecModel) {
  29336. var legendModels = ecModel.findComponents({
  29337. mainType: 'legend'
  29338. });
  29339. if (legendModels && legendModels.length) {
  29340. ecModel.filterSeries(function (series) {
  29341. // If in any legend component the status is not selected.
  29342. // Because in legend series is assumed selected when it is not in the legend data.
  29343. for (var i = 0; i < legendModels.length; i++) {
  29344. if (!legendModels[i].isSelected(series.name)) {
  29345. return false;
  29346. }
  29347. }
  29348. return true;
  29349. });
  29350. }
  29351. };
  29352. /***/ },
  29353. /* 299 */
  29354. /***/ function(module, exports, __webpack_require__) {
  29355. // FIXME Better way to pack data in graphic element
  29356. __webpack_require__(300);
  29357. __webpack_require__(301);
  29358. // Show tip action
  29359. /**
  29360. * @action
  29361. * @property {string} type
  29362. * @property {number} seriesIndex
  29363. * @property {number} dataIndex
  29364. * @property {number} [x]
  29365. * @property {number} [y]
  29366. */
  29367. __webpack_require__(1).registerAction(
  29368. {
  29369. type: 'showTip',
  29370. event: 'showTip',
  29371. update: 'tooltip:manuallyShowTip'
  29372. },
  29373. // noop
  29374. function () {}
  29375. );
  29376. // Hide tip action
  29377. __webpack_require__(1).registerAction(
  29378. {
  29379. type: 'hideTip',
  29380. event: 'hideTip',
  29381. update: 'tooltip:manuallyHideTip'
  29382. },
  29383. // noop
  29384. function () {}
  29385. );
  29386. /***/ },
  29387. /* 300 */
  29388. /***/ function(module, exports, __webpack_require__) {
  29389. __webpack_require__(1).extendComponentModel({
  29390. type: 'tooltip',
  29391. defaultOption: {
  29392. zlevel: 0,
  29393. z: 8,
  29394. show: true,
  29395. // tooltip主体内容
  29396. showContent: true,
  29397. // 触发类型,默认数据触发,见下图,可选为:'item' ¦ 'axis'
  29398. trigger: 'item',
  29399. // 触发条件,支持 'click' | 'mousemove' | 'none'
  29400. triggerOn: 'mousemove',
  29401. // 是否永远显示 content
  29402. alwaysShowContent: false,
  29403. // 位置 {Array} | {Function}
  29404. // position: null
  29405. // 是否约束 content 在 viewRect 中。默认 false 是为了兼容以前版本。
  29406. confine: false,
  29407. // 内容格式器:{string}(Template) ¦ {Function}
  29408. // formatter: null
  29409. showDelay: 0,
  29410. // 隐藏延迟,单位ms
  29411. hideDelay: 100,
  29412. // 动画变换时间,单位s
  29413. transitionDuration: 0.4,
  29414. enterable: false,
  29415. // 提示背景颜色,默认为透明度为0.7的黑色
  29416. backgroundColor: 'rgba(50,50,50,0.7)',
  29417. // 提示边框颜色
  29418. borderColor: '#333',
  29419. // 提示边框圆角,单位px,默认为4
  29420. borderRadius: 4,
  29421. // 提示边框线宽,单位px,默认为0(无边框)
  29422. borderWidth: 0,
  29423. // 提示内边距,单位px,默认各方向内边距为5,
  29424. // 接受数组分别设定上右下左边距,同css
  29425. padding: 5,
  29426. // Extra css text
  29427. extraCssText: '',
  29428. // 坐标轴指示器,坐标轴触发有效
  29429. axisPointer: {
  29430. // 默认为直线
  29431. // 可选为:'line' | 'shadow' | 'cross'
  29432. type: 'line',
  29433. // type 为 line 的时候有效,指定 tooltip line 所在的轴,可选
  29434. // 可选 'x' | 'y' | 'angle' | 'radius' | 'auto'
  29435. // 默认 'auto',会选择类型为 cateogry 的轴,对于双数值轴,笛卡尔坐标系会默认选择 x 轴
  29436. // 极坐标系会默认选择 angle 轴
  29437. axis: 'auto',
  29438. animation: true,
  29439. animationDurationUpdate: 200,
  29440. animationEasingUpdate: 'exponentialOut',
  29441. // 直线指示器样式设置
  29442. lineStyle: {
  29443. color: '#555',
  29444. width: 1,
  29445. type: 'solid'
  29446. },
  29447. crossStyle: {
  29448. color: '#555',
  29449. width: 1,
  29450. type: 'dashed',
  29451. // TODO formatter
  29452. textStyle: {}
  29453. },
  29454. // 阴影指示器样式设置
  29455. shadowStyle: {
  29456. color: 'rgba(150,150,150,0.3)'
  29457. }
  29458. },
  29459. textStyle: {
  29460. color: '#fff',
  29461. fontSize: 14
  29462. }
  29463. }
  29464. });
  29465. /***/ },
  29466. /* 301 */
  29467. /***/ function(module, exports, __webpack_require__) {
  29468. var TooltipContent = __webpack_require__(302);
  29469. var graphic = __webpack_require__(43);
  29470. var zrUtil = __webpack_require__(4);
  29471. var formatUtil = __webpack_require__(6);
  29472. var numberUtil = __webpack_require__(7);
  29473. var modelUtil = __webpack_require__(5);
  29474. var parsePercent = numberUtil.parsePercent;
  29475. var env = __webpack_require__(2);
  29476. var Model = __webpack_require__(12);
  29477. function dataEqual(a, b) {
  29478. if (!a || !b) {
  29479. return false;
  29480. }
  29481. var round = numberUtil.round;
  29482. return round(a[0]) === round(b[0])
  29483. && round(a[1]) === round(b[1]);
  29484. }
  29485. /**
  29486. * @inner
  29487. */
  29488. function makeLineShape(x1, y1, x2, y2) {
  29489. return {
  29490. x1: x1,
  29491. y1: y1,
  29492. x2: x2,
  29493. y2: y2
  29494. };
  29495. }
  29496. /**
  29497. * @inner
  29498. */
  29499. function makeRectShape(x, y, width, height) {
  29500. return {
  29501. x: x,
  29502. y: y,
  29503. width: width,
  29504. height: height
  29505. };
  29506. }
  29507. /**
  29508. * @inner
  29509. */
  29510. function makeSectorShape(cx, cy, r0, r, startAngle, endAngle) {
  29511. return {
  29512. cx: cx,
  29513. cy: cy,
  29514. r0: r0,
  29515. r: r,
  29516. startAngle: startAngle,
  29517. endAngle: endAngle,
  29518. clockwise: true
  29519. };
  29520. }
  29521. function refixTooltipPosition(x, y, el, viewWidth, viewHeight) {
  29522. var width = el.clientWidth;
  29523. var height = el.clientHeight;
  29524. var gap = 20;
  29525. if (x + width + gap > viewWidth) {
  29526. x -= width + gap;
  29527. }
  29528. else {
  29529. x += gap;
  29530. }
  29531. if (y + height + gap > viewHeight) {
  29532. y -= height + gap;
  29533. }
  29534. else {
  29535. y += gap;
  29536. }
  29537. return [x, y];
  29538. }
  29539. function confineTooltipPosition(x, y, el, viewWidth, viewHeight) {
  29540. var width = el.clientWidth;
  29541. var height = el.clientHeight;
  29542. x = Math.min(x + width, viewWidth) - width;
  29543. y = Math.min(y + height, viewHeight) - height;
  29544. x = Math.max(x, 0);
  29545. y = Math.max(y, 0);
  29546. return [x, y];
  29547. }
  29548. function calcTooltipPosition(position, rect, dom) {
  29549. var domWidth = dom.clientWidth;
  29550. var domHeight = dom.clientHeight;
  29551. var gap = 5;
  29552. var x = 0;
  29553. var y = 0;
  29554. var rectWidth = rect.width;
  29555. var rectHeight = rect.height;
  29556. switch (position) {
  29557. case 'inside':
  29558. x = rect.x + rectWidth / 2 - domWidth / 2;
  29559. y = rect.y + rectHeight / 2 - domHeight / 2;
  29560. break;
  29561. case 'top':
  29562. x = rect.x + rectWidth / 2 - domWidth / 2;
  29563. y = rect.y - domHeight - gap;
  29564. break;
  29565. case 'bottom':
  29566. x = rect.x + rectWidth / 2 - domWidth / 2;
  29567. y = rect.y + rectHeight + gap;
  29568. break;
  29569. case 'left':
  29570. x = rect.x - domWidth - gap;
  29571. y = rect.y + rectHeight / 2 - domHeight / 2;
  29572. break;
  29573. case 'right':
  29574. x = rect.x + rectWidth + gap;
  29575. y = rect.y + rectHeight / 2 - domHeight / 2;
  29576. }
  29577. return [x, y];
  29578. }
  29579. /**
  29580. * @param {string|Function|Array.<number>} positionExpr
  29581. * @param {number} x Mouse x
  29582. * @param {number} y Mouse y
  29583. * @param {boolean} confine Whether confine tooltip content in view rect.
  29584. * @param {module:echarts/component/tooltip/TooltipContent} content
  29585. * @param {Object|<Array.<Object>} params
  29586. * @param {module:zrender/Element} el target element
  29587. * @param {module:echarts/ExtensionAPI} api
  29588. * @return {Array.<number>}
  29589. */
  29590. function updatePosition(positionExpr, x, y, confine, content, params, el, api) {
  29591. var viewWidth = api.getWidth();
  29592. var viewHeight = api.getHeight();
  29593. var rect = el && el.getBoundingRect().clone();
  29594. el && rect.applyTransform(el.transform);
  29595. if (typeof positionExpr === 'function') {
  29596. // Callback of position can be an array or a string specify the position
  29597. positionExpr = positionExpr([x, y], params, content.el, rect);
  29598. }
  29599. if (zrUtil.isArray(positionExpr)) {
  29600. x = parsePercent(positionExpr[0], viewWidth);
  29601. y = parsePercent(positionExpr[1], viewHeight);
  29602. }
  29603. // Specify tooltip position by string 'top' 'bottom' 'left' 'right' around graphic element
  29604. else if (typeof positionExpr === 'string' && el) {
  29605. var pos = calcTooltipPosition(
  29606. positionExpr, rect, content.el
  29607. );
  29608. x = pos[0];
  29609. y = pos[1];
  29610. }
  29611. else {
  29612. var pos = refixTooltipPosition(
  29613. x, y, content.el, viewWidth, viewHeight
  29614. );
  29615. x = pos[0];
  29616. y = pos[1];
  29617. }
  29618. if (confine) {
  29619. var pos = confineTooltipPosition(
  29620. x, y, content.el, viewWidth, viewHeight
  29621. );
  29622. x = pos[0];
  29623. y = pos[1];
  29624. }
  29625. content.moveTo(x, y);
  29626. }
  29627. function ifSeriesSupportAxisTrigger(seriesModel) {
  29628. var coordSys = seriesModel.coordinateSystem;
  29629. var trigger = seriesModel.get('tooltip.trigger', true);
  29630. // Ignore series use item tooltip trigger and series coordinate system is not cartesian or
  29631. return !(!coordSys
  29632. || (coordSys.type !== 'cartesian2d' && coordSys.type !== 'polar' && coordSys.type !== 'singleAxis')
  29633. || trigger === 'item');
  29634. }
  29635. __webpack_require__(1).extendComponentView({
  29636. type: 'tooltip',
  29637. _axisPointers: {},
  29638. init: function (ecModel, api) {
  29639. if (env.node) {
  29640. return;
  29641. }
  29642. var tooltipContent = new TooltipContent(api.getDom(), api);
  29643. this._tooltipContent = tooltipContent;
  29644. },
  29645. render: function (tooltipModel, ecModel, api) {
  29646. if (env.node) {
  29647. return;
  29648. }
  29649. // Reset
  29650. this.group.removeAll();
  29651. /**
  29652. * @type {Object}
  29653. * @private
  29654. */
  29655. this._axisPointers = {};
  29656. /**
  29657. * @private
  29658. * @type {module:echarts/component/tooltip/TooltipModel}
  29659. */
  29660. this._tooltipModel = tooltipModel;
  29661. /**
  29662. * @private
  29663. * @type {module:echarts/model/Global}
  29664. */
  29665. this._ecModel = ecModel;
  29666. /**
  29667. * @private
  29668. * @type {module:echarts/ExtensionAPI}
  29669. */
  29670. this._api = api;
  29671. /**
  29672. * @type {Object}
  29673. * @private
  29674. */
  29675. this._lastHover = {
  29676. // data
  29677. // payloadBatch
  29678. };
  29679. var tooltipContent = this._tooltipContent;
  29680. tooltipContent.update();
  29681. tooltipContent.enterable = tooltipModel.get('enterable');
  29682. this._alwaysShowContent = tooltipModel.get('alwaysShowContent');
  29683. /**
  29684. * @type {Object.<string, Array>}
  29685. */
  29686. this._seriesGroupByAxis = this._prepareAxisTriggerData(
  29687. tooltipModel, ecModel
  29688. );
  29689. var crossText = this._crossText;
  29690. if (crossText) {
  29691. this.group.add(crossText);
  29692. }
  29693. var triggerOn = tooltipModel.get('triggerOn');
  29694. // Try to keep the tooltip show when refreshing
  29695. if (this._lastX != null
  29696. && this._lastY != null
  29697. // When user is willing to control tooltip totally using API,
  29698. // self.manuallyShowTip({x, y}) might cause tooltip hide,
  29699. // which is not expected.
  29700. && triggerOn !== 'none'
  29701. ) {
  29702. var self = this;
  29703. clearTimeout(this._refreshUpdateTimeout);
  29704. this._refreshUpdateTimeout = setTimeout(function () {
  29705. // Show tip next tick after other charts are rendered
  29706. // In case highlight action has wrong result
  29707. // FIXME
  29708. self.manuallyShowTip(tooltipModel, ecModel, api, {
  29709. x: self._lastX,
  29710. y: self._lastY
  29711. });
  29712. });
  29713. }
  29714. var zr = this._api.getZr();
  29715. zr.off('click', this._tryShow);
  29716. zr.off('mousemove', this._mousemove);
  29717. zr.off('mouseout', this._hide);
  29718. zr.off('globalout', this._hide);
  29719. if (triggerOn === 'click') {
  29720. zr.on('click', this._tryShow, this);
  29721. }
  29722. else if (triggerOn === 'mousemove') {
  29723. zr.on('mousemove', this._mousemove, this);
  29724. zr.on('mouseout', this._hide, this);
  29725. zr.on('globalout', this._hide, this);
  29726. }
  29727. // else triggerOn is 'none', which enable user
  29728. // to control tooltip totally using API.
  29729. },
  29730. _mousemove: function (e) {
  29731. var showDelay = this._tooltipModel.get('showDelay');
  29732. var self = this;
  29733. clearTimeout(this._showTimeout);
  29734. if (showDelay > 0) {
  29735. this._showTimeout = setTimeout(function () {
  29736. self._tryShow(e);
  29737. }, showDelay);
  29738. }
  29739. else {
  29740. this._tryShow(e);
  29741. }
  29742. },
  29743. /**
  29744. * Show tip manually by
  29745. * dispatchAction({
  29746. * type: 'showTip',
  29747. * x: 10,
  29748. * y: 10
  29749. * });
  29750. * Or
  29751. * dispatchAction({
  29752. * type: 'showTip',
  29753. * seriesIndex: 0,
  29754. * dataIndex or dataIndexInside or name
  29755. * });
  29756. *
  29757. * TODO Batch
  29758. */
  29759. manuallyShowTip: function (tooltipModel, ecModel, api, payload) {
  29760. // From self
  29761. if (payload.from === this.uid) {
  29762. return;
  29763. }
  29764. var ecModel = this._ecModel;
  29765. var seriesIndex = payload.seriesIndex;
  29766. var seriesModel = ecModel.getSeriesByIndex(seriesIndex);
  29767. var api = this._api;
  29768. var isTriggerAxis = this._tooltipModel.get('trigger') === 'axis';
  29769. function seriesHaveDataOnIndex(_series) {
  29770. var data = _series.getData();
  29771. var dataIndex = modelUtil.queryDataIndex(data, payload);
  29772. // Have single dataIndex
  29773. if (dataIndex != null && !zrUtil.isArray(dataIndex)
  29774. && data.hasValue(dataIndex)
  29775. ) {
  29776. return true;
  29777. }
  29778. }
  29779. if (payload.x == null || payload.y == null) {
  29780. if (isTriggerAxis) {
  29781. // Find another series.
  29782. if (seriesModel && !seriesHaveDataOnIndex(seriesModel)) {
  29783. seriesModel = null;
  29784. }
  29785. if (!seriesModel) {
  29786. // Find the first series can use axis trigger And data is not null
  29787. ecModel.eachSeries(function (_series) {
  29788. if (ifSeriesSupportAxisTrigger(_series) && !seriesModel) {
  29789. if (seriesHaveDataOnIndex(_series)) {
  29790. seriesModel = _series;
  29791. }
  29792. }
  29793. });
  29794. }
  29795. }
  29796. else {
  29797. // Use the first series by default.
  29798. seriesModel = seriesModel || ecModel.getSeriesByIndex(0);
  29799. }
  29800. if (seriesModel) {
  29801. var data = seriesModel.getData();
  29802. var dataIndex = modelUtil.queryDataIndex(data, payload);
  29803. if (dataIndex == null || zrUtil.isArray(dataIndex)) {
  29804. return;
  29805. }
  29806. var el = data.getItemGraphicEl(dataIndex);
  29807. var cx;
  29808. var cy;
  29809. // Try to get the point in coordinate system
  29810. var coordSys = seriesModel.coordinateSystem;
  29811. if (seriesModel.getTooltipPosition) {
  29812. var point = seriesModel.getTooltipPosition(dataIndex) || [];
  29813. cx = point[0];
  29814. cy = point[1];
  29815. }
  29816. else if (coordSys && coordSys.dataToPoint) {
  29817. var point = coordSys.dataToPoint(
  29818. data.getValues(
  29819. zrUtil.map(coordSys.dimensions, function (dim) {
  29820. return seriesModel.coordDimToDataDim(dim)[0];
  29821. }), dataIndex, true
  29822. )
  29823. );
  29824. cx = point && point[0];
  29825. cy = point && point[1];
  29826. }
  29827. else if (el) {
  29828. // Use graphic bounding rect
  29829. var rect = el.getBoundingRect().clone();
  29830. rect.applyTransform(el.transform);
  29831. cx = rect.x + rect.width / 2;
  29832. cy = rect.y + rect.height / 2;
  29833. }
  29834. if (cx != null && cy != null) {
  29835. this._tryShow({
  29836. offsetX: cx,
  29837. offsetY: cy,
  29838. position: payload.position,
  29839. target: el,
  29840. event: {}
  29841. });
  29842. }
  29843. }
  29844. }
  29845. else {
  29846. var el = api.getZr().handler.findHover(payload.x, payload.y);
  29847. this._tryShow({
  29848. offsetX: payload.x,
  29849. offsetY: payload.y,
  29850. position: payload.position,
  29851. target: el,
  29852. event: {}
  29853. });
  29854. }
  29855. },
  29856. manuallyHideTip: function (tooltipModel, ecModel, api, payload) {
  29857. if (payload.from === this.uid) {
  29858. return;
  29859. }
  29860. this._hide();
  29861. },
  29862. _prepareAxisTriggerData: function (tooltipModel, ecModel) {
  29863. // Prepare data for axis trigger
  29864. var seriesGroupByAxis = {};
  29865. ecModel.eachSeries(function (seriesModel) {
  29866. if (ifSeriesSupportAxisTrigger(seriesModel)) {
  29867. var coordSys = seriesModel.coordinateSystem;
  29868. var baseAxis;
  29869. var key;
  29870. // Only cartesian2d, polar and single support axis trigger
  29871. if (coordSys.type === 'cartesian2d') {
  29872. // FIXME `axisPointer.axis` is not baseAxis
  29873. baseAxis = coordSys.getBaseAxis();
  29874. key = baseAxis.dim + baseAxis.index;
  29875. }
  29876. else if (coordSys.type === 'singleAxis') {
  29877. baseAxis = coordSys.getAxis();
  29878. key = baseAxis.dim + baseAxis.type;
  29879. }
  29880. else {
  29881. baseAxis = coordSys.getBaseAxis();
  29882. key = baseAxis.dim + coordSys.name;
  29883. }
  29884. seriesGroupByAxis[key] = seriesGroupByAxis[key] || {
  29885. coordSys: [],
  29886. series: []
  29887. };
  29888. seriesGroupByAxis[key].coordSys.push(coordSys);
  29889. seriesGroupByAxis[key].series.push(seriesModel);
  29890. }
  29891. }, this);
  29892. return seriesGroupByAxis;
  29893. },
  29894. /**
  29895. * mousemove handler
  29896. * @param {Object} e
  29897. * @private
  29898. */
  29899. _tryShow: function (e) {
  29900. var el = e.target;
  29901. var tooltipModel = this._tooltipModel;
  29902. var globalTrigger = tooltipModel.get('trigger');
  29903. var ecModel = this._ecModel;
  29904. var api = this._api;
  29905. if (!tooltipModel) {
  29906. return;
  29907. }
  29908. // Save mouse x, mouse y. So we can try to keep showing the tip if chart is refreshed
  29909. this._lastX = e.offsetX;
  29910. this._lastY = e.offsetY;
  29911. // Always show item tooltip if mouse is on the element with dataIndex
  29912. if (el && el.dataIndex != null) {
  29913. // Use dataModel in element if possible
  29914. // Used when mouseover on a element like markPoint or edge
  29915. // In which case, the data is not main data in series.
  29916. var dataModel = el.dataModel || ecModel.getSeriesByIndex(el.seriesIndex);
  29917. var dataIndex = el.dataIndex;
  29918. var data = dataModel.getData();
  29919. var itemModel = data.getItemModel(dataIndex);
  29920. // Series or single data may use item trigger when global is axis trigger
  29921. if ((itemModel.get('tooltip.trigger') || globalTrigger) === 'axis') {
  29922. this._showAxisTooltip(tooltipModel, ecModel, e);
  29923. }
  29924. else {
  29925. // Reset ticket
  29926. this._ticket = '';
  29927. // If either single data or series use item trigger
  29928. this._hideAxisPointer();
  29929. // Reset last hover and dispatch downplay action
  29930. this._resetLastHover();
  29931. this._showItemTooltipContent(dataModel, dataIndex, el.dataType, e);
  29932. }
  29933. api.dispatchAction({
  29934. type: 'showTip',
  29935. from: this.uid,
  29936. dataIndexInside: dataIndex,
  29937. dataIndex: data.getRawIndex(dataIndex), // expose to user.
  29938. seriesIndex: el.seriesIndex
  29939. });
  29940. }
  29941. // Tooltip provided directly. Like legend
  29942. else if (el && el.tooltip) {
  29943. var tooltipOpt = el.tooltip;
  29944. if (typeof tooltipOpt === 'string') {
  29945. var content = tooltipOpt;
  29946. tooltipOpt = {
  29947. content: content,
  29948. // Fixed formatter
  29949. formatter: content
  29950. };
  29951. }
  29952. var subTooltipModel = new Model(tooltipOpt, tooltipModel);
  29953. var defaultHtml = subTooltipModel.get('content');
  29954. var asyncTicket = Math.random();
  29955. this._showTooltipContent(
  29956. // TODO params
  29957. subTooltipModel, defaultHtml, subTooltipModel.get('formatterParams') || {},
  29958. asyncTicket, e.offsetX, e.offsetY, e.position, el, api
  29959. );
  29960. }
  29961. else {
  29962. if (globalTrigger === 'item') {
  29963. this._hide();
  29964. }
  29965. else {
  29966. // Try show axis tooltip
  29967. this._showAxisTooltip(tooltipModel, ecModel, e);
  29968. }
  29969. // Action of cross pointer
  29970. // other pointer types will trigger action in _dispatchAndShowSeriesTooltipContent method
  29971. if (tooltipModel.get('axisPointer.type') === 'cross') {
  29972. api.dispatchAction({
  29973. type: 'showTip',
  29974. from: this.uid,
  29975. x: e.offsetX,
  29976. y: e.offsetY
  29977. });
  29978. }
  29979. }
  29980. },
  29981. /**
  29982. * Show tooltip on axis
  29983. * @param {module:echarts/component/tooltip/TooltipModel} tooltipModel
  29984. * @param {module:echarts/model/Global} ecModel
  29985. * @param {Object} e
  29986. * @private
  29987. */
  29988. _showAxisTooltip: function (tooltipModel, ecModel, e) {
  29989. var axisPointerModel = tooltipModel.getModel('axisPointer');
  29990. var axisPointerType = axisPointerModel.get('type');
  29991. if (axisPointerType === 'cross') {
  29992. var el = e.target;
  29993. if (el && el.dataIndex != null) {
  29994. var seriesModel = ecModel.getSeriesByIndex(el.seriesIndex);
  29995. var dataIndex = el.dataIndex;
  29996. this._showItemTooltipContent(seriesModel, dataIndex, el.dataType, e);
  29997. }
  29998. }
  29999. this._showAxisPointer();
  30000. var allNotShow = true;
  30001. zrUtil.each(this._seriesGroupByAxis, function (seriesCoordSysSameAxis) {
  30002. // Try show the axis pointer
  30003. var allCoordSys = seriesCoordSysSameAxis.coordSys;
  30004. var coordSys = allCoordSys[0];
  30005. // If mouse position is not in the grid or polar
  30006. var point = [e.offsetX, e.offsetY];
  30007. if (!coordSys.containPoint(point)) {
  30008. // Hide axis pointer
  30009. this._hideAxisPointer(coordSys.name);
  30010. return;
  30011. }
  30012. allNotShow = false;
  30013. // Make sure point is discrete on cateogry axis
  30014. var dimensions = coordSys.dimensions;
  30015. var value = coordSys.pointToData(point, true);
  30016. point = coordSys.dataToPoint(value);
  30017. var baseAxis = coordSys.getBaseAxis();
  30018. var axisType = axisPointerModel.get('axis');
  30019. if (axisType === 'auto') {
  30020. axisType = baseAxis.dim;
  30021. }
  30022. if (baseAxis.isBlank() || zrUtil.eqNaN(point[0]) || zrUtil.eqNaN(point[1])) {
  30023. this._hideAxisPointer(coordSys.name);
  30024. return;
  30025. }
  30026. var contentNotChange = false;
  30027. var lastHover = this._lastHover;
  30028. if (axisPointerType === 'cross') {
  30029. // If hover data not changed
  30030. // Possible when two axes are all category
  30031. if (dataEqual(lastHover.data, value)) {
  30032. contentNotChange = true;
  30033. }
  30034. lastHover.data = value;
  30035. }
  30036. else {
  30037. var valIndex = zrUtil.indexOf(dimensions, axisType);
  30038. // If hover data not changed on the axis dimension
  30039. if (lastHover.data === value[valIndex]) {
  30040. contentNotChange = true;
  30041. }
  30042. lastHover.data = value[valIndex];
  30043. }
  30044. var enableAnimation = tooltipModel.get('animation');
  30045. if (coordSys.type === 'cartesian2d' && !contentNotChange) {
  30046. this._showCartesianPointer(
  30047. axisPointerModel, coordSys, axisType, point, enableAnimation
  30048. );
  30049. }
  30050. else if (coordSys.type === 'polar' && !contentNotChange) {
  30051. this._showPolarPointer(
  30052. axisPointerModel, coordSys, axisType, point, enableAnimation
  30053. );
  30054. }
  30055. else if (coordSys.type === 'singleAxis' && !contentNotChange) {
  30056. this._showSinglePointer(
  30057. axisPointerModel, coordSys, axisType, point, enableAnimation
  30058. );
  30059. }
  30060. if (axisPointerType !== 'cross') {
  30061. this._dispatchAndShowSeriesTooltipContent(
  30062. coordSys, seriesCoordSysSameAxis.series, point, value, contentNotChange, e.position
  30063. );
  30064. }
  30065. }, this);
  30066. if (!this._tooltipModel.get('show')) {
  30067. this._hideAxisPointer();
  30068. }
  30069. if (allNotShow) {
  30070. this._hide();
  30071. }
  30072. },
  30073. /**
  30074. * Show tooltip on axis of cartesian coordinate
  30075. * @param {module:echarts/model/Model} axisPointerModel
  30076. * @param {module:echarts/coord/cartesian/Cartesian2D} cartesians
  30077. * @param {string} axisType
  30078. * @param {Array.<number>} point
  30079. * @private
  30080. */
  30081. _showCartesianPointer: function (axisPointerModel, cartesian, axisType, point, enableAnimation) {
  30082. var self = this;
  30083. var axisPointerType = axisPointerModel.get('type');
  30084. var baseAxis = cartesian.getBaseAxis();
  30085. var moveAnimation = enableAnimation
  30086. && axisPointerType !== 'cross'
  30087. && baseAxis.type === 'category'
  30088. && baseAxis.getBandWidth() > 20;
  30089. if (axisPointerType === 'cross') {
  30090. moveGridLine('x', point, cartesian.getAxis('y').getGlobalExtent());
  30091. moveGridLine('y', point, cartesian.getAxis('x').getGlobalExtent());
  30092. this._updateCrossText(cartesian, point, axisPointerModel);
  30093. }
  30094. else {
  30095. var otherAxis = cartesian.getAxis(axisType === 'x' ? 'y' : 'x');
  30096. var otherExtent = otherAxis.getGlobalExtent();
  30097. if (cartesian.type === 'cartesian2d') {
  30098. (axisPointerType === 'line' ? moveGridLine : moveGridShadow)(
  30099. axisType, point, otherExtent
  30100. );
  30101. }
  30102. }
  30103. /**
  30104. * @inner
  30105. */
  30106. function moveGridLine(axisType, point, otherExtent) {
  30107. var targetShape = axisType === 'x'
  30108. ? makeLineShape(point[0], otherExtent[0], point[0], otherExtent[1])
  30109. : makeLineShape(otherExtent[0], point[1], otherExtent[1], point[1]);
  30110. var pointerEl = self._getPointerElement(
  30111. cartesian, axisPointerModel, axisType, targetShape
  30112. );
  30113. graphic.subPixelOptimizeLine({
  30114. shape: targetShape,
  30115. style: pointerEl.style
  30116. });
  30117. moveAnimation
  30118. ? graphic.updateProps(pointerEl, {
  30119. shape: targetShape
  30120. }, axisPointerModel)
  30121. : pointerEl.attr({
  30122. shape: targetShape
  30123. });
  30124. }
  30125. /**
  30126. * @inner
  30127. */
  30128. function moveGridShadow(axisType, point, otherExtent) {
  30129. var axis = cartesian.getAxis(axisType);
  30130. var bandWidth = axis.getBandWidth();
  30131. var span = otherExtent[1] - otherExtent[0];
  30132. var targetShape = axisType === 'x'
  30133. ? makeRectShape(point[0] - bandWidth / 2, otherExtent[0], bandWidth, span)
  30134. : makeRectShape(otherExtent[0], point[1] - bandWidth / 2, span, bandWidth);
  30135. var pointerEl = self._getPointerElement(
  30136. cartesian, axisPointerModel, axisType, targetShape
  30137. );
  30138. moveAnimation
  30139. ? graphic.updateProps(pointerEl, {
  30140. shape: targetShape
  30141. }, axisPointerModel)
  30142. : pointerEl.attr({
  30143. shape: targetShape
  30144. });
  30145. }
  30146. },
  30147. _showSinglePointer: function (axisPointerModel, single, axisType, point, enableAnimation) {
  30148. var self = this;
  30149. var axisPointerType = axisPointerModel.get('type');
  30150. var moveAnimation =
  30151. enableAnimation
  30152. && axisPointerType !== 'cross'
  30153. && single.getBaseAxis().type === 'category';
  30154. var rect = single.getRect();
  30155. var otherExtent = [rect.y, rect.y + rect.height];
  30156. moveSingleLine(axisType, point, otherExtent);
  30157. /**
  30158. * @inner
  30159. */
  30160. function moveSingleLine(axisType, point, otherExtent) {
  30161. var axis = single.getAxis();
  30162. var orient = axis.orient;
  30163. var targetShape = orient === 'horizontal'
  30164. ? makeLineShape(point[0], otherExtent[0], point[0], otherExtent[1])
  30165. : makeLineShape(otherExtent[0], point[1], otherExtent[1], point[1]);
  30166. var pointerEl = self._getPointerElement(
  30167. single, axisPointerModel, axisType, targetShape
  30168. );
  30169. moveAnimation
  30170. ? graphic.updateProps(pointerEl, {
  30171. shape: targetShape
  30172. }, axisPointerModel)
  30173. : pointerEl.attr({
  30174. shape: targetShape
  30175. });
  30176. }
  30177. },
  30178. /**
  30179. * Show tooltip on axis of polar coordinate
  30180. * @param {module:echarts/model/Model} axisPointerModel
  30181. * @param {Array.<module:echarts/coord/polar/Polar>} polar
  30182. * @param {string} axisType
  30183. * @param {Array.<number>} point
  30184. */
  30185. _showPolarPointer: function (axisPointerModel, polar, axisType, point, enableAnimation) {
  30186. var self = this;
  30187. var axisPointerType = axisPointerModel.get('type');
  30188. var angleAxis = polar.getAngleAxis();
  30189. var radiusAxis = polar.getRadiusAxis();
  30190. var moveAnimation = enableAnimation
  30191. && axisPointerType !== 'cross'
  30192. && polar.getBaseAxis().type === 'category';
  30193. if (axisPointerType === 'cross') {
  30194. movePolarLine('angle', point, radiusAxis.getExtent());
  30195. movePolarLine('radius', point, angleAxis.getExtent());
  30196. this._updateCrossText(polar, point, axisPointerModel);
  30197. }
  30198. else {
  30199. var otherAxis = polar.getAxis(axisType === 'radius' ? 'angle' : 'radius');
  30200. var otherExtent = otherAxis.getExtent();
  30201. (axisPointerType === 'line' ? movePolarLine : movePolarShadow)(
  30202. axisType, point, otherExtent
  30203. );
  30204. }
  30205. /**
  30206. * @inner
  30207. */
  30208. function movePolarLine(axisType, point, otherExtent) {
  30209. var mouseCoord = polar.pointToCoord(point);
  30210. var targetShape;
  30211. if (axisType === 'angle') {
  30212. var p1 = polar.coordToPoint([otherExtent[0], mouseCoord[1]]);
  30213. var p2 = polar.coordToPoint([otherExtent[1], mouseCoord[1]]);
  30214. targetShape = makeLineShape(p1[0], p1[1], p2[0], p2[1]);
  30215. }
  30216. else {
  30217. targetShape = {
  30218. cx: polar.cx,
  30219. cy: polar.cy,
  30220. r: mouseCoord[0]
  30221. };
  30222. }
  30223. var pointerEl = self._getPointerElement(
  30224. polar, axisPointerModel, axisType, targetShape
  30225. );
  30226. moveAnimation
  30227. ? graphic.updateProps(pointerEl, {
  30228. shape: targetShape
  30229. }, axisPointerModel)
  30230. : pointerEl.attr({
  30231. shape: targetShape
  30232. });
  30233. }
  30234. /**
  30235. * @inner
  30236. */
  30237. function movePolarShadow(axisType, point, otherExtent) {
  30238. var axis = polar.getAxis(axisType);
  30239. var bandWidth = axis.getBandWidth();
  30240. var mouseCoord = polar.pointToCoord(point);
  30241. var targetShape;
  30242. var radian = Math.PI / 180;
  30243. if (axisType === 'angle') {
  30244. targetShape = makeSectorShape(
  30245. polar.cx, polar.cy,
  30246. otherExtent[0], otherExtent[1],
  30247. // In ECharts y is negative if angle is positive
  30248. (-mouseCoord[1] - bandWidth / 2) * radian,
  30249. (-mouseCoord[1] + bandWidth / 2) * radian
  30250. );
  30251. }
  30252. else {
  30253. targetShape = makeSectorShape(
  30254. polar.cx, polar.cy,
  30255. mouseCoord[0] - bandWidth / 2,
  30256. mouseCoord[0] + bandWidth / 2,
  30257. 0, Math.PI * 2
  30258. );
  30259. }
  30260. var pointerEl = self._getPointerElement(
  30261. polar, axisPointerModel, axisType, targetShape
  30262. );
  30263. moveAnimation
  30264. ? graphic.updateProps(pointerEl, {
  30265. shape: targetShape
  30266. }, axisPointerModel)
  30267. : pointerEl.attr({
  30268. shape: targetShape
  30269. });
  30270. }
  30271. },
  30272. _updateCrossText: function (coordSys, point, axisPointerModel) {
  30273. var crossStyleModel = axisPointerModel.getModel('crossStyle');
  30274. var textStyleModel = crossStyleModel.getModel('textStyle');
  30275. var tooltipModel = this._tooltipModel;
  30276. var text = this._crossText;
  30277. if (!text) {
  30278. text = this._crossText = new graphic.Text({
  30279. style: {
  30280. textAlign: 'left',
  30281. textVerticalAlign: 'bottom'
  30282. }
  30283. });
  30284. this.group.add(text);
  30285. }
  30286. var value = coordSys.pointToData(point);
  30287. var dims = coordSys.dimensions;
  30288. value = zrUtil.map(value, function (val, idx) {
  30289. var axis = coordSys.getAxis(dims[idx]);
  30290. if (axis.type === 'category' || axis.type === 'time') {
  30291. val = axis.scale.getLabel(val);
  30292. }
  30293. else {
  30294. val = formatUtil.addCommas(
  30295. val.toFixed(axis.getPixelPrecision())
  30296. );
  30297. }
  30298. return val;
  30299. });
  30300. text.setStyle({
  30301. fill: textStyleModel.getTextColor() || crossStyleModel.get('color'),
  30302. textFont: textStyleModel.getFont(),
  30303. text: value.join(', '),
  30304. x: point[0] + 5,
  30305. y: point[1] - 5
  30306. });
  30307. text.z = tooltipModel.get('z');
  30308. text.zlevel = tooltipModel.get('zlevel');
  30309. },
  30310. _getPointerElement: function (coordSys, pointerModel, axisType, initShape) {
  30311. var tooltipModel = this._tooltipModel;
  30312. var z = tooltipModel.get('z');
  30313. var zlevel = tooltipModel.get('zlevel');
  30314. var axisPointers = this._axisPointers;
  30315. var coordSysName = coordSys.name;
  30316. axisPointers[coordSysName] = axisPointers[coordSysName] || {};
  30317. if (axisPointers[coordSysName][axisType]) {
  30318. return axisPointers[coordSysName][axisType];
  30319. }
  30320. // Create if not exists
  30321. var pointerType = pointerModel.get('type');
  30322. var styleModel = pointerModel.getModel(pointerType + 'Style');
  30323. var isShadow = pointerType === 'shadow';
  30324. var style = styleModel[isShadow ? 'getAreaStyle' : 'getLineStyle']();
  30325. var elementType = coordSys.type === 'polar'
  30326. ? (isShadow ? 'Sector' : (axisType === 'radius' ? 'Circle' : 'Line'))
  30327. : (isShadow ? 'Rect' : 'Line');
  30328. isShadow ? (style.stroke = null) : (style.fill = null);
  30329. var el = axisPointers[coordSysName][axisType] = new graphic[elementType]({
  30330. style: style,
  30331. z: z,
  30332. zlevel: zlevel,
  30333. silent: true,
  30334. shape: initShape
  30335. });
  30336. this.group.add(el);
  30337. return el;
  30338. },
  30339. /**
  30340. * Dispatch actions and show tooltip on series
  30341. * @param {Array.<module:echarts/model/Series>} seriesList
  30342. * @param {Array.<number>} point
  30343. * @param {Array.<number>} value
  30344. * @param {boolean} contentNotChange
  30345. * @param {Array.<number>|string|Function} [positionExpr]
  30346. */
  30347. _dispatchAndShowSeriesTooltipContent: function (
  30348. coordSys, seriesList, point, value, contentNotChange, positionExpr
  30349. ) {
  30350. var rootTooltipModel = this._tooltipModel;
  30351. var baseAxis = coordSys.getBaseAxis();
  30352. var baseDimIndex = ({x: 1, radius: 1, single: 1})[baseAxis.dim] ? 0 : 1;
  30353. if (!seriesList.length) {
  30354. return;
  30355. }
  30356. var payloadBatch = zrUtil.map(seriesList, function (series) {
  30357. return {
  30358. seriesIndex: series.seriesIndex,
  30359. dataIndexInside: series.getAxisTooltipDataIndex
  30360. ? series.getAxisTooltipDataIndex(series.coordDimToDataDim(baseAxis.dim), value, baseAxis)
  30361. : series.getData().indexOfNearest(
  30362. series.coordDimToDataDim(baseAxis.dim)[0],
  30363. value[baseDimIndex],
  30364. // Add a threshold to avoid find the wrong dataIndex when data length is not same
  30365. false, baseAxis.type === 'category' ? 0.5 : null
  30366. )
  30367. };
  30368. });
  30369. var sampleSeriesIndex;
  30370. zrUtil.each(payloadBatch, function (payload, idx) {
  30371. if (seriesList[idx].getData().hasValue(payload.dataIndexInside)) {
  30372. sampleSeriesIndex = idx;
  30373. }
  30374. });
  30375. // Fallback to 0.
  30376. sampleSeriesIndex = sampleSeriesIndex || 0;
  30377. var lastHover = this._lastHover;
  30378. var api = this._api;
  30379. // Dispatch downplay action
  30380. if (lastHover.payloadBatch && !contentNotChange) {
  30381. api.dispatchAction({
  30382. type: 'downplay',
  30383. batch: lastHover.payloadBatch
  30384. });
  30385. }
  30386. // Dispatch highlight action
  30387. if (!contentNotChange) {
  30388. api.dispatchAction({
  30389. type: 'highlight',
  30390. batch: payloadBatch
  30391. });
  30392. lastHover.payloadBatch = payloadBatch;
  30393. }
  30394. // Dispatch showTip action
  30395. var dataIndex = payloadBatch[sampleSeriesIndex].dataIndexInside;
  30396. api.dispatchAction({
  30397. type: 'showTip',
  30398. dataIndexInside: dataIndex,
  30399. // expose to user.
  30400. dataIndex: seriesList[sampleSeriesIndex].getData().getRawIndex(dataIndex),
  30401. seriesIndex: payloadBatch[sampleSeriesIndex].seriesIndex,
  30402. from: this.uid
  30403. });
  30404. if (baseAxis && rootTooltipModel.get('showContent') && rootTooltipModel.get('show')) {
  30405. var paramsList = zrUtil.map(seriesList, function (series, index) {
  30406. return series.getDataParams(payloadBatch[index].dataIndexInside);
  30407. });
  30408. if (!contentNotChange) {
  30409. // Update html content
  30410. var firstDataIndex = payloadBatch[sampleSeriesIndex].dataIndexInside;
  30411. // Default tooltip content
  30412. // FIXME
  30413. // (1) shold be the first data which has name?
  30414. // (2) themeRiver, firstDataIndex is array, and first line is unnecessary.
  30415. var firstLine = baseAxis.type === 'time'
  30416. ? baseAxis.scale.getLabel(value[baseDimIndex])
  30417. : seriesList[sampleSeriesIndex].getData().getName(firstDataIndex);
  30418. var defaultHtml = (firstLine ? formatUtil.encodeHTML(firstLine) + '<br />' : '')
  30419. + zrUtil.map(seriesList, function (series, index) {
  30420. return series.formatTooltip(payloadBatch[index].dataIndexInside, true);
  30421. }).join('<br />');
  30422. var asyncTicket = 'axis_' + coordSys.name + '_' + firstDataIndex;
  30423. this._showTooltipContent(
  30424. rootTooltipModel, defaultHtml, paramsList, asyncTicket,
  30425. point[0], point[1], positionExpr, null, api
  30426. );
  30427. }
  30428. else {
  30429. updatePosition(
  30430. positionExpr || rootTooltipModel.get('position'),
  30431. point[0], point[1],
  30432. rootTooltipModel.get('confine'),
  30433. this._tooltipContent, paramsList, null, api
  30434. );
  30435. }
  30436. }
  30437. },
  30438. /**
  30439. * Show tooltip on item
  30440. * @param {module:echarts/model/Series} seriesModel
  30441. * @param {number} dataIndex
  30442. * @param {string} dataType
  30443. * @param {Object} e
  30444. */
  30445. _showItemTooltipContent: function (seriesModel, dataIndex, dataType, e) {
  30446. // FIXME Graph data
  30447. var api = this._api;
  30448. var data = seriesModel.getData(dataType);
  30449. var itemModel = data.getItemModel(dataIndex);
  30450. var tooltipOpt = itemModel.get('tooltip', true);
  30451. if (typeof tooltipOpt === 'string') {
  30452. // In each data item tooltip can be simply write:
  30453. // {
  30454. // value: 10,
  30455. // tooltip: 'Something you need to know'
  30456. // }
  30457. var tooltipContent = tooltipOpt;
  30458. tooltipOpt = {
  30459. formatter: tooltipContent
  30460. };
  30461. }
  30462. var rootTooltipModel = this._tooltipModel;
  30463. var seriesTooltipModel = seriesModel.getModel(
  30464. 'tooltip', rootTooltipModel
  30465. );
  30466. var tooltipModel = new Model(tooltipOpt, seriesTooltipModel, seriesTooltipModel.ecModel);
  30467. var params = seriesModel.getDataParams(dataIndex, dataType);
  30468. var defaultHtml = seriesModel.formatTooltip(dataIndex, false, dataType);
  30469. var asyncTicket = 'item_' + seriesModel.name + '_' + dataIndex;
  30470. this._showTooltipContent(
  30471. tooltipModel, defaultHtml, params, asyncTicket,
  30472. e.offsetX, e.offsetY, e.position, e.target, api
  30473. );
  30474. },
  30475. _showTooltipContent: function (
  30476. tooltipModel, defaultHtml, params, asyncTicket, x, y, positionExpr, target, api
  30477. ) {
  30478. // Reset ticket
  30479. this._ticket = '';
  30480. if (tooltipModel.get('showContent') && tooltipModel.get('show')) {
  30481. var tooltipContent = this._tooltipContent;
  30482. var confine = tooltipModel.get('confine');
  30483. var formatter = tooltipModel.get('formatter');
  30484. positionExpr = positionExpr || tooltipModel.get('position');
  30485. var html = defaultHtml;
  30486. if (formatter) {
  30487. if (typeof formatter === 'string') {
  30488. html = formatUtil.formatTpl(formatter, params, true);
  30489. }
  30490. else if (typeof formatter === 'function') {
  30491. var self = this;
  30492. var ticket = asyncTicket;
  30493. var callback = function (cbTicket, html) {
  30494. if (cbTicket === self._ticket) {
  30495. tooltipContent.setContent(html);
  30496. updatePosition(
  30497. positionExpr, x, y, confine,
  30498. tooltipContent, params, target, api
  30499. );
  30500. }
  30501. };
  30502. self._ticket = ticket;
  30503. html = formatter(params, ticket, callback);
  30504. }
  30505. }
  30506. tooltipContent.show(tooltipModel);
  30507. tooltipContent.setContent(html);
  30508. updatePosition(
  30509. positionExpr, x, y, confine,
  30510. tooltipContent, params, target, api
  30511. );
  30512. }
  30513. },
  30514. /**
  30515. * Show axis pointer
  30516. * @param {string} [coordSysName]
  30517. */
  30518. _showAxisPointer: function (coordSysName) {
  30519. if (coordSysName) {
  30520. var axisPointers = this._axisPointers[coordSysName];
  30521. axisPointers && zrUtil.each(axisPointers, function (el) {
  30522. el.show();
  30523. });
  30524. }
  30525. else {
  30526. this.group.eachChild(function (child) {
  30527. child.show();
  30528. });
  30529. this.group.show();
  30530. }
  30531. },
  30532. _resetLastHover: function () {
  30533. var lastHover = this._lastHover;
  30534. if (lastHover.payloadBatch) {
  30535. this._api.dispatchAction({
  30536. type: 'downplay',
  30537. batch: lastHover.payloadBatch
  30538. });
  30539. }
  30540. // Reset lastHover
  30541. this._lastHover = {};
  30542. },
  30543. /**
  30544. * Hide axis pointer
  30545. * @param {string} [coordSysName]
  30546. */
  30547. _hideAxisPointer: function (coordSysName) {
  30548. if (coordSysName) {
  30549. var axisPointers = this._axisPointers[coordSysName];
  30550. axisPointers && zrUtil.each(axisPointers, function (el) {
  30551. el.hide();
  30552. });
  30553. }
  30554. else {
  30555. if (this.group.children().length) {
  30556. this.group.hide();
  30557. }
  30558. }
  30559. },
  30560. _hide: function () {
  30561. clearTimeout(this._showTimeout);
  30562. this._hideAxisPointer();
  30563. this._resetLastHover();
  30564. if (!this._alwaysShowContent) {
  30565. this._tooltipContent.hideLater(this._tooltipModel.get('hideDelay'));
  30566. }
  30567. this._api.dispatchAction({
  30568. type: 'hideTip',
  30569. from: this.uid
  30570. });
  30571. this._lastX = this._lastY = null;
  30572. },
  30573. dispose: function (ecModel, api) {
  30574. if (env.node) {
  30575. return;
  30576. }
  30577. var zr = api.getZr();
  30578. this._tooltipContent.hide();
  30579. zr.off('click', this._tryShow);
  30580. zr.off('mousemove', this._mousemove);
  30581. zr.off('mouseout', this._hide);
  30582. zr.off('globalout', this._hide);
  30583. }
  30584. });
  30585. /***/ },
  30586. /* 302 */
  30587. /***/ function(module, exports, __webpack_require__) {
  30588. /**
  30589. * @module echarts/component/tooltip/TooltipContent
  30590. */
  30591. var zrUtil = __webpack_require__(4);
  30592. var zrColor = __webpack_require__(39);
  30593. var eventUtil = __webpack_require__(88);
  30594. var formatUtil = __webpack_require__(6);
  30595. var each = zrUtil.each;
  30596. var toCamelCase = formatUtil.toCamelCase;
  30597. var env = __webpack_require__(2);
  30598. var vendors = ['', '-webkit-', '-moz-', '-o-'];
  30599. var gCssText = 'position:absolute;display:block;border-style:solid;white-space:nowrap;z-index:9999999;';
  30600. /**
  30601. * @param {number} duration
  30602. * @return {string}
  30603. * @inner
  30604. */
  30605. function assembleTransition(duration) {
  30606. var transitionCurve = 'cubic-bezier(0.23, 1, 0.32, 1)';
  30607. var transitionText = 'left ' + duration + 's ' + transitionCurve + ','
  30608. + 'top ' + duration + 's ' + transitionCurve;
  30609. return zrUtil.map(vendors, function (vendorPrefix) {
  30610. return vendorPrefix + 'transition:' + transitionText;
  30611. }).join(';');
  30612. }
  30613. /**
  30614. * @param {Object} textStyle
  30615. * @return {string}
  30616. * @inner
  30617. */
  30618. function assembleFont(textStyleModel) {
  30619. var cssText = [];
  30620. var fontSize = textStyleModel.get('fontSize');
  30621. var color = textStyleModel.getTextColor();
  30622. color && cssText.push('color:' + color);
  30623. cssText.push('font:' + textStyleModel.getFont());
  30624. fontSize &&
  30625. cssText.push('line-height:' + Math.round(fontSize * 3 / 2) + 'px');
  30626. each(['decoration', 'align'], function (name) {
  30627. var val = textStyleModel.get(name);
  30628. val && cssText.push('text-' + name + ':' + val);
  30629. });
  30630. return cssText.join(';');
  30631. }
  30632. /**
  30633. * @param {Object} tooltipModel
  30634. * @return {string}
  30635. * @inner
  30636. */
  30637. function assembleCssText(tooltipModel) {
  30638. tooltipModel = tooltipModel;
  30639. var cssText = [];
  30640. var transitionDuration = tooltipModel.get('transitionDuration');
  30641. var backgroundColor = tooltipModel.get('backgroundColor');
  30642. var textStyleModel = tooltipModel.getModel('textStyle');
  30643. var padding = tooltipModel.get('padding');
  30644. // Animation transition
  30645. transitionDuration &&
  30646. cssText.push(assembleTransition(transitionDuration));
  30647. if (backgroundColor) {
  30648. if (env.canvasSupported) {
  30649. cssText.push('background-Color:' + backgroundColor);
  30650. }
  30651. else {
  30652. // for ie
  30653. cssText.push(
  30654. 'background-Color:#' + zrColor.toHex(backgroundColor)
  30655. );
  30656. cssText.push('filter:alpha(opacity=70)');
  30657. }
  30658. }
  30659. // Border style
  30660. each(['width', 'color', 'radius'], function (name) {
  30661. var borderName = 'border-' + name;
  30662. var camelCase = toCamelCase(borderName);
  30663. var val = tooltipModel.get(camelCase);
  30664. val != null &&
  30665. cssText.push(borderName + ':' + val + (name === 'color' ? '' : 'px'));
  30666. });
  30667. // Text style
  30668. cssText.push(assembleFont(textStyleModel));
  30669. // Padding
  30670. if (padding != null) {
  30671. cssText.push('padding:' + formatUtil.normalizeCssArray(padding).join('px ') + 'px');
  30672. }
  30673. return cssText.join(';') + ';';
  30674. }
  30675. /**
  30676. * @alias module:echarts/component/tooltip/TooltipContent
  30677. * @constructor
  30678. */
  30679. function TooltipContent(container, api) {
  30680. var el = document.createElement('div');
  30681. var zr = api.getZr();
  30682. this.el = el;
  30683. this._x = api.getWidth() / 2;
  30684. this._y = api.getHeight() / 2;
  30685. container.appendChild(el);
  30686. this._container = container;
  30687. this._show = false;
  30688. /**
  30689. * @private
  30690. */
  30691. this._hideTimeout;
  30692. var self = this;
  30693. el.onmouseenter = function () {
  30694. // clear the timeout in hideLater and keep showing tooltip
  30695. if (self.enterable) {
  30696. clearTimeout(self._hideTimeout);
  30697. self._show = true;
  30698. }
  30699. self._inContent = true;
  30700. };
  30701. el.onmousemove = function (e) {
  30702. e = e || window.event;
  30703. if (!self.enterable) {
  30704. // Try trigger zrender event to avoid mouse
  30705. // in and out shape too frequently
  30706. var handler = zr.handler;
  30707. eventUtil.normalizeEvent(container, e, true);
  30708. handler.dispatch('mousemove', e);
  30709. }
  30710. };
  30711. el.onmouseleave = function () {
  30712. if (self.enterable) {
  30713. if (self._show) {
  30714. self.hideLater(self._hideDelay);
  30715. }
  30716. }
  30717. self._inContent = false;
  30718. };
  30719. }
  30720. TooltipContent.prototype = {
  30721. constructor: TooltipContent,
  30722. enterable: true,
  30723. /**
  30724. * Update when tooltip is rendered
  30725. */
  30726. update: function () {
  30727. var container = this._container;
  30728. var stl = container.currentStyle
  30729. || document.defaultView.getComputedStyle(container);
  30730. var domStyle = container.style;
  30731. if (domStyle.position !== 'absolute' && stl.position !== 'absolute') {
  30732. domStyle.position = 'relative';
  30733. }
  30734. // Hide the tooltip
  30735. // PENDING
  30736. // this.hide();
  30737. },
  30738. show: function (tooltipModel) {
  30739. clearTimeout(this._hideTimeout);
  30740. var el = this.el;
  30741. el.style.cssText = gCssText + assembleCssText(tooltipModel)
  30742. // http://stackoverflow.com/questions/21125587/css3-transition-not-working-in-chrome-anymore
  30743. + ';left:' + this._x + 'px;top:' + this._y + 'px;'
  30744. + (tooltipModel.get('extraCssText') || '');
  30745. el.style.display = el.innerHTML ? 'block' : 'none';
  30746. this._show = true;
  30747. },
  30748. setContent: function (content) {
  30749. var el = this.el;
  30750. el.innerHTML = content;
  30751. el.style.display = content ? 'block' : 'none';
  30752. },
  30753. moveTo: function (x, y) {
  30754. var style = this.el.style;
  30755. style.left = x + 'px';
  30756. style.top = y + 'px';
  30757. this._x = x;
  30758. this._y = y;
  30759. },
  30760. hide: function () {
  30761. this.el.style.display = 'none';
  30762. this._show = false;
  30763. },
  30764. // showLater: function ()
  30765. hideLater: function (time) {
  30766. if (this._show && !(this._inContent && this.enterable)) {
  30767. if (time) {
  30768. this._hideDelay = time;
  30769. // Set show false to avoid invoke hideLater mutiple times
  30770. this._show = false;
  30771. this._hideTimeout = setTimeout(zrUtil.bind(this.hide, this), time);
  30772. }
  30773. else {
  30774. this.hide();
  30775. }
  30776. }
  30777. },
  30778. isShow: function () {
  30779. return this._show;
  30780. }
  30781. };
  30782. module.exports = TooltipContent;
  30783. /***/ },
  30784. /* 303 */,
  30785. /* 304 */,
  30786. /* 305 */,
  30787. /* 306 */,
  30788. /* 307 */,
  30789. /* 308 */,
  30790. /* 309 */,
  30791. /* 310 */,
  30792. /* 311 */,
  30793. /* 312 */,
  30794. /* 313 */,
  30795. /* 314 */,
  30796. /* 315 */,
  30797. /* 316 */,
  30798. /* 317 */,
  30799. /* 318 */,
  30800. /* 319 */,
  30801. /* 320 */,
  30802. /* 321 */,
  30803. /* 322 */
  30804. /***/ function(module, exports, __webpack_require__) {
  30805. var zrUtil = __webpack_require__(4);
  30806. var graphic = __webpack_require__(43);
  30807. var each = zrUtil.each;
  30808. var helper = {};
  30809. var COMPONENT_NAMES = ['geo', 'xAxis', 'yAxis'];
  30810. var PANEL_ID_SPLIT = '--';
  30811. var COORD_CONVERTS = ['dataToPoint', 'pointToData'];
  30812. helper.parseOutputRanges = function (areas, coordInfoList, ecModel, rangesCoordInfo) {
  30813. each(areas, function (area, index) {
  30814. var panelId = area.panelId;
  30815. if (panelId) {
  30816. panelId = panelId.split(PANEL_ID_SPLIT);
  30817. area[panelId[0] + 'Index'] = +panelId[1];
  30818. var coordInfo = findCoordInfo(area, coordInfoList);
  30819. area.coordRange = coordConvert[area.brushType](
  30820. 1, coordInfo, area.range
  30821. );
  30822. rangesCoordInfo && (rangesCoordInfo[index] = coordInfo);
  30823. }
  30824. });
  30825. };
  30826. helper.parseInputRanges = function (brushModel, ecModel) {
  30827. each(brushModel.areas, function (area) {
  30828. var coordInfo = findCoordInfo(area, brushModel.coordInfoList);
  30829. if (true) {
  30830. zrUtil.assert(
  30831. !coordInfo || coordInfo === true || area.coordRange,
  30832. 'coordRange must be specified when coord index specified.'
  30833. );
  30834. zrUtil.assert(
  30835. !coordInfo || coordInfo !== true || area.range,
  30836. 'range must be specified.'
  30837. );
  30838. }
  30839. area.range = area.range || [];
  30840. // convert coordRange to global range and set panelId.
  30841. if (coordInfo && coordInfo !== true) {
  30842. area.range = coordConvert[area.brushType](
  30843. 0, coordInfo, area.coordRange
  30844. );
  30845. area.panelId = coordInfo.panelId;
  30846. }
  30847. });
  30848. };
  30849. helper.makePanelOpts = function (coordInfoList) {
  30850. var panelOpts = [];
  30851. each(coordInfoList, function (coordInfo) {
  30852. var coordSys = coordInfo.coordSys;
  30853. var rect;
  30854. if (coordInfo.geoIndex >= 0) {
  30855. rect = coordSys.getBoundingRect().clone();
  30856. // geo roam and zoom transform
  30857. rect.applyTransform(graphic.getTransform(coordSys));
  30858. }
  30859. else { // xAxis or yAxis
  30860. // grid is not Transformable.
  30861. rect = coordSys.grid.getRect().clone();
  30862. }
  30863. panelOpts.push({panelId: coordInfo.panelId, rect: rect});
  30864. });
  30865. return panelOpts;
  30866. };
  30867. /**
  30868. * @param {Object} option {xAxisIndex, yAxisIndex, geoIndex}
  30869. * @param {module:echarts/model/Global} ecModel
  30870. * @return {Array.<Obejct>} coordInfoList
  30871. */
  30872. helper.makeCoordInfoList = function (option, ecModel) {
  30873. var coordInfoList = [];
  30874. each(COMPONENT_NAMES, function (componentName) {
  30875. var componentIndices = option[componentName + 'Index'];
  30876. if (componentIndices == null || componentIndices === 'none') {
  30877. return;
  30878. }
  30879. if (componentIndices !== 'all' && !zrUtil.isArray(componentIndices)) {
  30880. componentIndices = [componentIndices];
  30881. }
  30882. ecModel.eachComponent({mainType: componentName}, function (componentModel, index) {
  30883. if (componentIndices !== 'all' && zrUtil.indexOf(componentIndices, index) < 0) {
  30884. return;
  30885. }
  30886. var grid;
  30887. var coordSys;
  30888. (componentName === 'xAxis' || componentName === 'yAxis')
  30889. ? (grid = componentModel.axis.grid)
  30890. : (coordSys = componentModel.coordinateSystem); // geo
  30891. var coordInfo;
  30892. // Check duplicate and find cartesian when tranval to yAxis.
  30893. for (var i = 0, len = coordInfoList.length; i < len; i++) {
  30894. var cInfo = coordInfoList[i];
  30895. if (true) {
  30896. zrUtil.assert(
  30897. cInfo[componentName + 'Index'] != index,
  30898. 'Coord should not be defined duplicately: ' + componentName + index
  30899. );
  30900. }
  30901. // CoordSys is always required for `rect brush` or `polygon brush`.
  30902. // If both xAxisIndex and yAxisIndex specified, fetch cartesian by them.
  30903. if (componentName === 'yAxis' && !cInfo.yAxis && cInfo.xAxis) {
  30904. var aCoordSys = grid.getCartesian(cInfo.xAxisIndex, index);
  30905. if (aCoordSys) { // The yAxis and xAxis are in the same cartesian.
  30906. coordSys = aCoordSys;
  30907. coordInfo = cInfo;
  30908. break;
  30909. }
  30910. }
  30911. }
  30912. !coordInfo && coordInfoList.push(coordInfo = {});
  30913. coordInfo[componentName] = componentModel;
  30914. coordInfo[componentName + 'Index'] = index;
  30915. // If both xAxisIndex and yAxisIndex specified, panelId only use yAxisIndex,
  30916. // which is enough to index panel.
  30917. coordInfo.panelId = componentName + PANEL_ID_SPLIT + index;
  30918. coordInfo.coordSys = coordSys
  30919. // If only xAxisIndex or only yAxisIndex specified, find its first cartesian.
  30920. || grid.getCartesian(coordInfo.xAxisIndex, coordInfo.yAxisIndex);
  30921. coordInfo.coordSys
  30922. ? (coordInfoList[componentName + 'Has'] = true)
  30923. : coordInfoList.pop(); // If a coordInfo exists originally, existance of coordSys is ensured.
  30924. });
  30925. });
  30926. return coordInfoList;
  30927. };
  30928. helper.controlSeries = function (area, brushModel, seriesModel) {
  30929. // Check whether area is bound in coord, and series do not belong to that coord.
  30930. // If do not do this check, some brush (like lineX) will controll all axes.
  30931. var coordInfo = findCoordInfo(area, brushModel.coordInfoList);
  30932. return coordInfo === true || (coordInfo && coordInfo.coordSys === seriesModel.coordinateSystem);
  30933. };
  30934. function formatMinMax(minMax) {
  30935. minMax[0] > minMax[1] && minMax.reverse();
  30936. return minMax;
  30937. }
  30938. /**
  30939. * If return Object, a coord found.
  30940. * If reutrn true, global found.
  30941. * Otherwise nothing found.
  30942. *
  30943. * @param {Object} area {<componentName>Index}
  30944. * @param {Array} coordInfoList
  30945. * @return {Obejct|boolean}
  30946. */
  30947. function findCoordInfo(area, coordInfoList) {
  30948. var isGlobal = true;
  30949. for (var j = 0; j < COMPONENT_NAMES.length; j++) {
  30950. var indexAttr = COMPONENT_NAMES[j] + 'Index';
  30951. if (area[indexAttr] >= 0) {
  30952. isGlobal = false;
  30953. for (var i = 0; i < coordInfoList.length; i++) {
  30954. if (coordInfoList[i][indexAttr] === area[indexAttr]) {
  30955. return coordInfoList[i];
  30956. }
  30957. }
  30958. }
  30959. }
  30960. return isGlobal;
  30961. }
  30962. function axisConvert(axisName, to, coordInfo, coordRange) {
  30963. var axis = coordInfo.coordSys.getAxis(axisName);
  30964. if (true) {
  30965. zrUtil.assert(axis, 'line brush is only available in cartesian (grid).');
  30966. }
  30967. return formatMinMax(zrUtil.map([0, 1], function (i) {
  30968. return to
  30969. ? axis.coordToData(axis.toLocalCoord(coordRange[i]))
  30970. : axis.toGlobalCoord(axis.dataToCoord(coordRange[i]));
  30971. }));
  30972. }
  30973. var coordConvert = {
  30974. lineX: zrUtil.curry(axisConvert, 'x'),
  30975. lineY: zrUtil.curry(axisConvert, 'y'),
  30976. rect: function (to, coordInfo, coordRange) {
  30977. var coordSys = coordInfo.coordSys;
  30978. var xminymin = coordSys[COORD_CONVERTS[to]]([coordRange[0][0], coordRange[1][0]]);
  30979. var xmaxymax = coordSys[COORD_CONVERTS[to]]([coordRange[0][1], coordRange[1][1]]);
  30980. return [
  30981. formatMinMax([xminymin[0], xmaxymax[0]]),
  30982. formatMinMax([xminymin[1], xmaxymax[1]])
  30983. ];
  30984. },
  30985. polygon: function (to, coordInfo, coordRange) {
  30986. var coordSys = coordInfo.coordSys;
  30987. return zrUtil.map(coordRange, coordSys[COORD_CONVERTS[to]], coordSys);
  30988. }
  30989. };
  30990. module.exports = helper;
  30991. /***/ },
  30992. /* 323 */,
  30993. /* 324 */,
  30994. /* 325 */,
  30995. /* 326 */,
  30996. /* 327 */
  30997. /***/ function(module, exports) {
  30998. 'use strict';
  30999. var features = {};
  31000. module.exports = {
  31001. register: function (name, ctor) {
  31002. features[name] = ctor;
  31003. },
  31004. get: function (name) {
  31005. return features[name];
  31006. }
  31007. };
  31008. /***/ },
  31009. /* 328 */
  31010. /***/ function(module, exports, __webpack_require__) {
  31011. 'use strict';
  31012. var echarts = __webpack_require__(1);
  31013. var graphic = __webpack_require__(43);
  31014. var layout = __webpack_require__(21);
  31015. // Model
  31016. echarts.extendComponentModel({
  31017. type: 'title',
  31018. layoutMode: {type: 'box', ignoreSize: true},
  31019. defaultOption: {
  31020. // 一级层叠
  31021. zlevel: 0,
  31022. // 二级层叠
  31023. z: 6,
  31024. show: true,
  31025. text: '',
  31026. // 超链接跳转
  31027. // link: null,
  31028. // 仅支持self | blank
  31029. target: 'blank',
  31030. subtext: '',
  31031. // 超链接跳转
  31032. // sublink: null,
  31033. // 仅支持self | blank
  31034. subtarget: 'blank',
  31035. // 'center' ¦ 'left' ¦ 'right'
  31036. // ¦ {number}(x坐标,单位px)
  31037. left: 0,
  31038. // 'top' ¦ 'bottom' ¦ 'center'
  31039. // ¦ {number}(y坐标,单位px)
  31040. top: 0,
  31041. // 水平对齐
  31042. // 'auto' | 'left' | 'right' | 'center'
  31043. // 默认根据 left 的位置判断是左对齐还是右对齐
  31044. // textAlign: null
  31045. //
  31046. // 垂直对齐
  31047. // 'auto' | 'top' | 'bottom' | 'middle'
  31048. // 默认根据 top 位置判断是上对齐还是下对齐
  31049. // textBaseline: null
  31050. backgroundColor: 'rgba(0,0,0,0)',
  31051. // 标题边框颜色
  31052. borderColor: '#ccc',
  31053. // 标题边框线宽,单位px,默认为0(无边框)
  31054. borderWidth: 0,
  31055. // 标题内边距,单位px,默认各方向内边距为5,
  31056. // 接受数组分别设定上右下左边距,同css
  31057. padding: 5,
  31058. // 主副标题纵向间隔,单位px,默认为10,
  31059. itemGap: 10,
  31060. textStyle: {
  31061. fontSize: 18,
  31062. fontWeight: 'bolder',
  31063. color: '#333'
  31064. },
  31065. subtextStyle: {
  31066. color: '#aaa'
  31067. }
  31068. }
  31069. });
  31070. // View
  31071. echarts.extendComponentView({
  31072. type: 'title',
  31073. render: function (titleModel, ecModel, api) {
  31074. this.group.removeAll();
  31075. if (!titleModel.get('show')) {
  31076. return;
  31077. }
  31078. var group = this.group;
  31079. var textStyleModel = titleModel.getModel('textStyle');
  31080. var subtextStyleModel = titleModel.getModel('subtextStyle');
  31081. var textAlign = titleModel.get('textAlign');
  31082. var textBaseline = titleModel.get('textBaseline');
  31083. var textEl = new graphic.Text({
  31084. style: {
  31085. text: titleModel.get('text'),
  31086. textFont: textStyleModel.getFont(),
  31087. fill: textStyleModel.getTextColor()
  31088. },
  31089. z2: 10
  31090. });
  31091. var textRect = textEl.getBoundingRect();
  31092. var subText = titleModel.get('subtext');
  31093. var subTextEl = new graphic.Text({
  31094. style: {
  31095. text: subText,
  31096. textFont: subtextStyleModel.getFont(),
  31097. fill: subtextStyleModel.getTextColor(),
  31098. y: textRect.height + titleModel.get('itemGap'),
  31099. textBaseline: 'top'
  31100. },
  31101. z2: 10
  31102. });
  31103. var link = titleModel.get('link');
  31104. var sublink = titleModel.get('sublink');
  31105. textEl.silent = !link;
  31106. subTextEl.silent = !sublink;
  31107. if (link) {
  31108. textEl.on('click', function () {
  31109. window.open(link, '_' + titleModel.get('target'));
  31110. });
  31111. }
  31112. if (sublink) {
  31113. subTextEl.on('click', function () {
  31114. window.open(sublink, '_' + titleModel.get('subtarget'));
  31115. });
  31116. }
  31117. group.add(textEl);
  31118. subText && group.add(subTextEl);
  31119. // If no subText, but add subTextEl, there will be an empty line.
  31120. var groupRect = group.getBoundingRect();
  31121. var layoutOption = titleModel.getBoxLayoutParams();
  31122. layoutOption.width = groupRect.width;
  31123. layoutOption.height = groupRect.height;
  31124. var layoutRect = layout.getLayoutRect(
  31125. layoutOption, {
  31126. width: api.getWidth(),
  31127. height: api.getHeight()
  31128. }, titleModel.get('padding')
  31129. );
  31130. // Adjust text align based on position
  31131. if (!textAlign) {
  31132. // Align left if title is on the left. center and right is same
  31133. textAlign = titleModel.get('left') || titleModel.get('right');
  31134. if (textAlign === 'middle') {
  31135. textAlign = 'center';
  31136. }
  31137. // Adjust layout by text align
  31138. if (textAlign === 'right') {
  31139. layoutRect.x += layoutRect.width;
  31140. }
  31141. else if (textAlign === 'center') {
  31142. layoutRect.x += layoutRect.width / 2;
  31143. }
  31144. }
  31145. if (!textBaseline) {
  31146. textBaseline = titleModel.get('top') || titleModel.get('bottom');
  31147. if (textBaseline === 'center') {
  31148. textBaseline = 'middle';
  31149. }
  31150. if (textBaseline === 'bottom') {
  31151. layoutRect.y += layoutRect.height;
  31152. }
  31153. else if (textBaseline === 'middle') {
  31154. layoutRect.y += layoutRect.height / 2;
  31155. }
  31156. textBaseline = textBaseline || 'top';
  31157. }
  31158. group.attr('position', [layoutRect.x, layoutRect.y]);
  31159. var alignStyle = {
  31160. textAlign: textAlign,
  31161. textVerticalAlign: textBaseline
  31162. };
  31163. textEl.setStyle(alignStyle);
  31164. subTextEl.setStyle(alignStyle);
  31165. // Render background
  31166. // Get groupRect again because textAlign has been changed
  31167. groupRect = group.getBoundingRect();
  31168. var padding = layoutRect.margin;
  31169. var style = titleModel.getItemStyle(['color', 'opacity']);
  31170. style.fill = titleModel.get('backgroundColor');
  31171. var rect = new graphic.Rect({
  31172. shape: {
  31173. x: groupRect.x - padding[3],
  31174. y: groupRect.y - padding[0],
  31175. width: groupRect.width + padding[1] + padding[3],
  31176. height: groupRect.height + padding[0] + padding[2]
  31177. },
  31178. style: style,
  31179. silent: true
  31180. });
  31181. graphic.subPixelOptimizeRect(rect);
  31182. group.add(rect);
  31183. }
  31184. });
  31185. /***/ },
  31186. /* 329 */
  31187. /***/ function(module, exports, __webpack_require__) {
  31188. /**
  31189. * DataZoom component entry
  31190. */
  31191. __webpack_require__(330);
  31192. __webpack_require__(331);
  31193. __webpack_require__(334);
  31194. __webpack_require__(335);
  31195. __webpack_require__(336);
  31196. __webpack_require__(338);
  31197. __webpack_require__(339);
  31198. __webpack_require__(341);
  31199. __webpack_require__(342);
  31200. /***/ },
  31201. /* 330 */
  31202. /***/ function(module, exports, __webpack_require__) {
  31203. __webpack_require__(19).registerSubTypeDefaulter('dataZoom', function (option) {
  31204. // Default 'slider' when no type specified.
  31205. return 'slider';
  31206. });
  31207. /***/ },
  31208. /* 331 */
  31209. /***/ function(module, exports, __webpack_require__) {
  31210. /**
  31211. * @file Data zoom model
  31212. */
  31213. var zrUtil = __webpack_require__(4);
  31214. var env = __webpack_require__(2);
  31215. var echarts = __webpack_require__(1);
  31216. var modelUtil = __webpack_require__(5);
  31217. var helper = __webpack_require__(332);
  31218. var AxisProxy = __webpack_require__(333);
  31219. var each = zrUtil.each;
  31220. var eachAxisDim = helper.eachAxisDim;
  31221. var DataZoomModel = echarts.extendComponentModel({
  31222. type: 'dataZoom',
  31223. dependencies: [
  31224. 'xAxis', 'yAxis', 'zAxis', 'radiusAxis', 'angleAxis', 'singleAxis', 'series'
  31225. ],
  31226. /**
  31227. * @protected
  31228. */
  31229. defaultOption: {
  31230. zlevel: 0,
  31231. z: 4, // Higher than normal component (z: 2).
  31232. orient: null, // Default auto by axisIndex. Possible value: 'horizontal', 'vertical'.
  31233. xAxisIndex: null, // Default the first horizontal category axis.
  31234. yAxisIndex: null, // Default the first vertical category axis.
  31235. filterMode: 'filter', // Possible values: 'filter' or 'empty'.
  31236. // 'filter': data items which are out of window will be removed.
  31237. // This option is applicable when filtering outliers.
  31238. // 'empty': data items which are out of window will be set to empty.
  31239. // This option is applicable when user should not neglect
  31240. // that there are some data items out of window.
  31241. // Taking line chart as an example, line will be broken in
  31242. // the filtered points when filterModel is set to 'empty', but
  31243. // be connected when set to 'filter'.
  31244. throttle: null, // Dispatch action by the fixed rate, avoid frequency.
  31245. // default 100. Do not throttle when use null/undefined.
  31246. // If animation === true and animationDurationUpdate > 0,
  31247. // default value is 100, otherwise 20.
  31248. start: 0, // Start percent. 0 ~ 100
  31249. end: 100, // End percent. 0 ~ 100
  31250. startValue: null, // Start value. If startValue specified, start is ignored.
  31251. endValue: null // End value. If endValue specified, end is ignored.
  31252. },
  31253. /**
  31254. * @override
  31255. */
  31256. init: function (option, parentModel, ecModel) {
  31257. /**
  31258. * key like x_0, y_1
  31259. * @private
  31260. * @type {Object}
  31261. */
  31262. this._dataIntervalByAxis = {};
  31263. /**
  31264. * @private
  31265. */
  31266. this._dataInfo = {};
  31267. /**
  31268. * key like x_0, y_1
  31269. * @private
  31270. */
  31271. this._axisProxies = {};
  31272. /**
  31273. * @readOnly
  31274. */
  31275. this.textStyleModel;
  31276. /**
  31277. * @private
  31278. */
  31279. this._autoThrottle = true;
  31280. var rawOption = retrieveRaw(option);
  31281. this.mergeDefaultAndTheme(option, ecModel);
  31282. this.doInit(rawOption);
  31283. },
  31284. /**
  31285. * @override
  31286. */
  31287. mergeOption: function (newOption) {
  31288. var rawOption = retrieveRaw(newOption);
  31289. //FIX #2591
  31290. zrUtil.merge(this.option, newOption, true);
  31291. this.doInit(rawOption);
  31292. },
  31293. /**
  31294. * @protected
  31295. */
  31296. doInit: function (rawOption) {
  31297. var thisOption = this.option;
  31298. // Disable realtime view update if canvas is not supported.
  31299. if (!env.canvasSupported) {
  31300. thisOption.realtime = false;
  31301. }
  31302. this._setDefaultThrottle(rawOption);
  31303. processRangeProp('start', 'startValue', rawOption, thisOption);
  31304. processRangeProp('end', 'endValue', rawOption, thisOption);
  31305. this.textStyleModel = this.getModel('textStyle');
  31306. this._resetTarget();
  31307. this._giveAxisProxies();
  31308. },
  31309. /**
  31310. * @private
  31311. */
  31312. _giveAxisProxies: function () {
  31313. var axisProxies = this._axisProxies;
  31314. this.eachTargetAxis(function (dimNames, axisIndex, dataZoomModel, ecModel) {
  31315. var axisModel = this.dependentModels[dimNames.axis][axisIndex];
  31316. // If exists, share axisProxy with other dataZoomModels.
  31317. var axisProxy = axisModel.__dzAxisProxy || (
  31318. // Use the first dataZoomModel as the main model of axisProxy.
  31319. axisModel.__dzAxisProxy = new AxisProxy(
  31320. dimNames.name, axisIndex, this, ecModel
  31321. )
  31322. );
  31323. // FIXME
  31324. // dispose __dzAxisProxy
  31325. axisProxies[dimNames.name + '_' + axisIndex] = axisProxy;
  31326. }, this);
  31327. },
  31328. /**
  31329. * @private
  31330. */
  31331. _resetTarget: function () {
  31332. var thisOption = this.option;
  31333. var autoMode = this._judgeAutoMode();
  31334. eachAxisDim(function (dimNames) {
  31335. var axisIndexName = dimNames.axisIndex;
  31336. thisOption[axisIndexName] = modelUtil.normalizeToArray(
  31337. thisOption[axisIndexName]
  31338. );
  31339. }, this);
  31340. if (autoMode === 'axisIndex') {
  31341. this._autoSetAxisIndex();
  31342. }
  31343. else if (autoMode === 'orient') {
  31344. this._autoSetOrient();
  31345. }
  31346. },
  31347. /**
  31348. * @private
  31349. */
  31350. _judgeAutoMode: function () {
  31351. // Auto set only works for setOption at the first time.
  31352. // The following is user's reponsibility. So using merged
  31353. // option is OK.
  31354. var thisOption = this.option;
  31355. var hasIndexSpecified = false;
  31356. eachAxisDim(function (dimNames) {
  31357. // When user set axisIndex as a empty array, we think that user specify axisIndex
  31358. // but do not want use auto mode. Because empty array may be encountered when
  31359. // some error occured.
  31360. if (thisOption[dimNames.axisIndex] != null) {
  31361. hasIndexSpecified = true;
  31362. }
  31363. }, this);
  31364. var orient = thisOption.orient;
  31365. if (orient == null && hasIndexSpecified) {
  31366. return 'orient';
  31367. }
  31368. else if (!hasIndexSpecified) {
  31369. if (orient == null) {
  31370. thisOption.orient = 'horizontal';
  31371. }
  31372. return 'axisIndex';
  31373. }
  31374. },
  31375. /**
  31376. * @private
  31377. */
  31378. _autoSetAxisIndex: function () {
  31379. var autoAxisIndex = true;
  31380. var orient = this.get('orient', true);
  31381. var thisOption = this.option;
  31382. var dependentModels = this.dependentModels;
  31383. if (autoAxisIndex) {
  31384. // Find axis that parallel to dataZoom as default.
  31385. var dimName = orient === 'vertical' ? 'y' : 'x';
  31386. if (dependentModels[dimName + 'Axis'].length) {
  31387. thisOption[dimName + 'AxisIndex'] = [0];
  31388. autoAxisIndex = false;
  31389. }
  31390. else {
  31391. each(dependentModels.singleAxis, function (singleAxisModel) {
  31392. if (autoAxisIndex && singleAxisModel.get('orient', true) === orient) {
  31393. thisOption.singleAxisIndex = [singleAxisModel.componentIndex];
  31394. autoAxisIndex = false;
  31395. }
  31396. });
  31397. }
  31398. }
  31399. if (autoAxisIndex) {
  31400. // Find the first category axis as default. (consider polar)
  31401. eachAxisDim(function (dimNames) {
  31402. if (!autoAxisIndex) {
  31403. return;
  31404. }
  31405. var axisIndices = [];
  31406. var axisModels = this.dependentModels[dimNames.axis];
  31407. if (axisModels.length && !axisIndices.length) {
  31408. for (var i = 0, len = axisModels.length; i < len; i++) {
  31409. if (axisModels[i].get('type') === 'category') {
  31410. axisIndices.push(i);
  31411. }
  31412. }
  31413. }
  31414. thisOption[dimNames.axisIndex] = axisIndices;
  31415. if (axisIndices.length) {
  31416. autoAxisIndex = false;
  31417. }
  31418. }, this);
  31419. }
  31420. if (autoAxisIndex) {
  31421. // FIXME
  31422. // 这里是兼容ec2的写法(没指定xAxisIndex和yAxisIndex时把scatter和双数值轴折柱纳入dataZoom控制),
  31423. // 但是实际是否需要Grid.js#getScaleByOption来判断(考虑time,log等axis type)?
  31424. // If both dataZoom.xAxisIndex and dataZoom.yAxisIndex is not specified,
  31425. // dataZoom component auto adopts series that reference to
  31426. // both xAxis and yAxis which type is 'value'.
  31427. this.ecModel.eachSeries(function (seriesModel) {
  31428. if (this._isSeriesHasAllAxesTypeOf(seriesModel, 'value')) {
  31429. eachAxisDim(function (dimNames) {
  31430. var axisIndices = thisOption[dimNames.axisIndex];
  31431. var axisIndex = seriesModel.get(dimNames.axisIndex);
  31432. var axisId = seriesModel.get(dimNames.axisId);
  31433. var axisModel = seriesModel.ecModel.queryComponents({
  31434. mainType: dimNames.axis,
  31435. index: axisIndex,
  31436. id: axisId
  31437. })[0];
  31438. if (true) {
  31439. if (!axisModel) {
  31440. throw new Error(
  31441. dimNames.axis + ' "' + zrUtil.retrieve(
  31442. axisIndex,
  31443. axisId,
  31444. 0
  31445. ) + '" not found'
  31446. );
  31447. }
  31448. }
  31449. axisIndex = axisModel.componentIndex;
  31450. if (zrUtil.indexOf(axisIndices, axisIndex) < 0) {
  31451. axisIndices.push(axisIndex);
  31452. }
  31453. });
  31454. }
  31455. }, this);
  31456. }
  31457. },
  31458. /**
  31459. * @private
  31460. */
  31461. _autoSetOrient: function () {
  31462. var dim;
  31463. // Find the first axis
  31464. this.eachTargetAxis(function (dimNames) {
  31465. !dim && (dim = dimNames.name);
  31466. }, this);
  31467. this.option.orient = dim === 'y' ? 'vertical' : 'horizontal';
  31468. },
  31469. /**
  31470. * @private
  31471. */
  31472. _isSeriesHasAllAxesTypeOf: function (seriesModel, axisType) {
  31473. // FIXME
  31474. // 需要series的xAxisIndex和yAxisIndex都首先自动设置上。
  31475. // 例如series.type === scatter时。
  31476. var is = true;
  31477. eachAxisDim(function (dimNames) {
  31478. var seriesAxisIndex = seriesModel.get(dimNames.axisIndex);
  31479. var axisModel = this.dependentModels[dimNames.axis][seriesAxisIndex];
  31480. if (!axisModel || axisModel.get('type') !== axisType) {
  31481. is = false;
  31482. }
  31483. }, this);
  31484. return is;
  31485. },
  31486. /**
  31487. * @private
  31488. */
  31489. _setDefaultThrottle: function (rawOption) {
  31490. // When first time user set throttle, auto throttle ends.
  31491. if (rawOption.hasOwnProperty('throttle')) {
  31492. this._autoThrottle = false;
  31493. }
  31494. if (this._autoThrottle) {
  31495. var globalOption = this.ecModel.option;
  31496. this.option.throttle =
  31497. (globalOption.animation && globalOption.animationDurationUpdate > 0)
  31498. ? 100 : 20;
  31499. }
  31500. },
  31501. /**
  31502. * @public
  31503. */
  31504. getFirstTargetAxisModel: function () {
  31505. var firstAxisModel;
  31506. eachAxisDim(function (dimNames) {
  31507. if (firstAxisModel == null) {
  31508. var indices = this.get(dimNames.axisIndex);
  31509. if (indices.length) {
  31510. firstAxisModel = this.dependentModels[dimNames.axis][indices[0]];
  31511. }
  31512. }
  31513. }, this);
  31514. return firstAxisModel;
  31515. },
  31516. /**
  31517. * @public
  31518. * @param {Function} callback param: axisModel, dimNames, axisIndex, dataZoomModel, ecModel
  31519. */
  31520. eachTargetAxis: function (callback, context) {
  31521. var ecModel = this.ecModel;
  31522. eachAxisDim(function (dimNames) {
  31523. each(
  31524. this.get(dimNames.axisIndex),
  31525. function (axisIndex) {
  31526. callback.call(context, dimNames, axisIndex, this, ecModel);
  31527. },
  31528. this
  31529. );
  31530. }, this);
  31531. },
  31532. getAxisProxy: function (dimName, axisIndex) {
  31533. return this._axisProxies[dimName + '_' + axisIndex];
  31534. },
  31535. /**
  31536. * If not specified, set to undefined.
  31537. *
  31538. * @public
  31539. * @param {Object} opt
  31540. * @param {number} [opt.start]
  31541. * @param {number} [opt.end]
  31542. * @param {number} [opt.startValue]
  31543. * @param {number} [opt.endValue]
  31544. */
  31545. setRawRange: function (opt) {
  31546. each(['start', 'end', 'startValue', 'endValue'], function (name) {
  31547. // If any of those prop is null/undefined, we should alos set
  31548. // them, because only one pair between start/end and
  31549. // startValue/endValue can work.
  31550. this.option[name] = opt[name];
  31551. }, this);
  31552. },
  31553. /**
  31554. * @public
  31555. * @return {Array.<number>} [startPercent, endPercent]
  31556. */
  31557. getPercentRange: function () {
  31558. var axisProxy = this.findRepresentativeAxisProxy();
  31559. if (axisProxy) {
  31560. return axisProxy.getDataPercentWindow();
  31561. }
  31562. },
  31563. /**
  31564. * @public
  31565. * For example, chart.getModel().getComponent('dataZoom').getValueRange('y', 0);
  31566. *
  31567. * @param {string} [axisDimName]
  31568. * @param {number} [axisIndex]
  31569. * @return {Array.<number>} [startValue, endValue] value can only be '-' or finite number.
  31570. */
  31571. getValueRange: function (axisDimName, axisIndex) {
  31572. if (axisDimName == null && axisIndex == null) {
  31573. var axisProxy = this.findRepresentativeAxisProxy();
  31574. if (axisProxy) {
  31575. return axisProxy.getDataValueWindow();
  31576. }
  31577. }
  31578. else {
  31579. return this.getAxisProxy(axisDimName, axisIndex).getDataValueWindow();
  31580. }
  31581. },
  31582. /**
  31583. * @public
  31584. * @return {module:echarts/component/dataZoom/AxisProxy}
  31585. */
  31586. findRepresentativeAxisProxy: function () {
  31587. // Find the first hosted axisProxy
  31588. var axisProxies = this._axisProxies;
  31589. for (var key in axisProxies) {
  31590. if (axisProxies.hasOwnProperty(key) && axisProxies[key].hostedBy(this)) {
  31591. return axisProxies[key];
  31592. }
  31593. }
  31594. // If no hosted axis find not hosted axisProxy.
  31595. // Consider this case: dataZoomModel1 and dataZoomModel2 control the same axis,
  31596. // and the option.start or option.end settings are different. The percentRange
  31597. // should follow axisProxy.
  31598. // (We encounter this problem in toolbox data zoom.)
  31599. for (var key in axisProxies) {
  31600. if (axisProxies.hasOwnProperty(key) && !axisProxies[key].hostedBy(this)) {
  31601. return axisProxies[key];
  31602. }
  31603. }
  31604. }
  31605. });
  31606. function retrieveRaw(option) {
  31607. var ret = {};
  31608. each(
  31609. ['start', 'end', 'startValue', 'endValue', 'throttle'],
  31610. function (name) {
  31611. option.hasOwnProperty(name) && (ret[name] = option[name]);
  31612. }
  31613. );
  31614. return ret;
  31615. }
  31616. function processRangeProp(percentProp, valueProp, rawOption, thisOption) {
  31617. // start/end has higher priority over startValue/endValue,
  31618. // but we should make chart.setOption({endValue: 1000}) effective,
  31619. // rather than chart.setOption({endValue: 1000, end: null}).
  31620. if (rawOption[valueProp] != null && rawOption[percentProp] == null) {
  31621. thisOption[percentProp] = null;
  31622. }
  31623. // Otherwise do nothing and use the merge result.
  31624. }
  31625. module.exports = DataZoomModel;
  31626. /***/ },
  31627. /* 332 */
  31628. /***/ function(module, exports, __webpack_require__) {
  31629. var formatUtil = __webpack_require__(6);
  31630. var zrUtil = __webpack_require__(4);
  31631. var helper = {};
  31632. var AXIS_DIMS = ['x', 'y', 'z', 'radius', 'angle', 'single'];
  31633. // Supported coords.
  31634. var COORDS = ['cartesian2d', 'polar', 'singleAxis'];
  31635. /**
  31636. * @param {string} coordType
  31637. * @return {boolean}
  31638. */
  31639. helper.isCoordSupported = function (coordType) {
  31640. return zrUtil.indexOf(COORDS, coordType) >= 0;
  31641. };
  31642. /**
  31643. * Create "each" method to iterate names.
  31644. *
  31645. * @pubilc
  31646. * @param {Array.<string>} names
  31647. * @param {Array.<string>=} attrs
  31648. * @return {Function}
  31649. */
  31650. helper.createNameEach = function (names, attrs) {
  31651. names = names.slice();
  31652. var capitalNames = zrUtil.map(names, formatUtil.capitalFirst);
  31653. attrs = (attrs || []).slice();
  31654. var capitalAttrs = zrUtil.map(attrs, formatUtil.capitalFirst);
  31655. return function (callback, context) {
  31656. zrUtil.each(names, function (name, index) {
  31657. var nameObj = {name: name, capital: capitalNames[index]};
  31658. for (var j = 0; j < attrs.length; j++) {
  31659. nameObj[attrs[j]] = name + capitalAttrs[j];
  31660. }
  31661. callback.call(context, nameObj);
  31662. });
  31663. };
  31664. };
  31665. /**
  31666. * Iterate each dimension name.
  31667. *
  31668. * @public
  31669. * @param {Function} callback The parameter is like:
  31670. * {
  31671. * name: 'angle',
  31672. * capital: 'Angle',
  31673. * axis: 'angleAxis',
  31674. * axisIndex: 'angleAixs',
  31675. * index: 'angleIndex'
  31676. * }
  31677. * @param {Object} context
  31678. */
  31679. helper.eachAxisDim = helper.createNameEach(AXIS_DIMS, ['axisIndex', 'axis', 'index', 'id']);
  31680. /**
  31681. * If tow dataZoomModels has the same axis controlled, we say that they are 'linked'.
  31682. * dataZoomModels and 'links' make up one or more graphics.
  31683. * This function finds the graphic where the source dataZoomModel is in.
  31684. *
  31685. * @public
  31686. * @param {Function} forEachNode Node iterator.
  31687. * @param {Function} forEachEdgeType edgeType iterator
  31688. * @param {Function} edgeIdGetter Giving node and edgeType, return an array of edge id.
  31689. * @return {Function} Input: sourceNode, Output: Like {nodes: [], dims: {}}
  31690. */
  31691. helper.createLinkedNodesFinder = function (forEachNode, forEachEdgeType, edgeIdGetter) {
  31692. return function (sourceNode) {
  31693. var result = {
  31694. nodes: [],
  31695. records: {} // key: edgeType.name, value: Object (key: edge id, value: boolean).
  31696. };
  31697. forEachEdgeType(function (edgeType) {
  31698. result.records[edgeType.name] = {};
  31699. });
  31700. if (!sourceNode) {
  31701. return result;
  31702. }
  31703. absorb(sourceNode, result);
  31704. var existsLink;
  31705. do {
  31706. existsLink = false;
  31707. forEachNode(processSingleNode);
  31708. }
  31709. while (existsLink);
  31710. function processSingleNode(node) {
  31711. if (!isNodeAbsorded(node, result) && isLinked(node, result)) {
  31712. absorb(node, result);
  31713. existsLink = true;
  31714. }
  31715. }
  31716. return result;
  31717. };
  31718. function isNodeAbsorded(node, result) {
  31719. return zrUtil.indexOf(result.nodes, node) >= 0;
  31720. }
  31721. function isLinked(node, result) {
  31722. var hasLink = false;
  31723. forEachEdgeType(function (edgeType) {
  31724. zrUtil.each(edgeIdGetter(node, edgeType) || [], function (edgeId) {
  31725. result.records[edgeType.name][edgeId] && (hasLink = true);
  31726. });
  31727. });
  31728. return hasLink;
  31729. }
  31730. function absorb(node, result) {
  31731. result.nodes.push(node);
  31732. forEachEdgeType(function (edgeType) {
  31733. zrUtil.each(edgeIdGetter(node, edgeType) || [], function (edgeId) {
  31734. result.records[edgeType.name][edgeId] = true;
  31735. });
  31736. });
  31737. }
  31738. };
  31739. module.exports = helper;
  31740. /***/ },
  31741. /* 333 */
  31742. /***/ function(module, exports, __webpack_require__) {
  31743. /**
  31744. * @file Axis operator
  31745. */
  31746. var zrUtil = __webpack_require__(4);
  31747. var numberUtil = __webpack_require__(7);
  31748. var helper = __webpack_require__(332);
  31749. var each = zrUtil.each;
  31750. var asc = numberUtil.asc;
  31751. /**
  31752. * Operate single axis.
  31753. * One axis can only operated by one axis operator.
  31754. * Different dataZoomModels may be defined to operate the same axis.
  31755. * (i.e. 'inside' data zoom and 'slider' data zoom components)
  31756. * So dataZoomModels share one axisProxy in that case.
  31757. *
  31758. * @class
  31759. */
  31760. var AxisProxy = function (dimName, axisIndex, dataZoomModel, ecModel) {
  31761. /**
  31762. * @private
  31763. * @type {string}
  31764. */
  31765. this._dimName = dimName;
  31766. /**
  31767. * @private
  31768. */
  31769. this._axisIndex = axisIndex;
  31770. /**
  31771. * @private
  31772. * @type {Array.<number>}
  31773. */
  31774. this._valueWindow;
  31775. /**
  31776. * @private
  31777. * @type {Array.<number>}
  31778. */
  31779. this._percentWindow;
  31780. /**
  31781. * @private
  31782. * @type {Array.<number>}
  31783. */
  31784. this._dataExtent;
  31785. /**
  31786. * @readOnly
  31787. * @type {module: echarts/model/Global}
  31788. */
  31789. this.ecModel = ecModel;
  31790. /**
  31791. * @private
  31792. * @type {module: echarts/component/dataZoom/DataZoomModel}
  31793. */
  31794. this._dataZoomModel = dataZoomModel;
  31795. };
  31796. AxisProxy.prototype = {
  31797. constructor: AxisProxy,
  31798. /**
  31799. * Whether the axisProxy is hosted by dataZoomModel.
  31800. *
  31801. * @public
  31802. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  31803. * @return {boolean}
  31804. */
  31805. hostedBy: function (dataZoomModel) {
  31806. return this._dataZoomModel === dataZoomModel;
  31807. },
  31808. /**
  31809. * @return {Array.<number>} Value can only be NaN or finite value.
  31810. */
  31811. getDataValueWindow: function () {
  31812. return this._valueWindow.slice();
  31813. },
  31814. /**
  31815. * @return {Array.<number>}
  31816. */
  31817. getDataPercentWindow: function () {
  31818. return this._percentWindow.slice();
  31819. },
  31820. /**
  31821. * @public
  31822. * @param {number} axisIndex
  31823. * @return {Array} seriesModels
  31824. */
  31825. getTargetSeriesModels: function () {
  31826. var seriesModels = [];
  31827. var ecModel = this.ecModel;
  31828. ecModel.eachSeries(function (seriesModel) {
  31829. if (helper.isCoordSupported(seriesModel.get('coordinateSystem'))) {
  31830. var dimName = this._dimName;
  31831. var axisModel = ecModel.queryComponents({
  31832. mainType: dimName + 'Axis',
  31833. index: seriesModel.get(dimName + 'AxisIndex'),
  31834. id: seriesModel.get(dimName + 'AxisId')
  31835. })[0];
  31836. if (this._axisIndex === (axisModel && axisModel.componentIndex)) {
  31837. seriesModels.push(seriesModel);
  31838. }
  31839. }
  31840. }, this);
  31841. return seriesModels;
  31842. },
  31843. getAxisModel: function () {
  31844. return this.ecModel.getComponent(this._dimName + 'Axis', this._axisIndex);
  31845. },
  31846. getOtherAxisModel: function () {
  31847. var axisDim = this._dimName;
  31848. var ecModel = this.ecModel;
  31849. var axisModel = this.getAxisModel();
  31850. var isCartesian = axisDim === 'x' || axisDim === 'y';
  31851. var otherAxisDim;
  31852. var coordSysIndexName;
  31853. if (isCartesian) {
  31854. coordSysIndexName = 'gridIndex';
  31855. otherAxisDim = axisDim === 'x' ? 'y' : 'x';
  31856. }
  31857. else {
  31858. coordSysIndexName = 'polarIndex';
  31859. otherAxisDim = axisDim === 'angle' ? 'radius' : 'angle';
  31860. }
  31861. var foundOtherAxisModel;
  31862. ecModel.eachComponent(otherAxisDim + 'Axis', function (otherAxisModel) {
  31863. if ((otherAxisModel.get(coordSysIndexName) || 0)
  31864. === (axisModel.get(coordSysIndexName) || 0)
  31865. ) {
  31866. foundOtherAxisModel = otherAxisModel;
  31867. }
  31868. });
  31869. return foundOtherAxisModel;
  31870. },
  31871. /**
  31872. * Only calculate by given range and this._dataExtent, do not change anything.
  31873. *
  31874. * @param {Object} opt
  31875. * @param {number} [opt.start]
  31876. * @param {number} [opt.end]
  31877. * @param {number} [opt.startValue]
  31878. * @param {number} [opt.endValue]
  31879. */
  31880. calculateDataWindow: function (opt) {
  31881. var dataExtent = this._dataExtent;
  31882. var axisModel = this.getAxisModel();
  31883. var scale = axisModel.axis.scale;
  31884. var percentExtent = [0, 100];
  31885. var percentWindow = [
  31886. opt.start,
  31887. opt.end
  31888. ];
  31889. var valueWindow = [];
  31890. // In percent range is used and axis min/max/scale is set,
  31891. // window should be based on min/max/0, but should not be
  31892. // based on the extent of filtered data.
  31893. dataExtent = dataExtent.slice();
  31894. fixExtentByAxis(dataExtent, axisModel);
  31895. each(['startValue', 'endValue'], function (prop) {
  31896. valueWindow.push(opt[prop] != null ? scale.parse(opt[prop]) : null);
  31897. });
  31898. // Normalize bound.
  31899. each([0, 1], function (idx) {
  31900. var boundValue = valueWindow[idx];
  31901. var boundPercent = percentWindow[idx];
  31902. // start/end has higher priority over startValue/endValue,
  31903. // because start/end can be consistent among different type
  31904. // of axis but startValue/endValue not.
  31905. if (boundPercent != null || boundValue == null) {
  31906. if (boundPercent == null) {
  31907. boundPercent = percentExtent[idx];
  31908. }
  31909. // Use scale.parse to math round for category or time axis.
  31910. boundValue = scale.parse(numberUtil.linearMap(
  31911. boundPercent, percentExtent, dataExtent, true
  31912. ));
  31913. }
  31914. else { // boundPercent == null && boundValue != null
  31915. boundPercent = numberUtil.linearMap(
  31916. boundValue, dataExtent, percentExtent, true
  31917. );
  31918. }
  31919. // valueWindow[idx] = round(boundValue);
  31920. // percentWindow[idx] = round(boundPercent);
  31921. valueWindow[idx] = boundValue;
  31922. percentWindow[idx] = boundPercent;
  31923. });
  31924. return {
  31925. valueWindow: asc(valueWindow),
  31926. percentWindow: asc(percentWindow)
  31927. };
  31928. },
  31929. /**
  31930. * Notice: reset should not be called before series.restoreData() called,
  31931. * so it is recommanded to be called in "process stage" but not "model init
  31932. * stage".
  31933. *
  31934. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  31935. */
  31936. reset: function (dataZoomModel) {
  31937. if (dataZoomModel !== this._dataZoomModel) {
  31938. return;
  31939. }
  31940. // Culculate data window and data extent, and record them.
  31941. this._dataExtent = calculateDataExtent(
  31942. this._dimName, this.getTargetSeriesModels()
  31943. );
  31944. var dataWindow = this.calculateDataWindow(dataZoomModel.option);
  31945. this._valueWindow = dataWindow.valueWindow;
  31946. this._percentWindow = dataWindow.percentWindow;
  31947. // Update axis setting then.
  31948. setAxisModel(this);
  31949. },
  31950. /**
  31951. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  31952. */
  31953. restore: function (dataZoomModel) {
  31954. if (dataZoomModel !== this._dataZoomModel) {
  31955. return;
  31956. }
  31957. this._valueWindow = this._percentWindow = null;
  31958. setAxisModel(this, true);
  31959. },
  31960. /**
  31961. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  31962. */
  31963. filterData: function (dataZoomModel) {
  31964. if (dataZoomModel !== this._dataZoomModel) {
  31965. return;
  31966. }
  31967. var axisDim = this._dimName;
  31968. var seriesModels = this.getTargetSeriesModels();
  31969. var filterMode = dataZoomModel.get('filterMode');
  31970. var valueWindow = this._valueWindow;
  31971. // FIXME
  31972. // Toolbox may has dataZoom injected. And if there are stacked bar chart
  31973. // with NaN data, NaN will be filtered and stack will be wrong.
  31974. // So we need to force the mode to be set empty.
  31975. // In fect, it is not a big deal that do not support filterMode-'filter'
  31976. // when using toolbox#dataZoom, utill tooltip#dataZoom support "single axis
  31977. // selection" some day, which might need "adapt to data extent on the
  31978. // otherAxis", which is disabled by filterMode-'empty'.
  31979. var otherAxisModel = this.getOtherAxisModel();
  31980. if (dataZoomModel.get('$fromToolbox')
  31981. && otherAxisModel
  31982. && otherAxisModel.get('type') === 'category'
  31983. ) {
  31984. filterMode = 'empty';
  31985. }
  31986. // Process series data
  31987. each(seriesModels, function (seriesModel) {
  31988. var seriesData = seriesModel.getData();
  31989. seriesData && each(seriesModel.coordDimToDataDim(axisDim), function (dim) {
  31990. if (filterMode === 'empty') {
  31991. seriesModel.setData(
  31992. seriesData.map(dim, function (value) {
  31993. return !isInWindow(value) ? NaN : value;
  31994. })
  31995. );
  31996. }
  31997. else {
  31998. seriesData.filterSelf(dim, isInWindow);
  31999. }
  32000. });
  32001. });
  32002. function isInWindow(value) {
  32003. return value >= valueWindow[0] && value <= valueWindow[1];
  32004. }
  32005. }
  32006. };
  32007. function calculateDataExtent(axisDim, seriesModels) {
  32008. var dataExtent = [Infinity, -Infinity];
  32009. each(seriesModels, function (seriesModel) {
  32010. var seriesData = seriesModel.getData();
  32011. if (seriesData) {
  32012. each(seriesModel.coordDimToDataDim(axisDim), function (dim) {
  32013. var seriesExtent = seriesData.getDataExtent(dim);
  32014. seriesExtent[0] < dataExtent[0] && (dataExtent[0] = seriesExtent[0]);
  32015. seriesExtent[1] > dataExtent[1] && (dataExtent[1] = seriesExtent[1]);
  32016. });
  32017. }
  32018. }, this);
  32019. if (dataExtent[1] < dataExtent[0]) {
  32020. dataExtent = [NaN, NaN];
  32021. }
  32022. return dataExtent;
  32023. }
  32024. function fixExtentByAxis(dataExtent, axisModel) {
  32025. var min = axisModel.getMin(true);
  32026. if (min != null && min !== 'dataMin') {
  32027. dataExtent[0] = min;
  32028. }
  32029. var max = axisModel.getMax(true);
  32030. if (max != null && max !== 'dataMax') {
  32031. dataExtent[1] = max;
  32032. }
  32033. if (!axisModel.get('scale', true)) {
  32034. dataExtent[0] > 0 && (dataExtent[0] = 0);
  32035. dataExtent[1] < 0 && (dataExtent[1] = 0);
  32036. }
  32037. return dataExtent;
  32038. }
  32039. function setAxisModel(axisProxy, isRestore) {
  32040. var axisModel = axisProxy.getAxisModel();
  32041. var percentWindow = axisProxy._percentWindow;
  32042. var valueWindow = axisProxy._valueWindow;
  32043. if (!percentWindow) {
  32044. return;
  32045. }
  32046. // [0, 500]: arbitrary value, guess axis extent.
  32047. var precision = numberUtil.getPixelPrecision(valueWindow, [0, 500]);
  32048. // isRestore or isFull
  32049. var useOrigin = isRestore || (percentWindow[0] === 0 && percentWindow[1] === 100);
  32050. axisModel.setRange(
  32051. useOrigin ? null : +valueWindow[0].toFixed(precision),
  32052. useOrigin ? null : +valueWindow[1].toFixed(precision)
  32053. );
  32054. }
  32055. module.exports = AxisProxy;
  32056. /***/ },
  32057. /* 334 */
  32058. /***/ function(module, exports, __webpack_require__) {
  32059. var ComponentView = __webpack_require__(29);
  32060. module.exports = ComponentView.extend({
  32061. type: 'dataZoom',
  32062. render: function (dataZoomModel, ecModel, api, payload) {
  32063. this.dataZoomModel = dataZoomModel;
  32064. this.ecModel = ecModel;
  32065. this.api = api;
  32066. },
  32067. /**
  32068. * Find the first target coordinate system.
  32069. *
  32070. * @protected
  32071. * @return {Object} {
  32072. * grid: [
  32073. * {model: coord0, axisModels: [axis1, axis3], coordIndex: 1},
  32074. * {model: coord1, axisModels: [axis0, axis2], coordIndex: 0},
  32075. * ...
  32076. * ], // cartesians must not be null/undefined.
  32077. * polar: [
  32078. * {model: coord0, axisModels: [axis4], coordIndex: 0},
  32079. * ...
  32080. * ], // polars must not be null/undefined.
  32081. * singleAxis: [
  32082. * {model: coord0, axisModels: [], coordIndex: 0}
  32083. * ]
  32084. */
  32085. getTargetCoordInfo: function () {
  32086. var dataZoomModel = this.dataZoomModel;
  32087. var ecModel = this.ecModel;
  32088. var coordSysLists = {};
  32089. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex) {
  32090. var axisModel = ecModel.getComponent(dimNames.axis, axisIndex);
  32091. if (axisModel) {
  32092. var coordModel = axisModel.getCoordSysModel();
  32093. coordModel && save(
  32094. coordModel,
  32095. axisModel,
  32096. coordSysLists[coordModel.mainType] || (coordSysLists[coordModel.mainType] = []),
  32097. coordModel.componentIndex
  32098. );
  32099. }
  32100. }, this);
  32101. function save(coordModel, axisModel, store, coordIndex) {
  32102. var item;
  32103. for (var i = 0; i < store.length; i++) {
  32104. if (store[i].model === coordModel) {
  32105. item = store[i];
  32106. break;
  32107. }
  32108. }
  32109. if (!item) {
  32110. store.push(item = {
  32111. model: coordModel, axisModels: [], coordIndex: coordIndex
  32112. });
  32113. }
  32114. item.axisModels.push(axisModel);
  32115. }
  32116. return coordSysLists;
  32117. }
  32118. });
  32119. /***/ },
  32120. /* 335 */
  32121. /***/ function(module, exports, __webpack_require__) {
  32122. /**
  32123. * @file Data zoom model
  32124. */
  32125. var DataZoomModel = __webpack_require__(331);
  32126. var SliderZoomModel = DataZoomModel.extend({
  32127. type: 'dataZoom.slider',
  32128. layoutMode: 'box',
  32129. /**
  32130. * @protected
  32131. */
  32132. defaultOption: {
  32133. show: true,
  32134. // ph => placeholder. Using placehoder here because
  32135. // deault value can only be drived in view stage.
  32136. right: 'ph', // Default align to grid rect.
  32137. top: 'ph', // Default align to grid rect.
  32138. width: 'ph', // Default align to grid rect.
  32139. height: 'ph', // Default align to grid rect.
  32140. left: null, // Default align to grid rect.
  32141. bottom: null, // Default align to grid rect.
  32142. backgroundColor: 'rgba(47,69,84,0)', // Background of slider zoom component.
  32143. // dataBackgroundColor: '#ddd', // Background coor of data shadow and border of box,
  32144. // highest priority, remain for compatibility of
  32145. // previous version, but not recommended any more.
  32146. dataBackground: {
  32147. lineStyle: {
  32148. color: '#2f4554',
  32149. width: 0.5,
  32150. opacity: 0.3
  32151. },
  32152. areaStyle: {
  32153. color: 'rgba(47,69,84,0.3)',
  32154. opacity: 0.3
  32155. }
  32156. },
  32157. borderColor: '#ddd', // border color of the box. For compatibility,
  32158. // if dataBackgroundColor is set, borderColor
  32159. // is ignored.
  32160. fillerColor: 'rgba(167,183,204,0.4)', // Color of selected area.
  32161. // handleColor: 'rgba(89,170,216,0.95)', // Color of handle.
  32162. // handleIcon: 'path://M4.9,17.8c0-1.4,4.5-10.5,5.5-12.4c0-0.1,0.6-1.1,0.9-1.1c0.4,0,0.9,1,0.9,1.1c1.1,2.2,5.4,11,5.4,12.4v17.8c0,1.5-0.6,2.1-1.3,2.1H6.1c-0.7,0-1.3-0.6-1.3-2.1V17.8z',
  32163. handleIcon: 'M8.2,13.6V3.9H6.3v9.7H3.1v14.9h3.3v9.7h1.8v-9.7h3.3V13.6H8.2z M9.7,24.4H4.8v-1.4h4.9V24.4z M9.7,19.1H4.8v-1.4h4.9V19.1z',
  32164. // Percent of the slider height
  32165. handleSize: '100%',
  32166. handleStyle: {
  32167. color: '#a7b7cc'
  32168. },
  32169. labelPrecision: null,
  32170. labelFormatter: null,
  32171. showDetail: true,
  32172. showDataShadow: 'auto', // Default auto decision.
  32173. realtime: true,
  32174. zoomLock: false, // Whether disable zoom.
  32175. textStyle: {
  32176. color: '#333'
  32177. }
  32178. }
  32179. });
  32180. module.exports = SliderZoomModel;
  32181. /***/ },
  32182. /* 336 */
  32183. /***/ function(module, exports, __webpack_require__) {
  32184. var zrUtil = __webpack_require__(4);
  32185. var graphic = __webpack_require__(43);
  32186. var throttle = __webpack_require__(81);
  32187. var DataZoomView = __webpack_require__(334);
  32188. var Rect = graphic.Rect;
  32189. var numberUtil = __webpack_require__(7);
  32190. var linearMap = numberUtil.linearMap;
  32191. var layout = __webpack_require__(21);
  32192. var sliderMove = __webpack_require__(337);
  32193. var asc = numberUtil.asc;
  32194. var bind = zrUtil.bind;
  32195. // var mathMax = Math.max;
  32196. var each = zrUtil.each;
  32197. // Constants
  32198. var DEFAULT_LOCATION_EDGE_GAP = 7;
  32199. var DEFAULT_FRAME_BORDER_WIDTH = 1;
  32200. var DEFAULT_FILLER_SIZE = 30;
  32201. var HORIZONTAL = 'horizontal';
  32202. var VERTICAL = 'vertical';
  32203. var LABEL_GAP = 5;
  32204. var SHOW_DATA_SHADOW_SERIES_TYPE = ['line', 'bar', 'candlestick', 'scatter'];
  32205. var SliderZoomView = DataZoomView.extend({
  32206. type: 'dataZoom.slider',
  32207. init: function (ecModel, api) {
  32208. /**
  32209. * @private
  32210. * @type {Object}
  32211. */
  32212. this._displayables = {};
  32213. /**
  32214. * @private
  32215. * @type {string}
  32216. */
  32217. this._orient;
  32218. /**
  32219. * [0, 100]
  32220. * @private
  32221. */
  32222. this._range;
  32223. /**
  32224. * [coord of the first handle, coord of the second handle]
  32225. * @private
  32226. */
  32227. this._handleEnds;
  32228. /**
  32229. * [length, thick]
  32230. * @private
  32231. * @type {Array.<number>}
  32232. */
  32233. this._size;
  32234. /**
  32235. * @private
  32236. * @type {number}
  32237. */
  32238. this._handleWidth;
  32239. /**
  32240. * @private
  32241. * @type {number}
  32242. */
  32243. this._handleHeight;
  32244. /**
  32245. * @private
  32246. */
  32247. this._location;
  32248. /**
  32249. * @private
  32250. */
  32251. this._dragging;
  32252. /**
  32253. * @private
  32254. */
  32255. this._dataShadowInfo;
  32256. this.api = api;
  32257. },
  32258. /**
  32259. * @override
  32260. */
  32261. render: function (dataZoomModel, ecModel, api, payload) {
  32262. SliderZoomView.superApply(this, 'render', arguments);
  32263. throttle.createOrUpdate(
  32264. this,
  32265. '_dispatchZoomAction',
  32266. this.dataZoomModel.get('throttle'),
  32267. 'fixRate'
  32268. );
  32269. this._orient = dataZoomModel.get('orient');
  32270. if (this.dataZoomModel.get('show') === false) {
  32271. this.group.removeAll();
  32272. return;
  32273. }
  32274. // Notice: this._resetInterval() should not be executed when payload.type
  32275. // is 'dataZoom', origin this._range should be maintained, otherwise 'pan'
  32276. // or 'zoom' info will be missed because of 'throttle' of this.dispatchAction,
  32277. if (!payload || payload.type !== 'dataZoom' || payload.from !== this.uid) {
  32278. this._buildView();
  32279. }
  32280. this._updateView();
  32281. },
  32282. /**
  32283. * @override
  32284. */
  32285. remove: function () {
  32286. SliderZoomView.superApply(this, 'remove', arguments);
  32287. throttle.clear(this, '_dispatchZoomAction');
  32288. },
  32289. /**
  32290. * @override
  32291. */
  32292. dispose: function () {
  32293. SliderZoomView.superApply(this, 'dispose', arguments);
  32294. throttle.clear(this, '_dispatchZoomAction');
  32295. },
  32296. _buildView: function () {
  32297. var thisGroup = this.group;
  32298. thisGroup.removeAll();
  32299. this._resetLocation();
  32300. this._resetInterval();
  32301. var barGroup = this._displayables.barGroup = new graphic.Group();
  32302. this._renderBackground();
  32303. this._renderHandle();
  32304. this._renderDataShadow();
  32305. thisGroup.add(barGroup);
  32306. this._positionGroup();
  32307. },
  32308. /**
  32309. * @private
  32310. */
  32311. _resetLocation: function () {
  32312. var dataZoomModel = this.dataZoomModel;
  32313. var api = this.api;
  32314. // If some of x/y/width/height are not specified,
  32315. // auto-adapt according to target grid.
  32316. var coordRect = this._findCoordRect();
  32317. var ecSize = {width: api.getWidth(), height: api.getHeight()};
  32318. // Default align by coordinate system rect.
  32319. var positionInfo = this._orient === HORIZONTAL
  32320. ? {
  32321. // Why using 'right', because right should be used in vertical,
  32322. // and it is better to be consistent for dealing with position param merge.
  32323. right: ecSize.width - coordRect.x - coordRect.width,
  32324. top: (ecSize.height - DEFAULT_FILLER_SIZE - DEFAULT_LOCATION_EDGE_GAP),
  32325. width: coordRect.width,
  32326. height: DEFAULT_FILLER_SIZE
  32327. }
  32328. : { // vertical
  32329. right: DEFAULT_LOCATION_EDGE_GAP,
  32330. top: coordRect.y,
  32331. width: DEFAULT_FILLER_SIZE,
  32332. height: coordRect.height
  32333. };
  32334. // Do not write back to option and replace value 'ph', because
  32335. // the 'ph' value should be recalculated when resize.
  32336. var layoutParams = layout.getLayoutParams(dataZoomModel.option);
  32337. // Replace the placeholder value.
  32338. zrUtil.each(['right', 'top', 'width', 'height'], function (name) {
  32339. if (layoutParams[name] === 'ph') {
  32340. layoutParams[name] = positionInfo[name];
  32341. }
  32342. });
  32343. var layoutRect = layout.getLayoutRect(
  32344. layoutParams,
  32345. ecSize,
  32346. dataZoomModel.padding
  32347. );
  32348. this._location = {x: layoutRect.x, y: layoutRect.y};
  32349. this._size = [layoutRect.width, layoutRect.height];
  32350. this._orient === VERTICAL && this._size.reverse();
  32351. },
  32352. /**
  32353. * @private
  32354. */
  32355. _positionGroup: function () {
  32356. var thisGroup = this.group;
  32357. var location = this._location;
  32358. var orient = this._orient;
  32359. // Just use the first axis to determine mapping.
  32360. var targetAxisModel = this.dataZoomModel.getFirstTargetAxisModel();
  32361. var inverse = targetAxisModel && targetAxisModel.get('inverse');
  32362. var barGroup = this._displayables.barGroup;
  32363. var otherAxisInverse = (this._dataShadowInfo || {}).otherAxisInverse;
  32364. // Transform barGroup.
  32365. barGroup.attr(
  32366. (orient === HORIZONTAL && !inverse)
  32367. ? {scale: otherAxisInverse ? [1, 1] : [1, -1]}
  32368. : (orient === HORIZONTAL && inverse)
  32369. ? {scale: otherAxisInverse ? [-1, 1] : [-1, -1]}
  32370. : (orient === VERTICAL && !inverse)
  32371. ? {scale: otherAxisInverse ? [1, -1] : [1, 1], rotation: Math.PI / 2}
  32372. // Dont use Math.PI, considering shadow direction.
  32373. : {scale: otherAxisInverse ? [-1, -1] : [-1, 1], rotation: Math.PI / 2}
  32374. );
  32375. // Position barGroup
  32376. var rect = thisGroup.getBoundingRect([barGroup]);
  32377. thisGroup.attr('position', [location.x - rect.x, location.y - rect.y]);
  32378. },
  32379. /**
  32380. * @private
  32381. */
  32382. _getViewExtent: function () {
  32383. return [0, this._size[0]];
  32384. },
  32385. _renderBackground : function () {
  32386. var dataZoomModel = this.dataZoomModel;
  32387. var size = this._size;
  32388. this._displayables.barGroup.add(new Rect({
  32389. silent: true,
  32390. shape: {
  32391. x: 0, y: 0, width: size[0], height: size[1]
  32392. },
  32393. style: {
  32394. fill: dataZoomModel.get('backgroundColor')
  32395. },
  32396. z2: -40
  32397. }));
  32398. },
  32399. _renderDataShadow: function () {
  32400. var info = this._dataShadowInfo = this._prepareDataShadowInfo();
  32401. if (!info) {
  32402. return;
  32403. }
  32404. var size = this._size;
  32405. var seriesModel = info.series;
  32406. var data = seriesModel.getRawData();
  32407. var otherDim = seriesModel.getShadowDim
  32408. ? seriesModel.getShadowDim() // @see candlestick
  32409. : info.otherDim;
  32410. if (otherDim == null) {
  32411. return;
  32412. }
  32413. var otherDataExtent = data.getDataExtent(otherDim);
  32414. // Nice extent.
  32415. var otherOffset = (otherDataExtent[1] - otherDataExtent[0]) * 0.3;
  32416. otherDataExtent = [
  32417. otherDataExtent[0] - otherOffset,
  32418. otherDataExtent[1] + otherOffset
  32419. ];
  32420. var otherShadowExtent = [0, size[1]];
  32421. var thisShadowExtent = [0, size[0]];
  32422. var areaPoints = [[size[0], 0], [0, 0]];
  32423. var linePoints = [];
  32424. var step = thisShadowExtent[1] / (data.count() - 1);
  32425. var thisCoord = 0;
  32426. // Optimize for large data shadow
  32427. var stride = Math.round(data.count() / size[0]);
  32428. var lastIsEmpty;
  32429. data.each([otherDim], function (value, index) {
  32430. if (stride > 0 && (index % stride)) {
  32431. thisCoord += step;
  32432. return;
  32433. }
  32434. // FIXME
  32435. // Should consider axis.min/axis.max when drawing dataShadow.
  32436. // FIXME
  32437. // 应该使用统一的空判断?还是在list里进行空判断?
  32438. var isEmpty = value == null || isNaN(value) || value === '';
  32439. // See #4235.
  32440. var otherCoord = isEmpty
  32441. ? 0 : linearMap(value, otherDataExtent, otherShadowExtent, true);
  32442. // Attempt to draw data shadow precisely when there are empty value.
  32443. if (isEmpty && !lastIsEmpty && index) {
  32444. areaPoints.push([areaPoints[areaPoints.length - 1][0], 0]);
  32445. linePoints.push([linePoints[linePoints.length - 1][0], 0]);
  32446. }
  32447. else if (!isEmpty && lastIsEmpty) {
  32448. areaPoints.push([thisCoord, 0]);
  32449. linePoints.push([thisCoord, 0]);
  32450. }
  32451. areaPoints.push([thisCoord, otherCoord]);
  32452. linePoints.push([thisCoord, otherCoord]);
  32453. thisCoord += step;
  32454. lastIsEmpty = isEmpty;
  32455. });
  32456. var dataZoomModel = this.dataZoomModel;
  32457. // var dataBackgroundModel = dataZoomModel.getModel('dataBackground');
  32458. this._displayables.barGroup.add(new graphic.Polygon({
  32459. shape: {points: areaPoints},
  32460. style: zrUtil.defaults(
  32461. {fill: dataZoomModel.get('dataBackgroundColor')},
  32462. dataZoomModel.getModel('dataBackground.areaStyle').getAreaStyle()
  32463. ),
  32464. silent: true,
  32465. z2: -20
  32466. }));
  32467. this._displayables.barGroup.add(new graphic.Polyline({
  32468. shape: {points: linePoints},
  32469. style: dataZoomModel.getModel('dataBackground.lineStyle').getLineStyle(),
  32470. silent: true,
  32471. z2: -19
  32472. }));
  32473. },
  32474. _prepareDataShadowInfo: function () {
  32475. var dataZoomModel = this.dataZoomModel;
  32476. var showDataShadow = dataZoomModel.get('showDataShadow');
  32477. if (showDataShadow === false) {
  32478. return;
  32479. }
  32480. // Find a representative series.
  32481. var result;
  32482. var ecModel = this.ecModel;
  32483. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex) {
  32484. var seriesModels = dataZoomModel
  32485. .getAxisProxy(dimNames.name, axisIndex)
  32486. .getTargetSeriesModels();
  32487. zrUtil.each(seriesModels, function (seriesModel) {
  32488. if (result) {
  32489. return;
  32490. }
  32491. if (showDataShadow !== true && zrUtil.indexOf(
  32492. SHOW_DATA_SHADOW_SERIES_TYPE, seriesModel.get('type')
  32493. ) < 0
  32494. ) {
  32495. return;
  32496. }
  32497. var thisAxis = ecModel.getComponent(dimNames.axis, axisIndex).axis;
  32498. var otherDim = getOtherDim(dimNames.name);
  32499. var otherAxisInverse;
  32500. var coordSys = seriesModel.coordinateSystem;
  32501. if (otherDim != null && coordSys.getOtherAxis) {
  32502. otherAxisInverse = coordSys.getOtherAxis(thisAxis).inverse;
  32503. }
  32504. result = {
  32505. thisAxis: thisAxis,
  32506. series: seriesModel,
  32507. thisDim: dimNames.name,
  32508. otherDim: otherDim,
  32509. otherAxisInverse: otherAxisInverse
  32510. };
  32511. }, this);
  32512. }, this);
  32513. return result;
  32514. },
  32515. _renderHandle: function () {
  32516. var displaybles = this._displayables;
  32517. var handles = displaybles.handles = [];
  32518. var handleLabels = displaybles.handleLabels = [];
  32519. var barGroup = this._displayables.barGroup;
  32520. var size = this._size;
  32521. var dataZoomModel = this.dataZoomModel;
  32522. barGroup.add(displaybles.filler = new Rect({
  32523. draggable: true,
  32524. cursor: 'move',
  32525. drift: bind(this._onDragMove, this, 'all'),
  32526. ondragstart: bind(this._showDataInfo, this, true),
  32527. ondragend: bind(this._onDragEnd, this),
  32528. onmouseover: bind(this._showDataInfo, this, true),
  32529. onmouseout: bind(this._showDataInfo, this, false),
  32530. style: {
  32531. fill: dataZoomModel.get('fillerColor'),
  32532. textPosition : 'inside'
  32533. }
  32534. }));
  32535. // Frame border.
  32536. barGroup.add(new Rect(graphic.subPixelOptimizeRect({
  32537. silent: true,
  32538. shape: {
  32539. x: 0,
  32540. y: 0,
  32541. width: size[0],
  32542. height: size[1]
  32543. },
  32544. style: {
  32545. stroke: dataZoomModel.get('dataBackgroundColor')
  32546. || dataZoomModel.get('borderColor'),
  32547. lineWidth: DEFAULT_FRAME_BORDER_WIDTH,
  32548. fill: 'rgba(0,0,0,0)'
  32549. }
  32550. })));
  32551. var iconStr = dataZoomModel.get('handleIcon');
  32552. each([0, 1], function (handleIndex) {
  32553. var path = graphic.makePath(iconStr, {
  32554. style: {
  32555. strokeNoScale: true
  32556. },
  32557. rectHover: true,
  32558. cursor: this._orient === 'vertical' ? 'ns-resize' : 'ew-resize',
  32559. draggable: true,
  32560. drift: bind(this._onDragMove, this, handleIndex),
  32561. ondragend: bind(this._onDragEnd, this),
  32562. onmouseover: bind(this._showDataInfo, this, true),
  32563. onmouseout: bind(this._showDataInfo, this, false)
  32564. }, {
  32565. x: -0.5,
  32566. y: 0,
  32567. width: 1,
  32568. height: 1
  32569. }, 'center');
  32570. var bRect = path.getBoundingRect();
  32571. this._handleHeight = numberUtil.parsePercent(dataZoomModel.get('handleSize'), this._size[1]);
  32572. this._handleWidth = bRect.width / bRect.height * this._handleHeight;
  32573. path.setStyle(dataZoomModel.getModel('handleStyle').getItemStyle());
  32574. var handleColor = dataZoomModel.get('handleColor');
  32575. // Compatitable with previous version
  32576. if (handleColor != null) {
  32577. path.style.fill = handleColor;
  32578. }
  32579. barGroup.add(handles[handleIndex] = path);
  32580. var textStyleModel = dataZoomModel.textStyleModel;
  32581. this.group.add(
  32582. handleLabels[handleIndex] = new graphic.Text({
  32583. silent: true,
  32584. invisible: true,
  32585. style: {
  32586. x: 0, y: 0, text: '',
  32587. textVerticalAlign: 'middle',
  32588. textAlign: 'center',
  32589. fill: textStyleModel.getTextColor(),
  32590. textFont: textStyleModel.getFont()
  32591. },
  32592. z2: 10
  32593. }));
  32594. }, this);
  32595. },
  32596. /**
  32597. * @private
  32598. */
  32599. _resetInterval: function () {
  32600. var range = this._range = this.dataZoomModel.getPercentRange();
  32601. var viewExtent = this._getViewExtent();
  32602. this._handleEnds = [
  32603. linearMap(range[0], [0, 100], viewExtent, true),
  32604. linearMap(range[1], [0, 100], viewExtent, true)
  32605. ];
  32606. },
  32607. /**
  32608. * @private
  32609. * @param {(number|string)} handleIndex 0 or 1 or 'all'
  32610. * @param {number} dx
  32611. * @param {number} dy
  32612. */
  32613. _updateInterval: function (handleIndex, delta) {
  32614. var handleEnds = this._handleEnds;
  32615. var viewExtend = this._getViewExtent();
  32616. sliderMove(
  32617. delta,
  32618. handleEnds,
  32619. viewExtend,
  32620. (handleIndex === 'all' || this.dataZoomModel.get('zoomLock'))
  32621. ? 'rigid' : 'cross',
  32622. handleIndex
  32623. );
  32624. this._range = asc([
  32625. linearMap(handleEnds[0], viewExtend, [0, 100], true),
  32626. linearMap(handleEnds[1], viewExtend, [0, 100], true)
  32627. ]);
  32628. },
  32629. /**
  32630. * @private
  32631. */
  32632. _updateView: function (nonRealtime) {
  32633. var displaybles = this._displayables;
  32634. var handleEnds = this._handleEnds;
  32635. var handleInterval = asc(handleEnds.slice());
  32636. var size = this._size;
  32637. each([0, 1], function (handleIndex) {
  32638. // Handles
  32639. var handle = displaybles.handles[handleIndex];
  32640. var handleHeight = this._handleHeight;
  32641. handle.attr({
  32642. scale: [handleHeight, handleHeight],
  32643. position: [handleEnds[handleIndex], size[1] / 2 - handleHeight / 2]
  32644. });
  32645. }, this);
  32646. // Filler
  32647. displaybles.filler.setShape({
  32648. x: handleInterval[0],
  32649. y: 0,
  32650. width: handleInterval[1] - handleInterval[0],
  32651. height: size[1]
  32652. });
  32653. this._updateDataInfo(nonRealtime);
  32654. },
  32655. /**
  32656. * @private
  32657. */
  32658. _updateDataInfo: function (nonRealtime) {
  32659. var dataZoomModel = this.dataZoomModel;
  32660. var displaybles = this._displayables;
  32661. var handleLabels = displaybles.handleLabels;
  32662. var orient = this._orient;
  32663. var labelTexts = ['', ''];
  32664. // FIXME
  32665. // date型,支持formatter,autoformatter(ec2 date.getAutoFormatter)
  32666. if (dataZoomModel.get('showDetail')) {
  32667. var axisProxy = dataZoomModel.findRepresentativeAxisProxy();
  32668. if (axisProxy) {
  32669. var axis = axisProxy.getAxisModel().axis;
  32670. var range = this._range;
  32671. var dataInterval = nonRealtime
  32672. // See #4434, data and axis are not processed and reset yet in non-realtime mode.
  32673. ? axisProxy.calculateDataWindow({
  32674. start: range[0], end: range[1]
  32675. }).valueWindow
  32676. : axisProxy.getDataValueWindow();
  32677. labelTexts = [
  32678. this._formatLabel(dataInterval[0], axis),
  32679. this._formatLabel(dataInterval[1], axis)
  32680. ];
  32681. }
  32682. }
  32683. var orderedHandleEnds = asc(this._handleEnds.slice());
  32684. setLabel.call(this, 0);
  32685. setLabel.call(this, 1);
  32686. function setLabel(handleIndex) {
  32687. // Label
  32688. // Text should not transform by barGroup.
  32689. // Ignore handlers transform
  32690. var barTransform = graphic.getTransform(
  32691. displaybles.handles[handleIndex].parent, this.group
  32692. );
  32693. var direction = graphic.transformDirection(
  32694. handleIndex === 0 ? 'right' : 'left', barTransform
  32695. );
  32696. var offset = this._handleWidth / 2 + LABEL_GAP;
  32697. var textPoint = graphic.applyTransform(
  32698. [
  32699. orderedHandleEnds[handleIndex] + (handleIndex === 0 ? -offset : offset),
  32700. this._size[1] / 2
  32701. ],
  32702. barTransform
  32703. );
  32704. handleLabels[handleIndex].setStyle({
  32705. x: textPoint[0],
  32706. y: textPoint[1],
  32707. textVerticalAlign: orient === HORIZONTAL ? 'middle' : direction,
  32708. textAlign: orient === HORIZONTAL ? direction : 'center',
  32709. text: labelTexts[handleIndex]
  32710. });
  32711. }
  32712. },
  32713. /**
  32714. * @private
  32715. */
  32716. _formatLabel: function (value, axis) {
  32717. var dataZoomModel = this.dataZoomModel;
  32718. var labelFormatter = dataZoomModel.get('labelFormatter');
  32719. var labelPrecision = dataZoomModel.get('labelPrecision');
  32720. if (labelPrecision == null || labelPrecision === 'auto') {
  32721. labelPrecision = axis.getPixelPrecision();
  32722. }
  32723. var valueStr = (value == null || isNaN(value))
  32724. ? ''
  32725. // FIXME Glue code
  32726. : (axis.type === 'category' || axis.type === 'time')
  32727. ? axis.scale.getLabel(Math.round(value))
  32728. // param of toFixed should less then 20.
  32729. : value.toFixed(Math.min(labelPrecision, 20));
  32730. return zrUtil.isFunction(labelFormatter)
  32731. ? labelFormatter(value, valueStr)
  32732. : zrUtil.isString(labelFormatter)
  32733. ? labelFormatter.replace('{value}', valueStr)
  32734. : valueStr;
  32735. },
  32736. /**
  32737. * @private
  32738. * @param {boolean} showOrHide true: show, false: hide
  32739. */
  32740. _showDataInfo: function (showOrHide) {
  32741. // Always show when drgging.
  32742. showOrHide = this._dragging || showOrHide;
  32743. var handleLabels = this._displayables.handleLabels;
  32744. handleLabels[0].attr('invisible', !showOrHide);
  32745. handleLabels[1].attr('invisible', !showOrHide);
  32746. },
  32747. _onDragMove: function (handleIndex, dx, dy) {
  32748. this._dragging = true;
  32749. // Transform dx, dy to bar coordination.
  32750. var vertex = this._applyBarTransform([dx, dy], true);
  32751. this._updateInterval(handleIndex, vertex[0]);
  32752. var realtime = this.dataZoomModel.get('realtime');
  32753. this._updateView(!realtime);
  32754. if (realtime) {
  32755. realtime && this._dispatchZoomAction();
  32756. }
  32757. },
  32758. _onDragEnd: function () {
  32759. this._dragging = false;
  32760. this._showDataInfo(false);
  32761. this._dispatchZoomAction();
  32762. },
  32763. /**
  32764. * This action will be throttled.
  32765. * @private
  32766. */
  32767. _dispatchZoomAction: function () {
  32768. var range = this._range;
  32769. this.api.dispatchAction({
  32770. type: 'dataZoom',
  32771. from: this.uid,
  32772. dataZoomId: this.dataZoomModel.id,
  32773. start: range[0],
  32774. end: range[1]
  32775. });
  32776. },
  32777. /**
  32778. * @private
  32779. */
  32780. _applyBarTransform: function (vertex, inverse) {
  32781. var barTransform = this._displayables.barGroup.getLocalTransform();
  32782. return graphic.applyTransform(vertex, barTransform, inverse);
  32783. },
  32784. /**
  32785. * @private
  32786. */
  32787. _findCoordRect: function () {
  32788. // Find the grid coresponding to the first axis referred by dataZoom.
  32789. var rect;
  32790. each(this.getTargetCoordInfo(), function (coordInfoList) {
  32791. if (!rect && coordInfoList.length) {
  32792. var coordSys = coordInfoList[0].model.coordinateSystem;
  32793. rect = coordSys.getRect && coordSys.getRect();
  32794. }
  32795. });
  32796. if (!rect) {
  32797. var width = this.api.getWidth();
  32798. var height = this.api.getHeight();
  32799. rect = {
  32800. x: width * 0.2,
  32801. y: height * 0.2,
  32802. width: width * 0.6,
  32803. height: height * 0.6
  32804. };
  32805. }
  32806. return rect;
  32807. }
  32808. });
  32809. function getOtherDim(thisDim) {
  32810. // FIXME
  32811. // 这个逻辑和getOtherAxis里一致,但是写在这里是否不好
  32812. var map = {x: 'y', y: 'x', radius: 'angle', angle: 'radius'};
  32813. return map[thisDim];
  32814. }
  32815. module.exports = SliderZoomView;
  32816. /***/ },
  32817. /* 337 */
  32818. /***/ function(module, exports) {
  32819. /**
  32820. * Calculate slider move result.
  32821. *
  32822. * @param {number} delta Move length.
  32823. * @param {Array.<number>} handleEnds handleEnds[0] and be bigger then handleEnds[1].
  32824. * handleEnds will be modified in this method.
  32825. * @param {Array.<number>} extent handleEnds is restricted by extent.
  32826. * extent[0] should less or equals than extent[1].
  32827. * @param {string} mode 'rigid': Math.abs(handleEnds[0] - handleEnds[1]) remain unchanged,
  32828. * 'cross' handleEnds[0] can be bigger then handleEnds[1],
  32829. * 'push' handleEnds[0] can not be bigger then handleEnds[1],
  32830. * when they touch, one push other.
  32831. * @param {number} handleIndex If mode is 'rigid', handleIndex is not required.
  32832. * @param {Array.<number>} The input handleEnds.
  32833. */
  32834. module.exports = function (delta, handleEnds, extent, mode, handleIndex) {
  32835. if (!delta) {
  32836. return handleEnds;
  32837. }
  32838. if (mode === 'rigid') {
  32839. delta = getRealDelta(delta, handleEnds, extent);
  32840. handleEnds[0] += delta;
  32841. handleEnds[1] += delta;
  32842. }
  32843. else {
  32844. delta = getRealDelta(delta, handleEnds[handleIndex], extent);
  32845. handleEnds[handleIndex] += delta;
  32846. if (mode === 'push' && handleEnds[0] > handleEnds[1]) {
  32847. handleEnds[1 - handleIndex] = handleEnds[handleIndex];
  32848. }
  32849. }
  32850. return handleEnds;
  32851. function getRealDelta(delta, handleEnds, extent) {
  32852. var handleMinMax = !handleEnds.length
  32853. ? [handleEnds, handleEnds]
  32854. : handleEnds.slice();
  32855. handleEnds[0] > handleEnds[1] && handleMinMax.reverse();
  32856. if (delta < 0 && handleMinMax[0] + delta < extent[0]) {
  32857. delta = extent[0] - handleMinMax[0];
  32858. }
  32859. if (delta > 0 && handleMinMax[1] + delta > extent[1]) {
  32860. delta = extent[1] - handleMinMax[1];
  32861. }
  32862. return delta;
  32863. }
  32864. };
  32865. /***/ },
  32866. /* 338 */
  32867. /***/ function(module, exports, __webpack_require__) {
  32868. /**
  32869. * @file Data zoom model
  32870. */
  32871. module.exports = __webpack_require__(331).extend({
  32872. type: 'dataZoom.inside',
  32873. /**
  32874. * @protected
  32875. */
  32876. defaultOption: {
  32877. disabled: false, // Whether disable this inside zoom.
  32878. zoomLock: false // Whether disable zoom but only pan.
  32879. }
  32880. });
  32881. /***/ },
  32882. /* 339 */
  32883. /***/ function(module, exports, __webpack_require__) {
  32884. var DataZoomView = __webpack_require__(334);
  32885. var zrUtil = __webpack_require__(4);
  32886. var sliderMove = __webpack_require__(337);
  32887. var roams = __webpack_require__(340);
  32888. var bind = zrUtil.bind;
  32889. var InsideZoomView = DataZoomView.extend({
  32890. type: 'dataZoom.inside',
  32891. /**
  32892. * @override
  32893. */
  32894. init: function (ecModel, api) {
  32895. /**
  32896. * 'throttle' is used in this.dispatchAction, so we save range
  32897. * to avoid missing some 'pan' info.
  32898. * @private
  32899. * @type {Array.<number>}
  32900. */
  32901. this._range;
  32902. },
  32903. /**
  32904. * @override
  32905. */
  32906. render: function (dataZoomModel, ecModel, api, payload) {
  32907. InsideZoomView.superApply(this, 'render', arguments);
  32908. // Notice: origin this._range should be maintained, and should not be re-fetched
  32909. // from dataZoomModel when payload.type is 'dataZoom', otherwise 'pan' or 'zoom'
  32910. // info will be missed because of 'throttle' of this.dispatchAction.
  32911. if (roams.shouldRecordRange(payload, dataZoomModel.id)) {
  32912. this._range = dataZoomModel.getPercentRange();
  32913. }
  32914. // Reset controllers.
  32915. zrUtil.each(this.getTargetCoordInfo(), function (coordInfoList, coordSysName) {
  32916. var allCoordIds = zrUtil.map(coordInfoList, function (coordInfo) {
  32917. return roams.generateCoordId(coordInfo.model);
  32918. });
  32919. zrUtil.each(coordInfoList, function (coordInfo) {
  32920. var coordModel = coordInfo.model;
  32921. roams.register(
  32922. api,
  32923. {
  32924. coordId: roams.generateCoordId(coordModel),
  32925. allCoordIds: allCoordIds,
  32926. containsPoint: function (x, y) {
  32927. return coordModel.coordinateSystem.containPoint([x, y]);
  32928. },
  32929. dataZoomId: dataZoomModel.id,
  32930. throttleRate: dataZoomModel.get('throttle', true),
  32931. panGetRange: bind(this._onPan, this, coordInfo, coordSysName),
  32932. zoomGetRange: bind(this._onZoom, this, coordInfo, coordSysName)
  32933. }
  32934. );
  32935. }, this);
  32936. }, this);
  32937. },
  32938. /**
  32939. * @override
  32940. */
  32941. dispose: function () {
  32942. roams.unregister(this.api, this.dataZoomModel.id);
  32943. InsideZoomView.superApply(this, 'dispose', arguments);
  32944. this._range = null;
  32945. },
  32946. /**
  32947. * @private
  32948. */
  32949. _onPan: function (coordInfo, coordSysName, controller, dx, dy, oldX, oldY, newX, newY) {
  32950. if (this.dataZoomModel.option.disabled) {
  32951. return this._range;
  32952. }
  32953. var range = this._range.slice();
  32954. // Calculate transform by the first axis.
  32955. var axisModel = coordInfo.axisModels[0];
  32956. if (!axisModel) {
  32957. return;
  32958. }
  32959. var directionInfo = getDirectionInfo[coordSysName](
  32960. [oldX, oldY], [newX, newY], axisModel, controller, coordInfo
  32961. );
  32962. var percentDelta = directionInfo.signal
  32963. * (range[1] - range[0])
  32964. * directionInfo.pixel / directionInfo.pixelLength;
  32965. sliderMove(percentDelta, range, [0, 100], 'rigid');
  32966. return (this._range = range);
  32967. },
  32968. /**
  32969. * @private
  32970. */
  32971. _onZoom: function (coordInfo, coordSysName, controller, scale, mouseX, mouseY) {
  32972. var option = this.dataZoomModel.option;
  32973. if (option.disabled || option.zoomLock) {
  32974. return this._range;
  32975. }
  32976. var range = this._range.slice();
  32977. // Calculate transform by the first axis.
  32978. var axisModel = coordInfo.axisModels[0];
  32979. if (!axisModel) {
  32980. return;
  32981. }
  32982. var directionInfo = getDirectionInfo[coordSysName](
  32983. null, [mouseX, mouseY], axisModel, controller, coordInfo
  32984. );
  32985. var percentPoint = (directionInfo.pixel - directionInfo.pixelStart) /
  32986. directionInfo.pixelLength * (range[1] - range[0]) + range[0];
  32987. scale = Math.max(1 / scale, 0);
  32988. range[0] = (range[0] - percentPoint) * scale + percentPoint;
  32989. range[1] = (range[1] - percentPoint) * scale + percentPoint;
  32990. return (this._range = fixRange(range));
  32991. }
  32992. });
  32993. var getDirectionInfo = {
  32994. grid: function (oldPoint, newPoint, axisModel, controller, coordInfo) {
  32995. var axis = axisModel.axis;
  32996. var ret = {};
  32997. var rect = coordInfo.model.coordinateSystem.getRect();
  32998. oldPoint = oldPoint || [0, 0];
  32999. if (axis.dim === 'x') {
  33000. ret.pixel = newPoint[0] - oldPoint[0];
  33001. ret.pixelLength = rect.width;
  33002. ret.pixelStart = rect.x;
  33003. ret.signal = axis.inverse ? 1 : -1;
  33004. }
  33005. else { // axis.dim === 'y'
  33006. ret.pixel = newPoint[1] - oldPoint[1];
  33007. ret.pixelLength = rect.height;
  33008. ret.pixelStart = rect.y;
  33009. ret.signal = axis.inverse ? -1 : 1;
  33010. }
  33011. return ret;
  33012. },
  33013. polar: function (oldPoint, newPoint, axisModel, controller, coordInfo) {
  33014. var axis = axisModel.axis;
  33015. var ret = {};
  33016. var polar = coordInfo.model.coordinateSystem;
  33017. var radiusExtent = polar.getRadiusAxis().getExtent();
  33018. var angleExtent = polar.getAngleAxis().getExtent();
  33019. oldPoint = oldPoint ? polar.pointToCoord(oldPoint) : [0, 0];
  33020. newPoint = polar.pointToCoord(newPoint);
  33021. if (axisModel.mainType === 'radiusAxis') {
  33022. ret.pixel = newPoint[0] - oldPoint[0];
  33023. // ret.pixelLength = Math.abs(radiusExtent[1] - radiusExtent[0]);
  33024. // ret.pixelStart = Math.min(radiusExtent[0], radiusExtent[1]);
  33025. ret.pixelLength = radiusExtent[1] - radiusExtent[0];
  33026. ret.pixelStart = radiusExtent[0];
  33027. ret.signal = axis.inverse ? 1 : -1;
  33028. }
  33029. else { // 'angleAxis'
  33030. ret.pixel = newPoint[1] - oldPoint[1];
  33031. // ret.pixelLength = Math.abs(angleExtent[1] - angleExtent[0]);
  33032. // ret.pixelStart = Math.min(angleExtent[0], angleExtent[1]);
  33033. ret.pixelLength = angleExtent[1] - angleExtent[0];
  33034. ret.pixelStart = angleExtent[0];
  33035. ret.signal = axis.inverse ? -1 : 1;
  33036. }
  33037. return ret;
  33038. },
  33039. singleAxis: function (oldPoint, newPoint, axisModel, controller, coordInfo) {
  33040. var axis = axisModel.axis;
  33041. var rect = coordInfo.model.coordinateSystem.getRect();
  33042. var ret = {};
  33043. oldPoint = oldPoint || [0, 0];
  33044. if (axis.orient === 'horizontal') {
  33045. ret.pixel = newPoint[0] - oldPoint[0];
  33046. ret.pixelLength = rect.width;
  33047. ret.pixelStart = rect.x;
  33048. ret.signal = axis.inverse ? 1 : -1;
  33049. }
  33050. else { // 'vertical'
  33051. ret.pixel = newPoint[1] - oldPoint[1];
  33052. ret.pixelLength = rect.height;
  33053. ret.pixelStart = rect.y;
  33054. ret.signal = axis.inverse ? -1 : 1;
  33055. }
  33056. return ret;
  33057. }
  33058. };
  33059. function fixRange(range) {
  33060. // Clamp, using !(<= or >=) to handle NaN.
  33061. // jshint ignore:start
  33062. var bound = [0, 100];
  33063. !(range[0] <= bound[1]) && (range[0] = bound[1]);
  33064. !(range[1] <= bound[1]) && (range[1] = bound[1]);
  33065. !(range[0] >= bound[0]) && (range[0] = bound[0]);
  33066. !(range[1] >= bound[0]) && (range[1] = bound[0]);
  33067. // jshint ignore:end
  33068. return range;
  33069. }
  33070. module.exports = InsideZoomView;
  33071. /***/ },
  33072. /* 340 */
  33073. /***/ function(module, exports, __webpack_require__) {
  33074. /**
  33075. * @file Roam controller manager.
  33076. */
  33077. // Only create one roam controller for each coordinate system.
  33078. // one roam controller might be refered by two inside data zoom
  33079. // components (for example, one for x and one for y). When user
  33080. // pan or zoom, only dispatch one action for those data zoom
  33081. // components.
  33082. var zrUtil = __webpack_require__(4);
  33083. var RoamController = __webpack_require__(177);
  33084. var throttle = __webpack_require__(81);
  33085. var curry = zrUtil.curry;
  33086. var ATTR = '\0_ec_dataZoom_roams';
  33087. var roams = {
  33088. /**
  33089. * @public
  33090. * @param {module:echarts/ExtensionAPI} api
  33091. * @param {Object} dataZoomInfo
  33092. * @param {string} dataZoomInfo.coordId
  33093. * @param {Function} dataZoomInfo.containsPoint
  33094. * @param {Array.<string>} dataZoomInfo.allCoordIds
  33095. * @param {string} dataZoomInfo.dataZoomId
  33096. * @param {number} dataZoomInfo.throttleRate
  33097. * @param {Function} dataZoomInfo.panGetRange
  33098. * @param {Function} dataZoomInfo.zoomGetRange
  33099. */
  33100. register: function (api, dataZoomInfo) {
  33101. var store = giveStore(api);
  33102. var theDataZoomId = dataZoomInfo.dataZoomId;
  33103. var theCoordId = dataZoomInfo.coordId;
  33104. // Do clean when a dataZoom changes its target coordnate system.
  33105. // Avoid memory leak, dispose all not-used-registered.
  33106. zrUtil.each(store, function (record, coordId) {
  33107. var dataZoomInfos = record.dataZoomInfos;
  33108. if (dataZoomInfos[theDataZoomId]
  33109. && zrUtil.indexOf(dataZoomInfo.allCoordIds, theCoordId) < 0
  33110. ) {
  33111. delete dataZoomInfos[theDataZoomId];
  33112. record.count--;
  33113. }
  33114. });
  33115. cleanStore(store);
  33116. var record = store[theCoordId];
  33117. // Create if needed.
  33118. if (!record) {
  33119. record = store[theCoordId] = {
  33120. coordId: theCoordId,
  33121. dataZoomInfos: {},
  33122. count: 0
  33123. };
  33124. record.controller = createController(api, dataZoomInfo, record);
  33125. record.dispatchAction = zrUtil.curry(dispatchAction, api);
  33126. }
  33127. // Consider resize, area should be always updated.
  33128. record.controller.setContainsPoint(dataZoomInfo.containsPoint);
  33129. // Update throttle.
  33130. throttle.createOrUpdate(
  33131. record,
  33132. 'dispatchAction',
  33133. dataZoomInfo.throttleRate,
  33134. 'fixRate'
  33135. );
  33136. // Update reference of dataZoom.
  33137. !(record.dataZoomInfos[theDataZoomId]) && record.count++;
  33138. record.dataZoomInfos[theDataZoomId] = dataZoomInfo;
  33139. },
  33140. /**
  33141. * @public
  33142. * @param {module:echarts/ExtensionAPI} api
  33143. * @param {string} dataZoomId
  33144. */
  33145. unregister: function (api, dataZoomId) {
  33146. var store = giveStore(api);
  33147. zrUtil.each(store, function (record) {
  33148. record.controller.dispose();
  33149. var dataZoomInfos = record.dataZoomInfos;
  33150. if (dataZoomInfos[dataZoomId]) {
  33151. delete dataZoomInfos[dataZoomId];
  33152. record.count--;
  33153. }
  33154. });
  33155. cleanStore(store);
  33156. },
  33157. /**
  33158. * @public
  33159. */
  33160. shouldRecordRange: function (payload, dataZoomId) {
  33161. if (payload && payload.type === 'dataZoom' && payload.batch) {
  33162. for (var i = 0, len = payload.batch.length; i < len; i++) {
  33163. if (payload.batch[i].dataZoomId === dataZoomId) {
  33164. return false;
  33165. }
  33166. }
  33167. }
  33168. return true;
  33169. },
  33170. /**
  33171. * @public
  33172. */
  33173. generateCoordId: function (coordModel) {
  33174. return coordModel.type + '\0_' + coordModel.id;
  33175. }
  33176. };
  33177. /**
  33178. * Key: coordId, value: {dataZoomInfos: [], count, controller}
  33179. * @type {Array.<Object>}
  33180. */
  33181. function giveStore(api) {
  33182. // Mount store on zrender instance, so that we do not
  33183. // need to worry about dispose.
  33184. var zr = api.getZr();
  33185. return zr[ATTR] || (zr[ATTR] = {});
  33186. }
  33187. function createController(api, dataZoomInfo, newRecord) {
  33188. var controller = new RoamController(api.getZr());
  33189. controller.enable();
  33190. controller.on('pan', curry(onPan, newRecord));
  33191. controller.on('zoom', curry(onZoom, newRecord));
  33192. return controller;
  33193. }
  33194. function cleanStore(store) {
  33195. zrUtil.each(store, function (record, coordId) {
  33196. if (!record.count) {
  33197. record.controller.dispose();
  33198. delete store[coordId];
  33199. }
  33200. });
  33201. }
  33202. function onPan(record, dx, dy, oldX, oldY, newX, newY) {
  33203. wrapAndDispatch(record, function (info) {
  33204. return info.panGetRange(record.controller, dx, dy, oldX, oldY, newX, newY);
  33205. });
  33206. }
  33207. function onZoom(record, scale, mouseX, mouseY) {
  33208. wrapAndDispatch(record, function (info) {
  33209. return info.zoomGetRange(record.controller, scale, mouseX, mouseY);
  33210. });
  33211. }
  33212. function wrapAndDispatch(record, getRange) {
  33213. var batch = [];
  33214. zrUtil.each(record.dataZoomInfos, function (info) {
  33215. var range = getRange(info);
  33216. range && batch.push({
  33217. dataZoomId: info.dataZoomId,
  33218. start: range[0],
  33219. end: range[1]
  33220. });
  33221. });
  33222. record.dispatchAction(batch);
  33223. }
  33224. /**
  33225. * This action will be throttled.
  33226. */
  33227. function dispatchAction(api, batch) {
  33228. api.dispatchAction({
  33229. type: 'dataZoom',
  33230. batch: batch
  33231. });
  33232. }
  33233. module.exports = roams;
  33234. /***/ },
  33235. /* 341 */
  33236. /***/ function(module, exports, __webpack_require__) {
  33237. /**
  33238. * @file Data zoom processor
  33239. */
  33240. var echarts = __webpack_require__(1);
  33241. echarts.registerProcessor(function (ecModel, api) {
  33242. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  33243. // We calculate window and reset axis here but not in model
  33244. // init stage and not after action dispatch handler, because
  33245. // reset should be called after seriesData.restoreData.
  33246. dataZoomModel.eachTargetAxis(resetSingleAxis);
  33247. // Caution: data zoom filtering is order sensitive when using
  33248. // percent range and no min/max/scale set on axis.
  33249. // For example, we have dataZoom definition:
  33250. // [
  33251. // {xAxisIndex: 0, start: 30, end: 70},
  33252. // {yAxisIndex: 0, start: 20, end: 80}
  33253. // ]
  33254. // In this case, [20, 80] of y-dataZoom should be based on data
  33255. // that have filtered by x-dataZoom using range of [30, 70],
  33256. // but should not be based on full raw data. Thus sliding
  33257. // x-dataZoom will change both ranges of xAxis and yAxis,
  33258. // while sliding y-dataZoom will only change the range of yAxis.
  33259. // So we should filter x-axis after reset x-axis immediately,
  33260. // and then reset y-axis and filter y-axis.
  33261. dataZoomModel.eachTargetAxis(filterSingleAxis);
  33262. });
  33263. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  33264. // Fullfill all of the range props so that user
  33265. // is able to get them from chart.getOption().
  33266. var axisProxy = dataZoomModel.findRepresentativeAxisProxy();
  33267. var percentRange = axisProxy.getDataPercentWindow();
  33268. var valueRange = axisProxy.getDataValueWindow();
  33269. dataZoomModel.setRawRange({
  33270. start: percentRange[0],
  33271. end: percentRange[1],
  33272. startValue: valueRange[0],
  33273. endValue: valueRange[1]
  33274. });
  33275. });
  33276. });
  33277. function resetSingleAxis(dimNames, axisIndex, dataZoomModel) {
  33278. dataZoomModel.getAxisProxy(dimNames.name, axisIndex).reset(dataZoomModel);
  33279. }
  33280. function filterSingleAxis(dimNames, axisIndex, dataZoomModel) {
  33281. dataZoomModel.getAxisProxy(dimNames.name, axisIndex).filterData(dataZoomModel);
  33282. }
  33283. /***/ },
  33284. /* 342 */
  33285. /***/ function(module, exports, __webpack_require__) {
  33286. /**
  33287. * @file Data zoom action
  33288. */
  33289. var zrUtil = __webpack_require__(4);
  33290. var helper = __webpack_require__(332);
  33291. var echarts = __webpack_require__(1);
  33292. echarts.registerAction('dataZoom', function (payload, ecModel) {
  33293. var linkedNodesFinder = helper.createLinkedNodesFinder(
  33294. zrUtil.bind(ecModel.eachComponent, ecModel, 'dataZoom'),
  33295. helper.eachAxisDim,
  33296. function (model, dimNames) {
  33297. return model.get(dimNames.axisIndex);
  33298. }
  33299. );
  33300. var effectedModels = [];
  33301. ecModel.eachComponent(
  33302. {mainType: 'dataZoom', query: payload},
  33303. function (model, index) {
  33304. effectedModels.push.apply(
  33305. effectedModels, linkedNodesFinder(model).nodes
  33306. );
  33307. }
  33308. );
  33309. zrUtil.each(effectedModels, function (dataZoomModel, index) {
  33310. dataZoomModel.setRawRange({
  33311. start: payload.start,
  33312. end: payload.end,
  33313. startValue: payload.startValue,
  33314. endValue: payload.endValue
  33315. });
  33316. });
  33317. });
  33318. /***/ },
  33319. /* 343 */,
  33320. /* 344 */,
  33321. /* 345 */,
  33322. /* 346 */,
  33323. /* 347 */,
  33324. /* 348 */,
  33325. /* 349 */,
  33326. /* 350 */,
  33327. /* 351 */,
  33328. /* 352 */,
  33329. /* 353 */,
  33330. /* 354 */,
  33331. /* 355 */,
  33332. /* 356 */,
  33333. /* 357 */,
  33334. /* 358 */
  33335. /***/ function(module, exports, __webpack_require__) {
  33336. // HINT Markpoint can't be used too much
  33337. __webpack_require__(359);
  33338. __webpack_require__(361);
  33339. __webpack_require__(1).registerPreprocessor(function (opt) {
  33340. // Make sure markPoint component is enabled
  33341. opt.markPoint = opt.markPoint || {};
  33342. });
  33343. /***/ },
  33344. /* 359 */
  33345. /***/ function(module, exports, __webpack_require__) {
  33346. module.exports = __webpack_require__(360).extend({
  33347. type: 'markPoint',
  33348. defaultOption: {
  33349. zlevel: 0,
  33350. z: 5,
  33351. symbol: 'pin',
  33352. symbolSize: 50,
  33353. //symbolRotate: 0,
  33354. //symbolOffset: [0, 0]
  33355. tooltip: {
  33356. trigger: 'item'
  33357. },
  33358. label: {
  33359. normal: {
  33360. show: true,
  33361. position: 'inside'
  33362. },
  33363. emphasis: {
  33364. show: true
  33365. }
  33366. },
  33367. itemStyle: {
  33368. normal: {
  33369. borderWidth: 2
  33370. }
  33371. }
  33372. }
  33373. });
  33374. /***/ },
  33375. /* 360 */
  33376. /***/ function(module, exports, __webpack_require__) {
  33377. var modelUtil = __webpack_require__(5);
  33378. var zrUtil = __webpack_require__(4);
  33379. var env = __webpack_require__(2);
  33380. var formatUtil = __webpack_require__(6);
  33381. var addCommas = formatUtil.addCommas;
  33382. var encodeHTML = formatUtil.encodeHTML;
  33383. function fillLabel(opt) {
  33384. modelUtil.defaultEmphasis(
  33385. opt.label,
  33386. modelUtil.LABEL_OPTIONS
  33387. );
  33388. }
  33389. var MarkerModel = __webpack_require__(1).extendComponentModel({
  33390. type: 'marker',
  33391. dependencies: ['series', 'grid', 'polar', 'geo'],
  33392. /**
  33393. * @overrite
  33394. */
  33395. init: function (option, parentModel, ecModel, extraOpt) {
  33396. if (true) {
  33397. if (this.type === 'marker') {
  33398. throw new Error('Marker component is abstract component. Use markLine, markPoint, markArea instead.');
  33399. }
  33400. }
  33401. this.mergeDefaultAndTheme(option, ecModel);
  33402. this.mergeOption(option, ecModel, extraOpt.createdBySelf, true);
  33403. },
  33404. /**
  33405. * @return {boolean}
  33406. */
  33407. isAnimationEnabled: function () {
  33408. if (env.node) {
  33409. return false;
  33410. }
  33411. var hostSeries = this.__hostSeries;
  33412. return this.getShallow('animation') && hostSeries && hostSeries.isAnimationEnabled();
  33413. },
  33414. mergeOption: function (newOpt, ecModel, createdBySelf, isInit) {
  33415. var MarkerModel = this.constructor;
  33416. var modelPropName = this.mainType + 'Model';
  33417. if (!createdBySelf) {
  33418. ecModel.eachSeries(function (seriesModel) {
  33419. var markerOpt = seriesModel.get(this.mainType);
  33420. var markerModel = seriesModel[modelPropName];
  33421. if (!markerOpt || !markerOpt.data) {
  33422. seriesModel[modelPropName] = null;
  33423. return;
  33424. }
  33425. if (!markerModel) {
  33426. if (isInit) {
  33427. // Default label emphasis `position` and `show`
  33428. fillLabel(markerOpt);
  33429. }
  33430. zrUtil.each(markerOpt.data, function (item) {
  33431. // FIXME Overwrite fillLabel method ?
  33432. if (item instanceof Array) {
  33433. fillLabel(item[0]);
  33434. fillLabel(item[1]);
  33435. }
  33436. else {
  33437. fillLabel(item);
  33438. }
  33439. });
  33440. markerModel = new MarkerModel(
  33441. markerOpt, this, ecModel
  33442. );
  33443. zrUtil.extend(markerModel, {
  33444. mainType: this.mainType,
  33445. // Use the same series index and name
  33446. seriesIndex: seriesModel.seriesIndex,
  33447. name: seriesModel.name,
  33448. createdBySelf: true
  33449. });
  33450. markerModel.__hostSeries = seriesModel;
  33451. }
  33452. else {
  33453. markerModel.mergeOption(markerOpt, ecModel, true);
  33454. }
  33455. seriesModel[modelPropName] = markerModel;
  33456. }, this);
  33457. }
  33458. },
  33459. formatTooltip: function (dataIndex) {
  33460. var data = this.getData();
  33461. var value = this.getRawValue(dataIndex);
  33462. var formattedValue = zrUtil.isArray(value)
  33463. ? zrUtil.map(value, addCommas).join(', ') : addCommas(value);
  33464. var name = data.getName(dataIndex);
  33465. var html = encodeHTML(this.name);
  33466. if (value != null || name) {
  33467. html += '<br />';
  33468. }
  33469. if (name) {
  33470. html += encodeHTML(name);
  33471. if (value != null) {
  33472. html += ' : ';
  33473. }
  33474. }
  33475. if (value != null) {
  33476. html += encodeHTML(formattedValue);
  33477. }
  33478. return html;
  33479. },
  33480. getData: function () {
  33481. return this._data;
  33482. },
  33483. setData: function (data) {
  33484. this._data = data;
  33485. }
  33486. });
  33487. zrUtil.mixin(MarkerModel, modelUtil.dataFormatMixin);
  33488. module.exports = MarkerModel;
  33489. /***/ },
  33490. /* 361 */
  33491. /***/ function(module, exports, __webpack_require__) {
  33492. var SymbolDraw = __webpack_require__(105);
  33493. var zrUtil = __webpack_require__(4);
  33494. var numberUtil = __webpack_require__(7);
  33495. var List = __webpack_require__(98);
  33496. var markerHelper = __webpack_require__(362);
  33497. function updateMarkerLayout(mpData, seriesModel, api) {
  33498. var coordSys = seriesModel.coordinateSystem;
  33499. mpData.each(function (idx) {
  33500. var itemModel = mpData.getItemModel(idx);
  33501. var point;
  33502. var xPx = numberUtil.parsePercent(itemModel.get('x'), api.getWidth());
  33503. var yPx = numberUtil.parsePercent(itemModel.get('y'), api.getHeight());
  33504. if (!isNaN(xPx) && !isNaN(yPx)) {
  33505. point = [xPx, yPx];
  33506. }
  33507. // Chart like bar may have there own marker positioning logic
  33508. else if (seriesModel.getMarkerPosition) {
  33509. // Use the getMarkerPoisition
  33510. point = seriesModel.getMarkerPosition(
  33511. mpData.getValues(mpData.dimensions, idx)
  33512. );
  33513. }
  33514. else if (coordSys) {
  33515. var x = mpData.get(coordSys.dimensions[0], idx);
  33516. var y = mpData.get(coordSys.dimensions[1], idx);
  33517. point = coordSys.dataToPoint([x, y]);
  33518. }
  33519. // Use x, y if has any
  33520. if (!isNaN(xPx)) {
  33521. point[0] = xPx;
  33522. }
  33523. if (!isNaN(yPx)) {
  33524. point[1] = yPx;
  33525. }
  33526. mpData.setItemLayout(idx, point);
  33527. });
  33528. }
  33529. __webpack_require__(363).extend({
  33530. type: 'markPoint',
  33531. updateLayout: function (markPointModel, ecModel, api) {
  33532. ecModel.eachSeries(function (seriesModel) {
  33533. var mpModel = seriesModel.markPointModel;
  33534. if (mpModel) {
  33535. updateMarkerLayout(mpModel.getData(), seriesModel, api);
  33536. this.markerGroupMap[seriesModel.name].updateLayout(mpModel);
  33537. }
  33538. }, this);
  33539. },
  33540. renderSeries: function (seriesModel, mpModel, ecModel, api) {
  33541. var coordSys = seriesModel.coordinateSystem;
  33542. var seriesName = seriesModel.name;
  33543. var seriesData = seriesModel.getData();
  33544. var symbolDrawMap = this.markerGroupMap;
  33545. var symbolDraw = symbolDrawMap[seriesName];
  33546. if (!symbolDraw) {
  33547. symbolDraw = symbolDrawMap[seriesName] = new SymbolDraw();
  33548. }
  33549. var mpData = createList(coordSys, seriesModel, mpModel);
  33550. // FIXME
  33551. mpModel.setData(mpData);
  33552. updateMarkerLayout(mpModel.getData(), seriesModel, api);
  33553. mpData.each(function (idx) {
  33554. var itemModel = mpData.getItemModel(idx);
  33555. var symbolSize = itemModel.getShallow('symbolSize');
  33556. if (typeof symbolSize === 'function') {
  33557. // FIXME 这里不兼容 ECharts 2.x,2.x 貌似参数是整个数据?
  33558. symbolSize = symbolSize(
  33559. mpModel.getRawValue(idx), mpModel.getDataParams(idx)
  33560. );
  33561. }
  33562. mpData.setItemVisual(idx, {
  33563. symbolSize: symbolSize,
  33564. color: itemModel.get('itemStyle.normal.color')
  33565. || seriesData.getVisual('color'),
  33566. symbol: itemModel.getShallow('symbol')
  33567. });
  33568. });
  33569. // TODO Text are wrong
  33570. symbolDraw.updateData(mpData);
  33571. this.group.add(symbolDraw.group);
  33572. // Set host model for tooltip
  33573. // FIXME
  33574. mpData.eachItemGraphicEl(function (el) {
  33575. el.traverse(function (child) {
  33576. child.dataModel = mpModel;
  33577. });
  33578. });
  33579. symbolDraw.__keep = true;
  33580. symbolDraw.group.silent = mpModel.get('silent') || seriesModel.get('silent');
  33581. }
  33582. });
  33583. /**
  33584. * @inner
  33585. * @param {module:echarts/coord/*} [coordSys]
  33586. * @param {module:echarts/model/Series} seriesModel
  33587. * @param {module:echarts/model/Model} mpModel
  33588. */
  33589. function createList(coordSys, seriesModel, mpModel) {
  33590. var coordDimsInfos;
  33591. if (coordSys) {
  33592. coordDimsInfos = zrUtil.map(coordSys && coordSys.dimensions, function (coordDim) {
  33593. var info = seriesModel.getData().getDimensionInfo(
  33594. seriesModel.coordDimToDataDim(coordDim)[0]
  33595. ) || {}; // In map series data don't have lng and lat dimension. Fallback to same with coordSys
  33596. info.name = coordDim;
  33597. return info;
  33598. });
  33599. }
  33600. else {
  33601. coordDimsInfos =[{
  33602. name: 'value',
  33603. type: 'float'
  33604. }];
  33605. }
  33606. var mpData = new List(coordDimsInfos, mpModel);
  33607. var dataOpt = zrUtil.map(mpModel.get('data'), zrUtil.curry(
  33608. markerHelper.dataTransform, seriesModel
  33609. ));
  33610. if (coordSys) {
  33611. dataOpt = zrUtil.filter(
  33612. dataOpt, zrUtil.curry(markerHelper.dataFilter, coordSys)
  33613. );
  33614. }
  33615. mpData.initData(dataOpt, null,
  33616. coordSys ? markerHelper.dimValueGetter : function (item) {
  33617. return item.value;
  33618. }
  33619. );
  33620. return mpData;
  33621. }
  33622. /***/ },
  33623. /* 362 */
  33624. /***/ function(module, exports, __webpack_require__) {
  33625. var zrUtil = __webpack_require__(4);
  33626. var numberUtil = __webpack_require__(7);
  33627. var indexOf = zrUtil.indexOf;
  33628. function hasXOrY(item) {
  33629. return !(isNaN(parseFloat(item.x)) && isNaN(parseFloat(item.y)));
  33630. }
  33631. function hasXAndY(item) {
  33632. return !isNaN(parseFloat(item.x)) && !isNaN(parseFloat(item.y));
  33633. }
  33634. function getPrecision(data, valueAxisDim, dataIndex) {
  33635. var precision = -1;
  33636. do {
  33637. precision = Math.max(
  33638. numberUtil.getPrecision(data.get(
  33639. valueAxisDim, dataIndex
  33640. )),
  33641. precision
  33642. );
  33643. data = data.stackedOn;
  33644. } while (data);
  33645. return precision;
  33646. }
  33647. function markerTypeCalculatorWithExtent(
  33648. mlType, data, otherDataDim, targetDataDim, otherCoordIndex, targetCoordIndex
  33649. ) {
  33650. var coordArr = [];
  33651. var value = numCalculate(data, targetDataDim, mlType);
  33652. var dataIndex = data.indexOfNearest(targetDataDim, value, true);
  33653. coordArr[otherCoordIndex] = data.get(otherDataDim, dataIndex, true);
  33654. coordArr[targetCoordIndex] = data.get(targetDataDim, dataIndex, true);
  33655. var precision = getPrecision(data, targetDataDim, dataIndex);
  33656. if (precision >= 0) {
  33657. coordArr[targetCoordIndex] = +coordArr[targetCoordIndex].toFixed(precision);
  33658. }
  33659. return coordArr;
  33660. }
  33661. var curry = zrUtil.curry;
  33662. // TODO Specified percent
  33663. var markerTypeCalculator = {
  33664. /**
  33665. * @method
  33666. * @param {module:echarts/data/List} data
  33667. * @param {string} baseAxisDim
  33668. * @param {string} valueAxisDim
  33669. */
  33670. min: curry(markerTypeCalculatorWithExtent, 'min'),
  33671. /**
  33672. * @method
  33673. * @param {module:echarts/data/List} data
  33674. * @param {string} baseAxisDim
  33675. * @param {string} valueAxisDim
  33676. */
  33677. max: curry(markerTypeCalculatorWithExtent, 'max'),
  33678. /**
  33679. * @method
  33680. * @param {module:echarts/data/List} data
  33681. * @param {string} baseAxisDim
  33682. * @param {string} valueAxisDim
  33683. */
  33684. average: curry(markerTypeCalculatorWithExtent, 'average')
  33685. };
  33686. /**
  33687. * Transform markPoint data item to format used in List by do the following
  33688. * 1. Calculate statistic like `max`, `min`, `average`
  33689. * 2. Convert `item.xAxis`, `item.yAxis` to `item.coord` array
  33690. * @param {module:echarts/model/Series} seriesModel
  33691. * @param {module:echarts/coord/*} [coordSys]
  33692. * @param {Object} item
  33693. * @return {Object}
  33694. */
  33695. var dataTransform = function (seriesModel, item) {
  33696. var data = seriesModel.getData();
  33697. var coordSys = seriesModel.coordinateSystem;
  33698. // 1. If not specify the position with pixel directly
  33699. // 2. If `coord` is not a data array. Which uses `xAxis`,
  33700. // `yAxis` to specify the coord on each dimension
  33701. // parseFloat first because item.x and item.y can be percent string like '20%'
  33702. if (item && !hasXAndY(item) && !zrUtil.isArray(item.coord) && coordSys) {
  33703. var dims = coordSys.dimensions;
  33704. var axisInfo = getAxisInfo(item, data, coordSys, seriesModel);
  33705. // Clone the option
  33706. // Transform the properties xAxis, yAxis, radiusAxis, angleAxis, geoCoord to value
  33707. item = zrUtil.clone(item);
  33708. if (item.type
  33709. && markerTypeCalculator[item.type]
  33710. && axisInfo.baseAxis && axisInfo.valueAxis
  33711. ) {
  33712. var otherCoordIndex = indexOf(dims, axisInfo.baseAxis.dim);
  33713. var targetCoordIndex = indexOf(dims, axisInfo.valueAxis.dim);
  33714. item.coord = markerTypeCalculator[item.type](
  33715. data, axisInfo.baseDataDim, axisInfo.valueDataDim,
  33716. otherCoordIndex, targetCoordIndex
  33717. );
  33718. // Force to use the value of calculated value.
  33719. item.value = item.coord[targetCoordIndex];
  33720. }
  33721. else {
  33722. // FIXME Only has one of xAxis and yAxis.
  33723. var coord = [
  33724. item.xAxis != null ? item.xAxis : item.radiusAxis,
  33725. item.yAxis != null ? item.yAxis : item.angleAxis
  33726. ];
  33727. // Each coord support max, min, average
  33728. for (var i = 0; i < 2; i++) {
  33729. if (markerTypeCalculator[coord[i]]) {
  33730. var dataDim = seriesModel.coordDimToDataDim(dims[i])[0];
  33731. coord[i] = numCalculate(data, dataDim, coord[i]);
  33732. }
  33733. }
  33734. item.coord = coord;
  33735. }
  33736. }
  33737. return item;
  33738. };
  33739. var getAxisInfo = function (item, data, coordSys, seriesModel) {
  33740. var ret = {};
  33741. if (item.valueIndex != null || item.valueDim != null) {
  33742. ret.valueDataDim = item.valueIndex != null
  33743. ? data.getDimension(item.valueIndex) : item.valueDim;
  33744. ret.valueAxis = coordSys.getAxis(seriesModel.dataDimToCoordDim(ret.valueDataDim));
  33745. ret.baseAxis = coordSys.getOtherAxis(ret.valueAxis);
  33746. ret.baseDataDim = seriesModel.coordDimToDataDim(ret.baseAxis.dim)[0];
  33747. }
  33748. else {
  33749. ret.baseAxis = seriesModel.getBaseAxis();
  33750. ret.valueAxis = coordSys.getOtherAxis(ret.baseAxis);
  33751. ret.baseDataDim = seriesModel.coordDimToDataDim(ret.baseAxis.dim)[0];
  33752. ret.valueDataDim = seriesModel.coordDimToDataDim(ret.valueAxis.dim)[0];
  33753. }
  33754. return ret;
  33755. };
  33756. /**
  33757. * Filter data which is out of coordinateSystem range
  33758. * [dataFilter description]
  33759. * @param {module:echarts/coord/*} [coordSys]
  33760. * @param {Object} item
  33761. * @return {boolean}
  33762. */
  33763. var dataFilter = function (coordSys, item) {
  33764. // Alwalys return true if there is no coordSys
  33765. return (coordSys && coordSys.containData && item.coord && !hasXOrY(item))
  33766. ? coordSys.containData(item.coord) : true;
  33767. };
  33768. var dimValueGetter = function (item, dimName, dataIndex, dimIndex) {
  33769. // x, y, radius, angle
  33770. if (dimIndex < 2) {
  33771. return item.coord && item.coord[dimIndex];
  33772. }
  33773. return item.value;
  33774. };
  33775. var numCalculate = function (data, valueDataDim, type) {
  33776. if (type === 'average') {
  33777. var sum = 0;
  33778. var count = 0;
  33779. data.each(valueDataDim, function (val, idx) {
  33780. if (!isNaN(val)) {
  33781. sum += val;
  33782. count++;
  33783. }
  33784. }, true);
  33785. return sum / count;
  33786. }
  33787. else {
  33788. return data.getDataExtent(valueDataDim, true)[type === 'max' ? 1 : 0];
  33789. }
  33790. };
  33791. module.exports = {
  33792. dataTransform: dataTransform,
  33793. dataFilter: dataFilter,
  33794. dimValueGetter: dimValueGetter,
  33795. getAxisInfo: getAxisInfo,
  33796. numCalculate: numCalculate
  33797. };
  33798. /***/ },
  33799. /* 363 */
  33800. /***/ function(module, exports, __webpack_require__) {
  33801. module.exports = __webpack_require__(1).extendComponentView({
  33802. type: 'marker',
  33803. init: function () {
  33804. /**
  33805. * Markline grouped by series
  33806. * @private
  33807. * @type {Object}
  33808. */
  33809. this.markerGroupMap = {};
  33810. },
  33811. render: function (markerModel, ecModel, api) {
  33812. var markerGroupMap = this.markerGroupMap;
  33813. for (var name in markerGroupMap) {
  33814. if (markerGroupMap.hasOwnProperty(name)) {
  33815. markerGroupMap[name].__keep = false;
  33816. }
  33817. }
  33818. var markerModelKey = this.type + 'Model';
  33819. ecModel.eachSeries(function (seriesModel) {
  33820. var markerModel = seriesModel[markerModelKey];
  33821. markerModel && this.renderSeries(seriesModel, markerModel, ecModel, api);
  33822. }, this);
  33823. for (var name in markerGroupMap) {
  33824. if (markerGroupMap.hasOwnProperty(name) && !markerGroupMap[name].__keep) {
  33825. this.group.remove(markerGroupMap[name].group);
  33826. }
  33827. }
  33828. },
  33829. renderSeries: function () {}
  33830. });
  33831. /***/ },
  33832. /* 364 */
  33833. /***/ function(module, exports, __webpack_require__) {
  33834. __webpack_require__(365);
  33835. __webpack_require__(366);
  33836. __webpack_require__(1).registerPreprocessor(function (opt) {
  33837. // Make sure markLine component is enabled
  33838. opt.markLine = opt.markLine || {};
  33839. });
  33840. /***/ },
  33841. /* 365 */
  33842. /***/ function(module, exports, __webpack_require__) {
  33843. module.exports = __webpack_require__(360).extend({
  33844. type: 'markLine',
  33845. defaultOption: {
  33846. zlevel: 0,
  33847. z: 5,
  33848. symbol: ['circle', 'arrow'],
  33849. symbolSize: [8, 16],
  33850. //symbolRotate: 0,
  33851. precision: 2,
  33852. tooltip: {
  33853. trigger: 'item'
  33854. },
  33855. label: {
  33856. normal: {
  33857. show: true,
  33858. position: 'end'
  33859. },
  33860. emphasis: {
  33861. show: true
  33862. }
  33863. },
  33864. lineStyle: {
  33865. normal: {
  33866. type: 'dashed'
  33867. },
  33868. emphasis: {
  33869. width: 3
  33870. }
  33871. },
  33872. animationEasing: 'linear'
  33873. }
  33874. });
  33875. /***/ },
  33876. /* 366 */
  33877. /***/ function(module, exports, __webpack_require__) {
  33878. var zrUtil = __webpack_require__(4);
  33879. var List = __webpack_require__(98);
  33880. var numberUtil = __webpack_require__(7);
  33881. var markerHelper = __webpack_require__(362);
  33882. var LineDraw = __webpack_require__(202);
  33883. var markLineTransform = function (seriesModel, coordSys, mlModel, item) {
  33884. var data = seriesModel.getData();
  33885. // Special type markLine like 'min', 'max', 'average'
  33886. var mlType = item.type;
  33887. if (!zrUtil.isArray(item)
  33888. && (
  33889. mlType === 'min' || mlType === 'max' || mlType === 'average'
  33890. // In case
  33891. // data: [{
  33892. // yAxis: 10
  33893. // }]
  33894. || (item.xAxis != null || item.yAxis != null)
  33895. )
  33896. ) {
  33897. var valueAxis;
  33898. var valueDataDim;
  33899. var value;
  33900. if (item.yAxis != null || item.xAxis != null) {
  33901. valueDataDim = item.yAxis != null ? 'y' : 'x';
  33902. valueAxis = coordSys.getAxis(valueDataDim);
  33903. value = zrUtil.retrieve(item.yAxis, item.xAxis);
  33904. }
  33905. else {
  33906. var axisInfo = markerHelper.getAxisInfo(item, data, coordSys, seriesModel);
  33907. valueDataDim = axisInfo.valueDataDim;
  33908. valueAxis = axisInfo.valueAxis;
  33909. value = markerHelper.numCalculate(data, valueDataDim, mlType);
  33910. }
  33911. var valueIndex = valueDataDim === 'x' ? 0 : 1;
  33912. var baseIndex = 1 - valueIndex;
  33913. var mlFrom = zrUtil.clone(item);
  33914. var mlTo = {};
  33915. mlFrom.type = null;
  33916. mlFrom.coord = [];
  33917. mlTo.coord = [];
  33918. mlFrom.coord[baseIndex] = -Infinity;
  33919. mlTo.coord[baseIndex] = Infinity;
  33920. var precision = mlModel.get('precision');
  33921. if (precision >= 0 && typeof value === 'number') {
  33922. value = +value.toFixed(precision);
  33923. }
  33924. mlFrom.coord[valueIndex] = mlTo.coord[valueIndex] = value;
  33925. item = [mlFrom, mlTo, { // Extra option for tooltip and label
  33926. type: mlType,
  33927. valueIndex: item.valueIndex,
  33928. // Force to use the value of calculated value.
  33929. value: value
  33930. }];
  33931. }
  33932. item = [
  33933. markerHelper.dataTransform(seriesModel, item[0]),
  33934. markerHelper.dataTransform(seriesModel, item[1]),
  33935. zrUtil.extend({}, item[2])
  33936. ];
  33937. // Avoid line data type is extended by from(to) data type
  33938. item[2].type = item[2].type || '';
  33939. // Merge from option and to option into line option
  33940. zrUtil.merge(item[2], item[0]);
  33941. zrUtil.merge(item[2], item[1]);
  33942. return item;
  33943. };
  33944. function isInifinity(val) {
  33945. return !isNaN(val) && !isFinite(val);
  33946. }
  33947. // If a markLine has one dim
  33948. function ifMarkLineHasOnlyDim(dimIndex, fromCoord, toCoord, coordSys) {
  33949. var otherDimIndex = 1 - dimIndex;
  33950. var dimName = coordSys.dimensions[dimIndex];
  33951. return isInifinity(fromCoord[otherDimIndex]) && isInifinity(toCoord[otherDimIndex])
  33952. && fromCoord[dimIndex] === toCoord[dimIndex] && coordSys.getAxis(dimName).containData(fromCoord[dimIndex]);
  33953. }
  33954. function markLineFilter(coordSys, item) {
  33955. if (coordSys.type === 'cartesian2d') {
  33956. var fromCoord = item[0].coord;
  33957. var toCoord = item[1].coord;
  33958. // In case
  33959. // {
  33960. // markLine: {
  33961. // data: [{ yAxis: 2 }]
  33962. // }
  33963. // }
  33964. if (
  33965. fromCoord && toCoord &&
  33966. (ifMarkLineHasOnlyDim(1, fromCoord, toCoord, coordSys)
  33967. || ifMarkLineHasOnlyDim(0, fromCoord, toCoord, coordSys))
  33968. ) {
  33969. return true;
  33970. }
  33971. }
  33972. return markerHelper.dataFilter(coordSys, item[0])
  33973. && markerHelper.dataFilter(coordSys, item[1]);
  33974. }
  33975. function updateSingleMarkerEndLayout(
  33976. data, idx, isFrom, seriesModel, api
  33977. ) {
  33978. var coordSys = seriesModel.coordinateSystem;
  33979. var itemModel = data.getItemModel(idx);
  33980. var point;
  33981. var xPx = numberUtil.parsePercent(itemModel.get('x'), api.getWidth());
  33982. var yPx = numberUtil.parsePercent(itemModel.get('y'), api.getHeight());
  33983. if (!isNaN(xPx) && !isNaN(yPx)) {
  33984. point = [xPx, yPx];
  33985. }
  33986. else {
  33987. // Chart like bar may have there own marker positioning logic
  33988. if (seriesModel.getMarkerPosition) {
  33989. // Use the getMarkerPoisition
  33990. point = seriesModel.getMarkerPosition(
  33991. data.getValues(data.dimensions, idx)
  33992. );
  33993. }
  33994. else {
  33995. var dims = coordSys.dimensions;
  33996. var x = data.get(dims[0], idx);
  33997. var y = data.get(dims[1], idx);
  33998. point = coordSys.dataToPoint([x, y]);
  33999. }
  34000. // Expand line to the edge of grid if value on one axis is Inifnity
  34001. // In case
  34002. // markLine: {
  34003. // data: [{
  34004. // yAxis: 2
  34005. // // or
  34006. // type: 'average'
  34007. // }]
  34008. // }
  34009. if (coordSys.type === 'cartesian2d') {
  34010. var xAxis = coordSys.getAxis('x');
  34011. var yAxis = coordSys.getAxis('y');
  34012. var dims = coordSys.dimensions;
  34013. if (isInifinity(data.get(dims[0], idx))) {
  34014. point[0] = xAxis.toGlobalCoord(xAxis.getExtent()[isFrom ? 0 : 1]);
  34015. }
  34016. else if (isInifinity(data.get(dims[1], idx))) {
  34017. point[1] = yAxis.toGlobalCoord(yAxis.getExtent()[isFrom ? 0 : 1]);
  34018. }
  34019. }
  34020. // Use x, y if has any
  34021. if (!isNaN(xPx)) {
  34022. point[0] = xPx;
  34023. }
  34024. if (!isNaN(yPx)) {
  34025. point[1] = yPx;
  34026. }
  34027. }
  34028. data.setItemLayout(idx, point);
  34029. }
  34030. __webpack_require__(363).extend({
  34031. type: 'markLine',
  34032. updateLayout: function (markLineModel, ecModel, api) {
  34033. ecModel.eachSeries(function (seriesModel) {
  34034. var mlModel = seriesModel.markLineModel;
  34035. if (mlModel) {
  34036. var mlData = mlModel.getData();
  34037. var fromData = mlModel.__from;
  34038. var toData = mlModel.__to;
  34039. // Update visual and layout of from symbol and to symbol
  34040. fromData.each(function (idx) {
  34041. updateSingleMarkerEndLayout(fromData, idx, true, seriesModel, api);
  34042. updateSingleMarkerEndLayout(toData, idx, false, seriesModel, api);
  34043. });
  34044. // Update layout of line
  34045. mlData.each(function (idx) {
  34046. mlData.setItemLayout(idx, [
  34047. fromData.getItemLayout(idx),
  34048. toData.getItemLayout(idx)
  34049. ]);
  34050. });
  34051. this.markerGroupMap[seriesModel.name].updateLayout();
  34052. }
  34053. }, this);
  34054. },
  34055. renderSeries: function (seriesModel, mlModel, ecModel, api) {
  34056. var coordSys = seriesModel.coordinateSystem;
  34057. var seriesName = seriesModel.name;
  34058. var seriesData = seriesModel.getData();
  34059. var lineDrawMap = this.markerGroupMap;
  34060. var lineDraw = lineDrawMap[seriesName];
  34061. if (!lineDraw) {
  34062. lineDraw = lineDrawMap[seriesName] = new LineDraw();
  34063. }
  34064. this.group.add(lineDraw.group);
  34065. var mlData = createList(coordSys, seriesModel, mlModel);
  34066. var fromData = mlData.from;
  34067. var toData = mlData.to;
  34068. var lineData = mlData.line;
  34069. mlModel.__from = fromData;
  34070. mlModel.__to = toData;
  34071. // Line data for tooltip and formatter
  34072. mlModel.setData(lineData);
  34073. var symbolType = mlModel.get('symbol');
  34074. var symbolSize = mlModel.get('symbolSize');
  34075. if (!zrUtil.isArray(symbolType)) {
  34076. symbolType = [symbolType, symbolType];
  34077. }
  34078. if (typeof symbolSize === 'number') {
  34079. symbolSize = [symbolSize, symbolSize];
  34080. }
  34081. // Update visual and layout of from symbol and to symbol
  34082. mlData.from.each(function (idx) {
  34083. updateDataVisualAndLayout(fromData, idx, true);
  34084. updateDataVisualAndLayout(toData, idx, false);
  34085. });
  34086. // Update visual and layout of line
  34087. lineData.each(function (idx) {
  34088. var lineColor = lineData.getItemModel(idx).get('lineStyle.normal.color');
  34089. lineData.setItemVisual(idx, {
  34090. color: lineColor || fromData.getItemVisual(idx, 'color')
  34091. });
  34092. lineData.setItemLayout(idx, [
  34093. fromData.getItemLayout(idx),
  34094. toData.getItemLayout(idx)
  34095. ]);
  34096. lineData.setItemVisual(idx, {
  34097. 'fromSymbolSize': fromData.getItemVisual(idx, 'symbolSize'),
  34098. 'fromSymbol': fromData.getItemVisual(idx, 'symbol'),
  34099. 'toSymbolSize': toData.getItemVisual(idx, 'symbolSize'),
  34100. 'toSymbol': toData.getItemVisual(idx, 'symbol')
  34101. });
  34102. });
  34103. lineDraw.updateData(lineData);
  34104. // Set host model for tooltip
  34105. // FIXME
  34106. mlData.line.eachItemGraphicEl(function (el, idx) {
  34107. el.traverse(function (child) {
  34108. child.dataModel = mlModel;
  34109. });
  34110. });
  34111. function updateDataVisualAndLayout(data, idx, isFrom) {
  34112. var itemModel = data.getItemModel(idx);
  34113. updateSingleMarkerEndLayout(
  34114. data, idx, isFrom, seriesModel, api
  34115. );
  34116. data.setItemVisual(idx, {
  34117. symbolSize: itemModel.get('symbolSize') || symbolSize[isFrom ? 0 : 1],
  34118. symbol: itemModel.get('symbol', true) || symbolType[isFrom ? 0 : 1],
  34119. color: itemModel.get('itemStyle.normal.color') || seriesData.getVisual('color')
  34120. });
  34121. }
  34122. lineDraw.__keep = true;
  34123. lineDraw.group.silent = mlModel.get('silent') || seriesModel.get('silent');
  34124. }
  34125. });
  34126. /**
  34127. * @inner
  34128. * @param {module:echarts/coord/*} coordSys
  34129. * @param {module:echarts/model/Series} seriesModel
  34130. * @param {module:echarts/model/Model} mpModel
  34131. */
  34132. function createList(coordSys, seriesModel, mlModel) {
  34133. var coordDimsInfos;
  34134. if (coordSys) {
  34135. coordDimsInfos = zrUtil.map(coordSys && coordSys.dimensions, function (coordDim) {
  34136. var info = seriesModel.getData().getDimensionInfo(
  34137. seriesModel.coordDimToDataDim(coordDim)[0]
  34138. ) || {}; // In map series data don't have lng and lat dimension. Fallback to same with coordSys
  34139. info.name = coordDim;
  34140. return info;
  34141. });
  34142. }
  34143. else {
  34144. coordDimsInfos =[{
  34145. name: 'value',
  34146. type: 'float'
  34147. }];
  34148. }
  34149. var fromData = new List(coordDimsInfos, mlModel);
  34150. var toData = new List(coordDimsInfos, mlModel);
  34151. // No dimensions
  34152. var lineData = new List([], mlModel);
  34153. var optData = zrUtil.map(mlModel.get('data'), zrUtil.curry(
  34154. markLineTransform, seriesModel, coordSys, mlModel
  34155. ));
  34156. if (coordSys) {
  34157. optData = zrUtil.filter(
  34158. optData, zrUtil.curry(markLineFilter, coordSys)
  34159. );
  34160. }
  34161. var dimValueGetter = coordSys ? markerHelper.dimValueGetter : function (item) {
  34162. return item.value;
  34163. };
  34164. fromData.initData(
  34165. zrUtil.map(optData, function (item) { return item[0]; }),
  34166. null, dimValueGetter
  34167. );
  34168. toData.initData(
  34169. zrUtil.map(optData, function (item) { return item[1]; }),
  34170. null, dimValueGetter
  34171. );
  34172. lineData.initData(
  34173. zrUtil.map(optData, function (item) { return item[2]; })
  34174. );
  34175. lineData.hasItemOption = true;
  34176. return {
  34177. from: fromData,
  34178. to: toData,
  34179. line: lineData
  34180. };
  34181. }
  34182. /***/ },
  34183. /* 367 */
  34184. /***/ function(module, exports, __webpack_require__) {
  34185. __webpack_require__(368);
  34186. __webpack_require__(369);
  34187. __webpack_require__(1).registerPreprocessor(function (opt) {
  34188. // Make sure markArea component is enabled
  34189. opt.markArea = opt.markArea || {};
  34190. });
  34191. /***/ },
  34192. /* 368 */
  34193. /***/ function(module, exports, __webpack_require__) {
  34194. module.exports = __webpack_require__(360).extend({
  34195. type: 'markArea',
  34196. defaultOption: {
  34197. zlevel: 0,
  34198. // PENDING
  34199. z: 1,
  34200. tooltip: {
  34201. trigger: 'item'
  34202. },
  34203. // markArea should fixed on the coordinate system
  34204. animation: false,
  34205. label: {
  34206. normal: {
  34207. show: true,
  34208. position: 'top'
  34209. },
  34210. emphasis: {
  34211. show: true,
  34212. position: 'top'
  34213. }
  34214. },
  34215. itemStyle: {
  34216. normal: {
  34217. // color and borderColor default to use color from series
  34218. // color: 'auto'
  34219. // borderColor: 'auto'
  34220. borderWidth: 0
  34221. }
  34222. }
  34223. }
  34224. });
  34225. /***/ },
  34226. /* 369 */
  34227. /***/ function(module, exports, __webpack_require__) {
  34228. // TODO Better on polar
  34229. var zrUtil = __webpack_require__(4);
  34230. var List = __webpack_require__(98);
  34231. var numberUtil = __webpack_require__(7);
  34232. var graphic = __webpack_require__(43);
  34233. var colorUtil = __webpack_require__(39);
  34234. var markerHelper = __webpack_require__(362);
  34235. var markAreaTransform = function (seriesModel, coordSys, maModel, item) {
  34236. var lt = markerHelper.dataTransform(seriesModel, item[0]);
  34237. var rb = markerHelper.dataTransform(seriesModel, item[1]);
  34238. var retrieve = zrUtil.retrieve;
  34239. // FIXME make sure lt is less than rb
  34240. var ltCoord = lt.coord;
  34241. var rbCoord = rb.coord;
  34242. ltCoord[0] = retrieve(ltCoord[0], -Infinity);
  34243. ltCoord[1] = retrieve(ltCoord[1], -Infinity);
  34244. rbCoord[0] = retrieve(rbCoord[0], Infinity);
  34245. rbCoord[1] = retrieve(rbCoord[1], Infinity);
  34246. // Merge option into one
  34247. var result = zrUtil.mergeAll([{}, lt, rb]);
  34248. result.coord = [
  34249. lt.coord, rb.coord
  34250. ];
  34251. result.x0 = lt.x;
  34252. result.y0 = lt.y;
  34253. result.x1 = rb.x;
  34254. result.y1 = rb.y;
  34255. return result;
  34256. };
  34257. function isInifinity(val) {
  34258. return !isNaN(val) && !isFinite(val);
  34259. }
  34260. // If a markArea has one dim
  34261. function ifMarkLineHasOnlyDim(dimIndex, fromCoord, toCoord, coordSys) {
  34262. var otherDimIndex = 1 - dimIndex;
  34263. return isInifinity(fromCoord[otherDimIndex]) && isInifinity(toCoord[otherDimIndex]);
  34264. }
  34265. function markAreaFilter(coordSys, item) {
  34266. var fromCoord = item.coord[0];
  34267. var toCoord = item.coord[1];
  34268. if (coordSys.type === 'cartesian2d') {
  34269. // In case
  34270. // {
  34271. // markArea: {
  34272. // data: [{ yAxis: 2 }]
  34273. // }
  34274. // }
  34275. if (
  34276. fromCoord && toCoord &&
  34277. (ifMarkLineHasOnlyDim(1, fromCoord, toCoord, coordSys)
  34278. || ifMarkLineHasOnlyDim(0, fromCoord, toCoord, coordSys))
  34279. ) {
  34280. return true;
  34281. }
  34282. }
  34283. return markerHelper.dataFilter(coordSys, {
  34284. coord: fromCoord,
  34285. x: item.x0,
  34286. y: item.y0
  34287. })
  34288. || markerHelper.dataFilter(coordSys, {
  34289. coord: toCoord,
  34290. x: item.x1,
  34291. y: item.y1
  34292. });
  34293. }
  34294. // dims can be ['x0', 'y0'], ['x1', 'y1'], ['x0', 'y1'], ['x1', 'y0']
  34295. function getSingleMarkerEndPoint(data, idx, dims, seriesModel, api) {
  34296. var coordSys = seriesModel.coordinateSystem;
  34297. var itemModel = data.getItemModel(idx);
  34298. var point;
  34299. var xPx = numberUtil.parsePercent(itemModel.get(dims[0]), api.getWidth());
  34300. var yPx = numberUtil.parsePercent(itemModel.get(dims[1]), api.getHeight());
  34301. if (!isNaN(xPx) && !isNaN(yPx)) {
  34302. point = [xPx, yPx];
  34303. }
  34304. else {
  34305. // Chart like bar may have there own marker positioning logic
  34306. if (seriesModel.getMarkerPosition) {
  34307. // Use the getMarkerPoisition
  34308. point = seriesModel.getMarkerPosition(
  34309. data.getValues(dims, idx)
  34310. );
  34311. }
  34312. else {
  34313. var x = data.get(dims[0], idx);
  34314. var y = data.get(dims[1], idx);
  34315. point = coordSys.dataToPoint([x, y], true);
  34316. }
  34317. if (coordSys.type === 'cartesian2d') {
  34318. var xAxis = coordSys.getAxis('x');
  34319. var yAxis = coordSys.getAxis('y');
  34320. var x = data.get(dims[0], idx);
  34321. var y = data.get(dims[1], idx);
  34322. if (isInifinity(x)) {
  34323. point[0] = xAxis.toGlobalCoord(xAxis.getExtent()[dims[0] === 'x0' ? 0 : 1]);
  34324. }
  34325. else if (isInifinity(y)) {
  34326. point[1] = yAxis.toGlobalCoord(yAxis.getExtent()[dims[1] === 'y0' ? 0 : 1]);
  34327. }
  34328. }
  34329. // Use x, y if has any
  34330. if (!isNaN(xPx)) {
  34331. point[0] = xPx;
  34332. }
  34333. if (!isNaN(yPx)) {
  34334. point[1] = yPx;
  34335. }
  34336. }
  34337. return point;
  34338. }
  34339. var dimPermutations = [['x0', 'y0'], ['x1', 'y0'], ['x1', 'y1'], ['x0', 'y1']];
  34340. __webpack_require__(363).extend({
  34341. type: 'markArea',
  34342. updateLayout: function (markAreaModel, ecModel, api) {
  34343. ecModel.eachSeries(function (seriesModel) {
  34344. var maModel = seriesModel.markAreaModel;
  34345. if (maModel) {
  34346. var areaData = maModel.getData();
  34347. areaData.each(function (idx) {
  34348. var points = zrUtil.map(dimPermutations, function (dim) {
  34349. return getSingleMarkerEndPoint(areaData, idx, dim, seriesModel, api);
  34350. });
  34351. // Layout
  34352. areaData.setItemLayout(idx, points);
  34353. var el = areaData.getItemGraphicEl(idx);
  34354. el.setShape('points', points);
  34355. });
  34356. }
  34357. }, this);
  34358. },
  34359. renderSeries: function (seriesModel, maModel, ecModel, api) {
  34360. var coordSys = seriesModel.coordinateSystem;
  34361. var seriesName = seriesModel.name;
  34362. var seriesData = seriesModel.getData();
  34363. var areaGroupMap = this.markerGroupMap;
  34364. var polygonGroup = areaGroupMap[seriesName];
  34365. if (!polygonGroup) {
  34366. polygonGroup = areaGroupMap[seriesName] = {
  34367. group: new graphic.Group()
  34368. };
  34369. }
  34370. this.group.add(polygonGroup.group);
  34371. polygonGroup.__keep = true;
  34372. var areaData = createList(coordSys, seriesModel, maModel);
  34373. // Line data for tooltip and formatter
  34374. maModel.setData(areaData);
  34375. // Update visual and layout of line
  34376. areaData.each(function (idx) {
  34377. // Layout
  34378. areaData.setItemLayout(idx, zrUtil.map(dimPermutations, function (dim) {
  34379. return getSingleMarkerEndPoint(areaData, idx, dim, seriesModel, api);
  34380. }));
  34381. // Visual
  34382. areaData.setItemVisual(idx, {
  34383. color: seriesData.getVisual('color')
  34384. });
  34385. });
  34386. areaData.diff(polygonGroup.__data)
  34387. .add(function (idx) {
  34388. var polygon = new graphic.Polygon({
  34389. shape: {
  34390. points: areaData.getItemLayout(idx)
  34391. }
  34392. });
  34393. areaData.setItemGraphicEl(idx, polygon);
  34394. polygonGroup.group.add(polygon);
  34395. })
  34396. .update(function (newIdx, oldIdx) {
  34397. var polygon = polygonGroup.__data.getItemGraphicEl(oldIdx);
  34398. graphic.updateProps(polygon, {
  34399. shape: {
  34400. points: areaData.getItemLayout(newIdx)
  34401. }
  34402. }, maModel, newIdx);
  34403. polygonGroup.group.add(polygon);
  34404. areaData.setItemGraphicEl(newIdx, polygon);
  34405. })
  34406. .remove(function (idx) {
  34407. var polygon = polygonGroup.__data.getItemGraphicEl(idx);
  34408. polygonGroup.group.remove(polygon);
  34409. })
  34410. .execute();
  34411. areaData.eachItemGraphicEl(function (polygon, idx) {
  34412. var itemModel = areaData.getItemModel(idx);
  34413. var labelModel = itemModel.getModel('label.normal');
  34414. var labelHoverModel = itemModel.getModel('label.emphasis');
  34415. var color = areaData.getItemVisual(idx, 'color');
  34416. polygon.useStyle(
  34417. zrUtil.defaults(
  34418. itemModel.getModel('itemStyle.normal').getItemStyle(),
  34419. {
  34420. fill: colorUtil.modifyAlpha(color, 0.4),
  34421. stroke: color
  34422. }
  34423. )
  34424. );
  34425. polygon.hoverStyle = itemModel.getModel('itemStyle.normal').getItemStyle();
  34426. var defaultValue = areaData.getName(idx) || '';
  34427. var textColor = color || polygon.style.fill;
  34428. if (labelModel.getShallow('show')) {
  34429. graphic.setText(polygon.style, labelModel, textColor);
  34430. polygon.style.text = zrUtil.retrieve(
  34431. maModel.getFormattedLabel(idx, 'normal'),
  34432. defaultValue
  34433. );
  34434. }
  34435. else {
  34436. polygon.style.text = '';
  34437. }
  34438. if (labelHoverModel.getShallow('show')) {
  34439. graphic.setText(polygon.hoverStyle, labelHoverModel, textColor);
  34440. polygon.hoverStyle.text = zrUtil.retrieve(
  34441. maModel.getFormattedLabel(idx, 'emphasis'),
  34442. defaultValue
  34443. );
  34444. }
  34445. else {
  34446. polygon.hoverStyle.text = '';
  34447. }
  34448. graphic.setHoverStyle(polygon, {});
  34449. polygon.dataModel = maModel;
  34450. });
  34451. polygonGroup.__data = areaData;
  34452. polygonGroup.group.silent = maModel.get('silent') || seriesModel.get('silent');
  34453. }
  34454. });
  34455. /**
  34456. * @inner
  34457. * @param {module:echarts/coord/*} coordSys
  34458. * @param {module:echarts/model/Series} seriesModel
  34459. * @param {module:echarts/model/Model} mpModel
  34460. */
  34461. function createList(coordSys, seriesModel, maModel) {
  34462. var coordDimsInfos;
  34463. var areaData;
  34464. var dims = ['x0', 'y0', 'x1', 'y1'];
  34465. if (coordSys) {
  34466. coordDimsInfos = zrUtil.map(coordSys && coordSys.dimensions, function (coordDim) {
  34467. var info = seriesModel.getData().getDimensionInfo(
  34468. seriesModel.coordDimToDataDim(coordDim)[0]
  34469. ) || {}; // In map series data don't have lng and lat dimension. Fallback to same with coordSys
  34470. info.name = coordDim;
  34471. return info;
  34472. });
  34473. areaData = new List(zrUtil.map(dims, function (dim, idx) {
  34474. return {
  34475. name: dim,
  34476. type: coordDimsInfos[idx % 2].type
  34477. };
  34478. }), maModel);
  34479. }
  34480. else {
  34481. coordDimsInfos =[{
  34482. name: 'value',
  34483. type: 'float'
  34484. }];
  34485. areaData = new List(coordDimsInfos, maModel);
  34486. }
  34487. var optData = zrUtil.map(maModel.get('data'), zrUtil.curry(
  34488. markAreaTransform, seriesModel, coordSys, maModel
  34489. ));
  34490. if (coordSys) {
  34491. optData = zrUtil.filter(
  34492. optData, zrUtil.curry(markAreaFilter, coordSys)
  34493. );
  34494. }
  34495. var dimValueGetter = coordSys ? function (item, dimName, dataIndex, dimIndex) {
  34496. return item.coord[Math.floor(dimIndex / 2)][dimIndex % 2];
  34497. } : function (item) {
  34498. return item.value;
  34499. };
  34500. areaData.initData(optData, null, dimValueGetter);
  34501. areaData.hasItemOption = true;
  34502. return areaData;
  34503. }
  34504. /***/ },
  34505. /* 370 */,
  34506. /* 371 */,
  34507. /* 372 */,
  34508. /* 373 */,
  34509. /* 374 */,
  34510. /* 375 */,
  34511. /* 376 */,
  34512. /* 377 */,
  34513. /* 378 */,
  34514. /* 379 */
  34515. /***/ function(module, exports, __webpack_require__) {
  34516. __webpack_require__(380);
  34517. __webpack_require__(381);
  34518. __webpack_require__(382);
  34519. __webpack_require__(383);
  34520. __webpack_require__(384);
  34521. __webpack_require__(385);
  34522. __webpack_require__(390);
  34523. /***/ },
  34524. /* 380 */
  34525. /***/ function(module, exports, __webpack_require__) {
  34526. var featureManager = __webpack_require__(327);
  34527. var zrUtil = __webpack_require__(4);
  34528. var ToolboxModel = __webpack_require__(1).extendComponentModel({
  34529. type: 'toolbox',
  34530. layoutMode: {
  34531. type: 'box',
  34532. ignoreSize: true
  34533. },
  34534. mergeDefaultAndTheme: function (option) {
  34535. ToolboxModel.superApply(this, 'mergeDefaultAndTheme', arguments);
  34536. zrUtil.each(this.option.feature, function (featureOpt, featureName) {
  34537. var Feature = featureManager.get(featureName);
  34538. Feature && zrUtil.merge(featureOpt, Feature.defaultOption);
  34539. });
  34540. },
  34541. defaultOption: {
  34542. show: true,
  34543. z: 6,
  34544. zlevel: 0,
  34545. orient: 'horizontal',
  34546. left: 'right',
  34547. top: 'top',
  34548. // right
  34549. // bottom
  34550. backgroundColor: 'transparent',
  34551. borderColor: '#ccc',
  34552. borderWidth: 0,
  34553. padding: 5,
  34554. itemSize: 15,
  34555. itemGap: 8,
  34556. showTitle: true,
  34557. iconStyle: {
  34558. normal: {
  34559. borderColor: '#666',
  34560. color: 'none'
  34561. },
  34562. emphasis: {
  34563. borderColor: '#3E98C5'
  34564. }
  34565. }
  34566. // textStyle: {},
  34567. // feature
  34568. }
  34569. });
  34570. module.exports = ToolboxModel;
  34571. /***/ },
  34572. /* 381 */
  34573. /***/ function(module, exports, __webpack_require__) {
  34574. /* WEBPACK VAR INJECTION */(function(process) {
  34575. var featureManager = __webpack_require__(327);
  34576. var zrUtil = __webpack_require__(4);
  34577. var graphic = __webpack_require__(43);
  34578. var Model = __webpack_require__(12);
  34579. var DataDiffer = __webpack_require__(99);
  34580. var listComponentHelper = __webpack_require__(297);
  34581. var textContain = __webpack_require__(8);
  34582. module.exports = __webpack_require__(1).extendComponentView({
  34583. type: 'toolbox',
  34584. render: function (toolboxModel, ecModel, api, payload) {
  34585. var group = this.group;
  34586. group.removeAll();
  34587. if (!toolboxModel.get('show')) {
  34588. return;
  34589. }
  34590. var itemSize = +toolboxModel.get('itemSize');
  34591. var featureOpts = toolboxModel.get('feature') || {};
  34592. var features = this._features || (this._features = {});
  34593. var featureNames = [];
  34594. zrUtil.each(featureOpts, function (opt, name) {
  34595. featureNames.push(name);
  34596. });
  34597. (new DataDiffer(this._featureNames || [], featureNames))
  34598. .add(process)
  34599. .update(process)
  34600. .remove(zrUtil.curry(process, null))
  34601. .execute();
  34602. // Keep for diff.
  34603. this._featureNames = featureNames;
  34604. function process(newIndex, oldIndex) {
  34605. var featureName = featureNames[newIndex];
  34606. var oldName = featureNames[oldIndex];
  34607. var featureOpt = featureOpts[featureName];
  34608. var featureModel = new Model(featureOpt, toolboxModel, toolboxModel.ecModel);
  34609. var feature;
  34610. if (featureName && !oldName) { // Create
  34611. if (isUserFeatureName(featureName)) {
  34612. feature = {
  34613. model: featureModel,
  34614. onclick: featureModel.option.onclick,
  34615. featureName: featureName
  34616. };
  34617. }
  34618. else {
  34619. var Feature = featureManager.get(featureName);
  34620. if (!Feature) {
  34621. return;
  34622. }
  34623. feature = new Feature(featureModel, ecModel, api);
  34624. }
  34625. features[featureName] = feature;
  34626. }
  34627. else {
  34628. feature = features[oldName];
  34629. // If feature does not exsit.
  34630. if (!feature) {
  34631. return;
  34632. }
  34633. feature.model = featureModel;
  34634. feature.ecModel = ecModel;
  34635. feature.api = api;
  34636. }
  34637. if (!featureName && oldName) {
  34638. feature.dispose && feature.dispose(ecModel, api);
  34639. return;
  34640. }
  34641. if (!featureModel.get('show') || feature.unusable) {
  34642. feature.remove && feature.remove(ecModel, api);
  34643. return;
  34644. }
  34645. createIconPaths(featureModel, feature, featureName);
  34646. featureModel.setIconStatus = function (iconName, status) {
  34647. var option = this.option;
  34648. var iconPaths = this.iconPaths;
  34649. option.iconStatus = option.iconStatus || {};
  34650. option.iconStatus[iconName] = status;
  34651. // FIXME
  34652. iconPaths[iconName] && iconPaths[iconName].trigger(status);
  34653. };
  34654. if (feature.render) {
  34655. feature.render(featureModel, ecModel, api, payload);
  34656. }
  34657. }
  34658. function createIconPaths(featureModel, feature, featureName) {
  34659. var iconStyleModel = featureModel.getModel('iconStyle');
  34660. // If one feature has mutiple icon. they are orginaized as
  34661. // {
  34662. // icon: {
  34663. // foo: '',
  34664. // bar: ''
  34665. // },
  34666. // title: {
  34667. // foo: '',
  34668. // bar: ''
  34669. // }
  34670. // }
  34671. var icons = feature.getIcons ? feature.getIcons() : featureModel.get('icon');
  34672. var titles = featureModel.get('title') || {};
  34673. if (typeof icons === 'string') {
  34674. var icon = icons;
  34675. var title = titles;
  34676. icons = {};
  34677. titles = {};
  34678. icons[featureName] = icon;
  34679. titles[featureName] = title;
  34680. }
  34681. var iconPaths = featureModel.iconPaths = {};
  34682. zrUtil.each(icons, function (icon, iconName) {
  34683. var normalStyle = iconStyleModel.getModel('normal').getItemStyle();
  34684. var hoverStyle = iconStyleModel.getModel('emphasis').getItemStyle();
  34685. var style = {
  34686. x: -itemSize / 2,
  34687. y: -itemSize / 2,
  34688. width: itemSize,
  34689. height: itemSize
  34690. };
  34691. var path = icon.indexOf('image://') === 0
  34692. ? (
  34693. style.image = icon.slice(8),
  34694. new graphic.Image({style: style})
  34695. )
  34696. : graphic.makePath(
  34697. icon.replace('path://', ''),
  34698. {
  34699. style: normalStyle,
  34700. hoverStyle: hoverStyle,
  34701. rectHover: true
  34702. },
  34703. style,
  34704. 'center'
  34705. );
  34706. graphic.setHoverStyle(path);
  34707. if (toolboxModel.get('showTitle')) {
  34708. path.__title = titles[iconName];
  34709. path.on('mouseover', function () {
  34710. // Should not reuse above hoverStyle, which might be modified.
  34711. var hoverStyle = iconStyleModel.getModel('emphasis').getItemStyle();
  34712. path.setStyle({
  34713. text: titles[iconName],
  34714. textPosition: hoverStyle.textPosition || 'bottom',
  34715. textFill: hoverStyle.fill || hoverStyle.stroke || '#000',
  34716. textAlign: hoverStyle.textAlign || 'center'
  34717. });
  34718. })
  34719. .on('mouseout', function () {
  34720. path.setStyle({
  34721. textFill: null
  34722. });
  34723. });
  34724. }
  34725. path.trigger(featureModel.get('iconStatus.' + iconName) || 'normal');
  34726. group.add(path);
  34727. path.on('click', zrUtil.bind(
  34728. feature.onclick, feature, ecModel, api, iconName
  34729. ));
  34730. iconPaths[iconName] = path;
  34731. });
  34732. }
  34733. listComponentHelper.layout(group, toolboxModel, api);
  34734. // Render background after group is layout
  34735. // FIXME
  34736. listComponentHelper.addBackground(group, toolboxModel);
  34737. // Adjust icon title positions to avoid them out of screen
  34738. group.eachChild(function (icon) {
  34739. var titleText = icon.__title;
  34740. var hoverStyle = icon.hoverStyle;
  34741. // May be background element
  34742. if (hoverStyle && titleText) {
  34743. var rect = textContain.getBoundingRect(
  34744. titleText, hoverStyle.font
  34745. );
  34746. var offsetX = icon.position[0] + group.position[0];
  34747. var offsetY = icon.position[1] + group.position[1] + itemSize;
  34748. var needPutOnTop = false;
  34749. if (offsetY + rect.height > api.getHeight()) {
  34750. hoverStyle.textPosition = 'top';
  34751. needPutOnTop = true;
  34752. }
  34753. var topOffset = needPutOnTop ? (-5 - rect.height) : (itemSize + 8);
  34754. if (offsetX + rect.width / 2 > api.getWidth()) {
  34755. hoverStyle.textPosition = ['100%', topOffset];
  34756. hoverStyle.textAlign = 'right';
  34757. }
  34758. else if (offsetX - rect.width / 2 < 0) {
  34759. hoverStyle.textPosition = [0, topOffset];
  34760. hoverStyle.textAlign = 'left';
  34761. }
  34762. }
  34763. });
  34764. },
  34765. updateView: function (toolboxModel, ecModel, api, payload) {
  34766. zrUtil.each(this._features, function (feature) {
  34767. feature.updateView && feature.updateView(feature.model, ecModel, api, payload);
  34768. });
  34769. },
  34770. updateLayout: function (toolboxModel, ecModel, api, payload) {
  34771. zrUtil.each(this._features, function (feature) {
  34772. feature.updateLayout && feature.updateLayout(feature.model, ecModel, api, payload);
  34773. });
  34774. },
  34775. remove: function (ecModel, api) {
  34776. zrUtil.each(this._features, function (feature) {
  34777. feature.remove && feature.remove(ecModel, api);
  34778. });
  34779. this.group.removeAll();
  34780. },
  34781. dispose: function (ecModel, api) {
  34782. zrUtil.each(this._features, function (feature) {
  34783. feature.dispose && feature.dispose(ecModel, api);
  34784. });
  34785. }
  34786. });
  34787. function isUserFeatureName(featureName) {
  34788. return featureName.indexOf('my') === 0;
  34789. }
  34790. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(289)))
  34791. /***/ },
  34792. /* 382 */
  34793. /***/ function(module, exports, __webpack_require__) {
  34794. var env = __webpack_require__(2);
  34795. function SaveAsImage (model) {
  34796. this.model = model;
  34797. }
  34798. SaveAsImage.defaultOption = {
  34799. show: true,
  34800. icon: 'M4.7,22.9L29.3,45.5L54.7,23.4M4.6,43.6L4.6,58L53.8,58L53.8,43.6M29.2,45.1L29.2,0',
  34801. title: '保存为图片',
  34802. type: 'png',
  34803. // Default use option.backgroundColor
  34804. // backgroundColor: '#fff',
  34805. name: '',
  34806. excludeComponents: ['toolbox'],
  34807. pixelRatio: 1,
  34808. lang: ['右键另存为图片']
  34809. };
  34810. SaveAsImage.prototype.unusable = !env.canvasSupported;
  34811. var proto = SaveAsImage.prototype;
  34812. proto.onclick = function (ecModel, api) {
  34813. var model = this.model;
  34814. var title = model.get('name') || ecModel.get('title.0.text') || 'echarts';
  34815. var $a = document.createElement('a');
  34816. var type = model.get('type', true) || 'png';
  34817. $a.download = title + '.' + type;
  34818. $a.target = '_blank';
  34819. var url = api.getConnectedDataURL({
  34820. type: type,
  34821. backgroundColor: model.get('backgroundColor', true)
  34822. || ecModel.get('backgroundColor') || '#fff',
  34823. excludeComponents: model.get('excludeComponents'),
  34824. pixelRatio: model.get('pixelRatio')
  34825. });
  34826. $a.href = url;
  34827. // Chrome and Firefox
  34828. if (typeof MouseEvent === 'function' && !env.browser.ie && !env.browser.edge) {
  34829. var evt = new MouseEvent('click', {
  34830. view: window,
  34831. bubbles: true,
  34832. cancelable: false
  34833. });
  34834. $a.dispatchEvent(evt);
  34835. }
  34836. // IE
  34837. else {
  34838. var lang = model.get('lang');
  34839. var html = ''
  34840. + '<body style="margin:0;">'
  34841. + '<img src="' + url + '" style="max-width:100%;" title="' + ((lang && lang[0]) || '') + '" />'
  34842. + '</body>';
  34843. var tab = window.open();
  34844. tab.document.write(html);
  34845. }
  34846. };
  34847. __webpack_require__(327).register(
  34848. 'saveAsImage', SaveAsImage
  34849. );
  34850. module.exports = SaveAsImage;
  34851. /***/ },
  34852. /* 383 */
  34853. /***/ function(module, exports, __webpack_require__) {
  34854. 'use strict';
  34855. var zrUtil = __webpack_require__(4);
  34856. function MagicType(model) {
  34857. this.model = model;
  34858. }
  34859. MagicType.defaultOption = {
  34860. show: true,
  34861. type: [],
  34862. // Icon group
  34863. icon: {
  34864. line: 'M4.1,28.9h7.1l9.3-22l7.4,38l9.7-19.7l3,12.8h14.9M4.1,58h51.4',
  34865. bar: 'M6.7,22.9h10V48h-10V22.9zM24.9,13h10v35h-10V13zM43.2,2h10v46h-10V2zM3.1,58h53.7',
  34866. stack: 'M8.2,38.4l-8.4,4.1l30.6,15.3L60,42.5l-8.1-4.1l-21.5,11L8.2,38.4z M51.9,30l-8.1,4.2l-13.4,6.9l-13.9-6.9L8.2,30l-8.4,4.2l8.4,4.2l22.2,11l21.5-11l8.1-4.2L51.9,30z M51.9,21.7l-8.1,4.2L35.7,30l-5.3,2.8L24.9,30l-8.4-4.1l-8.3-4.2l-8.4,4.2L8.2,30l8.3,4.2l13.9,6.9l13.4-6.9l8.1-4.2l8.1-4.1L51.9,21.7zM30.4,2.2L-0.2,17.5l8.4,4.1l8.3,4.2l8.4,4.2l5.5,2.7l5.3-2.7l8.1-4.2l8.1-4.2l8.1-4.1L30.4,2.2z', // jshint ignore:line
  34867. tiled: 'M2.3,2.2h22.8V25H2.3V2.2z M35,2.2h22.8V25H35V2.2zM2.3,35h22.8v22.8H2.3V35z M35,35h22.8v22.8H35V35z'
  34868. },
  34869. title: {
  34870. line: '切换为折线图',
  34871. bar: '切换为柱状图',
  34872. stack: '切换为堆叠',
  34873. tiled: '切换为平铺'
  34874. },
  34875. option: {},
  34876. seriesIndex: {}
  34877. };
  34878. var proto = MagicType.prototype;
  34879. proto.getIcons = function () {
  34880. var model = this.model;
  34881. var availableIcons = model.get('icon');
  34882. var icons = {};
  34883. zrUtil.each(model.get('type'), function (type) {
  34884. if (availableIcons[type]) {
  34885. icons[type] = availableIcons[type];
  34886. }
  34887. });
  34888. return icons;
  34889. };
  34890. var seriesOptGenreator = {
  34891. 'line': function (seriesType, seriesId, seriesModel, model) {
  34892. if (seriesType === 'bar') {
  34893. return zrUtil.merge({
  34894. id: seriesId,
  34895. type: 'line',
  34896. // Preserve data related option
  34897. data: seriesModel.get('data'),
  34898. stack: seriesModel.get('stack'),
  34899. markPoint: seriesModel.get('markPoint'),
  34900. markLine: seriesModel.get('markLine')
  34901. }, model.get('option.line') || {}, true);
  34902. }
  34903. },
  34904. 'bar': function (seriesType, seriesId, seriesModel, model) {
  34905. if (seriesType === 'line') {
  34906. return zrUtil.merge({
  34907. id: seriesId,
  34908. type: 'bar',
  34909. // Preserve data related option
  34910. data: seriesModel.get('data'),
  34911. stack: seriesModel.get('stack'),
  34912. markPoint: seriesModel.get('markPoint'),
  34913. markLine: seriesModel.get('markLine')
  34914. }, model.get('option.bar') || {}, true);
  34915. }
  34916. },
  34917. 'stack': function (seriesType, seriesId, seriesModel, model) {
  34918. if (seriesType === 'line' || seriesType === 'bar') {
  34919. return zrUtil.merge({
  34920. id: seriesId,
  34921. stack: '__ec_magicType_stack__'
  34922. }, model.get('option.stack') || {}, true);
  34923. }
  34924. },
  34925. 'tiled': function (seriesType, seriesId, seriesModel, model) {
  34926. if (seriesType === 'line' || seriesType === 'bar') {
  34927. return zrUtil.merge({
  34928. id: seriesId,
  34929. stack: ''
  34930. }, model.get('option.tiled') || {}, true);
  34931. }
  34932. }
  34933. };
  34934. var radioTypes = [
  34935. ['line', 'bar'],
  34936. ['stack', 'tiled']
  34937. ];
  34938. proto.onclick = function (ecModel, api, type) {
  34939. var model = this.model;
  34940. var seriesIndex = model.get('seriesIndex.' + type);
  34941. // Not supported magicType
  34942. if (!seriesOptGenreator[type]) {
  34943. return;
  34944. }
  34945. var newOption = {
  34946. series: []
  34947. };
  34948. var generateNewSeriesTypes = function (seriesModel) {
  34949. var seriesType = seriesModel.subType;
  34950. var seriesId = seriesModel.id;
  34951. var newSeriesOpt = seriesOptGenreator[type](
  34952. seriesType, seriesId, seriesModel, model
  34953. );
  34954. if (newSeriesOpt) {
  34955. // PENDING If merge original option?
  34956. zrUtil.defaults(newSeriesOpt, seriesModel.option);
  34957. newOption.series.push(newSeriesOpt);
  34958. }
  34959. // Modify boundaryGap
  34960. var coordSys = seriesModel.coordinateSystem;
  34961. if (coordSys && coordSys.type === 'cartesian2d' && (type === 'line' || type === 'bar')) {
  34962. var categoryAxis = coordSys.getAxesByScale('ordinal')[0];
  34963. if (categoryAxis) {
  34964. var axisDim = categoryAxis.dim;
  34965. var axisType = axisDim + 'Axis';
  34966. var axisModel = ecModel.queryComponents({
  34967. mainType: axisType,
  34968. index: seriesModel.get(name + 'Index'),
  34969. id: seriesModel.get(name + 'Id')
  34970. })[0];
  34971. var axisIndex = axisModel.componentIndex;
  34972. newOption[axisType] = newOption[axisType] || [];
  34973. for (var i = 0; i <= axisIndex; i++) {
  34974. newOption[axisType][axisIndex] = newOption[axisType][axisIndex] || {};
  34975. }
  34976. newOption[axisType][axisIndex].boundaryGap = type === 'bar' ? true : false;
  34977. }
  34978. }
  34979. };
  34980. zrUtil.each(radioTypes, function (radio) {
  34981. if (zrUtil.indexOf(radio, type) >= 0) {
  34982. zrUtil.each(radio, function (item) {
  34983. model.setIconStatus(item, 'normal');
  34984. });
  34985. }
  34986. });
  34987. model.setIconStatus(type, 'emphasis');
  34988. ecModel.eachComponent(
  34989. {
  34990. mainType: 'series',
  34991. query: seriesIndex == null ? null : {
  34992. seriesIndex: seriesIndex
  34993. }
  34994. }, generateNewSeriesTypes
  34995. );
  34996. api.dispatchAction({
  34997. type: 'changeMagicType',
  34998. currentType: type,
  34999. newOption: newOption
  35000. });
  35001. };
  35002. var echarts = __webpack_require__(1);
  35003. echarts.registerAction({
  35004. type: 'changeMagicType',
  35005. event: 'magicTypeChanged',
  35006. update: 'prepareAndUpdate'
  35007. }, function (payload, ecModel) {
  35008. ecModel.mergeOption(payload.newOption);
  35009. });
  35010. __webpack_require__(327).register('magicType', MagicType);
  35011. module.exports = MagicType;
  35012. /***/ },
  35013. /* 384 */
  35014. /***/ function(module, exports, __webpack_require__) {
  35015. /**
  35016. * @module echarts/component/toolbox/feature/DataView
  35017. */
  35018. var zrUtil = __webpack_require__(4);
  35019. var eventTool = __webpack_require__(88);
  35020. var BLOCK_SPLITER = new Array(60).join('-');
  35021. var ITEM_SPLITER = '\t';
  35022. /**
  35023. * Group series into two types
  35024. * 1. on category axis, like line, bar
  35025. * 2. others, like scatter, pie
  35026. * @param {module:echarts/model/Global} ecModel
  35027. * @return {Object}
  35028. * @inner
  35029. */
  35030. function groupSeries(ecModel) {
  35031. var seriesGroupByCategoryAxis = {};
  35032. var otherSeries = [];
  35033. var meta = [];
  35034. ecModel.eachRawSeries(function (seriesModel) {
  35035. var coordSys = seriesModel.coordinateSystem;
  35036. if (coordSys && (coordSys.type === 'cartesian2d' || coordSys.type === 'polar')) {
  35037. var baseAxis = coordSys.getBaseAxis();
  35038. if (baseAxis.type === 'category') {
  35039. var key = baseAxis.dim + '_' + baseAxis.index;
  35040. if (!seriesGroupByCategoryAxis[key]) {
  35041. seriesGroupByCategoryAxis[key] = {
  35042. categoryAxis: baseAxis,
  35043. valueAxis: coordSys.getOtherAxis(baseAxis),
  35044. series: []
  35045. };
  35046. meta.push({
  35047. axisDim: baseAxis.dim,
  35048. axisIndex: baseAxis.index
  35049. });
  35050. }
  35051. seriesGroupByCategoryAxis[key].series.push(seriesModel);
  35052. }
  35053. else {
  35054. otherSeries.push(seriesModel);
  35055. }
  35056. }
  35057. else {
  35058. otherSeries.push(seriesModel);
  35059. }
  35060. });
  35061. return {
  35062. seriesGroupByCategoryAxis: seriesGroupByCategoryAxis,
  35063. other: otherSeries,
  35064. meta: meta
  35065. };
  35066. }
  35067. /**
  35068. * Assemble content of series on cateogory axis
  35069. * @param {Array.<module:echarts/model/Series>} series
  35070. * @return {string}
  35071. * @inner
  35072. */
  35073. function assembleSeriesWithCategoryAxis(series) {
  35074. var tables = [];
  35075. zrUtil.each(series, function (group, key) {
  35076. var categoryAxis = group.categoryAxis;
  35077. var valueAxis = group.valueAxis;
  35078. var valueAxisDim = valueAxis.dim;
  35079. var headers = [' '].concat(zrUtil.map(group.series, function (series) {
  35080. return series.name;
  35081. }));
  35082. var columns = [categoryAxis.model.getCategories()];
  35083. zrUtil.each(group.series, function (series) {
  35084. columns.push(series.getRawData().mapArray(valueAxisDim, function (val) {
  35085. return val;
  35086. }));
  35087. });
  35088. // Assemble table content
  35089. var lines = [headers.join(ITEM_SPLITER)];
  35090. for (var i = 0; i < columns[0].length; i++) {
  35091. var items = [];
  35092. for (var j = 0; j < columns.length; j++) {
  35093. items.push(columns[j][i]);
  35094. }
  35095. lines.push(items.join(ITEM_SPLITER));
  35096. }
  35097. tables.push(lines.join('\n'));
  35098. });
  35099. return tables.join('\n\n' + BLOCK_SPLITER + '\n\n');
  35100. }
  35101. /**
  35102. * Assemble content of other series
  35103. * @param {Array.<module:echarts/model/Series>} series
  35104. * @return {string}
  35105. * @inner
  35106. */
  35107. function assembleOtherSeries(series) {
  35108. return zrUtil.map(series, function (series) {
  35109. var data = series.getRawData();
  35110. var lines = [series.name];
  35111. var vals = [];
  35112. data.each(data.dimensions, function () {
  35113. var argLen = arguments.length;
  35114. var dataIndex = arguments[argLen - 1];
  35115. var name = data.getName(dataIndex);
  35116. for (var i = 0; i < argLen - 1; i++) {
  35117. vals[i] = arguments[i];
  35118. }
  35119. lines.push((name ? (name + ITEM_SPLITER) : '') + vals.join(ITEM_SPLITER));
  35120. });
  35121. return lines.join('\n');
  35122. }).join('\n\n' + BLOCK_SPLITER + '\n\n');
  35123. }
  35124. /**
  35125. * @param {module:echarts/model/Global}
  35126. * @return {string}
  35127. * @inner
  35128. */
  35129. function getContentFromModel(ecModel) {
  35130. var result = groupSeries(ecModel);
  35131. return {
  35132. value: zrUtil.filter([
  35133. assembleSeriesWithCategoryAxis(result.seriesGroupByCategoryAxis),
  35134. assembleOtherSeries(result.other)
  35135. ], function (str) {
  35136. return str.replace(/[\n\t\s]/g, '');
  35137. }).join('\n\n' + BLOCK_SPLITER + '\n\n'),
  35138. meta: result.meta
  35139. };
  35140. }
  35141. function trim(str) {
  35142. return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
  35143. }
  35144. /**
  35145. * If a block is tsv format
  35146. */
  35147. function isTSVFormat(block) {
  35148. // Simple method to find out if a block is tsv format
  35149. var firstLine = block.slice(0, block.indexOf('\n'));
  35150. if (firstLine.indexOf(ITEM_SPLITER) >= 0) {
  35151. return true;
  35152. }
  35153. }
  35154. var itemSplitRegex = new RegExp('[' + ITEM_SPLITER + ']+', 'g');
  35155. /**
  35156. * @param {string} tsv
  35157. * @return {Array.<Object>}
  35158. */
  35159. function parseTSVContents(tsv) {
  35160. var tsvLines = tsv.split(/\n+/g);
  35161. var headers = trim(tsvLines.shift()).split(itemSplitRegex);
  35162. var categories = [];
  35163. var series = zrUtil.map(headers, function (header) {
  35164. return {
  35165. name: header,
  35166. data: []
  35167. };
  35168. });
  35169. for (var i = 0; i < tsvLines.length; i++) {
  35170. var items = trim(tsvLines[i]).split(itemSplitRegex);
  35171. categories.push(items.shift());
  35172. for (var j = 0; j < items.length; j++) {
  35173. series[j] && (series[j].data[i] = items[j]);
  35174. }
  35175. }
  35176. return {
  35177. series: series,
  35178. categories: categories
  35179. };
  35180. }
  35181. /**
  35182. * @param {string} str
  35183. * @return {Array.<Object>}
  35184. * @inner
  35185. */
  35186. function parseListContents(str) {
  35187. var lines = str.split(/\n+/g);
  35188. var seriesName = trim(lines.shift());
  35189. var data = [];
  35190. for (var i = 0; i < lines.length; i++) {
  35191. var items = trim(lines[i]).split(itemSplitRegex);
  35192. var name = '';
  35193. var value;
  35194. var hasName = false;
  35195. if (isNaN(items[0])) { // First item is name
  35196. hasName = true;
  35197. name = items[0];
  35198. items = items.slice(1);
  35199. data[i] = {
  35200. name: name,
  35201. value: []
  35202. };
  35203. value = data[i].value;
  35204. }
  35205. else {
  35206. value = data[i] = [];
  35207. }
  35208. for (var j = 0; j < items.length; j++) {
  35209. value.push(+items[j]);
  35210. }
  35211. if (value.length === 1) {
  35212. hasName ? (data[i].value = value[0]) : (data[i] = value[0]);
  35213. }
  35214. }
  35215. return {
  35216. name: seriesName,
  35217. data: data
  35218. };
  35219. }
  35220. /**
  35221. * @param {string} str
  35222. * @param {Array.<Object>} blockMetaList
  35223. * @return {Object}
  35224. * @inner
  35225. */
  35226. function parseContents(str, blockMetaList) {
  35227. var blocks = str.split(new RegExp('\n*' + BLOCK_SPLITER + '\n*', 'g'));
  35228. var newOption = {
  35229. series: []
  35230. };
  35231. zrUtil.each(blocks, function (block, idx) {
  35232. if (isTSVFormat(block)) {
  35233. var result = parseTSVContents(block);
  35234. var blockMeta = blockMetaList[idx];
  35235. var axisKey = blockMeta.axisDim + 'Axis';
  35236. if (blockMeta) {
  35237. newOption[axisKey] = newOption[axisKey] || [];
  35238. newOption[axisKey][blockMeta.axisIndex] = {
  35239. data: result.categories
  35240. };
  35241. newOption.series = newOption.series.concat(result.series);
  35242. }
  35243. }
  35244. else {
  35245. var result = parseListContents(block);
  35246. newOption.series.push(result);
  35247. }
  35248. });
  35249. return newOption;
  35250. }
  35251. /**
  35252. * @alias {module:echarts/component/toolbox/feature/DataView}
  35253. * @constructor
  35254. * @param {module:echarts/model/Model} model
  35255. */
  35256. function DataView(model) {
  35257. this._dom = null;
  35258. this.model = model;
  35259. }
  35260. DataView.defaultOption = {
  35261. show: true,
  35262. readOnly: false,
  35263. optionToContent: null,
  35264. contentToOption: null,
  35265. icon: 'M17.5,17.3H33 M17.5,17.3H33 M45.4,29.5h-28 M11.5,2v56H51V14.8L38.4,2H11.5z M38.4,2.2v12.7H51 M45.4,41.7h-28',
  35266. title: '数据视图',
  35267. lang: ['数据视图', '关闭', '刷新'],
  35268. backgroundColor: '#fff',
  35269. textColor: '#000',
  35270. textareaColor: '#fff',
  35271. textareaBorderColor: '#333',
  35272. buttonColor: '#c23531',
  35273. buttonTextColor: '#fff'
  35274. };
  35275. DataView.prototype.onclick = function (ecModel, api) {
  35276. var container = api.getDom();
  35277. var model = this.model;
  35278. if (this._dom) {
  35279. container.removeChild(this._dom);
  35280. }
  35281. var root = document.createElement('div');
  35282. root.style.cssText = 'position:absolute;left:5px;top:5px;bottom:5px;right:5px;';
  35283. root.style.backgroundColor = model.get('backgroundColor') || '#fff';
  35284. // Create elements
  35285. var header = document.createElement('h4');
  35286. var lang = model.get('lang') || [];
  35287. header.innerHTML = lang[0] || model.get('title');
  35288. header.style.cssText = 'margin: 10px 20px;';
  35289. header.style.color = model.get('textColor');
  35290. var viewMain = document.createElement('div');
  35291. var textarea = document.createElement('textarea');
  35292. viewMain.style.cssText = 'display:block;width:100%;overflow:hidden;';
  35293. var optionToContent = model.get('optionToContent');
  35294. var contentToOption = model.get('contentToOption');
  35295. var result = getContentFromModel(ecModel);
  35296. if (typeof optionToContent === 'function') {
  35297. var htmlOrDom = optionToContent(api.getOption());
  35298. if (typeof htmlOrDom === 'string') {
  35299. viewMain.innerHTML = htmlOrDom;
  35300. }
  35301. else if (zrUtil.isDom(htmlOrDom)) {
  35302. viewMain.appendChild(htmlOrDom);
  35303. }
  35304. }
  35305. else {
  35306. // Use default textarea
  35307. viewMain.appendChild(textarea);
  35308. textarea.readOnly = model.get('readOnly');
  35309. textarea.style.cssText = 'width:100%;height:100%;font-family:monospace;font-size:14px;line-height:1.6rem;';
  35310. textarea.style.color = model.get('textColor');
  35311. textarea.style.borderColor = model.get('textareaBorderColor');
  35312. textarea.style.backgroundColor = model.get('textareaColor');
  35313. textarea.value = result.value;
  35314. }
  35315. var blockMetaList = result.meta;
  35316. var buttonContainer = document.createElement('div');
  35317. buttonContainer.style.cssText = 'position:absolute;bottom:0;left:0;right:0;';
  35318. var buttonStyle = 'float:right;margin-right:20px;border:none;'
  35319. + 'cursor:pointer;padding:2px 5px;font-size:12px;border-radius:3px';
  35320. var closeButton = document.createElement('div');
  35321. var refreshButton = document.createElement('div');
  35322. buttonStyle += ';background-color:' + model.get('buttonColor');
  35323. buttonStyle += ';color:' + model.get('buttonTextColor');
  35324. var self = this;
  35325. function close() {
  35326. container.removeChild(root);
  35327. self._dom = null;
  35328. }
  35329. eventTool.addEventListener(closeButton, 'click', close);
  35330. eventTool.addEventListener(refreshButton, 'click', function () {
  35331. var newOption;
  35332. try {
  35333. if (typeof contentToOption === 'function') {
  35334. newOption = contentToOption(viewMain, api.getOption());
  35335. }
  35336. else {
  35337. newOption = parseContents(textarea.value, blockMetaList);
  35338. }
  35339. }
  35340. catch (e) {
  35341. close();
  35342. throw new Error('Data view format error ' + e);
  35343. }
  35344. if (newOption) {
  35345. api.dispatchAction({
  35346. type: 'changeDataView',
  35347. newOption: newOption
  35348. });
  35349. }
  35350. close();
  35351. });
  35352. closeButton.innerHTML = lang[1];
  35353. refreshButton.innerHTML = lang[2];
  35354. refreshButton.style.cssText = buttonStyle;
  35355. closeButton.style.cssText = buttonStyle;
  35356. !model.get('readOnly') && buttonContainer.appendChild(refreshButton);
  35357. buttonContainer.appendChild(closeButton);
  35358. // http://stackoverflow.com/questions/6637341/use-tab-to-indent-in-textarea
  35359. eventTool.addEventListener(textarea, 'keydown', function (e) {
  35360. if ((e.keyCode || e.which) === 9) {
  35361. // get caret position/selection
  35362. var val = this.value;
  35363. var start = this.selectionStart;
  35364. var end = this.selectionEnd;
  35365. // set textarea value to: text before caret + tab + text after caret
  35366. this.value = val.substring(0, start) + ITEM_SPLITER + val.substring(end);
  35367. // put caret at right position again
  35368. this.selectionStart = this.selectionEnd = start + 1;
  35369. // prevent the focus lose
  35370. eventTool.stop(e);
  35371. }
  35372. });
  35373. root.appendChild(header);
  35374. root.appendChild(viewMain);
  35375. root.appendChild(buttonContainer);
  35376. viewMain.style.height = (container.clientHeight - 80) + 'px';
  35377. container.appendChild(root);
  35378. this._dom = root;
  35379. };
  35380. DataView.prototype.remove = function (ecModel, api) {
  35381. this._dom && api.getDom().removeChild(this._dom);
  35382. };
  35383. DataView.prototype.dispose = function (ecModel, api) {
  35384. this.remove(ecModel, api);
  35385. };
  35386. /**
  35387. * @inner
  35388. */
  35389. function tryMergeDataOption(newData, originalData) {
  35390. return zrUtil.map(newData, function (newVal, idx) {
  35391. var original = originalData && originalData[idx];
  35392. if (zrUtil.isObject(original) && !zrUtil.isArray(original)) {
  35393. if (zrUtil.isObject(newVal) && !zrUtil.isArray(newVal)) {
  35394. newVal = newVal.value;
  35395. }
  35396. // Original data has option
  35397. return zrUtil.defaults({
  35398. value: newVal
  35399. }, original);
  35400. }
  35401. else {
  35402. return newVal;
  35403. }
  35404. });
  35405. }
  35406. __webpack_require__(327).register('dataView', DataView);
  35407. __webpack_require__(1).registerAction({
  35408. type: 'changeDataView',
  35409. event: 'dataViewChanged',
  35410. update: 'prepareAndUpdate'
  35411. }, function (payload, ecModel) {
  35412. var newSeriesOptList = [];
  35413. zrUtil.each(payload.newOption.series, function (seriesOpt) {
  35414. var seriesModel = ecModel.getSeriesByName(seriesOpt.name)[0];
  35415. if (!seriesModel) {
  35416. // New created series
  35417. // Geuss the series type
  35418. newSeriesOptList.push(zrUtil.extend({
  35419. // Default is scatter
  35420. type: 'scatter'
  35421. }, seriesOpt));
  35422. }
  35423. else {
  35424. var originalData = seriesModel.get('data');
  35425. newSeriesOptList.push({
  35426. name: seriesOpt.name,
  35427. data: tryMergeDataOption(seriesOpt.data, originalData)
  35428. });
  35429. }
  35430. });
  35431. ecModel.mergeOption(zrUtil.defaults({
  35432. series: newSeriesOptList
  35433. }, payload.newOption));
  35434. });
  35435. module.exports = DataView;
  35436. /***/ },
  35437. /* 385 */
  35438. /***/ function(module, exports, __webpack_require__) {
  35439. 'use strict';
  35440. var zrUtil = __webpack_require__(4);
  35441. var BrushController = __webpack_require__(236);
  35442. var brushHelper = __webpack_require__(322);
  35443. var history = __webpack_require__(386);
  35444. var each = zrUtil.each;
  35445. // Use dataZoomSelect
  35446. __webpack_require__(387);
  35447. // Spectial component id start with \0ec\0, see echarts/model/Global.js~hasInnerId
  35448. var DATA_ZOOM_ID_BASE = '\0_ec_\0toolbox-dataZoom_';
  35449. function DataZoom(model, ecModel, api) {
  35450. /**
  35451. * @private
  35452. * @type {module:echarts/component/helper/BrushController}
  35453. */
  35454. (this._brushController = new BrushController(api.getZr()))
  35455. .on('brush', zrUtil.bind(this._onBrush, this))
  35456. .mount();
  35457. /**
  35458. * @private
  35459. * @type {boolean}
  35460. */
  35461. this._isZoomActive;
  35462. }
  35463. DataZoom.defaultOption = {
  35464. show: true,
  35465. // Icon group
  35466. icon: {
  35467. zoom: 'M0,13.5h26.9 M13.5,26.9V0 M32.1,13.5H58V58H13.5 V32.1',
  35468. back: 'M22,1.4L9.9,13.5l12.3,12.3 M10.3,13.5H54.9v44.6 H10.3v-26'
  35469. },
  35470. title: {
  35471. zoom: '区域缩放',
  35472. back: '区域缩放还原'
  35473. }
  35474. };
  35475. var proto = DataZoom.prototype;
  35476. proto.render = function (featureModel, ecModel, api, payload) {
  35477. this.model = featureModel;
  35478. this.ecModel = ecModel;
  35479. this.api = api;
  35480. updateZoomBtnStatus(featureModel, ecModel, this, payload);
  35481. updateBackBtnStatus(featureModel, ecModel);
  35482. };
  35483. proto.onclick = function (ecModel, api, type) {
  35484. handlers[type].call(this);
  35485. };
  35486. proto.remove = function (ecModel, api) {
  35487. this._brushController.unmount();
  35488. };
  35489. proto.dispose = function (ecModel, api) {
  35490. this._brushController.dispose();
  35491. };
  35492. /**
  35493. * @private
  35494. */
  35495. var handlers = {
  35496. zoom: function () {
  35497. var nextActive = !this._isZoomActive;
  35498. this.api.dispatchAction({
  35499. type: 'takeGlobalCursor',
  35500. key: 'dataZoomSelect',
  35501. dataZoomSelectActive: nextActive
  35502. });
  35503. },
  35504. back: function () {
  35505. this._dispatchZoomAction(history.pop(this.ecModel));
  35506. }
  35507. };
  35508. /**
  35509. * @private
  35510. */
  35511. proto._onBrush = function (areas, opt) {
  35512. if (!opt.isEnd || !areas.length) {
  35513. return;
  35514. }
  35515. var snapshot = {};
  35516. var ecModel = this.ecModel;
  35517. this._brushController.updateCovers([]); // remove cover
  35518. var coordInfoList = brushHelper.makeCoordInfoList(
  35519. retrieveAxisSetting(this.model.option), ecModel
  35520. );
  35521. var rangesCoordInfoList = [];
  35522. brushHelper.parseOutputRanges(areas, coordInfoList, ecModel, rangesCoordInfoList);
  35523. var area = areas[0]; // dataZoom can not multiple area.
  35524. var coordInfo = rangesCoordInfoList[0];
  35525. var coordRange = area.coordRange;
  35526. var brushType = area.brushType;
  35527. if (coordInfo && coordRange) {
  35528. if (brushType === 'rect') {
  35529. setBatch('xAxis', coordRange[0], coordInfo);
  35530. setBatch('yAxis', coordRange[1], coordInfo);
  35531. }
  35532. else {
  35533. var axisNames = {lineX: 'xAxis', lineY: 'yAxis'};
  35534. setBatch(axisNames[brushType], coordRange, coordInfo);
  35535. }
  35536. }
  35537. history.push(ecModel, snapshot);
  35538. this._dispatchZoomAction(snapshot);
  35539. function setBatch(axisName, minMax, coordInfo) {
  35540. var dataZoomModel = findDataZoom(axisName, coordInfo[axisName], ecModel);
  35541. if (dataZoomModel) {
  35542. snapshot[dataZoomModel.id] = {
  35543. dataZoomId: dataZoomModel.id,
  35544. startValue: minMax[0],
  35545. endValue: minMax[1]
  35546. };
  35547. }
  35548. }
  35549. function findDataZoom(axisName, axisModel, ecModel) {
  35550. var dataZoomModel;
  35551. ecModel.eachComponent(
  35552. {mainType: 'dataZoom', subType: 'select'},
  35553. function (dzModel, dataZoomIndex) {
  35554. var axisIndex = dzModel.get(axisName + 'Index');
  35555. if (axisIndex != null
  35556. && ecModel.getComponent(axisName, axisIndex) === axisModel
  35557. ) {
  35558. dataZoomModel = dzModel;
  35559. }
  35560. }
  35561. );
  35562. return dataZoomModel;
  35563. }
  35564. };
  35565. /**
  35566. * @private
  35567. */
  35568. proto._dispatchZoomAction = function (snapshot) {
  35569. var batch = [];
  35570. // Convert from hash map to array.
  35571. each(snapshot, function (batchItem, dataZoomId) {
  35572. batch.push(zrUtil.clone(batchItem));
  35573. });
  35574. batch.length && this.api.dispatchAction({
  35575. type: 'dataZoom',
  35576. from: this.uid,
  35577. batch: batch
  35578. });
  35579. };
  35580. function retrieveAxisSetting(option) {
  35581. var setting = {};
  35582. // Compatible with previous setting: null => all axis, false => no axis.
  35583. zrUtil.each(['xAxisIndex', 'yAxisIndex'], function (name) {
  35584. setting[name] = option[name];
  35585. setting[name] == null && (setting[name] = 'all');
  35586. (setting[name] === false || setting[name] === 'none') && (setting[name] = []);
  35587. });
  35588. return setting;
  35589. }
  35590. function updateBackBtnStatus(featureModel, ecModel) {
  35591. featureModel.setIconStatus(
  35592. 'back',
  35593. history.count(ecModel) > 1 ? 'emphasis' : 'normal'
  35594. );
  35595. }
  35596. function updateZoomBtnStatus(featureModel, ecModel, view, payload) {
  35597. var zoomActive = view._isZoomActive;
  35598. if (payload && payload.type === 'takeGlobalCursor') {
  35599. zoomActive = payload.key === 'dataZoomSelect'
  35600. ? payload.dataZoomSelectActive : false;
  35601. }
  35602. view._isZoomActive = zoomActive;
  35603. featureModel.setIconStatus('zoom', zoomActive ? 'emphasis' : 'normal');
  35604. var coordInfoList = brushHelper.makeCoordInfoList(
  35605. retrieveAxisSetting(featureModel.option), ecModel
  35606. );
  35607. var brushType = (coordInfoList.xAxisHas && !coordInfoList.yAxisHas)
  35608. ? 'lineX'
  35609. : (!coordInfoList.xAxisHas && coordInfoList.yAxisHas)
  35610. ? 'lineY'
  35611. : 'rect';
  35612. view._brushController
  35613. .setPanels(brushHelper.makePanelOpts(coordInfoList))
  35614. .enableBrush(
  35615. zoomActive
  35616. ? {
  35617. brushType: brushType,
  35618. brushStyle: { // FIXME user customized?
  35619. lineWidth: 0,
  35620. // stroke: '#333',
  35621. fill: 'rgba(0,0,0,0.2)'
  35622. }
  35623. }
  35624. : false
  35625. );
  35626. }
  35627. __webpack_require__(327).register('dataZoom', DataZoom);
  35628. // Create special dataZoom option for select
  35629. __webpack_require__(1).registerPreprocessor(function (option) {
  35630. if (!option) {
  35631. return;
  35632. }
  35633. var dataZoomOpts = option.dataZoom || (option.dataZoom = []);
  35634. if (!zrUtil.isArray(dataZoomOpts)) {
  35635. option.dataZoom = dataZoomOpts = [dataZoomOpts];
  35636. }
  35637. var toolboxOpt = option.toolbox;
  35638. if (toolboxOpt) {
  35639. // Assume there is only one toolbox
  35640. if (zrUtil.isArray(toolboxOpt)) {
  35641. toolboxOpt = toolboxOpt[0];
  35642. }
  35643. if (toolboxOpt && toolboxOpt.feature) {
  35644. var dataZoomOpt = toolboxOpt.feature.dataZoom;
  35645. addForAxis('xAxis', dataZoomOpt);
  35646. addForAxis('yAxis', dataZoomOpt);
  35647. }
  35648. }
  35649. function addForAxis(axisName, dataZoomOpt) {
  35650. if (!dataZoomOpt) {
  35651. return;
  35652. }
  35653. // Try not to modify model, because it is not merged yet.
  35654. var axisIndicesName = axisName + 'Index';
  35655. var givenAxisIndices = dataZoomOpt[axisIndicesName];
  35656. if (givenAxisIndices != null
  35657. && givenAxisIndices != 'all'
  35658. && !zrUtil.isArray(givenAxisIndices)
  35659. ) {
  35660. givenAxisIndices = (givenAxisIndices === false || givenAxisIndices === 'none') ? [] : [givenAxisIndices];
  35661. }
  35662. forEachComponent(axisName, function (axisOpt, axisIndex) {
  35663. if (givenAxisIndices != null
  35664. && givenAxisIndices != 'all'
  35665. && zrUtil.indexOf(givenAxisIndices, axisIndex) === -1
  35666. ) {
  35667. return;
  35668. }
  35669. var newOpt = {
  35670. type: 'select',
  35671. $fromToolbox: true,
  35672. // Id for merge mapping.
  35673. id: DATA_ZOOM_ID_BASE + axisName + axisIndex
  35674. };
  35675. // FIXME
  35676. // Only support one axis now.
  35677. newOpt[axisIndicesName] = axisIndex;
  35678. dataZoomOpts.push(newOpt);
  35679. });
  35680. }
  35681. function forEachComponent(mainType, cb) {
  35682. var opts = option[mainType];
  35683. if (!zrUtil.isArray(opts)) {
  35684. opts = opts ? [opts] : [];
  35685. }
  35686. each(opts, cb);
  35687. }
  35688. });
  35689. module.exports = DataZoom;
  35690. /***/ },
  35691. /* 386 */
  35692. /***/ function(module, exports, __webpack_require__) {
  35693. /**
  35694. * @file History manager.
  35695. */
  35696. var zrUtil = __webpack_require__(4);
  35697. var each = zrUtil.each;
  35698. var ATTR = '\0_ec_hist_store';
  35699. var history = {
  35700. /**
  35701. * @public
  35702. * @param {module:echarts/model/Global} ecModel
  35703. * @param {Object} newSnapshot {dataZoomId, batch: [payloadInfo, ...]}
  35704. */
  35705. push: function (ecModel, newSnapshot) {
  35706. var store = giveStore(ecModel);
  35707. // If previous dataZoom can not be found,
  35708. // complete an range with current range.
  35709. each(newSnapshot, function (batchItem, dataZoomId) {
  35710. var i = store.length - 1;
  35711. for (; i >= 0; i--) {
  35712. var snapshot = store[i];
  35713. if (snapshot[dataZoomId]) {
  35714. break;
  35715. }
  35716. }
  35717. if (i < 0) {
  35718. // No origin range set, create one by current range.
  35719. var dataZoomModel = ecModel.queryComponents(
  35720. {mainType: 'dataZoom', subType: 'select', id: dataZoomId}
  35721. )[0];
  35722. if (dataZoomModel) {
  35723. var percentRange = dataZoomModel.getPercentRange();
  35724. store[0][dataZoomId] = {
  35725. dataZoomId: dataZoomId,
  35726. start: percentRange[0],
  35727. end: percentRange[1]
  35728. };
  35729. }
  35730. }
  35731. });
  35732. store.push(newSnapshot);
  35733. },
  35734. /**
  35735. * @public
  35736. * @param {module:echarts/model/Global} ecModel
  35737. * @return {Object} snapshot
  35738. */
  35739. pop: function (ecModel) {
  35740. var store = giveStore(ecModel);
  35741. var head = store[store.length - 1];
  35742. store.length > 1 && store.pop();
  35743. // Find top for all dataZoom.
  35744. var snapshot = {};
  35745. each(head, function (batchItem, dataZoomId) {
  35746. for (var i = store.length - 1; i >= 0; i--) {
  35747. var batchItem = store[i][dataZoomId];
  35748. if (batchItem) {
  35749. snapshot[dataZoomId] = batchItem;
  35750. break;
  35751. }
  35752. }
  35753. });
  35754. return snapshot;
  35755. },
  35756. /**
  35757. * @public
  35758. */
  35759. clear: function (ecModel) {
  35760. ecModel[ATTR] = null;
  35761. },
  35762. /**
  35763. * @public
  35764. * @param {module:echarts/model/Global} ecModel
  35765. * @return {number} records. always >= 1.
  35766. */
  35767. count: function (ecModel) {
  35768. return giveStore(ecModel).length;
  35769. }
  35770. };
  35771. /**
  35772. * [{key: dataZoomId, value: {dataZoomId, range}}, ...]
  35773. * History length of each dataZoom may be different.
  35774. * this._history[0] is used to store origin range.
  35775. * @type {Array.<Object>}
  35776. */
  35777. function giveStore(ecModel) {
  35778. var store = ecModel[ATTR];
  35779. if (!store) {
  35780. store = ecModel[ATTR] = [{}];
  35781. }
  35782. return store;
  35783. }
  35784. module.exports = history;
  35785. /***/ },
  35786. /* 387 */
  35787. /***/ function(module, exports, __webpack_require__) {
  35788. /**
  35789. * DataZoom component entry
  35790. */
  35791. __webpack_require__(330);
  35792. __webpack_require__(331);
  35793. __webpack_require__(334);
  35794. __webpack_require__(388);
  35795. __webpack_require__(389);
  35796. __webpack_require__(341);
  35797. __webpack_require__(342);
  35798. /***/ },
  35799. /* 388 */
  35800. /***/ function(module, exports, __webpack_require__) {
  35801. /**
  35802. * @file Data zoom model
  35803. */
  35804. var DataZoomModel = __webpack_require__(331);
  35805. module.exports = DataZoomModel.extend({
  35806. type: 'dataZoom.select'
  35807. });
  35808. /***/ },
  35809. /* 389 */
  35810. /***/ function(module, exports, __webpack_require__) {
  35811. module.exports = __webpack_require__(334).extend({
  35812. type: 'dataZoom.select'
  35813. });
  35814. /***/ },
  35815. /* 390 */
  35816. /***/ function(module, exports, __webpack_require__) {
  35817. 'use strict';
  35818. var history = __webpack_require__(386);
  35819. function Restore(model) {
  35820. this.model = model;
  35821. }
  35822. Restore.defaultOption = {
  35823. show: true,
  35824. icon: 'M3.8,33.4 M47,18.9h9.8V8.7 M56.3,20.1 C52.1,9,40.5,0.6,26.8,2.1C12.6,3.7,1.6,16.2,2.1,30.6 M13,41.1H3.1v10.2 M3.7,39.9c4.2,11.1,15.8,19.5,29.5,18 c14.2-1.6,25.2-14.1,24.7-28.5',
  35825. title: '还原'
  35826. };
  35827. var proto = Restore.prototype;
  35828. proto.onclick = function (ecModel, api, type) {
  35829. history.clear(ecModel);
  35830. api.dispatchAction({
  35831. type: 'restore',
  35832. from: this.uid
  35833. });
  35834. };
  35835. __webpack_require__(327).register('restore', Restore);
  35836. __webpack_require__(1).registerAction(
  35837. {type: 'restore', event: 'restore', update: 'prepareAndUpdate'},
  35838. function (payload, ecModel) {
  35839. ecModel.resetOption('recreate');
  35840. }
  35841. );
  35842. module.exports = Restore;
  35843. /***/ },
  35844. /* 391 */
  35845. /***/ function(module, exports, __webpack_require__) {
  35846. __webpack_require__(392);
  35847. __webpack_require__(82).registerPainter('vml', __webpack_require__(394));
  35848. /***/ },
  35849. /* 392 */
  35850. /***/ function(module, exports, __webpack_require__) {
  35851. // http://www.w3.org/TR/NOTE-VML
  35852. // TODO Use proxy like svg instead of overwrite brush methods
  35853. if (!__webpack_require__(2).canvasSupported) {
  35854. var vec2 = __webpack_require__(10);
  35855. var BoundingRect = __webpack_require__(9);
  35856. var CMD = __webpack_require__(49).CMD;
  35857. var colorTool = __webpack_require__(39);
  35858. var textContain = __webpack_require__(8);
  35859. var RectText = __webpack_require__(48);
  35860. var Displayable = __webpack_require__(46);
  35861. var ZImage = __webpack_require__(61);
  35862. var Text = __webpack_require__(63);
  35863. var Path = __webpack_require__(45);
  35864. var Gradient = __webpack_require__(79);
  35865. var vmlCore = __webpack_require__(393);
  35866. var round = Math.round;
  35867. var sqrt = Math.sqrt;
  35868. var abs = Math.abs;
  35869. var cos = Math.cos;
  35870. var sin = Math.sin;
  35871. var mathMax = Math.max;
  35872. var applyTransform = vec2.applyTransform;
  35873. var comma = ',';
  35874. var imageTransformPrefix = 'progid:DXImageTransform.Microsoft';
  35875. var Z = 21600;
  35876. var Z2 = Z / 2;
  35877. var ZLEVEL_BASE = 100000;
  35878. var Z_BASE = 1000;
  35879. var initRootElStyle = function (el) {
  35880. el.style.cssText = 'position:absolute;left:0;top:0;width:1px;height:1px;';
  35881. el.coordsize = Z + ',' + Z;
  35882. el.coordorigin = '0,0';
  35883. };
  35884. var encodeHtmlAttribute = function (s) {
  35885. return String(s).replace(/&/g, '&amp;').replace(/"/g, '&quot;');
  35886. };
  35887. var rgb2Str = function (r, g, b) {
  35888. return 'rgb(' + [r, g, b].join(',') + ')';
  35889. };
  35890. var append = function (parent, child) {
  35891. if (child && parent && child.parentNode !== parent) {
  35892. parent.appendChild(child);
  35893. }
  35894. };
  35895. var remove = function (parent, child) {
  35896. if (child && parent && child.parentNode === parent) {
  35897. parent.removeChild(child);
  35898. }
  35899. };
  35900. var getZIndex = function (zlevel, z, z2) {
  35901. // z 的取值范围为 [0, 1000]
  35902. return (parseFloat(zlevel) || 0) * ZLEVEL_BASE + (parseFloat(z) || 0) * Z_BASE + z2;
  35903. };
  35904. var parsePercent = function (value, maxValue) {
  35905. if (typeof value === 'string') {
  35906. if (value.lastIndexOf('%') >= 0) {
  35907. return parseFloat(value) / 100 * maxValue;
  35908. }
  35909. return parseFloat(value);
  35910. }
  35911. return value;
  35912. };
  35913. /***************************************************
  35914. * PATH
  35915. **************************************************/
  35916. var setColorAndOpacity = function (el, color, opacity) {
  35917. var colorArr = colorTool.parse(color);
  35918. opacity = +opacity;
  35919. if (isNaN(opacity)) {
  35920. opacity = 1;
  35921. }
  35922. if (colorArr) {
  35923. el.color = rgb2Str(colorArr[0], colorArr[1], colorArr[2]);
  35924. el.opacity = opacity * colorArr[3];
  35925. }
  35926. };
  35927. var getColorAndAlpha = function (color) {
  35928. var colorArr = colorTool.parse(color);
  35929. return [
  35930. rgb2Str(colorArr[0], colorArr[1], colorArr[2]),
  35931. colorArr[3]
  35932. ];
  35933. };
  35934. var updateFillNode = function (el, style, zrEl) {
  35935. // TODO pattern
  35936. var fill = style.fill;
  35937. if (fill != null) {
  35938. // Modified from excanvas
  35939. if (fill instanceof Gradient) {
  35940. var gradientType;
  35941. var angle = 0;
  35942. var focus = [0, 0];
  35943. // additional offset
  35944. var shift = 0;
  35945. // scale factor for offset
  35946. var expansion = 1;
  35947. var rect = zrEl.getBoundingRect();
  35948. var rectWidth = rect.width;
  35949. var rectHeight = rect.height;
  35950. if (fill.type === 'linear') {
  35951. gradientType = 'gradient';
  35952. var transform = zrEl.transform;
  35953. var p0 = [fill.x * rectWidth, fill.y * rectHeight];
  35954. var p1 = [fill.x2 * rectWidth, fill.y2 * rectHeight];
  35955. if (transform) {
  35956. applyTransform(p0, p0, transform);
  35957. applyTransform(p1, p1, transform);
  35958. }
  35959. var dx = p1[0] - p0[0];
  35960. var dy = p1[1] - p0[1];
  35961. angle = Math.atan2(dx, dy) * 180 / Math.PI;
  35962. // The angle should be a non-negative number.
  35963. if (angle < 0) {
  35964. angle += 360;
  35965. }
  35966. // Very small angles produce an unexpected result because they are
  35967. // converted to a scientific notation string.
  35968. if (angle < 1e-6) {
  35969. angle = 0;
  35970. }
  35971. }
  35972. else {
  35973. gradientType = 'gradientradial';
  35974. var p0 = [fill.x * rectWidth, fill.y * rectHeight];
  35975. var transform = zrEl.transform;
  35976. var scale = zrEl.scale;
  35977. var width = rectWidth;
  35978. var height = rectHeight;
  35979. focus = [
  35980. // Percent in bounding rect
  35981. (p0[0] - rect.x) / width,
  35982. (p0[1] - rect.y) / height
  35983. ];
  35984. if (transform) {
  35985. applyTransform(p0, p0, transform);
  35986. }
  35987. width /= scale[0] * Z;
  35988. height /= scale[1] * Z;
  35989. var dimension = mathMax(width, height);
  35990. shift = 2 * 0 / dimension;
  35991. expansion = 2 * fill.r / dimension - shift;
  35992. }
  35993. // We need to sort the color stops in ascending order by offset,
  35994. // otherwise IE won't interpret it correctly.
  35995. var stops = fill.colorStops.slice();
  35996. stops.sort(function(cs1, cs2) {
  35997. return cs1.offset - cs2.offset;
  35998. });
  35999. var length = stops.length;
  36000. // Color and alpha list of first and last stop
  36001. var colorAndAlphaList = [];
  36002. var colors = [];
  36003. for (var i = 0; i < length; i++) {
  36004. var stop = stops[i];
  36005. var colorAndAlpha = getColorAndAlpha(stop.color);
  36006. colors.push(stop.offset * expansion + shift + ' ' + colorAndAlpha[0]);
  36007. if (i === 0 || i === length - 1) {
  36008. colorAndAlphaList.push(colorAndAlpha);
  36009. }
  36010. }
  36011. if (length >= 2) {
  36012. var color1 = colorAndAlphaList[0][0];
  36013. var color2 = colorAndAlphaList[1][0];
  36014. var opacity1 = colorAndAlphaList[0][1] * style.opacity;
  36015. var opacity2 = colorAndAlphaList[1][1] * style.opacity;
  36016. el.type = gradientType;
  36017. el.method = 'none';
  36018. el.focus = '100%';
  36019. el.angle = angle;
  36020. el.color = color1;
  36021. el.color2 = color2;
  36022. el.colors = colors.join(',');
  36023. // When colors attribute is used, the meanings of opacity and o:opacity2
  36024. // are reversed.
  36025. el.opacity = opacity2;
  36026. // FIXME g_o_:opacity ?
  36027. el.opacity2 = opacity1;
  36028. }
  36029. if (gradientType === 'radial') {
  36030. el.focusposition = focus.join(',');
  36031. }
  36032. }
  36033. else {
  36034. // FIXME Change from Gradient fill to color fill
  36035. setColorAndOpacity(el, fill, style.opacity);
  36036. }
  36037. }
  36038. };
  36039. var updateStrokeNode = function (el, style) {
  36040. // if (style.lineJoin != null) {
  36041. // el.joinstyle = style.lineJoin;
  36042. // }
  36043. // if (style.miterLimit != null) {
  36044. // el.miterlimit = style.miterLimit * Z;
  36045. // }
  36046. // if (style.lineCap != null) {
  36047. // el.endcap = style.lineCap;
  36048. // }
  36049. if (style.lineDash != null) {
  36050. el.dashstyle = style.lineDash.join(' ');
  36051. }
  36052. if (style.stroke != null && !(style.stroke instanceof Gradient)) {
  36053. setColorAndOpacity(el, style.stroke, style.opacity);
  36054. }
  36055. };
  36056. var updateFillAndStroke = function (vmlEl, type, style, zrEl) {
  36057. var isFill = type == 'fill';
  36058. var el = vmlEl.getElementsByTagName(type)[0];
  36059. // Stroke must have lineWidth
  36060. if (style[type] != null && style[type] !== 'none' && (isFill || (!isFill && style.lineWidth))) {
  36061. vmlEl[isFill ? 'filled' : 'stroked'] = 'true';
  36062. // FIXME Remove before updating, or set `colors` will throw error
  36063. if (style[type] instanceof Gradient) {
  36064. remove(vmlEl, el);
  36065. }
  36066. if (!el) {
  36067. el = vmlCore.createNode(type);
  36068. }
  36069. isFill ? updateFillNode(el, style, zrEl) : updateStrokeNode(el, style);
  36070. append(vmlEl, el);
  36071. }
  36072. else {
  36073. vmlEl[isFill ? 'filled' : 'stroked'] = 'false';
  36074. remove(vmlEl, el);
  36075. }
  36076. };
  36077. var points = [[], [], []];
  36078. var pathDataToString = function (data, m) {
  36079. var M = CMD.M;
  36080. var C = CMD.C;
  36081. var L = CMD.L;
  36082. var A = CMD.A;
  36083. var Q = CMD.Q;
  36084. var str = [];
  36085. var nPoint;
  36086. var cmdStr;
  36087. var cmd;
  36088. var i;
  36089. var xi;
  36090. var yi;
  36091. for (i = 0; i < data.length;) {
  36092. cmd = data[i++];
  36093. cmdStr = '';
  36094. nPoint = 0;
  36095. switch (cmd) {
  36096. case M:
  36097. cmdStr = ' m ';
  36098. nPoint = 1;
  36099. xi = data[i++];
  36100. yi = data[i++];
  36101. points[0][0] = xi;
  36102. points[0][1] = yi;
  36103. break;
  36104. case L:
  36105. cmdStr = ' l ';
  36106. nPoint = 1;
  36107. xi = data[i++];
  36108. yi = data[i++];
  36109. points[0][0] = xi;
  36110. points[0][1] = yi;
  36111. break;
  36112. case Q:
  36113. case C:
  36114. cmdStr = ' c ';
  36115. nPoint = 3;
  36116. var x1 = data[i++];
  36117. var y1 = data[i++];
  36118. var x2 = data[i++];
  36119. var y2 = data[i++];
  36120. var x3;
  36121. var y3;
  36122. if (cmd === Q) {
  36123. // Convert quadratic to cubic using degree elevation
  36124. x3 = x2;
  36125. y3 = y2;
  36126. x2 = (x2 + 2 * x1) / 3;
  36127. y2 = (y2 + 2 * y1) / 3;
  36128. x1 = (xi + 2 * x1) / 3;
  36129. y1 = (yi + 2 * y1) / 3;
  36130. }
  36131. else {
  36132. x3 = data[i++];
  36133. y3 = data[i++];
  36134. }
  36135. points[0][0] = x1;
  36136. points[0][1] = y1;
  36137. points[1][0] = x2;
  36138. points[1][1] = y2;
  36139. points[2][0] = x3;
  36140. points[2][1] = y3;
  36141. xi = x3;
  36142. yi = y3;
  36143. break;
  36144. case A:
  36145. var x = 0;
  36146. var y = 0;
  36147. var sx = 1;
  36148. var sy = 1;
  36149. var angle = 0;
  36150. if (m) {
  36151. // Extract SRT from matrix
  36152. x = m[4];
  36153. y = m[5];
  36154. sx = sqrt(m[0] * m[0] + m[1] * m[1]);
  36155. sy = sqrt(m[2] * m[2] + m[3] * m[3]);
  36156. angle = Math.atan2(-m[1] / sy, m[0] / sx);
  36157. }
  36158. var cx = data[i++];
  36159. var cy = data[i++];
  36160. var rx = data[i++];
  36161. var ry = data[i++];
  36162. var startAngle = data[i++] + angle;
  36163. var endAngle = data[i++] + startAngle + angle;
  36164. // FIXME
  36165. // var psi = data[i++];
  36166. i++;
  36167. var clockwise = data[i++];
  36168. var x0 = cx + cos(startAngle) * rx;
  36169. var y0 = cy + sin(startAngle) * ry;
  36170. var x1 = cx + cos(endAngle) * rx;
  36171. var y1 = cy + sin(endAngle) * ry;
  36172. var type = clockwise ? ' wa ' : ' at ';
  36173. if (Math.abs(x0 - x1) < 1e-4) {
  36174. // IE won't render arches drawn counter clockwise if x0 == x1.
  36175. if (Math.abs(endAngle - startAngle) > 1e-2) {
  36176. // Offset x0 by 1/80 of a pixel. Use something
  36177. // that can be represented in binary
  36178. if (clockwise) {
  36179. x0 += 270 / Z;
  36180. }
  36181. }
  36182. else {
  36183. // Avoid case draw full circle
  36184. if (Math.abs(y0 - cy) < 1e-4) {
  36185. if ((clockwise && x0 < cx) || (!clockwise && x0 > cx)) {
  36186. y1 -= 270 / Z;
  36187. }
  36188. else {
  36189. y1 += 270 / Z;
  36190. }
  36191. }
  36192. else if ((clockwise && y0 < cy) || (!clockwise && y0 > cy)) {
  36193. x1 += 270 / Z;
  36194. }
  36195. else {
  36196. x1 -= 270 / Z;
  36197. }
  36198. }
  36199. }
  36200. str.push(
  36201. type,
  36202. round(((cx - rx) * sx + x) * Z - Z2), comma,
  36203. round(((cy - ry) * sy + y) * Z - Z2), comma,
  36204. round(((cx + rx) * sx + x) * Z - Z2), comma,
  36205. round(((cy + ry) * sy + y) * Z - Z2), comma,
  36206. round((x0 * sx + x) * Z - Z2), comma,
  36207. round((y0 * sy + y) * Z - Z2), comma,
  36208. round((x1 * sx + x) * Z - Z2), comma,
  36209. round((y1 * sy + y) * Z - Z2)
  36210. );
  36211. xi = x1;
  36212. yi = y1;
  36213. break;
  36214. case CMD.R:
  36215. var p0 = points[0];
  36216. var p1 = points[1];
  36217. // x0, y0
  36218. p0[0] = data[i++];
  36219. p0[1] = data[i++];
  36220. // x1, y1
  36221. p1[0] = p0[0] + data[i++];
  36222. p1[1] = p0[1] + data[i++];
  36223. if (m) {
  36224. applyTransform(p0, p0, m);
  36225. applyTransform(p1, p1, m);
  36226. }
  36227. p0[0] = round(p0[0] * Z - Z2);
  36228. p1[0] = round(p1[0] * Z - Z2);
  36229. p0[1] = round(p0[1] * Z - Z2);
  36230. p1[1] = round(p1[1] * Z - Z2);
  36231. str.push(
  36232. // x0, y0
  36233. ' m ', p0[0], comma, p0[1],
  36234. // x1, y0
  36235. ' l ', p1[0], comma, p0[1],
  36236. // x1, y1
  36237. ' l ', p1[0], comma, p1[1],
  36238. // x0, y1
  36239. ' l ', p0[0], comma, p1[1]
  36240. );
  36241. break;
  36242. case CMD.Z:
  36243. // FIXME Update xi, yi
  36244. str.push(' x ');
  36245. }
  36246. if (nPoint > 0) {
  36247. str.push(cmdStr);
  36248. for (var k = 0; k < nPoint; k++) {
  36249. var p = points[k];
  36250. m && applyTransform(p, p, m);
  36251. // 不 round 会非常慢
  36252. str.push(
  36253. round(p[0] * Z - Z2), comma, round(p[1] * Z - Z2),
  36254. k < nPoint - 1 ? comma : ''
  36255. );
  36256. }
  36257. }
  36258. }
  36259. return str.join('');
  36260. };
  36261. // Rewrite the original path method
  36262. Path.prototype.brushVML = function (vmlRoot) {
  36263. var style = this.style;
  36264. var vmlEl = this._vmlEl;
  36265. if (!vmlEl) {
  36266. vmlEl = vmlCore.createNode('shape');
  36267. initRootElStyle(vmlEl);
  36268. this._vmlEl = vmlEl;
  36269. }
  36270. updateFillAndStroke(vmlEl, 'fill', style, this);
  36271. updateFillAndStroke(vmlEl, 'stroke', style, this);
  36272. var m = this.transform;
  36273. var needTransform = m != null;
  36274. var strokeEl = vmlEl.getElementsByTagName('stroke')[0];
  36275. if (strokeEl) {
  36276. var lineWidth = style.lineWidth;
  36277. // Get the line scale.
  36278. // Determinant of this.m_ means how much the area is enlarged by the
  36279. // transformation. So its square root can be used as a scale factor
  36280. // for width.
  36281. if (needTransform && !style.strokeNoScale) {
  36282. var det = m[0] * m[3] - m[1] * m[2];
  36283. lineWidth *= sqrt(abs(det));
  36284. }
  36285. strokeEl.weight = lineWidth + 'px';
  36286. }
  36287. var path = this.path;
  36288. if (this.__dirtyPath) {
  36289. path.beginPath();
  36290. this.buildPath(path, this.shape);
  36291. path.toStatic();
  36292. this.__dirtyPath = false;
  36293. }
  36294. vmlEl.path = pathDataToString(path.data, this.transform);
  36295. vmlEl.style.zIndex = getZIndex(this.zlevel, this.z, this.z2);
  36296. // Append to root
  36297. append(vmlRoot, vmlEl);
  36298. // Text
  36299. if (style.text != null) {
  36300. this.drawRectText(vmlRoot, this.getBoundingRect());
  36301. }
  36302. else {
  36303. this.removeRectText(vmlRoot);
  36304. }
  36305. };
  36306. Path.prototype.onRemove = function (vmlRoot) {
  36307. remove(vmlRoot, this._vmlEl);
  36308. this.removeRectText(vmlRoot);
  36309. };
  36310. Path.prototype.onAdd = function (vmlRoot) {
  36311. append(vmlRoot, this._vmlEl);
  36312. this.appendRectText(vmlRoot);
  36313. };
  36314. /***************************************************
  36315. * IMAGE
  36316. **************************************************/
  36317. var isImage = function (img) {
  36318. // FIXME img instanceof Image 如果 img 是一个字符串的时候,IE8 下会报错
  36319. return (typeof img === 'object') && img.tagName && img.tagName.toUpperCase() === 'IMG';
  36320. // return img instanceof Image;
  36321. };
  36322. // Rewrite the original path method
  36323. ZImage.prototype.brushVML = function (vmlRoot) {
  36324. var style = this.style;
  36325. var image = style.image;
  36326. // Image original width, height
  36327. var ow;
  36328. var oh;
  36329. if (isImage(image)) {
  36330. var src = image.src;
  36331. if (src === this._imageSrc) {
  36332. ow = this._imageWidth;
  36333. oh = this._imageHeight;
  36334. }
  36335. else {
  36336. var imageRuntimeStyle = image.runtimeStyle;
  36337. var oldRuntimeWidth = imageRuntimeStyle.width;
  36338. var oldRuntimeHeight = imageRuntimeStyle.height;
  36339. imageRuntimeStyle.width = 'auto';
  36340. imageRuntimeStyle.height = 'auto';
  36341. // get the original size
  36342. ow = image.width;
  36343. oh = image.height;
  36344. // and remove overides
  36345. imageRuntimeStyle.width = oldRuntimeWidth;
  36346. imageRuntimeStyle.height = oldRuntimeHeight;
  36347. // Caching image original width, height and src
  36348. this._imageSrc = src;
  36349. this._imageWidth = ow;
  36350. this._imageHeight = oh;
  36351. }
  36352. image = src;
  36353. }
  36354. else {
  36355. if (image === this._imageSrc) {
  36356. ow = this._imageWidth;
  36357. oh = this._imageHeight;
  36358. }
  36359. }
  36360. if (!image) {
  36361. return;
  36362. }
  36363. var x = style.x || 0;
  36364. var y = style.y || 0;
  36365. var dw = style.width;
  36366. var dh = style.height;
  36367. var sw = style.sWidth;
  36368. var sh = style.sHeight;
  36369. var sx = style.sx || 0;
  36370. var sy = style.sy || 0;
  36371. var hasCrop = sw && sh;
  36372. var vmlEl = this._vmlEl;
  36373. if (!vmlEl) {
  36374. // FIXME 使用 group 在 left, top 都不是 0 的时候就无法显示了。
  36375. // vmlEl = vmlCore.createNode('group');
  36376. vmlEl = vmlCore.doc.createElement('div');
  36377. initRootElStyle(vmlEl);
  36378. this._vmlEl = vmlEl;
  36379. }
  36380. var vmlElStyle = vmlEl.style;
  36381. var hasRotation = false;
  36382. var m;
  36383. var scaleX = 1;
  36384. var scaleY = 1;
  36385. if (this.transform) {
  36386. m = this.transform;
  36387. scaleX = sqrt(m[0] * m[0] + m[1] * m[1]);
  36388. scaleY = sqrt(m[2] * m[2] + m[3] * m[3]);
  36389. hasRotation = m[1] || m[2];
  36390. }
  36391. if (hasRotation) {
  36392. // If filters are necessary (rotation exists), create them
  36393. // filters are bog-slow, so only create them if abbsolutely necessary
  36394. // The following check doesn't account for skews (which don't exist
  36395. // in the canvas spec (yet) anyway.
  36396. // From excanvas
  36397. var p0 = [x, y];
  36398. var p1 = [x + dw, y];
  36399. var p2 = [x, y + dh];
  36400. var p3 = [x + dw, y + dh];
  36401. applyTransform(p0, p0, m);
  36402. applyTransform(p1, p1, m);
  36403. applyTransform(p2, p2, m);
  36404. applyTransform(p3, p3, m);
  36405. var maxX = mathMax(p0[0], p1[0], p2[0], p3[0]);
  36406. var maxY = mathMax(p0[1], p1[1], p2[1], p3[1]);
  36407. var transformFilter = [];
  36408. transformFilter.push('M11=', m[0] / scaleX, comma,
  36409. 'M12=', m[2] / scaleY, comma,
  36410. 'M21=', m[1] / scaleX, comma,
  36411. 'M22=', m[3] / scaleY, comma,
  36412. 'Dx=', round(x * scaleX + m[4]), comma,
  36413. 'Dy=', round(y * scaleY + m[5]));
  36414. vmlElStyle.padding = '0 ' + round(maxX) + 'px ' + round(maxY) + 'px 0';
  36415. // FIXME DXImageTransform 在 IE11 的兼容模式下不起作用
  36416. vmlElStyle.filter = imageTransformPrefix + '.Matrix('
  36417. + transformFilter.join('') + ', SizingMethod=clip)';
  36418. }
  36419. else {
  36420. if (m) {
  36421. x = x * scaleX + m[4];
  36422. y = y * scaleY + m[5];
  36423. }
  36424. vmlElStyle.filter = '';
  36425. vmlElStyle.left = round(x) + 'px';
  36426. vmlElStyle.top = round(y) + 'px';
  36427. }
  36428. var imageEl = this._imageEl;
  36429. var cropEl = this._cropEl;
  36430. if (!imageEl) {
  36431. imageEl = vmlCore.doc.createElement('div');
  36432. this._imageEl = imageEl;
  36433. }
  36434. var imageELStyle = imageEl.style;
  36435. if (hasCrop) {
  36436. // Needs know image original width and height
  36437. if (! (ow && oh)) {
  36438. var tmpImage = new Image();
  36439. var self = this;
  36440. tmpImage.onload = function () {
  36441. tmpImage.onload = null;
  36442. ow = tmpImage.width;
  36443. oh = tmpImage.height;
  36444. // Adjust image width and height to fit the ratio destinationSize / sourceSize
  36445. imageELStyle.width = round(scaleX * ow * dw / sw) + 'px';
  36446. imageELStyle.height = round(scaleY * oh * dh / sh) + 'px';
  36447. // Caching image original width, height and src
  36448. self._imageWidth = ow;
  36449. self._imageHeight = oh;
  36450. self._imageSrc = image;
  36451. };
  36452. tmpImage.src = image;
  36453. }
  36454. else {
  36455. imageELStyle.width = round(scaleX * ow * dw / sw) + 'px';
  36456. imageELStyle.height = round(scaleY * oh * dh / sh) + 'px';
  36457. }
  36458. if (! cropEl) {
  36459. cropEl = vmlCore.doc.createElement('div');
  36460. cropEl.style.overflow = 'hidden';
  36461. this._cropEl = cropEl;
  36462. }
  36463. var cropElStyle = cropEl.style;
  36464. cropElStyle.width = round((dw + sx * dw / sw) * scaleX);
  36465. cropElStyle.height = round((dh + sy * dh / sh) * scaleY);
  36466. cropElStyle.filter = imageTransformPrefix + '.Matrix(Dx='
  36467. + (-sx * dw / sw * scaleX) + ',Dy=' + (-sy * dh / sh * scaleY) + ')';
  36468. if (! cropEl.parentNode) {
  36469. vmlEl.appendChild(cropEl);
  36470. }
  36471. if (imageEl.parentNode != cropEl) {
  36472. cropEl.appendChild(imageEl);
  36473. }
  36474. }
  36475. else {
  36476. imageELStyle.width = round(scaleX * dw) + 'px';
  36477. imageELStyle.height = round(scaleY * dh) + 'px';
  36478. vmlEl.appendChild(imageEl);
  36479. if (cropEl && cropEl.parentNode) {
  36480. vmlEl.removeChild(cropEl);
  36481. this._cropEl = null;
  36482. }
  36483. }
  36484. var filterStr = '';
  36485. var alpha = style.opacity;
  36486. if (alpha < 1) {
  36487. filterStr += '.Alpha(opacity=' + round(alpha * 100) + ') ';
  36488. }
  36489. filterStr += imageTransformPrefix + '.AlphaImageLoader(src=' + image + ', SizingMethod=scale)';
  36490. imageELStyle.filter = filterStr;
  36491. vmlEl.style.zIndex = getZIndex(this.zlevel, this.z, this.z2);
  36492. // Append to root
  36493. append(vmlRoot, vmlEl);
  36494. // Text
  36495. if (style.text != null) {
  36496. this.drawRectText(vmlRoot, this.getBoundingRect());
  36497. }
  36498. };
  36499. ZImage.prototype.onRemove = function (vmlRoot) {
  36500. remove(vmlRoot, this._vmlEl);
  36501. this._vmlEl = null;
  36502. this._cropEl = null;
  36503. this._imageEl = null;
  36504. this.removeRectText(vmlRoot);
  36505. };
  36506. ZImage.prototype.onAdd = function (vmlRoot) {
  36507. append(vmlRoot, this._vmlEl);
  36508. this.appendRectText(vmlRoot);
  36509. };
  36510. /***************************************************
  36511. * TEXT
  36512. **************************************************/
  36513. var DEFAULT_STYLE_NORMAL = 'normal';
  36514. var fontStyleCache = {};
  36515. var fontStyleCacheCount = 0;
  36516. var MAX_FONT_CACHE_SIZE = 100;
  36517. var fontEl = document.createElement('div');
  36518. var getFontStyle = function (fontString) {
  36519. var fontStyle = fontStyleCache[fontString];
  36520. if (!fontStyle) {
  36521. // Clear cache
  36522. if (fontStyleCacheCount > MAX_FONT_CACHE_SIZE) {
  36523. fontStyleCacheCount = 0;
  36524. fontStyleCache = {};
  36525. }
  36526. var style = fontEl.style;
  36527. var fontFamily;
  36528. try {
  36529. style.font = fontString;
  36530. fontFamily = style.fontFamily.split(',')[0];
  36531. }
  36532. catch (e) {
  36533. }
  36534. fontStyle = {
  36535. style: style.fontStyle || DEFAULT_STYLE_NORMAL,
  36536. variant: style.fontVariant || DEFAULT_STYLE_NORMAL,
  36537. weight: style.fontWeight || DEFAULT_STYLE_NORMAL,
  36538. size: parseFloat(style.fontSize || 12) | 0,
  36539. family: fontFamily || 'Microsoft YaHei'
  36540. };
  36541. fontStyleCache[fontString] = fontStyle;
  36542. fontStyleCacheCount++;
  36543. }
  36544. return fontStyle;
  36545. };
  36546. var textMeasureEl;
  36547. // Overwrite measure text method
  36548. textContain.measureText = function (text, textFont) {
  36549. var doc = vmlCore.doc;
  36550. if (!textMeasureEl) {
  36551. textMeasureEl = doc.createElement('div');
  36552. textMeasureEl.style.cssText = 'position:absolute;top:-20000px;left:0;'
  36553. + 'padding:0;margin:0;border:none;white-space:pre;';
  36554. vmlCore.doc.body.appendChild(textMeasureEl);
  36555. }
  36556. try {
  36557. textMeasureEl.style.font = textFont;
  36558. } catch (ex) {
  36559. // Ignore failures to set to invalid font.
  36560. }
  36561. textMeasureEl.innerHTML = '';
  36562. // Don't use innerHTML or innerText because they allow markup/whitespace.
  36563. textMeasureEl.appendChild(doc.createTextNode(text));
  36564. return {
  36565. width: textMeasureEl.offsetWidth
  36566. };
  36567. };
  36568. var tmpRect = new BoundingRect();
  36569. var drawRectText = function (vmlRoot, rect, textRect, fromTextEl) {
  36570. var style = this.style;
  36571. var text = style.text;
  36572. // Convert to string
  36573. text != null && (text += '');
  36574. if (!text) {
  36575. return;
  36576. }
  36577. var x;
  36578. var y;
  36579. var align = style.textAlign;
  36580. var fontStyle = getFontStyle(style.textFont);
  36581. // FIXME encodeHtmlAttribute ?
  36582. var font = fontStyle.style + ' ' + fontStyle.variant + ' ' + fontStyle.weight + ' '
  36583. + fontStyle.size + 'px "' + fontStyle.family + '"';
  36584. var baseline = style.textBaseline;
  36585. var verticalAlign = style.textVerticalAlign;
  36586. textRect = textRect || textContain.getBoundingRect(text, font, align, baseline);
  36587. // Transform rect to view space
  36588. var m = this.transform;
  36589. // Ignore transform for text in other element
  36590. if (m && !fromTextEl) {
  36591. tmpRect.copy(rect);
  36592. tmpRect.applyTransform(m);
  36593. rect = tmpRect;
  36594. }
  36595. if (!fromTextEl) {
  36596. var textPosition = style.textPosition;
  36597. var distance = style.textDistance;
  36598. // Text position represented by coord
  36599. if (textPosition instanceof Array) {
  36600. x = rect.x + parsePercent(textPosition[0], rect.width);
  36601. y = rect.y + parsePercent(textPosition[1], rect.height);
  36602. align = align || 'left';
  36603. baseline = baseline || 'top';
  36604. }
  36605. else {
  36606. var res = textContain.adjustTextPositionOnRect(
  36607. textPosition, rect, textRect, distance
  36608. );
  36609. x = res.x;
  36610. y = res.y;
  36611. // Default align and baseline when has textPosition
  36612. align = align || res.textAlign;
  36613. baseline = baseline || res.textBaseline;
  36614. }
  36615. }
  36616. else {
  36617. x = rect.x;
  36618. y = rect.y;
  36619. }
  36620. if (verticalAlign) {
  36621. switch (verticalAlign) {
  36622. case 'middle':
  36623. y -= textRect.height / 2;
  36624. break;
  36625. case 'bottom':
  36626. y -= textRect.height;
  36627. break;
  36628. // 'top'
  36629. }
  36630. // Ignore baseline
  36631. baseline = 'top';
  36632. }
  36633. var fontSize = fontStyle.size;
  36634. // 1.75 is an arbitrary number, as there is no info about the text baseline
  36635. switch (baseline) {
  36636. case 'hanging':
  36637. case 'top':
  36638. y += fontSize / 1.75;
  36639. break;
  36640. case 'middle':
  36641. break;
  36642. default:
  36643. // case null:
  36644. // case 'alphabetic':
  36645. // case 'ideographic':
  36646. // case 'bottom':
  36647. y -= fontSize / 2.25;
  36648. break;
  36649. }
  36650. switch (align) {
  36651. case 'left':
  36652. break;
  36653. case 'center':
  36654. x -= textRect.width / 2;
  36655. break;
  36656. case 'right':
  36657. x -= textRect.width;
  36658. break;
  36659. // case 'end':
  36660. // align = elementStyle.direction == 'ltr' ? 'right' : 'left';
  36661. // break;
  36662. // case 'start':
  36663. // align = elementStyle.direction == 'rtl' ? 'right' : 'left';
  36664. // break;
  36665. // default:
  36666. // align = 'left';
  36667. }
  36668. var createNode = vmlCore.createNode;
  36669. var textVmlEl = this._textVmlEl;
  36670. var pathEl;
  36671. var textPathEl;
  36672. var skewEl;
  36673. if (!textVmlEl) {
  36674. textVmlEl = createNode('line');
  36675. pathEl = createNode('path');
  36676. textPathEl = createNode('textpath');
  36677. skewEl = createNode('skew');
  36678. // FIXME Why here is not cammel case
  36679. // Align 'center' seems wrong
  36680. textPathEl.style['v-text-align'] = 'left';
  36681. initRootElStyle(textVmlEl);
  36682. pathEl.textpathok = true;
  36683. textPathEl.on = true;
  36684. textVmlEl.from = '0 0';
  36685. textVmlEl.to = '1000 0.05';
  36686. append(textVmlEl, skewEl);
  36687. append(textVmlEl, pathEl);
  36688. append(textVmlEl, textPathEl);
  36689. this._textVmlEl = textVmlEl;
  36690. }
  36691. else {
  36692. // 这里是在前面 appendChild 保证顺序的前提下
  36693. skewEl = textVmlEl.firstChild;
  36694. pathEl = skewEl.nextSibling;
  36695. textPathEl = pathEl.nextSibling;
  36696. }
  36697. var coords = [x, y];
  36698. var textVmlElStyle = textVmlEl.style;
  36699. // Ignore transform for text in other element
  36700. if (m && fromTextEl) {
  36701. applyTransform(coords, coords, m);
  36702. skewEl.on = true;
  36703. skewEl.matrix = m[0].toFixed(3) + comma + m[2].toFixed(3) + comma +
  36704. m[1].toFixed(3) + comma + m[3].toFixed(3) + ',0,0';
  36705. // Text position
  36706. skewEl.offset = (round(coords[0]) || 0) + ',' + (round(coords[1]) || 0);
  36707. // Left top point as origin
  36708. skewEl.origin = '0 0';
  36709. textVmlElStyle.left = '0px';
  36710. textVmlElStyle.top = '0px';
  36711. }
  36712. else {
  36713. skewEl.on = false;
  36714. textVmlElStyle.left = round(x) + 'px';
  36715. textVmlElStyle.top = round(y) + 'px';
  36716. }
  36717. textPathEl.string = encodeHtmlAttribute(text);
  36718. // TODO
  36719. try {
  36720. textPathEl.style.font = font;
  36721. }
  36722. // Error font format
  36723. catch (e) {}
  36724. updateFillAndStroke(textVmlEl, 'fill', {
  36725. fill: fromTextEl ? style.fill : style.textFill,
  36726. opacity: style.opacity
  36727. }, this);
  36728. updateFillAndStroke(textVmlEl, 'stroke', {
  36729. stroke: fromTextEl ? style.stroke : style.textStroke,
  36730. opacity: style.opacity,
  36731. lineDash: style.lineDash
  36732. }, this);
  36733. textVmlEl.style.zIndex = getZIndex(this.zlevel, this.z, this.z2);
  36734. // Attached to root
  36735. append(vmlRoot, textVmlEl);
  36736. };
  36737. var removeRectText = function (vmlRoot) {
  36738. remove(vmlRoot, this._textVmlEl);
  36739. this._textVmlEl = null;
  36740. };
  36741. var appendRectText = function (vmlRoot) {
  36742. append(vmlRoot, this._textVmlEl);
  36743. };
  36744. var list = [RectText, Displayable, ZImage, Path, Text];
  36745. // In case Displayable has been mixed in RectText
  36746. for (var i = 0; i < list.length; i++) {
  36747. var proto = list[i].prototype;
  36748. proto.drawRectText = drawRectText;
  36749. proto.removeRectText = removeRectText;
  36750. proto.appendRectText = appendRectText;
  36751. }
  36752. Text.prototype.brushVML = function (vmlRoot) {
  36753. var style = this.style;
  36754. if (style.text != null) {
  36755. this.drawRectText(vmlRoot, {
  36756. x: style.x || 0, y: style.y || 0,
  36757. width: 0, height: 0
  36758. }, this.getBoundingRect(), true);
  36759. }
  36760. else {
  36761. this.removeRectText(vmlRoot);
  36762. }
  36763. };
  36764. Text.prototype.onRemove = function (vmlRoot) {
  36765. this.removeRectText(vmlRoot);
  36766. };
  36767. Text.prototype.onAdd = function (vmlRoot) {
  36768. this.appendRectText(vmlRoot);
  36769. };
  36770. }
  36771. /***/ },
  36772. /* 393 */
  36773. /***/ function(module, exports, __webpack_require__) {
  36774. if (!__webpack_require__(2).canvasSupported) {
  36775. var urn = 'urn:schemas-microsoft-com:vml';
  36776. var createNode;
  36777. var win = window;
  36778. var doc = win.document;
  36779. var vmlInited = false;
  36780. try {
  36781. !doc.namespaces.zrvml && doc.namespaces.add('zrvml', urn);
  36782. createNode = function (tagName) {
  36783. return doc.createElement('<zrvml:' + tagName + ' class="zrvml">');
  36784. };
  36785. }
  36786. catch (e) {
  36787. createNode = function (tagName) {
  36788. return doc.createElement('<' + tagName + ' xmlns="' + urn + '" class="zrvml">');
  36789. };
  36790. }
  36791. // From raphael
  36792. var initVML = function () {
  36793. if (vmlInited) {
  36794. return;
  36795. }
  36796. vmlInited = true;
  36797. var styleSheets = doc.styleSheets;
  36798. if (styleSheets.length < 31) {
  36799. doc.createStyleSheet().addRule('.zrvml', 'behavior:url(#default#VML)');
  36800. }
  36801. else {
  36802. // http://msdn.microsoft.com/en-us/library/ms531194%28VS.85%29.aspx
  36803. styleSheets[0].addRule('.zrvml', 'behavior:url(#default#VML)');
  36804. }
  36805. };
  36806. // Not useing return to avoid error when converting to CommonJS module
  36807. module.exports = {
  36808. doc: doc,
  36809. initVML: initVML,
  36810. createNode: createNode
  36811. };
  36812. }
  36813. /***/ },
  36814. /* 394 */
  36815. /***/ function(module, exports, __webpack_require__) {
  36816. /**
  36817. * VML Painter.
  36818. *
  36819. * @module zrender/vml/Painter
  36820. */
  36821. var zrLog = __webpack_require__(40);
  36822. var vmlCore = __webpack_require__(393);
  36823. function parseInt10(val) {
  36824. return parseInt(val, 10);
  36825. }
  36826. /**
  36827. * @alias module:zrender/vml/Painter
  36828. */
  36829. function VMLPainter(root, storage) {
  36830. vmlCore.initVML();
  36831. this.root = root;
  36832. this.storage = storage;
  36833. var vmlViewport = document.createElement('div');
  36834. var vmlRoot = document.createElement('div');
  36835. vmlViewport.style.cssText = 'display:inline-block;overflow:hidden;position:relative;width:300px;height:150px;';
  36836. vmlRoot.style.cssText = 'position:absolute;left:0;top:0;';
  36837. root.appendChild(vmlViewport);
  36838. this._vmlRoot = vmlRoot;
  36839. this._vmlViewport = vmlViewport;
  36840. this.resize();
  36841. // Modify storage
  36842. var oldDelFromMap = storage.delFromMap;
  36843. var oldAddToMap = storage.addToMap;
  36844. storage.delFromMap = function (elId) {
  36845. var el = storage.get(elId);
  36846. oldDelFromMap.call(storage, elId);
  36847. if (el) {
  36848. el.onRemove && el.onRemove(vmlRoot);
  36849. }
  36850. };
  36851. storage.addToMap = function (el) {
  36852. // Displayable already has a vml node
  36853. el.onAdd && el.onAdd(vmlRoot);
  36854. oldAddToMap.call(storage, el);
  36855. };
  36856. this._firstPaint = true;
  36857. }
  36858. VMLPainter.prototype = {
  36859. constructor: VMLPainter,
  36860. /**
  36861. * @return {HTMLDivElement}
  36862. */
  36863. getViewportRoot: function () {
  36864. return this._vmlViewport;
  36865. },
  36866. /**
  36867. * 刷新
  36868. */
  36869. refresh: function () {
  36870. var list = this.storage.getDisplayList(true, true);
  36871. this._paintList(list);
  36872. },
  36873. _paintList: function (list) {
  36874. var vmlRoot = this._vmlRoot;
  36875. for (var i = 0; i < list.length; i++) {
  36876. var el = list[i];
  36877. if (el.invisible || el.ignore) {
  36878. if (!el.__alreadyNotVisible) {
  36879. el.onRemove(vmlRoot);
  36880. }
  36881. // Set as already invisible
  36882. el.__alreadyNotVisible = true;
  36883. }
  36884. else {
  36885. if (el.__alreadyNotVisible) {
  36886. el.onAdd(vmlRoot);
  36887. }
  36888. el.__alreadyNotVisible = false;
  36889. if (el.__dirty) {
  36890. el.beforeBrush && el.beforeBrush();
  36891. (el.brushVML || el.brush).call(el, vmlRoot);
  36892. el.afterBrush && el.afterBrush();
  36893. }
  36894. }
  36895. el.__dirty = false;
  36896. }
  36897. if (this._firstPaint) {
  36898. // Detached from document at first time
  36899. // to avoid page refreshing too many times
  36900. // FIXME 如果每次都先 removeChild 可能会导致一些填充和描边的效果改变
  36901. this._vmlViewport.appendChild(vmlRoot);
  36902. this._firstPaint = false;
  36903. }
  36904. },
  36905. resize: function (width, height) {
  36906. var width = width == null ? this._getWidth() : width;
  36907. var height = height == null ? this._getHeight() : height;
  36908. if (this._width != width || this._height != height) {
  36909. this._width = width;
  36910. this._height = height;
  36911. var vmlViewportStyle = this._vmlViewport.style;
  36912. vmlViewportStyle.width = width + 'px';
  36913. vmlViewportStyle.height = height + 'px';
  36914. }
  36915. },
  36916. dispose: function () {
  36917. this.root.innerHTML = '';
  36918. this._vmlRoot =
  36919. this._vmlViewport =
  36920. this.storage = null;
  36921. },
  36922. getWidth: function () {
  36923. return this._width;
  36924. },
  36925. getHeight: function () {
  36926. return this._height;
  36927. },
  36928. clear: function () {
  36929. if (this._vmlViewport) {
  36930. this.root.removeChild(this._vmlViewport);
  36931. }
  36932. },
  36933. _getWidth: function () {
  36934. var root = this.root;
  36935. var stl = root.currentStyle;
  36936. return ((root.clientWidth || parseInt10(stl.width))
  36937. - parseInt10(stl.paddingLeft)
  36938. - parseInt10(stl.paddingRight)) | 0;
  36939. },
  36940. _getHeight: function () {
  36941. var root = this.root;
  36942. var stl = root.currentStyle;
  36943. return ((root.clientHeight || parseInt10(stl.height))
  36944. - parseInt10(stl.paddingTop)
  36945. - parseInt10(stl.paddingBottom)) | 0;
  36946. }
  36947. };
  36948. // Not supported methods
  36949. function createMethodNotSupport(method) {
  36950. return function () {
  36951. zrLog('In IE8.0 VML mode painter not support method "' + method + '"');
  36952. };
  36953. }
  36954. var notSupportedMethods = [
  36955. 'getLayer', 'insertLayer', 'eachLayer', 'eachBuildinLayer', 'eachOtherLayer', 'getLayers',
  36956. 'modLayer', 'delLayer', 'clearLayer', 'toDataURL', 'pathToImage'
  36957. ];
  36958. for (var i = 0; i < notSupportedMethods.length; i++) {
  36959. var name = notSupportedMethods[i];
  36960. VMLPainter.prototype[name] = createMethodNotSupport(name);
  36961. }
  36962. module.exports = VMLPainter;
  36963. /***/ }
  36964. /******/ ])
  36965. });
  36966. ;