echarts.common.js 1.1 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230
  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__(92);
  50. __webpack_require__(128);
  51. __webpack_require__(133);
  52. __webpack_require__(142);
  53. __webpack_require__(271);
  54. __webpack_require__(265);
  55. __webpack_require__(107);
  56. __webpack_require__(289);
  57. __webpack_require__(319);
  58. __webpack_require__(323);
  59. __webpack_require__(290);
  60. __webpack_require__(335);
  61. __webpack_require__(349);
  62. /***/ },
  63. /* 1 */
  64. /***/ function(module, exports, __webpack_require__) {
  65. /*!
  66. * ECharts, a javascript interactive chart library.
  67. *
  68. * Copyright (c) 2015, Baidu Inc.
  69. * All rights reserved.
  70. *
  71. * LICENSE
  72. * https://github.com/ecomfe/echarts/blob/master/LICENSE.txt
  73. */
  74. /**
  75. * @module echarts
  76. */
  77. var GlobalModel = __webpack_require__(2);
  78. var ExtensionAPI = __webpack_require__(24);
  79. var CoordinateSystemManager = __webpack_require__(25);
  80. var OptionManager = __webpack_require__(26);
  81. var ComponentModel = __webpack_require__(19);
  82. var SeriesModel = __webpack_require__(27);
  83. var ComponentView = __webpack_require__(28);
  84. var ChartView = __webpack_require__(41);
  85. var graphic = __webpack_require__(42);
  86. var zrender = __webpack_require__(78);
  87. var zrUtil = __webpack_require__(3);
  88. var colorTool = __webpack_require__(38);
  89. var env = __webpack_require__(79);
  90. var Eventful = __webpack_require__(32);
  91. var each = zrUtil.each;
  92. var VISUAL_CODING_STAGES = ['echarts', 'chart', 'component'];
  93. // TODO Transform first or filter first
  94. var PROCESSOR_STAGES = ['transform', 'filter', 'statistic'];
  95. function createRegisterEventWithLowercaseName(method) {
  96. return function (eventName, handler, context) {
  97. // Event name is all lowercase
  98. eventName = eventName && eventName.toLowerCase();
  99. Eventful.prototype[method].call(this, eventName, handler, context);
  100. };
  101. }
  102. /**
  103. * @module echarts~MessageCenter
  104. */
  105. function MessageCenter() {
  106. Eventful.call(this);
  107. }
  108. MessageCenter.prototype.on = createRegisterEventWithLowercaseName('on');
  109. MessageCenter.prototype.off = createRegisterEventWithLowercaseName('off');
  110. MessageCenter.prototype.one = createRegisterEventWithLowercaseName('one');
  111. zrUtil.mixin(MessageCenter, Eventful);
  112. /**
  113. * @module echarts~ECharts
  114. */
  115. function ECharts (dom, theme, opts) {
  116. opts = opts || {};
  117. // Get theme by name
  118. if (typeof theme === 'string') {
  119. theme = themeStorage[theme];
  120. }
  121. if (theme) {
  122. each(optionPreprocessorFuncs, function (preProcess) {
  123. preProcess(theme);
  124. });
  125. }
  126. /**
  127. * @type {string}
  128. */
  129. this.id;
  130. /**
  131. * Group id
  132. * @type {string}
  133. */
  134. this.group;
  135. /**
  136. * @type {HTMLDomElement}
  137. * @private
  138. */
  139. this._dom = dom;
  140. /**
  141. * @type {module:zrender/ZRender}
  142. * @private
  143. */
  144. this._zr = zrender.init(dom, {
  145. renderer: opts.renderer || 'canvas',
  146. devicePixelRatio: opts.devicePixelRatio
  147. });
  148. /**
  149. * @type {Object}
  150. * @private
  151. */
  152. this._theme = zrUtil.clone(theme);
  153. /**
  154. * @type {Array.<module:echarts/view/Chart>}
  155. * @private
  156. */
  157. this._chartsViews = [];
  158. /**
  159. * @type {Object.<string, module:echarts/view/Chart>}
  160. * @private
  161. */
  162. this._chartsMap = {};
  163. /**
  164. * @type {Array.<module:echarts/view/Component>}
  165. * @private
  166. */
  167. this._componentsViews = [];
  168. /**
  169. * @type {Object.<string, module:echarts/view/Component>}
  170. * @private
  171. */
  172. this._componentsMap = {};
  173. /**
  174. * @type {module:echarts/ExtensionAPI}
  175. * @private
  176. */
  177. this._api = new ExtensionAPI(this);
  178. /**
  179. * @type {module:echarts/CoordinateSystem}
  180. * @private
  181. */
  182. this._coordSysMgr = new CoordinateSystemManager();
  183. Eventful.call(this);
  184. /**
  185. * @type {module:echarts~MessageCenter}
  186. * @private
  187. */
  188. this._messageCenter = new MessageCenter();
  189. // Init mouse events
  190. this._initEvents();
  191. // In case some people write `window.onresize = chart.resize`
  192. this.resize = zrUtil.bind(this.resize, this);
  193. }
  194. var echartsProto = ECharts.prototype;
  195. /**
  196. * @return {HTMLDomElement}
  197. */
  198. echartsProto.getDom = function () {
  199. return this._dom;
  200. };
  201. /**
  202. * @return {module:zrender~ZRender}
  203. */
  204. echartsProto.getZr = function () {
  205. return this._zr;
  206. };
  207. /**
  208. * @param {Object} option
  209. * @param {boolean} notMerge
  210. * @param {boolean} [notRefreshImmediately=false] Useful when setOption frequently.
  211. */
  212. echartsProto.setOption = function (option, notMerge, notRefreshImmediately) {
  213. if (!this._model || notMerge) {
  214. this._model = new GlobalModel(
  215. null, null, this._theme, new OptionManager(this._api)
  216. );
  217. }
  218. this._model.setOption(option, optionPreprocessorFuncs);
  219. updateMethods.prepareAndUpdate.call(this);
  220. !notRefreshImmediately && this._zr.refreshImmediately();
  221. };
  222. /**
  223. * @DEPRECATED
  224. */
  225. echartsProto.setTheme = function () {
  226. console.log('ECharts#setTheme() is DEPRECATED in ECharts 3.0');
  227. };
  228. /**
  229. * @return {module:echarts/model/Global}
  230. */
  231. echartsProto.getModel = function () {
  232. return this._model;
  233. };
  234. /**
  235. * @return {Object}
  236. */
  237. echartsProto.getOption = function () {
  238. return this._model.getOption();
  239. };
  240. /**
  241. * @return {number}
  242. */
  243. echartsProto.getWidth = function () {
  244. return this._zr.getWidth();
  245. };
  246. /**
  247. * @return {number}
  248. */
  249. echartsProto.getHeight = function () {
  250. return this._zr.getHeight();
  251. };
  252. /**
  253. * Get canvas which has all thing rendered
  254. * @param {Object} opts
  255. * @param {string} [opts.backgroundColor]
  256. */
  257. echartsProto.getRenderedCanvas = function (opts) {
  258. if (!env.canvasSupported) {
  259. return;
  260. }
  261. opts = opts || {};
  262. opts.pixelRatio = opts.pixelRatio || 1;
  263. opts.backgroundColor = opts.backgroundColor
  264. || this._model.get('backgroundColor');
  265. var zr = this._zr;
  266. var list = zr.storage.getDisplayList();
  267. // Stop animations
  268. zrUtil.each(list, function (el) {
  269. el.stopAnimation(true);
  270. });
  271. return zr.painter.getRenderedCanvas(opts);
  272. };
  273. /**
  274. * @return {string}
  275. * @param {Object} opts
  276. * @param {string} [opts.type='png']
  277. * @param {string} [opts.pixelRatio=1]
  278. * @param {string} [opts.backgroundColor]
  279. */
  280. echartsProto.getDataURL = function (opts) {
  281. opts = opts || {};
  282. var excludeComponents = opts.excludeComponents;
  283. var ecModel = this._model;
  284. var excludesComponentViews = [];
  285. var self = this;
  286. each(excludeComponents, function (componentType) {
  287. ecModel.eachComponent({
  288. mainType: componentType
  289. }, function (component) {
  290. var view = self._componentsMap[component.__viewId];
  291. if (!view.group.ignore) {
  292. excludesComponentViews.push(view);
  293. view.group.ignore = true;
  294. }
  295. });
  296. });
  297. var url = this.getRenderedCanvas(opts).toDataURL(
  298. 'image/' + (opts && opts.type || 'png')
  299. );
  300. each(excludesComponentViews, function (view) {
  301. view.group.ignore = false;
  302. });
  303. return url;
  304. };
  305. /**
  306. * @return {string}
  307. * @param {Object} opts
  308. * @param {string} [opts.type='png']
  309. * @param {string} [opts.pixelRatio=1]
  310. * @param {string} [opts.backgroundColor]
  311. */
  312. echartsProto.getConnectedDataURL = function (opts) {
  313. if (!env.canvasSupported) {
  314. return;
  315. }
  316. var groupId = this.group;
  317. var mathMin = Math.min;
  318. var mathMax = Math.max;
  319. var MAX_NUMBER = Infinity;
  320. if (connectedGroups[groupId]) {
  321. var left = MAX_NUMBER;
  322. var top = MAX_NUMBER;
  323. var right = -MAX_NUMBER;
  324. var bottom = -MAX_NUMBER;
  325. var canvasList = [];
  326. var dpr = (opts && opts.pixelRatio) || 1;
  327. for (var id in instances) {
  328. var chart = instances[id];
  329. if (chart.group === groupId) {
  330. var canvas = chart.getRenderedCanvas(
  331. zrUtil.clone(opts)
  332. );
  333. var boundingRect = chart.getDom().getBoundingClientRect();
  334. left = mathMin(boundingRect.left, left);
  335. top = mathMin(boundingRect.top, top);
  336. right = mathMax(boundingRect.right, right);
  337. bottom = mathMax(boundingRect.bottom, bottom);
  338. canvasList.push({
  339. dom: canvas,
  340. left: boundingRect.left,
  341. top: boundingRect.top
  342. });
  343. }
  344. }
  345. left *= dpr;
  346. top *= dpr;
  347. right *= dpr;
  348. bottom *= dpr;
  349. var width = right - left;
  350. var height = bottom - top;
  351. var targetCanvas = zrUtil.createCanvas();
  352. targetCanvas.width = width;
  353. targetCanvas.height = height;
  354. var zr = zrender.init(targetCanvas);
  355. each(canvasList, function (item) {
  356. var img = new graphic.Image({
  357. style: {
  358. x: item.left * dpr - left,
  359. y: item.top * dpr - top,
  360. image: item.dom
  361. }
  362. });
  363. zr.add(img);
  364. });
  365. zr.refreshImmediately();
  366. return targetCanvas.toDataURL('image/' + (opts && opts.type || 'png'));
  367. }
  368. else {
  369. return this.getDataURL(opts);
  370. }
  371. };
  372. var updateMethods = {
  373. /**
  374. * @param {Object} payload
  375. * @private
  376. */
  377. update: function (payload) {
  378. // console.time && console.time('update');
  379. var ecModel = this._model;
  380. var api = this._api;
  381. var coordSysMgr = this._coordSysMgr;
  382. // update before setOption
  383. if (!ecModel) {
  384. return;
  385. }
  386. // Fixme First time update ?
  387. ecModel.restoreData();
  388. // TODO
  389. // Save total ecModel here for undo/redo (after restoring data and before processing data).
  390. // Undo (restoration of total ecModel) can be carried out in 'action' or outside API call.
  391. // Create new coordinate system each update
  392. // In LineView may save the old coordinate system and use it to get the orignal point
  393. coordSysMgr.create(this._model, this._api);
  394. processData.call(this, ecModel, api);
  395. stackSeriesData.call(this, ecModel);
  396. coordSysMgr.update(ecModel, api);
  397. doLayout.call(this, ecModel, payload);
  398. doVisualCoding.call(this, ecModel, payload);
  399. doRender.call(this, ecModel, payload);
  400. // Set background
  401. var backgroundColor = ecModel.get('backgroundColor') || 'transparent';
  402. var painter = this._zr.painter;
  403. // TODO all use clearColor ?
  404. if (painter.isSingleCanvas && painter.isSingleCanvas()) {
  405. this._zr.configLayer(0, {
  406. clearColor: backgroundColor
  407. });
  408. }
  409. else {
  410. // In IE8
  411. if (!env.canvasSupported) {
  412. var colorArr = colorTool.parse(backgroundColor);
  413. backgroundColor = colorTool.stringify(colorArr, 'rgb');
  414. if (colorArr[3] === 0) {
  415. backgroundColor = 'transparent';
  416. }
  417. }
  418. backgroundColor = backgroundColor;
  419. this._dom.style.backgroundColor = backgroundColor;
  420. }
  421. // console.time && console.timeEnd('update');
  422. },
  423. // PENDING
  424. /**
  425. * @param {Object} payload
  426. * @private
  427. */
  428. updateView: function (payload) {
  429. var ecModel = this._model;
  430. // update before setOption
  431. if (!ecModel) {
  432. return;
  433. }
  434. doLayout.call(this, ecModel, payload);
  435. doVisualCoding.call(this, ecModel, payload);
  436. invokeUpdateMethod.call(this, 'updateView', ecModel, payload);
  437. },
  438. /**
  439. * @param {Object} payload
  440. * @private
  441. */
  442. updateVisual: function (payload) {
  443. var ecModel = this._model;
  444. // update before setOption
  445. if (!ecModel) {
  446. return;
  447. }
  448. doVisualCoding.call(this, ecModel, payload);
  449. invokeUpdateMethod.call(this, 'updateVisual', ecModel, payload);
  450. },
  451. /**
  452. * @param {Object} payload
  453. * @private
  454. */
  455. updateLayout: function (payload) {
  456. var ecModel = this._model;
  457. // update before setOption
  458. if (!ecModel) {
  459. return;
  460. }
  461. doLayout.call(this, ecModel, payload);
  462. invokeUpdateMethod.call(this, 'updateLayout', ecModel, payload);
  463. },
  464. /**
  465. * @param {Object} payload
  466. * @private
  467. */
  468. highlight: function (payload) {
  469. toggleHighlight.call(this, 'highlight', payload);
  470. },
  471. /**
  472. * @param {Object} payload
  473. * @private
  474. */
  475. downplay: function (payload) {
  476. toggleHighlight.call(this, 'downplay', payload);
  477. },
  478. /**
  479. * @param {Object} payload
  480. * @private
  481. */
  482. prepareAndUpdate: function (payload) {
  483. var ecModel = this._model;
  484. prepareView.call(this, 'component', ecModel);
  485. prepareView.call(this, 'chart', ecModel);
  486. updateMethods.update.call(this, payload);
  487. }
  488. };
  489. /**
  490. * @param {Object} payload
  491. * @private
  492. */
  493. function toggleHighlight(method, payload) {
  494. var ecModel = this._model;
  495. // dispatchAction before setOption
  496. if (!ecModel) {
  497. return;
  498. }
  499. ecModel.eachComponent(
  500. {mainType: 'series', query: payload},
  501. function (seriesModel, index) {
  502. var chartView = this._chartsMap[seriesModel.__viewId];
  503. if (chartView && chartView.__alive) {
  504. chartView[method](
  505. seriesModel, ecModel, this._api, payload
  506. );
  507. }
  508. },
  509. this
  510. );
  511. }
  512. /**
  513. * Resize the chart
  514. */
  515. echartsProto.resize = function () {
  516. this._zr.resize();
  517. var optionChanged = this._model && this._model.resetOption('media');
  518. updateMethods[optionChanged ? 'prepareAndUpdate' : 'update'].call(this);
  519. // Resize loading effect
  520. this._loadingFX && this._loadingFX.resize();
  521. };
  522. var defaultLoadingEffect = __webpack_require__(88);
  523. /**
  524. * Show loading effect
  525. * @param {string} [name='default']
  526. * @param {Object} [cfg]
  527. */
  528. echartsProto.showLoading = function (name, cfg) {
  529. if (zrUtil.isObject(name)) {
  530. cfg = name;
  531. name = 'default';
  532. }
  533. this.hideLoading();
  534. var el = defaultLoadingEffect(this._api, cfg);
  535. var zr = this._zr;
  536. this._loadingFX = el;
  537. zr.add(el);
  538. };
  539. /**
  540. * Hide loading effect
  541. */
  542. echartsProto.hideLoading = function () {
  543. this._loadingFX && this._zr.remove(this._loadingFX);
  544. this._loadingFX = null;
  545. };
  546. /**
  547. * @param {Object} eventObj
  548. * @return {Object}
  549. */
  550. echartsProto.makeActionFromEvent = function (eventObj) {
  551. var payload = zrUtil.extend({}, eventObj);
  552. payload.type = eventActionMap[eventObj.type];
  553. return payload;
  554. };
  555. /**
  556. * @pubilc
  557. * @param {Object} payload
  558. * @param {string} [payload.type] Action type
  559. * @param {boolean} [silent=false] Whether trigger event.
  560. */
  561. echartsProto.dispatchAction = function (payload, silent) {
  562. var actionWrap = actions[payload.type];
  563. if (actionWrap) {
  564. var actionInfo = actionWrap.actionInfo;
  565. var updateMethod = actionInfo.update || 'update';
  566. var payloads = [payload];
  567. var batched = false;
  568. // Batch action
  569. if (payload.batch) {
  570. batched = true;
  571. payloads = zrUtil.map(payload.batch, function (item) {
  572. item = zrUtil.defaults(zrUtil.extend({}, item), payload);
  573. item.batch = null;
  574. return item;
  575. });
  576. }
  577. var eventObjBatch = [];
  578. var eventObj;
  579. var isHighlightOrDownplay = payload.type === 'highlight' || payload.type === 'downplay';
  580. for (var i = 0; i < payloads.length; i++) {
  581. var batchItem = payloads[i];
  582. // Action can specify the event by return it.
  583. eventObj = actionWrap.action(batchItem, this._model);
  584. // Emit event outside
  585. eventObj = eventObj || zrUtil.extend({}, batchItem);
  586. // Convert type to eventType
  587. eventObj.type = actionInfo.event || eventObj.type;
  588. eventObjBatch.push(eventObj);
  589. // Highlight and downplay are special.
  590. isHighlightOrDownplay && updateMethods[updateMethod].call(this, batchItem);
  591. }
  592. (updateMethod !== 'none' && !isHighlightOrDownplay)
  593. && updateMethods[updateMethod].call(this, payload);
  594. if (!silent) {
  595. // Follow the rule of action batch
  596. if (batched) {
  597. eventObj = {
  598. type: actionInfo.event || payload.type,
  599. batch: eventObjBatch
  600. };
  601. }
  602. else {
  603. eventObj = eventObjBatch[0];
  604. }
  605. this._messageCenter.trigger(eventObj.type, eventObj);
  606. }
  607. }
  608. };
  609. /**
  610. * Register event
  611. * @method
  612. */
  613. echartsProto.on = createRegisterEventWithLowercaseName('on');
  614. echartsProto.off = createRegisterEventWithLowercaseName('off');
  615. echartsProto.one = createRegisterEventWithLowercaseName('one');
  616. /**
  617. * @param {string} methodName
  618. * @private
  619. */
  620. function invokeUpdateMethod(methodName, ecModel, payload) {
  621. var api = this._api;
  622. // Update all components
  623. each(this._componentsViews, function (component) {
  624. var componentModel = component.__model;
  625. component[methodName](componentModel, ecModel, api, payload);
  626. updateZ(componentModel, component);
  627. }, this);
  628. // Upate all charts
  629. ecModel.eachSeries(function (seriesModel, idx) {
  630. var chart = this._chartsMap[seriesModel.__viewId];
  631. chart[methodName](seriesModel, ecModel, api, payload);
  632. updateZ(seriesModel, chart);
  633. }, this);
  634. }
  635. /**
  636. * Prepare view instances of charts and components
  637. * @param {module:echarts/model/Global} ecModel
  638. * @private
  639. */
  640. function prepareView(type, ecModel) {
  641. var isComponent = type === 'component';
  642. var viewList = isComponent ? this._componentsViews : this._chartsViews;
  643. var viewMap = isComponent ? this._componentsMap : this._chartsMap;
  644. var zr = this._zr;
  645. for (var i = 0; i < viewList.length; i++) {
  646. viewList[i].__alive = false;
  647. }
  648. ecModel[isComponent ? 'eachComponent' : 'eachSeries'](function (componentType, model) {
  649. if (isComponent) {
  650. if (componentType === 'series') {
  651. return;
  652. }
  653. }
  654. else {
  655. model = componentType;
  656. }
  657. // Consider: id same and type changed.
  658. var viewId = model.id + '_' + model.type;
  659. var view = viewMap[viewId];
  660. if (!view) {
  661. var classType = ComponentModel.parseClassType(model.type);
  662. var Clazz = isComponent
  663. ? ComponentView.getClass(classType.main, classType.sub)
  664. : ChartView.getClass(classType.sub);
  665. if (Clazz) {
  666. view = new Clazz();
  667. view.init(ecModel, this._api);
  668. viewMap[viewId] = view;
  669. viewList.push(view);
  670. zr.add(view.group);
  671. }
  672. else {
  673. // Error
  674. return;
  675. }
  676. }
  677. model.__viewId = viewId;
  678. view.__alive = true;
  679. view.__id = viewId;
  680. view.__model = model;
  681. }, this);
  682. for (var i = 0; i < viewList.length;) {
  683. var view = viewList[i];
  684. if (!view.__alive) {
  685. zr.remove(view.group);
  686. view.dispose(ecModel, this._api);
  687. viewList.splice(i, 1);
  688. delete viewMap[view.__id];
  689. }
  690. else {
  691. i++;
  692. }
  693. }
  694. }
  695. /**
  696. * Processor data in each series
  697. *
  698. * @param {module:echarts/model/Global} ecModel
  699. * @private
  700. */
  701. function processData(ecModel, api) {
  702. each(PROCESSOR_STAGES, function (stage) {
  703. each(dataProcessorFuncs[stage] || [], function (process) {
  704. process(ecModel, api);
  705. });
  706. });
  707. }
  708. /**
  709. * @private
  710. */
  711. function stackSeriesData(ecModel) {
  712. var stackedDataMap = {};
  713. ecModel.eachSeries(function (series) {
  714. var stack = series.get('stack');
  715. var data = series.getData();
  716. if (stack && data.type === 'list') {
  717. var previousStack = stackedDataMap[stack];
  718. if (previousStack) {
  719. data.stackedOn = previousStack;
  720. }
  721. stackedDataMap[stack] = data;
  722. }
  723. });
  724. }
  725. /**
  726. * Layout before each chart render there series, after visual coding and data processing
  727. *
  728. * @param {module:echarts/model/Global} ecModel
  729. * @private
  730. */
  731. function doLayout(ecModel, payload) {
  732. var api = this._api;
  733. each(layoutFuncs, function (layout) {
  734. layout(ecModel, api, payload);
  735. });
  736. }
  737. /**
  738. * Code visual infomation from data after data processing
  739. *
  740. * @param {module:echarts/model/Global} ecModel
  741. * @private
  742. */
  743. function doVisualCoding(ecModel, payload) {
  744. each(VISUAL_CODING_STAGES, function (stage) {
  745. each(visualCodingFuncs[stage] || [], function (visualCoding) {
  746. visualCoding(ecModel, payload);
  747. });
  748. });
  749. }
  750. /**
  751. * Render each chart and component
  752. * @private
  753. */
  754. function doRender(ecModel, payload) {
  755. var api = this._api;
  756. // Render all components
  757. each(this._componentsViews, function (componentView) {
  758. var componentModel = componentView.__model;
  759. componentView.render(componentModel, ecModel, api, payload);
  760. updateZ(componentModel, componentView);
  761. }, this);
  762. each(this._chartsViews, function (chart) {
  763. chart.__alive = false;
  764. }, this);
  765. // Render all charts
  766. ecModel.eachSeries(function (seriesModel, idx) {
  767. var chartView = this._chartsMap[seriesModel.__viewId];
  768. chartView.__alive = true;
  769. chartView.render(seriesModel, ecModel, api, payload);
  770. chartView.group.silent = !!seriesModel.get('silent');
  771. updateZ(seriesModel, chartView);
  772. }, this);
  773. // Remove groups of unrendered charts
  774. each(this._chartsViews, function (chart) {
  775. if (!chart.__alive) {
  776. chart.remove(ecModel, api);
  777. }
  778. }, this);
  779. }
  780. var MOUSE_EVENT_NAMES = [
  781. 'click', 'dblclick', 'mouseover', 'mouseout', 'mousedown', 'mouseup', 'globalout'
  782. ];
  783. /**
  784. * @private
  785. */
  786. echartsProto._initEvents = function () {
  787. each(MOUSE_EVENT_NAMES, function (eveName) {
  788. this._zr.on(eveName, function (e) {
  789. var ecModel = this.getModel();
  790. var el = e.target;
  791. if (el && el.dataIndex != null) {
  792. var dataModel = el.dataModel || ecModel.getSeriesByIndex(el.seriesIndex);
  793. var params = dataModel && dataModel.getDataParams(el.dataIndex, el.dataType) || {};
  794. params.event = e;
  795. params.type = eveName;
  796. this.trigger(eveName, params);
  797. }
  798. // If element has custom eventData of components
  799. else if (el && el.eventData) {
  800. this.trigger(eveName, el.eventData);
  801. }
  802. }, this);
  803. }, this);
  804. each(eventActionMap, function (actionType, eventType) {
  805. this._messageCenter.on(eventType, function (event) {
  806. this.trigger(eventType, event);
  807. }, this);
  808. }, this);
  809. };
  810. /**
  811. * @return {boolean}
  812. */
  813. echartsProto.isDisposed = function () {
  814. return this._disposed;
  815. };
  816. /**
  817. * Clear
  818. */
  819. echartsProto.clear = function () {
  820. this.setOption({}, true);
  821. };
  822. /**
  823. * Dispose instance
  824. */
  825. echartsProto.dispose = function () {
  826. this._disposed = true;
  827. var api = this._api;
  828. var ecModel = this._model;
  829. each(this._componentsViews, function (component) {
  830. component.dispose(ecModel, api);
  831. });
  832. each(this._chartsViews, function (chart) {
  833. chart.dispose(ecModel, api);
  834. });
  835. this._zr.dispose();
  836. delete instances[this.id];
  837. };
  838. zrUtil.mixin(ECharts, Eventful);
  839. /**
  840. * @param {module:echarts/model/Series|module:echarts/model/Component} model
  841. * @param {module:echarts/view/Component|module:echarts/view/Chart} view
  842. * @return {string}
  843. */
  844. function updateZ(model, view) {
  845. var z = model.get('z');
  846. var zlevel = model.get('zlevel');
  847. // Set z and zlevel
  848. view.group.traverse(function (el) {
  849. z != null && (el.z = z);
  850. zlevel != null && (el.zlevel = zlevel);
  851. });
  852. }
  853. /**
  854. * @type {Array.<Function>}
  855. * @inner
  856. */
  857. var actions = [];
  858. /**
  859. * Map eventType to actionType
  860. * @type {Object}
  861. */
  862. var eventActionMap = {};
  863. /**
  864. * @type {Array.<Function>}
  865. * @inner
  866. */
  867. var layoutFuncs = [];
  868. /**
  869. * Data processor functions of each stage
  870. * @type {Array.<Object.<string, Function>>}
  871. * @inner
  872. */
  873. var dataProcessorFuncs = {};
  874. /**
  875. * @type {Array.<Function>}
  876. * @inner
  877. */
  878. var optionPreprocessorFuncs = [];
  879. /**
  880. * Visual coding functions of each stage
  881. * @type {Array.<Object.<string, Function>>}
  882. * @inner
  883. */
  884. var visualCodingFuncs = {};
  885. /**
  886. * Theme storage
  887. * @type {Object.<key, Object>}
  888. */
  889. var themeStorage = {};
  890. var instances = {};
  891. var connectedGroups = {};
  892. var idBase = new Date() - 0;
  893. var groupIdBase = new Date() - 0;
  894. var DOM_ATTRIBUTE_KEY = '_echarts_instance_';
  895. /**
  896. * @alias module:echarts
  897. */
  898. var echarts = {
  899. /**
  900. * @type {number}
  901. */
  902. version: '3.1.10',
  903. dependencies: {
  904. zrender: '3.1.0'
  905. }
  906. };
  907. function enableConnect(chart) {
  908. var STATUS_PENDING = 0;
  909. var STATUS_UPDATING = 1;
  910. var STATUS_UPDATED = 2;
  911. var STATUS_KEY = '__connectUpdateStatus';
  912. function updateConnectedChartsStatus(charts, status) {
  913. for (var i = 0; i < charts.length; i++) {
  914. var otherChart = charts[i];
  915. otherChart[STATUS_KEY] = status;
  916. }
  917. }
  918. zrUtil.each(eventActionMap, function (actionType, eventType) {
  919. chart._messageCenter.on(eventType, function (event) {
  920. if (connectedGroups[chart.group] && chart[STATUS_KEY] !== STATUS_PENDING) {
  921. var action = chart.makeActionFromEvent(event);
  922. var otherCharts = [];
  923. for (var id in instances) {
  924. var otherChart = instances[id];
  925. if (otherChart !== chart && otherChart.group === chart.group) {
  926. otherCharts.push(otherChart);
  927. }
  928. }
  929. updateConnectedChartsStatus(otherCharts, STATUS_PENDING);
  930. each(otherCharts, function (otherChart) {
  931. if (otherChart[STATUS_KEY] !== STATUS_UPDATING) {
  932. otherChart.dispatchAction(action);
  933. }
  934. });
  935. updateConnectedChartsStatus(otherCharts, STATUS_UPDATED);
  936. }
  937. });
  938. });
  939. }
  940. /**
  941. * @param {HTMLDomElement} dom
  942. * @param {Object} [theme]
  943. * @param {Object} opts
  944. */
  945. echarts.init = function (dom, theme, opts) {
  946. // Check version
  947. if ((zrender.version.replace('.', '') - 0) < (echarts.dependencies.zrender.replace('.', '') - 0)) {
  948. throw new Error(
  949. 'ZRender ' + zrender.version
  950. + ' is too old for ECharts ' + echarts.version
  951. + '. Current version need ZRender '
  952. + echarts.dependencies.zrender + '+'
  953. );
  954. }
  955. if (!dom) {
  956. throw new Error('Initialize failed: invalid dom.');
  957. }
  958. var chart = new ECharts(dom, theme, opts);
  959. chart.id = 'ec_' + idBase++;
  960. instances[chart.id] = chart;
  961. dom.setAttribute &&
  962. dom.setAttribute(DOM_ATTRIBUTE_KEY, chart.id);
  963. enableConnect(chart);
  964. return chart;
  965. };
  966. /**
  967. * @return {string|Array.<module:echarts~ECharts>} groupId
  968. */
  969. echarts.connect = function (groupId) {
  970. // Is array of charts
  971. if (zrUtil.isArray(groupId)) {
  972. var charts = groupId;
  973. groupId = null;
  974. // If any chart has group
  975. zrUtil.each(charts, function (chart) {
  976. if (chart.group != null) {
  977. groupId = chart.group;
  978. }
  979. });
  980. groupId = groupId || ('g_' + groupIdBase++);
  981. zrUtil.each(charts, function (chart) {
  982. chart.group = groupId;
  983. });
  984. }
  985. connectedGroups[groupId] = true;
  986. return groupId;
  987. };
  988. /**
  989. * @return {string} groupId
  990. */
  991. echarts.disConnect = function (groupId) {
  992. connectedGroups[groupId] = false;
  993. };
  994. /**
  995. * Dispose a chart instance
  996. * @param {module:echarts~ECharts|HTMLDomElement|string} chart
  997. */
  998. echarts.dispose = function (chart) {
  999. if (zrUtil.isDom(chart)) {
  1000. chart = echarts.getInstanceByDom(chart);
  1001. }
  1002. else if (typeof chart === 'string') {
  1003. chart = instances[chart];
  1004. }
  1005. if ((chart instanceof ECharts) && !chart.isDisposed()) {
  1006. chart.dispose();
  1007. }
  1008. };
  1009. /**
  1010. * @param {HTMLDomElement} dom
  1011. * @return {echarts~ECharts}
  1012. */
  1013. echarts.getInstanceByDom = function (dom) {
  1014. var key = dom.getAttribute(DOM_ATTRIBUTE_KEY);
  1015. return instances[key];
  1016. };
  1017. /**
  1018. * @param {string} key
  1019. * @return {echarts~ECharts}
  1020. */
  1021. echarts.getInstanceById = function (key) {
  1022. return instances[key];
  1023. };
  1024. /**
  1025. * Register theme
  1026. */
  1027. echarts.registerTheme = function (name, theme) {
  1028. themeStorage[name] = theme;
  1029. };
  1030. /**
  1031. * Register option preprocessor
  1032. * @param {Function} preprocessorFunc
  1033. */
  1034. echarts.registerPreprocessor = function (preprocessorFunc) {
  1035. optionPreprocessorFuncs.push(preprocessorFunc);
  1036. };
  1037. /**
  1038. * @param {string} stage
  1039. * @param {Function} processorFunc
  1040. */
  1041. echarts.registerProcessor = function (stage, processorFunc) {
  1042. if (zrUtil.indexOf(PROCESSOR_STAGES, stage) < 0) {
  1043. throw new Error('stage should be one of ' + PROCESSOR_STAGES);
  1044. }
  1045. var funcs = dataProcessorFuncs[stage] || (dataProcessorFuncs[stage] = []);
  1046. funcs.push(processorFunc);
  1047. };
  1048. /**
  1049. * Usage:
  1050. * registerAction('someAction', 'someEvent', function () { ... });
  1051. * registerAction('someAction', function () { ... });
  1052. * registerAction(
  1053. * {type: 'someAction', event: 'someEvent', update: 'updateView'},
  1054. * function () { ... }
  1055. * );
  1056. *
  1057. * @param {(string|Object)} actionInfo
  1058. * @param {string} actionInfo.type
  1059. * @param {string} [actionInfo.event]
  1060. * @param {string} [actionInfo.update]
  1061. * @param {string} [eventName]
  1062. * @param {Function} action
  1063. */
  1064. echarts.registerAction = function (actionInfo, eventName, action) {
  1065. if (typeof eventName === 'function') {
  1066. action = eventName;
  1067. eventName = '';
  1068. }
  1069. var actionType = zrUtil.isObject(actionInfo)
  1070. ? actionInfo.type
  1071. : ([actionInfo, actionInfo = {
  1072. event: eventName
  1073. }][0]);
  1074. // Event name is all lowercase
  1075. actionInfo.event = (actionInfo.event || actionType).toLowerCase();
  1076. eventName = actionInfo.event;
  1077. if (!actions[actionType]) {
  1078. actions[actionType] = {action: action, actionInfo: actionInfo};
  1079. }
  1080. eventActionMap[eventName] = actionType;
  1081. };
  1082. /**
  1083. * @param {string} type
  1084. * @param {*} CoordinateSystem
  1085. */
  1086. echarts.registerCoordinateSystem = function (type, CoordinateSystem) {
  1087. CoordinateSystemManager.register(type, CoordinateSystem);
  1088. };
  1089. /**
  1090. * @param {*} layout
  1091. */
  1092. echarts.registerLayout = function (layout) {
  1093. // PENDING All functions ?
  1094. if (zrUtil.indexOf(layoutFuncs, layout) < 0) {
  1095. layoutFuncs.push(layout);
  1096. }
  1097. };
  1098. /**
  1099. * @param {string} stage
  1100. * @param {Function} visualCodingFunc
  1101. */
  1102. echarts.registerVisualCoding = function (stage, visualCodingFunc) {
  1103. if (zrUtil.indexOf(VISUAL_CODING_STAGES, stage) < 0) {
  1104. throw new Error('stage should be one of ' + VISUAL_CODING_STAGES);
  1105. }
  1106. var funcs = visualCodingFuncs[stage] || (visualCodingFuncs[stage] = []);
  1107. funcs.push(visualCodingFunc);
  1108. };
  1109. /**
  1110. * @param {Object} opts
  1111. */
  1112. echarts.extendChartView = function (opts) {
  1113. return ChartView.extend(opts);
  1114. };
  1115. /**
  1116. * @param {Object} opts
  1117. */
  1118. echarts.extendComponentModel = function (opts) {
  1119. return ComponentModel.extend(opts);
  1120. };
  1121. /**
  1122. * @param {Object} opts
  1123. */
  1124. echarts.extendSeriesModel = function (opts) {
  1125. return SeriesModel.extend(opts);
  1126. };
  1127. /**
  1128. * @param {Object} opts
  1129. */
  1130. echarts.extendComponentView = function (opts) {
  1131. return ComponentView.extend(opts);
  1132. };
  1133. /**
  1134. * ZRender need a canvas context to do measureText.
  1135. * But in node environment canvas may be created by node-canvas.
  1136. * So we need to specify how to create a canvas instead of using document.createElement('canvas')
  1137. *
  1138. * Be careful of using it in the browser.
  1139. *
  1140. * @param {Function} creator
  1141. * @example
  1142. * var Canvas = require('canvas');
  1143. * var echarts = require('echarts');
  1144. * echarts.setCanvasCreator(function () {
  1145. * // Small size is enough.
  1146. * return new Canvas(32, 32);
  1147. * });
  1148. */
  1149. echarts.setCanvasCreator = function (creator) {
  1150. zrUtil.createCanvas = creator;
  1151. };
  1152. echarts.registerVisualCoding('echarts', zrUtil.curry(
  1153. __webpack_require__(89), '', 'itemStyle'
  1154. ));
  1155. echarts.registerPreprocessor(__webpack_require__(90));
  1156. // Default action
  1157. echarts.registerAction({
  1158. type: 'highlight',
  1159. event: 'highlight',
  1160. update: 'highlight'
  1161. }, zrUtil.noop);
  1162. echarts.registerAction({
  1163. type: 'downplay',
  1164. event: 'downplay',
  1165. update: 'downplay'
  1166. }, zrUtil.noop);
  1167. // --------
  1168. // Exports
  1169. // --------
  1170. echarts.graphic = __webpack_require__(42);
  1171. echarts.number = __webpack_require__(7);
  1172. echarts.format = __webpack_require__(6);
  1173. echarts.matrix = __webpack_require__(17);
  1174. echarts.vector = __webpack_require__(16);
  1175. echarts.util = {};
  1176. each([
  1177. 'map', 'each', 'filter', 'indexOf', 'inherits',
  1178. 'reduce', 'filter', 'bind', 'curry', 'isArray',
  1179. 'isString', 'isObject', 'isFunction', 'extend'
  1180. ],
  1181. function (name) {
  1182. echarts.util[name] = zrUtil[name];
  1183. }
  1184. );
  1185. module.exports = echarts;
  1186. /***/ },
  1187. /* 2 */
  1188. /***/ function(module, exports, __webpack_require__) {
  1189. /**
  1190. * ECharts global model
  1191. *
  1192. * @module {echarts/model/Global}
  1193. *
  1194. */
  1195. var zrUtil = __webpack_require__(3);
  1196. var modelUtil = __webpack_require__(5);
  1197. var Model = __webpack_require__(8);
  1198. var each = zrUtil.each;
  1199. var filter = zrUtil.filter;
  1200. var map = zrUtil.map;
  1201. var isArray = zrUtil.isArray;
  1202. var indexOf = zrUtil.indexOf;
  1203. var isObject = zrUtil.isObject;
  1204. var ComponentModel = __webpack_require__(19);
  1205. var globalDefault = __webpack_require__(23);
  1206. var OPTION_INNER_KEY = '\0_ec_inner';
  1207. /**
  1208. * @alias module:echarts/model/Global
  1209. *
  1210. * @param {Object} option
  1211. * @param {module:echarts/model/Model} parentModel
  1212. * @param {Object} theme
  1213. */
  1214. var GlobalModel = Model.extend({
  1215. constructor: GlobalModel,
  1216. init: function (option, parentModel, theme, optionManager) {
  1217. theme = theme || {};
  1218. this.option = null; // Mark as not initialized.
  1219. /**
  1220. * @type {module:echarts/model/Model}
  1221. * @private
  1222. */
  1223. this._theme = new Model(theme);
  1224. /**
  1225. * @type {module:echarts/model/OptionManager}
  1226. */
  1227. this._optionManager = optionManager;
  1228. },
  1229. setOption: function (option, optionPreprocessorFuncs) {
  1230. zrUtil.assert(
  1231. !(OPTION_INNER_KEY in option),
  1232. 'please use chart.getOption()'
  1233. );
  1234. this._optionManager.setOption(option, optionPreprocessorFuncs);
  1235. this.resetOption();
  1236. },
  1237. /**
  1238. * @param {string} type null/undefined: reset all.
  1239. * 'recreate': force recreate all.
  1240. * 'timeline': only reset timeline option
  1241. * 'media': only reset media query option
  1242. * @return {boolean} Whether option changed.
  1243. */
  1244. resetOption: function (type) {
  1245. var optionChanged = false;
  1246. var optionManager = this._optionManager;
  1247. if (!type || type === 'recreate') {
  1248. var baseOption = optionManager.mountOption(type === 'recreate');
  1249. if (!this.option || type === 'recreate') {
  1250. initBase.call(this, baseOption);
  1251. }
  1252. else {
  1253. this.restoreData();
  1254. this.mergeOption(baseOption);
  1255. }
  1256. optionChanged = true;
  1257. }
  1258. if (type === 'timeline' || type === 'media') {
  1259. this.restoreData();
  1260. }
  1261. if (!type || type === 'recreate' || type === 'timeline') {
  1262. var timelineOption = optionManager.getTimelineOption(this);
  1263. timelineOption && (this.mergeOption(timelineOption), optionChanged = true);
  1264. }
  1265. if (!type || type === 'recreate' || type === 'media') {
  1266. var mediaOptions = optionManager.getMediaOption(this, this._api);
  1267. if (mediaOptions.length) {
  1268. each(mediaOptions, function (mediaOption) {
  1269. this.mergeOption(mediaOption, optionChanged = true);
  1270. }, this);
  1271. }
  1272. }
  1273. return optionChanged;
  1274. },
  1275. /**
  1276. * @protected
  1277. */
  1278. mergeOption: function (newOption) {
  1279. var option = this.option;
  1280. var componentsMap = this._componentsMap;
  1281. var newCptTypes = [];
  1282. // 如果不存在对应的 component model 则直接 merge
  1283. each(newOption, function (componentOption, mainType) {
  1284. if (componentOption == null) {
  1285. return;
  1286. }
  1287. if (!ComponentModel.hasClass(mainType)) {
  1288. option[mainType] = option[mainType] == null
  1289. ? zrUtil.clone(componentOption)
  1290. : zrUtil.merge(option[mainType], componentOption, true);
  1291. }
  1292. else {
  1293. newCptTypes.push(mainType);
  1294. }
  1295. });
  1296. // FIXME OPTION 同步是否要改回原来的
  1297. ComponentModel.topologicalTravel(
  1298. newCptTypes, ComponentModel.getAllClassMainTypes(), visitComponent, this
  1299. );
  1300. function visitComponent(mainType, dependencies) {
  1301. var newCptOptionList = modelUtil.normalizeToArray(newOption[mainType]);
  1302. var mapResult = modelUtil.mappingToExists(
  1303. componentsMap[mainType], newCptOptionList
  1304. );
  1305. makeKeyInfo(mainType, mapResult);
  1306. var dependentModels = getComponentsByTypes(
  1307. componentsMap, dependencies
  1308. );
  1309. option[mainType] = [];
  1310. componentsMap[mainType] = [];
  1311. each(mapResult, function (resultItem, index) {
  1312. var componentModel = resultItem.exist;
  1313. var newCptOption = resultItem.option;
  1314. zrUtil.assert(
  1315. isObject(newCptOption) || componentModel,
  1316. 'Empty component definition'
  1317. );
  1318. // Consider where is no new option and should be merged using {},
  1319. // see removeEdgeAndAdd in topologicalTravel and
  1320. // ComponentModel.getAllClassMainTypes.
  1321. if (!newCptOption) {
  1322. componentModel.mergeOption({}, this);
  1323. componentModel.optionUpdated(this);
  1324. }
  1325. else {
  1326. var ComponentModelClass = ComponentModel.getClass(
  1327. mainType, resultItem.keyInfo.subType, true
  1328. );
  1329. if (componentModel && componentModel instanceof ComponentModelClass) {
  1330. componentModel.mergeOption(newCptOption, this);
  1331. componentModel.optionUpdated(this);
  1332. }
  1333. else {
  1334. // PENDING Global as parent ?
  1335. componentModel = new ComponentModelClass(
  1336. newCptOption, this, this,
  1337. zrUtil.extend(
  1338. {
  1339. dependentModels: dependentModels,
  1340. componentIndex: index
  1341. },
  1342. resultItem.keyInfo
  1343. )
  1344. );
  1345. // Call optionUpdated after init
  1346. componentModel.optionUpdated(this);
  1347. }
  1348. }
  1349. componentsMap[mainType][index] = componentModel;
  1350. option[mainType][index] = componentModel.option;
  1351. }, this);
  1352. // Backup series for filtering.
  1353. if (mainType === 'series') {
  1354. this._seriesIndices = createSeriesIndices(componentsMap.series);
  1355. }
  1356. }
  1357. },
  1358. /**
  1359. * Get option for output (cloned option and inner info removed)
  1360. * @public
  1361. * @return {Object}
  1362. */
  1363. getOption: function () {
  1364. var option = zrUtil.clone(this.option);
  1365. each(option, function (opts, mainType) {
  1366. if (ComponentModel.hasClass(mainType)) {
  1367. var opts = modelUtil.normalizeToArray(opts);
  1368. for (var i = opts.length - 1; i >= 0; i--) {
  1369. // Remove options with inner id.
  1370. if (modelUtil.isIdInner(opts[i])) {
  1371. opts.splice(i, 1);
  1372. }
  1373. }
  1374. option[mainType] = opts;
  1375. }
  1376. });
  1377. delete option[OPTION_INNER_KEY];
  1378. return option;
  1379. },
  1380. /**
  1381. * @return {module:echarts/model/Model}
  1382. */
  1383. getTheme: function () {
  1384. return this._theme;
  1385. },
  1386. /**
  1387. * @param {string} mainType
  1388. * @param {number} [idx=0]
  1389. * @return {module:echarts/model/Component}
  1390. */
  1391. getComponent: function (mainType, idx) {
  1392. var list = this._componentsMap[mainType];
  1393. if (list) {
  1394. return list[idx || 0];
  1395. }
  1396. },
  1397. /**
  1398. * @param {Object} condition
  1399. * @param {string} condition.mainType
  1400. * @param {string} [condition.subType] If ignore, only query by mainType
  1401. * @param {number} [condition.index] Either input index or id or name.
  1402. * @param {string} [condition.id] Either input index or id or name.
  1403. * @param {string} [condition.name] Either input index or id or name.
  1404. * @return {Array.<module:echarts/model/Component>}
  1405. */
  1406. queryComponents: function (condition) {
  1407. var mainType = condition.mainType;
  1408. if (!mainType) {
  1409. return [];
  1410. }
  1411. var index = condition.index;
  1412. var id = condition.id;
  1413. var name = condition.name;
  1414. var cpts = this._componentsMap[mainType];
  1415. if (!cpts || !cpts.length) {
  1416. return [];
  1417. }
  1418. var result;
  1419. if (index != null) {
  1420. if (!isArray(index)) {
  1421. index = [index];
  1422. }
  1423. result = filter(map(index, function (idx) {
  1424. return cpts[idx];
  1425. }), function (val) {
  1426. return !!val;
  1427. });
  1428. }
  1429. else if (id != null) {
  1430. var isIdArray = isArray(id);
  1431. result = filter(cpts, function (cpt) {
  1432. return (isIdArray && indexOf(id, cpt.id) >= 0)
  1433. || (!isIdArray && cpt.id === id);
  1434. });
  1435. }
  1436. else if (name != null) {
  1437. var isNameArray = isArray(name);
  1438. result = filter(cpts, function (cpt) {
  1439. return (isNameArray && indexOf(name, cpt.name) >= 0)
  1440. || (!isNameArray && cpt.name === name);
  1441. });
  1442. }
  1443. return filterBySubType(result, condition);
  1444. },
  1445. /**
  1446. * The interface is different from queryComponents,
  1447. * which is convenient for inner usage.
  1448. *
  1449. * @usage
  1450. * var result = findComponents(
  1451. * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}}
  1452. * );
  1453. * var result = findComponents(
  1454. * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}}
  1455. * );
  1456. * var result = findComponents(
  1457. * {mainType: 'series'},
  1458. * function (model, index) {...}
  1459. * );
  1460. * // result like [component0, componnet1, ...]
  1461. *
  1462. * @param {Object} condition
  1463. * @param {string} condition.mainType Mandatory.
  1464. * @param {string} [condition.subType] Optional.
  1465. * @param {Object} [condition.query] like {xxxIndex, xxxId, xxxName},
  1466. * where xxx is mainType.
  1467. * If query attribute is null/undefined or has no index/id/name,
  1468. * do not filtering by query conditions, which is convenient for
  1469. * no-payload situations or when target of action is global.
  1470. * @param {Function} [condition.filter] parameter: component, return boolean.
  1471. * @return {Array.<module:echarts/model/Component>}
  1472. */
  1473. findComponents: function (condition) {
  1474. var query = condition.query;
  1475. var mainType = condition.mainType;
  1476. var queryCond = getQueryCond(query);
  1477. var result = queryCond
  1478. ? this.queryComponents(queryCond)
  1479. : this._componentsMap[mainType];
  1480. return doFilter(filterBySubType(result, condition));
  1481. function getQueryCond(q) {
  1482. var indexAttr = mainType + 'Index';
  1483. var idAttr = mainType + 'Id';
  1484. var nameAttr = mainType + 'Name';
  1485. return q && (
  1486. q.hasOwnProperty(indexAttr)
  1487. || q.hasOwnProperty(idAttr)
  1488. || q.hasOwnProperty(nameAttr)
  1489. )
  1490. ? {
  1491. mainType: mainType,
  1492. // subType will be filtered finally.
  1493. index: q[indexAttr],
  1494. id: q[idAttr],
  1495. name: q[nameAttr]
  1496. }
  1497. : null;
  1498. }
  1499. function doFilter(res) {
  1500. return condition.filter
  1501. ? filter(res, condition.filter)
  1502. : res;
  1503. }
  1504. },
  1505. /**
  1506. * @usage
  1507. * eachComponent('legend', function (legendModel, index) {
  1508. * ...
  1509. * });
  1510. * eachComponent(function (componentType, model, index) {
  1511. * // componentType does not include subType
  1512. * // (componentType is 'xxx' but not 'xxx.aa')
  1513. * });
  1514. * eachComponent(
  1515. * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}},
  1516. * function (model, index) {...}
  1517. * );
  1518. * eachComponent(
  1519. * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}},
  1520. * function (model, index) {...}
  1521. * );
  1522. *
  1523. * @param {string|Object=} mainType When mainType is object, the definition
  1524. * is the same as the method 'findComponents'.
  1525. * @param {Function} cb
  1526. * @param {*} context
  1527. */
  1528. eachComponent: function (mainType, cb, context) {
  1529. var componentsMap = this._componentsMap;
  1530. if (typeof mainType === 'function') {
  1531. context = cb;
  1532. cb = mainType;
  1533. each(componentsMap, function (components, componentType) {
  1534. each(components, function (component, index) {
  1535. cb.call(context, componentType, component, index);
  1536. });
  1537. });
  1538. }
  1539. else if (zrUtil.isString(mainType)) {
  1540. each(componentsMap[mainType], cb, context);
  1541. }
  1542. else if (isObject(mainType)) {
  1543. var queryResult = this.findComponents(mainType);
  1544. each(queryResult, cb, context);
  1545. }
  1546. },
  1547. /**
  1548. * @param {string} name
  1549. * @return {Array.<module:echarts/model/Series>}
  1550. */
  1551. getSeriesByName: function (name) {
  1552. var series = this._componentsMap.series;
  1553. return filter(series, function (oneSeries) {
  1554. return oneSeries.name === name;
  1555. });
  1556. },
  1557. /**
  1558. * @param {number} seriesIndex
  1559. * @return {module:echarts/model/Series}
  1560. */
  1561. getSeriesByIndex: function (seriesIndex) {
  1562. return this._componentsMap.series[seriesIndex];
  1563. },
  1564. /**
  1565. * @param {string} subType
  1566. * @return {Array.<module:echarts/model/Series>}
  1567. */
  1568. getSeriesByType: function (subType) {
  1569. var series = this._componentsMap.series;
  1570. return filter(series, function (oneSeries) {
  1571. return oneSeries.subType === subType;
  1572. });
  1573. },
  1574. /**
  1575. * @return {Array.<module:echarts/model/Series>}
  1576. */
  1577. getSeries: function () {
  1578. return this._componentsMap.series.slice();
  1579. },
  1580. /**
  1581. * After filtering, series may be different
  1582. * frome raw series.
  1583. *
  1584. * @param {Function} cb
  1585. * @param {*} context
  1586. */
  1587. eachSeries: function (cb, context) {
  1588. assertSeriesInitialized(this);
  1589. each(this._seriesIndices, function (rawSeriesIndex) {
  1590. var series = this._componentsMap.series[rawSeriesIndex];
  1591. cb.call(context, series, rawSeriesIndex);
  1592. }, this);
  1593. },
  1594. /**
  1595. * Iterate raw series before filtered.
  1596. *
  1597. * @param {Function} cb
  1598. * @param {*} context
  1599. */
  1600. eachRawSeries: function (cb, context) {
  1601. each(this._componentsMap.series, cb, context);
  1602. },
  1603. /**
  1604. * After filtering, series may be different.
  1605. * frome raw series.
  1606. *
  1607. * @parma {string} subType
  1608. * @param {Function} cb
  1609. * @param {*} context
  1610. */
  1611. eachSeriesByType: function (subType, cb, context) {
  1612. assertSeriesInitialized(this);
  1613. each(this._seriesIndices, function (rawSeriesIndex) {
  1614. var series = this._componentsMap.series[rawSeriesIndex];
  1615. if (series.subType === subType) {
  1616. cb.call(context, series, rawSeriesIndex);
  1617. }
  1618. }, this);
  1619. },
  1620. /**
  1621. * Iterate raw series before filtered of given type.
  1622. *
  1623. * @parma {string} subType
  1624. * @param {Function} cb
  1625. * @param {*} context
  1626. */
  1627. eachRawSeriesByType: function (subType, cb, context) {
  1628. return each(this.getSeriesByType(subType), cb, context);
  1629. },
  1630. /**
  1631. * @param {module:echarts/model/Series} seriesModel
  1632. */
  1633. isSeriesFiltered: function (seriesModel) {
  1634. assertSeriesInitialized(this);
  1635. return zrUtil.indexOf(this._seriesIndices, seriesModel.componentIndex) < 0;
  1636. },
  1637. /**
  1638. * @param {Function} cb
  1639. * @param {*} context
  1640. */
  1641. filterSeries: function (cb, context) {
  1642. assertSeriesInitialized(this);
  1643. var filteredSeries = filter(
  1644. this._componentsMap.series, cb, context
  1645. );
  1646. this._seriesIndices = createSeriesIndices(filteredSeries);
  1647. },
  1648. restoreData: function () {
  1649. var componentsMap = this._componentsMap;
  1650. this._seriesIndices = createSeriesIndices(componentsMap.series);
  1651. var componentTypes = [];
  1652. each(componentsMap, function (components, componentType) {
  1653. componentTypes.push(componentType);
  1654. });
  1655. ComponentModel.topologicalTravel(
  1656. componentTypes,
  1657. ComponentModel.getAllClassMainTypes(),
  1658. function (componentType, dependencies) {
  1659. each(componentsMap[componentType], function (component) {
  1660. component.restoreData();
  1661. });
  1662. }
  1663. );
  1664. }
  1665. });
  1666. /**
  1667. * @inner
  1668. */
  1669. function mergeTheme(option, theme) {
  1670. for (var name in theme) {
  1671. // 如果有 component model 则把具体的 merge 逻辑交给该 model 处理
  1672. if (!ComponentModel.hasClass(name)) {
  1673. if (typeof theme[name] === 'object') {
  1674. option[name] = !option[name]
  1675. ? zrUtil.clone(theme[name])
  1676. : zrUtil.merge(option[name], theme[name], false);
  1677. }
  1678. else {
  1679. if (option[name] == null) {
  1680. option[name] = theme[name];
  1681. }
  1682. }
  1683. }
  1684. }
  1685. }
  1686. function initBase(baseOption) {
  1687. baseOption = baseOption;
  1688. // Using OPTION_INNER_KEY to mark that this option can not be used outside,
  1689. // i.e. `chart.setOption(chart.getModel().option);` is forbiden.
  1690. this.option = {};
  1691. this.option[OPTION_INNER_KEY] = 1;
  1692. /**
  1693. * @type {Object.<string, Array.<module:echarts/model/Model>>}
  1694. * @private
  1695. */
  1696. this._componentsMap = {};
  1697. /**
  1698. * Mapping between filtered series list and raw series list.
  1699. * key: filtered series indices, value: raw series indices.
  1700. * @type {Array.<nubmer>}
  1701. * @private
  1702. */
  1703. this._seriesIndices = null;
  1704. mergeTheme(baseOption, this._theme.option);
  1705. // TODO Needs clone when merging to the unexisted property
  1706. zrUtil.merge(baseOption, globalDefault, false);
  1707. this.mergeOption(baseOption);
  1708. }
  1709. /**
  1710. * @inner
  1711. * @param {Array.<string>|string} types model types
  1712. * @return {Object} key: {string} type, value: {Array.<Object>} models
  1713. */
  1714. function getComponentsByTypes(componentsMap, types) {
  1715. if (!zrUtil.isArray(types)) {
  1716. types = types ? [types] : [];
  1717. }
  1718. var ret = {};
  1719. each(types, function (type) {
  1720. ret[type] = (componentsMap[type] || []).slice();
  1721. });
  1722. return ret;
  1723. }
  1724. /**
  1725. * @inner
  1726. */
  1727. function makeKeyInfo(mainType, mapResult) {
  1728. // We use this id to hash component models and view instances
  1729. // in echarts. id can be specified by user, or auto generated.
  1730. // The id generation rule ensures new view instance are able
  1731. // to mapped to old instance when setOption are called in
  1732. // no-merge mode. So we generate model id by name and plus
  1733. // type in view id.
  1734. // name can be duplicated among components, which is convenient
  1735. // to specify multi components (like series) by one name.
  1736. // Ensure that each id is distinct.
  1737. var idMap = {};
  1738. each(mapResult, function (item, index) {
  1739. var existCpt = item.exist;
  1740. existCpt && (idMap[existCpt.id] = item);
  1741. });
  1742. each(mapResult, function (item, index) {
  1743. var opt = item.option;
  1744. zrUtil.assert(
  1745. !opt || opt.id == null || !idMap[opt.id] || idMap[opt.id] === item,
  1746. 'id duplicates: ' + (opt && opt.id)
  1747. );
  1748. opt && opt.id != null && (idMap[opt.id] = item);
  1749. // Complete subType
  1750. if (isObject(opt)) {
  1751. var subType = determineSubType(mainType, opt, item.exist);
  1752. item.keyInfo = {mainType: mainType, subType: subType};
  1753. }
  1754. });
  1755. // Make name and id.
  1756. each(mapResult, function (item, index) {
  1757. var existCpt = item.exist;
  1758. var opt = item.option;
  1759. var keyInfo = item.keyInfo;
  1760. if (!isObject(opt)) {
  1761. return;
  1762. }
  1763. // name can be overwitten. Consider case: axis.name = '20km'.
  1764. // But id generated by name will not be changed, which affect
  1765. // only in that case: setOption with 'not merge mode' and view
  1766. // instance will be recreated, which can be accepted.
  1767. keyInfo.name = opt.name != null
  1768. ? opt.name + ''
  1769. : existCpt
  1770. ? existCpt.name
  1771. : '\0-';
  1772. if (existCpt) {
  1773. keyInfo.id = existCpt.id;
  1774. }
  1775. else if (opt.id != null) {
  1776. keyInfo.id = opt.id + '';
  1777. }
  1778. else {
  1779. // Consider this situatoin:
  1780. // optionA: [{name: 'a'}, {name: 'a'}, {..}]
  1781. // optionB [{..}, {name: 'a'}, {name: 'a'}]
  1782. // Series with the same name between optionA and optionB
  1783. // should be mapped.
  1784. var idNum = 0;
  1785. do {
  1786. keyInfo.id = '\0' + keyInfo.name + '\0' + idNum++;
  1787. }
  1788. while (idMap[keyInfo.id]);
  1789. }
  1790. idMap[keyInfo.id] = item;
  1791. });
  1792. }
  1793. /**
  1794. * @inner
  1795. */
  1796. function determineSubType(mainType, newCptOption, existComponent) {
  1797. var subType = newCptOption.type
  1798. ? newCptOption.type
  1799. : existComponent
  1800. ? existComponent.subType
  1801. // Use determineSubType only when there is no existComponent.
  1802. : ComponentModel.determineSubType(mainType, newCptOption);
  1803. // tooltip, markline, markpoint may always has no subType
  1804. return subType;
  1805. }
  1806. /**
  1807. * @inner
  1808. */
  1809. function createSeriesIndices(seriesModels) {
  1810. return map(seriesModels, function (series) {
  1811. return series.componentIndex;
  1812. }) || [];
  1813. }
  1814. /**
  1815. * @inner
  1816. */
  1817. function filterBySubType(components, condition) {
  1818. // Using hasOwnProperty for restrict. Consider
  1819. // subType is undefined in user payload.
  1820. return condition.hasOwnProperty('subType')
  1821. ? filter(components, function (cpt) {
  1822. return cpt.subType === condition.subType;
  1823. })
  1824. : components;
  1825. }
  1826. /**
  1827. * @inner
  1828. */
  1829. function assertSeriesInitialized(ecModel) {
  1830. // Components that use _seriesIndices should depends on series component,
  1831. // which make sure that their initialization is after series.
  1832. if (!ecModel._seriesIndices) {
  1833. throw new Error('Series has not been initialized yet.');
  1834. }
  1835. }
  1836. module.exports = GlobalModel;
  1837. /***/ },
  1838. /* 3 */
  1839. /***/ function(module, exports, __webpack_require__) {
  1840. /**
  1841. * @module zrender/core/util
  1842. */
  1843. var Gradient = __webpack_require__(4);
  1844. // 用于处理merge时无法遍历Date等对象的问题
  1845. var BUILTIN_OBJECT = {
  1846. '[object Function]': 1,
  1847. '[object RegExp]': 1,
  1848. '[object Date]': 1,
  1849. '[object Error]': 1,
  1850. '[object CanvasGradient]': 1
  1851. };
  1852. var objToString = Object.prototype.toString;
  1853. var arrayProto = Array.prototype;
  1854. var nativeForEach = arrayProto.forEach;
  1855. var nativeFilter = arrayProto.filter;
  1856. var nativeSlice = arrayProto.slice;
  1857. var nativeMap = arrayProto.map;
  1858. var nativeReduce = arrayProto.reduce;
  1859. /**
  1860. * @param {*} source
  1861. * @return {*} 拷贝后的新对象
  1862. */
  1863. function clone(source) {
  1864. if (typeof source == 'object' && source !== null) {
  1865. var result = source;
  1866. if (source instanceof Array) {
  1867. result = [];
  1868. for (var i = 0, len = source.length; i < len; i++) {
  1869. result[i] = clone(source[i]);
  1870. }
  1871. }
  1872. else if (
  1873. !isBuildInObject(source)
  1874. // 是否为 dom 对象
  1875. && !isDom(source)
  1876. ) {
  1877. result = {};
  1878. for (var key in source) {
  1879. if (source.hasOwnProperty(key)) {
  1880. result[key] = clone(source[key]);
  1881. }
  1882. }
  1883. }
  1884. return result;
  1885. }
  1886. return source;
  1887. }
  1888. /**
  1889. * @memberOf module:zrender/core/util
  1890. * @param {*} target
  1891. * @param {*} source
  1892. * @param {boolean} [overwrite=false]
  1893. */
  1894. function merge(target, source, overwrite) {
  1895. // We should escapse that source is string
  1896. // and enter for ... in ...
  1897. if (!isObject(source) || !isObject(target)) {
  1898. return overwrite ? clone(source) : target;
  1899. }
  1900. for (var key in source) {
  1901. if (source.hasOwnProperty(key)) {
  1902. var targetProp = target[key];
  1903. var sourceProp = source[key];
  1904. if (isObject(sourceProp)
  1905. && isObject(targetProp)
  1906. && !isArray(sourceProp)
  1907. && !isArray(targetProp)
  1908. && !isDom(sourceProp)
  1909. && !isDom(targetProp)
  1910. && !isBuildInObject(sourceProp)
  1911. && !isBuildInObject(targetProp)
  1912. ) {
  1913. // 如果需要递归覆盖,就递归调用merge
  1914. merge(targetProp, sourceProp, overwrite);
  1915. }
  1916. else if (overwrite || !(key in target)) {
  1917. // 否则只处理overwrite为true,或者在目标对象中没有此属性的情况
  1918. // NOTE,在 target[key] 不存在的时候也是直接覆盖
  1919. target[key] = clone(source[key], true);
  1920. }
  1921. }
  1922. }
  1923. return target;
  1924. }
  1925. /**
  1926. * @param {Array} targetAndSources The first item is target, and the rests are source.
  1927. * @param {boolean} [overwrite=false]
  1928. * @return {*} target
  1929. */
  1930. function mergeAll(targetAndSources, overwrite) {
  1931. var result = targetAndSources[0];
  1932. for (var i = 1, len = targetAndSources.length; i < len; i++) {
  1933. result = merge(result, targetAndSources[i], overwrite);
  1934. }
  1935. return result;
  1936. }
  1937. /**
  1938. * @param {*} target
  1939. * @param {*} source
  1940. * @memberOf module:zrender/core/util
  1941. */
  1942. function extend(target, source) {
  1943. for (var key in source) {
  1944. if (source.hasOwnProperty(key)) {
  1945. target[key] = source[key];
  1946. }
  1947. }
  1948. return target;
  1949. }
  1950. /**
  1951. * @param {*} target
  1952. * @param {*} source
  1953. * @param {boolen} [overlay=false]
  1954. * @memberOf module:zrender/core/util
  1955. */
  1956. function defaults(target, source, overlay) {
  1957. for (var key in source) {
  1958. if (source.hasOwnProperty(key)
  1959. && (overlay ? source[key] != null : target[key] == null)
  1960. ) {
  1961. target[key] = source[key];
  1962. }
  1963. }
  1964. return target;
  1965. }
  1966. function createCanvas() {
  1967. return document.createElement('canvas');
  1968. }
  1969. // FIXME
  1970. var _ctx;
  1971. function getContext() {
  1972. if (!_ctx) {
  1973. // Use util.createCanvas instead of createCanvas
  1974. // because createCanvas may be overwritten in different environment
  1975. _ctx = util.createCanvas().getContext('2d');
  1976. }
  1977. return _ctx;
  1978. }
  1979. /**
  1980. * 查询数组中元素的index
  1981. * @memberOf module:zrender/core/util
  1982. */
  1983. function indexOf(array, value) {
  1984. if (array) {
  1985. if (array.indexOf) {
  1986. return array.indexOf(value);
  1987. }
  1988. for (var i = 0, len = array.length; i < len; i++) {
  1989. if (array[i] === value) {
  1990. return i;
  1991. }
  1992. }
  1993. }
  1994. return -1;
  1995. }
  1996. /**
  1997. * 构造类继承关系
  1998. *
  1999. * @memberOf module:zrender/core/util
  2000. * @param {Function} clazz 源类
  2001. * @param {Function} baseClazz 基类
  2002. */
  2003. function inherits(clazz, baseClazz) {
  2004. var clazzPrototype = clazz.prototype;
  2005. function F() {}
  2006. F.prototype = baseClazz.prototype;
  2007. clazz.prototype = new F();
  2008. for (var prop in clazzPrototype) {
  2009. clazz.prototype[prop] = clazzPrototype[prop];
  2010. }
  2011. clazz.prototype.constructor = clazz;
  2012. clazz.superClass = baseClazz;
  2013. }
  2014. /**
  2015. * @memberOf module:zrender/core/util
  2016. * @param {Object|Function} target
  2017. * @param {Object|Function} sorce
  2018. * @param {boolean} overlay
  2019. */
  2020. function mixin(target, source, overlay) {
  2021. target = 'prototype' in target ? target.prototype : target;
  2022. source = 'prototype' in source ? source.prototype : source;
  2023. defaults(target, source, overlay);
  2024. }
  2025. /**
  2026. * @param {Array|TypedArray} data
  2027. */
  2028. function isArrayLike(data) {
  2029. if (! data) {
  2030. return;
  2031. }
  2032. if (typeof data == 'string') {
  2033. return false;
  2034. }
  2035. return typeof data.length == 'number';
  2036. }
  2037. /**
  2038. * 数组或对象遍历
  2039. * @memberOf module:zrender/core/util
  2040. * @param {Object|Array} obj
  2041. * @param {Function} cb
  2042. * @param {*} [context]
  2043. */
  2044. function each(obj, cb, context) {
  2045. if (!(obj && cb)) {
  2046. return;
  2047. }
  2048. if (obj.forEach && obj.forEach === nativeForEach) {
  2049. obj.forEach(cb, context);
  2050. }
  2051. else if (obj.length === +obj.length) {
  2052. for (var i = 0, len = obj.length; i < len; i++) {
  2053. cb.call(context, obj[i], i, obj);
  2054. }
  2055. }
  2056. else {
  2057. for (var key in obj) {
  2058. if (obj.hasOwnProperty(key)) {
  2059. cb.call(context, obj[key], key, obj);
  2060. }
  2061. }
  2062. }
  2063. }
  2064. /**
  2065. * 数组映射
  2066. * @memberOf module:zrender/core/util
  2067. * @param {Array} obj
  2068. * @param {Function} cb
  2069. * @param {*} [context]
  2070. * @return {Array}
  2071. */
  2072. function map(obj, cb, context) {
  2073. if (!(obj && cb)) {
  2074. return;
  2075. }
  2076. if (obj.map && obj.map === nativeMap) {
  2077. return obj.map(cb, context);
  2078. }
  2079. else {
  2080. var result = [];
  2081. for (var i = 0, len = obj.length; i < len; i++) {
  2082. result.push(cb.call(context, obj[i], i, obj));
  2083. }
  2084. return result;
  2085. }
  2086. }
  2087. /**
  2088. * @memberOf module:zrender/core/util
  2089. * @param {Array} obj
  2090. * @param {Function} cb
  2091. * @param {Object} [memo]
  2092. * @param {*} [context]
  2093. * @return {Array}
  2094. */
  2095. function reduce(obj, cb, memo, context) {
  2096. if (!(obj && cb)) {
  2097. return;
  2098. }
  2099. if (obj.reduce && obj.reduce === nativeReduce) {
  2100. return obj.reduce(cb, memo, context);
  2101. }
  2102. else {
  2103. for (var i = 0, len = obj.length; i < len; i++) {
  2104. memo = cb.call(context, memo, obj[i], i, obj);
  2105. }
  2106. return memo;
  2107. }
  2108. }
  2109. /**
  2110. * 数组过滤
  2111. * @memberOf module:zrender/core/util
  2112. * @param {Array} obj
  2113. * @param {Function} cb
  2114. * @param {*} [context]
  2115. * @return {Array}
  2116. */
  2117. function filter(obj, cb, context) {
  2118. if (!(obj && cb)) {
  2119. return;
  2120. }
  2121. if (obj.filter && obj.filter === nativeFilter) {
  2122. return obj.filter(cb, context);
  2123. }
  2124. else {
  2125. var result = [];
  2126. for (var i = 0, len = obj.length; i < len; i++) {
  2127. if (cb.call(context, obj[i], i, obj)) {
  2128. result.push(obj[i]);
  2129. }
  2130. }
  2131. return result;
  2132. }
  2133. }
  2134. /**
  2135. * 数组项查找
  2136. * @memberOf module:zrender/core/util
  2137. * @param {Array} obj
  2138. * @param {Function} cb
  2139. * @param {*} [context]
  2140. * @return {Array}
  2141. */
  2142. function find(obj, cb, context) {
  2143. if (!(obj && cb)) {
  2144. return;
  2145. }
  2146. for (var i = 0, len = obj.length; i < len; i++) {
  2147. if (cb.call(context, obj[i], i, obj)) {
  2148. return obj[i];
  2149. }
  2150. }
  2151. }
  2152. /**
  2153. * @memberOf module:zrender/core/util
  2154. * @param {Function} func
  2155. * @param {*} context
  2156. * @return {Function}
  2157. */
  2158. function bind(func, context) {
  2159. var args = nativeSlice.call(arguments, 2);
  2160. return function () {
  2161. return func.apply(context, args.concat(nativeSlice.call(arguments)));
  2162. };
  2163. }
  2164. /**
  2165. * @memberOf module:zrender/core/util
  2166. * @param {Function} func
  2167. * @return {Function}
  2168. */
  2169. function curry(func) {
  2170. var args = nativeSlice.call(arguments, 1);
  2171. return function () {
  2172. return func.apply(this, args.concat(nativeSlice.call(arguments)));
  2173. };
  2174. }
  2175. /**
  2176. * @memberOf module:zrender/core/util
  2177. * @param {*} value
  2178. * @return {boolean}
  2179. */
  2180. function isArray(value) {
  2181. return objToString.call(value) === '[object Array]';
  2182. }
  2183. /**
  2184. * @memberOf module:zrender/core/util
  2185. * @param {*} value
  2186. * @return {boolean}
  2187. */
  2188. function isFunction(value) {
  2189. return typeof value === 'function';
  2190. }
  2191. /**
  2192. * @memberOf module:zrender/core/util
  2193. * @param {*} value
  2194. * @return {boolean}
  2195. */
  2196. function isString(value) {
  2197. return objToString.call(value) === '[object String]';
  2198. }
  2199. /**
  2200. * @memberOf module:zrender/core/util
  2201. * @param {*} value
  2202. * @return {boolean}
  2203. */
  2204. function isObject(value) {
  2205. // Avoid a V8 JIT bug in Chrome 19-20.
  2206. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  2207. var type = typeof value;
  2208. return type === 'function' || (!!value && type == 'object');
  2209. }
  2210. /**
  2211. * @memberOf module:zrender/core/util
  2212. * @param {*} value
  2213. * @return {boolean}
  2214. */
  2215. function isBuildInObject(value) {
  2216. return !!BUILTIN_OBJECT[objToString.call(value)]
  2217. || (value instanceof Gradient);
  2218. }
  2219. /**
  2220. * @memberOf module:zrender/core/util
  2221. * @param {*} value
  2222. * @return {boolean}
  2223. */
  2224. function isDom(value) {
  2225. return value && value.nodeType === 1
  2226. && typeof(value.nodeName) == 'string';
  2227. }
  2228. /**
  2229. * If value1 is not null, then return value1, otherwise judget rest of values.
  2230. * @memberOf module:zrender/core/util
  2231. * @return {*} Final value
  2232. */
  2233. function retrieve(values) {
  2234. for (var i = 0, len = arguments.length; i < len; i++) {
  2235. if (arguments[i] != null) {
  2236. return arguments[i];
  2237. }
  2238. }
  2239. }
  2240. /**
  2241. * @memberOf module:zrender/core/util
  2242. * @param {Array} arr
  2243. * @param {number} startIndex
  2244. * @param {number} endIndex
  2245. * @return {Array}
  2246. */
  2247. function slice() {
  2248. return Function.call.apply(nativeSlice, arguments);
  2249. }
  2250. /**
  2251. * @memberOf module:zrender/core/util
  2252. * @param {boolean} condition
  2253. * @param {string} message
  2254. */
  2255. function assert(condition, message) {
  2256. if (!condition) {
  2257. throw new Error(message);
  2258. }
  2259. }
  2260. var util = {
  2261. inherits: inherits,
  2262. mixin: mixin,
  2263. clone: clone,
  2264. merge: merge,
  2265. mergeAll: mergeAll,
  2266. extend: extend,
  2267. defaults: defaults,
  2268. getContext: getContext,
  2269. createCanvas: createCanvas,
  2270. indexOf: indexOf,
  2271. slice: slice,
  2272. find: find,
  2273. isArrayLike: isArrayLike,
  2274. each: each,
  2275. map: map,
  2276. reduce: reduce,
  2277. filter: filter,
  2278. bind: bind,
  2279. curry: curry,
  2280. isArray: isArray,
  2281. isString: isString,
  2282. isObject: isObject,
  2283. isFunction: isFunction,
  2284. isBuildInObject: isBuildInObject,
  2285. isDom: isDom,
  2286. retrieve: retrieve,
  2287. assert: assert,
  2288. noop: function () {}
  2289. };
  2290. module.exports = util;
  2291. /***/ },
  2292. /* 4 */
  2293. /***/ function(module, exports) {
  2294. /**
  2295. * @param {Array.<Object>} colorStops
  2296. */
  2297. var Gradient = function (colorStops) {
  2298. this.colorStops = colorStops || [];
  2299. };
  2300. Gradient.prototype = {
  2301. constructor: Gradient,
  2302. addColorStop: function (offset, color) {
  2303. this.colorStops.push({
  2304. offset: offset,
  2305. color: color
  2306. });
  2307. }
  2308. };
  2309. module.exports = Gradient;
  2310. /***/ },
  2311. /* 5 */
  2312. /***/ function(module, exports, __webpack_require__) {
  2313. var formatUtil = __webpack_require__(6);
  2314. var nubmerUtil = __webpack_require__(7);
  2315. var zrUtil = __webpack_require__(3);
  2316. var AXIS_DIMS = ['x', 'y', 'z', 'radius', 'angle'];
  2317. var modelUtil = {};
  2318. /**
  2319. * Create "each" method to iterate names.
  2320. *
  2321. * @pubilc
  2322. * @param {Array.<string>} names
  2323. * @param {Array.<string>=} attrs
  2324. * @return {Function}
  2325. */
  2326. modelUtil.createNameEach = function (names, attrs) {
  2327. names = names.slice();
  2328. var capitalNames = zrUtil.map(names, modelUtil.capitalFirst);
  2329. attrs = (attrs || []).slice();
  2330. var capitalAttrs = zrUtil.map(attrs, modelUtil.capitalFirst);
  2331. return function (callback, context) {
  2332. zrUtil.each(names, function (name, index) {
  2333. var nameObj = {name: name, capital: capitalNames[index]};
  2334. for (var j = 0; j < attrs.length; j++) {
  2335. nameObj[attrs[j]] = name + capitalAttrs[j];
  2336. }
  2337. callback.call(context, nameObj);
  2338. });
  2339. };
  2340. };
  2341. /**
  2342. * @public
  2343. */
  2344. modelUtil.capitalFirst = function (str) {
  2345. return str ? str.charAt(0).toUpperCase() + str.substr(1) : str;
  2346. };
  2347. /**
  2348. * Iterate each dimension name.
  2349. *
  2350. * @public
  2351. * @param {Function} callback The parameter is like:
  2352. * {
  2353. * name: 'angle',
  2354. * capital: 'Angle',
  2355. * axis: 'angleAxis',
  2356. * axisIndex: 'angleAixs',
  2357. * index: 'angleIndex'
  2358. * }
  2359. * @param {Object} context
  2360. */
  2361. modelUtil.eachAxisDim = modelUtil.createNameEach(AXIS_DIMS, ['axisIndex', 'axis', 'index']);
  2362. /**
  2363. * If value is not array, then translate it to array.
  2364. * @param {*} value
  2365. * @return {Array} [value] or value
  2366. */
  2367. modelUtil.normalizeToArray = function (value) {
  2368. return zrUtil.isArray(value)
  2369. ? value
  2370. : value == null
  2371. ? []
  2372. : [value];
  2373. };
  2374. /**
  2375. * If tow dataZoomModels has the same axis controlled, we say that they are 'linked'.
  2376. * dataZoomModels and 'links' make up one or more graphics.
  2377. * This function finds the graphic where the source dataZoomModel is in.
  2378. *
  2379. * @public
  2380. * @param {Function} forEachNode Node iterator.
  2381. * @param {Function} forEachEdgeType edgeType iterator
  2382. * @param {Function} edgeIdGetter Giving node and edgeType, return an array of edge id.
  2383. * @return {Function} Input: sourceNode, Output: Like {nodes: [], dims: {}}
  2384. */
  2385. modelUtil.createLinkedNodesFinder = function (forEachNode, forEachEdgeType, edgeIdGetter) {
  2386. return function (sourceNode) {
  2387. var result = {
  2388. nodes: [],
  2389. records: {} // key: edgeType.name, value: Object (key: edge id, value: boolean).
  2390. };
  2391. forEachEdgeType(function (edgeType) {
  2392. result.records[edgeType.name] = {};
  2393. });
  2394. if (!sourceNode) {
  2395. return result;
  2396. }
  2397. absorb(sourceNode, result);
  2398. var existsLink;
  2399. do {
  2400. existsLink = false;
  2401. forEachNode(processSingleNode);
  2402. }
  2403. while (existsLink);
  2404. function processSingleNode(node) {
  2405. if (!isNodeAbsorded(node, result) && isLinked(node, result)) {
  2406. absorb(node, result);
  2407. existsLink = true;
  2408. }
  2409. }
  2410. return result;
  2411. };
  2412. function isNodeAbsorded(node, result) {
  2413. return zrUtil.indexOf(result.nodes, node) >= 0;
  2414. }
  2415. function isLinked(node, result) {
  2416. var hasLink = false;
  2417. forEachEdgeType(function (edgeType) {
  2418. zrUtil.each(edgeIdGetter(node, edgeType) || [], function (edgeId) {
  2419. result.records[edgeType.name][edgeId] && (hasLink = true);
  2420. });
  2421. });
  2422. return hasLink;
  2423. }
  2424. function absorb(node, result) {
  2425. result.nodes.push(node);
  2426. forEachEdgeType(function (edgeType) {
  2427. zrUtil.each(edgeIdGetter(node, edgeType) || [], function (edgeId) {
  2428. result.records[edgeType.name][edgeId] = true;
  2429. });
  2430. });
  2431. }
  2432. };
  2433. /**
  2434. * Sync default option between normal and emphasis like `position` and `show`
  2435. * In case some one will write code like
  2436. * label: {
  2437. * normal: {
  2438. * show: false,
  2439. * position: 'outside',
  2440. * textStyle: {
  2441. * fontSize: 18
  2442. * }
  2443. * },
  2444. * emphasis: {
  2445. * show: true
  2446. * }
  2447. * }
  2448. * @param {Object} opt
  2449. * @param {Array.<string>} subOpts
  2450. */
  2451. modelUtil.defaultEmphasis = function (opt, subOpts) {
  2452. if (opt) {
  2453. var emphasisOpt = opt.emphasis = opt.emphasis || {};
  2454. var normalOpt = opt.normal = opt.normal || {};
  2455. // Default emphasis option from normal
  2456. zrUtil.each(subOpts, function (subOptName) {
  2457. var val = zrUtil.retrieve(emphasisOpt[subOptName], normalOpt[subOptName]);
  2458. if (val != null) {
  2459. emphasisOpt[subOptName] = val;
  2460. }
  2461. });
  2462. }
  2463. };
  2464. modelUtil.LABEL_OPTIONS = ['position', 'show', 'textStyle', 'distance', 'formatter'];
  2465. /**
  2466. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  2467. * This helper method retieves value from data.
  2468. * @param {string|number|Date|Array|Object} dataItem
  2469. * @return {number|string|Date|Array.<number|string|Date>}
  2470. */
  2471. modelUtil.getDataItemValue = function (dataItem) {
  2472. // Performance sensitive.
  2473. return dataItem && (dataItem.value == null ? dataItem : dataItem.value);
  2474. };
  2475. /**
  2476. * This helper method convert value in data.
  2477. * @param {string|number|Date} value
  2478. * @param {Object|string} [dimInfo] If string (like 'x'), dimType defaults 'number'.
  2479. */
  2480. modelUtil.converDataValue = function (value, dimInfo) {
  2481. // Performance sensitive.
  2482. var dimType = dimInfo && dimInfo.type;
  2483. if (dimType === 'ordinal') {
  2484. return value;
  2485. }
  2486. if (dimType === 'time' && !isFinite(value) && value != null && value !== '-') {
  2487. value = +nubmerUtil.parseDate(value);
  2488. }
  2489. // dimType defaults 'number'.
  2490. // If dimType is not ordinal and value is null or undefined or NaN or '-',
  2491. // parse to NaN.
  2492. return (value == null || value === '')
  2493. ? NaN : +value; // If string (like '-'), using '+' parse to NaN
  2494. };
  2495. modelUtil.dataFormatMixin = {
  2496. /**
  2497. * Get params for formatter
  2498. * @param {number} dataIndex
  2499. * @param {string} [dataType]
  2500. * @return {Object}
  2501. */
  2502. getDataParams: function (dataIndex, dataType) {
  2503. var data = this.getData(dataType);
  2504. var seriesIndex = this.seriesIndex;
  2505. var seriesName = this.name;
  2506. var rawValue = this.getRawValue(dataIndex, dataType);
  2507. var rawDataIndex = data.getRawIndex(dataIndex);
  2508. var name = data.getName(dataIndex, true);
  2509. var itemOpt = data.getRawDataItem(dataIndex);
  2510. return {
  2511. componentType: this.mainType,
  2512. componentSubType: this.subType,
  2513. seriesType: this.mainType === 'series' ? this.subType : null,
  2514. seriesIndex: seriesIndex,
  2515. seriesName: seriesName,
  2516. name: name,
  2517. dataIndex: rawDataIndex,
  2518. data: itemOpt,
  2519. dataType: dataType,
  2520. value: rawValue,
  2521. color: data.getItemVisual(dataIndex, 'color'),
  2522. // Param name list for mapping `a`, `b`, `c`, `d`, `e`
  2523. $vars: ['seriesName', 'name', 'value']
  2524. };
  2525. },
  2526. /**
  2527. * Format label
  2528. * @param {number} dataIndex
  2529. * @param {string} [status='normal'] 'normal' or 'emphasis'
  2530. * @param {string} [dataType]
  2531. * @param {number} [dimIndex]
  2532. * @return {string}
  2533. */
  2534. getFormattedLabel: function (dataIndex, status, dataType, dimIndex) {
  2535. status = status || 'normal';
  2536. var data = this.getData(dataType);
  2537. var itemModel = data.getItemModel(dataIndex);
  2538. var params = this.getDataParams(dataIndex, dataType);
  2539. if (dimIndex != null && zrUtil.isArray(params.value)) {
  2540. params.value = params.value[dimIndex];
  2541. }
  2542. var formatter = itemModel.get(['label', status, 'formatter']);
  2543. if (typeof formatter === 'function') {
  2544. params.status = status;
  2545. return formatter(params);
  2546. }
  2547. else if (typeof formatter === 'string') {
  2548. return formatUtil.formatTpl(formatter, params);
  2549. }
  2550. },
  2551. /**
  2552. * Get raw value in option
  2553. * @param {number} idx
  2554. * @param {string} [dataType]
  2555. * @return {Object}
  2556. */
  2557. getRawValue: function (idx, dataType) {
  2558. var data = this.getData(dataType);
  2559. var dataItem = data.getRawDataItem(idx);
  2560. if (dataItem != null) {
  2561. return (zrUtil.isObject(dataItem) && !zrUtil.isArray(dataItem))
  2562. ? dataItem.value : dataItem;
  2563. }
  2564. },
  2565. /**
  2566. * Should be implemented.
  2567. * @param {number} dataIndex
  2568. * @param {boolean} [multipleSeries=false]
  2569. * @param {number} [dataType]
  2570. * @return {string} tooltip string
  2571. */
  2572. formatTooltip: zrUtil.noop
  2573. };
  2574. /**
  2575. * Mapping to exists for merge.
  2576. *
  2577. * @public
  2578. * @param {Array.<Object>|Array.<module:echarts/model/Component>} exists
  2579. * @param {Object|Array.<Object>} newCptOptions
  2580. * @return {Array.<Object>} Result, like [{exist: ..., option: ...}, {}],
  2581. * which order is the same as exists.
  2582. */
  2583. modelUtil.mappingToExists = function (exists, newCptOptions) {
  2584. // Mapping by the order by original option (but not order of
  2585. // new option) in merge mode. Because we should ensure
  2586. // some specified index (like xAxisIndex) is consistent with
  2587. // original option, which is easy to understand, espatially in
  2588. // media query. And in most case, merge option is used to
  2589. // update partial option but not be expected to change order.
  2590. newCptOptions = (newCptOptions || []).slice();
  2591. var result = zrUtil.map(exists || [], function (obj, index) {
  2592. return {exist: obj};
  2593. });
  2594. // Mapping by id or name if specified.
  2595. zrUtil.each(newCptOptions, function (cptOption, index) {
  2596. if (!zrUtil.isObject(cptOption)) {
  2597. return;
  2598. }
  2599. for (var i = 0; i < result.length; i++) {
  2600. var exist = result[i].exist;
  2601. if (!result[i].option // Consider name: two map to one.
  2602. && (
  2603. // id has highest priority.
  2604. (cptOption.id != null && exist.id === cptOption.id + '')
  2605. || (cptOption.name != null
  2606. && !modelUtil.isIdInner(cptOption)
  2607. && !modelUtil.isIdInner(exist)
  2608. && exist.name === cptOption.name + ''
  2609. )
  2610. )
  2611. ) {
  2612. result[i].option = cptOption;
  2613. newCptOptions[index] = null;
  2614. break;
  2615. }
  2616. }
  2617. });
  2618. // Otherwise mapping by index.
  2619. zrUtil.each(newCptOptions, function (cptOption, index) {
  2620. if (!zrUtil.isObject(cptOption)) {
  2621. return;
  2622. }
  2623. var i = 0;
  2624. for (; i < result.length; i++) {
  2625. var exist = result[i].exist;
  2626. if (!result[i].option
  2627. && !modelUtil.isIdInner(exist)
  2628. // Caution:
  2629. // Do not overwrite id. But name can be overwritten,
  2630. // because axis use name as 'show label text'.
  2631. // 'exist' always has id and name and we dont
  2632. // need to check it.
  2633. && cptOption.id == null
  2634. ) {
  2635. result[i].option = cptOption;
  2636. break;
  2637. }
  2638. }
  2639. if (i >= result.length) {
  2640. result.push({option: cptOption});
  2641. }
  2642. });
  2643. return result;
  2644. };
  2645. /**
  2646. * @public
  2647. * @param {Object} cptOption
  2648. * @return {boolean}
  2649. */
  2650. modelUtil.isIdInner = function (cptOption) {
  2651. return zrUtil.isObject(cptOption)
  2652. && cptOption.id
  2653. && (cptOption.id + '').indexOf('\0_ec_\0') === 0;
  2654. };
  2655. module.exports = modelUtil;
  2656. /***/ },
  2657. /* 6 */
  2658. /***/ function(module, exports, __webpack_require__) {
  2659. var zrUtil = __webpack_require__(3);
  2660. var numberUtil = __webpack_require__(7);
  2661. /**
  2662. * 每三位默认加,格式化
  2663. * @type {string|number} x
  2664. */
  2665. function addCommas(x) {
  2666. if (isNaN(x)) {
  2667. return '-';
  2668. }
  2669. x = (x + '').split('.');
  2670. return x[0].replace(/(\d{1,3})(?=(?:\d{3})+(?!\d))/g,'$1,')
  2671. + (x.length > 1 ? ('.' + x[1]) : '');
  2672. }
  2673. /**
  2674. * @param {string} str
  2675. * @return {string} str
  2676. */
  2677. function toCamelCase(str) {
  2678. return str.toLowerCase().replace(/-(.)/g, function(match, group1) {
  2679. return group1.toUpperCase();
  2680. });
  2681. }
  2682. /**
  2683. * Normalize css liked array configuration
  2684. * e.g.
  2685. * 3 => [3, 3, 3, 3]
  2686. * [4, 2] => [4, 2, 4, 2]
  2687. * [4, 3, 2] => [4, 3, 2, 3]
  2688. * @param {number|Array.<number>} val
  2689. */
  2690. function normalizeCssArray(val) {
  2691. var len = val.length;
  2692. if (typeof (val) === 'number') {
  2693. return [val, val, val, val];
  2694. }
  2695. else if (len === 2) {
  2696. // vertical | horizontal
  2697. return [val[0], val[1], val[0], val[1]];
  2698. }
  2699. else if (len === 3) {
  2700. // top | horizontal | bottom
  2701. return [val[0], val[1], val[2], val[1]];
  2702. }
  2703. return val;
  2704. }
  2705. function encodeHTML(source) {
  2706. return String(source)
  2707. .replace(/&/g, '&amp;')
  2708. .replace(/</g, '&lt;')
  2709. .replace(/>/g, '&gt;')
  2710. .replace(/"/g, '&quot;')
  2711. .replace(/'/g, '&#39;');
  2712. }
  2713. var TPL_VAR_ALIAS = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
  2714. function wrapVar(varName, seriesIdx) {
  2715. return '{' + varName + (seriesIdx == null ? '' : seriesIdx) + '}';
  2716. }
  2717. /**
  2718. * Template formatter
  2719. * @param {string} tpl
  2720. * @param {Array.<Object>|Object} paramsList
  2721. * @return {string}
  2722. */
  2723. function formatTpl(tpl, paramsList) {
  2724. if (!zrUtil.isArray(paramsList)) {
  2725. paramsList = [paramsList];
  2726. }
  2727. var seriesLen = paramsList.length;
  2728. if (!seriesLen) {
  2729. return '';
  2730. }
  2731. var $vars = paramsList[0].$vars;
  2732. for (var i = 0; i < $vars.length; i++) {
  2733. var alias = TPL_VAR_ALIAS[i];
  2734. tpl = tpl.replace(wrapVar(alias), wrapVar(alias, 0));
  2735. }
  2736. for (var seriesIdx = 0; seriesIdx < seriesLen; seriesIdx++) {
  2737. for (var k = 0; k < $vars.length; k++) {
  2738. tpl = tpl.replace(
  2739. wrapVar(TPL_VAR_ALIAS[k], seriesIdx),
  2740. paramsList[seriesIdx][$vars[k]]
  2741. );
  2742. }
  2743. }
  2744. return tpl;
  2745. }
  2746. /**
  2747. * ISO Date format
  2748. * @param {string} tpl
  2749. * @param {number} value
  2750. * @inner
  2751. */
  2752. function formatTime(tpl, value) {
  2753. if (tpl === 'week'
  2754. || tpl === 'month'
  2755. || tpl === 'quarter'
  2756. || tpl === 'half-year'
  2757. || tpl === 'year'
  2758. ) {
  2759. tpl = 'MM-dd\nyyyy';
  2760. }
  2761. var date = numberUtil.parseDate(value);
  2762. var y = date.getFullYear();
  2763. var M = date.getMonth() + 1;
  2764. var d = date.getDate();
  2765. var h = date.getHours();
  2766. var m = date.getMinutes();
  2767. var s = date.getSeconds();
  2768. tpl = tpl.replace('MM', s2d(M))
  2769. .toLowerCase()
  2770. .replace('yyyy', y)
  2771. .replace('yy', y % 100)
  2772. .replace('dd', s2d(d))
  2773. .replace('d', d)
  2774. .replace('hh', s2d(h))
  2775. .replace('h', h)
  2776. .replace('mm', s2d(m))
  2777. .replace('m', m)
  2778. .replace('ss', s2d(s))
  2779. .replace('s', s);
  2780. return tpl;
  2781. }
  2782. /**
  2783. * @param {string} str
  2784. * @return {string}
  2785. * @inner
  2786. */
  2787. function s2d(str) {
  2788. return str < 10 ? ('0' + str) : str;
  2789. }
  2790. module.exports = {
  2791. normalizeCssArray: normalizeCssArray,
  2792. addCommas: addCommas,
  2793. toCamelCase: toCamelCase,
  2794. encodeHTML: encodeHTML,
  2795. formatTpl: formatTpl,
  2796. formatTime: formatTime
  2797. };
  2798. /***/ },
  2799. /* 7 */
  2800. /***/ function(module, exports) {
  2801. /**
  2802. * 数值处理模块
  2803. * @module echarts/util/number
  2804. */
  2805. var number = {};
  2806. var RADIAN_EPSILON = 1e-4;
  2807. function _trim(str) {
  2808. return str.replace(/^\s+/, '').replace(/\s+$/, '');
  2809. }
  2810. /**
  2811. * Linear mapping a value from domain to range
  2812. * @memberOf module:echarts/util/number
  2813. * @param {(number|Array.<number>)} val
  2814. * @param {Array.<number>} domain Domain extent domain[0] can be bigger than domain[1]
  2815. * @param {Array.<number>} range Range extent range[0] can be bigger than range[1]
  2816. * @param {boolean} clamp
  2817. * @return {(number|Array.<number>}
  2818. */
  2819. number.linearMap = function (val, domain, range, clamp) {
  2820. var subDomain = domain[1] - domain[0];
  2821. var subRange = range[1] - range[0];
  2822. if (subDomain === 0) {
  2823. return subRange === 0
  2824. ? range[0]
  2825. : (range[0] + range[1]) / 2;
  2826. }
  2827. // Avoid accuracy problem in edge, such as
  2828. // 146.39 - 62.83 === 83.55999999999999.
  2829. // See echarts/test/ut/spec/util/number.js#linearMap#accuracyError
  2830. // It is a little verbose for efficiency considering this method
  2831. // is a hotspot.
  2832. if (clamp) {
  2833. if (subDomain > 0) {
  2834. if (val <= domain[0]) {
  2835. return range[0];
  2836. }
  2837. else if (val >= domain[1]) {
  2838. return range[1];
  2839. }
  2840. }
  2841. else {
  2842. if (val >= domain[0]) {
  2843. return range[0];
  2844. }
  2845. else if (val <= domain[1]) {
  2846. return range[1];
  2847. }
  2848. }
  2849. }
  2850. else {
  2851. if (val === domain[0]) {
  2852. return range[0];
  2853. }
  2854. if (val === domain[1]) {
  2855. return range[1];
  2856. }
  2857. }
  2858. return (val - domain[0]) / subDomain * subRange + range[0];
  2859. };
  2860. /**
  2861. * Convert a percent string to absolute number.
  2862. * Returns NaN if percent is not a valid string or number
  2863. * @memberOf module:echarts/util/number
  2864. * @param {string|number} percent
  2865. * @param {number} all
  2866. * @return {number}
  2867. */
  2868. number.parsePercent = function(percent, all) {
  2869. switch (percent) {
  2870. case 'center':
  2871. case 'middle':
  2872. percent = '50%';
  2873. break;
  2874. case 'left':
  2875. case 'top':
  2876. percent = '0%';
  2877. break;
  2878. case 'right':
  2879. case 'bottom':
  2880. percent = '100%';
  2881. break;
  2882. }
  2883. if (typeof percent === 'string') {
  2884. if (_trim(percent).match(/%$/)) {
  2885. return parseFloat(percent) / 100 * all;
  2886. }
  2887. return parseFloat(percent);
  2888. }
  2889. return percent == null ? NaN : +percent;
  2890. };
  2891. /**
  2892. * Fix rounding error of float numbers
  2893. * @param {number} x
  2894. * @return {number}
  2895. */
  2896. number.round = function (x) {
  2897. // PENDING
  2898. return +(+x).toFixed(10);
  2899. };
  2900. number.asc = function (arr) {
  2901. arr.sort(function (a, b) {
  2902. return a - b;
  2903. });
  2904. return arr;
  2905. };
  2906. /**
  2907. * Get precision
  2908. * @param {number} val
  2909. */
  2910. number.getPrecision = function (val) {
  2911. if (isNaN(val)) {
  2912. return 0;
  2913. }
  2914. // It is much faster than methods converting number to string as follows
  2915. // var tmp = val.toString();
  2916. // return tmp.length - 1 - tmp.indexOf('.');
  2917. // especially when precision is low
  2918. var e = 1;
  2919. var count = 0;
  2920. while (Math.round(val * e) / e !== val) {
  2921. e *= 10;
  2922. count++;
  2923. }
  2924. return count;
  2925. };
  2926. /**
  2927. * @param {Array.<number>} dataExtent
  2928. * @param {Array.<number>} pixelExtent
  2929. * @return {number} precision
  2930. */
  2931. number.getPixelPrecision = function (dataExtent, pixelExtent) {
  2932. var log = Math.log;
  2933. var LN10 = Math.LN10;
  2934. var dataQuantity = Math.floor(log(dataExtent[1] - dataExtent[0]) / LN10);
  2935. var sizeQuantity = Math.round(log(Math.abs(pixelExtent[1] - pixelExtent[0])) / LN10);
  2936. return Math.max(
  2937. -dataQuantity + sizeQuantity,
  2938. 0
  2939. );
  2940. };
  2941. // Number.MAX_SAFE_INTEGER, ie do not support.
  2942. number.MAX_SAFE_INTEGER = 9007199254740991;
  2943. /**
  2944. * To 0 - 2 * PI, considering negative radian.
  2945. * @param {number} radian
  2946. * @return {number}
  2947. */
  2948. number.remRadian = function (radian) {
  2949. var pi2 = Math.PI * 2;
  2950. return (radian % pi2 + pi2) % pi2;
  2951. };
  2952. /**
  2953. * @param {type} radian
  2954. * @return {boolean}
  2955. */
  2956. number.isRadianAroundZero = function (val) {
  2957. return val > -RADIAN_EPSILON && val < RADIAN_EPSILON;
  2958. };
  2959. /**
  2960. * @param {string|Date|number} value
  2961. * @return {number} timestamp
  2962. */
  2963. number.parseDate = function (value) {
  2964. return value instanceof Date
  2965. ? value
  2966. : new Date(
  2967. typeof value === 'string'
  2968. ? value.replace(/-/g, '/')
  2969. : Math.round(value)
  2970. );
  2971. };
  2972. /**
  2973. * Quantity of a number. e.g. 0.1, 1, 10, 100
  2974. * @param {number} val
  2975. * @return {number}
  2976. */
  2977. number.quantity = function (val) {
  2978. return Math.pow(10, Math.floor(Math.log(val) / Math.LN10));
  2979. };
  2980. // "Nice Numbers for Graph Labels" of Graphic Gems
  2981. /**
  2982. * find a “nice” number approximately equal to x. Round the number if round = true, take ceiling if round = false
  2983. * The primary observation is that the “nicest” numbers in decimal are 1, 2, and 5, and all power-of-ten multiples of these numbers.
  2984. * @param {number} val
  2985. * @param {boolean} round
  2986. * @return {number}
  2987. */
  2988. number.nice = function (val, round) {
  2989. var exp10 = number.quantity(val);
  2990. var f = val / exp10; // between 1 and 10
  2991. var nf;
  2992. if (round) {
  2993. if (f < 1.5) { nf = 1; }
  2994. else if (f < 2.5) { nf = 2; }
  2995. else if (f < 4) { nf = 3; }
  2996. else if (f < 7) { nf = 5; }
  2997. else { nf = 10; }
  2998. }
  2999. else {
  3000. if (f < 1) { nf = 1; }
  3001. else if (f < 2) { nf = 2; }
  3002. else if (f < 3) { nf = 3; }
  3003. else if (f < 5) { nf = 5; }
  3004. else { nf = 10; }
  3005. }
  3006. return nf * exp10;
  3007. };
  3008. module.exports = number;
  3009. /***/ },
  3010. /* 8 */
  3011. /***/ function(module, exports, __webpack_require__) {
  3012. /**
  3013. * @module echarts/model/Model
  3014. */
  3015. var zrUtil = __webpack_require__(3);
  3016. var clazzUtil = __webpack_require__(9);
  3017. /**
  3018. * @alias module:echarts/model/Model
  3019. * @constructor
  3020. * @param {Object} option
  3021. * @param {module:echarts/model/Model} [parentModel]
  3022. * @param {module:echarts/model/Global} [ecModel]
  3023. * @param {Object} extraOpt
  3024. */
  3025. function Model(option, parentModel, ecModel, extraOpt) {
  3026. /**
  3027. * @type {module:echarts/model/Model}
  3028. * @readOnly
  3029. */
  3030. this.parentModel = parentModel;
  3031. /**
  3032. * @type {module:echarts/model/Global}
  3033. * @readOnly
  3034. */
  3035. this.ecModel = ecModel;
  3036. /**
  3037. * @type {Object}
  3038. * @protected
  3039. */
  3040. this.option = option;
  3041. // Simple optimization
  3042. if (this.init) {
  3043. if (arguments.length <= 4) {
  3044. this.init(option, parentModel, ecModel, extraOpt);
  3045. }
  3046. else {
  3047. this.init.apply(this, arguments);
  3048. }
  3049. }
  3050. }
  3051. Model.prototype = {
  3052. constructor: Model,
  3053. /**
  3054. * Model 的初始化函数
  3055. * @param {Object} option
  3056. */
  3057. init: null,
  3058. /**
  3059. * 从新的 Option merge
  3060. */
  3061. mergeOption: function (option) {
  3062. zrUtil.merge(this.option, option, true);
  3063. },
  3064. /**
  3065. * @param {string} path
  3066. * @param {boolean} [ignoreParent=false]
  3067. * @return {*}
  3068. */
  3069. get: function (path, ignoreParent) {
  3070. if (!path) {
  3071. return this.option;
  3072. }
  3073. if (typeof path === 'string') {
  3074. path = path.split('.');
  3075. }
  3076. var obj = this.option;
  3077. var parentModel = this.parentModel;
  3078. for (var i = 0; i < path.length; i++) {
  3079. // Ignore empty
  3080. if (!path[i]) {
  3081. continue;
  3082. }
  3083. // obj could be number/string/... (like 0)
  3084. obj = (obj && typeof obj === 'object') ? obj[path[i]] : null;
  3085. if (obj == null) {
  3086. break;
  3087. }
  3088. }
  3089. if (obj == null && parentModel && !ignoreParent) {
  3090. obj = parentModel.get(path);
  3091. }
  3092. return obj;
  3093. },
  3094. /**
  3095. * @param {string} key
  3096. * @param {boolean} [ignoreParent=false]
  3097. * @return {*}
  3098. */
  3099. getShallow: function (key, ignoreParent) {
  3100. var option = this.option;
  3101. var val = option && option[key];
  3102. var parentModel = this.parentModel;
  3103. if (val == null && parentModel && !ignoreParent) {
  3104. val = parentModel.getShallow(key);
  3105. }
  3106. return val;
  3107. },
  3108. /**
  3109. * @param {string} path
  3110. * @param {module:echarts/model/Model} [parentModel]
  3111. * @return {module:echarts/model/Model}
  3112. */
  3113. getModel: function (path, parentModel) {
  3114. var obj = this.get(path, true);
  3115. var thisParentModel = this.parentModel;
  3116. var model = new Model(
  3117. obj, parentModel || (thisParentModel && thisParentModel.getModel(path)),
  3118. this.ecModel
  3119. );
  3120. return model;
  3121. },
  3122. /**
  3123. * If model has option
  3124. */
  3125. isEmpty: function () {
  3126. return this.option == null;
  3127. },
  3128. restoreData: function () {},
  3129. // Pending
  3130. clone: function () {
  3131. var Ctor = this.constructor;
  3132. return new Ctor(zrUtil.clone(this.option));
  3133. },
  3134. setReadOnly: function (properties) {
  3135. clazzUtil.setReadOnly(this, properties);
  3136. }
  3137. };
  3138. // Enable Model.extend.
  3139. clazzUtil.enableClassExtend(Model);
  3140. var mixin = zrUtil.mixin;
  3141. mixin(Model, __webpack_require__(10));
  3142. mixin(Model, __webpack_require__(12));
  3143. mixin(Model, __webpack_require__(13));
  3144. mixin(Model, __webpack_require__(18));
  3145. module.exports = Model;
  3146. /***/ },
  3147. /* 9 */
  3148. /***/ function(module, exports, __webpack_require__) {
  3149. var zrUtil = __webpack_require__(3);
  3150. var clazz = {};
  3151. var TYPE_DELIMITER = '.';
  3152. var IS_CONTAINER = '___EC__COMPONENT__CONTAINER___';
  3153. /**
  3154. * @public
  3155. */
  3156. var parseClassType = clazz.parseClassType = function (componentType) {
  3157. var ret = {main: '', sub: ''};
  3158. if (componentType) {
  3159. componentType = componentType.split(TYPE_DELIMITER);
  3160. ret.main = componentType[0] || '';
  3161. ret.sub = componentType[1] || '';
  3162. }
  3163. return ret;
  3164. };
  3165. /**
  3166. * @public
  3167. */
  3168. clazz.enableClassExtend = function (RootClass, preConstruct) {
  3169. RootClass.extend = function (proto) {
  3170. var ExtendedClass = function () {
  3171. preConstruct && preConstruct.apply(this, arguments);
  3172. RootClass.apply(this, arguments);
  3173. };
  3174. zrUtil.extend(ExtendedClass.prototype, proto);
  3175. ExtendedClass.extend = this.extend;
  3176. ExtendedClass.superCall = superCall;
  3177. ExtendedClass.superApply = superApply;
  3178. zrUtil.inherits(ExtendedClass, this);
  3179. ExtendedClass.superClass = this;
  3180. return ExtendedClass;
  3181. };
  3182. };
  3183. // superCall should have class info, which can not be fetch from 'this'.
  3184. // Consider this case:
  3185. // class A has method f,
  3186. // class B inherits class A, overrides method f, f call superApply('f'),
  3187. // class C inherits class B, do not overrides method f,
  3188. // then when method of class C is called, dead loop occured.
  3189. function superCall(context, methodName) {
  3190. var args = zrUtil.slice(arguments, 2);
  3191. return this.superClass.prototype[methodName].apply(context, args);
  3192. }
  3193. function superApply(context, methodName, args) {
  3194. return this.superClass.prototype[methodName].apply(context, args);
  3195. }
  3196. /**
  3197. * @param {Object} entity
  3198. * @param {Object} options
  3199. * @param {boolean} [options.registerWhenExtend]
  3200. * @public
  3201. */
  3202. clazz.enableClassManagement = function (entity, options) {
  3203. options = options || {};
  3204. /**
  3205. * Component model classes
  3206. * key: componentType,
  3207. * value:
  3208. * componentClass, when componentType is 'xxx'
  3209. * or Object.<subKey, componentClass>, when componentType is 'xxx.yy'
  3210. * @type {Object}
  3211. */
  3212. var storage = {};
  3213. entity.registerClass = function (Clazz, componentType) {
  3214. if (componentType) {
  3215. componentType = parseClassType(componentType);
  3216. if (!componentType.sub) {
  3217. if (storage[componentType.main]) {
  3218. throw new Error(componentType.main + 'exists.');
  3219. }
  3220. storage[componentType.main] = Clazz;
  3221. }
  3222. else if (componentType.sub !== IS_CONTAINER) {
  3223. var container = makeContainer(componentType);
  3224. container[componentType.sub] = Clazz;
  3225. }
  3226. }
  3227. return Clazz;
  3228. };
  3229. entity.getClass = function (componentTypeMain, subType, throwWhenNotFound) {
  3230. var Clazz = storage[componentTypeMain];
  3231. if (Clazz && Clazz[IS_CONTAINER]) {
  3232. Clazz = subType ? Clazz[subType] : null;
  3233. }
  3234. if (throwWhenNotFound && !Clazz) {
  3235. throw new Error(
  3236. 'Component ' + componentTypeMain + '.' + (subType || '') + ' not exists. Load it first.'
  3237. );
  3238. }
  3239. return Clazz;
  3240. };
  3241. entity.getClassesByMainType = function (componentType) {
  3242. componentType = parseClassType(componentType);
  3243. var result = [];
  3244. var obj = storage[componentType.main];
  3245. if (obj && obj[IS_CONTAINER]) {
  3246. zrUtil.each(obj, function (o, type) {
  3247. type !== IS_CONTAINER && result.push(o);
  3248. });
  3249. }
  3250. else {
  3251. result.push(obj);
  3252. }
  3253. return result;
  3254. };
  3255. entity.hasClass = function (componentType) {
  3256. // Just consider componentType.main.
  3257. componentType = parseClassType(componentType);
  3258. return !!storage[componentType.main];
  3259. };
  3260. /**
  3261. * @return {Array.<string>} Like ['aa', 'bb'], but can not be ['aa.xx']
  3262. */
  3263. entity.getAllClassMainTypes = function () {
  3264. var types = [];
  3265. zrUtil.each(storage, function (obj, type) {
  3266. types.push(type);
  3267. });
  3268. return types;
  3269. };
  3270. /**
  3271. * If a main type is container and has sub types
  3272. * @param {string} mainType
  3273. * @return {boolean}
  3274. */
  3275. entity.hasSubTypes = function (componentType) {
  3276. componentType = parseClassType(componentType);
  3277. var obj = storage[componentType.main];
  3278. return obj && obj[IS_CONTAINER];
  3279. };
  3280. entity.parseClassType = parseClassType;
  3281. function makeContainer(componentType) {
  3282. var container = storage[componentType.main];
  3283. if (!container || !container[IS_CONTAINER]) {
  3284. container = storage[componentType.main] = {};
  3285. container[IS_CONTAINER] = true;
  3286. }
  3287. return container;
  3288. }
  3289. if (options.registerWhenExtend) {
  3290. var originalExtend = entity.extend;
  3291. if (originalExtend) {
  3292. entity.extend = function (proto) {
  3293. var ExtendedClass = originalExtend.call(this, proto);
  3294. return entity.registerClass(ExtendedClass, proto.type);
  3295. };
  3296. }
  3297. }
  3298. return entity;
  3299. };
  3300. /**
  3301. * @param {string|Array.<string>} properties
  3302. */
  3303. clazz.setReadOnly = function (obj, properties) {
  3304. // FIXME It seems broken in IE8 simulation of IE11
  3305. // if (!zrUtil.isArray(properties)) {
  3306. // properties = properties != null ? [properties] : [];
  3307. // }
  3308. // zrUtil.each(properties, function (prop) {
  3309. // var value = obj[prop];
  3310. // Object.defineProperty
  3311. // && Object.defineProperty(obj, prop, {
  3312. // value: value, writable: false
  3313. // });
  3314. // zrUtil.isArray(obj[prop])
  3315. // && Object.freeze
  3316. // && Object.freeze(obj[prop]);
  3317. // });
  3318. };
  3319. module.exports = clazz;
  3320. /***/ },
  3321. /* 10 */
  3322. /***/ function(module, exports, __webpack_require__) {
  3323. var getLineStyle = __webpack_require__(11)(
  3324. [
  3325. ['lineWidth', 'width'],
  3326. ['stroke', 'color'],
  3327. ['opacity'],
  3328. ['shadowBlur'],
  3329. ['shadowOffsetX'],
  3330. ['shadowOffsetY'],
  3331. ['shadowColor']
  3332. ]
  3333. );
  3334. module.exports = {
  3335. getLineStyle: function (excludes) {
  3336. var style = getLineStyle.call(this, excludes);
  3337. var lineDash = this.getLineDash();
  3338. lineDash && (style.lineDash = lineDash);
  3339. return style;
  3340. },
  3341. getLineDash: function () {
  3342. var lineType = this.get('type');
  3343. return (lineType === 'solid' || lineType == null) ? null
  3344. : (lineType === 'dashed' ? [5, 5] : [1, 1]);
  3345. }
  3346. };
  3347. /***/ },
  3348. /* 11 */
  3349. /***/ function(module, exports, __webpack_require__) {
  3350. // TODO Parse shadow style
  3351. // TODO Only shallow path support
  3352. var zrUtil = __webpack_require__(3);
  3353. module.exports = function (properties) {
  3354. // Normalize
  3355. for (var i = 0; i < properties.length; i++) {
  3356. if (!properties[i][1]) {
  3357. properties[i][1] = properties[i][0];
  3358. }
  3359. }
  3360. return function (excludes) {
  3361. var style = {};
  3362. for (var i = 0; i < properties.length; i++) {
  3363. var propName = properties[i][1];
  3364. if (excludes && zrUtil.indexOf(excludes, propName) >= 0) {
  3365. continue;
  3366. }
  3367. var val = this.getShallow(propName);
  3368. if (val != null) {
  3369. style[properties[i][0]] = val;
  3370. }
  3371. }
  3372. return style;
  3373. };
  3374. };
  3375. /***/ },
  3376. /* 12 */
  3377. /***/ function(module, exports, __webpack_require__) {
  3378. module.exports = {
  3379. getAreaStyle: __webpack_require__(11)(
  3380. [
  3381. ['fill', 'color'],
  3382. ['shadowBlur'],
  3383. ['shadowOffsetX'],
  3384. ['shadowOffsetY'],
  3385. ['opacity'],
  3386. ['shadowColor']
  3387. ]
  3388. )
  3389. };
  3390. /***/ },
  3391. /* 13 */
  3392. /***/ function(module, exports, __webpack_require__) {
  3393. var textContain = __webpack_require__(14);
  3394. function getShallow(model, path) {
  3395. return model && model.getShallow(path);
  3396. }
  3397. module.exports = {
  3398. /**
  3399. * Get color property or get color from option.textStyle.color
  3400. * @return {string}
  3401. */
  3402. getTextColor: function () {
  3403. var ecModel = this.ecModel;
  3404. return this.getShallow('color')
  3405. || (ecModel && ecModel.get('textStyle.color'));
  3406. },
  3407. /**
  3408. * Create font string from fontStyle, fontWeight, fontSize, fontFamily
  3409. * @return {string}
  3410. */
  3411. getFont: function () {
  3412. var ecModel = this.ecModel;
  3413. var gTextStyleModel = ecModel && ecModel.getModel('textStyle');
  3414. return [
  3415. // FIXME in node-canvas fontWeight is before fontStyle
  3416. this.getShallow('fontStyle') || getShallow(gTextStyleModel, 'fontStyle'),
  3417. this.getShallow('fontWeight') || getShallow(gTextStyleModel, 'fontWeight'),
  3418. (this.getShallow('fontSize') || getShallow(gTextStyleModel, 'fontSize') || 12) + 'px',
  3419. this.getShallow('fontFamily') || getShallow(gTextStyleModel, 'fontFamily') || 'sans-serif'
  3420. ].join(' ');
  3421. },
  3422. getTextRect: function (text) {
  3423. var textStyle = this.get('textStyle') || {};
  3424. return textContain.getBoundingRect(
  3425. text,
  3426. this.getFont(),
  3427. textStyle.align,
  3428. textStyle.baseline
  3429. );
  3430. },
  3431. ellipsis: function (text, containerWidth, options) {
  3432. return textContain.ellipsis(
  3433. text, this.getFont(), containerWidth, options
  3434. );
  3435. }
  3436. };
  3437. /***/ },
  3438. /* 14 */
  3439. /***/ function(module, exports, __webpack_require__) {
  3440. var textWidthCache = {};
  3441. var textWidthCacheCounter = 0;
  3442. var TEXT_CACHE_MAX = 5000;
  3443. var util = __webpack_require__(3);
  3444. var BoundingRect = __webpack_require__(15);
  3445. function getTextWidth(text, textFont) {
  3446. var key = text + ':' + textFont;
  3447. if (textWidthCache[key]) {
  3448. return textWidthCache[key];
  3449. }
  3450. var textLines = (text + '').split('\n');
  3451. var width = 0;
  3452. for (var i = 0, l = textLines.length; i < l; i++) {
  3453. // measureText 可以被覆盖以兼容不支持 Canvas 的环境
  3454. width = Math.max(textContain.measureText(textLines[i], textFont).width, width);
  3455. }
  3456. if (textWidthCacheCounter > TEXT_CACHE_MAX) {
  3457. textWidthCacheCounter = 0;
  3458. textWidthCache = {};
  3459. }
  3460. textWidthCacheCounter++;
  3461. textWidthCache[key] = width;
  3462. return width;
  3463. }
  3464. function getTextRect(text, textFont, textAlign, textBaseline) {
  3465. var textLineLen = ((text || '') + '').split('\n').length;
  3466. var width = getTextWidth(text, textFont);
  3467. // FIXME 高度计算比较粗暴
  3468. var lineHeight = getTextWidth('国', textFont);
  3469. var height = textLineLen * lineHeight;
  3470. var rect = new BoundingRect(0, 0, width, height);
  3471. // Text has a special line height property
  3472. rect.lineHeight = lineHeight;
  3473. switch (textBaseline) {
  3474. case 'bottom':
  3475. case 'alphabetic':
  3476. rect.y -= lineHeight;
  3477. break;
  3478. case 'middle':
  3479. rect.y -= lineHeight / 2;
  3480. break;
  3481. // case 'hanging':
  3482. // case 'top':
  3483. }
  3484. // FIXME Right to left language
  3485. switch (textAlign) {
  3486. case 'end':
  3487. case 'right':
  3488. rect.x -= rect.width;
  3489. break;
  3490. case 'center':
  3491. rect.x -= rect.width / 2;
  3492. break;
  3493. // case 'start':
  3494. // case 'left':
  3495. }
  3496. return rect;
  3497. }
  3498. function adjustTextPositionOnRect(textPosition, rect, textRect, distance) {
  3499. var x = rect.x;
  3500. var y = rect.y;
  3501. var height = rect.height;
  3502. var width = rect.width;
  3503. var textHeight = textRect.height;
  3504. var halfHeight = height / 2 - textHeight / 2;
  3505. var textAlign = 'left';
  3506. switch (textPosition) {
  3507. case 'left':
  3508. x -= distance;
  3509. y += halfHeight;
  3510. textAlign = 'right';
  3511. break;
  3512. case 'right':
  3513. x += distance + width;
  3514. y += halfHeight;
  3515. textAlign = 'left';
  3516. break;
  3517. case 'top':
  3518. x += width / 2;
  3519. y -= distance + textHeight;
  3520. textAlign = 'center';
  3521. break;
  3522. case 'bottom':
  3523. x += width / 2;
  3524. y += height + distance;
  3525. textAlign = 'center';
  3526. break;
  3527. case 'inside':
  3528. x += width / 2;
  3529. y += halfHeight;
  3530. textAlign = 'center';
  3531. break;
  3532. case 'insideLeft':
  3533. x += distance;
  3534. y += halfHeight;
  3535. textAlign = 'left';
  3536. break;
  3537. case 'insideRight':
  3538. x += width - distance;
  3539. y += halfHeight;
  3540. textAlign = 'right';
  3541. break;
  3542. case 'insideTop':
  3543. x += width / 2;
  3544. y += distance;
  3545. textAlign = 'center';
  3546. break;
  3547. case 'insideBottom':
  3548. x += width / 2;
  3549. y += height - textHeight - distance;
  3550. textAlign = 'center';
  3551. break;
  3552. case 'insideTopLeft':
  3553. x += distance;
  3554. y += distance;
  3555. textAlign = 'left';
  3556. break;
  3557. case 'insideTopRight':
  3558. x += width - distance;
  3559. y += distance;
  3560. textAlign = 'right';
  3561. break;
  3562. case 'insideBottomLeft':
  3563. x += distance;
  3564. y += height - textHeight - distance;
  3565. break;
  3566. case 'insideBottomRight':
  3567. x += width - distance;
  3568. y += height - textHeight - distance;
  3569. textAlign = 'right';
  3570. break;
  3571. }
  3572. return {
  3573. x: x,
  3574. y: y,
  3575. textAlign: textAlign,
  3576. textBaseline: 'top'
  3577. };
  3578. }
  3579. /**
  3580. * Show ellipsis if overflow.
  3581. *
  3582. * @param {string} text
  3583. * @param {string} textFont
  3584. * @param {string} containerWidth
  3585. * @param {Object} [options]
  3586. * @param {number} [options.ellipsis='...']
  3587. * @param {number} [options.maxIterations=3]
  3588. * @param {number} [options.minCharacters=3]
  3589. * @return {string}
  3590. */
  3591. function textEllipsis(text, textFont, containerWidth, options) {
  3592. if (!containerWidth) {
  3593. return '';
  3594. }
  3595. options = util.defaults({
  3596. ellipsis: '...',
  3597. minCharacters: 3,
  3598. maxIterations: 3,
  3599. cnCharWidth: getTextWidth('国', textFont),
  3600. // FIXME
  3601. // 未考虑非等宽字体
  3602. ascCharWidth: getTextWidth('a', textFont)
  3603. }, options, true);
  3604. containerWidth -= getTextWidth(options.ellipsis);
  3605. var textLines = (text + '').split('\n');
  3606. for (var i = 0, len = textLines.length; i < len; i++) {
  3607. textLines[i] = textLineTruncate(
  3608. textLines[i], textFont, containerWidth, options
  3609. );
  3610. }
  3611. return textLines.join('\n');
  3612. }
  3613. function textLineTruncate(text, textFont, containerWidth, options) {
  3614. // FIXME
  3615. // 粗糙得写的,尚未考虑性能和各种语言、字体的效果。
  3616. for (var i = 0;; i++) {
  3617. var lineWidth = getTextWidth(text, textFont);
  3618. if (lineWidth < containerWidth || i >= options.maxIterations) {
  3619. text += options.ellipsis;
  3620. break;
  3621. }
  3622. var subLength = i === 0
  3623. ? estimateLength(text, containerWidth, options)
  3624. : Math.floor(text.length * containerWidth / lineWidth);
  3625. if (subLength < options.minCharacters) {
  3626. text = '';
  3627. break;
  3628. }
  3629. text = text.substr(0, subLength);
  3630. }
  3631. return text;
  3632. }
  3633. function estimateLength(text, containerWidth, options) {
  3634. var width = 0;
  3635. var i = 0;
  3636. for (var len = text.length; i < len && width < containerWidth; i++) {
  3637. var charCode = text.charCodeAt(i);
  3638. width += (0 <= charCode && charCode <= 127)
  3639. ? options.ascCharWidth : options.cnCharWidth;
  3640. }
  3641. return i;
  3642. }
  3643. var textContain = {
  3644. getWidth: getTextWidth,
  3645. getBoundingRect: getTextRect,
  3646. adjustTextPositionOnRect: adjustTextPositionOnRect,
  3647. ellipsis: textEllipsis,
  3648. measureText: function (text, textFont) {
  3649. var ctx = util.getContext();
  3650. ctx.font = textFont;
  3651. return ctx.measureText(text);
  3652. }
  3653. };
  3654. module.exports = textContain;
  3655. /***/ },
  3656. /* 15 */
  3657. /***/ function(module, exports, __webpack_require__) {
  3658. 'use strict';
  3659. /**
  3660. * @module echarts/core/BoundingRect
  3661. */
  3662. var vec2 = __webpack_require__(16);
  3663. var matrix = __webpack_require__(17);
  3664. var v2ApplyTransform = vec2.applyTransform;
  3665. var mathMin = Math.min;
  3666. var mathAbs = Math.abs;
  3667. var mathMax = Math.max;
  3668. /**
  3669. * @alias module:echarts/core/BoundingRect
  3670. */
  3671. function BoundingRect(x, y, width, height) {
  3672. /**
  3673. * @type {number}
  3674. */
  3675. this.x = x;
  3676. /**
  3677. * @type {number}
  3678. */
  3679. this.y = y;
  3680. /**
  3681. * @type {number}
  3682. */
  3683. this.width = width;
  3684. /**
  3685. * @type {number}
  3686. */
  3687. this.height = height;
  3688. }
  3689. BoundingRect.prototype = {
  3690. constructor: BoundingRect,
  3691. /**
  3692. * @param {module:echarts/core/BoundingRect} other
  3693. */
  3694. union: function (other) {
  3695. var x = mathMin(other.x, this.x);
  3696. var y = mathMin(other.y, this.y);
  3697. this.width = mathMax(
  3698. other.x + other.width,
  3699. this.x + this.width
  3700. ) - x;
  3701. this.height = mathMax(
  3702. other.y + other.height,
  3703. this.y + this.height
  3704. ) - y;
  3705. this.x = x;
  3706. this.y = y;
  3707. },
  3708. /**
  3709. * @param {Array.<number>} m
  3710. * @methods
  3711. */
  3712. applyTransform: (function () {
  3713. var min = [];
  3714. var max = [];
  3715. return function (m) {
  3716. // In case usage like this
  3717. // el.getBoundingRect().applyTransform(el.transform)
  3718. // And element has no transform
  3719. if (!m) {
  3720. return;
  3721. }
  3722. min[0] = this.x;
  3723. min[1] = this.y;
  3724. max[0] = this.x + this.width;
  3725. max[1] = this.y + this.height;
  3726. v2ApplyTransform(min, min, m);
  3727. v2ApplyTransform(max, max, m);
  3728. this.x = mathMin(min[0], max[0]);
  3729. this.y = mathMin(min[1], max[1]);
  3730. this.width = mathAbs(max[0] - min[0]);
  3731. this.height = mathAbs(max[1] - min[1]);
  3732. };
  3733. })(),
  3734. /**
  3735. * Calculate matrix of transforming from self to target rect
  3736. * @param {module:zrender/core/BoundingRect} b
  3737. * @return {Array.<number>}
  3738. */
  3739. calculateTransform: function (b) {
  3740. var a = this;
  3741. var sx = b.width / a.width;
  3742. var sy = b.height / a.height;
  3743. var m = matrix.create();
  3744. // 矩阵右乘
  3745. matrix.translate(m, m, [-a.x, -a.y]);
  3746. matrix.scale(m, m, [sx, sy]);
  3747. matrix.translate(m, m, [b.x, b.y]);
  3748. return m;
  3749. },
  3750. /**
  3751. * @param {(module:echarts/core/BoundingRect|Object)} b
  3752. * @return {boolean}
  3753. */
  3754. intersect: function (b) {
  3755. var a = this;
  3756. var ax0 = a.x;
  3757. var ax1 = a.x + a.width;
  3758. var ay0 = a.y;
  3759. var ay1 = a.y + a.height;
  3760. var bx0 = b.x;
  3761. var bx1 = b.x + b.width;
  3762. var by0 = b.y;
  3763. var by1 = b.y + b.height;
  3764. return ! (ax1 < bx0 || bx1 < ax0 || ay1 < by0 || by1 < ay0);
  3765. },
  3766. contain: function (x, y) {
  3767. var rect = this;
  3768. return x >= rect.x
  3769. && x <= (rect.x + rect.width)
  3770. && y >= rect.y
  3771. && y <= (rect.y + rect.height);
  3772. },
  3773. /**
  3774. * @return {module:echarts/core/BoundingRect}
  3775. */
  3776. clone: function () {
  3777. return new BoundingRect(this.x, this.y, this.width, this.height);
  3778. },
  3779. /**
  3780. * Copy from another rect
  3781. */
  3782. copy: function (other) {
  3783. this.x = other.x;
  3784. this.y = other.y;
  3785. this.width = other.width;
  3786. this.height = other.height;
  3787. }
  3788. };
  3789. module.exports = BoundingRect;
  3790. /***/ },
  3791. /* 16 */
  3792. /***/ function(module, exports) {
  3793. var ArrayCtor = typeof Float32Array === 'undefined'
  3794. ? Array
  3795. : Float32Array;
  3796. /**
  3797. * @typedef {Float32Array|Array.<number>} Vector2
  3798. */
  3799. /**
  3800. * 二维向量类
  3801. * @exports zrender/tool/vector
  3802. */
  3803. var vector = {
  3804. /**
  3805. * 创建一个向量
  3806. * @param {number} [x=0]
  3807. * @param {number} [y=0]
  3808. * @return {Vector2}
  3809. */
  3810. create: function (x, y) {
  3811. var out = new ArrayCtor(2);
  3812. out[0] = x || 0;
  3813. out[1] = y || 0;
  3814. return out;
  3815. },
  3816. /**
  3817. * 复制向量数据
  3818. * @param {Vector2} out
  3819. * @param {Vector2} v
  3820. * @return {Vector2}
  3821. */
  3822. copy: function (out, v) {
  3823. out[0] = v[0];
  3824. out[1] = v[1];
  3825. return out;
  3826. },
  3827. /**
  3828. * 克隆一个向量
  3829. * @param {Vector2} v
  3830. * @return {Vector2}
  3831. */
  3832. clone: function (v) {
  3833. var out = new ArrayCtor(2);
  3834. out[0] = v[0];
  3835. out[1] = v[1];
  3836. return out;
  3837. },
  3838. /**
  3839. * 设置向量的两个项
  3840. * @param {Vector2} out
  3841. * @param {number} a
  3842. * @param {number} b
  3843. * @return {Vector2} 结果
  3844. */
  3845. set: function (out, a, b) {
  3846. out[0] = a;
  3847. out[1] = b;
  3848. return out;
  3849. },
  3850. /**
  3851. * 向量相加
  3852. * @param {Vector2} out
  3853. * @param {Vector2} v1
  3854. * @param {Vector2} v2
  3855. */
  3856. add: function (out, v1, v2) {
  3857. out[0] = v1[0] + v2[0];
  3858. out[1] = v1[1] + v2[1];
  3859. return out;
  3860. },
  3861. /**
  3862. * 向量缩放后相加
  3863. * @param {Vector2} out
  3864. * @param {Vector2} v1
  3865. * @param {Vector2} v2
  3866. * @param {number} a
  3867. */
  3868. scaleAndAdd: function (out, v1, v2, a) {
  3869. out[0] = v1[0] + v2[0] * a;
  3870. out[1] = v1[1] + v2[1] * a;
  3871. return out;
  3872. },
  3873. /**
  3874. * 向量相减
  3875. * @param {Vector2} out
  3876. * @param {Vector2} v1
  3877. * @param {Vector2} v2
  3878. */
  3879. sub: function (out, v1, v2) {
  3880. out[0] = v1[0] - v2[0];
  3881. out[1] = v1[1] - v2[1];
  3882. return out;
  3883. },
  3884. /**
  3885. * 向量长度
  3886. * @param {Vector2} v
  3887. * @return {number}
  3888. */
  3889. len: function (v) {
  3890. return Math.sqrt(this.lenSquare(v));
  3891. },
  3892. /**
  3893. * 向量长度平方
  3894. * @param {Vector2} v
  3895. * @return {number}
  3896. */
  3897. lenSquare: function (v) {
  3898. return v[0] * v[0] + v[1] * v[1];
  3899. },
  3900. /**
  3901. * 向量乘法
  3902. * @param {Vector2} out
  3903. * @param {Vector2} v1
  3904. * @param {Vector2} v2
  3905. */
  3906. mul: function (out, v1, v2) {
  3907. out[0] = v1[0] * v2[0];
  3908. out[1] = v1[1] * v2[1];
  3909. return out;
  3910. },
  3911. /**
  3912. * 向量除法
  3913. * @param {Vector2} out
  3914. * @param {Vector2} v1
  3915. * @param {Vector2} v2
  3916. */
  3917. div: function (out, v1, v2) {
  3918. out[0] = v1[0] / v2[0];
  3919. out[1] = v1[1] / v2[1];
  3920. return out;
  3921. },
  3922. /**
  3923. * 向量点乘
  3924. * @param {Vector2} v1
  3925. * @param {Vector2} v2
  3926. * @return {number}
  3927. */
  3928. dot: function (v1, v2) {
  3929. return v1[0] * v2[0] + v1[1] * v2[1];
  3930. },
  3931. /**
  3932. * 向量缩放
  3933. * @param {Vector2} out
  3934. * @param {Vector2} v
  3935. * @param {number} s
  3936. */
  3937. scale: function (out, v, s) {
  3938. out[0] = v[0] * s;
  3939. out[1] = v[1] * s;
  3940. return out;
  3941. },
  3942. /**
  3943. * 向量归一化
  3944. * @param {Vector2} out
  3945. * @param {Vector2} v
  3946. */
  3947. normalize: function (out, v) {
  3948. var d = vector.len(v);
  3949. if (d === 0) {
  3950. out[0] = 0;
  3951. out[1] = 0;
  3952. }
  3953. else {
  3954. out[0] = v[0] / d;
  3955. out[1] = v[1] / d;
  3956. }
  3957. return out;
  3958. },
  3959. /**
  3960. * 计算向量间距离
  3961. * @param {Vector2} v1
  3962. * @param {Vector2} v2
  3963. * @return {number}
  3964. */
  3965. distance: function (v1, v2) {
  3966. return Math.sqrt(
  3967. (v1[0] - v2[0]) * (v1[0] - v2[0])
  3968. + (v1[1] - v2[1]) * (v1[1] - v2[1])
  3969. );
  3970. },
  3971. /**
  3972. * 向量距离平方
  3973. * @param {Vector2} v1
  3974. * @param {Vector2} v2
  3975. * @return {number}
  3976. */
  3977. distanceSquare: function (v1, v2) {
  3978. return (v1[0] - v2[0]) * (v1[0] - v2[0])
  3979. + (v1[1] - v2[1]) * (v1[1] - v2[1]);
  3980. },
  3981. /**
  3982. * 求负向量
  3983. * @param {Vector2} out
  3984. * @param {Vector2} v
  3985. */
  3986. negate: function (out, v) {
  3987. out[0] = -v[0];
  3988. out[1] = -v[1];
  3989. return out;
  3990. },
  3991. /**
  3992. * 插值两个点
  3993. * @param {Vector2} out
  3994. * @param {Vector2} v1
  3995. * @param {Vector2} v2
  3996. * @param {number} t
  3997. */
  3998. lerp: function (out, v1, v2, t) {
  3999. out[0] = v1[0] + t * (v2[0] - v1[0]);
  4000. out[1] = v1[1] + t * (v2[1] - v1[1]);
  4001. return out;
  4002. },
  4003. /**
  4004. * 矩阵左乘向量
  4005. * @param {Vector2} out
  4006. * @param {Vector2} v
  4007. * @param {Vector2} m
  4008. */
  4009. applyTransform: function (out, v, m) {
  4010. var x = v[0];
  4011. var y = v[1];
  4012. out[0] = m[0] * x + m[2] * y + m[4];
  4013. out[1] = m[1] * x + m[3] * y + m[5];
  4014. return out;
  4015. },
  4016. /**
  4017. * 求两个向量最小值
  4018. * @param {Vector2} out
  4019. * @param {Vector2} v1
  4020. * @param {Vector2} v2
  4021. */
  4022. min: function (out, v1, v2) {
  4023. out[0] = Math.min(v1[0], v2[0]);
  4024. out[1] = Math.min(v1[1], v2[1]);
  4025. return out;
  4026. },
  4027. /**
  4028. * 求两个向量最大值
  4029. * @param {Vector2} out
  4030. * @param {Vector2} v1
  4031. * @param {Vector2} v2
  4032. */
  4033. max: function (out, v1, v2) {
  4034. out[0] = Math.max(v1[0], v2[0]);
  4035. out[1] = Math.max(v1[1], v2[1]);
  4036. return out;
  4037. }
  4038. };
  4039. vector.length = vector.len;
  4040. vector.lengthSquare = vector.lenSquare;
  4041. vector.dist = vector.distance;
  4042. vector.distSquare = vector.distanceSquare;
  4043. module.exports = vector;
  4044. /***/ },
  4045. /* 17 */
  4046. /***/ function(module, exports) {
  4047. var ArrayCtor = typeof Float32Array === 'undefined'
  4048. ? Array
  4049. : Float32Array;
  4050. /**
  4051. * 3x2矩阵操作类
  4052. * @exports zrender/tool/matrix
  4053. */
  4054. var matrix = {
  4055. /**
  4056. * 创建一个单位矩阵
  4057. * @return {Float32Array|Array.<number>}
  4058. */
  4059. create : function() {
  4060. var out = new ArrayCtor(6);
  4061. matrix.identity(out);
  4062. return out;
  4063. },
  4064. /**
  4065. * 设置矩阵为单位矩阵
  4066. * @param {Float32Array|Array.<number>} out
  4067. */
  4068. identity : function(out) {
  4069. out[0] = 1;
  4070. out[1] = 0;
  4071. out[2] = 0;
  4072. out[3] = 1;
  4073. out[4] = 0;
  4074. out[5] = 0;
  4075. return out;
  4076. },
  4077. /**
  4078. * 复制矩阵
  4079. * @param {Float32Array|Array.<number>} out
  4080. * @param {Float32Array|Array.<number>} m
  4081. */
  4082. copy: function(out, m) {
  4083. out[0] = m[0];
  4084. out[1] = m[1];
  4085. out[2] = m[2];
  4086. out[3] = m[3];
  4087. out[4] = m[4];
  4088. out[5] = m[5];
  4089. return out;
  4090. },
  4091. /**
  4092. * 矩阵相乘
  4093. * @param {Float32Array|Array.<number>} out
  4094. * @param {Float32Array|Array.<number>} m1
  4095. * @param {Float32Array|Array.<number>} m2
  4096. */
  4097. mul : function (out, m1, m2) {
  4098. // Consider matrix.mul(m, m2, m);
  4099. // where out is the same as m2.
  4100. // So use temp variable to escape error.
  4101. var out0 = m1[0] * m2[0] + m1[2] * m2[1];
  4102. var out1 = m1[1] * m2[0] + m1[3] * m2[1];
  4103. var out2 = m1[0] * m2[2] + m1[2] * m2[3];
  4104. var out3 = m1[1] * m2[2] + m1[3] * m2[3];
  4105. var out4 = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  4106. var out5 = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  4107. out[0] = out0;
  4108. out[1] = out1;
  4109. out[2] = out2;
  4110. out[3] = out3;
  4111. out[4] = out4;
  4112. out[5] = out5;
  4113. return out;
  4114. },
  4115. /**
  4116. * 平移变换
  4117. * @param {Float32Array|Array.<number>} out
  4118. * @param {Float32Array|Array.<number>} a
  4119. * @param {Float32Array|Array.<number>} v
  4120. */
  4121. translate : function(out, a, v) {
  4122. out[0] = a[0];
  4123. out[1] = a[1];
  4124. out[2] = a[2];
  4125. out[3] = a[3];
  4126. out[4] = a[4] + v[0];
  4127. out[5] = a[5] + v[1];
  4128. return out;
  4129. },
  4130. /**
  4131. * 旋转变换
  4132. * @param {Float32Array|Array.<number>} out
  4133. * @param {Float32Array|Array.<number>} a
  4134. * @param {number} rad
  4135. */
  4136. rotate : function(out, a, rad) {
  4137. var aa = a[0];
  4138. var ac = a[2];
  4139. var atx = a[4];
  4140. var ab = a[1];
  4141. var ad = a[3];
  4142. var aty = a[5];
  4143. var st = Math.sin(rad);
  4144. var ct = Math.cos(rad);
  4145. out[0] = aa * ct + ab * st;
  4146. out[1] = -aa * st + ab * ct;
  4147. out[2] = ac * ct + ad * st;
  4148. out[3] = -ac * st + ct * ad;
  4149. out[4] = ct * atx + st * aty;
  4150. out[5] = ct * aty - st * atx;
  4151. return out;
  4152. },
  4153. /**
  4154. * 缩放变换
  4155. * @param {Float32Array|Array.<number>} out
  4156. * @param {Float32Array|Array.<number>} a
  4157. * @param {Float32Array|Array.<number>} v
  4158. */
  4159. scale : function(out, a, v) {
  4160. var vx = v[0];
  4161. var vy = v[1];
  4162. out[0] = a[0] * vx;
  4163. out[1] = a[1] * vy;
  4164. out[2] = a[2] * vx;
  4165. out[3] = a[3] * vy;
  4166. out[4] = a[4] * vx;
  4167. out[5] = a[5] * vy;
  4168. return out;
  4169. },
  4170. /**
  4171. * 求逆矩阵
  4172. * @param {Float32Array|Array.<number>} out
  4173. * @param {Float32Array|Array.<number>} a
  4174. */
  4175. invert : function(out, a) {
  4176. var aa = a[0];
  4177. var ac = a[2];
  4178. var atx = a[4];
  4179. var ab = a[1];
  4180. var ad = a[3];
  4181. var aty = a[5];
  4182. var det = aa * ad - ab * ac;
  4183. if (!det) {
  4184. return null;
  4185. }
  4186. det = 1.0 / det;
  4187. out[0] = ad * det;
  4188. out[1] = -ab * det;
  4189. out[2] = -ac * det;
  4190. out[3] = aa * det;
  4191. out[4] = (ac * aty - ad * atx) * det;
  4192. out[5] = (ab * atx - aa * aty) * det;
  4193. return out;
  4194. }
  4195. };
  4196. module.exports = matrix;
  4197. /***/ },
  4198. /* 18 */
  4199. /***/ function(module, exports, __webpack_require__) {
  4200. module.exports = {
  4201. getItemStyle: __webpack_require__(11)(
  4202. [
  4203. ['fill', 'color'],
  4204. ['stroke', 'borderColor'],
  4205. ['lineWidth', 'borderWidth'],
  4206. ['opacity'],
  4207. ['shadowBlur'],
  4208. ['shadowOffsetX'],
  4209. ['shadowOffsetY'],
  4210. ['shadowColor']
  4211. ]
  4212. )
  4213. };
  4214. /***/ },
  4215. /* 19 */
  4216. /***/ function(module, exports, __webpack_require__) {
  4217. /**
  4218. * Component model
  4219. *
  4220. * @module echarts/model/Component
  4221. */
  4222. var Model = __webpack_require__(8);
  4223. var zrUtil = __webpack_require__(3);
  4224. var arrayPush = Array.prototype.push;
  4225. var componentUtil = __webpack_require__(20);
  4226. var clazzUtil = __webpack_require__(9);
  4227. var layout = __webpack_require__(21);
  4228. /**
  4229. * @alias module:echarts/model/Component
  4230. * @constructor
  4231. * @param {Object} option
  4232. * @param {module:echarts/model/Model} parentModel
  4233. * @param {module:echarts/model/Model} ecModel
  4234. */
  4235. var ComponentModel = Model.extend({
  4236. type: 'component',
  4237. /**
  4238. * @readOnly
  4239. * @type {string}
  4240. */
  4241. id: '',
  4242. /**
  4243. * @readOnly
  4244. */
  4245. name: '',
  4246. /**
  4247. * @readOnly
  4248. * @type {string}
  4249. */
  4250. mainType: '',
  4251. /**
  4252. * @readOnly
  4253. * @type {string}
  4254. */
  4255. subType: '',
  4256. /**
  4257. * @readOnly
  4258. * @type {number}
  4259. */
  4260. componentIndex: 0,
  4261. /**
  4262. * @type {Object}
  4263. * @protected
  4264. */
  4265. defaultOption: null,
  4266. /**
  4267. * @type {module:echarts/model/Global}
  4268. * @readOnly
  4269. */
  4270. ecModel: null,
  4271. /**
  4272. * key: componentType
  4273. * value: Component model list, can not be null.
  4274. * @type {Object.<string, Array.<module:echarts/model/Model>>}
  4275. * @readOnly
  4276. */
  4277. dependentModels: [],
  4278. /**
  4279. * @type {string}
  4280. * @readOnly
  4281. */
  4282. uid: null,
  4283. /**
  4284. * Support merge layout params.
  4285. * Only support 'box' now (left/right/top/bottom/width/height).
  4286. * @type {string|Object} Object can be {ignoreSize: true}
  4287. * @readOnly
  4288. */
  4289. layoutMode: null,
  4290. init: function (option, parentModel, ecModel, extraOpt) {
  4291. this.mergeDefaultAndTheme(this.option, this.ecModel);
  4292. },
  4293. mergeDefaultAndTheme: function (option, ecModel) {
  4294. var layoutMode = this.layoutMode;
  4295. var inputPositionParams = layoutMode
  4296. ? layout.getLayoutParams(option) : {};
  4297. var themeModel = ecModel.getTheme();
  4298. zrUtil.merge(option, themeModel.get(this.mainType));
  4299. zrUtil.merge(option, this.getDefaultOption());
  4300. if (layoutMode) {
  4301. layout.mergeLayoutParam(option, inputPositionParams, layoutMode);
  4302. }
  4303. },
  4304. mergeOption: function (option) {
  4305. zrUtil.merge(this.option, option, true);
  4306. var layoutMode = this.layoutMode;
  4307. if (layoutMode) {
  4308. layout.mergeLayoutParam(this.option, option, layoutMode);
  4309. }
  4310. },
  4311. // Hooker after init or mergeOption
  4312. optionUpdated: function (ecModel) {},
  4313. getDefaultOption: function () {
  4314. if (!this.hasOwnProperty('__defaultOption')) {
  4315. var optList = [];
  4316. var Class = this.constructor;
  4317. while (Class) {
  4318. var opt = Class.prototype.defaultOption;
  4319. opt && optList.push(opt);
  4320. Class = Class.superClass;
  4321. }
  4322. var defaultOption = {};
  4323. for (var i = optList.length - 1; i >= 0; i--) {
  4324. defaultOption = zrUtil.merge(defaultOption, optList[i], true);
  4325. }
  4326. this.__defaultOption = defaultOption;
  4327. }
  4328. return this.__defaultOption;
  4329. }
  4330. });
  4331. // Reset ComponentModel.extend, add preConstruct.
  4332. clazzUtil.enableClassExtend(
  4333. ComponentModel,
  4334. function (option, parentModel, ecModel, extraOpt) {
  4335. // Set dependentModels, componentIndex, name, id, mainType, subType.
  4336. zrUtil.extend(this, extraOpt);
  4337. this.uid = componentUtil.getUID('componentModel');
  4338. // this.setReadOnly([
  4339. // 'type', 'id', 'uid', 'name', 'mainType', 'subType',
  4340. // 'dependentModels', 'componentIndex'
  4341. // ]);
  4342. }
  4343. );
  4344. // Add capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  4345. clazzUtil.enableClassManagement(
  4346. ComponentModel, {registerWhenExtend: true}
  4347. );
  4348. componentUtil.enableSubTypeDefaulter(ComponentModel);
  4349. // Add capability of ComponentModel.topologicalTravel.
  4350. componentUtil.enableTopologicalTravel(ComponentModel, getDependencies);
  4351. function getDependencies(componentType) {
  4352. var deps = [];
  4353. zrUtil.each(ComponentModel.getClassesByMainType(componentType), function (Clazz) {
  4354. arrayPush.apply(deps, Clazz.prototype.dependencies || []);
  4355. });
  4356. // Ensure main type
  4357. return zrUtil.map(deps, function (type) {
  4358. return clazzUtil.parseClassType(type).main;
  4359. });
  4360. }
  4361. zrUtil.mixin(ComponentModel, __webpack_require__(22));
  4362. module.exports = ComponentModel;
  4363. /***/ },
  4364. /* 20 */
  4365. /***/ function(module, exports, __webpack_require__) {
  4366. var zrUtil = __webpack_require__(3);
  4367. var clazz = __webpack_require__(9);
  4368. var parseClassType = clazz.parseClassType;
  4369. var base = 0;
  4370. var componentUtil = {};
  4371. var DELIMITER = '_';
  4372. /**
  4373. * @public
  4374. * @param {string} type
  4375. * @return {string}
  4376. */
  4377. componentUtil.getUID = function (type) {
  4378. // Considering the case of crossing js context,
  4379. // use Math.random to make id as unique as possible.
  4380. return [(type || ''), base++, Math.random()].join(DELIMITER);
  4381. };
  4382. /**
  4383. * @inner
  4384. */
  4385. componentUtil.enableSubTypeDefaulter = function (entity) {
  4386. var subTypeDefaulters = {};
  4387. entity.registerSubTypeDefaulter = function (componentType, defaulter) {
  4388. componentType = parseClassType(componentType);
  4389. subTypeDefaulters[componentType.main] = defaulter;
  4390. };
  4391. entity.determineSubType = function (componentType, option) {
  4392. var type = option.type;
  4393. if (!type) {
  4394. var componentTypeMain = parseClassType(componentType).main;
  4395. if (entity.hasSubTypes(componentType) && subTypeDefaulters[componentTypeMain]) {
  4396. type = subTypeDefaulters[componentTypeMain](option);
  4397. }
  4398. }
  4399. return type;
  4400. };
  4401. return entity;
  4402. };
  4403. /**
  4404. * Topological travel on Activity Network (Activity On Vertices).
  4405. * Dependencies is defined in Model.prototype.dependencies, like ['xAxis', 'yAxis'].
  4406. *
  4407. * If 'xAxis' or 'yAxis' is absent in componentTypeList, just ignore it in topology.
  4408. *
  4409. * If there is circle dependencey, Error will be thrown.
  4410. *
  4411. */
  4412. componentUtil.enableTopologicalTravel = function (entity, dependencyGetter) {
  4413. /**
  4414. * @public
  4415. * @param {Array.<string>} targetNameList Target Component type list.
  4416. * Can be ['aa', 'bb', 'aa.xx']
  4417. * @param {Array.<string>} fullNameList By which we can build dependency graph.
  4418. * @param {Function} callback Params: componentType, dependencies.
  4419. * @param {Object} context Scope of callback.
  4420. */
  4421. entity.topologicalTravel = function (targetNameList, fullNameList, callback, context) {
  4422. if (!targetNameList.length) {
  4423. return;
  4424. }
  4425. var result = makeDepndencyGraph(fullNameList);
  4426. var graph = result.graph;
  4427. var stack = result.noEntryList;
  4428. var targetNameSet = {};
  4429. zrUtil.each(targetNameList, function (name) {
  4430. targetNameSet[name] = true;
  4431. });
  4432. while (stack.length) {
  4433. var currComponentType = stack.pop();
  4434. var currVertex = graph[currComponentType];
  4435. var isInTargetNameSet = !!targetNameSet[currComponentType];
  4436. if (isInTargetNameSet) {
  4437. callback.call(context, currComponentType, currVertex.originalDeps.slice());
  4438. delete targetNameSet[currComponentType];
  4439. }
  4440. zrUtil.each(
  4441. currVertex.successor,
  4442. isInTargetNameSet ? removeEdgeAndAdd : removeEdge
  4443. );
  4444. }
  4445. zrUtil.each(targetNameSet, function () {
  4446. throw new Error('Circle dependency may exists');
  4447. });
  4448. function removeEdge(succComponentType) {
  4449. graph[succComponentType].entryCount--;
  4450. if (graph[succComponentType].entryCount === 0) {
  4451. stack.push(succComponentType);
  4452. }
  4453. }
  4454. // Consider this case: legend depends on series, and we call
  4455. // chart.setOption({series: [...]}), where only series is in option.
  4456. // If we do not have 'removeEdgeAndAdd', legendModel.mergeOption will
  4457. // not be called, but only sereis.mergeOption is called. Thus legend
  4458. // have no chance to update its local record about series (like which
  4459. // name of series is available in legend).
  4460. function removeEdgeAndAdd(succComponentType) {
  4461. targetNameSet[succComponentType] = true;
  4462. removeEdge(succComponentType);
  4463. }
  4464. };
  4465. /**
  4466. * DepndencyGraph: {Object}
  4467. * key: conponentType,
  4468. * value: {
  4469. * successor: [conponentTypes...],
  4470. * originalDeps: [conponentTypes...],
  4471. * entryCount: {number}
  4472. * }
  4473. */
  4474. function makeDepndencyGraph(fullNameList) {
  4475. var graph = {};
  4476. var noEntryList = [];
  4477. zrUtil.each(fullNameList, function (name) {
  4478. var thisItem = createDependencyGraphItem(graph, name);
  4479. var originalDeps = thisItem.originalDeps = dependencyGetter(name);
  4480. var availableDeps = getAvailableDependencies(originalDeps, fullNameList);
  4481. thisItem.entryCount = availableDeps.length;
  4482. if (thisItem.entryCount === 0) {
  4483. noEntryList.push(name);
  4484. }
  4485. zrUtil.each(availableDeps, function (dependentName) {
  4486. if (zrUtil.indexOf(thisItem.predecessor, dependentName) < 0) {
  4487. thisItem.predecessor.push(dependentName);
  4488. }
  4489. var thatItem = createDependencyGraphItem(graph, dependentName);
  4490. if (zrUtil.indexOf(thatItem.successor, dependentName) < 0) {
  4491. thatItem.successor.push(name);
  4492. }
  4493. });
  4494. });
  4495. return {graph: graph, noEntryList: noEntryList};
  4496. }
  4497. function createDependencyGraphItem(graph, name) {
  4498. if (!graph[name]) {
  4499. graph[name] = {predecessor: [], successor: []};
  4500. }
  4501. return graph[name];
  4502. }
  4503. function getAvailableDependencies(originalDeps, fullNameList) {
  4504. var availableDeps = [];
  4505. zrUtil.each(originalDeps, function (dep) {
  4506. zrUtil.indexOf(fullNameList, dep) >= 0 && availableDeps.push(dep);
  4507. });
  4508. return availableDeps;
  4509. }
  4510. };
  4511. module.exports = componentUtil;
  4512. /***/ },
  4513. /* 21 */
  4514. /***/ function(module, exports, __webpack_require__) {
  4515. 'use strict';
  4516. // Layout helpers for each component positioning
  4517. var zrUtil = __webpack_require__(3);
  4518. var BoundingRect = __webpack_require__(15);
  4519. var numberUtil = __webpack_require__(7);
  4520. var formatUtil = __webpack_require__(6);
  4521. var parsePercent = numberUtil.parsePercent;
  4522. var each = zrUtil.each;
  4523. var layout = {};
  4524. var LOCATION_PARAMS = ['left', 'right', 'top', 'bottom', 'width', 'height'];
  4525. function boxLayout(orient, group, gap, maxWidth, maxHeight) {
  4526. var x = 0;
  4527. var y = 0;
  4528. if (maxWidth == null) {
  4529. maxWidth = Infinity;
  4530. }
  4531. if (maxHeight == null) {
  4532. maxHeight = Infinity;
  4533. }
  4534. var currentLineMaxSize = 0;
  4535. group.eachChild(function (child, idx) {
  4536. var position = child.position;
  4537. var rect = child.getBoundingRect();
  4538. var nextChild = group.childAt(idx + 1);
  4539. var nextChildRect = nextChild && nextChild.getBoundingRect();
  4540. var nextX;
  4541. var nextY;
  4542. if (orient === 'horizontal') {
  4543. var moveX = rect.width + (nextChildRect ? (-nextChildRect.x + rect.x) : 0);
  4544. nextX = x + moveX;
  4545. // Wrap when width exceeds maxWidth or meet a `newline` group
  4546. if (nextX > maxWidth || child.newline) {
  4547. x = 0;
  4548. nextX = moveX;
  4549. y += currentLineMaxSize + gap;
  4550. currentLineMaxSize = rect.height;
  4551. }
  4552. else {
  4553. currentLineMaxSize = Math.max(currentLineMaxSize, rect.height);
  4554. }
  4555. }
  4556. else {
  4557. var moveY = rect.height + (nextChildRect ? (-nextChildRect.y + rect.y) : 0);
  4558. nextY = y + moveY;
  4559. // Wrap when width exceeds maxHeight or meet a `newline` group
  4560. if (nextY > maxHeight || child.newline) {
  4561. x += currentLineMaxSize + gap;
  4562. y = 0;
  4563. nextY = moveY;
  4564. currentLineMaxSize = rect.width;
  4565. }
  4566. else {
  4567. currentLineMaxSize = Math.max(currentLineMaxSize, rect.width);
  4568. }
  4569. }
  4570. if (child.newline) {
  4571. return;
  4572. }
  4573. position[0] = x;
  4574. position[1] = y;
  4575. orient === 'horizontal'
  4576. ? (x = nextX + gap)
  4577. : (y = nextY + gap);
  4578. });
  4579. }
  4580. /**
  4581. * VBox or HBox layouting
  4582. * @param {string} orient
  4583. * @param {module:zrender/container/Group} group
  4584. * @param {number} gap
  4585. * @param {number} [width=Infinity]
  4586. * @param {number} [height=Infinity]
  4587. */
  4588. layout.box = boxLayout;
  4589. /**
  4590. * VBox layouting
  4591. * @param {module:zrender/container/Group} group
  4592. * @param {number} gap
  4593. * @param {number} [width=Infinity]
  4594. * @param {number} [height=Infinity]
  4595. */
  4596. layout.vbox = zrUtil.curry(boxLayout, 'vertical');
  4597. /**
  4598. * HBox layouting
  4599. * @param {module:zrender/container/Group} group
  4600. * @param {number} gap
  4601. * @param {number} [width=Infinity]
  4602. * @param {number} [height=Infinity]
  4603. */
  4604. layout.hbox = zrUtil.curry(boxLayout, 'horizontal');
  4605. /**
  4606. * If x or x2 is not specified or 'center' 'left' 'right',
  4607. * the width would be as long as possible.
  4608. * If y or y2 is not specified or 'middle' 'top' 'bottom',
  4609. * the height would be as long as possible.
  4610. *
  4611. * @param {Object} positionInfo
  4612. * @param {number|string} [positionInfo.x]
  4613. * @param {number|string} [positionInfo.y]
  4614. * @param {number|string} [positionInfo.x2]
  4615. * @param {number|string} [positionInfo.y2]
  4616. * @param {Object} containerRect
  4617. * @param {string|number} margin
  4618. * @return {Object} {width, height}
  4619. */
  4620. layout.getAvailableSize = function (positionInfo, containerRect, margin) {
  4621. var containerWidth = containerRect.width;
  4622. var containerHeight = containerRect.height;
  4623. var x = parsePercent(positionInfo.x, containerWidth);
  4624. var y = parsePercent(positionInfo.y, containerHeight);
  4625. var x2 = parsePercent(positionInfo.x2, containerWidth);
  4626. var y2 = parsePercent(positionInfo.y2, containerHeight);
  4627. (isNaN(x) || isNaN(parseFloat(positionInfo.x))) && (x = 0);
  4628. (isNaN(x2) || isNaN(parseFloat(positionInfo.x2))) && (x2 = containerWidth);
  4629. (isNaN(y) || isNaN(parseFloat(positionInfo.y))) && (y = 0);
  4630. (isNaN(y2) || isNaN(parseFloat(positionInfo.y2))) && (y2 = containerHeight);
  4631. margin = formatUtil.normalizeCssArray(margin || 0);
  4632. return {
  4633. width: Math.max(x2 - x - margin[1] - margin[3], 0),
  4634. height: Math.max(y2 - y - margin[0] - margin[2], 0)
  4635. };
  4636. };
  4637. /**
  4638. * Parse position info.
  4639. *
  4640. * @param {Object} positionInfo
  4641. * @param {number|string} [positionInfo.left]
  4642. * @param {number|string} [positionInfo.top]
  4643. * @param {number|string} [positionInfo.right]
  4644. * @param {number|string} [positionInfo.bottom]
  4645. * @param {number|string} [positionInfo.width]
  4646. * @param {number|string} [positionInfo.height]
  4647. * @param {number|string} [positionInfo.aspect] Aspect is width / height
  4648. * @param {Object} containerRect
  4649. * @param {string|number} [margin]
  4650. *
  4651. * @return {module:zrender/core/BoundingRect}
  4652. */
  4653. layout.getLayoutRect = function (
  4654. positionInfo, containerRect, margin
  4655. ) {
  4656. margin = formatUtil.normalizeCssArray(margin || 0);
  4657. var containerWidth = containerRect.width;
  4658. var containerHeight = containerRect.height;
  4659. var left = parsePercent(positionInfo.left, containerWidth);
  4660. var top = parsePercent(positionInfo.top, containerHeight);
  4661. var right = parsePercent(positionInfo.right, containerWidth);
  4662. var bottom = parsePercent(positionInfo.bottom, containerHeight);
  4663. var width = parsePercent(positionInfo.width, containerWidth);
  4664. var height = parsePercent(positionInfo.height, containerHeight);
  4665. var verticalMargin = margin[2] + margin[0];
  4666. var horizontalMargin = margin[1] + margin[3];
  4667. var aspect = positionInfo.aspect;
  4668. // If width is not specified, calculate width from left and right
  4669. if (isNaN(width)) {
  4670. width = containerWidth - right - horizontalMargin - left;
  4671. }
  4672. if (isNaN(height)) {
  4673. height = containerHeight - bottom - verticalMargin - top;
  4674. }
  4675. // If width and height are not given
  4676. // 1. Graph should not exceeds the container
  4677. // 2. Aspect must be keeped
  4678. // 3. Graph should take the space as more as possible
  4679. if (isNaN(width) && isNaN(height)) {
  4680. if (aspect > containerWidth / containerHeight) {
  4681. width = containerWidth * 0.8;
  4682. }
  4683. else {
  4684. height = containerHeight * 0.8;
  4685. }
  4686. }
  4687. if (aspect != null) {
  4688. // Calculate width or height with given aspect
  4689. if (isNaN(width)) {
  4690. width = aspect * height;
  4691. }
  4692. if (isNaN(height)) {
  4693. height = width / aspect;
  4694. }
  4695. }
  4696. // If left is not specified, calculate left from right and width
  4697. if (isNaN(left)) {
  4698. left = containerWidth - right - width - horizontalMargin;
  4699. }
  4700. if (isNaN(top)) {
  4701. top = containerHeight - bottom - height - verticalMargin;
  4702. }
  4703. // Align left and top
  4704. switch (positionInfo.left || positionInfo.right) {
  4705. case 'center':
  4706. left = containerWidth / 2 - width / 2 - margin[3];
  4707. break;
  4708. case 'right':
  4709. left = containerWidth - width - horizontalMargin;
  4710. break;
  4711. }
  4712. switch (positionInfo.top || positionInfo.bottom) {
  4713. case 'middle':
  4714. case 'center':
  4715. top = containerHeight / 2 - height / 2 - margin[0];
  4716. break;
  4717. case 'bottom':
  4718. top = containerHeight - height - verticalMargin;
  4719. break;
  4720. }
  4721. // If something is wrong and left, top, width, height are calculated as NaN
  4722. left = left || 0;
  4723. top = top || 0;
  4724. if (isNaN(width)) {
  4725. // Width may be NaN if only one value is given except width
  4726. width = containerWidth - left - (right || 0);
  4727. }
  4728. if (isNaN(height)) {
  4729. // Height may be NaN if only one value is given except height
  4730. height = containerHeight - top - (bottom || 0);
  4731. }
  4732. var rect = new BoundingRect(left + margin[3], top + margin[0], width, height);
  4733. rect.margin = margin;
  4734. return rect;
  4735. };
  4736. /**
  4737. * Position group of component in viewport
  4738. * Group position is specified by either
  4739. * {left, top}, {right, bottom}
  4740. * If all properties exists, right and bottom will be igonred.
  4741. *
  4742. * @param {module:zrender/container/Group} group
  4743. * @param {Object} positionInfo
  4744. * @param {number|string} [positionInfo.left]
  4745. * @param {number|string} [positionInfo.top]
  4746. * @param {number|string} [positionInfo.right]
  4747. * @param {number|string} [positionInfo.bottom]
  4748. * @param {Object} containerRect
  4749. * @param {string|number} margin
  4750. */
  4751. layout.positionGroup = function (
  4752. group, positionInfo, containerRect, margin
  4753. ) {
  4754. var groupRect = group.getBoundingRect();
  4755. positionInfo = zrUtil.extend(zrUtil.clone(positionInfo), {
  4756. width: groupRect.width,
  4757. height: groupRect.height
  4758. });
  4759. positionInfo = layout.getLayoutRect(
  4760. positionInfo, containerRect, margin
  4761. );
  4762. group.position = [
  4763. positionInfo.x - groupRect.x,
  4764. positionInfo.y - groupRect.y
  4765. ];
  4766. };
  4767. /**
  4768. * Consider Case:
  4769. * When defulat option has {left: 0, width: 100}, and we set {right: 0}
  4770. * through setOption or media query, using normal zrUtil.merge will cause
  4771. * {right: 0} does not take effect.
  4772. *
  4773. * @example
  4774. * ComponentModel.extend({
  4775. * init: function () {
  4776. * ...
  4777. * var inputPositionParams = layout.getLayoutParams(option);
  4778. * this.mergeOption(inputPositionParams);
  4779. * },
  4780. * mergeOption: function (newOption) {
  4781. * newOption && zrUtil.merge(thisOption, newOption, true);
  4782. * layout.mergeLayoutParam(thisOption, newOption);
  4783. * }
  4784. * });
  4785. *
  4786. * @param {Object} targetOption
  4787. * @param {Object} newOption
  4788. * @param {Object|string} [opt]
  4789. * @param {boolean} [opt.ignoreSize=false] Some component must has width and height.
  4790. */
  4791. layout.mergeLayoutParam = function (targetOption, newOption, opt) {
  4792. !zrUtil.isObject(opt) && (opt = {});
  4793. var hNames = ['width', 'left', 'right']; // Order by priority.
  4794. var vNames = ['height', 'top', 'bottom']; // Order by priority.
  4795. var hResult = merge(hNames);
  4796. var vResult = merge(vNames);
  4797. copy(hNames, targetOption, hResult);
  4798. copy(vNames, targetOption, vResult);
  4799. function merge(names) {
  4800. var newParams = {};
  4801. var newValueCount = 0;
  4802. var merged = {};
  4803. var mergedValueCount = 0;
  4804. var enoughParamNumber = opt.ignoreSize ? 1 : 2;
  4805. each(names, function (name) {
  4806. merged[name] = targetOption[name];
  4807. });
  4808. each(names, function (name) {
  4809. // Consider case: newOption.width is null, which is
  4810. // set by user for removing width setting.
  4811. hasProp(newOption, name) && (newParams[name] = merged[name] = newOption[name]);
  4812. hasValue(newParams, name) && newValueCount++;
  4813. hasValue(merged, name) && mergedValueCount++;
  4814. });
  4815. // Case: newOption: {width: ..., right: ...},
  4816. // or targetOption: {right: ...} and newOption: {width: ...},
  4817. // There is no conflict when merged only has params count
  4818. // little than enoughParamNumber.
  4819. if (mergedValueCount === enoughParamNumber || !newValueCount) {
  4820. return merged;
  4821. }
  4822. // Case: newOption: {width: ..., right: ...},
  4823. // Than we can make sure user only want those two, and ignore
  4824. // all origin params in targetOption.
  4825. else if (newValueCount >= enoughParamNumber) {
  4826. return newParams;
  4827. }
  4828. else {
  4829. // Chose another param from targetOption by priority.
  4830. // When 'ignoreSize', enoughParamNumber is 1 and those will not happen.
  4831. for (var i = 0; i < names.length; i++) {
  4832. var name = names[i];
  4833. if (!hasProp(newParams, name) && hasProp(targetOption, name)) {
  4834. newParams[name] = targetOption[name];
  4835. break;
  4836. }
  4837. }
  4838. return newParams;
  4839. }
  4840. }
  4841. function hasProp(obj, name) {
  4842. return obj.hasOwnProperty(name);
  4843. }
  4844. function hasValue(obj, name) {
  4845. return obj[name] != null && obj[name] !== 'auto';
  4846. }
  4847. function copy(names, target, source) {
  4848. each(names, function (name) {
  4849. target[name] = source[name];
  4850. });
  4851. }
  4852. };
  4853. /**
  4854. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  4855. * @param {Object} source
  4856. * @return {Object} Result contains those props.
  4857. */
  4858. layout.getLayoutParams = function (source) {
  4859. return layout.copyLayoutParams({}, source);
  4860. };
  4861. /**
  4862. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  4863. * @param {Object} source
  4864. * @return {Object} Result contains those props.
  4865. */
  4866. layout.copyLayoutParams = function (target, source) {
  4867. source && target && each(LOCATION_PARAMS, function (name) {
  4868. source.hasOwnProperty(name) && (target[name] = source[name]);
  4869. });
  4870. return target;
  4871. };
  4872. module.exports = layout;
  4873. /***/ },
  4874. /* 22 */
  4875. /***/ function(module, exports) {
  4876. module.exports = {
  4877. getBoxLayoutParams: function () {
  4878. return {
  4879. left: this.get('left'),
  4880. top: this.get('top'),
  4881. right: this.get('right'),
  4882. bottom: this.get('bottom'),
  4883. width: this.get('width'),
  4884. height: this.get('height')
  4885. };
  4886. }
  4887. };
  4888. /***/ },
  4889. /* 23 */
  4890. /***/ function(module, exports) {
  4891. var platform = '';
  4892. // Navigator not exists in node
  4893. if (typeof navigator !== 'undefined') {
  4894. platform = navigator.platform || '';
  4895. }
  4896. module.exports = {
  4897. // 全图默认背景
  4898. // backgroundColor: 'rgba(0,0,0,0)',
  4899. // https://dribbble.com/shots/1065960-Infographic-Pie-chart-visualization
  4900. // color: ['#5793f3', '#d14a61', '#fd9c35', '#675bba', '#fec42c', '#dd4444', '#d4df5a', '#cd4870'],
  4901. // 浅色
  4902. // color: ['#bcd3bb', '#e88f70', '#edc1a5', '#9dc5c8', '#e1e8c8', '#7b7c68', '#e5b5b5', '#f0b489', '#928ea8', '#bda29a'],
  4903. // color: ['#cc5664', '#9bd6ec', '#ea946e', '#8acaaa', '#f1ec64', '#ee8686', '#a48dc1', '#5da6bc', '#b9dcae'],
  4904. // 深色
  4905. color: ['#c23531','#2f4554', '#61a0a8', '#d48265', '#91c7ae','#749f83', '#ca8622', '#bda29a','#6e7074', '#546570', '#c4ccd3'],
  4906. // 默认需要 Grid 配置项
  4907. grid: {},
  4908. // 主题,主题
  4909. textStyle: {
  4910. // color: '#000',
  4911. // decoration: 'none',
  4912. // PENDING
  4913. fontFamily: platform.match(/^Win/) ? 'Microsoft YaHei' : 'sans-serif',
  4914. // fontFamily: 'Arial, Verdana, sans-serif',
  4915. fontSize: 12,
  4916. fontStyle: 'normal',
  4917. fontWeight: 'normal'
  4918. },
  4919. // 主题,默认标志图形类型列表
  4920. // symbolList: [
  4921. // 'circle', 'rectangle', 'triangle', 'diamond',
  4922. // 'emptyCircle', 'emptyRectangle', 'emptyTriangle', 'emptyDiamond'
  4923. // ],
  4924. animation: true, // 过渡动画是否开启
  4925. animationThreshold: 2000, // 动画元素阀值,产生的图形原素超过2000不出动画
  4926. animationDuration: 1000, // 过渡动画参数:进入
  4927. animationDurationUpdate: 300, // 过渡动画参数:更新
  4928. animationEasing: 'exponentialOut', //BounceOut
  4929. animationEasingUpdate: 'cubicOut'
  4930. };
  4931. /***/ },
  4932. /* 24 */
  4933. /***/ function(module, exports, __webpack_require__) {
  4934. 'use strict';
  4935. var zrUtil = __webpack_require__(3);
  4936. var echartsAPIList = [
  4937. 'getDom', 'getZr', 'getWidth', 'getHeight', 'dispatchAction',
  4938. 'on', 'off', 'getDataURL', 'getConnectedDataURL', 'getModel', 'getOption'
  4939. ];
  4940. function ExtensionAPI(chartInstance) {
  4941. zrUtil.each(echartsAPIList, function (name) {
  4942. this[name] = zrUtil.bind(chartInstance[name], chartInstance);
  4943. }, this);
  4944. }
  4945. module.exports = ExtensionAPI;
  4946. /***/ },
  4947. /* 25 */
  4948. /***/ function(module, exports) {
  4949. 'use strict';
  4950. // var zrUtil = require('zrender/lib/core/util');
  4951. var coordinateSystemCreators = {};
  4952. function CoordinateSystemManager() {
  4953. this._coordinateSystems = [];
  4954. }
  4955. CoordinateSystemManager.prototype = {
  4956. constructor: CoordinateSystemManager,
  4957. create: function (ecModel, api) {
  4958. var coordinateSystems = [];
  4959. for (var type in coordinateSystemCreators) {
  4960. var list = coordinateSystemCreators[type].create(ecModel, api);
  4961. list && (coordinateSystems = coordinateSystems.concat(list));
  4962. }
  4963. this._coordinateSystems = coordinateSystems;
  4964. },
  4965. update: function (ecModel, api) {
  4966. var coordinateSystems = this._coordinateSystems;
  4967. for (var i = 0; i < coordinateSystems.length; i++) {
  4968. // FIXME MUST have
  4969. coordinateSystems[i].update && coordinateSystems[i].update(ecModel, api);
  4970. }
  4971. }
  4972. };
  4973. CoordinateSystemManager.register = function (type, coordinateSystemCreator) {
  4974. coordinateSystemCreators[type] = coordinateSystemCreator;
  4975. };
  4976. CoordinateSystemManager.get = function (type) {
  4977. return coordinateSystemCreators[type];
  4978. };
  4979. module.exports = CoordinateSystemManager;
  4980. /***/ },
  4981. /* 26 */
  4982. /***/ function(module, exports, __webpack_require__) {
  4983. /**
  4984. * ECharts option manager
  4985. *
  4986. * @module {echarts/model/OptionManager}
  4987. */
  4988. var zrUtil = __webpack_require__(3);
  4989. var modelUtil = __webpack_require__(5);
  4990. var ComponentModel = __webpack_require__(19);
  4991. var each = zrUtil.each;
  4992. var clone = zrUtil.clone;
  4993. var map = zrUtil.map;
  4994. var merge = zrUtil.merge;
  4995. var QUERY_REG = /^(min|max)?(.+)$/;
  4996. /**
  4997. * TERM EXPLANATIONS:
  4998. *
  4999. * [option]:
  5000. *
  5001. * An object that contains definitions of components. For example:
  5002. * var option = {
  5003. * title: {...},
  5004. * legend: {...},
  5005. * visualMap: {...},
  5006. * series: [
  5007. * {data: [...]},
  5008. * {data: [...]},
  5009. * ...
  5010. * ]
  5011. * };
  5012. *
  5013. * [rawOption]:
  5014. *
  5015. * An object input to echarts.setOption. 'rawOption' may be an
  5016. * 'option', or may be an object contains multi-options. For example:
  5017. * var option = {
  5018. * baseOption: {
  5019. * title: {...},
  5020. * legend: {...},
  5021. * series: [
  5022. * {data: [...]},
  5023. * {data: [...]},
  5024. * ...
  5025. * ]
  5026. * },
  5027. * timeline: {...},
  5028. * options: [
  5029. * {title: {...}, series: {data: [...]}},
  5030. * {title: {...}, series: {data: [...]}},
  5031. * ...
  5032. * ],
  5033. * media: [
  5034. * {
  5035. * query: {maxWidth: 320},
  5036. * option: {series: {x: 20}, visualMap: {show: false}}
  5037. * },
  5038. * {
  5039. * query: {minWidth: 320, maxWidth: 720},
  5040. * option: {series: {x: 500}, visualMap: {show: true}}
  5041. * },
  5042. * {
  5043. * option: {series: {x: 1200}, visualMap: {show: true}}
  5044. * }
  5045. * ]
  5046. * };
  5047. *
  5048. * @alias module:echarts/model/OptionManager
  5049. * @param {module:echarts/ExtensionAPI} api
  5050. */
  5051. function OptionManager(api) {
  5052. /**
  5053. * @private
  5054. * @type {module:echarts/ExtensionAPI}
  5055. */
  5056. this._api = api;
  5057. /**
  5058. * @private
  5059. * @type {Array.<number>}
  5060. */
  5061. this._timelineOptions = [];
  5062. /**
  5063. * @private
  5064. * @type {Array.<Object>}
  5065. */
  5066. this._mediaList = [];
  5067. /**
  5068. * @private
  5069. * @type {Object}
  5070. */
  5071. this._mediaDefault;
  5072. /**
  5073. * -1, means default.
  5074. * empty means no media.
  5075. * @private
  5076. * @type {Array.<number>}
  5077. */
  5078. this._currentMediaIndices = [];
  5079. /**
  5080. * @private
  5081. * @type {Object}
  5082. */
  5083. this._optionBackup;
  5084. /**
  5085. * @private
  5086. * @type {Object}
  5087. */
  5088. this._newBaseOption;
  5089. }
  5090. // timeline.notMerge is not supported in ec3. Firstly there is rearly
  5091. // case that notMerge is needed. Secondly supporting 'notMerge' requires
  5092. // rawOption cloned and backuped when timeline changed, which does no
  5093. // good to performance. What's more, that both timeline and setOption
  5094. // method supply 'notMerge' brings complex and some problems.
  5095. // Consider this case:
  5096. // (step1) chart.setOption({timeline: {notMerge: false}, ...}, false);
  5097. // (step2) chart.setOption({timeline: {notMerge: true}, ...}, false);
  5098. OptionManager.prototype = {
  5099. constructor: OptionManager,
  5100. /**
  5101. * @public
  5102. * @param {Object} rawOption Raw option.
  5103. * @param {module:echarts/model/Global} ecModel
  5104. * @param {Array.<Function>} optionPreprocessorFuncs
  5105. * @return {Object} Init option
  5106. */
  5107. setOption: function (rawOption, optionPreprocessorFuncs) {
  5108. rawOption = clone(rawOption, true);
  5109. // FIXME
  5110. // 如果 timeline options 或者 media 中设置了某个属性,而baseOption中没有设置,则进行警告。
  5111. var oldOptionBackup = this._optionBackup;
  5112. var newParsedOption = parseRawOption.call(
  5113. this, rawOption, optionPreprocessorFuncs
  5114. );
  5115. this._newBaseOption = newParsedOption.baseOption;
  5116. // For setOption at second time (using merge mode);
  5117. if (oldOptionBackup) {
  5118. // Only baseOption can be merged.
  5119. mergeOption(oldOptionBackup.baseOption, newParsedOption.baseOption);
  5120. // For simplicity, timeline options and media options do not support merge,
  5121. // that is, if you `setOption` twice and both has timeline options, the latter
  5122. // timeline opitons will not be merged to the formers, but just substitude them.
  5123. if (newParsedOption.timelineOptions.length) {
  5124. oldOptionBackup.timelineOptions = newParsedOption.timelineOptions;
  5125. }
  5126. if (newParsedOption.mediaList.length) {
  5127. oldOptionBackup.mediaList = newParsedOption.mediaList;
  5128. }
  5129. if (newParsedOption.mediaDefault) {
  5130. oldOptionBackup.mediaDefault = newParsedOption.mediaDefault;
  5131. }
  5132. }
  5133. else {
  5134. this._optionBackup = newParsedOption;
  5135. }
  5136. },
  5137. /**
  5138. * @param {boolean} isRecreate
  5139. * @return {Object}
  5140. */
  5141. mountOption: function (isRecreate) {
  5142. var optionBackup = this._optionBackup;
  5143. // TODO
  5144. // 如果没有reset功能则不clone。
  5145. this._timelineOptions = map(optionBackup.timelineOptions, clone);
  5146. this._mediaList = map(optionBackup.mediaList, clone);
  5147. this._mediaDefault = clone(optionBackup.mediaDefault);
  5148. this._currentMediaIndices = [];
  5149. return clone(isRecreate
  5150. // this._optionBackup.baseOption, which is created at the first `setOption`
  5151. // called, and is merged into every new option by inner method `mergeOption`
  5152. // each time `setOption` called, can be only used in `isRecreate`, because
  5153. // its reliability is under suspicion. In other cases option merge is
  5154. // proformed by `model.mergeOption`.
  5155. ? optionBackup.baseOption : this._newBaseOption
  5156. );
  5157. },
  5158. /**
  5159. * @param {module:echarts/model/Global} ecModel
  5160. * @return {Object}
  5161. */
  5162. getTimelineOption: function (ecModel) {
  5163. var option;
  5164. var timelineOptions = this._timelineOptions;
  5165. if (timelineOptions.length) {
  5166. // getTimelineOption can only be called after ecModel inited,
  5167. // so we can get currentIndex from timelineModel.
  5168. var timelineModel = ecModel.getComponent('timeline');
  5169. if (timelineModel) {
  5170. option = clone(
  5171. timelineOptions[timelineModel.getCurrentIndex()],
  5172. true
  5173. );
  5174. }
  5175. }
  5176. return option;
  5177. },
  5178. /**
  5179. * @param {module:echarts/model/Global} ecModel
  5180. * @return {Array.<Object>}
  5181. */
  5182. getMediaOption: function (ecModel) {
  5183. var ecWidth = this._api.getWidth();
  5184. var ecHeight = this._api.getHeight();
  5185. var mediaList = this._mediaList;
  5186. var mediaDefault = this._mediaDefault;
  5187. var indices = [];
  5188. var result = [];
  5189. // No media defined.
  5190. if (!mediaList.length && !mediaDefault) {
  5191. return result;
  5192. }
  5193. // Multi media may be applied, the latter defined media has higher priority.
  5194. for (var i = 0, len = mediaList.length; i < len; i++) {
  5195. if (applyMediaQuery(mediaList[i].query, ecWidth, ecHeight)) {
  5196. indices.push(i);
  5197. }
  5198. }
  5199. // FIXME
  5200. // 是否mediaDefault应该强制用户设置,否则可能修改不能回归。
  5201. if (!indices.length && mediaDefault) {
  5202. indices = [-1];
  5203. }
  5204. if (indices.length && !indicesEquals(indices, this._currentMediaIndices)) {
  5205. result = map(indices, function (index) {
  5206. return clone(
  5207. index === -1 ? mediaDefault.option : mediaList[index].option
  5208. );
  5209. });
  5210. }
  5211. // Otherwise return nothing.
  5212. this._currentMediaIndices = indices;
  5213. return result;
  5214. }
  5215. };
  5216. function parseRawOption(rawOption, optionPreprocessorFuncs) {
  5217. var timelineOptions = [];
  5218. var mediaList = [];
  5219. var mediaDefault;
  5220. var baseOption;
  5221. // Compatible with ec2.
  5222. var timelineOpt = rawOption.timeline;
  5223. if (rawOption.baseOption) {
  5224. baseOption = rawOption.baseOption;
  5225. }
  5226. // For timeline
  5227. if (timelineOpt || rawOption.options) {
  5228. baseOption = baseOption || {};
  5229. timelineOptions = (rawOption.options || []).slice();
  5230. }
  5231. // For media query
  5232. if (rawOption.media) {
  5233. baseOption = baseOption || {};
  5234. var media = rawOption.media;
  5235. each(media, function (singleMedia) {
  5236. if (singleMedia && singleMedia.option) {
  5237. if (singleMedia.query) {
  5238. mediaList.push(singleMedia);
  5239. }
  5240. else if (!mediaDefault) {
  5241. // Use the first media default.
  5242. mediaDefault = singleMedia;
  5243. }
  5244. }
  5245. });
  5246. }
  5247. // For normal option
  5248. if (!baseOption) {
  5249. baseOption = rawOption;
  5250. }
  5251. // Set timelineOpt to baseOption in ec3,
  5252. // which is convenient for merge option.
  5253. if (!baseOption.timeline) {
  5254. baseOption.timeline = timelineOpt;
  5255. }
  5256. // Preprocess.
  5257. each([baseOption].concat(timelineOptions)
  5258. .concat(zrUtil.map(mediaList, function (media) {
  5259. return media.option;
  5260. })),
  5261. function (option) {
  5262. each(optionPreprocessorFuncs, function (preProcess) {
  5263. preProcess(option);
  5264. });
  5265. }
  5266. );
  5267. return {
  5268. baseOption: baseOption,
  5269. timelineOptions: timelineOptions,
  5270. mediaDefault: mediaDefault,
  5271. mediaList: mediaList
  5272. };
  5273. }
  5274. /**
  5275. * @see <http://www.w3.org/TR/css3-mediaqueries/#media1>
  5276. * Support: width, height, aspectRatio
  5277. * Can use max or min as prefix.
  5278. */
  5279. function applyMediaQuery(query, ecWidth, ecHeight) {
  5280. var realMap = {
  5281. width: ecWidth,
  5282. height: ecHeight,
  5283. aspectratio: ecWidth / ecHeight // lowser case for convenientce.
  5284. };
  5285. var applicatable = true;
  5286. zrUtil.each(query, function (value, attr) {
  5287. var matched = attr.match(QUERY_REG);
  5288. if (!matched || !matched[1] || !matched[2]) {
  5289. return;
  5290. }
  5291. var operator = matched[1];
  5292. var realAttr = matched[2].toLowerCase();
  5293. if (!compare(realMap[realAttr], value, operator)) {
  5294. applicatable = false;
  5295. }
  5296. });
  5297. return applicatable;
  5298. }
  5299. function compare(real, expect, operator) {
  5300. if (operator === 'min') {
  5301. return real >= expect;
  5302. }
  5303. else if (operator === 'max') {
  5304. return real <= expect;
  5305. }
  5306. else { // Equals
  5307. return real === expect;
  5308. }
  5309. }
  5310. function indicesEquals(indices1, indices2) {
  5311. // indices is always order by asc and has only finite number.
  5312. return indices1.join(',') === indices2.join(',');
  5313. }
  5314. /**
  5315. * Consider case:
  5316. * `chart.setOption(opt1);`
  5317. * Then user do some interaction like dataZoom, dataView changing.
  5318. * `chart.setOption(opt2);`
  5319. * Then user press 'reset button' in toolbox.
  5320. *
  5321. * After doing that all of the interaction effects should be reset, the
  5322. * chart should be the same as the result of invoke
  5323. * `chart.setOption(opt1); chart.setOption(opt2);`.
  5324. *
  5325. * Although it is not able ensure that
  5326. * `chart.setOption(opt1); chart.setOption(opt2);` is equivalents to
  5327. * `chart.setOption(merge(opt1, opt2));` exactly,
  5328. * this might be the only simple way to implement that feature.
  5329. *
  5330. * MEMO: We've considered some other approaches:
  5331. * 1. Each model handle its self restoration but not uniform treatment.
  5332. * (Too complex in logic and error-prone)
  5333. * 2. Use a shadow ecModel. (Performace expensive)
  5334. */
  5335. function mergeOption(oldOption, newOption) {
  5336. newOption = newOption || {};
  5337. each(newOption, function (newCptOpt, mainType) {
  5338. if (newCptOpt == null) {
  5339. return;
  5340. }
  5341. var oldCptOpt = oldOption[mainType];
  5342. if (!ComponentModel.hasClass(mainType)) {
  5343. oldOption[mainType] = merge(oldCptOpt, newCptOpt, true);
  5344. }
  5345. else {
  5346. newCptOpt = modelUtil.normalizeToArray(newCptOpt);
  5347. oldCptOpt = modelUtil.normalizeToArray(oldCptOpt);
  5348. var mapResult = modelUtil.mappingToExists(oldCptOpt, newCptOpt);
  5349. oldOption[mainType] = map(mapResult, function (item) {
  5350. return (item.option && item.exist)
  5351. ? merge(item.exist, item.option, true)
  5352. : (item.exist || item.option);
  5353. });
  5354. }
  5355. });
  5356. }
  5357. module.exports = OptionManager;
  5358. /***/ },
  5359. /* 27 */
  5360. /***/ function(module, exports, __webpack_require__) {
  5361. 'use strict';
  5362. var zrUtil = __webpack_require__(3);
  5363. var formatUtil = __webpack_require__(6);
  5364. var modelUtil = __webpack_require__(5);
  5365. var ComponentModel = __webpack_require__(19);
  5366. var encodeHTML = formatUtil.encodeHTML;
  5367. var addCommas = formatUtil.addCommas;
  5368. var SeriesModel = ComponentModel.extend({
  5369. type: 'series.__base__',
  5370. /**
  5371. * @readOnly
  5372. */
  5373. seriesIndex: 0,
  5374. // coodinateSystem will be injected in the echarts/CoordinateSystem
  5375. coordinateSystem: null,
  5376. /**
  5377. * @type {Object}
  5378. * @protected
  5379. */
  5380. defaultOption: null,
  5381. /**
  5382. * Data provided for legend
  5383. * @type {Function}
  5384. */
  5385. // PENDING
  5386. legendDataProvider: null,
  5387. init: function (option, parentModel, ecModel, extraOpt) {
  5388. /**
  5389. * @type {number}
  5390. * @readOnly
  5391. */
  5392. this.seriesIndex = this.componentIndex;
  5393. this.mergeDefaultAndTheme(option, ecModel);
  5394. /**
  5395. * @type {module:echarts/data/List|module:echarts/data/Tree|module:echarts/data/Graph}
  5396. * @private
  5397. */
  5398. this._dataBeforeProcessed = this.getInitialData(option, ecModel);
  5399. // If we reverse the order (make this._data firstly, and then make
  5400. // this._dataBeforeProcessed by cloneShallow), cloneShallow will
  5401. // cause this._data.graph.data !== this._data when using
  5402. // module:echarts/data/Graph or module:echarts/data/Tree.
  5403. // See module:echarts/data/helper/linkList
  5404. this._data = this._dataBeforeProcessed.cloneShallow();
  5405. },
  5406. /**
  5407. * Util for merge default and theme to option
  5408. * @param {Object} option
  5409. * @param {module:echarts/model/Global} ecModel
  5410. */
  5411. mergeDefaultAndTheme: function (option, ecModel) {
  5412. zrUtil.merge(
  5413. option,
  5414. ecModel.getTheme().get(this.subType)
  5415. );
  5416. zrUtil.merge(option, this.getDefaultOption());
  5417. // Default label emphasis `position` and `show`
  5418. // FIXME Set label in mergeOption
  5419. modelUtil.defaultEmphasis(option.label, modelUtil.LABEL_OPTIONS);
  5420. this.fillDataTextStyle(option.data);
  5421. },
  5422. mergeOption: function (newSeriesOption, ecModel) {
  5423. newSeriesOption = zrUtil.merge(this.option, newSeriesOption, true);
  5424. this.fillDataTextStyle(newSeriesOption.data);
  5425. var data = this.getInitialData(newSeriesOption, ecModel);
  5426. // TODO Merge data?
  5427. if (data) {
  5428. this._data = data;
  5429. this._dataBeforeProcessed = data.cloneShallow();
  5430. }
  5431. },
  5432. fillDataTextStyle: function (data) {
  5433. // Default data label emphasis `position` and `show`
  5434. // FIXME Tree structure data ?
  5435. // FIXME Performance ?
  5436. if (data) {
  5437. for (var i = 0; i < data.length; i++) {
  5438. if (data[i] && data[i].label) {
  5439. modelUtil.defaultEmphasis(data[i].label, modelUtil.LABEL_OPTIONS);
  5440. }
  5441. }
  5442. }
  5443. },
  5444. /**
  5445. * Init a data structure from data related option in series
  5446. * Must be overwritten
  5447. */
  5448. getInitialData: function () {},
  5449. /**
  5450. * @param {string} [dataType]
  5451. * @return {module:echarts/data/List}
  5452. */
  5453. getData: function (dataType) {
  5454. return dataType == null ? this._data : this._data.getLinkedData(dataType);
  5455. },
  5456. /**
  5457. * @param {module:echarts/data/List} data
  5458. */
  5459. setData: function (data) {
  5460. this._data = data;
  5461. },
  5462. /**
  5463. * Get data before processed
  5464. * @return {module:echarts/data/List}
  5465. */
  5466. getRawData: function () {
  5467. return this._dataBeforeProcessed;
  5468. },
  5469. /**
  5470. * Coord dimension to data dimension.
  5471. *
  5472. * By default the result is the same as dimensions of series data.
  5473. * But in some series data dimensions are different from coord dimensions (i.e.
  5474. * candlestick and boxplot). Override this method to handle those cases.
  5475. *
  5476. * Coord dimension to data dimension can be one-to-many
  5477. *
  5478. * @param {string} coordDim
  5479. * @return {Array.<string>} dimensions on the axis.
  5480. */
  5481. coordDimToDataDim: function (coordDim) {
  5482. return [coordDim];
  5483. },
  5484. /**
  5485. * Convert data dimension to coord dimension.
  5486. *
  5487. * @param {string|number} dataDim
  5488. * @return {string}
  5489. */
  5490. dataDimToCoordDim: function (dataDim) {
  5491. return dataDim;
  5492. },
  5493. /**
  5494. * Get base axis if has coordinate system and has axis.
  5495. * By default use coordSys.getBaseAxis();
  5496. * Can be overrided for some chart.
  5497. * @return {type} description
  5498. */
  5499. getBaseAxis: function () {
  5500. var coordSys = this.coordinateSystem;
  5501. return coordSys && coordSys.getBaseAxis && coordSys.getBaseAxis();
  5502. },
  5503. // FIXME
  5504. /**
  5505. * Default tooltip formatter
  5506. *
  5507. * @param {number} dataIndex
  5508. * @param {boolean} [multipleSeries=false]
  5509. * @param {number} [dataType]
  5510. */
  5511. formatTooltip: function (dataIndex, multipleSeries, dataType) {
  5512. var data = this._data;
  5513. var value = this.getRawValue(dataIndex);
  5514. var formattedValue = zrUtil.isArray(value)
  5515. ? zrUtil.map(value, addCommas).join(', ') : addCommas(value);
  5516. var name = data.getName(dataIndex);
  5517. var color = data.getItemVisual(dataIndex, 'color');
  5518. var colorEl = '<span style="display:inline-block;margin-right:5px;'
  5519. + 'border-radius:10px;width:9px;height:9px;background-color:' + color + '"></span>';
  5520. var seriesName = this.name;
  5521. // FIXME
  5522. if (seriesName === '\0-') {
  5523. // Not show '-'
  5524. seriesName = '';
  5525. }
  5526. return !multipleSeries
  5527. ? ((seriesName && encodeHTML(seriesName) + '<br />') + colorEl
  5528. + (name
  5529. ? encodeHTML(name) + ' : ' + formattedValue
  5530. : formattedValue)
  5531. )
  5532. : (colorEl + encodeHTML(this.name) + ' : ' + formattedValue);
  5533. },
  5534. restoreData: function () {
  5535. this._data = this._dataBeforeProcessed.cloneShallow();
  5536. },
  5537. getAxisTooltipDataIndex: null
  5538. });
  5539. zrUtil.mixin(SeriesModel, modelUtil.dataFormatMixin);
  5540. module.exports = SeriesModel;
  5541. /***/ },
  5542. /* 28 */
  5543. /***/ function(module, exports, __webpack_require__) {
  5544. var Group = __webpack_require__(29);
  5545. var componentUtil = __webpack_require__(20);
  5546. var clazzUtil = __webpack_require__(9);
  5547. var Component = function () {
  5548. /**
  5549. * @type {module:zrender/container/Group}
  5550. * @readOnly
  5551. */
  5552. this.group = new Group();
  5553. /**
  5554. * @type {string}
  5555. * @readOnly
  5556. */
  5557. this.uid = componentUtil.getUID('viewComponent');
  5558. };
  5559. Component.prototype = {
  5560. constructor: Component,
  5561. init: function (ecModel, api) {},
  5562. render: function (componentModel, ecModel, api, payload) {},
  5563. dispose: function () {}
  5564. };
  5565. var componentProto = Component.prototype;
  5566. componentProto.updateView
  5567. = componentProto.updateLayout
  5568. = componentProto.updateVisual
  5569. = function (seriesModel, ecModel, api, payload) {
  5570. // Do nothing;
  5571. };
  5572. // Enable Component.extend.
  5573. clazzUtil.enableClassExtend(Component);
  5574. // Enable capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  5575. clazzUtil.enableClassManagement(Component, {registerWhenExtend: true});
  5576. module.exports = Component;
  5577. /***/ },
  5578. /* 29 */
  5579. /***/ function(module, exports, __webpack_require__) {
  5580. /**
  5581. * Group是一个容器,可以插入子节点,Group的变换也会被应用到子节点上
  5582. * @module zrender/graphic/Group
  5583. * @example
  5584. * var Group = require('zrender/lib/container/Group');
  5585. * var Circle = require('zrender/lib/graphic/shape/Circle');
  5586. * var g = new Group();
  5587. * g.position[0] = 100;
  5588. * g.position[1] = 100;
  5589. * g.add(new Circle({
  5590. * style: {
  5591. * x: 100,
  5592. * y: 100,
  5593. * r: 20,
  5594. * }
  5595. * }));
  5596. * zr.add(g);
  5597. */
  5598. var zrUtil = __webpack_require__(3);
  5599. var Element = __webpack_require__(30);
  5600. var BoundingRect = __webpack_require__(15);
  5601. /**
  5602. * @alias module:zrender/graphic/Group
  5603. * @constructor
  5604. * @extends module:zrender/mixin/Transformable
  5605. * @extends module:zrender/mixin/Eventful
  5606. */
  5607. var Group = function (opts) {
  5608. opts = opts || {};
  5609. Element.call(this, opts);
  5610. for (var key in opts) {
  5611. this[key] = opts[key];
  5612. }
  5613. this._children = [];
  5614. this.__storage = null;
  5615. this.__dirty = true;
  5616. };
  5617. Group.prototype = {
  5618. constructor: Group,
  5619. /**
  5620. * @type {string}
  5621. */
  5622. type: 'group',
  5623. /**
  5624. * 所有子孙元素是否响应鼠标事件
  5625. * @name module:/zrender/container/Group#silent
  5626. * @type {boolean}
  5627. * @default false
  5628. */
  5629. silent: false,
  5630. /**
  5631. * @return {Array.<module:zrender/Element>}
  5632. */
  5633. children: function () {
  5634. return this._children.slice();
  5635. },
  5636. /**
  5637. * 获取指定 index 的儿子节点
  5638. * @param {number} idx
  5639. * @return {module:zrender/Element}
  5640. */
  5641. childAt: function (idx) {
  5642. return this._children[idx];
  5643. },
  5644. /**
  5645. * 获取指定名字的儿子节点
  5646. * @param {string} name
  5647. * @return {module:zrender/Element}
  5648. */
  5649. childOfName: function (name) {
  5650. var children = this._children;
  5651. for (var i = 0; i < children.length; i++) {
  5652. if (children[i].name === name) {
  5653. return children[i];
  5654. }
  5655. }
  5656. },
  5657. /**
  5658. * @return {number}
  5659. */
  5660. childCount: function () {
  5661. return this._children.length;
  5662. },
  5663. /**
  5664. * 添加子节点到最后
  5665. * @param {module:zrender/Element} child
  5666. */
  5667. add: function (child) {
  5668. if (child && child !== this && child.parent !== this) {
  5669. this._children.push(child);
  5670. this._doAdd(child);
  5671. }
  5672. return this;
  5673. },
  5674. /**
  5675. * 添加子节点在 nextSibling 之前
  5676. * @param {module:zrender/Element} child
  5677. * @param {module:zrender/Element} nextSibling
  5678. */
  5679. addBefore: function (child, nextSibling) {
  5680. if (child && child !== this && child.parent !== this
  5681. && nextSibling && nextSibling.parent === this) {
  5682. var children = this._children;
  5683. var idx = children.indexOf(nextSibling);
  5684. if (idx >= 0) {
  5685. children.splice(idx, 0, child);
  5686. this._doAdd(child);
  5687. }
  5688. }
  5689. return this;
  5690. },
  5691. _doAdd: function (child) {
  5692. if (child.parent) {
  5693. child.parent.remove(child);
  5694. }
  5695. child.parent = this;
  5696. var storage = this.__storage;
  5697. var zr = this.__zr;
  5698. if (storage && storage !== child.__storage) {
  5699. storage.addToMap(child);
  5700. if (child instanceof Group) {
  5701. child.addChildrenToStorage(storage);
  5702. }
  5703. }
  5704. zr && zr.refresh();
  5705. },
  5706. /**
  5707. * 移除子节点
  5708. * @param {module:zrender/Element} child
  5709. */
  5710. remove: function (child) {
  5711. var zr = this.__zr;
  5712. var storage = this.__storage;
  5713. var children = this._children;
  5714. var idx = zrUtil.indexOf(children, child);
  5715. if (idx < 0) {
  5716. return this;
  5717. }
  5718. children.splice(idx, 1);
  5719. child.parent = null;
  5720. if (storage) {
  5721. storage.delFromMap(child.id);
  5722. if (child instanceof Group) {
  5723. child.delChildrenFromStorage(storage);
  5724. }
  5725. }
  5726. zr && zr.refresh();
  5727. return this;
  5728. },
  5729. /**
  5730. * 移除所有子节点
  5731. */
  5732. removeAll: function () {
  5733. var children = this._children;
  5734. var storage = this.__storage;
  5735. var child;
  5736. var i;
  5737. for (i = 0; i < children.length; i++) {
  5738. child = children[i];
  5739. if (storage) {
  5740. storage.delFromMap(child.id);
  5741. if (child instanceof Group) {
  5742. child.delChildrenFromStorage(storage);
  5743. }
  5744. }
  5745. child.parent = null;
  5746. }
  5747. children.length = 0;
  5748. return this;
  5749. },
  5750. /**
  5751. * 遍历所有子节点
  5752. * @param {Function} cb
  5753. * @param {} context
  5754. */
  5755. eachChild: function (cb, context) {
  5756. var children = this._children;
  5757. for (var i = 0; i < children.length; i++) {
  5758. var child = children[i];
  5759. cb.call(context, child, i);
  5760. }
  5761. return this;
  5762. },
  5763. /**
  5764. * 深度优先遍历所有子孙节点
  5765. * @param {Function} cb
  5766. * @param {} context
  5767. */
  5768. traverse: function (cb, context) {
  5769. for (var i = 0; i < this._children.length; i++) {
  5770. var child = this._children[i];
  5771. cb.call(context, child);
  5772. if (child.type === 'group') {
  5773. child.traverse(cb, context);
  5774. }
  5775. }
  5776. return this;
  5777. },
  5778. addChildrenToStorage: function (storage) {
  5779. for (var i = 0; i < this._children.length; i++) {
  5780. var child = this._children[i];
  5781. storage.addToMap(child);
  5782. if (child instanceof Group) {
  5783. child.addChildrenToStorage(storage);
  5784. }
  5785. }
  5786. },
  5787. delChildrenFromStorage: function (storage) {
  5788. for (var i = 0; i < this._children.length; i++) {
  5789. var child = this._children[i];
  5790. storage.delFromMap(child.id);
  5791. if (child instanceof Group) {
  5792. child.delChildrenFromStorage(storage);
  5793. }
  5794. }
  5795. },
  5796. dirty: function () {
  5797. this.__dirty = true;
  5798. this.__zr && this.__zr.refresh();
  5799. return this;
  5800. },
  5801. /**
  5802. * @return {module:zrender/core/BoundingRect}
  5803. */
  5804. getBoundingRect: function (includeChildren) {
  5805. // TODO Caching
  5806. // TODO Transform
  5807. var rect = null;
  5808. var tmpRect = new BoundingRect(0, 0, 0, 0);
  5809. var children = includeChildren || this._children;
  5810. var tmpMat = [];
  5811. for (var i = 0; i < children.length; i++) {
  5812. var child = children[i];
  5813. if (child.ignore || child.invisible) {
  5814. continue;
  5815. }
  5816. var childRect = child.getBoundingRect();
  5817. var transform = child.getLocalTransform(tmpMat);
  5818. if (transform) {
  5819. tmpRect.copy(childRect);
  5820. tmpRect.applyTransform(transform);
  5821. rect = rect || tmpRect.clone();
  5822. rect.union(tmpRect);
  5823. }
  5824. else {
  5825. rect = rect || childRect.clone();
  5826. rect.union(childRect);
  5827. }
  5828. }
  5829. return rect || tmpRect;
  5830. }
  5831. };
  5832. zrUtil.inherits(Group, Element);
  5833. module.exports = Group;
  5834. /***/ },
  5835. /* 30 */
  5836. /***/ function(module, exports, __webpack_require__) {
  5837. 'use strict';
  5838. /**
  5839. * @module zrender/Element
  5840. */
  5841. var guid = __webpack_require__(31);
  5842. var Eventful = __webpack_require__(32);
  5843. var Transformable = __webpack_require__(33);
  5844. var Animatable = __webpack_require__(34);
  5845. var zrUtil = __webpack_require__(3);
  5846. /**
  5847. * @alias module:zrender/Element
  5848. * @constructor
  5849. * @extends {module:zrender/mixin/Animatable}
  5850. * @extends {module:zrender/mixin/Transformable}
  5851. * @extends {module:zrender/mixin/Eventful}
  5852. */
  5853. var Element = function (opts) {
  5854. Transformable.call(this, opts);
  5855. Eventful.call(this, opts);
  5856. Animatable.call(this, opts);
  5857. /**
  5858. * 画布元素ID
  5859. * @type {string}
  5860. */
  5861. this.id = opts.id || guid();
  5862. };
  5863. Element.prototype = {
  5864. /**
  5865. * 元素类型
  5866. * Element type
  5867. * @type {string}
  5868. */
  5869. type: 'element',
  5870. /**
  5871. * 元素名字
  5872. * Element name
  5873. * @type {string}
  5874. */
  5875. name: '',
  5876. /**
  5877. * ZRender 实例对象,会在 element 添加到 zrender 实例中后自动赋值
  5878. * ZRender instance will be assigned when element is associated with zrender
  5879. * @name module:/zrender/Element#__zr
  5880. * @type {module:zrender/ZRender}
  5881. */
  5882. __zr: null,
  5883. /**
  5884. * 图形是否忽略,为true时忽略图形的绘制以及事件触发
  5885. * If ignore drawing and events of the element object
  5886. * @name module:/zrender/Element#ignore
  5887. * @type {boolean}
  5888. * @default false
  5889. */
  5890. ignore: false,
  5891. /**
  5892. * 用于裁剪的路径(shape),所有 Group 内的路径在绘制时都会被这个路径裁剪
  5893. * 该路径会继承被裁减对象的变换
  5894. * @type {module:zrender/graphic/Path}
  5895. * @see http://www.w3.org/TR/2dcontext/#clipping-region
  5896. * @readOnly
  5897. */
  5898. clipPath: null,
  5899. /**
  5900. * Drift element
  5901. * @param {number} dx dx on the global space
  5902. * @param {number} dy dy on the global space
  5903. */
  5904. drift: function (dx, dy) {
  5905. switch (this.draggable) {
  5906. case 'horizontal':
  5907. dy = 0;
  5908. break;
  5909. case 'vertical':
  5910. dx = 0;
  5911. break;
  5912. }
  5913. var m = this.transform;
  5914. if (!m) {
  5915. m = this.transform = [1, 0, 0, 1, 0, 0];
  5916. }
  5917. m[4] += dx;
  5918. m[5] += dy;
  5919. this.decomposeTransform();
  5920. this.dirty();
  5921. },
  5922. /**
  5923. * Hook before update
  5924. */
  5925. beforeUpdate: function () {},
  5926. /**
  5927. * Hook after update
  5928. */
  5929. afterUpdate: function () {},
  5930. /**
  5931. * Update each frame
  5932. */
  5933. update: function () {
  5934. this.updateTransform();
  5935. },
  5936. /**
  5937. * @param {Function} cb
  5938. * @param {} context
  5939. */
  5940. traverse: function (cb, context) {},
  5941. /**
  5942. * @protected
  5943. */
  5944. attrKV: function (key, value) {
  5945. if (key === 'position' || key === 'scale' || key === 'origin') {
  5946. // Copy the array
  5947. if (value) {
  5948. var target = this[key];
  5949. if (!target) {
  5950. target = this[key] = [];
  5951. }
  5952. target[0] = value[0];
  5953. target[1] = value[1];
  5954. }
  5955. }
  5956. else {
  5957. this[key] = value;
  5958. }
  5959. },
  5960. /**
  5961. * Hide the element
  5962. */
  5963. hide: function () {
  5964. this.ignore = true;
  5965. this.__zr && this.__zr.refresh();
  5966. },
  5967. /**
  5968. * Show the element
  5969. */
  5970. show: function () {
  5971. this.ignore = false;
  5972. this.__zr && this.__zr.refresh();
  5973. },
  5974. /**
  5975. * @param {string|Object} key
  5976. * @param {*} value
  5977. */
  5978. attr: function (key, value) {
  5979. if (typeof key === 'string') {
  5980. this.attrKV(key, value);
  5981. }
  5982. else if (zrUtil.isObject(key)) {
  5983. for (var name in key) {
  5984. if (key.hasOwnProperty(name)) {
  5985. this.attrKV(name, key[name]);
  5986. }
  5987. }
  5988. }
  5989. this.dirty();
  5990. return this;
  5991. },
  5992. /**
  5993. * @param {module:zrender/graphic/Path} clipPath
  5994. */
  5995. setClipPath: function (clipPath) {
  5996. var zr = this.__zr;
  5997. if (zr) {
  5998. clipPath.addSelfToZr(zr);
  5999. }
  6000. // Remove previous clip path
  6001. if (this.clipPath && this.clipPath !== clipPath) {
  6002. this.removeClipPath();
  6003. }
  6004. this.clipPath = clipPath;
  6005. clipPath.__zr = zr;
  6006. clipPath.__clipTarget = this;
  6007. this.dirty();
  6008. },
  6009. /**
  6010. */
  6011. removeClipPath: function () {
  6012. var clipPath = this.clipPath;
  6013. if (clipPath) {
  6014. if (clipPath.__zr) {
  6015. clipPath.removeSelfFromZr(clipPath.__zr);
  6016. }
  6017. clipPath.__zr = null;
  6018. clipPath.__clipTarget = null;
  6019. this.clipPath = null;
  6020. this.dirty();
  6021. }
  6022. },
  6023. /**
  6024. * Add self from zrender instance.
  6025. * Not recursively because it will be invoked when element added to storage.
  6026. * @param {module:zrender/ZRender} zr
  6027. */
  6028. addSelfToZr: function (zr) {
  6029. this.__zr = zr;
  6030. // 添加动画
  6031. var animators = this.animators;
  6032. if (animators) {
  6033. for (var i = 0; i < animators.length; i++) {
  6034. zr.animation.addAnimator(animators[i]);
  6035. }
  6036. }
  6037. if (this.clipPath) {
  6038. this.clipPath.addSelfToZr(zr);
  6039. }
  6040. },
  6041. /**
  6042. * Remove self from zrender instance.
  6043. * Not recursively because it will be invoked when element added to storage.
  6044. * @param {module:zrender/ZRender} zr
  6045. */
  6046. removeSelfFromZr: function (zr) {
  6047. this.__zr = null;
  6048. // 移除动画
  6049. var animators = this.animators;
  6050. if (animators) {
  6051. for (var i = 0; i < animators.length; i++) {
  6052. zr.animation.removeAnimator(animators[i]);
  6053. }
  6054. }
  6055. if (this.clipPath) {
  6056. this.clipPath.removeSelfFromZr(zr);
  6057. }
  6058. }
  6059. };
  6060. zrUtil.mixin(Element, Animatable);
  6061. zrUtil.mixin(Element, Transformable);
  6062. zrUtil.mixin(Element, Eventful);
  6063. module.exports = Element;
  6064. /***/ },
  6065. /* 31 */
  6066. /***/ function(module, exports) {
  6067. /**
  6068. * zrender: 生成唯一id
  6069. *
  6070. * @author errorrik (errorrik@gmail.com)
  6071. */
  6072. var idStart = 0x0907;
  6073. module.exports = function () {
  6074. return 'zr_' + (idStart++);
  6075. };
  6076. /***/ },
  6077. /* 32 */
  6078. /***/ function(module, exports, __webpack_require__) {
  6079. /**
  6080. * 事件扩展
  6081. * @module zrender/mixin/Eventful
  6082. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  6083. * pissang (https://www.github.com/pissang)
  6084. */
  6085. var arrySlice = Array.prototype.slice;
  6086. var zrUtil = __webpack_require__(3);
  6087. var indexOf = zrUtil.indexOf;
  6088. /**
  6089. * 事件分发器
  6090. * @alias module:zrender/mixin/Eventful
  6091. * @constructor
  6092. */
  6093. var Eventful = function () {
  6094. this._$handlers = {};
  6095. };
  6096. Eventful.prototype = {
  6097. constructor: Eventful,
  6098. /**
  6099. * 单次触发绑定,trigger后销毁
  6100. *
  6101. * @param {string} event 事件名
  6102. * @param {Function} handler 响应函数
  6103. * @param {Object} context
  6104. */
  6105. one: function (event, handler, context) {
  6106. var _h = this._$handlers;
  6107. if (!handler || !event) {
  6108. return this;
  6109. }
  6110. if (!_h[event]) {
  6111. _h[event] = [];
  6112. }
  6113. if (indexOf(_h[event], event) >= 0) {
  6114. return this;
  6115. }
  6116. _h[event].push({
  6117. h: handler,
  6118. one: true,
  6119. ctx: context || this
  6120. });
  6121. return this;
  6122. },
  6123. /**
  6124. * 绑定事件
  6125. * @param {string} event 事件名
  6126. * @param {Function} handler 事件处理函数
  6127. * @param {Object} [context]
  6128. */
  6129. on: function (event, handler, context) {
  6130. var _h = this._$handlers;
  6131. if (!handler || !event) {
  6132. return this;
  6133. }
  6134. if (!_h[event]) {
  6135. _h[event] = [];
  6136. }
  6137. _h[event].push({
  6138. h: handler,
  6139. one: false,
  6140. ctx: context || this
  6141. });
  6142. return this;
  6143. },
  6144. /**
  6145. * 是否绑定了事件
  6146. * @param {string} event
  6147. * @return {boolean}
  6148. */
  6149. isSilent: function (event) {
  6150. var _h = this._$handlers;
  6151. return _h[event] && _h[event].length;
  6152. },
  6153. /**
  6154. * 解绑事件
  6155. * @param {string} event 事件名
  6156. * @param {Function} [handler] 事件处理函数
  6157. */
  6158. off: function (event, handler) {
  6159. var _h = this._$handlers;
  6160. if (!event) {
  6161. this._$handlers = {};
  6162. return this;
  6163. }
  6164. if (handler) {
  6165. if (_h[event]) {
  6166. var newList = [];
  6167. for (var i = 0, l = _h[event].length; i < l; i++) {
  6168. if (_h[event][i]['h'] != handler) {
  6169. newList.push(_h[event][i]);
  6170. }
  6171. }
  6172. _h[event] = newList;
  6173. }
  6174. if (_h[event] && _h[event].length === 0) {
  6175. delete _h[event];
  6176. }
  6177. }
  6178. else {
  6179. delete _h[event];
  6180. }
  6181. return this;
  6182. },
  6183. /**
  6184. * 事件分发
  6185. *
  6186. * @param {string} type 事件类型
  6187. */
  6188. trigger: function (type) {
  6189. if (this._$handlers[type]) {
  6190. var args = arguments;
  6191. var argLen = args.length;
  6192. if (argLen > 3) {
  6193. args = arrySlice.call(args, 1);
  6194. }
  6195. var _h = this._$handlers[type];
  6196. var len = _h.length;
  6197. for (var i = 0; i < len;) {
  6198. // Optimize advise from backbone
  6199. switch (argLen) {
  6200. case 1:
  6201. _h[i]['h'].call(_h[i]['ctx']);
  6202. break;
  6203. case 2:
  6204. _h[i]['h'].call(_h[i]['ctx'], args[1]);
  6205. break;
  6206. case 3:
  6207. _h[i]['h'].call(_h[i]['ctx'], args[1], args[2]);
  6208. break;
  6209. default:
  6210. // have more than 2 given arguments
  6211. _h[i]['h'].apply(_h[i]['ctx'], args);
  6212. break;
  6213. }
  6214. if (_h[i]['one']) {
  6215. _h.splice(i, 1);
  6216. len--;
  6217. }
  6218. else {
  6219. i++;
  6220. }
  6221. }
  6222. }
  6223. return this;
  6224. },
  6225. /**
  6226. * 带有context的事件分发, 最后一个参数是事件回调的context
  6227. * @param {string} type 事件类型
  6228. */
  6229. triggerWithContext: function (type) {
  6230. if (this._$handlers[type]) {
  6231. var args = arguments;
  6232. var argLen = args.length;
  6233. if (argLen > 4) {
  6234. args = arrySlice.call(args, 1, args.length - 1);
  6235. }
  6236. var ctx = args[args.length - 1];
  6237. var _h = this._$handlers[type];
  6238. var len = _h.length;
  6239. for (var i = 0; i < len;) {
  6240. // Optimize advise from backbone
  6241. switch (argLen) {
  6242. case 1:
  6243. _h[i]['h'].call(ctx);
  6244. break;
  6245. case 2:
  6246. _h[i]['h'].call(ctx, args[1]);
  6247. break;
  6248. case 3:
  6249. _h[i]['h'].call(ctx, args[1], args[2]);
  6250. break;
  6251. default:
  6252. // have more than 2 given arguments
  6253. _h[i]['h'].apply(ctx, args);
  6254. break;
  6255. }
  6256. if (_h[i]['one']) {
  6257. _h.splice(i, 1);
  6258. len--;
  6259. }
  6260. else {
  6261. i++;
  6262. }
  6263. }
  6264. }
  6265. return this;
  6266. }
  6267. };
  6268. // 对象可以通过 onxxxx 绑定事件
  6269. /**
  6270. * @event module:zrender/mixin/Eventful#onclick
  6271. * @type {Function}
  6272. * @default null
  6273. */
  6274. /**
  6275. * @event module:zrender/mixin/Eventful#onmouseover
  6276. * @type {Function}
  6277. * @default null
  6278. */
  6279. /**
  6280. * @event module:zrender/mixin/Eventful#onmouseout
  6281. * @type {Function}
  6282. * @default null
  6283. */
  6284. /**
  6285. * @event module:zrender/mixin/Eventful#onmousemove
  6286. * @type {Function}
  6287. * @default null
  6288. */
  6289. /**
  6290. * @event module:zrender/mixin/Eventful#onmousewheel
  6291. * @type {Function}
  6292. * @default null
  6293. */
  6294. /**
  6295. * @event module:zrender/mixin/Eventful#onmousedown
  6296. * @type {Function}
  6297. * @default null
  6298. */
  6299. /**
  6300. * @event module:zrender/mixin/Eventful#onmouseup
  6301. * @type {Function}
  6302. * @default null
  6303. */
  6304. /**
  6305. * @event module:zrender/mixin/Eventful#ondragstart
  6306. * @type {Function}
  6307. * @default null
  6308. */
  6309. /**
  6310. * @event module:zrender/mixin/Eventful#ondragend
  6311. * @type {Function}
  6312. * @default null
  6313. */
  6314. /**
  6315. * @event module:zrender/mixin/Eventful#ondragenter
  6316. * @type {Function}
  6317. * @default null
  6318. */
  6319. /**
  6320. * @event module:zrender/mixin/Eventful#ondragleave
  6321. * @type {Function}
  6322. * @default null
  6323. */
  6324. /**
  6325. * @event module:zrender/mixin/Eventful#ondragover
  6326. * @type {Function}
  6327. * @default null
  6328. */
  6329. /**
  6330. * @event module:zrender/mixin/Eventful#ondrop
  6331. * @type {Function}
  6332. * @default null
  6333. */
  6334. module.exports = Eventful;
  6335. /***/ },
  6336. /* 33 */
  6337. /***/ function(module, exports, __webpack_require__) {
  6338. 'use strict';
  6339. /**
  6340. * 提供变换扩展
  6341. * @module zrender/mixin/Transformable
  6342. * @author pissang (https://www.github.com/pissang)
  6343. */
  6344. var matrix = __webpack_require__(17);
  6345. var vector = __webpack_require__(16);
  6346. var mIdentity = matrix.identity;
  6347. var EPSILON = 5e-5;
  6348. function isNotAroundZero(val) {
  6349. return val > EPSILON || val < -EPSILON;
  6350. }
  6351. /**
  6352. * @alias module:zrender/mixin/Transformable
  6353. * @constructor
  6354. */
  6355. var Transformable = function (opts) {
  6356. opts = opts || {};
  6357. // If there are no given position, rotation, scale
  6358. if (!opts.position) {
  6359. /**
  6360. * 平移
  6361. * @type {Array.<number>}
  6362. * @default [0, 0]
  6363. */
  6364. this.position = [0, 0];
  6365. }
  6366. if (opts.rotation == null) {
  6367. /**
  6368. * 旋转
  6369. * @type {Array.<number>}
  6370. * @default 0
  6371. */
  6372. this.rotation = 0;
  6373. }
  6374. if (!opts.scale) {
  6375. /**
  6376. * 缩放
  6377. * @type {Array.<number>}
  6378. * @default [1, 1]
  6379. */
  6380. this.scale = [1, 1];
  6381. }
  6382. /**
  6383. * 旋转和缩放的原点
  6384. * @type {Array.<number>}
  6385. * @default null
  6386. */
  6387. this.origin = this.origin || null;
  6388. };
  6389. var transformableProto = Transformable.prototype;
  6390. transformableProto.transform = null;
  6391. /**
  6392. * 判断是否需要有坐标变换
  6393. * 如果有坐标变换, 则从position, rotation, scale以及父节点的transform计算出自身的transform矩阵
  6394. */
  6395. transformableProto.needLocalTransform = function () {
  6396. return isNotAroundZero(this.rotation)
  6397. || isNotAroundZero(this.position[0])
  6398. || isNotAroundZero(this.position[1])
  6399. || isNotAroundZero(this.scale[0] - 1)
  6400. || isNotAroundZero(this.scale[1] - 1);
  6401. };
  6402. transformableProto.updateTransform = function () {
  6403. var parent = this.parent;
  6404. var parentHasTransform = parent && parent.transform;
  6405. var needLocalTransform = this.needLocalTransform();
  6406. var m = this.transform;
  6407. if (!(needLocalTransform || parentHasTransform)) {
  6408. m && mIdentity(m);
  6409. return;
  6410. }
  6411. m = m || matrix.create();
  6412. if (needLocalTransform) {
  6413. this.getLocalTransform(m);
  6414. }
  6415. else {
  6416. mIdentity(m);
  6417. }
  6418. // 应用父节点变换
  6419. if (parentHasTransform) {
  6420. if (needLocalTransform) {
  6421. matrix.mul(m, parent.transform, m);
  6422. }
  6423. else {
  6424. matrix.copy(m, parent.transform);
  6425. }
  6426. }
  6427. // 保存这个变换矩阵
  6428. this.transform = m;
  6429. this.invTransform = this.invTransform || matrix.create();
  6430. matrix.invert(this.invTransform, m);
  6431. };
  6432. transformableProto.getLocalTransform = function (m) {
  6433. m = m || [];
  6434. mIdentity(m);
  6435. var origin = this.origin;
  6436. var scale = this.scale;
  6437. var rotation = this.rotation;
  6438. var position = this.position;
  6439. if (origin) {
  6440. // Translate to origin
  6441. m[4] -= origin[0];
  6442. m[5] -= origin[1];
  6443. }
  6444. matrix.scale(m, m, scale);
  6445. if (rotation) {
  6446. matrix.rotate(m, m, rotation);
  6447. }
  6448. if (origin) {
  6449. // Translate back from origin
  6450. m[4] += origin[0];
  6451. m[5] += origin[1];
  6452. }
  6453. m[4] += position[0];
  6454. m[5] += position[1];
  6455. return m;
  6456. };
  6457. /**
  6458. * 将自己的transform应用到context上
  6459. * @param {Context2D} ctx
  6460. */
  6461. transformableProto.setTransform = function (ctx) {
  6462. var m = this.transform;
  6463. if (m) {
  6464. ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
  6465. }
  6466. };
  6467. var tmpTransform = [];
  6468. /**
  6469. * 分解`transform`矩阵到`position`, `rotation`, `scale`
  6470. */
  6471. transformableProto.decomposeTransform = function () {
  6472. if (!this.transform) {
  6473. return;
  6474. }
  6475. var parent = this.parent;
  6476. var m = this.transform;
  6477. if (parent && parent.transform) {
  6478. // Get local transform and decompose them to position, scale, rotation
  6479. matrix.mul(tmpTransform, parent.invTransform, m);
  6480. m = tmpTransform;
  6481. }
  6482. var sx = m[0] * m[0] + m[1] * m[1];
  6483. var sy = m[2] * m[2] + m[3] * m[3];
  6484. var position = this.position;
  6485. var scale = this.scale;
  6486. if (isNotAroundZero(sx - 1)) {
  6487. sx = Math.sqrt(sx);
  6488. }
  6489. if (isNotAroundZero(sy - 1)) {
  6490. sy = Math.sqrt(sy);
  6491. }
  6492. if (m[0] < 0) {
  6493. sx = -sx;
  6494. }
  6495. if (m[3] < 0) {
  6496. sy = -sy;
  6497. }
  6498. position[0] = m[4];
  6499. position[1] = m[5];
  6500. scale[0] = sx;
  6501. scale[1] = sy;
  6502. this.rotation = Math.atan2(-m[1] / sy, m[0] / sx);
  6503. };
  6504. /**
  6505. * Get global scale
  6506. * @return {Array.<number>}
  6507. */
  6508. transformableProto.getGlobalScale = function () {
  6509. var m = this.transform;
  6510. if (!m) {
  6511. return [1, 1];
  6512. }
  6513. var sx = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
  6514. var sy = Math.sqrt(m[2] * m[2] + m[3] * m[3]);
  6515. if (m[0] < 0) {
  6516. sx = -sx;
  6517. }
  6518. if (m[3] < 0) {
  6519. sy = -sy;
  6520. }
  6521. return [sx, sy];
  6522. };
  6523. /**
  6524. * 变换坐标位置到 shape 的局部坐标空间
  6525. * @method
  6526. * @param {number} x
  6527. * @param {number} y
  6528. * @return {Array.<number>}
  6529. */
  6530. transformableProto.transformCoordToLocal = function (x, y) {
  6531. var v2 = [x, y];
  6532. var invTransform = this.invTransform;
  6533. if (invTransform) {
  6534. vector.applyTransform(v2, v2, invTransform);
  6535. }
  6536. return v2;
  6537. };
  6538. /**
  6539. * 变换局部坐标位置到全局坐标空间
  6540. * @method
  6541. * @param {number} x
  6542. * @param {number} y
  6543. * @return {Array.<number>}
  6544. */
  6545. transformableProto.transformCoordToGlobal = function (x, y) {
  6546. var v2 = [x, y];
  6547. var transform = this.transform;
  6548. if (transform) {
  6549. vector.applyTransform(v2, v2, transform);
  6550. }
  6551. return v2;
  6552. };
  6553. module.exports = Transformable;
  6554. /***/ },
  6555. /* 34 */
  6556. /***/ function(module, exports, __webpack_require__) {
  6557. 'use strict';
  6558. /**
  6559. * @module zrender/mixin/Animatable
  6560. */
  6561. var Animator = __webpack_require__(35);
  6562. var util = __webpack_require__(3);
  6563. var isString = util.isString;
  6564. var isFunction = util.isFunction;
  6565. var isObject = util.isObject;
  6566. var log = __webpack_require__(39);
  6567. /**
  6568. * @alias modue:zrender/mixin/Animatable
  6569. * @constructor
  6570. */
  6571. var Animatable = function () {
  6572. /**
  6573. * @type {Array.<module:zrender/animation/Animator>}
  6574. * @readOnly
  6575. */
  6576. this.animators = [];
  6577. };
  6578. Animatable.prototype = {
  6579. constructor: Animatable,
  6580. /**
  6581. * 动画
  6582. *
  6583. * @param {string} path 需要添加动画的属性获取路径,可以通过a.b.c来获取深层的属性
  6584. * @param {boolean} [loop] 动画是否循环
  6585. * @return {module:zrender/animation/Animator}
  6586. * @example:
  6587. * el.animate('style', false)
  6588. * .when(1000, {x: 10} )
  6589. * .done(function(){ // Animation done })
  6590. * .start()
  6591. */
  6592. animate: function (path, loop) {
  6593. var target;
  6594. var animatingShape = false;
  6595. var el = this;
  6596. var zr = this.__zr;
  6597. if (path) {
  6598. var pathSplitted = path.split('.');
  6599. var prop = el;
  6600. // If animating shape
  6601. animatingShape = pathSplitted[0] === 'shape';
  6602. for (var i = 0, l = pathSplitted.length; i < l; i++) {
  6603. if (!prop) {
  6604. continue;
  6605. }
  6606. prop = prop[pathSplitted[i]];
  6607. }
  6608. if (prop) {
  6609. target = prop;
  6610. }
  6611. }
  6612. else {
  6613. target = el;
  6614. }
  6615. if (!target) {
  6616. log(
  6617. 'Property "'
  6618. + path
  6619. + '" is not existed in element '
  6620. + el.id
  6621. );
  6622. return;
  6623. }
  6624. var animators = el.animators;
  6625. var animator = new Animator(target, loop);
  6626. animator.during(function (target) {
  6627. el.dirty(animatingShape);
  6628. })
  6629. .done(function () {
  6630. // FIXME Animator will not be removed if use `Animator#stop` to stop animation
  6631. animators.splice(util.indexOf(animators, animator), 1);
  6632. });
  6633. animators.push(animator);
  6634. // If animate after added to the zrender
  6635. if (zr) {
  6636. zr.animation.addAnimator(animator);
  6637. }
  6638. return animator;
  6639. },
  6640. /**
  6641. * 停止动画
  6642. * @param {boolean} forwardToLast If move to last frame before stop
  6643. */
  6644. stopAnimation: function (forwardToLast) {
  6645. var animators = this.animators;
  6646. var len = animators.length;
  6647. for (var i = 0; i < len; i++) {
  6648. animators[i].stop(forwardToLast);
  6649. }
  6650. animators.length = 0;
  6651. return this;
  6652. },
  6653. /**
  6654. * @param {Object} target
  6655. * @param {number} [time=500] Time in ms
  6656. * @param {string} [easing='linear']
  6657. * @param {number} [delay=0]
  6658. * @param {Function} [callback]
  6659. *
  6660. * @example
  6661. * // Animate position
  6662. * el.animateTo({
  6663. * position: [10, 10]
  6664. * }, function () { // done })
  6665. *
  6666. * // Animate shape, style and position in 100ms, delayed 100ms, with cubicOut easing
  6667. * el.animateTo({
  6668. * shape: {
  6669. * width: 500
  6670. * },
  6671. * style: {
  6672. * fill: 'red'
  6673. * }
  6674. * position: [10, 10]
  6675. * }, 100, 100, 'cubicOut', function () { // done })
  6676. */
  6677. // TODO Return animation key
  6678. animateTo: function (target, time, delay, easing, callback) {
  6679. // animateTo(target, time, easing, callback);
  6680. if (isString(delay)) {
  6681. callback = easing;
  6682. easing = delay;
  6683. delay = 0;
  6684. }
  6685. // animateTo(target, time, delay, callback);
  6686. else if (isFunction(easing)) {
  6687. callback = easing;
  6688. easing = 'linear';
  6689. delay = 0;
  6690. }
  6691. // animateTo(target, time, callback);
  6692. else if (isFunction(delay)) {
  6693. callback = delay;
  6694. delay = 0;
  6695. }
  6696. // animateTo(target, callback)
  6697. else if (isFunction(time)) {
  6698. callback = time;
  6699. time = 500;
  6700. }
  6701. // animateTo(target)
  6702. else if (!time) {
  6703. time = 500;
  6704. }
  6705. // Stop all previous animations
  6706. this.stopAnimation();
  6707. this._animateToShallow('', this, target, time, delay, easing, callback);
  6708. // Animators may be removed immediately after start
  6709. // if there is nothing to animate
  6710. var animators = this.animators.slice();
  6711. var count = animators.length;
  6712. function done() {
  6713. count--;
  6714. if (!count) {
  6715. callback && callback();
  6716. }
  6717. }
  6718. // No animators. This should be checked before animators[i].start(),
  6719. // because 'done' may be executed immediately if no need to animate.
  6720. if (!count) {
  6721. callback && callback();
  6722. }
  6723. // Start after all animators created
  6724. // Incase any animator is done immediately when all animation properties are not changed
  6725. for (var i = 0; i < animators.length; i++) {
  6726. animators[i]
  6727. .done(done)
  6728. .start(easing);
  6729. }
  6730. },
  6731. /**
  6732. * @private
  6733. * @param {string} path=''
  6734. * @param {Object} source=this
  6735. * @param {Object} target
  6736. * @param {number} [time=500]
  6737. * @param {number} [delay=0]
  6738. *
  6739. * @example
  6740. * // Animate position
  6741. * el._animateToShallow({
  6742. * position: [10, 10]
  6743. * })
  6744. *
  6745. * // Animate shape, style and position in 100ms, delayed 100ms
  6746. * el._animateToShallow({
  6747. * shape: {
  6748. * width: 500
  6749. * },
  6750. * style: {
  6751. * fill: 'red'
  6752. * }
  6753. * position: [10, 10]
  6754. * }, 100, 100)
  6755. */
  6756. _animateToShallow: function (path, source, target, time, delay) {
  6757. var objShallow = {};
  6758. var propertyCount = 0;
  6759. for (var name in target) {
  6760. if (source[name] != null) {
  6761. if (isObject(target[name]) && !util.isArrayLike(target[name])) {
  6762. this._animateToShallow(
  6763. path ? path + '.' + name : name,
  6764. source[name],
  6765. target[name],
  6766. time,
  6767. delay
  6768. );
  6769. }
  6770. else {
  6771. objShallow[name] = target[name];
  6772. propertyCount++;
  6773. }
  6774. }
  6775. else if (target[name] != null) {
  6776. // Attr directly if not has property
  6777. // FIXME, if some property not needed for element ?
  6778. if (!path) {
  6779. this.attr(name, target[name]);
  6780. }
  6781. else { // Shape or style
  6782. var props = {};
  6783. props[path] = {};
  6784. props[path][name] = target[name];
  6785. this.attr(props);
  6786. }
  6787. }
  6788. }
  6789. if (propertyCount > 0) {
  6790. this.animate(path, false)
  6791. .when(time == null ? 500 : time, objShallow)
  6792. .delay(delay || 0);
  6793. }
  6794. return this;
  6795. }
  6796. };
  6797. module.exports = Animatable;
  6798. /***/ },
  6799. /* 35 */
  6800. /***/ function(module, exports, __webpack_require__) {
  6801. /**
  6802. * @module echarts/animation/Animator
  6803. */
  6804. var Clip = __webpack_require__(36);
  6805. var color = __webpack_require__(38);
  6806. var util = __webpack_require__(3);
  6807. var isArrayLike = util.isArrayLike;
  6808. var arraySlice = Array.prototype.slice;
  6809. function defaultGetter(target, key) {
  6810. return target[key];
  6811. }
  6812. function defaultSetter(target, key, value) {
  6813. target[key] = value;
  6814. }
  6815. /**
  6816. * @param {number} p0
  6817. * @param {number} p1
  6818. * @param {number} percent
  6819. * @return {number}
  6820. */
  6821. function interpolateNumber(p0, p1, percent) {
  6822. return (p1 - p0) * percent + p0;
  6823. }
  6824. /**
  6825. * @param {string} p0
  6826. * @param {string} p1
  6827. * @param {number} percent
  6828. * @return {string}
  6829. */
  6830. function interpolateString(p0, p1, percent) {
  6831. return percent > 0.5 ? p1 : p0;
  6832. }
  6833. /**
  6834. * @param {Array} p0
  6835. * @param {Array} p1
  6836. * @param {number} percent
  6837. * @param {Array} out
  6838. * @param {number} arrDim
  6839. */
  6840. function interpolateArray(p0, p1, percent, out, arrDim) {
  6841. var len = p0.length;
  6842. if (arrDim == 1) {
  6843. for (var i = 0; i < len; i++) {
  6844. out[i] = interpolateNumber(p0[i], p1[i], percent);
  6845. }
  6846. }
  6847. else {
  6848. var len2 = p0[0].length;
  6849. for (var i = 0; i < len; i++) {
  6850. for (var j = 0; j < len2; j++) {
  6851. out[i][j] = interpolateNumber(
  6852. p0[i][j], p1[i][j], percent
  6853. );
  6854. }
  6855. }
  6856. }
  6857. }
  6858. // arr0 is source array, arr1 is target array.
  6859. // Do some preprocess to avoid error happened when interpolating from arr0 to arr1
  6860. function fillArr(arr0, arr1, arrDim) {
  6861. var arr0Len = arr0.length;
  6862. var arr1Len = arr1.length;
  6863. if (arr0Len !== arr1Len) {
  6864. // FIXME Not work for TypedArray
  6865. var isPreviousLarger = arr0Len > arr1Len;
  6866. if (isPreviousLarger) {
  6867. // Cut the previous
  6868. arr0.length = arr1Len;
  6869. }
  6870. else {
  6871. // Fill the previous
  6872. for (var i = arr0Len; i < arr1Len; i++) {
  6873. arr0.push(
  6874. arrDim === 1 ? arr1[i] : arraySlice.call(arr1[i])
  6875. );
  6876. }
  6877. }
  6878. }
  6879. // Handling NaN value
  6880. var len2 = arr0[0] && arr0[0].length;
  6881. for (var i = 0; i < arr0.length; i++) {
  6882. if (arrDim === 1) {
  6883. if (isNaN(arr0[i])) {
  6884. arr0[i] = arr1[i];
  6885. }
  6886. }
  6887. else {
  6888. for (var j = 0; j < len2; j++) {
  6889. if (isNaN(arr0[i][j])) {
  6890. arr0[i][j] = arr1[i][j];
  6891. }
  6892. }
  6893. }
  6894. }
  6895. }
  6896. /**
  6897. * @param {Array} arr0
  6898. * @param {Array} arr1
  6899. * @param {number} arrDim
  6900. * @return {boolean}
  6901. */
  6902. function isArraySame(arr0, arr1, arrDim) {
  6903. if (arr0 === arr1) {
  6904. return true;
  6905. }
  6906. var len = arr0.length;
  6907. if (len !== arr1.length) {
  6908. return false;
  6909. }
  6910. if (arrDim === 1) {
  6911. for (var i = 0; i < len; i++) {
  6912. if (arr0[i] !== arr1[i]) {
  6913. return false;
  6914. }
  6915. }
  6916. }
  6917. else {
  6918. var len2 = arr0[0].length;
  6919. for (var i = 0; i < len; i++) {
  6920. for (var j = 0; j < len2; j++) {
  6921. if (arr0[i][j] !== arr1[i][j]) {
  6922. return false;
  6923. }
  6924. }
  6925. }
  6926. }
  6927. return true;
  6928. }
  6929. /**
  6930. * Catmull Rom interpolate array
  6931. * @param {Array} p0
  6932. * @param {Array} p1
  6933. * @param {Array} p2
  6934. * @param {Array} p3
  6935. * @param {number} t
  6936. * @param {number} t2
  6937. * @param {number} t3
  6938. * @param {Array} out
  6939. * @param {number} arrDim
  6940. */
  6941. function catmullRomInterpolateArray(
  6942. p0, p1, p2, p3, t, t2, t3, out, arrDim
  6943. ) {
  6944. var len = p0.length;
  6945. if (arrDim == 1) {
  6946. for (var i = 0; i < len; i++) {
  6947. out[i] = catmullRomInterpolate(
  6948. p0[i], p1[i], p2[i], p3[i], t, t2, t3
  6949. );
  6950. }
  6951. }
  6952. else {
  6953. var len2 = p0[0].length;
  6954. for (var i = 0; i < len; i++) {
  6955. for (var j = 0; j < len2; j++) {
  6956. out[i][j] = catmullRomInterpolate(
  6957. p0[i][j], p1[i][j], p2[i][j], p3[i][j],
  6958. t, t2, t3
  6959. );
  6960. }
  6961. }
  6962. }
  6963. }
  6964. /**
  6965. * Catmull Rom interpolate number
  6966. * @param {number} p0
  6967. * @param {number} p1
  6968. * @param {number} p2
  6969. * @param {number} p3
  6970. * @param {number} t
  6971. * @param {number} t2
  6972. * @param {number} t3
  6973. * @return {number}
  6974. */
  6975. function catmullRomInterpolate(p0, p1, p2, p3, t, t2, t3) {
  6976. var v0 = (p2 - p0) * 0.5;
  6977. var v1 = (p3 - p1) * 0.5;
  6978. return (2 * (p1 - p2) + v0 + v1) * t3
  6979. + (-3 * (p1 - p2) - 2 * v0 - v1) * t2
  6980. + v0 * t + p1;
  6981. }
  6982. function cloneValue(value) {
  6983. if (isArrayLike(value)) {
  6984. var len = value.length;
  6985. if (isArrayLike(value[0])) {
  6986. var ret = [];
  6987. for (var i = 0; i < len; i++) {
  6988. ret.push(arraySlice.call(value[i]));
  6989. }
  6990. return ret;
  6991. }
  6992. return arraySlice.call(value);
  6993. }
  6994. return value;
  6995. }
  6996. function rgba2String(rgba) {
  6997. rgba[0] = Math.floor(rgba[0]);
  6998. rgba[1] = Math.floor(rgba[1]);
  6999. rgba[2] = Math.floor(rgba[2]);
  7000. return 'rgba(' + rgba.join(',') + ')';
  7001. }
  7002. function createTrackClip (animator, easing, oneTrackDone, keyframes, propName) {
  7003. var getter = animator._getter;
  7004. var setter = animator._setter;
  7005. var useSpline = easing === 'spline';
  7006. var trackLen = keyframes.length;
  7007. if (!trackLen) {
  7008. return;
  7009. }
  7010. // Guess data type
  7011. var firstVal = keyframes[0].value;
  7012. var isValueArray = isArrayLike(firstVal);
  7013. var isValueColor = false;
  7014. var isValueString = false;
  7015. // For vertices morphing
  7016. var arrDim = (
  7017. isValueArray
  7018. && isArrayLike(firstVal[0])
  7019. )
  7020. ? 2 : 1;
  7021. var trackMaxTime;
  7022. // Sort keyframe as ascending
  7023. keyframes.sort(function(a, b) {
  7024. return a.time - b.time;
  7025. });
  7026. trackMaxTime = keyframes[trackLen - 1].time;
  7027. // Percents of each keyframe
  7028. var kfPercents = [];
  7029. // Value of each keyframe
  7030. var kfValues = [];
  7031. var prevValue = keyframes[0].value;
  7032. var isAllValueEqual = true;
  7033. for (var i = 0; i < trackLen; i++) {
  7034. kfPercents.push(keyframes[i].time / trackMaxTime);
  7035. // Assume value is a color when it is a string
  7036. var value = keyframes[i].value;
  7037. // Check if value is equal, deep check if value is array
  7038. if (!((isValueArray && isArraySame(value, prevValue, arrDim))
  7039. || (!isValueArray && value === prevValue))) {
  7040. isAllValueEqual = false;
  7041. }
  7042. prevValue = value;
  7043. // Try converting a string to a color array
  7044. if (typeof value == 'string') {
  7045. var colorArray = color.parse(value);
  7046. if (colorArray) {
  7047. value = colorArray;
  7048. isValueColor = true;
  7049. }
  7050. else {
  7051. isValueString = true;
  7052. }
  7053. }
  7054. kfValues.push(value);
  7055. }
  7056. if (isAllValueEqual) {
  7057. return;
  7058. }
  7059. var lastValue = kfValues[trackLen - 1];
  7060. // Polyfill array and NaN value
  7061. for (var i = 0; i < trackLen - 1; i++) {
  7062. if (isValueArray) {
  7063. fillArr(kfValues[i], lastValue, arrDim);
  7064. }
  7065. else {
  7066. if (isNaN(kfValues[i]) && !isNaN(lastValue) && !isValueString && !isValueColor) {
  7067. kfValues[i] = lastValue;
  7068. }
  7069. }
  7070. }
  7071. isValueArray && fillArr(getter(animator._target, propName), lastValue, arrDim);
  7072. // Cache the key of last frame to speed up when
  7073. // animation playback is sequency
  7074. var lastFrame = 0;
  7075. var lastFramePercent = 0;
  7076. var start;
  7077. var w;
  7078. var p0;
  7079. var p1;
  7080. var p2;
  7081. var p3;
  7082. if (isValueColor) {
  7083. var rgba = [0, 0, 0, 0];
  7084. }
  7085. var onframe = function (target, percent) {
  7086. // Find the range keyframes
  7087. // kf1-----kf2---------current--------kf3
  7088. // find kf2 and kf3 and do interpolation
  7089. var frame;
  7090. if (percent < lastFramePercent) {
  7091. // Start from next key
  7092. start = Math.min(lastFrame + 1, trackLen - 1);
  7093. for (frame = start; frame >= 0; frame--) {
  7094. if (kfPercents[frame] <= percent) {
  7095. break;
  7096. }
  7097. }
  7098. frame = Math.min(frame, trackLen - 2);
  7099. }
  7100. else {
  7101. for (frame = lastFrame; frame < trackLen; frame++) {
  7102. if (kfPercents[frame] > percent) {
  7103. break;
  7104. }
  7105. }
  7106. frame = Math.min(frame - 1, trackLen - 2);
  7107. }
  7108. lastFrame = frame;
  7109. lastFramePercent = percent;
  7110. var range = (kfPercents[frame + 1] - kfPercents[frame]);
  7111. if (range === 0) {
  7112. return;
  7113. }
  7114. else {
  7115. w = (percent - kfPercents[frame]) / range;
  7116. }
  7117. if (useSpline) {
  7118. p1 = kfValues[frame];
  7119. p0 = kfValues[frame === 0 ? frame : frame - 1];
  7120. p2 = kfValues[frame > trackLen - 2 ? trackLen - 1 : frame + 1];
  7121. p3 = kfValues[frame > trackLen - 3 ? trackLen - 1 : frame + 2];
  7122. if (isValueArray) {
  7123. catmullRomInterpolateArray(
  7124. p0, p1, p2, p3, w, w * w, w * w * w,
  7125. getter(target, propName),
  7126. arrDim
  7127. );
  7128. }
  7129. else {
  7130. var value;
  7131. if (isValueColor) {
  7132. value = catmullRomInterpolateArray(
  7133. p0, p1, p2, p3, w, w * w, w * w * w,
  7134. rgba, 1
  7135. );
  7136. value = rgba2String(rgba);
  7137. }
  7138. else if (isValueString) {
  7139. // String is step(0.5)
  7140. return interpolateString(p1, p2, w);
  7141. }
  7142. else {
  7143. value = catmullRomInterpolate(
  7144. p0, p1, p2, p3, w, w * w, w * w * w
  7145. );
  7146. }
  7147. setter(
  7148. target,
  7149. propName,
  7150. value
  7151. );
  7152. }
  7153. }
  7154. else {
  7155. if (isValueArray) {
  7156. interpolateArray(
  7157. kfValues[frame], kfValues[frame + 1], w,
  7158. getter(target, propName),
  7159. arrDim
  7160. );
  7161. }
  7162. else {
  7163. var value;
  7164. if (isValueColor) {
  7165. interpolateArray(
  7166. kfValues[frame], kfValues[frame + 1], w,
  7167. rgba, 1
  7168. );
  7169. value = rgba2String(rgba);
  7170. }
  7171. else if (isValueString) {
  7172. // String is step(0.5)
  7173. return interpolateString(kfValues[frame], kfValues[frame + 1], w);
  7174. }
  7175. else {
  7176. value = interpolateNumber(kfValues[frame], kfValues[frame + 1], w);
  7177. }
  7178. setter(
  7179. target,
  7180. propName,
  7181. value
  7182. );
  7183. }
  7184. }
  7185. };
  7186. var clip = new Clip({
  7187. target: animator._target,
  7188. life: trackMaxTime,
  7189. loop: animator._loop,
  7190. delay: animator._delay,
  7191. onframe: onframe,
  7192. ondestroy: oneTrackDone
  7193. });
  7194. if (easing && easing !== 'spline') {
  7195. clip.easing = easing;
  7196. }
  7197. return clip;
  7198. }
  7199. /**
  7200. * @alias module:zrender/animation/Animator
  7201. * @constructor
  7202. * @param {Object} target
  7203. * @param {boolean} loop
  7204. * @param {Function} getter
  7205. * @param {Function} setter
  7206. */
  7207. var Animator = function(target, loop, getter, setter) {
  7208. this._tracks = {};
  7209. this._target = target;
  7210. this._loop = loop || false;
  7211. this._getter = getter || defaultGetter;
  7212. this._setter = setter || defaultSetter;
  7213. this._clipCount = 0;
  7214. this._delay = 0;
  7215. this._doneList = [];
  7216. this._onframeList = [];
  7217. this._clipList = [];
  7218. };
  7219. Animator.prototype = {
  7220. /**
  7221. * 设置动画关键帧
  7222. * @param {number} time 关键帧时间,单位是ms
  7223. * @param {Object} props 关键帧的属性值,key-value表示
  7224. * @return {module:zrender/animation/Animator}
  7225. */
  7226. when: function(time /* ms */, props) {
  7227. var tracks = this._tracks;
  7228. for (var propName in props) {
  7229. if (!tracks[propName]) {
  7230. tracks[propName] = [];
  7231. // Invalid value
  7232. var value = this._getter(this._target, propName);
  7233. if (value == null) {
  7234. // zrLog('Invalid property ' + propName);
  7235. continue;
  7236. }
  7237. // If time is 0
  7238. // Then props is given initialize value
  7239. // Else
  7240. // Initialize value from current prop value
  7241. if (time !== 0) {
  7242. tracks[propName].push({
  7243. time: 0,
  7244. value: cloneValue(value)
  7245. });
  7246. }
  7247. }
  7248. tracks[propName].push({
  7249. time: time,
  7250. value: props[propName]
  7251. });
  7252. }
  7253. return this;
  7254. },
  7255. /**
  7256. * 添加动画每一帧的回调函数
  7257. * @param {Function} callback
  7258. * @return {module:zrender/animation/Animator}
  7259. */
  7260. during: function (callback) {
  7261. this._onframeList.push(callback);
  7262. return this;
  7263. },
  7264. _doneCallback: function () {
  7265. // Clear all tracks
  7266. this._tracks = {};
  7267. // Clear all clips
  7268. this._clipList.length = 0;
  7269. var doneList = this._doneList;
  7270. var len = doneList.length;
  7271. for (var i = 0; i < len; i++) {
  7272. doneList[i].call(this);
  7273. }
  7274. },
  7275. /**
  7276. * 开始执行动画
  7277. * @param {string|Function} easing
  7278. * 动画缓动函数,详见{@link module:zrender/animation/easing}
  7279. * @return {module:zrender/animation/Animator}
  7280. */
  7281. start: function (easing) {
  7282. var self = this;
  7283. var clipCount = 0;
  7284. var oneTrackDone = function() {
  7285. clipCount--;
  7286. if (!clipCount) {
  7287. self._doneCallback();
  7288. }
  7289. };
  7290. var lastClip;
  7291. for (var propName in this._tracks) {
  7292. var clip = createTrackClip(
  7293. this, easing, oneTrackDone,
  7294. this._tracks[propName], propName
  7295. );
  7296. if (clip) {
  7297. this._clipList.push(clip);
  7298. clipCount++;
  7299. // If start after added to animation
  7300. if (this.animation) {
  7301. this.animation.addClip(clip);
  7302. }
  7303. lastClip = clip;
  7304. }
  7305. }
  7306. // Add during callback on the last clip
  7307. if (lastClip) {
  7308. var oldOnFrame = lastClip.onframe;
  7309. lastClip.onframe = function (target, percent) {
  7310. oldOnFrame(target, percent);
  7311. for (var i = 0; i < self._onframeList.length; i++) {
  7312. self._onframeList[i](target, percent);
  7313. }
  7314. };
  7315. }
  7316. if (!clipCount) {
  7317. this._doneCallback();
  7318. }
  7319. return this;
  7320. },
  7321. /**
  7322. * 停止动画
  7323. * @param {boolean} forwardToLast If move to last frame before stop
  7324. */
  7325. stop: function (forwardToLast) {
  7326. var clipList = this._clipList;
  7327. var animation = this.animation;
  7328. for (var i = 0; i < clipList.length; i++) {
  7329. var clip = clipList[i];
  7330. if (forwardToLast) {
  7331. // Move to last frame before stop
  7332. clip.onframe(this._target, 1);
  7333. }
  7334. animation && animation.removeClip(clip);
  7335. }
  7336. clipList.length = 0;
  7337. },
  7338. /**
  7339. * 设置动画延迟开始的时间
  7340. * @param {number} time 单位ms
  7341. * @return {module:zrender/animation/Animator}
  7342. */
  7343. delay: function (time) {
  7344. this._delay = time;
  7345. return this;
  7346. },
  7347. /**
  7348. * 添加动画结束的回调
  7349. * @param {Function} cb
  7350. * @return {module:zrender/animation/Animator}
  7351. */
  7352. done: function(cb) {
  7353. if (cb) {
  7354. this._doneList.push(cb);
  7355. }
  7356. return this;
  7357. },
  7358. /**
  7359. * @return {Array.<module:zrender/animation/Clip>}
  7360. */
  7361. getClips: function () {
  7362. return this._clipList;
  7363. }
  7364. };
  7365. module.exports = Animator;
  7366. /***/ },
  7367. /* 36 */
  7368. /***/ function(module, exports, __webpack_require__) {
  7369. /**
  7370. * 动画主控制器
  7371. * @config target 动画对象,可以是数组,如果是数组的话会批量分发onframe等事件
  7372. * @config life(1000) 动画时长
  7373. * @config delay(0) 动画延迟时间
  7374. * @config loop(true)
  7375. * @config gap(0) 循环的间隔时间
  7376. * @config onframe
  7377. * @config easing(optional)
  7378. * @config ondestroy(optional)
  7379. * @config onrestart(optional)
  7380. *
  7381. * TODO pause
  7382. */
  7383. var easingFuncs = __webpack_require__(37);
  7384. function Clip(options) {
  7385. this._target = options.target;
  7386. // 生命周期
  7387. this._life = options.life || 1000;
  7388. // 延时
  7389. this._delay = options.delay || 0;
  7390. // 开始时间
  7391. // this._startTime = new Date().getTime() + this._delay;// 单位毫秒
  7392. this._initialized = false;
  7393. // 是否循环
  7394. this.loop = options.loop == null ? false : options.loop;
  7395. this.gap = options.gap || 0;
  7396. this.easing = options.easing || 'Linear';
  7397. this.onframe = options.onframe;
  7398. this.ondestroy = options.ondestroy;
  7399. this.onrestart = options.onrestart;
  7400. }
  7401. Clip.prototype = {
  7402. constructor: Clip,
  7403. step: function (time) {
  7404. // Set startTime on first step, or _startTime may has milleseconds different between clips
  7405. // PENDING
  7406. if (!this._initialized) {
  7407. this._startTime = new Date().getTime() + this._delay;
  7408. this._initialized = true;
  7409. }
  7410. var percent = (time - this._startTime) / this._life;
  7411. // 还没开始
  7412. if (percent < 0) {
  7413. return;
  7414. }
  7415. percent = Math.min(percent, 1);
  7416. var easing = this.easing;
  7417. var easingFunc = typeof easing == 'string' ? easingFuncs[easing] : easing;
  7418. var schedule = typeof easingFunc === 'function'
  7419. ? easingFunc(percent)
  7420. : percent;
  7421. this.fire('frame', schedule);
  7422. // 结束
  7423. if (percent == 1) {
  7424. if (this.loop) {
  7425. this.restart();
  7426. // 重新开始周期
  7427. // 抛出而不是直接调用事件直到 stage.update 后再统一调用这些事件
  7428. return 'restart';
  7429. }
  7430. // 动画完成将这个控制器标识为待删除
  7431. // 在Animation.update中进行批量删除
  7432. this._needsRemove = true;
  7433. return 'destroy';
  7434. }
  7435. return null;
  7436. },
  7437. restart: function() {
  7438. var time = new Date().getTime();
  7439. var remainder = (time - this._startTime) % this._life;
  7440. this._startTime = new Date().getTime() - remainder + this.gap;
  7441. this._needsRemove = false;
  7442. },
  7443. fire: function(eventType, arg) {
  7444. eventType = 'on' + eventType;
  7445. if (this[eventType]) {
  7446. this[eventType](this._target, arg);
  7447. }
  7448. }
  7449. };
  7450. module.exports = Clip;
  7451. /***/ },
  7452. /* 37 */
  7453. /***/ function(module, exports) {
  7454. /**
  7455. * 缓动代码来自 https://github.com/sole/tween.js/blob/master/src/Tween.js
  7456. * @see http://sole.github.io/tween.js/examples/03_graphs.html
  7457. * @exports zrender/animation/easing
  7458. */
  7459. var easing = {
  7460. /**
  7461. * @param {number} k
  7462. * @return {number}
  7463. */
  7464. linear: function (k) {
  7465. return k;
  7466. },
  7467. /**
  7468. * @param {number} k
  7469. * @return {number}
  7470. */
  7471. quadraticIn: function (k) {
  7472. return k * k;
  7473. },
  7474. /**
  7475. * @param {number} k
  7476. * @return {number}
  7477. */
  7478. quadraticOut: function (k) {
  7479. return k * (2 - k);
  7480. },
  7481. /**
  7482. * @param {number} k
  7483. * @return {number}
  7484. */
  7485. quadraticInOut: function (k) {
  7486. if ((k *= 2) < 1) {
  7487. return 0.5 * k * k;
  7488. }
  7489. return -0.5 * (--k * (k - 2) - 1);
  7490. },
  7491. // 三次方的缓动(t^3)
  7492. /**
  7493. * @param {number} k
  7494. * @return {number}
  7495. */
  7496. cubicIn: function (k) {
  7497. return k * k * k;
  7498. },
  7499. /**
  7500. * @param {number} k
  7501. * @return {number}
  7502. */
  7503. cubicOut: function (k) {
  7504. return --k * k * k + 1;
  7505. },
  7506. /**
  7507. * @param {number} k
  7508. * @return {number}
  7509. */
  7510. cubicInOut: function (k) {
  7511. if ((k *= 2) < 1) {
  7512. return 0.5 * k * k * k;
  7513. }
  7514. return 0.5 * ((k -= 2) * k * k + 2);
  7515. },
  7516. // 四次方的缓动(t^4)
  7517. /**
  7518. * @param {number} k
  7519. * @return {number}
  7520. */
  7521. quarticIn: function (k) {
  7522. return k * k * k * k;
  7523. },
  7524. /**
  7525. * @param {number} k
  7526. * @return {number}
  7527. */
  7528. quarticOut: function (k) {
  7529. return 1 - (--k * k * k * k);
  7530. },
  7531. /**
  7532. * @param {number} k
  7533. * @return {number}
  7534. */
  7535. quarticInOut: function (k) {
  7536. if ((k *= 2) < 1) {
  7537. return 0.5 * k * k * k * k;
  7538. }
  7539. return -0.5 * ((k -= 2) * k * k * k - 2);
  7540. },
  7541. // 五次方的缓动(t^5)
  7542. /**
  7543. * @param {number} k
  7544. * @return {number}
  7545. */
  7546. quinticIn: function (k) {
  7547. return k * k * k * k * k;
  7548. },
  7549. /**
  7550. * @param {number} k
  7551. * @return {number}
  7552. */
  7553. quinticOut: function (k) {
  7554. return --k * k * k * k * k + 1;
  7555. },
  7556. /**
  7557. * @param {number} k
  7558. * @return {number}
  7559. */
  7560. quinticInOut: function (k) {
  7561. if ((k *= 2) < 1) {
  7562. return 0.5 * k * k * k * k * k;
  7563. }
  7564. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  7565. },
  7566. // 正弦曲线的缓动(sin(t))
  7567. /**
  7568. * @param {number} k
  7569. * @return {number}
  7570. */
  7571. sinusoidalIn: function (k) {
  7572. return 1 - Math.cos(k * Math.PI / 2);
  7573. },
  7574. /**
  7575. * @param {number} k
  7576. * @return {number}
  7577. */
  7578. sinusoidalOut: function (k) {
  7579. return Math.sin(k * Math.PI / 2);
  7580. },
  7581. /**
  7582. * @param {number} k
  7583. * @return {number}
  7584. */
  7585. sinusoidalInOut: function (k) {
  7586. return 0.5 * (1 - Math.cos(Math.PI * k));
  7587. },
  7588. // 指数曲线的缓动(2^t)
  7589. /**
  7590. * @param {number} k
  7591. * @return {number}
  7592. */
  7593. exponentialIn: function (k) {
  7594. return k === 0 ? 0 : Math.pow(1024, k - 1);
  7595. },
  7596. /**
  7597. * @param {number} k
  7598. * @return {number}
  7599. */
  7600. exponentialOut: function (k) {
  7601. return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
  7602. },
  7603. /**
  7604. * @param {number} k
  7605. * @return {number}
  7606. */
  7607. exponentialInOut: function (k) {
  7608. if (k === 0) {
  7609. return 0;
  7610. }
  7611. if (k === 1) {
  7612. return 1;
  7613. }
  7614. if ((k *= 2) < 1) {
  7615. return 0.5 * Math.pow(1024, k - 1);
  7616. }
  7617. return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
  7618. },
  7619. // 圆形曲线的缓动(sqrt(1-t^2))
  7620. /**
  7621. * @param {number} k
  7622. * @return {number}
  7623. */
  7624. circularIn: function (k) {
  7625. return 1 - Math.sqrt(1 - k * k);
  7626. },
  7627. /**
  7628. * @param {number} k
  7629. * @return {number}
  7630. */
  7631. circularOut: function (k) {
  7632. return Math.sqrt(1 - (--k * k));
  7633. },
  7634. /**
  7635. * @param {number} k
  7636. * @return {number}
  7637. */
  7638. circularInOut: function (k) {
  7639. if ((k *= 2) < 1) {
  7640. return -0.5 * (Math.sqrt(1 - k * k) - 1);
  7641. }
  7642. return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
  7643. },
  7644. // 创建类似于弹簧在停止前来回振荡的动画
  7645. /**
  7646. * @param {number} k
  7647. * @return {number}
  7648. */
  7649. elasticIn: function (k) {
  7650. var s;
  7651. var a = 0.1;
  7652. var p = 0.4;
  7653. if (k === 0) {
  7654. return 0;
  7655. }
  7656. if (k === 1) {
  7657. return 1;
  7658. }
  7659. if (!a || a < 1) {
  7660. a = 1; s = p / 4;
  7661. }
  7662. else {
  7663. s = p * Math.asin(1 / a) / (2 * Math.PI);
  7664. }
  7665. return -(a * Math.pow(2, 10 * (k -= 1)) *
  7666. Math.sin((k - s) * (2 * Math.PI) / p));
  7667. },
  7668. /**
  7669. * @param {number} k
  7670. * @return {number}
  7671. */
  7672. elasticOut: function (k) {
  7673. var s;
  7674. var a = 0.1;
  7675. var p = 0.4;
  7676. if (k === 0) {
  7677. return 0;
  7678. }
  7679. if (k === 1) {
  7680. return 1;
  7681. }
  7682. if (!a || a < 1) {
  7683. a = 1; s = p / 4;
  7684. }
  7685. else {
  7686. s = p * Math.asin(1 / a) / (2 * Math.PI);
  7687. }
  7688. return (a * Math.pow(2, -10 * k) *
  7689. Math.sin((k - s) * (2 * Math.PI) / p) + 1);
  7690. },
  7691. /**
  7692. * @param {number} k
  7693. * @return {number}
  7694. */
  7695. elasticInOut: function (k) {
  7696. var s;
  7697. var a = 0.1;
  7698. var p = 0.4;
  7699. if (k === 0) {
  7700. return 0;
  7701. }
  7702. if (k === 1) {
  7703. return 1;
  7704. }
  7705. if (!a || a < 1) {
  7706. a = 1; s = p / 4;
  7707. }
  7708. else {
  7709. s = p * Math.asin(1 / a) / (2 * Math.PI);
  7710. }
  7711. if ((k *= 2) < 1) {
  7712. return -0.5 * (a * Math.pow(2, 10 * (k -= 1))
  7713. * Math.sin((k - s) * (2 * Math.PI) / p));
  7714. }
  7715. return a * Math.pow(2, -10 * (k -= 1))
  7716. * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
  7717. },
  7718. // 在某一动画开始沿指示的路径进行动画处理前稍稍收回该动画的移动
  7719. /**
  7720. * @param {number} k
  7721. * @return {number}
  7722. */
  7723. backIn: function (k) {
  7724. var s = 1.70158;
  7725. return k * k * ((s + 1) * k - s);
  7726. },
  7727. /**
  7728. * @param {number} k
  7729. * @return {number}
  7730. */
  7731. backOut: function (k) {
  7732. var s = 1.70158;
  7733. return --k * k * ((s + 1) * k + s) + 1;
  7734. },
  7735. /**
  7736. * @param {number} k
  7737. * @return {number}
  7738. */
  7739. backInOut: function (k) {
  7740. var s = 1.70158 * 1.525;
  7741. if ((k *= 2) < 1) {
  7742. return 0.5 * (k * k * ((s + 1) * k - s));
  7743. }
  7744. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  7745. },
  7746. // 创建弹跳效果
  7747. /**
  7748. * @param {number} k
  7749. * @return {number}
  7750. */
  7751. bounceIn: function (k) {
  7752. return 1 - easing.bounceOut(1 - k);
  7753. },
  7754. /**
  7755. * @param {number} k
  7756. * @return {number}
  7757. */
  7758. bounceOut: function (k) {
  7759. if (k < (1 / 2.75)) {
  7760. return 7.5625 * k * k;
  7761. }
  7762. else if (k < (2 / 2.75)) {
  7763. return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;
  7764. }
  7765. else if (k < (2.5 / 2.75)) {
  7766. return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;
  7767. }
  7768. else {
  7769. return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;
  7770. }
  7771. },
  7772. /**
  7773. * @param {number} k
  7774. * @return {number}
  7775. */
  7776. bounceInOut: function (k) {
  7777. if (k < 0.5) {
  7778. return easing.bounceIn(k * 2) * 0.5;
  7779. }
  7780. return easing.bounceOut(k * 2 - 1) * 0.5 + 0.5;
  7781. }
  7782. };
  7783. module.exports = easing;
  7784. /***/ },
  7785. /* 38 */
  7786. /***/ function(module, exports) {
  7787. /**
  7788. * @module zrender/tool/color
  7789. */
  7790. var kCSSColorTable = {
  7791. 'transparent': [0,0,0,0], 'aliceblue': [240,248,255,1],
  7792. 'antiquewhite': [250,235,215,1], 'aqua': [0,255,255,1],
  7793. 'aquamarine': [127,255,212,1], 'azure': [240,255,255,1],
  7794. 'beige': [245,245,220,1], 'bisque': [255,228,196,1],
  7795. 'black': [0,0,0,1], 'blanchedalmond': [255,235,205,1],
  7796. 'blue': [0,0,255,1], 'blueviolet': [138,43,226,1],
  7797. 'brown': [165,42,42,1], 'burlywood': [222,184,135,1],
  7798. 'cadetblue': [95,158,160,1], 'chartreuse': [127,255,0,1],
  7799. 'chocolate': [210,105,30,1], 'coral': [255,127,80,1],
  7800. 'cornflowerblue': [100,149,237,1], 'cornsilk': [255,248,220,1],
  7801. 'crimson': [220,20,60,1], 'cyan': [0,255,255,1],
  7802. 'darkblue': [0,0,139,1], 'darkcyan': [0,139,139,1],
  7803. 'darkgoldenrod': [184,134,11,1], 'darkgray': [169,169,169,1],
  7804. 'darkgreen': [0,100,0,1], 'darkgrey': [169,169,169,1],
  7805. 'darkkhaki': [189,183,107,1], 'darkmagenta': [139,0,139,1],
  7806. 'darkolivegreen': [85,107,47,1], 'darkorange': [255,140,0,1],
  7807. 'darkorchid': [153,50,204,1], 'darkred': [139,0,0,1],
  7808. 'darksalmon': [233,150,122,1], 'darkseagreen': [143,188,143,1],
  7809. 'darkslateblue': [72,61,139,1], 'darkslategray': [47,79,79,1],
  7810. 'darkslategrey': [47,79,79,1], 'darkturquoise': [0,206,209,1],
  7811. 'darkviolet': [148,0,211,1], 'deeppink': [255,20,147,1],
  7812. 'deepskyblue': [0,191,255,1], 'dimgray': [105,105,105,1],
  7813. 'dimgrey': [105,105,105,1], 'dodgerblue': [30,144,255,1],
  7814. 'firebrick': [178,34,34,1], 'floralwhite': [255,250,240,1],
  7815. 'forestgreen': [34,139,34,1], 'fuchsia': [255,0,255,1],
  7816. 'gainsboro': [220,220,220,1], 'ghostwhite': [248,248,255,1],
  7817. 'gold': [255,215,0,1], 'goldenrod': [218,165,32,1],
  7818. 'gray': [128,128,128,1], 'green': [0,128,0,1],
  7819. 'greenyellow': [173,255,47,1], 'grey': [128,128,128,1],
  7820. 'honeydew': [240,255,240,1], 'hotpink': [255,105,180,1],
  7821. 'indianred': [205,92,92,1], 'indigo': [75,0,130,1],
  7822. 'ivory': [255,255,240,1], 'khaki': [240,230,140,1],
  7823. 'lavender': [230,230,250,1], 'lavenderblush': [255,240,245,1],
  7824. 'lawngreen': [124,252,0,1], 'lemonchiffon': [255,250,205,1],
  7825. 'lightblue': [173,216,230,1], 'lightcoral': [240,128,128,1],
  7826. 'lightcyan': [224,255,255,1], 'lightgoldenrodyellow': [250,250,210,1],
  7827. 'lightgray': [211,211,211,1], 'lightgreen': [144,238,144,1],
  7828. 'lightgrey': [211,211,211,1], 'lightpink': [255,182,193,1],
  7829. 'lightsalmon': [255,160,122,1], 'lightseagreen': [32,178,170,1],
  7830. 'lightskyblue': [135,206,250,1], 'lightslategray': [119,136,153,1],
  7831. 'lightslategrey': [119,136,153,1], 'lightsteelblue': [176,196,222,1],
  7832. 'lightyellow': [255,255,224,1], 'lime': [0,255,0,1],
  7833. 'limegreen': [50,205,50,1], 'linen': [250,240,230,1],
  7834. 'magenta': [255,0,255,1], 'maroon': [128,0,0,1],
  7835. 'mediumaquamarine': [102,205,170,1], 'mediumblue': [0,0,205,1],
  7836. 'mediumorchid': [186,85,211,1], 'mediumpurple': [147,112,219,1],
  7837. 'mediumseagreen': [60,179,113,1], 'mediumslateblue': [123,104,238,1],
  7838. 'mediumspringgreen': [0,250,154,1], 'mediumturquoise': [72,209,204,1],
  7839. 'mediumvioletred': [199,21,133,1], 'midnightblue': [25,25,112,1],
  7840. 'mintcream': [245,255,250,1], 'mistyrose': [255,228,225,1],
  7841. 'moccasin': [255,228,181,1], 'navajowhite': [255,222,173,1],
  7842. 'navy': [0,0,128,1], 'oldlace': [253,245,230,1],
  7843. 'olive': [128,128,0,1], 'olivedrab': [107,142,35,1],
  7844. 'orange': [255,165,0,1], 'orangered': [255,69,0,1],
  7845. 'orchid': [218,112,214,1], 'palegoldenrod': [238,232,170,1],
  7846. 'palegreen': [152,251,152,1], 'paleturquoise': [175,238,238,1],
  7847. 'palevioletred': [219,112,147,1], 'papayawhip': [255,239,213,1],
  7848. 'peachpuff': [255,218,185,1], 'peru': [205,133,63,1],
  7849. 'pink': [255,192,203,1], 'plum': [221,160,221,1],
  7850. 'powderblue': [176,224,230,1], 'purple': [128,0,128,1],
  7851. 'red': [255,0,0,1], 'rosybrown': [188,143,143,1],
  7852. 'royalblue': [65,105,225,1], 'saddlebrown': [139,69,19,1],
  7853. 'salmon': [250,128,114,1], 'sandybrown': [244,164,96,1],
  7854. 'seagreen': [46,139,87,1], 'seashell': [255,245,238,1],
  7855. 'sienna': [160,82,45,1], 'silver': [192,192,192,1],
  7856. 'skyblue': [135,206,235,1], 'slateblue': [106,90,205,1],
  7857. 'slategray': [112,128,144,1], 'slategrey': [112,128,144,1],
  7858. 'snow': [255,250,250,1], 'springgreen': [0,255,127,1],
  7859. 'steelblue': [70,130,180,1], 'tan': [210,180,140,1],
  7860. 'teal': [0,128,128,1], 'thistle': [216,191,216,1],
  7861. 'tomato': [255,99,71,1], 'turquoise': [64,224,208,1],
  7862. 'violet': [238,130,238,1], 'wheat': [245,222,179,1],
  7863. 'white': [255,255,255,1], 'whitesmoke': [245,245,245,1],
  7864. 'yellow': [255,255,0,1], 'yellowgreen': [154,205,50,1]
  7865. };
  7866. function clampCssByte(i) { // Clamp to integer 0 .. 255.
  7867. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  7868. return i < 0 ? 0 : i > 255 ? 255 : i;
  7869. }
  7870. function clampCssAngle(i) { // Clamp to integer 0 .. 360.
  7871. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  7872. return i < 0 ? 0 : i > 360 ? 360 : i;
  7873. }
  7874. function clampCssFloat(f) { // Clamp to float 0.0 .. 1.0.
  7875. return f < 0 ? 0 : f > 1 ? 1 : f;
  7876. }
  7877. function parseCssInt(str) { // int or percentage.
  7878. if (str.length && str.charAt(str.length - 1) === '%') {
  7879. return clampCssByte(parseFloat(str) / 100 * 255);
  7880. }
  7881. return clampCssByte(parseInt(str, 10));
  7882. }
  7883. function parseCssFloat(str) { // float or percentage.
  7884. if (str.length && str.charAt(str.length - 1) === '%') {
  7885. return clampCssFloat(parseFloat(str) / 100);
  7886. }
  7887. return clampCssFloat(parseFloat(str));
  7888. }
  7889. function cssHueToRgb(m1, m2, h) {
  7890. if (h < 0) {
  7891. h += 1;
  7892. }
  7893. else if (h > 1) {
  7894. h -= 1;
  7895. }
  7896. if (h * 6 < 1) {
  7897. return m1 + (m2 - m1) * h * 6;
  7898. }
  7899. if (h * 2 < 1) {
  7900. return m2;
  7901. }
  7902. if (h * 3 < 2) {
  7903. return m1 + (m2 - m1) * (2/3 - h) * 6;
  7904. }
  7905. return m1;
  7906. }
  7907. function lerp(a, b, p) {
  7908. return a + (b - a) * p;
  7909. }
  7910. /**
  7911. * @param {string} colorStr
  7912. * @return {Array.<number>}
  7913. * @memberOf module:zrender/util/color
  7914. */
  7915. function parse(colorStr) {
  7916. if (!colorStr) {
  7917. return;
  7918. }
  7919. // colorStr may be not string
  7920. colorStr = colorStr + '';
  7921. // Remove all whitespace, not compliant, but should just be more accepting.
  7922. var str = colorStr.replace(/ /g, '').toLowerCase();
  7923. // Color keywords (and transparent) lookup.
  7924. if (str in kCSSColorTable) {
  7925. return kCSSColorTable[str].slice(); // dup.
  7926. }
  7927. // #abc and #abc123 syntax.
  7928. if (str.charAt(0) === '#') {
  7929. if (str.length === 4) {
  7930. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  7931. if (!(iv >= 0 && iv <= 0xfff)) {
  7932. return; // Covers NaN.
  7933. }
  7934. return [
  7935. ((iv & 0xf00) >> 4) | ((iv & 0xf00) >> 8),
  7936. (iv & 0xf0) | ((iv & 0xf0) >> 4),
  7937. (iv & 0xf) | ((iv & 0xf) << 4),
  7938. 1
  7939. ];
  7940. }
  7941. else if (str.length === 7) {
  7942. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  7943. if (!(iv >= 0 && iv <= 0xffffff)) {
  7944. return; // Covers NaN.
  7945. }
  7946. return [
  7947. (iv & 0xff0000) >> 16,
  7948. (iv & 0xff00) >> 8,
  7949. iv & 0xff,
  7950. 1
  7951. ];
  7952. }
  7953. return;
  7954. }
  7955. var op = str.indexOf('('), ep = str.indexOf(')');
  7956. if (op !== -1 && ep + 1 === str.length) {
  7957. var fname = str.substr(0, op);
  7958. var params = str.substr(op + 1, ep - (op + 1)).split(',');
  7959. var alpha = 1; // To allow case fallthrough.
  7960. switch (fname) {
  7961. case 'rgba':
  7962. if (params.length !== 4) {
  7963. return;
  7964. }
  7965. alpha = parseCssFloat(params.pop()); // jshint ignore:line
  7966. // Fall through.
  7967. case 'rgb':
  7968. if (params.length !== 3) {
  7969. return;
  7970. }
  7971. return [
  7972. parseCssInt(params[0]),
  7973. parseCssInt(params[1]),
  7974. parseCssInt(params[2]),
  7975. alpha
  7976. ];
  7977. case 'hsla':
  7978. if (params.length !== 4) {
  7979. return;
  7980. }
  7981. params[3] = parseCssFloat(params[3]);
  7982. return hsla2rgba(params);
  7983. case 'hsl':
  7984. if (params.length !== 3) {
  7985. return;
  7986. }
  7987. return hsla2rgba(params);
  7988. default:
  7989. return;
  7990. }
  7991. }
  7992. return;
  7993. }
  7994. /**
  7995. * @param {Array.<number>} hsla
  7996. * @return {Array.<number>} rgba
  7997. */
  7998. function hsla2rgba(hsla) {
  7999. var h = (((parseFloat(hsla[0]) % 360) + 360) % 360) / 360; // 0 .. 1
  8000. // NOTE(deanm): According to the CSS spec s/l should only be
  8001. // percentages, but we don't bother and let float or percentage.
  8002. var s = parseCssFloat(hsla[1]);
  8003. var l = parseCssFloat(hsla[2]);
  8004. var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  8005. var m1 = l * 2 - m2;
  8006. var rgba = [
  8007. clampCssByte(cssHueToRgb(m1, m2, h + 1 / 3) * 255),
  8008. clampCssByte(cssHueToRgb(m1, m2, h) * 255),
  8009. clampCssByte(cssHueToRgb(m1, m2, h - 1 / 3) * 255)
  8010. ];
  8011. if (hsla.length === 4) {
  8012. rgba[3] = hsla[3];
  8013. }
  8014. return rgba;
  8015. }
  8016. /**
  8017. * @param {Array.<number>} rgba
  8018. * @return {Array.<number>} hsla
  8019. */
  8020. function rgba2hsla(rgba) {
  8021. if (!rgba) {
  8022. return;
  8023. }
  8024. // RGB from 0 to 255
  8025. var R = rgba[0] / 255;
  8026. var G = rgba[1] / 255;
  8027. var B = rgba[2] / 255;
  8028. var vMin = Math.min(R, G, B); // Min. value of RGB
  8029. var vMax = Math.max(R, G, B); // Max. value of RGB
  8030. var delta = vMax - vMin; // Delta RGB value
  8031. var L = (vMax + vMin) / 2;
  8032. var H;
  8033. var S;
  8034. // HSL results from 0 to 1
  8035. if (delta === 0) {
  8036. H = 0;
  8037. S = 0;
  8038. }
  8039. else {
  8040. if (L < 0.5) {
  8041. S = delta / (vMax + vMin);
  8042. }
  8043. else {
  8044. S = delta / (2 - vMax - vMin);
  8045. }
  8046. var deltaR = (((vMax - R) / 6) + (delta / 2)) / delta;
  8047. var deltaG = (((vMax - G) / 6) + (delta / 2)) / delta;
  8048. var deltaB = (((vMax - B) / 6) + (delta / 2)) / delta;
  8049. if (R === vMax) {
  8050. H = deltaB - deltaG;
  8051. }
  8052. else if (G === vMax) {
  8053. H = (1 / 3) + deltaR - deltaB;
  8054. }
  8055. else if (B === vMax) {
  8056. H = (2 / 3) + deltaG - deltaR;
  8057. }
  8058. if (H < 0) {
  8059. H += 1;
  8060. }
  8061. if (H > 1) {
  8062. H -= 1;
  8063. }
  8064. }
  8065. var hsla = [H * 360, S, L];
  8066. if (rgba[3] != null) {
  8067. hsla.push(rgba[3]);
  8068. }
  8069. return hsla;
  8070. }
  8071. /**
  8072. * @param {string} color
  8073. * @param {number} level
  8074. * @return {string}
  8075. * @memberOf module:zrender/util/color
  8076. */
  8077. function lift(color, level) {
  8078. var colorArr = parse(color);
  8079. if (colorArr) {
  8080. for (var i = 0; i < 3; i++) {
  8081. if (level < 0) {
  8082. colorArr[i] = colorArr[i] * (1 - level) | 0;
  8083. }
  8084. else {
  8085. colorArr[i] = ((255 - colorArr[i]) * level + colorArr[i]) | 0;
  8086. }
  8087. }
  8088. return stringify(colorArr, colorArr.length === 4 ? 'rgba' : 'rgb');
  8089. }
  8090. }
  8091. /**
  8092. * @param {string} color
  8093. * @return {string}
  8094. * @memberOf module:zrender/util/color
  8095. */
  8096. function toHex(color, level) {
  8097. var colorArr = parse(color);
  8098. if (colorArr) {
  8099. return ((1 << 24) + (colorArr[0] << 16) + (colorArr[1] << 8) + (+colorArr[2])).toString(16).slice(1);
  8100. }
  8101. }
  8102. /**
  8103. * Map value to color. Faster than mapToColor methods because color is represented by rgba array
  8104. * @param {number} normalizedValue A float between 0 and 1.
  8105. * @param {Array.<Array.<number>>} colors List of rgba color array
  8106. * @param {Array.<number>} [out] Mapped gba color array
  8107. * @return {Array.<number>}
  8108. */
  8109. function fastMapToColor(normalizedValue, colors, out) {
  8110. if (!(colors && colors.length)
  8111. || !(normalizedValue >= 0 && normalizedValue <= 1)
  8112. ) {
  8113. return;
  8114. }
  8115. out = out || [0, 0, 0, 0];
  8116. var value = normalizedValue * (colors.length - 1);
  8117. var leftIndex = Math.floor(value);
  8118. var rightIndex = Math.ceil(value);
  8119. var leftColor = colors[leftIndex];
  8120. var rightColor = colors[rightIndex];
  8121. var dv = value - leftIndex;
  8122. out[0] = clampCssByte(lerp(leftColor[0], rightColor[0], dv));
  8123. out[1] = clampCssByte(lerp(leftColor[1], rightColor[1], dv));
  8124. out[2] = clampCssByte(lerp(leftColor[2], rightColor[2], dv));
  8125. out[3] = clampCssByte(lerp(leftColor[3], rightColor[3], dv));
  8126. return out;
  8127. }
  8128. /**
  8129. * @param {number} normalizedValue A float between 0 and 1.
  8130. * @param {Array.<string>} colors Color list.
  8131. * @param {boolean=} fullOutput Default false.
  8132. * @return {(string|Object)} Result color. If fullOutput,
  8133. * return {color: ..., leftIndex: ..., rightIndex: ..., value: ...},
  8134. * @memberOf module:zrender/util/color
  8135. */
  8136. function mapToColor(normalizedValue, colors, fullOutput) {
  8137. if (!(colors && colors.length)
  8138. || !(normalizedValue >= 0 && normalizedValue <= 1)
  8139. ) {
  8140. return;
  8141. }
  8142. var value = normalizedValue * (colors.length - 1);
  8143. var leftIndex = Math.floor(value);
  8144. var rightIndex = Math.ceil(value);
  8145. var leftColor = parse(colors[leftIndex]);
  8146. var rightColor = parse(colors[rightIndex]);
  8147. var dv = value - leftIndex;
  8148. var color = stringify(
  8149. [
  8150. clampCssByte(lerp(leftColor[0], rightColor[0], dv)),
  8151. clampCssByte(lerp(leftColor[1], rightColor[1], dv)),
  8152. clampCssByte(lerp(leftColor[2], rightColor[2], dv)),
  8153. clampCssFloat(lerp(leftColor[3], rightColor[3], dv))
  8154. ],
  8155. 'rgba'
  8156. );
  8157. return fullOutput
  8158. ? {
  8159. color: color,
  8160. leftIndex: leftIndex,
  8161. rightIndex: rightIndex,
  8162. value: value
  8163. }
  8164. : color;
  8165. }
  8166. /**
  8167. * @param {string} color
  8168. * @param {number=} h 0 ~ 360, ignore when null.
  8169. * @param {number=} s 0 ~ 1, ignore when null.
  8170. * @param {number=} l 0 ~ 1, ignore when null.
  8171. * @return {string} Color string in rgba format.
  8172. * @memberOf module:zrender/util/color
  8173. */
  8174. function modifyHSL(color, h, s, l) {
  8175. color = parse(color);
  8176. if (color) {
  8177. color = rgba2hsla(color);
  8178. h != null && (color[0] = clampCssAngle(h));
  8179. s != null && (color[1] = parseCssFloat(s));
  8180. l != null && (color[2] = parseCssFloat(l));
  8181. return stringify(hsla2rgba(color), 'rgba');
  8182. }
  8183. }
  8184. /**
  8185. * @param {string} color
  8186. * @param {number=} alpha 0 ~ 1
  8187. * @return {string} Color string in rgba format.
  8188. * @memberOf module:zrender/util/color
  8189. */
  8190. function modifyAlpha(color, alpha) {
  8191. color = parse(color);
  8192. if (color && alpha != null) {
  8193. color[3] = clampCssFloat(alpha);
  8194. return stringify(color, 'rgba');
  8195. }
  8196. }
  8197. /**
  8198. * @param {Array.<string>} colors Color list.
  8199. * @param {string} type 'rgba', 'hsva', ...
  8200. * @return {string} Result color.
  8201. */
  8202. function stringify(arrColor, type) {
  8203. if (type === 'rgb' || type === 'hsv' || type === 'hsl') {
  8204. arrColor = arrColor.slice(0, 3);
  8205. }
  8206. return type + '(' + arrColor.join(',') + ')';
  8207. }
  8208. module.exports = {
  8209. parse: parse,
  8210. lift: lift,
  8211. toHex: toHex,
  8212. fastMapToColor: fastMapToColor,
  8213. mapToColor: mapToColor,
  8214. modifyHSL: modifyHSL,
  8215. modifyAlpha: modifyAlpha,
  8216. stringify: stringify
  8217. };
  8218. /***/ },
  8219. /* 39 */
  8220. /***/ function(module, exports, __webpack_require__) {
  8221. var config = __webpack_require__(40);
  8222. /**
  8223. * @exports zrender/tool/log
  8224. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  8225. */
  8226. module.exports = function() {
  8227. if (config.debugMode === 0) {
  8228. return;
  8229. }
  8230. else if (config.debugMode == 1) {
  8231. for (var k in arguments) {
  8232. throw new Error(arguments[k]);
  8233. }
  8234. }
  8235. else if (config.debugMode > 1) {
  8236. for (var k in arguments) {
  8237. console.log(arguments[k]);
  8238. }
  8239. }
  8240. };
  8241. /* for debug
  8242. return function(mes) {
  8243. document.getElementById('wrong-message').innerHTML =
  8244. mes + ' ' + (new Date() - 0)
  8245. + '<br/>'
  8246. + document.getElementById('wrong-message').innerHTML;
  8247. };
  8248. */
  8249. /***/ },
  8250. /* 40 */
  8251. /***/ function(module, exports) {
  8252. var dpr = 1;
  8253. // If in browser environment
  8254. if (typeof window !== 'undefined') {
  8255. dpr = Math.max(window.devicePixelRatio || 1, 1);
  8256. }
  8257. /**
  8258. * config默认配置项
  8259. * @exports zrender/config
  8260. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  8261. */
  8262. var config = {
  8263. /**
  8264. * debug日志选项:catchBrushException为true下有效
  8265. * 0 : 不生成debug数据,发布用
  8266. * 1 : 异常抛出,调试用
  8267. * 2 : 控制台输出,调试用
  8268. */
  8269. debugMode: 0,
  8270. // retina 屏幕优化
  8271. devicePixelRatio: dpr
  8272. };
  8273. module.exports = config;
  8274. /***/ },
  8275. /* 41 */
  8276. /***/ function(module, exports, __webpack_require__) {
  8277. var Group = __webpack_require__(29);
  8278. var componentUtil = __webpack_require__(20);
  8279. var clazzUtil = __webpack_require__(9);
  8280. function Chart() {
  8281. /**
  8282. * @type {module:zrender/container/Group}
  8283. * @readOnly
  8284. */
  8285. this.group = new Group();
  8286. /**
  8287. * @type {string}
  8288. * @readOnly
  8289. */
  8290. this.uid = componentUtil.getUID('viewChart');
  8291. }
  8292. Chart.prototype = {
  8293. type: 'chart',
  8294. /**
  8295. * Init the chart
  8296. * @param {module:echarts/model/Global} ecModel
  8297. * @param {module:echarts/ExtensionAPI} api
  8298. */
  8299. init: function (ecModel, api) {},
  8300. /**
  8301. * Render the chart
  8302. * @param {module:echarts/model/Series} seriesModel
  8303. * @param {module:echarts/model/Global} ecModel
  8304. * @param {module:echarts/ExtensionAPI} api
  8305. * @param {Object} payload
  8306. */
  8307. render: function (seriesModel, ecModel, api, payload) {},
  8308. /**
  8309. * Highlight series or specified data item
  8310. * @param {module:echarts/model/Series} seriesModel
  8311. * @param {module:echarts/model/Global} ecModel
  8312. * @param {module:echarts/ExtensionAPI} api
  8313. * @param {Object} payload
  8314. */
  8315. highlight: function (seriesModel, ecModel, api, payload) {
  8316. toggleHighlight(seriesModel.getData(), payload, 'emphasis');
  8317. },
  8318. /**
  8319. * Downplay series or specified data item
  8320. * @param {module:echarts/model/Series} seriesModel
  8321. * @param {module:echarts/model/Global} ecModel
  8322. * @param {module:echarts/ExtensionAPI} api
  8323. * @param {Object} payload
  8324. */
  8325. downplay: function (seriesModel, ecModel, api, payload) {
  8326. toggleHighlight(seriesModel.getData(), payload, 'normal');
  8327. },
  8328. /**
  8329. * Remove self
  8330. * @param {module:echarts/model/Global} ecModel
  8331. * @param {module:echarts/ExtensionAPI} api
  8332. */
  8333. remove: function (ecModel, api) {
  8334. this.group.removeAll();
  8335. },
  8336. /**
  8337. * Dispose self
  8338. * @param {module:echarts/model/Global} ecModel
  8339. * @param {module:echarts/ExtensionAPI} api
  8340. */
  8341. dispose: function () {}
  8342. };
  8343. var chartProto = Chart.prototype;
  8344. chartProto.updateView
  8345. = chartProto.updateLayout
  8346. = chartProto.updateVisual
  8347. = function (seriesModel, ecModel, api, payload) {
  8348. this.render(seriesModel, ecModel, api, payload);
  8349. };
  8350. /**
  8351. * Set state of single element
  8352. * @param {module:zrender/Element} el
  8353. * @param {string} state
  8354. */
  8355. function elSetState(el, state) {
  8356. if (el) {
  8357. el.trigger(state);
  8358. if (el.type === 'group') {
  8359. for (var i = 0; i < el.childCount(); i++) {
  8360. elSetState(el.childAt(i), state);
  8361. }
  8362. }
  8363. }
  8364. }
  8365. /**
  8366. * @param {module:echarts/data/List} data
  8367. * @param {Object} payload
  8368. * @param {string} state 'normal'|'emphasis'
  8369. * @inner
  8370. */
  8371. function toggleHighlight(data, payload, state) {
  8372. if (payload.dataIndex != null) {
  8373. var el = data.getItemGraphicEl(payload.dataIndex);
  8374. elSetState(el, state);
  8375. }
  8376. else if (payload.name) {
  8377. var dataIndex = data.indexOfName(payload.name);
  8378. var el = data.getItemGraphicEl(dataIndex);
  8379. elSetState(el, state);
  8380. }
  8381. else {
  8382. data.eachItemGraphicEl(function (el) {
  8383. elSetState(el, state);
  8384. });
  8385. }
  8386. }
  8387. // Enable Chart.extend.
  8388. clazzUtil.enableClassExtend(Chart);
  8389. // Add capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  8390. clazzUtil.enableClassManagement(Chart, {registerWhenExtend: true});
  8391. module.exports = Chart;
  8392. /***/ },
  8393. /* 42 */
  8394. /***/ function(module, exports, __webpack_require__) {
  8395. 'use strict';
  8396. var zrUtil = __webpack_require__(3);
  8397. var pathTool = __webpack_require__(43);
  8398. var round = Math.round;
  8399. var Path = __webpack_require__(44);
  8400. var colorTool = __webpack_require__(38);
  8401. var matrix = __webpack_require__(17);
  8402. var vector = __webpack_require__(16);
  8403. var Gradient = __webpack_require__(4);
  8404. var graphic = {};
  8405. graphic.Group = __webpack_require__(29);
  8406. graphic.Image = __webpack_require__(59);
  8407. graphic.Text = __webpack_require__(62);
  8408. graphic.Circle = __webpack_require__(63);
  8409. graphic.Sector = __webpack_require__(64);
  8410. graphic.Ring = __webpack_require__(65);
  8411. graphic.Polygon = __webpack_require__(66);
  8412. graphic.Polyline = __webpack_require__(70);
  8413. graphic.Rect = __webpack_require__(71);
  8414. graphic.Line = __webpack_require__(72);
  8415. graphic.BezierCurve = __webpack_require__(73);
  8416. graphic.Arc = __webpack_require__(74);
  8417. graphic.CompoundPath = __webpack_require__(75);
  8418. graphic.LinearGradient = __webpack_require__(76);
  8419. graphic.RadialGradient = __webpack_require__(77);
  8420. graphic.BoundingRect = __webpack_require__(15);
  8421. /**
  8422. * Extend shape with parameters
  8423. */
  8424. graphic.extendShape = function (opts) {
  8425. return Path.extend(opts);
  8426. };
  8427. /**
  8428. * Extend path
  8429. */
  8430. graphic.extendPath = function (pathData, opts) {
  8431. return pathTool.extendFromString(pathData, opts);
  8432. };
  8433. /**
  8434. * Create a path element from path data string
  8435. * @param {string} pathData
  8436. * @param {Object} opts
  8437. * @param {module:zrender/core/BoundingRect} rect
  8438. * @param {string} [layout=cover] 'center' or 'cover'
  8439. */
  8440. graphic.makePath = function (pathData, opts, rect, layout) {
  8441. var path = pathTool.createFromString(pathData, opts);
  8442. var boundingRect = path.getBoundingRect();
  8443. if (rect) {
  8444. var aspect = boundingRect.width / boundingRect.height;
  8445. if (layout === 'center') {
  8446. // Set rect to center, keep width / height ratio.
  8447. var width = rect.height * aspect;
  8448. var height;
  8449. if (width <= rect.width) {
  8450. height = rect.height;
  8451. }
  8452. else {
  8453. width = rect.width;
  8454. height = width / aspect;
  8455. }
  8456. var cx = rect.x + rect.width / 2;
  8457. var cy = rect.y + rect.height / 2;
  8458. rect.x = cx - width / 2;
  8459. rect.y = cy - height / 2;
  8460. rect.width = width;
  8461. rect.height = height;
  8462. }
  8463. this.resizePath(path, rect);
  8464. }
  8465. return path;
  8466. };
  8467. graphic.mergePath = pathTool.mergePath,
  8468. /**
  8469. * Resize a path to fit the rect
  8470. * @param {module:zrender/graphic/Path} path
  8471. * @param {Object} rect
  8472. */
  8473. graphic.resizePath = function (path, rect) {
  8474. if (!path.applyTransform) {
  8475. return;
  8476. }
  8477. var pathRect = path.getBoundingRect();
  8478. var m = pathRect.calculateTransform(rect);
  8479. path.applyTransform(m);
  8480. };
  8481. /**
  8482. * Sub pixel optimize line for canvas
  8483. *
  8484. * @param {Object} param
  8485. * @param {Object} [param.shape]
  8486. * @param {number} [param.shape.x1]
  8487. * @param {number} [param.shape.y1]
  8488. * @param {number} [param.shape.x2]
  8489. * @param {number} [param.shape.y2]
  8490. * @param {Object} [param.style]
  8491. * @param {number} [param.style.lineWidth]
  8492. * @return {Object} Modified param
  8493. */
  8494. graphic.subPixelOptimizeLine = function (param) {
  8495. var subPixelOptimize = graphic.subPixelOptimize;
  8496. var shape = param.shape;
  8497. var lineWidth = param.style.lineWidth;
  8498. if (round(shape.x1 * 2) === round(shape.x2 * 2)) {
  8499. shape.x1 = shape.x2 = subPixelOptimize(shape.x1, lineWidth, true);
  8500. }
  8501. if (round(shape.y1 * 2) === round(shape.y2 * 2)) {
  8502. shape.y1 = shape.y2 = subPixelOptimize(shape.y1, lineWidth, true);
  8503. }
  8504. return param;
  8505. };
  8506. /**
  8507. * Sub pixel optimize rect for canvas
  8508. *
  8509. * @param {Object} param
  8510. * @param {Object} [param.shape]
  8511. * @param {number} [param.shape.x]
  8512. * @param {number} [param.shape.y]
  8513. * @param {number} [param.shape.width]
  8514. * @param {number} [param.shape.height]
  8515. * @param {Object} [param.style]
  8516. * @param {number} [param.style.lineWidth]
  8517. * @return {Object} Modified param
  8518. */
  8519. graphic.subPixelOptimizeRect = function (param) {
  8520. var subPixelOptimize = graphic.subPixelOptimize;
  8521. var shape = param.shape;
  8522. var lineWidth = param.style.lineWidth;
  8523. var originX = shape.x;
  8524. var originY = shape.y;
  8525. var originWidth = shape.width;
  8526. var originHeight = shape.height;
  8527. shape.x = subPixelOptimize(shape.x, lineWidth, true);
  8528. shape.y = subPixelOptimize(shape.y, lineWidth, true);
  8529. shape.width = Math.max(
  8530. subPixelOptimize(originX + originWidth, lineWidth, false) - shape.x,
  8531. originWidth === 0 ? 0 : 1
  8532. );
  8533. shape.height = Math.max(
  8534. subPixelOptimize(originY + originHeight, lineWidth, false) - shape.y,
  8535. originHeight === 0 ? 0 : 1
  8536. );
  8537. return param;
  8538. };
  8539. /**
  8540. * Sub pixel optimize for canvas
  8541. *
  8542. * @param {number} position Coordinate, such as x, y
  8543. * @param {number} lineWidth Should be nonnegative integer.
  8544. * @param {boolean=} positiveOrNegative Default false (negative).
  8545. * @return {number} Optimized position.
  8546. */
  8547. graphic.subPixelOptimize = function (position, lineWidth, positiveOrNegative) {
  8548. // Assure that (position + lineWidth / 2) is near integer edge,
  8549. // otherwise line will be fuzzy in canvas.
  8550. var doubledPosition = round(position * 2);
  8551. return (doubledPosition + round(lineWidth)) % 2 === 0
  8552. ? doubledPosition / 2
  8553. : (doubledPosition + (positiveOrNegative ? 1 : -1)) / 2;
  8554. };
  8555. function hasFillOrStroke(fillOrStroke) {
  8556. return fillOrStroke != null && fillOrStroke != 'none';
  8557. }
  8558. function liftColor(color) {
  8559. return color instanceof Gradient ? color : colorTool.lift(color, -0.1);
  8560. }
  8561. /**
  8562. * @private
  8563. */
  8564. function cacheElementStl(el) {
  8565. if (el.__hoverStlDirty) {
  8566. var stroke = el.style.stroke;
  8567. var fill = el.style.fill;
  8568. // Create hoverStyle on mouseover
  8569. var hoverStyle = el.__hoverStl;
  8570. hoverStyle.fill = hoverStyle.fill
  8571. || (hasFillOrStroke(fill) ? liftColor(fill) : null);
  8572. hoverStyle.stroke = hoverStyle.stroke
  8573. || (hasFillOrStroke(stroke) ? liftColor(stroke) : null);
  8574. var normalStyle = {};
  8575. for (var name in hoverStyle) {
  8576. if (hoverStyle.hasOwnProperty(name)) {
  8577. normalStyle[name] = el.style[name];
  8578. }
  8579. }
  8580. el.__normalStl = normalStyle;
  8581. el.__hoverStlDirty = false;
  8582. }
  8583. }
  8584. /**
  8585. * @private
  8586. */
  8587. function doSingleEnterHover(el) {
  8588. if (el.__isHover) {
  8589. return;
  8590. }
  8591. cacheElementStl(el);
  8592. el.setStyle(el.__hoverStl);
  8593. el.z2 += 1;
  8594. el.__isHover = true;
  8595. }
  8596. /**
  8597. * @inner
  8598. */
  8599. function doSingleLeaveHover(el) {
  8600. if (!el.__isHover) {
  8601. return;
  8602. }
  8603. var normalStl = el.__normalStl;
  8604. normalStl && el.setStyle(normalStl);
  8605. el.z2 -= 1;
  8606. el.__isHover = false;
  8607. }
  8608. /**
  8609. * @inner
  8610. */
  8611. function doEnterHover(el) {
  8612. el.type === 'group'
  8613. ? el.traverse(function (child) {
  8614. if (child.type !== 'group') {
  8615. doSingleEnterHover(child);
  8616. }
  8617. })
  8618. : doSingleEnterHover(el);
  8619. }
  8620. function doLeaveHover(el) {
  8621. el.type === 'group'
  8622. ? el.traverse(function (child) {
  8623. if (child.type !== 'group') {
  8624. doSingleLeaveHover(child);
  8625. }
  8626. })
  8627. : doSingleLeaveHover(el);
  8628. }
  8629. /**
  8630. * @inner
  8631. */
  8632. function setElementHoverStl(el, hoverStl) {
  8633. // If element has sepcified hoverStyle, then use it instead of given hoverStyle
  8634. // Often used when item group has a label element and it's hoverStyle is different
  8635. el.__hoverStl = el.hoverStyle || hoverStl || {};
  8636. el.__hoverStlDirty = true;
  8637. if (el.__isHover) {
  8638. cacheElementStl(el);
  8639. }
  8640. }
  8641. /**
  8642. * @inner
  8643. */
  8644. function onElementMouseOver() {
  8645. // Only if element is not in emphasis status
  8646. !this.__isEmphasis && doEnterHover(this);
  8647. }
  8648. /**
  8649. * @inner
  8650. */
  8651. function onElementMouseOut() {
  8652. // Only if element is not in emphasis status
  8653. !this.__isEmphasis && doLeaveHover(this);
  8654. }
  8655. /**
  8656. * @inner
  8657. */
  8658. function enterEmphasis() {
  8659. this.__isEmphasis = true;
  8660. doEnterHover(this);
  8661. }
  8662. /**
  8663. * @inner
  8664. */
  8665. function leaveEmphasis() {
  8666. this.__isEmphasis = false;
  8667. doLeaveHover(this);
  8668. }
  8669. /**
  8670. * Set hover style of element
  8671. * @param {module:zrender/Element} el
  8672. * @param {Object} [hoverStyle]
  8673. */
  8674. graphic.setHoverStyle = function (el, hoverStyle) {
  8675. el.type === 'group'
  8676. ? el.traverse(function (child) {
  8677. if (child.type !== 'group') {
  8678. setElementHoverStl(child, hoverStyle);
  8679. }
  8680. })
  8681. : setElementHoverStl(el, hoverStyle);
  8682. // Remove previous bound handlers
  8683. el.on('mouseover', onElementMouseOver)
  8684. .on('mouseout', onElementMouseOut);
  8685. // Emphasis, normal can be triggered manually
  8686. el.on('emphasis', enterEmphasis)
  8687. .on('normal', leaveEmphasis);
  8688. };
  8689. /**
  8690. * Set text option in the style
  8691. * @param {Object} textStyle
  8692. * @param {module:echarts/model/Model} labelModel
  8693. * @param {string} color
  8694. */
  8695. graphic.setText = function (textStyle, labelModel, color) {
  8696. var labelPosition = labelModel.getShallow('position') || 'inside';
  8697. var labelColor = labelPosition.indexOf('inside') >= 0 ? 'white' : color;
  8698. var textStyleModel = labelModel.getModel('textStyle');
  8699. zrUtil.extend(textStyle, {
  8700. textDistance: labelModel.getShallow('distance') || 5,
  8701. textFont: textStyleModel.getFont(),
  8702. textPosition: labelPosition,
  8703. textFill: textStyleModel.getTextColor() || labelColor
  8704. });
  8705. };
  8706. function animateOrSetProps(isUpdate, el, props, animatableModel, dataIndex, cb) {
  8707. if (typeof dataIndex === 'function') {
  8708. cb = dataIndex;
  8709. dataIndex = null;
  8710. }
  8711. var postfix = isUpdate ? 'Update' : '';
  8712. var duration = animatableModel
  8713. && animatableModel.getShallow('animationDuration' + postfix);
  8714. var animationEasing = animatableModel
  8715. && animatableModel.getShallow('animationEasing' + postfix);
  8716. var animationDelay = animatableModel
  8717. && animatableModel.getShallow('animationDelay' + postfix);
  8718. if (typeof animationDelay === 'function') {
  8719. animationDelay = animationDelay(dataIndex);
  8720. }
  8721. animatableModel && animatableModel.getShallow('animation')
  8722. ? el.animateTo(props, duration, animationDelay || 0, animationEasing, cb)
  8723. : (el.attr(props), cb && cb());
  8724. }
  8725. /**
  8726. * Update graphic element properties with or without animation according to the configuration in series
  8727. * @param {module:zrender/Element} el
  8728. * @param {Object} props
  8729. * @param {module:echarts/model/Model} [animatableModel]
  8730. * @param {number} [dataIndex]
  8731. * @param {Function} [cb]
  8732. * @example
  8733. * graphic.updateProps(el, {
  8734. * position: [100, 100]
  8735. * }, seriesModel, dataIndex, function () { console.log('Animation done!'); });
  8736. * // Or
  8737. * graphic.updateProps(el, {
  8738. * position: [100, 100]
  8739. * }, seriesModel, function () { console.log('Animation done!'); });
  8740. */
  8741. graphic.updateProps = zrUtil.curry(animateOrSetProps, true);
  8742. /**
  8743. * Init graphic element properties with or without animation according to the configuration in series
  8744. * @param {module:zrender/Element} el
  8745. * @param {Object} props
  8746. * @param {module:echarts/model/Model} [animatableModel]
  8747. * @param {Function} cb
  8748. */
  8749. graphic.initProps = zrUtil.curry(animateOrSetProps, false);
  8750. /**
  8751. * Get transform matrix of target (param target),
  8752. * in coordinate of its ancestor (param ancestor)
  8753. *
  8754. * @param {module:zrender/mixin/Transformable} target
  8755. * @param {module:zrender/mixin/Transformable} [ancestor]
  8756. */
  8757. graphic.getTransform = function (target, ancestor) {
  8758. var mat = matrix.identity([]);
  8759. while (target && target !== ancestor) {
  8760. matrix.mul(mat, target.getLocalTransform(), mat);
  8761. target = target.parent;
  8762. }
  8763. return mat;
  8764. };
  8765. /**
  8766. * Apply transform to an vertex.
  8767. * @param {Array.<number>} vertex [x, y]
  8768. * @param {Array.<number>} transform Transform matrix: like [1, 0, 0, 1, 0, 0]
  8769. * @param {boolean=} invert Whether use invert matrix.
  8770. * @return {Array.<number>} [x, y]
  8771. */
  8772. graphic.applyTransform = function (vertex, transform, invert) {
  8773. if (invert) {
  8774. transform = matrix.invert([], transform);
  8775. }
  8776. return vector.applyTransform([], vertex, transform);
  8777. };
  8778. /**
  8779. * @param {string} direction 'left' 'right' 'top' 'bottom'
  8780. * @param {Array.<number>} transform Transform matrix: like [1, 0, 0, 1, 0, 0]
  8781. * @param {boolean=} invert Whether use invert matrix.
  8782. * @return {string} Transformed direction. 'left' 'right' 'top' 'bottom'
  8783. */
  8784. graphic.transformDirection = function (direction, transform, invert) {
  8785. // Pick a base, ensure that transform result will not be (0, 0).
  8786. var hBase = (transform[4] === 0 || transform[5] === 0 || transform[0] === 0)
  8787. ? 1 : Math.abs(2 * transform[4] / transform[0]);
  8788. var vBase = (transform[4] === 0 || transform[5] === 0 || transform[2] === 0)
  8789. ? 1 : Math.abs(2 * transform[4] / transform[2]);
  8790. var vertex = [
  8791. direction === 'left' ? -hBase : direction === 'right' ? hBase : 0,
  8792. direction === 'top' ? -vBase : direction === 'bottom' ? vBase : 0
  8793. ];
  8794. vertex = graphic.applyTransform(vertex, transform, invert);
  8795. return Math.abs(vertex[0]) > Math.abs(vertex[1])
  8796. ? (vertex[0] > 0 ? 'right' : 'left')
  8797. : (vertex[1] > 0 ? 'bottom' : 'top');
  8798. };
  8799. module.exports = graphic;
  8800. /***/ },
  8801. /* 43 */
  8802. /***/ function(module, exports, __webpack_require__) {
  8803. var Path = __webpack_require__(44);
  8804. var PathProxy = __webpack_require__(48);
  8805. var transformPath = __webpack_require__(58);
  8806. var matrix = __webpack_require__(17);
  8807. // command chars
  8808. var cc = [
  8809. 'm', 'M', 'l', 'L', 'v', 'V', 'h', 'H', 'z', 'Z',
  8810. 'c', 'C', 'q', 'Q', 't', 'T', 's', 'S', 'a', 'A'
  8811. ];
  8812. var mathSqrt = Math.sqrt;
  8813. var mathSin = Math.sin;
  8814. var mathCos = Math.cos;
  8815. var PI = Math.PI;
  8816. var vMag = function(v) {
  8817. return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
  8818. };
  8819. var vRatio = function(u, v) {
  8820. return (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v));
  8821. };
  8822. var vAngle = function(u, v) {
  8823. return (u[0] * v[1] < u[1] * v[0] ? -1 : 1)
  8824. * Math.acos(vRatio(u, v));
  8825. };
  8826. function processArc(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg, cmd, path) {
  8827. var psi = psiDeg * (PI / 180.0);
  8828. var xp = mathCos(psi) * (x1 - x2) / 2.0
  8829. + mathSin(psi) * (y1 - y2) / 2.0;
  8830. var yp = -1 * mathSin(psi) * (x1 - x2) / 2.0
  8831. + mathCos(psi) * (y1 - y2) / 2.0;
  8832. var lambda = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry);
  8833. if (lambda > 1) {
  8834. rx *= mathSqrt(lambda);
  8835. ry *= mathSqrt(lambda);
  8836. }
  8837. var f = (fa === fs ? -1 : 1)
  8838. * mathSqrt((((rx * rx) * (ry * ry))
  8839. - ((rx * rx) * (yp * yp))
  8840. - ((ry * ry) * (xp * xp))) / ((rx * rx) * (yp * yp)
  8841. + (ry * ry) * (xp * xp))
  8842. ) || 0;
  8843. var cxp = f * rx * yp / ry;
  8844. var cyp = f * -ry * xp / rx;
  8845. var cx = (x1 + x2) / 2.0
  8846. + mathCos(psi) * cxp
  8847. - mathSin(psi) * cyp;
  8848. var cy = (y1 + y2) / 2.0
  8849. + mathSin(psi) * cxp
  8850. + mathCos(psi) * cyp;
  8851. var theta = vAngle([ 1, 0 ], [ (xp - cxp) / rx, (yp - cyp) / ry ]);
  8852. var u = [ (xp - cxp) / rx, (yp - cyp) / ry ];
  8853. var v = [ (-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry ];
  8854. var dTheta = vAngle(u, v);
  8855. if (vRatio(u, v) <= -1) {
  8856. dTheta = PI;
  8857. }
  8858. if (vRatio(u, v) >= 1) {
  8859. dTheta = 0;
  8860. }
  8861. if (fs === 0 && dTheta > 0) {
  8862. dTheta = dTheta - 2 * PI;
  8863. }
  8864. if (fs === 1 && dTheta < 0) {
  8865. dTheta = dTheta + 2 * PI;
  8866. }
  8867. path.addData(cmd, cx, cy, rx, ry, theta, dTheta, psi, fs);
  8868. }
  8869. function createPathProxyFromString(data) {
  8870. if (!data) {
  8871. return [];
  8872. }
  8873. // command string
  8874. var cs = data.replace(/-/g, ' -')
  8875. .replace(/ /g, ' ')
  8876. .replace(/ /g, ',')
  8877. .replace(/,,/g, ',');
  8878. var n;
  8879. // create pipes so that we can split the data
  8880. for (n = 0; n < cc.length; n++) {
  8881. cs = cs.replace(new RegExp(cc[n], 'g'), '|' + cc[n]);
  8882. }
  8883. // create array
  8884. var arr = cs.split('|');
  8885. // init context point
  8886. var cpx = 0;
  8887. var cpy = 0;
  8888. var path = new PathProxy();
  8889. var CMD = PathProxy.CMD;
  8890. var prevCmd;
  8891. for (n = 1; n < arr.length; n++) {
  8892. var str = arr[n];
  8893. var c = str.charAt(0);
  8894. var off = 0;
  8895. var p = str.slice(1).replace(/e,-/g, 'e-').split(',');
  8896. var cmd;
  8897. if (p.length > 0 && p[0] === '') {
  8898. p.shift();
  8899. }
  8900. for (var i = 0; i < p.length; i++) {
  8901. p[i] = parseFloat(p[i]);
  8902. }
  8903. while (off < p.length && !isNaN(p[off])) {
  8904. if (isNaN(p[0])) {
  8905. break;
  8906. }
  8907. var ctlPtx;
  8908. var ctlPty;
  8909. var rx;
  8910. var ry;
  8911. var psi;
  8912. var fa;
  8913. var fs;
  8914. var x1 = cpx;
  8915. var y1 = cpy;
  8916. // convert l, H, h, V, and v to L
  8917. switch (c) {
  8918. case 'l':
  8919. cpx += p[off++];
  8920. cpy += p[off++];
  8921. cmd = CMD.L;
  8922. path.addData(cmd, cpx, cpy);
  8923. break;
  8924. case 'L':
  8925. cpx = p[off++];
  8926. cpy = p[off++];
  8927. cmd = CMD.L;
  8928. path.addData(cmd, cpx, cpy);
  8929. break;
  8930. case 'm':
  8931. cpx += p[off++];
  8932. cpy += p[off++];
  8933. cmd = CMD.M;
  8934. path.addData(cmd, cpx, cpy);
  8935. c = 'l';
  8936. break;
  8937. case 'M':
  8938. cpx = p[off++];
  8939. cpy = p[off++];
  8940. cmd = CMD.M;
  8941. path.addData(cmd, cpx, cpy);
  8942. c = 'L';
  8943. break;
  8944. case 'h':
  8945. cpx += p[off++];
  8946. cmd = CMD.L;
  8947. path.addData(cmd, cpx, cpy);
  8948. break;
  8949. case 'H':
  8950. cpx = p[off++];
  8951. cmd = CMD.L;
  8952. path.addData(cmd, cpx, cpy);
  8953. break;
  8954. case 'v':
  8955. cpy += p[off++];
  8956. cmd = CMD.L;
  8957. path.addData(cmd, cpx, cpy);
  8958. break;
  8959. case 'V':
  8960. cpy = p[off++];
  8961. cmd = CMD.L;
  8962. path.addData(cmd, cpx, cpy);
  8963. break;
  8964. case 'C':
  8965. cmd = CMD.C;
  8966. path.addData(
  8967. cmd, p[off++], p[off++], p[off++], p[off++], p[off++], p[off++]
  8968. );
  8969. cpx = p[off - 2];
  8970. cpy = p[off - 1];
  8971. break;
  8972. case 'c':
  8973. cmd = CMD.C;
  8974. path.addData(
  8975. cmd,
  8976. p[off++] + cpx, p[off++] + cpy,
  8977. p[off++] + cpx, p[off++] + cpy,
  8978. p[off++] + cpx, p[off++] + cpy
  8979. );
  8980. cpx += p[off - 2];
  8981. cpy += p[off - 1];
  8982. break;
  8983. case 'S':
  8984. ctlPtx = cpx;
  8985. ctlPty = cpy;
  8986. var len = path.len();
  8987. var pathData = path.data;
  8988. if (prevCmd === CMD.C) {
  8989. ctlPtx += cpx - pathData[len - 4];
  8990. ctlPty += cpy - pathData[len - 3];
  8991. }
  8992. cmd = CMD.C;
  8993. x1 = p[off++];
  8994. y1 = p[off++];
  8995. cpx = p[off++];
  8996. cpy = p[off++];
  8997. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  8998. break;
  8999. case 's':
  9000. ctlPtx = cpx;
  9001. ctlPty = cpy;
  9002. var len = path.len();
  9003. var pathData = path.data;
  9004. if (prevCmd === CMD.C) {
  9005. ctlPtx += cpx - pathData[len - 4];
  9006. ctlPty += cpy - pathData[len - 3];
  9007. }
  9008. cmd = CMD.C;
  9009. x1 = cpx + p[off++];
  9010. y1 = cpy + p[off++];
  9011. cpx += p[off++];
  9012. cpy += p[off++];
  9013. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  9014. break;
  9015. case 'Q':
  9016. x1 = p[off++];
  9017. y1 = p[off++];
  9018. cpx = p[off++];
  9019. cpy = p[off++];
  9020. cmd = CMD.Q;
  9021. path.addData(cmd, x1, y1, cpx, cpy);
  9022. break;
  9023. case 'q':
  9024. x1 = p[off++] + cpx;
  9025. y1 = p[off++] + cpy;
  9026. cpx += p[off++];
  9027. cpy += p[off++];
  9028. cmd = CMD.Q;
  9029. path.addData(cmd, x1, y1, cpx, cpy);
  9030. break;
  9031. case 'T':
  9032. ctlPtx = cpx;
  9033. ctlPty = cpy;
  9034. var len = path.len();
  9035. var pathData = path.data;
  9036. if (prevCmd === CMD.Q) {
  9037. ctlPtx += cpx - pathData[len - 4];
  9038. ctlPty += cpy - pathData[len - 3];
  9039. }
  9040. cpx = p[off++];
  9041. cpy = p[off++];
  9042. cmd = CMD.Q;
  9043. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  9044. break;
  9045. case 't':
  9046. ctlPtx = cpx;
  9047. ctlPty = cpy;
  9048. var len = path.len();
  9049. var pathData = path.data;
  9050. if (prevCmd === CMD.Q) {
  9051. ctlPtx += cpx - pathData[len - 4];
  9052. ctlPty += cpy - pathData[len - 3];
  9053. }
  9054. cpx += p[off++];
  9055. cpy += p[off++];
  9056. cmd = CMD.Q;
  9057. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  9058. break;
  9059. case 'A':
  9060. rx = p[off++];
  9061. ry = p[off++];
  9062. psi = p[off++];
  9063. fa = p[off++];
  9064. fs = p[off++];
  9065. x1 = cpx, y1 = cpy;
  9066. cpx = p[off++];
  9067. cpy = p[off++];
  9068. cmd = CMD.A;
  9069. processArc(
  9070. x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path
  9071. );
  9072. break;
  9073. case 'a':
  9074. rx = p[off++];
  9075. ry = p[off++];
  9076. psi = p[off++];
  9077. fa = p[off++];
  9078. fs = p[off++];
  9079. x1 = cpx, y1 = cpy;
  9080. cpx += p[off++];
  9081. cpy += p[off++];
  9082. cmd = CMD.A;
  9083. processArc(
  9084. x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path
  9085. );
  9086. break;
  9087. }
  9088. }
  9089. if (c === 'z' || c === 'Z') {
  9090. cmd = CMD.Z;
  9091. path.addData(cmd);
  9092. }
  9093. prevCmd = cmd;
  9094. }
  9095. path.toStatic();
  9096. return path;
  9097. }
  9098. // TODO Optimize double memory cost problem
  9099. function createPathOptions(str, opts) {
  9100. var pathProxy = createPathProxyFromString(str);
  9101. var transform;
  9102. opts = opts || {};
  9103. opts.buildPath = function (path) {
  9104. path.setData(pathProxy.data);
  9105. transform && transformPath(path, transform);
  9106. // Svg and vml renderer don't have context
  9107. var ctx = path.getContext();
  9108. if (ctx) {
  9109. path.rebuildPath(ctx);
  9110. }
  9111. };
  9112. opts.applyTransform = function (m) {
  9113. if (!transform) {
  9114. transform = matrix.create();
  9115. }
  9116. matrix.mul(transform, m, transform);
  9117. };
  9118. return opts;
  9119. }
  9120. module.exports = {
  9121. /**
  9122. * Create a Path object from path string data
  9123. * http://www.w3.org/TR/SVG/paths.html#PathData
  9124. * @param {Object} opts Other options
  9125. */
  9126. createFromString: function (str, opts) {
  9127. return new Path(createPathOptions(str, opts));
  9128. },
  9129. /**
  9130. * Create a Path class from path string data
  9131. * @param {string} str
  9132. * @param {Object} opts Other options
  9133. */
  9134. extendFromString: function (str, opts) {
  9135. return Path.extend(createPathOptions(str, opts));
  9136. },
  9137. /**
  9138. * Merge multiple paths
  9139. */
  9140. // TODO Apply transform
  9141. // TODO stroke dash
  9142. // TODO Optimize double memory cost problem
  9143. mergePath: function (pathEls, opts) {
  9144. var pathList = [];
  9145. var len = pathEls.length;
  9146. var pathEl;
  9147. var i;
  9148. for (i = 0; i < len; i++) {
  9149. pathEl = pathEls[i];
  9150. if (pathEl.__dirty) {
  9151. pathEl.buildPath(pathEl.path, pathEl.shape);
  9152. }
  9153. pathList.push(pathEl.path);
  9154. }
  9155. var pathBundle = new Path(opts);
  9156. pathBundle.buildPath = function (path) {
  9157. path.appendPath(pathList);
  9158. // Svg and vml renderer don't have context
  9159. var ctx = path.getContext();
  9160. if (ctx) {
  9161. path.rebuildPath(ctx);
  9162. }
  9163. };
  9164. return pathBundle;
  9165. }
  9166. };
  9167. /***/ },
  9168. /* 44 */
  9169. /***/ function(module, exports, __webpack_require__) {
  9170. /**
  9171. * Path element
  9172. * @module zrender/graphic/Path
  9173. */
  9174. var Displayable = __webpack_require__(45);
  9175. var zrUtil = __webpack_require__(3);
  9176. var PathProxy = __webpack_require__(48);
  9177. var pathContain = __webpack_require__(51);
  9178. var Gradient = __webpack_require__(4);
  9179. function pathHasFill(style) {
  9180. var fill = style.fill;
  9181. return fill != null && fill !== 'none';
  9182. }
  9183. function pathHasStroke(style) {
  9184. var stroke = style.stroke;
  9185. return stroke != null && stroke !== 'none' && style.lineWidth > 0;
  9186. }
  9187. var abs = Math.abs;
  9188. /**
  9189. * @alias module:zrender/graphic/Path
  9190. * @extends module:zrender/graphic/Displayable
  9191. * @constructor
  9192. * @param {Object} opts
  9193. */
  9194. function Path(opts) {
  9195. Displayable.call(this, opts);
  9196. /**
  9197. * @type {module:zrender/core/PathProxy}
  9198. * @readOnly
  9199. */
  9200. this.path = new PathProxy();
  9201. }
  9202. Path.prototype = {
  9203. constructor: Path,
  9204. type: 'path',
  9205. __dirtyPath: true,
  9206. strokeContainThreshold: 5,
  9207. brush: function (ctx) {
  9208. ctx.save();
  9209. var style = this.style;
  9210. var path = this.path;
  9211. var hasStroke = pathHasStroke(style);
  9212. var hasFill = pathHasFill(style);
  9213. var hasFillGradient = hasFill && !!(style.fill.colorStops);
  9214. var hasStrokeGradient = hasStroke && !!(style.stroke.colorStops);
  9215. style.bind(ctx, this);
  9216. this.setTransform(ctx);
  9217. if (this.__dirtyPath) {
  9218. var rect = this.getBoundingRect();
  9219. // Update gradient because bounding rect may changed
  9220. if (hasFillGradient) {
  9221. this._fillGradient = style.getGradient(ctx, style.fill, rect);
  9222. }
  9223. if (hasStrokeGradient) {
  9224. this._strokeGradient = style.getGradient(ctx, style.stroke, rect);
  9225. }
  9226. }
  9227. // Use the gradient
  9228. if (hasFillGradient) {
  9229. ctx.fillStyle = this._fillGradient;
  9230. }
  9231. if (hasStrokeGradient) {
  9232. ctx.strokeStyle = this._strokeGradient;
  9233. }
  9234. var lineDash = style.lineDash;
  9235. var lineDashOffset = style.lineDashOffset;
  9236. var ctxLineDash = !!ctx.setLineDash;
  9237. // Update path sx, sy
  9238. var scale = this.getGlobalScale();
  9239. path.setScale(scale[0], scale[1]);
  9240. // Proxy context
  9241. // Rebuild path in following 2 cases
  9242. // 1. Path is dirty
  9243. // 2. Path needs javascript implemented lineDash stroking.
  9244. // In this case, lineDash information will not be saved in PathProxy
  9245. if (this.__dirtyPath || (
  9246. lineDash && !ctxLineDash && hasStroke
  9247. )) {
  9248. path = this.path.beginPath(ctx);
  9249. // Setting line dash before build path
  9250. if (lineDash && !ctxLineDash) {
  9251. path.setLineDash(lineDash);
  9252. path.setLineDashOffset(lineDashOffset);
  9253. }
  9254. this.buildPath(path, this.shape);
  9255. // Clear path dirty flag
  9256. this.__dirtyPath = false;
  9257. }
  9258. else {
  9259. // Replay path building
  9260. ctx.beginPath();
  9261. this.path.rebuildPath(ctx);
  9262. }
  9263. hasFill && path.fill(ctx);
  9264. if (lineDash && ctxLineDash) {
  9265. ctx.setLineDash(lineDash);
  9266. ctx.lineDashOffset = lineDashOffset;
  9267. }
  9268. hasStroke && path.stroke(ctx);
  9269. // Draw rect text
  9270. if (style.text != null) {
  9271. // var rect = this.getBoundingRect();
  9272. this.drawRectText(ctx, this.getBoundingRect());
  9273. }
  9274. ctx.restore();
  9275. },
  9276. buildPath: function (ctx, shapeCfg) {},
  9277. getBoundingRect: function () {
  9278. var rect = this._rect;
  9279. var style = this.style;
  9280. var needsUpdateRect = !rect;
  9281. if (needsUpdateRect) {
  9282. var path = this.path;
  9283. if (this.__dirtyPath) {
  9284. path.beginPath();
  9285. this.buildPath(path, this.shape);
  9286. }
  9287. rect = path.getBoundingRect();
  9288. }
  9289. this._rect = rect;
  9290. if (pathHasStroke(style)) {
  9291. // Needs update rect with stroke lineWidth when
  9292. // 1. Element changes scale or lineWidth
  9293. // 2. Shape is changed
  9294. var rectWithStroke = this._rectWithStroke || (this._rectWithStroke = rect.clone());
  9295. if (this.__dirty || needsUpdateRect) {
  9296. rectWithStroke.copy(rect);
  9297. // FIXME Must after updateTransform
  9298. var w = style.lineWidth;
  9299. // PENDING, Min line width is needed when line is horizontal or vertical
  9300. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  9301. // Only add extra hover lineWidth when there are no fill
  9302. if (!pathHasFill(style)) {
  9303. w = Math.max(w, this.strokeContainThreshold);
  9304. }
  9305. // Consider line width
  9306. // Line scale can't be 0;
  9307. if (lineScale > 1e-10) {
  9308. rectWithStroke.width += w / lineScale;
  9309. rectWithStroke.height += w / lineScale;
  9310. rectWithStroke.x -= w / lineScale / 2;
  9311. rectWithStroke.y -= w / lineScale / 2;
  9312. }
  9313. }
  9314. // Return rect with stroke
  9315. return rectWithStroke;
  9316. }
  9317. return rect;
  9318. },
  9319. contain: function (x, y) {
  9320. var localPos = this.transformCoordToLocal(x, y);
  9321. var rect = this.getBoundingRect();
  9322. var style = this.style;
  9323. x = localPos[0];
  9324. y = localPos[1];
  9325. if (rect.contain(x, y)) {
  9326. var pathData = this.path.data;
  9327. if (pathHasStroke(style)) {
  9328. var lineWidth = style.lineWidth;
  9329. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  9330. // Line scale can't be 0;
  9331. if (lineScale > 1e-10) {
  9332. // Only add extra hover lineWidth when there are no fill
  9333. if (!pathHasFill(style)) {
  9334. lineWidth = Math.max(lineWidth, this.strokeContainThreshold);
  9335. }
  9336. if (pathContain.containStroke(
  9337. pathData, lineWidth / lineScale, x, y
  9338. )) {
  9339. return true;
  9340. }
  9341. }
  9342. }
  9343. if (pathHasFill(style)) {
  9344. return pathContain.contain(pathData, x, y);
  9345. }
  9346. }
  9347. return false;
  9348. },
  9349. /**
  9350. * @param {boolean} dirtyPath
  9351. */
  9352. dirty: function (dirtyPath) {
  9353. if (arguments.length ===0) {
  9354. dirtyPath = true;
  9355. }
  9356. // Only mark dirty, not mark clean
  9357. if (dirtyPath) {
  9358. this.__dirtyPath = dirtyPath;
  9359. this._rect = null;
  9360. }
  9361. this.__dirty = true;
  9362. this.__zr && this.__zr.refresh();
  9363. // Used as a clipping path
  9364. if (this.__clipTarget) {
  9365. this.__clipTarget.dirty();
  9366. }
  9367. },
  9368. /**
  9369. * Alias for animate('shape')
  9370. * @param {boolean} loop
  9371. */
  9372. animateShape: function (loop) {
  9373. return this.animate('shape', loop);
  9374. },
  9375. // Overwrite attrKV
  9376. attrKV: function (key, value) {
  9377. // FIXME
  9378. if (key === 'shape') {
  9379. this.setShape(value);
  9380. }
  9381. else {
  9382. Displayable.prototype.attrKV.call(this, key, value);
  9383. }
  9384. },
  9385. /**
  9386. * @param {Object|string} key
  9387. * @param {*} value
  9388. */
  9389. setShape: function (key, value) {
  9390. var shape = this.shape;
  9391. // Path from string may not have shape
  9392. if (shape) {
  9393. if (zrUtil.isObject(key)) {
  9394. for (var name in key) {
  9395. shape[name] = key[name];
  9396. }
  9397. }
  9398. else {
  9399. shape[key] = value;
  9400. }
  9401. this.dirty(true);
  9402. }
  9403. return this;
  9404. },
  9405. getLineScale: function () {
  9406. var m = this.transform;
  9407. // Get the line scale.
  9408. // Determinant of `m` means how much the area is enlarged by the
  9409. // transformation. So its square root can be used as a scale factor
  9410. // for width.
  9411. return m && abs(m[0] - 1) > 1e-10 && abs(m[3] - 1) > 1e-10
  9412. ? Math.sqrt(abs(m[0] * m[3] - m[2] * m[1]))
  9413. : 1;
  9414. }
  9415. };
  9416. /**
  9417. * 扩展一个 Path element, 比如星形,圆等。
  9418. * Extend a path element
  9419. * @param {Object} props
  9420. * @param {string} props.type Path type
  9421. * @param {Function} props.init Initialize
  9422. * @param {Function} props.buildPath Overwrite buildPath method
  9423. * @param {Object} [props.style] Extended default style config
  9424. * @param {Object} [props.shape] Extended default shape config
  9425. */
  9426. Path.extend = function (defaults) {
  9427. var Sub = function (opts) {
  9428. Path.call(this, opts);
  9429. if (defaults.style) {
  9430. // Extend default style
  9431. this.style.extendFrom(defaults.style, false);
  9432. }
  9433. // Extend default shape
  9434. var defaultShape = defaults.shape;
  9435. if (defaultShape) {
  9436. this.shape = this.shape || {};
  9437. var thisShape = this.shape;
  9438. for (var name in defaultShape) {
  9439. if (
  9440. ! thisShape.hasOwnProperty(name)
  9441. && defaultShape.hasOwnProperty(name)
  9442. ) {
  9443. thisShape[name] = defaultShape[name];
  9444. }
  9445. }
  9446. }
  9447. defaults.init && defaults.init.call(this, opts);
  9448. };
  9449. zrUtil.inherits(Sub, Path);
  9450. // FIXME 不能 extend position, rotation 等引用对象
  9451. for (var name in defaults) {
  9452. // Extending prototype values and methods
  9453. if (name !== 'style' && name !== 'shape') {
  9454. Sub.prototype[name] = defaults[name];
  9455. }
  9456. }
  9457. return Sub;
  9458. };
  9459. zrUtil.inherits(Path, Displayable);
  9460. module.exports = Path;
  9461. /***/ },
  9462. /* 45 */
  9463. /***/ function(module, exports, __webpack_require__) {
  9464. /**
  9465. * 可绘制的图形基类
  9466. * Base class of all displayable graphic objects
  9467. * @module zrender/graphic/Displayable
  9468. */
  9469. var zrUtil = __webpack_require__(3);
  9470. var Style = __webpack_require__(46);
  9471. var Element = __webpack_require__(30);
  9472. var RectText = __webpack_require__(47);
  9473. // var Stateful = require('./mixin/Stateful');
  9474. /**
  9475. * @alias module:zrender/graphic/Displayable
  9476. * @extends module:zrender/Element
  9477. * @extends module:zrender/graphic/mixin/RectText
  9478. */
  9479. function Displayable(opts) {
  9480. opts = opts || {};
  9481. Element.call(this, opts);
  9482. // Extend properties
  9483. for (var name in opts) {
  9484. if (
  9485. opts.hasOwnProperty(name) &&
  9486. name !== 'style'
  9487. ) {
  9488. this[name] = opts[name];
  9489. }
  9490. }
  9491. /**
  9492. * @type {module:zrender/graphic/Style}
  9493. */
  9494. this.style = new Style(opts.style);
  9495. this._rect = null;
  9496. // Shapes for cascade clipping.
  9497. this.__clipPaths = [];
  9498. // FIXME Stateful must be mixined after style is setted
  9499. // Stateful.call(this, opts);
  9500. }
  9501. Displayable.prototype = {
  9502. constructor: Displayable,
  9503. type: 'displayable',
  9504. /**
  9505. * Displayable 是否为脏,Painter 中会根据该标记判断是否需要是否需要重新绘制
  9506. * Dirty flag. From which painter will determine if this displayable object needs brush
  9507. * @name module:zrender/graphic/Displayable#__dirty
  9508. * @type {boolean}
  9509. */
  9510. __dirty: true,
  9511. /**
  9512. * 图形是否可见,为true时不绘制图形,但是仍能触发鼠标事件
  9513. * If ignore drawing of the displayable object. Mouse event will still be triggered
  9514. * @name module:/zrender/graphic/Displayable#invisible
  9515. * @type {boolean}
  9516. * @default false
  9517. */
  9518. invisible: false,
  9519. /**
  9520. * @name module:/zrender/graphic/Displayable#z
  9521. * @type {number}
  9522. * @default 0
  9523. */
  9524. z: 0,
  9525. /**
  9526. * @name module:/zrender/graphic/Displayable#z
  9527. * @type {number}
  9528. * @default 0
  9529. */
  9530. z2: 0,
  9531. /**
  9532. * z层level,决定绘画在哪层canvas中
  9533. * @name module:/zrender/graphic/Displayable#zlevel
  9534. * @type {number}
  9535. * @default 0
  9536. */
  9537. zlevel: 0,
  9538. /**
  9539. * 是否可拖拽
  9540. * @name module:/zrender/graphic/Displayable#draggable
  9541. * @type {boolean}
  9542. * @default false
  9543. */
  9544. draggable: false,
  9545. /**
  9546. * 是否正在拖拽
  9547. * @name module:/zrender/graphic/Displayable#draggable
  9548. * @type {boolean}
  9549. * @default false
  9550. */
  9551. dragging: false,
  9552. /**
  9553. * 是否相应鼠标事件
  9554. * @name module:/zrender/graphic/Displayable#silent
  9555. * @type {boolean}
  9556. * @default false
  9557. */
  9558. silent: false,
  9559. /**
  9560. * If enable culling
  9561. * @type {boolean}
  9562. * @default false
  9563. */
  9564. culling: false,
  9565. /**
  9566. * Mouse cursor when hovered
  9567. * @name module:/zrender/graphic/Displayable#cursor
  9568. * @type {string}
  9569. */
  9570. cursor: 'pointer',
  9571. /**
  9572. * If hover area is bounding rect
  9573. * @name module:/zrender/graphic/Displayable#rectHover
  9574. * @type {string}
  9575. */
  9576. rectHover: false,
  9577. beforeBrush: function (ctx) {},
  9578. afterBrush: function (ctx) {},
  9579. /**
  9580. * 图形绘制方法
  9581. * @param {Canvas2DRenderingContext} ctx
  9582. */
  9583. // Interface
  9584. brush: function (ctx) {},
  9585. /**
  9586. * 获取最小包围盒
  9587. * @return {module:zrender/core/BoundingRect}
  9588. */
  9589. // Interface
  9590. getBoundingRect: function () {},
  9591. /**
  9592. * 判断坐标 x, y 是否在图形上
  9593. * If displayable element contain coord x, y
  9594. * @param {number} x
  9595. * @param {number} y
  9596. * @return {boolean}
  9597. */
  9598. contain: function (x, y) {
  9599. return this.rectContain(x, y);
  9600. },
  9601. /**
  9602. * @param {Function} cb
  9603. * @param {} context
  9604. */
  9605. traverse: function (cb, context) {
  9606. cb.call(context, this);
  9607. },
  9608. /**
  9609. * 判断坐标 x, y 是否在图形的包围盒上
  9610. * If bounding rect of element contain coord x, y
  9611. * @param {number} x
  9612. * @param {number} y
  9613. * @return {boolean}
  9614. */
  9615. rectContain: function (x, y) {
  9616. var coord = this.transformCoordToLocal(x, y);
  9617. var rect = this.getBoundingRect();
  9618. return rect.contain(coord[0], coord[1]);
  9619. },
  9620. /**
  9621. * 标记图形元素为脏,并且在下一帧重绘
  9622. * Mark displayable element dirty and refresh next frame
  9623. */
  9624. dirty: function () {
  9625. this.__dirty = true;
  9626. this._rect = null;
  9627. this.__zr && this.__zr.refresh();
  9628. },
  9629. /**
  9630. * 图形是否会触发事件
  9631. * If displayable object binded any event
  9632. * @return {boolean}
  9633. */
  9634. // TODO, 通过 bind 绑定的事件
  9635. // isSilent: function () {
  9636. // return !(
  9637. // this.hoverable || this.draggable
  9638. // || this.onmousemove || this.onmouseover || this.onmouseout
  9639. // || this.onmousedown || this.onmouseup || this.onclick
  9640. // || this.ondragenter || this.ondragover || this.ondragleave
  9641. // || this.ondrop
  9642. // );
  9643. // },
  9644. /**
  9645. * Alias for animate('style')
  9646. * @param {boolean} loop
  9647. */
  9648. animateStyle: function (loop) {
  9649. return this.animate('style', loop);
  9650. },
  9651. attrKV: function (key, value) {
  9652. if (key !== 'style') {
  9653. Element.prototype.attrKV.call(this, key, value);
  9654. }
  9655. else {
  9656. this.style.set(value);
  9657. }
  9658. },
  9659. /**
  9660. * @param {Object|string} key
  9661. * @param {*} value
  9662. */
  9663. setStyle: function (key, value) {
  9664. this.style.set(key, value);
  9665. this.dirty(false);
  9666. return this;
  9667. },
  9668. /**
  9669. * Use given style object
  9670. * @param {Object} obj
  9671. */
  9672. useStyle: function (obj) {
  9673. this.style = new Style(obj);
  9674. this.dirty(false);
  9675. return this;
  9676. }
  9677. };
  9678. zrUtil.inherits(Displayable, Element);
  9679. zrUtil.mixin(Displayable, RectText);
  9680. // zrUtil.mixin(Displayable, Stateful);
  9681. module.exports = Displayable;
  9682. /***/ },
  9683. /* 46 */
  9684. /***/ function(module, exports) {
  9685. /**
  9686. * @module zrender/graphic/Style
  9687. */
  9688. var STYLE_LIST_COMMON = [
  9689. 'lineCap', 'lineJoin', 'miterLimit',
  9690. 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY', 'shadowColor'
  9691. ];
  9692. var Style = function (opts) {
  9693. this.extendFrom(opts);
  9694. };
  9695. Style.prototype = {
  9696. constructor: Style,
  9697. /**
  9698. * @type {string}
  9699. */
  9700. fill: '#000000',
  9701. /**
  9702. * @type {string}
  9703. */
  9704. stroke: null,
  9705. /**
  9706. * @type {number}
  9707. */
  9708. opacity: 1,
  9709. /**
  9710. * @type {Array.<number>}
  9711. */
  9712. lineDash: null,
  9713. /**
  9714. * @type {number}
  9715. */
  9716. lineDashOffset: 0,
  9717. /**
  9718. * @type {number}
  9719. */
  9720. shadowBlur: 0,
  9721. /**
  9722. * @type {number}
  9723. */
  9724. shadowOffsetX: 0,
  9725. /**
  9726. * @type {number}
  9727. */
  9728. shadowOffsetY: 0,
  9729. /**
  9730. * @type {number}
  9731. */
  9732. lineWidth: 1,
  9733. /**
  9734. * If stroke ignore scale
  9735. * @type {Boolean}
  9736. */
  9737. strokeNoScale: false,
  9738. // Bounding rect text configuration
  9739. // Not affected by element transform
  9740. /**
  9741. * @type {string}
  9742. */
  9743. text: null,
  9744. /**
  9745. * @type {string}
  9746. */
  9747. textFill: '#000',
  9748. /**
  9749. * @type {string}
  9750. */
  9751. textStroke: null,
  9752. /**
  9753. * 'inside', 'left', 'right', 'top', 'bottom'
  9754. * [x, y]
  9755. * @type {string|Array.<number>}
  9756. * @default 'inside'
  9757. */
  9758. textPosition: 'inside',
  9759. /**
  9760. * @type {string}
  9761. */
  9762. textBaseline: null,
  9763. /**
  9764. * @type {string}
  9765. */
  9766. textAlign: null,
  9767. /**
  9768. * @type {string}
  9769. */
  9770. textVerticalAlign: null,
  9771. /**
  9772. * @type {number}
  9773. */
  9774. textDistance: 5,
  9775. /**
  9776. * @type {number}
  9777. */
  9778. textShadowBlur: 0,
  9779. /**
  9780. * @type {number}
  9781. */
  9782. textShadowOffsetX: 0,
  9783. /**
  9784. * @type {number}
  9785. */
  9786. textShadowOffsetY: 0,
  9787. /**
  9788. * @param {CanvasRenderingContext2D} ctx
  9789. */
  9790. bind: function (ctx, el) {
  9791. var fill = this.fill;
  9792. var stroke = this.stroke;
  9793. for (var i = 0; i < STYLE_LIST_COMMON.length; i++) {
  9794. var styleName = STYLE_LIST_COMMON[i];
  9795. if (this[styleName] != null) {
  9796. ctx[styleName] = this[styleName];
  9797. }
  9798. }
  9799. if (stroke != null) {
  9800. var lineWidth = this.lineWidth;
  9801. ctx.lineWidth = lineWidth / (
  9802. (this.strokeNoScale && el && el.getLineScale) ? el.getLineScale() : 1
  9803. );
  9804. }
  9805. // Gradient will be created and set in Path#brush. So ignore it here
  9806. if (fill != null && fill !== 'none' && !fill.colorStops) {
  9807. ctx.fillStyle = fill;
  9808. }
  9809. if (stroke != null && stroke !== 'none' && !stroke.colorStops) {
  9810. // Use canvas gradient if has
  9811. ctx.strokeStyle = stroke;
  9812. }
  9813. this.opacity != null && (ctx.globalAlpha = this.opacity);
  9814. },
  9815. /**
  9816. * Extend from other style
  9817. * @param {zrender/graphic/Style} otherStyle
  9818. * @param {boolean} overwrite
  9819. */
  9820. extendFrom: function (otherStyle, overwrite) {
  9821. if (otherStyle) {
  9822. var target = this;
  9823. for (var name in otherStyle) {
  9824. if (otherStyle.hasOwnProperty(name)
  9825. && (overwrite || ! target.hasOwnProperty(name))
  9826. ) {
  9827. target[name] = otherStyle[name];
  9828. }
  9829. }
  9830. }
  9831. },
  9832. /**
  9833. * Batch setting style with a given object
  9834. * @param {Object|string} obj
  9835. * @param {*} [obj]
  9836. */
  9837. set: function (obj, value) {
  9838. if (typeof obj === 'string') {
  9839. this[obj] = value;
  9840. }
  9841. else {
  9842. this.extendFrom(obj, true);
  9843. }
  9844. },
  9845. /**
  9846. * Clone
  9847. * @return {zrender/graphic/Style} [description]
  9848. */
  9849. clone: function () {
  9850. var newStyle = new this.constructor();
  9851. newStyle.extendFrom(this, true);
  9852. return newStyle;
  9853. },
  9854. createLinearGradient: function (ctx, obj, rect) {
  9855. // var size =
  9856. var x = obj.x * rect.width + rect.x;
  9857. var x2 = obj.x2 * rect.width + rect.x;
  9858. var y = obj.y * rect.height + rect.y;
  9859. var y2 = obj.y2 * rect.height + rect.y;
  9860. var canvasGradient = ctx.createLinearGradient(x, y, x2, y2);
  9861. return canvasGradient;
  9862. },
  9863. createRadialGradient: function (ctx, obj, rect) {
  9864. var width = rect.width;
  9865. var height = rect.height;
  9866. var min = Math.min(width, height);
  9867. var x = obj.x * width + rect.x;
  9868. var y = obj.y * height + rect.y;
  9869. var r = obj.r * min;
  9870. var canvasGradient = ctx.createRadialGradient(x, y, 0, x, y, r);
  9871. return canvasGradient;
  9872. },
  9873. getGradient: function (ctx, obj, rect) {
  9874. var method = obj.type === 'radial' ? 'createRadialGradient' : 'createLinearGradient';
  9875. var canvasGradient = this[method](ctx, obj, rect);
  9876. var colorStops = obj.colorStops;
  9877. for (var i = 0; i < colorStops.length; i++) {
  9878. canvasGradient.addColorStop(
  9879. colorStops[i].offset, colorStops[i].color
  9880. );
  9881. }
  9882. return canvasGradient;
  9883. }
  9884. };
  9885. var styleProto = Style.prototype;
  9886. var name;
  9887. var i;
  9888. for (i = 0; i < STYLE_LIST_COMMON.length; i++) {
  9889. name = STYLE_LIST_COMMON[i];
  9890. if (!(name in styleProto)) {
  9891. styleProto[name] = null;
  9892. }
  9893. }
  9894. module.exports = Style;
  9895. /***/ },
  9896. /* 47 */
  9897. /***/ function(module, exports, __webpack_require__) {
  9898. /**
  9899. * Mixin for drawing text in a element bounding rect
  9900. * @module zrender/mixin/RectText
  9901. */
  9902. var textContain = __webpack_require__(14);
  9903. var BoundingRect = __webpack_require__(15);
  9904. var tmpRect = new BoundingRect();
  9905. var RectText = function () {};
  9906. function parsePercent(value, maxValue) {
  9907. if (typeof value === 'string') {
  9908. if (value.lastIndexOf('%') >= 0) {
  9909. return parseFloat(value) / 100 * maxValue;
  9910. }
  9911. return parseFloat(value);
  9912. }
  9913. return value;
  9914. }
  9915. function setTransform(ctx, m) {
  9916. ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
  9917. }
  9918. RectText.prototype = {
  9919. constructor: RectText,
  9920. /**
  9921. * Draw text in a rect with specified position.
  9922. * @param {CanvasRenderingContext} ctx
  9923. * @param {Object} rect Displayable rect
  9924. * @return {Object} textRect Alternative precalculated text bounding rect
  9925. */
  9926. drawRectText: function (ctx, rect, textRect) {
  9927. var style = this.style;
  9928. var text = style.text;
  9929. // Convert to string
  9930. text != null && (text += '');
  9931. if (!text) {
  9932. return;
  9933. }
  9934. var x;
  9935. var y;
  9936. var textPosition = style.textPosition;
  9937. var distance = style.textDistance;
  9938. var align = style.textAlign;
  9939. var font = style.textFont || style.font;
  9940. var baseline = style.textBaseline;
  9941. var verticalAlign = style.textVerticalAlign;
  9942. textRect = textRect || textContain.getBoundingRect(text, font, align, baseline);
  9943. // Transform rect to view space
  9944. var transform = this.transform;
  9945. var invTransform = this.invTransform;
  9946. if (transform) {
  9947. tmpRect.copy(rect);
  9948. tmpRect.applyTransform(transform);
  9949. rect = tmpRect;
  9950. // Transform back
  9951. setTransform(ctx, invTransform);
  9952. }
  9953. // Text position represented by coord
  9954. if (textPosition instanceof Array) {
  9955. // Percent
  9956. x = rect.x + parsePercent(textPosition[0], rect.width);
  9957. y = rect.y + parsePercent(textPosition[1], rect.height);
  9958. align = align || 'left';
  9959. baseline = baseline || 'top';
  9960. if (verticalAlign) {
  9961. switch (verticalAlign) {
  9962. case 'middle':
  9963. y -= textRect.height / 2 - textRect.lineHeight / 2;
  9964. break;
  9965. case 'bottom':
  9966. y -= textRect.height - textRect.lineHeight / 2;
  9967. break;
  9968. default:
  9969. y += textRect.lineHeight / 2;
  9970. }
  9971. // Force bseline to be middle
  9972. baseline = 'middle';
  9973. }
  9974. }
  9975. else {
  9976. var res = textContain.adjustTextPositionOnRect(
  9977. textPosition, rect, textRect, distance
  9978. );
  9979. x = res.x;
  9980. y = res.y;
  9981. // Default align and baseline when has textPosition
  9982. align = align || res.textAlign;
  9983. baseline = baseline || res.textBaseline;
  9984. }
  9985. ctx.textAlign = align;
  9986. ctx.textBaseline = baseline;
  9987. var textFill = style.textFill;
  9988. var textStroke = style.textStroke;
  9989. textFill && (ctx.fillStyle = textFill);
  9990. textStroke && (ctx.strokeStyle = textStroke);
  9991. ctx.font = font;
  9992. // Text shadow
  9993. ctx.shadowColor = style.textShadowColor;
  9994. ctx.shadowBlur = style.textShadowBlur;
  9995. ctx.shadowOffsetX = style.textShadowOffsetX;
  9996. ctx.shadowOffsetY = style.textShadowOffsetY;
  9997. var textLines = text.split('\n');
  9998. for (var i = 0; i < textLines.length; i++) {
  9999. textFill && ctx.fillText(textLines[i], x, y);
  10000. textStroke && ctx.strokeText(textLines[i], x, y);
  10001. y += textRect.lineHeight;
  10002. }
  10003. // Transform again
  10004. transform && setTransform(ctx, transform);
  10005. }
  10006. };
  10007. module.exports = RectText;
  10008. /***/ },
  10009. /* 48 */
  10010. /***/ function(module, exports, __webpack_require__) {
  10011. 'use strict';
  10012. /**
  10013. * Path 代理,可以在`buildPath`中用于替代`ctx`, 会保存每个path操作的命令到pathCommands属性中
  10014. * 可以用于 isInsidePath 判断以及获取boundingRect
  10015. *
  10016. * @module zrender/core/PathProxy
  10017. * @author Yi Shen (http://www.github.com/pissang)
  10018. */
  10019. // TODO getTotalLength, getPointAtLength
  10020. var curve = __webpack_require__(49);
  10021. var vec2 = __webpack_require__(16);
  10022. var bbox = __webpack_require__(50);
  10023. var BoundingRect = __webpack_require__(15);
  10024. var dpr = __webpack_require__(40).devicePixelRatio;
  10025. var CMD = {
  10026. M: 1,
  10027. L: 2,
  10028. C: 3,
  10029. Q: 4,
  10030. A: 5,
  10031. Z: 6,
  10032. // Rect
  10033. R: 7
  10034. };
  10035. var min = [];
  10036. var max = [];
  10037. var min2 = [];
  10038. var max2 = [];
  10039. var mathMin = Math.min;
  10040. var mathMax = Math.max;
  10041. var mathCos = Math.cos;
  10042. var mathSin = Math.sin;
  10043. var mathSqrt = Math.sqrt;
  10044. var mathAbs = Math.abs;
  10045. var hasTypedArray = typeof Float32Array != 'undefined';
  10046. /**
  10047. * @alias module:zrender/core/PathProxy
  10048. * @constructor
  10049. */
  10050. var PathProxy = function () {
  10051. /**
  10052. * Path data. Stored as flat array
  10053. * @type {Array.<Object>}
  10054. */
  10055. this.data = [];
  10056. this._len = 0;
  10057. this._ctx = null;
  10058. this._xi = 0;
  10059. this._yi = 0;
  10060. this._x0 = 0;
  10061. this._y0 = 0;
  10062. // Unit x, Unit y. Provide for avoiding drawing that too short line segment
  10063. this._ux = 0;
  10064. this._uy = 0;
  10065. };
  10066. /**
  10067. * 快速计算Path包围盒(并不是最小包围盒)
  10068. * @return {Object}
  10069. */
  10070. PathProxy.prototype = {
  10071. constructor: PathProxy,
  10072. _lineDash: null,
  10073. _dashOffset: 0,
  10074. _dashIdx: 0,
  10075. _dashSum: 0,
  10076. /**
  10077. * @readOnly
  10078. */
  10079. setScale: function (sx, sy) {
  10080. this._ux = mathAbs(1 / dpr / sx) || 0;
  10081. this._uy = mathAbs(1 / dpr / sy) || 0;
  10082. },
  10083. getContext: function () {
  10084. return this._ctx;
  10085. },
  10086. /**
  10087. * @param {CanvasRenderingContext2D} ctx
  10088. * @return {module:zrender/core/PathProxy}
  10089. */
  10090. beginPath: function (ctx) {
  10091. this._ctx = ctx;
  10092. ctx && ctx.beginPath();
  10093. // Reset
  10094. this._len = 0;
  10095. if (this._lineDash) {
  10096. this._lineDash = null;
  10097. this._dashOffset = 0;
  10098. }
  10099. return this;
  10100. },
  10101. /**
  10102. * @param {number} x
  10103. * @param {number} y
  10104. * @return {module:zrender/core/PathProxy}
  10105. */
  10106. moveTo: function (x, y) {
  10107. this.addData(CMD.M, x, y);
  10108. this._ctx && this._ctx.moveTo(x, y);
  10109. // x0, y0, xi, yi 是记录在 _dashedXXXXTo 方法中使用
  10110. // xi, yi 记录当前点, x0, y0 在 closePath 的时候回到起始点。
  10111. // 有可能在 beginPath 之后直接调用 lineTo,这时候 x0, y0 需要
  10112. // 在 lineTo 方法中记录,这里先不考虑这种情况,dashed line 也只在 IE10- 中不支持
  10113. this._x0 = x;
  10114. this._y0 = y;
  10115. this._xi = x;
  10116. this._yi = y;
  10117. return this;
  10118. },
  10119. /**
  10120. * @param {number} x
  10121. * @param {number} y
  10122. * @return {module:zrender/core/PathProxy}
  10123. */
  10124. lineTo: function (x, y) {
  10125. var exceedUnit = mathAbs(x - this._xi) > this._ux
  10126. || mathAbs(y - this._yi) > this._uy
  10127. // Force draw the first segment
  10128. || this._len === 0;
  10129. this.addData(CMD.L, x, y);
  10130. if (this._ctx && exceedUnit) {
  10131. this._needsDash() ? this._dashedLineTo(x, y)
  10132. : this._ctx.lineTo(x, y);
  10133. }
  10134. if (exceedUnit) {
  10135. this._xi = x;
  10136. this._yi = y;
  10137. }
  10138. return this;
  10139. },
  10140. /**
  10141. * @param {number} x1
  10142. * @param {number} y1
  10143. * @param {number} x2
  10144. * @param {number} y2
  10145. * @param {number} x3
  10146. * @param {number} y3
  10147. * @return {module:zrender/core/PathProxy}
  10148. */
  10149. bezierCurveTo: function (x1, y1, x2, y2, x3, y3) {
  10150. this.addData(CMD.C, x1, y1, x2, y2, x3, y3);
  10151. if (this._ctx) {
  10152. this._needsDash() ? this._dashedBezierTo(x1, y1, x2, y2, x3, y3)
  10153. : this._ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  10154. }
  10155. this._xi = x3;
  10156. this._yi = y3;
  10157. return this;
  10158. },
  10159. /**
  10160. * @param {number} x1
  10161. * @param {number} y1
  10162. * @param {number} x2
  10163. * @param {number} y2
  10164. * @return {module:zrender/core/PathProxy}
  10165. */
  10166. quadraticCurveTo: function (x1, y1, x2, y2) {
  10167. this.addData(CMD.Q, x1, y1, x2, y2);
  10168. if (this._ctx) {
  10169. this._needsDash() ? this._dashedQuadraticTo(x1, y1, x2, y2)
  10170. : this._ctx.quadraticCurveTo(x1, y1, x2, y2);
  10171. }
  10172. this._xi = x2;
  10173. this._yi = y2;
  10174. return this;
  10175. },
  10176. /**
  10177. * @param {number} cx
  10178. * @param {number} cy
  10179. * @param {number} r
  10180. * @param {number} startAngle
  10181. * @param {number} endAngle
  10182. * @param {boolean} anticlockwise
  10183. * @return {module:zrender/core/PathProxy}
  10184. */
  10185. arc: function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  10186. this.addData(
  10187. CMD.A, cx, cy, r, r, startAngle, endAngle - startAngle, 0, anticlockwise ? 0 : 1
  10188. );
  10189. this._ctx && this._ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  10190. this._xi = mathCos(endAngle) * r + cx;
  10191. this._xi = mathSin(endAngle) * r + cx;
  10192. return this;
  10193. },
  10194. // TODO
  10195. arcTo: function (x1, y1, x2, y2, radius) {
  10196. if (this._ctx) {
  10197. this._ctx.arcTo(x1, y1, x2, y2, radius);
  10198. }
  10199. return this;
  10200. },
  10201. // TODO
  10202. rect: function (x, y, w, h) {
  10203. this._ctx && this._ctx.rect(x, y, w, h);
  10204. this.addData(CMD.R, x, y, w, h);
  10205. return this;
  10206. },
  10207. /**
  10208. * @return {module:zrender/core/PathProxy}
  10209. */
  10210. closePath: function () {
  10211. this.addData(CMD.Z);
  10212. var ctx = this._ctx;
  10213. var x0 = this._x0;
  10214. var y0 = this._y0;
  10215. if (ctx) {
  10216. this._needsDash() && this._dashedLineTo(x0, y0);
  10217. ctx.closePath();
  10218. }
  10219. this._xi = x0;
  10220. this._yi = y0;
  10221. return this;
  10222. },
  10223. /**
  10224. * Context 从外部传入,因为有可能是 rebuildPath 完之后再 fill。
  10225. * stroke 同样
  10226. * @param {CanvasRenderingContext2D} ctx
  10227. * @return {module:zrender/core/PathProxy}
  10228. */
  10229. fill: function (ctx) {
  10230. ctx && ctx.fill();
  10231. this.toStatic();
  10232. },
  10233. /**
  10234. * @param {CanvasRenderingContext2D} ctx
  10235. * @return {module:zrender/core/PathProxy}
  10236. */
  10237. stroke: function (ctx) {
  10238. ctx && ctx.stroke();
  10239. this.toStatic();
  10240. },
  10241. /**
  10242. * 必须在其它绘制命令前调用
  10243. * Must be invoked before all other path drawing methods
  10244. * @return {module:zrender/core/PathProxy}
  10245. */
  10246. setLineDash: function (lineDash) {
  10247. if (lineDash instanceof Array) {
  10248. this._lineDash = lineDash;
  10249. this._dashIdx = 0;
  10250. var lineDashSum = 0;
  10251. for (var i = 0; i < lineDash.length; i++) {
  10252. lineDashSum += lineDash[i];
  10253. }
  10254. this._dashSum = lineDashSum;
  10255. }
  10256. return this;
  10257. },
  10258. /**
  10259. * 必须在其它绘制命令前调用
  10260. * Must be invoked before all other path drawing methods
  10261. * @return {module:zrender/core/PathProxy}
  10262. */
  10263. setLineDashOffset: function (offset) {
  10264. this._dashOffset = offset;
  10265. return this;
  10266. },
  10267. /**
  10268. *
  10269. * @return {boolean}
  10270. */
  10271. len: function () {
  10272. return this._len;
  10273. },
  10274. /**
  10275. * 直接设置 Path 数据
  10276. */
  10277. setData: function (data) {
  10278. var len = data.length;
  10279. if (! (this.data && this.data.length == len) && hasTypedArray) {
  10280. this.data = new Float32Array(len);
  10281. }
  10282. for (var i = 0; i < len; i++) {
  10283. this.data[i] = data[i];
  10284. }
  10285. this._len = len;
  10286. },
  10287. /**
  10288. * 添加子路径
  10289. * @param {module:zrender/core/PathProxy|Array.<module:zrender/core/PathProxy>} path
  10290. */
  10291. appendPath: function (path) {
  10292. if (!(path instanceof Array)) {
  10293. path = [path];
  10294. }
  10295. var len = path.length;
  10296. var appendSize = 0;
  10297. var offset = this._len;
  10298. for (var i = 0; i < len; i++) {
  10299. appendSize += path[i].len();
  10300. }
  10301. if (hasTypedArray && (this.data instanceof Float32Array)) {
  10302. this.data = new Float32Array(offset + appendSize);
  10303. }
  10304. for (var i = 0; i < len; i++) {
  10305. var appendPathData = path[i].data;
  10306. for (var k = 0; k < appendPathData.length; k++) {
  10307. this.data[offset++] = appendPathData[k];
  10308. }
  10309. }
  10310. this._len = offset;
  10311. },
  10312. /**
  10313. * 填充 Path 数据。
  10314. * 尽量复用而不申明新的数组。大部分图形重绘的指令数据长度都是不变的。
  10315. */
  10316. addData: function (cmd) {
  10317. var data = this.data;
  10318. if (this._len + arguments.length > data.length) {
  10319. // 因为之前的数组已经转换成静态的 Float32Array
  10320. // 所以不够用时需要扩展一个新的动态数组
  10321. this._expandData();
  10322. data = this.data;
  10323. }
  10324. for (var i = 0; i < arguments.length; i++) {
  10325. data[this._len++] = arguments[i];
  10326. }
  10327. this._prevCmd = cmd;
  10328. },
  10329. _expandData: function () {
  10330. // Only if data is Float32Array
  10331. if (!(this.data instanceof Array)) {
  10332. var newData = [];
  10333. for (var i = 0; i < this._len; i++) {
  10334. newData[i] = this.data[i];
  10335. }
  10336. this.data = newData;
  10337. }
  10338. },
  10339. /**
  10340. * If needs js implemented dashed line
  10341. * @return {boolean}
  10342. * @private
  10343. */
  10344. _needsDash: function () {
  10345. return this._lineDash;
  10346. },
  10347. _dashedLineTo: function (x1, y1) {
  10348. var dashSum = this._dashSum;
  10349. var offset = this._dashOffset;
  10350. var lineDash = this._lineDash;
  10351. var ctx = this._ctx;
  10352. var x0 = this._xi;
  10353. var y0 = this._yi;
  10354. var dx = x1 - x0;
  10355. var dy = y1 - y0;
  10356. var dist = mathSqrt(dx * dx + dy * dy);
  10357. var x = x0;
  10358. var y = y0;
  10359. var dash;
  10360. var nDash = lineDash.length;
  10361. var idx;
  10362. dx /= dist;
  10363. dy /= dist;
  10364. if (offset < 0) {
  10365. // Convert to positive offset
  10366. offset = dashSum + offset;
  10367. }
  10368. offset %= dashSum;
  10369. x -= offset * dx;
  10370. y -= offset * dy;
  10371. while ((dx >= 0 && x <= x1) || (dx < 0 && x > x1)) {
  10372. idx = this._dashIdx;
  10373. dash = lineDash[idx];
  10374. x += dx * dash;
  10375. y += dy * dash;
  10376. this._dashIdx = (idx + 1) % nDash;
  10377. // Skip positive offset
  10378. if ((dx > 0 && x < x0) || (dx < 0 && x > x0)) {
  10379. continue;
  10380. }
  10381. ctx[idx % 2 ? 'moveTo' : 'lineTo'](
  10382. dx >= 0 ? mathMin(x, x1) : mathMax(x, x1),
  10383. dy >= 0 ? mathMin(y, y1) : mathMax(y, y1)
  10384. );
  10385. }
  10386. // Offset for next lineTo
  10387. dx = x - x1;
  10388. dy = y - y1;
  10389. this._dashOffset = -mathSqrt(dx * dx + dy * dy);
  10390. },
  10391. // Not accurate dashed line to
  10392. _dashedBezierTo: function (x1, y1, x2, y2, x3, y3) {
  10393. var dashSum = this._dashSum;
  10394. var offset = this._dashOffset;
  10395. var lineDash = this._lineDash;
  10396. var ctx = this._ctx;
  10397. var x0 = this._xi;
  10398. var y0 = this._yi;
  10399. var t;
  10400. var dx;
  10401. var dy;
  10402. var cubicAt = curve.cubicAt;
  10403. var bezierLen = 0;
  10404. var idx = this._dashIdx;
  10405. var nDash = lineDash.length;
  10406. var x;
  10407. var y;
  10408. var tmpLen = 0;
  10409. if (offset < 0) {
  10410. // Convert to positive offset
  10411. offset = dashSum + offset;
  10412. }
  10413. offset %= dashSum;
  10414. // Bezier approx length
  10415. for (t = 0; t < 1; t += 0.1) {
  10416. dx = cubicAt(x0, x1, x2, x3, t + 0.1)
  10417. - cubicAt(x0, x1, x2, x3, t);
  10418. dy = cubicAt(y0, y1, y2, y3, t + 0.1)
  10419. - cubicAt(y0, y1, y2, y3, t);
  10420. bezierLen += mathSqrt(dx * dx + dy * dy);
  10421. }
  10422. // Find idx after add offset
  10423. for (; idx < nDash; idx++) {
  10424. tmpLen += lineDash[idx];
  10425. if (tmpLen > offset) {
  10426. break;
  10427. }
  10428. }
  10429. t = (tmpLen - offset) / bezierLen;
  10430. while (t <= 1) {
  10431. x = cubicAt(x0, x1, x2, x3, t);
  10432. y = cubicAt(y0, y1, y2, y3, t);
  10433. // Use line to approximate dashed bezier
  10434. // Bad result if dash is long
  10435. idx % 2 ? ctx.moveTo(x, y)
  10436. : ctx.lineTo(x, y);
  10437. t += lineDash[idx] / bezierLen;
  10438. idx = (idx + 1) % nDash;
  10439. }
  10440. // Finish the last segment and calculate the new offset
  10441. (idx % 2 !== 0) && ctx.lineTo(x3, y3);
  10442. dx = x3 - x;
  10443. dy = y3 - y;
  10444. this._dashOffset = -mathSqrt(dx * dx + dy * dy);
  10445. },
  10446. _dashedQuadraticTo: function (x1, y1, x2, y2) {
  10447. // Convert quadratic to cubic using degree elevation
  10448. var x3 = x2;
  10449. var y3 = y2;
  10450. x2 = (x2 + 2 * x1) / 3;
  10451. y2 = (y2 + 2 * y1) / 3;
  10452. x1 = (this._xi + 2 * x1) / 3;
  10453. y1 = (this._yi + 2 * y1) / 3;
  10454. this._dashedBezierTo(x1, y1, x2, y2, x3, y3);
  10455. },
  10456. /**
  10457. * 转成静态的 Float32Array 减少堆内存占用
  10458. * Convert dynamic array to static Float32Array
  10459. */
  10460. toStatic: function () {
  10461. var data = this.data;
  10462. if (data instanceof Array) {
  10463. data.length = this._len;
  10464. if (hasTypedArray) {
  10465. this.data = new Float32Array(data);
  10466. }
  10467. }
  10468. },
  10469. /**
  10470. * @return {module:zrender/core/BoundingRect}
  10471. */
  10472. getBoundingRect: function () {
  10473. min[0] = min[1] = min2[0] = min2[1] = Number.MAX_VALUE;
  10474. max[0] = max[1] = max2[0] = max2[1] = -Number.MAX_VALUE;
  10475. var data = this.data;
  10476. var xi = 0;
  10477. var yi = 0;
  10478. var x0 = 0;
  10479. var y0 = 0;
  10480. for (var i = 0; i < data.length;) {
  10481. var cmd = data[i++];
  10482. if (i == 1) {
  10483. // 如果第一个命令是 L, C, Q
  10484. // 则 previous point 同绘制命令的第一个 point
  10485. //
  10486. // 第一个命令为 Arc 的情况下会在后面特殊处理
  10487. xi = data[i];
  10488. yi = data[i + 1];
  10489. x0 = xi;
  10490. y0 = yi;
  10491. }
  10492. switch (cmd) {
  10493. case CMD.M:
  10494. // moveTo 命令重新创建一个新的 subpath, 并且更新新的起点
  10495. // 在 closePath 的时候使用
  10496. x0 = data[i++];
  10497. y0 = data[i++];
  10498. xi = x0;
  10499. yi = y0;
  10500. min2[0] = x0;
  10501. min2[1] = y0;
  10502. max2[0] = x0;
  10503. max2[1] = y0;
  10504. break;
  10505. case CMD.L:
  10506. bbox.fromLine(xi, yi, data[i], data[i + 1], min2, max2);
  10507. xi = data[i++];
  10508. yi = data[i++];
  10509. break;
  10510. case CMD.C:
  10511. bbox.fromCubic(
  10512. xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],
  10513. min2, max2
  10514. );
  10515. xi = data[i++];
  10516. yi = data[i++];
  10517. break;
  10518. case CMD.Q:
  10519. bbox.fromQuadratic(
  10520. xi, yi, data[i++], data[i++], data[i], data[i + 1],
  10521. min2, max2
  10522. );
  10523. xi = data[i++];
  10524. yi = data[i++];
  10525. break;
  10526. case CMD.A:
  10527. // TODO Arc 判断的开销比较大
  10528. var cx = data[i++];
  10529. var cy = data[i++];
  10530. var rx = data[i++];
  10531. var ry = data[i++];
  10532. var startAngle = data[i++];
  10533. var endAngle = data[i++] + startAngle;
  10534. // TODO Arc 旋转
  10535. var psi = data[i++];
  10536. var anticlockwise = 1 - data[i++];
  10537. if (i == 1) {
  10538. // 直接使用 arc 命令
  10539. // 第一个命令起点还未定义
  10540. x0 = mathCos(startAngle) * rx + cx;
  10541. y0 = mathSin(startAngle) * ry + cy;
  10542. }
  10543. bbox.fromArc(
  10544. cx, cy, rx, ry, startAngle, endAngle,
  10545. anticlockwise, min2, max2
  10546. );
  10547. xi = mathCos(endAngle) * rx + cx;
  10548. yi = mathSin(endAngle) * ry + cy;
  10549. break;
  10550. case CMD.R:
  10551. x0 = xi = data[i++];
  10552. y0 = yi = data[i++];
  10553. var width = data[i++];
  10554. var height = data[i++];
  10555. // Use fromLine
  10556. bbox.fromLine(x0, y0, x0 + width, y0 + height, min2, max2);
  10557. break;
  10558. case CMD.Z:
  10559. xi = x0;
  10560. yi = y0;
  10561. break;
  10562. }
  10563. // Union
  10564. vec2.min(min, min, min2);
  10565. vec2.max(max, max, max2);
  10566. }
  10567. // No data
  10568. if (i === 0) {
  10569. min[0] = min[1] = max[0] = max[1] = 0;
  10570. }
  10571. return new BoundingRect(
  10572. min[0], min[1], max[0] - min[0], max[1] - min[1]
  10573. );
  10574. },
  10575. /**
  10576. * Rebuild path from current data
  10577. * Rebuild path will not consider javascript implemented line dash.
  10578. * @param {CanvasRenderingContext} ctx
  10579. */
  10580. rebuildPath: function (ctx) {
  10581. var d = this.data;
  10582. var x0, y0;
  10583. var xi, yi;
  10584. var x, y;
  10585. var ux = this._ux;
  10586. var uy = this._uy;
  10587. var len = this._len;
  10588. for (var i = 0; i < len;) {
  10589. var cmd = d[i++];
  10590. if (i == 1) {
  10591. // 如果第一个命令是 L, C, Q
  10592. // 则 previous point 同绘制命令的第一个 point
  10593. //
  10594. // 第一个命令为 Arc 的情况下会在后面特殊处理
  10595. xi = d[i];
  10596. yi = d[i + 1];
  10597. x0 = xi;
  10598. y0 = yi;
  10599. }
  10600. switch (cmd) {
  10601. case CMD.M:
  10602. x0 = xi = d[i++];
  10603. y0 = yi = d[i++];
  10604. ctx.moveTo(xi, yi);
  10605. break;
  10606. case CMD.L:
  10607. x = d[i++];
  10608. y = d[i++];
  10609. // Not draw too small seg between
  10610. if (mathAbs(x - xi) > ux || mathAbs(y - yi) > uy || i === len - 1) {
  10611. ctx.lineTo(x, y);
  10612. xi = x;
  10613. yi = y;
  10614. }
  10615. break;
  10616. case CMD.C:
  10617. ctx.bezierCurveTo(
  10618. d[i++], d[i++], d[i++], d[i++], d[i++], d[i++]
  10619. );
  10620. xi = d[i - 2];
  10621. yi = d[i - 1];
  10622. break;
  10623. case CMD.Q:
  10624. ctx.quadraticCurveTo(d[i++], d[i++], d[i++], d[i++]);
  10625. xi = d[i - 2];
  10626. yi = d[i - 1];
  10627. break;
  10628. case CMD.A:
  10629. var cx = d[i++];
  10630. var cy = d[i++];
  10631. var rx = d[i++];
  10632. var ry = d[i++];
  10633. var theta = d[i++];
  10634. var dTheta = d[i++];
  10635. var psi = d[i++];
  10636. var fs = d[i++];
  10637. var r = (rx > ry) ? rx : ry;
  10638. var scaleX = (rx > ry) ? 1 : rx / ry;
  10639. var scaleY = (rx > ry) ? ry / rx : 1;
  10640. var isEllipse = Math.abs(rx - ry) > 1e-3;
  10641. var endAngle = theta + dTheta;
  10642. if (isEllipse) {
  10643. ctx.translate(cx, cy);
  10644. ctx.rotate(psi);
  10645. ctx.scale(scaleX, scaleY);
  10646. ctx.arc(0, 0, r, theta, endAngle, 1 - fs);
  10647. ctx.scale(1 / scaleX, 1 / scaleY);
  10648. ctx.rotate(-psi);
  10649. ctx.translate(-cx, -cy);
  10650. }
  10651. else {
  10652. ctx.arc(cx, cy, r, theta, endAngle, 1 - fs);
  10653. }
  10654. if (i == 1) {
  10655. // 直接使用 arc 命令
  10656. // 第一个命令起点还未定义
  10657. x0 = mathCos(theta) * rx + cx;
  10658. y0 = mathSin(theta) * ry + cy;
  10659. }
  10660. xi = mathCos(endAngle) * rx + cx;
  10661. yi = mathSin(endAngle) * ry + cy;
  10662. break;
  10663. case CMD.R:
  10664. x0 = xi = d[i];
  10665. y0 = yi = d[i + 1];
  10666. ctx.rect(d[i++], d[i++], d[i++], d[i++]);
  10667. break;
  10668. case CMD.Z:
  10669. ctx.closePath();
  10670. xi = x0;
  10671. yi = y0;
  10672. }
  10673. }
  10674. }
  10675. };
  10676. PathProxy.CMD = CMD;
  10677. module.exports = PathProxy;
  10678. /***/ },
  10679. /* 49 */
  10680. /***/ function(module, exports, __webpack_require__) {
  10681. 'use strict';
  10682. /**
  10683. * 曲线辅助模块
  10684. * @module zrender/core/curve
  10685. * @author pissang(https://www.github.com/pissang)
  10686. */
  10687. var vec2 = __webpack_require__(16);
  10688. var v2Create = vec2.create;
  10689. var v2DistSquare = vec2.distSquare;
  10690. var mathPow = Math.pow;
  10691. var mathSqrt = Math.sqrt;
  10692. var EPSILON = 1e-8;
  10693. var EPSILON_NUMERIC = 1e-4;
  10694. var THREE_SQRT = mathSqrt(3);
  10695. var ONE_THIRD = 1 / 3;
  10696. // 临时变量
  10697. var _v0 = v2Create();
  10698. var _v1 = v2Create();
  10699. var _v2 = v2Create();
  10700. // var _v3 = vec2.create();
  10701. function isAroundZero(val) {
  10702. return val > -EPSILON && val < EPSILON;
  10703. }
  10704. function isNotAroundZero(val) {
  10705. return val > EPSILON || val < -EPSILON;
  10706. }
  10707. /**
  10708. * 计算三次贝塞尔值
  10709. * @memberOf module:zrender/core/curve
  10710. * @param {number} p0
  10711. * @param {number} p1
  10712. * @param {number} p2
  10713. * @param {number} p3
  10714. * @param {number} t
  10715. * @return {number}
  10716. */
  10717. function cubicAt(p0, p1, p2, p3, t) {
  10718. var onet = 1 - t;
  10719. return onet * onet * (onet * p0 + 3 * t * p1)
  10720. + t * t * (t * p3 + 3 * onet * p2);
  10721. }
  10722. /**
  10723. * 计算三次贝塞尔导数值
  10724. * @memberOf module:zrender/core/curve
  10725. * @param {number} p0
  10726. * @param {number} p1
  10727. * @param {number} p2
  10728. * @param {number} p3
  10729. * @param {number} t
  10730. * @return {number}
  10731. */
  10732. function cubicDerivativeAt(p0, p1, p2, p3, t) {
  10733. var onet = 1 - t;
  10734. return 3 * (
  10735. ((p1 - p0) * onet + 2 * (p2 - p1) * t) * onet
  10736. + (p3 - p2) * t * t
  10737. );
  10738. }
  10739. /**
  10740. * 计算三次贝塞尔方程根,使用盛金公式
  10741. * @memberOf module:zrender/core/curve
  10742. * @param {number} p0
  10743. * @param {number} p1
  10744. * @param {number} p2
  10745. * @param {number} p3
  10746. * @param {number} val
  10747. * @param {Array.<number>} roots
  10748. * @return {number} 有效根数目
  10749. */
  10750. function cubicRootAt(p0, p1, p2, p3, val, roots) {
  10751. // Evaluate roots of cubic functions
  10752. var a = p3 + 3 * (p1 - p2) - p0;
  10753. var b = 3 * (p2 - p1 * 2 + p0);
  10754. var c = 3 * (p1 - p0);
  10755. var d = p0 - val;
  10756. var A = b * b - 3 * a * c;
  10757. var B = b * c - 9 * a * d;
  10758. var C = c * c - 3 * b * d;
  10759. var n = 0;
  10760. if (isAroundZero(A) && isAroundZero(B)) {
  10761. if (isAroundZero(b)) {
  10762. roots[0] = 0;
  10763. }
  10764. else {
  10765. var t1 = -c / b; //t1, t2, t3, b is not zero
  10766. if (t1 >= 0 && t1 <= 1) {
  10767. roots[n++] = t1;
  10768. }
  10769. }
  10770. }
  10771. else {
  10772. var disc = B * B - 4 * A * C;
  10773. if (isAroundZero(disc)) {
  10774. var K = B / A;
  10775. var t1 = -b / a + K; // t1, a is not zero
  10776. var t2 = -K / 2; // t2, t3
  10777. if (t1 >= 0 && t1 <= 1) {
  10778. roots[n++] = t1;
  10779. }
  10780. if (t2 >= 0 && t2 <= 1) {
  10781. roots[n++] = t2;
  10782. }
  10783. }
  10784. else if (disc > 0) {
  10785. var discSqrt = mathSqrt(disc);
  10786. var Y1 = A * b + 1.5 * a * (-B + discSqrt);
  10787. var Y2 = A * b + 1.5 * a * (-B - discSqrt);
  10788. if (Y1 < 0) {
  10789. Y1 = -mathPow(-Y1, ONE_THIRD);
  10790. }
  10791. else {
  10792. Y1 = mathPow(Y1, ONE_THIRD);
  10793. }
  10794. if (Y2 < 0) {
  10795. Y2 = -mathPow(-Y2, ONE_THIRD);
  10796. }
  10797. else {
  10798. Y2 = mathPow(Y2, ONE_THIRD);
  10799. }
  10800. var t1 = (-b - (Y1 + Y2)) / (3 * a);
  10801. if (t1 >= 0 && t1 <= 1) {
  10802. roots[n++] = t1;
  10803. }
  10804. }
  10805. else {
  10806. var T = (2 * A * b - 3 * a * B) / (2 * mathSqrt(A * A * A));
  10807. var theta = Math.acos(T) / 3;
  10808. var ASqrt = mathSqrt(A);
  10809. var tmp = Math.cos(theta);
  10810. var t1 = (-b - 2 * ASqrt * tmp) / (3 * a);
  10811. var t2 = (-b + ASqrt * (tmp + THREE_SQRT * Math.sin(theta))) / (3 * a);
  10812. var t3 = (-b + ASqrt * (tmp - THREE_SQRT * Math.sin(theta))) / (3 * a);
  10813. if (t1 >= 0 && t1 <= 1) {
  10814. roots[n++] = t1;
  10815. }
  10816. if (t2 >= 0 && t2 <= 1) {
  10817. roots[n++] = t2;
  10818. }
  10819. if (t3 >= 0 && t3 <= 1) {
  10820. roots[n++] = t3;
  10821. }
  10822. }
  10823. }
  10824. return n;
  10825. }
  10826. /**
  10827. * 计算三次贝塞尔方程极限值的位置
  10828. * @memberOf module:zrender/core/curve
  10829. * @param {number} p0
  10830. * @param {number} p1
  10831. * @param {number} p2
  10832. * @param {number} p3
  10833. * @param {Array.<number>} extrema
  10834. * @return {number} 有效数目
  10835. */
  10836. function cubicExtrema(p0, p1, p2, p3, extrema) {
  10837. var b = 6 * p2 - 12 * p1 + 6 * p0;
  10838. var a = 9 * p1 + 3 * p3 - 3 * p0 - 9 * p2;
  10839. var c = 3 * p1 - 3 * p0;
  10840. var n = 0;
  10841. if (isAroundZero(a)) {
  10842. if (isNotAroundZero(b)) {
  10843. var t1 = -c / b;
  10844. if (t1 >= 0 && t1 <=1) {
  10845. extrema[n++] = t1;
  10846. }
  10847. }
  10848. }
  10849. else {
  10850. var disc = b * b - 4 * a * c;
  10851. if (isAroundZero(disc)) {
  10852. extrema[0] = -b / (2 * a);
  10853. }
  10854. else if (disc > 0) {
  10855. var discSqrt = mathSqrt(disc);
  10856. var t1 = (-b + discSqrt) / (2 * a);
  10857. var t2 = (-b - discSqrt) / (2 * a);
  10858. if (t1 >= 0 && t1 <= 1) {
  10859. extrema[n++] = t1;
  10860. }
  10861. if (t2 >= 0 && t2 <= 1) {
  10862. extrema[n++] = t2;
  10863. }
  10864. }
  10865. }
  10866. return n;
  10867. }
  10868. /**
  10869. * 细分三次贝塞尔曲线
  10870. * @memberOf module:zrender/core/curve
  10871. * @param {number} p0
  10872. * @param {number} p1
  10873. * @param {number} p2
  10874. * @param {number} p3
  10875. * @param {number} t
  10876. * @param {Array.<number>} out
  10877. */
  10878. function cubicSubdivide(p0, p1, p2, p3, t, out) {
  10879. var p01 = (p1 - p0) * t + p0;
  10880. var p12 = (p2 - p1) * t + p1;
  10881. var p23 = (p3 - p2) * t + p2;
  10882. var p012 = (p12 - p01) * t + p01;
  10883. var p123 = (p23 - p12) * t + p12;
  10884. var p0123 = (p123 - p012) * t + p012;
  10885. // Seg0
  10886. out[0] = p0;
  10887. out[1] = p01;
  10888. out[2] = p012;
  10889. out[3] = p0123;
  10890. // Seg1
  10891. out[4] = p0123;
  10892. out[5] = p123;
  10893. out[6] = p23;
  10894. out[7] = p3;
  10895. }
  10896. /**
  10897. * 投射点到三次贝塞尔曲线上,返回投射距离。
  10898. * 投射点有可能会有一个或者多个,这里只返回其中距离最短的一个。
  10899. * @param {number} x0
  10900. * @param {number} y0
  10901. * @param {number} x1
  10902. * @param {number} y1
  10903. * @param {number} x2
  10904. * @param {number} y2
  10905. * @param {number} x3
  10906. * @param {number} y3
  10907. * @param {number} x
  10908. * @param {number} y
  10909. * @param {Array.<number>} [out] 投射点
  10910. * @return {number}
  10911. */
  10912. function cubicProjectPoint(
  10913. x0, y0, x1, y1, x2, y2, x3, y3,
  10914. x, y, out
  10915. ) {
  10916. // http://pomax.github.io/bezierinfo/#projections
  10917. var t;
  10918. var interval = 0.005;
  10919. var d = Infinity;
  10920. var prev;
  10921. var next;
  10922. var d1;
  10923. var d2;
  10924. _v0[0] = x;
  10925. _v0[1] = y;
  10926. // 先粗略估计一下可能的最小距离的 t 值
  10927. // PENDING
  10928. for (var _t = 0; _t < 1; _t += 0.05) {
  10929. _v1[0] = cubicAt(x0, x1, x2, x3, _t);
  10930. _v1[1] = cubicAt(y0, y1, y2, y3, _t);
  10931. d1 = v2DistSquare(_v0, _v1);
  10932. if (d1 < d) {
  10933. t = _t;
  10934. d = d1;
  10935. }
  10936. }
  10937. d = Infinity;
  10938. // At most 32 iteration
  10939. for (var i = 0; i < 32; i++) {
  10940. if (interval < EPSILON_NUMERIC) {
  10941. break;
  10942. }
  10943. prev = t - interval;
  10944. next = t + interval;
  10945. // t - interval
  10946. _v1[0] = cubicAt(x0, x1, x2, x3, prev);
  10947. _v1[1] = cubicAt(y0, y1, y2, y3, prev);
  10948. d1 = v2DistSquare(_v1, _v0);
  10949. if (prev >= 0 && d1 < d) {
  10950. t = prev;
  10951. d = d1;
  10952. }
  10953. else {
  10954. // t + interval
  10955. _v2[0] = cubicAt(x0, x1, x2, x3, next);
  10956. _v2[1] = cubicAt(y0, y1, y2, y3, next);
  10957. d2 = v2DistSquare(_v2, _v0);
  10958. if (next <= 1 && d2 < d) {
  10959. t = next;
  10960. d = d2;
  10961. }
  10962. else {
  10963. interval *= 0.5;
  10964. }
  10965. }
  10966. }
  10967. // t
  10968. if (out) {
  10969. out[0] = cubicAt(x0, x1, x2, x3, t);
  10970. out[1] = cubicAt(y0, y1, y2, y3, t);
  10971. }
  10972. // console.log(interval, i);
  10973. return mathSqrt(d);
  10974. }
  10975. /**
  10976. * 计算二次方贝塞尔值
  10977. * @param {number} p0
  10978. * @param {number} p1
  10979. * @param {number} p2
  10980. * @param {number} t
  10981. * @return {number}
  10982. */
  10983. function quadraticAt(p0, p1, p2, t) {
  10984. var onet = 1 - t;
  10985. return onet * (onet * p0 + 2 * t * p1) + t * t * p2;
  10986. }
  10987. /**
  10988. * 计算二次方贝塞尔导数值
  10989. * @param {number} p0
  10990. * @param {number} p1
  10991. * @param {number} p2
  10992. * @param {number} t
  10993. * @return {number}
  10994. */
  10995. function quadraticDerivativeAt(p0, p1, p2, t) {
  10996. return 2 * ((1 - t) * (p1 - p0) + t * (p2 - p1));
  10997. }
  10998. /**
  10999. * 计算二次方贝塞尔方程根
  11000. * @param {number} p0
  11001. * @param {number} p1
  11002. * @param {number} p2
  11003. * @param {number} t
  11004. * @param {Array.<number>} roots
  11005. * @return {number} 有效根数目
  11006. */
  11007. function quadraticRootAt(p0, p1, p2, val, roots) {
  11008. var a = p0 - 2 * p1 + p2;
  11009. var b = 2 * (p1 - p0);
  11010. var c = p0 - val;
  11011. var n = 0;
  11012. if (isAroundZero(a)) {
  11013. if (isNotAroundZero(b)) {
  11014. var t1 = -c / b;
  11015. if (t1 >= 0 && t1 <= 1) {
  11016. roots[n++] = t1;
  11017. }
  11018. }
  11019. }
  11020. else {
  11021. var disc = b * b - 4 * a * c;
  11022. if (isAroundZero(disc)) {
  11023. var t1 = -b / (2 * a);
  11024. if (t1 >= 0 && t1 <= 1) {
  11025. roots[n++] = t1;
  11026. }
  11027. }
  11028. else if (disc > 0) {
  11029. var discSqrt = mathSqrt(disc);
  11030. var t1 = (-b + discSqrt) / (2 * a);
  11031. var t2 = (-b - discSqrt) / (2 * a);
  11032. if (t1 >= 0 && t1 <= 1) {
  11033. roots[n++] = t1;
  11034. }
  11035. if (t2 >= 0 && t2 <= 1) {
  11036. roots[n++] = t2;
  11037. }
  11038. }
  11039. }
  11040. return n;
  11041. }
  11042. /**
  11043. * 计算二次贝塞尔方程极限值
  11044. * @memberOf module:zrender/core/curve
  11045. * @param {number} p0
  11046. * @param {number} p1
  11047. * @param {number} p2
  11048. * @return {number}
  11049. */
  11050. function quadraticExtremum(p0, p1, p2) {
  11051. var divider = p0 + p2 - 2 * p1;
  11052. if (divider === 0) {
  11053. // p1 is center of p0 and p2
  11054. return 0.5;
  11055. }
  11056. else {
  11057. return (p0 - p1) / divider;
  11058. }
  11059. }
  11060. /**
  11061. * 细分二次贝塞尔曲线
  11062. * @memberOf module:zrender/core/curve
  11063. * @param {number} p0
  11064. * @param {number} p1
  11065. * @param {number} p2
  11066. * @param {number} t
  11067. * @param {Array.<number>} out
  11068. */
  11069. function quadraticSubdivide(p0, p1, p2, t, out) {
  11070. var p01 = (p1 - p0) * t + p0;
  11071. var p12 = (p2 - p1) * t + p1;
  11072. var p012 = (p12 - p01) * t + p01;
  11073. // Seg0
  11074. out[0] = p0;
  11075. out[1] = p01;
  11076. out[2] = p012;
  11077. // Seg1
  11078. out[3] = p012;
  11079. out[4] = p12;
  11080. out[5] = p2;
  11081. }
  11082. /**
  11083. * 投射点到二次贝塞尔曲线上,返回投射距离。
  11084. * 投射点有可能会有一个或者多个,这里只返回其中距离最短的一个。
  11085. * @param {number} x0
  11086. * @param {number} y0
  11087. * @param {number} x1
  11088. * @param {number} y1
  11089. * @param {number} x2
  11090. * @param {number} y2
  11091. * @param {number} x
  11092. * @param {number} y
  11093. * @param {Array.<number>} out 投射点
  11094. * @return {number}
  11095. */
  11096. function quadraticProjectPoint(
  11097. x0, y0, x1, y1, x2, y2,
  11098. x, y, out
  11099. ) {
  11100. // http://pomax.github.io/bezierinfo/#projections
  11101. var t;
  11102. var interval = 0.005;
  11103. var d = Infinity;
  11104. _v0[0] = x;
  11105. _v0[1] = y;
  11106. // 先粗略估计一下可能的最小距离的 t 值
  11107. // PENDING
  11108. for (var _t = 0; _t < 1; _t += 0.05) {
  11109. _v1[0] = quadraticAt(x0, x1, x2, _t);
  11110. _v1[1] = quadraticAt(y0, y1, y2, _t);
  11111. var d1 = v2DistSquare(_v0, _v1);
  11112. if (d1 < d) {
  11113. t = _t;
  11114. d = d1;
  11115. }
  11116. }
  11117. d = Infinity;
  11118. // At most 32 iteration
  11119. for (var i = 0; i < 32; i++) {
  11120. if (interval < EPSILON_NUMERIC) {
  11121. break;
  11122. }
  11123. var prev = t - interval;
  11124. var next = t + interval;
  11125. // t - interval
  11126. _v1[0] = quadraticAt(x0, x1, x2, prev);
  11127. _v1[1] = quadraticAt(y0, y1, y2, prev);
  11128. var d1 = v2DistSquare(_v1, _v0);
  11129. if (prev >= 0 && d1 < d) {
  11130. t = prev;
  11131. d = d1;
  11132. }
  11133. else {
  11134. // t + interval
  11135. _v2[0] = quadraticAt(x0, x1, x2, next);
  11136. _v2[1] = quadraticAt(y0, y1, y2, next);
  11137. var d2 = v2DistSquare(_v2, _v0);
  11138. if (next <= 1 && d2 < d) {
  11139. t = next;
  11140. d = d2;
  11141. }
  11142. else {
  11143. interval *= 0.5;
  11144. }
  11145. }
  11146. }
  11147. // t
  11148. if (out) {
  11149. out[0] = quadraticAt(x0, x1, x2, t);
  11150. out[1] = quadraticAt(y0, y1, y2, t);
  11151. }
  11152. // console.log(interval, i);
  11153. return mathSqrt(d);
  11154. }
  11155. module.exports = {
  11156. cubicAt: cubicAt,
  11157. cubicDerivativeAt: cubicDerivativeAt,
  11158. cubicRootAt: cubicRootAt,
  11159. cubicExtrema: cubicExtrema,
  11160. cubicSubdivide: cubicSubdivide,
  11161. cubicProjectPoint: cubicProjectPoint,
  11162. quadraticAt: quadraticAt,
  11163. quadraticDerivativeAt: quadraticDerivativeAt,
  11164. quadraticRootAt: quadraticRootAt,
  11165. quadraticExtremum: quadraticExtremum,
  11166. quadraticSubdivide: quadraticSubdivide,
  11167. quadraticProjectPoint: quadraticProjectPoint
  11168. };
  11169. /***/ },
  11170. /* 50 */
  11171. /***/ function(module, exports, __webpack_require__) {
  11172. /**
  11173. * @author Yi Shen(https://github.com/pissang)
  11174. */
  11175. var vec2 = __webpack_require__(16);
  11176. var curve = __webpack_require__(49);
  11177. var bbox = {};
  11178. var mathMin = Math.min;
  11179. var mathMax = Math.max;
  11180. var mathSin = Math.sin;
  11181. var mathCos = Math.cos;
  11182. var start = vec2.create();
  11183. var end = vec2.create();
  11184. var extremity = vec2.create();
  11185. var PI2 = Math.PI * 2;
  11186. /**
  11187. * 从顶点数组中计算出最小包围盒,写入`min`和`max`中
  11188. * @module zrender/core/bbox
  11189. * @param {Array<Object>} points 顶点数组
  11190. * @param {number} min
  11191. * @param {number} max
  11192. */
  11193. bbox.fromPoints = function(points, min, max) {
  11194. if (points.length === 0) {
  11195. return;
  11196. }
  11197. var p = points[0];
  11198. var left = p[0];
  11199. var right = p[0];
  11200. var top = p[1];
  11201. var bottom = p[1];
  11202. var i;
  11203. for (i = 1; i < points.length; i++) {
  11204. p = points[i];
  11205. left = mathMin(left, p[0]);
  11206. right = mathMax(right, p[0]);
  11207. top = mathMin(top, p[1]);
  11208. bottom = mathMax(bottom, p[1]);
  11209. }
  11210. min[0] = left;
  11211. min[1] = top;
  11212. max[0] = right;
  11213. max[1] = bottom;
  11214. };
  11215. /**
  11216. * @memberOf module:zrender/core/bbox
  11217. * @param {number} x0
  11218. * @param {number} y0
  11219. * @param {number} x1
  11220. * @param {number} y1
  11221. * @param {Array.<number>} min
  11222. * @param {Array.<number>} max
  11223. */
  11224. bbox.fromLine = function (x0, y0, x1, y1, min, max) {
  11225. min[0] = mathMin(x0, x1);
  11226. min[1] = mathMin(y0, y1);
  11227. max[0] = mathMax(x0, x1);
  11228. max[1] = mathMax(y0, y1);
  11229. };
  11230. var xDim = [];
  11231. var yDim = [];
  11232. /**
  11233. * 从三阶贝塞尔曲线(p0, p1, p2, p3)中计算出最小包围盒,写入`min`和`max`中
  11234. * @memberOf module:zrender/core/bbox
  11235. * @param {number} x0
  11236. * @param {number} y0
  11237. * @param {number} x1
  11238. * @param {number} y1
  11239. * @param {number} x2
  11240. * @param {number} y2
  11241. * @param {number} x3
  11242. * @param {number} y3
  11243. * @param {Array.<number>} min
  11244. * @param {Array.<number>} max
  11245. */
  11246. bbox.fromCubic = function(
  11247. x0, y0, x1, y1, x2, y2, x3, y3, min, max
  11248. ) {
  11249. var cubicExtrema = curve.cubicExtrema;
  11250. var cubicAt = curve.cubicAt;
  11251. var i;
  11252. var n = cubicExtrema(x0, x1, x2, x3, xDim);
  11253. min[0] = Infinity;
  11254. min[1] = Infinity;
  11255. max[0] = -Infinity;
  11256. max[1] = -Infinity;
  11257. for (i = 0; i < n; i++) {
  11258. var x = cubicAt(x0, x1, x2, x3, xDim[i]);
  11259. min[0] = mathMin(x, min[0]);
  11260. max[0] = mathMax(x, max[0]);
  11261. }
  11262. n = cubicExtrema(y0, y1, y2, y3, yDim);
  11263. for (i = 0; i < n; i++) {
  11264. var y = cubicAt(y0, y1, y2, y3, yDim[i]);
  11265. min[1] = mathMin(y, min[1]);
  11266. max[1] = mathMax(y, max[1]);
  11267. }
  11268. min[0] = mathMin(x0, min[0]);
  11269. max[0] = mathMax(x0, max[0]);
  11270. min[0] = mathMin(x3, min[0]);
  11271. max[0] = mathMax(x3, max[0]);
  11272. min[1] = mathMin(y0, min[1]);
  11273. max[1] = mathMax(y0, max[1]);
  11274. min[1] = mathMin(y3, min[1]);
  11275. max[1] = mathMax(y3, max[1]);
  11276. };
  11277. /**
  11278. * 从二阶贝塞尔曲线(p0, p1, p2)中计算出最小包围盒,写入`min`和`max`中
  11279. * @memberOf module:zrender/core/bbox
  11280. * @param {number} x0
  11281. * @param {number} y0
  11282. * @param {number} x1
  11283. * @param {number} y1
  11284. * @param {number} x2
  11285. * @param {number} y2
  11286. * @param {Array.<number>} min
  11287. * @param {Array.<number>} max
  11288. */
  11289. bbox.fromQuadratic = function(x0, y0, x1, y1, x2, y2, min, max) {
  11290. var quadraticExtremum = curve.quadraticExtremum;
  11291. var quadraticAt = curve.quadraticAt;
  11292. // Find extremities, where derivative in x dim or y dim is zero
  11293. var tx =
  11294. mathMax(
  11295. mathMin(quadraticExtremum(x0, x1, x2), 1), 0
  11296. );
  11297. var ty =
  11298. mathMax(
  11299. mathMin(quadraticExtremum(y0, y1, y2), 1), 0
  11300. );
  11301. var x = quadraticAt(x0, x1, x2, tx);
  11302. var y = quadraticAt(y0, y1, y2, ty);
  11303. min[0] = mathMin(x0, x2, x);
  11304. min[1] = mathMin(y0, y2, y);
  11305. max[0] = mathMax(x0, x2, x);
  11306. max[1] = mathMax(y0, y2, y);
  11307. };
  11308. /**
  11309. * 从圆弧中计算出最小包围盒,写入`min`和`max`中
  11310. * @method
  11311. * @memberOf module:zrender/core/bbox
  11312. * @param {number} x
  11313. * @param {number} y
  11314. * @param {number} rx
  11315. * @param {number} ry
  11316. * @param {number} startAngle
  11317. * @param {number} endAngle
  11318. * @param {number} anticlockwise
  11319. * @param {Array.<number>} min
  11320. * @param {Array.<number>} max
  11321. */
  11322. bbox.fromArc = function (
  11323. x, y, rx, ry, startAngle, endAngle, anticlockwise, min, max
  11324. ) {
  11325. var vec2Min = vec2.min;
  11326. var vec2Max = vec2.max;
  11327. var diff = Math.abs(startAngle - endAngle);
  11328. if (diff % PI2 < 1e-4 && diff > 1e-4) {
  11329. // Is a circle
  11330. min[0] = x - rx;
  11331. min[1] = y - ry;
  11332. max[0] = x + rx;
  11333. max[1] = y + ry;
  11334. return;
  11335. }
  11336. start[0] = mathCos(startAngle) * rx + x;
  11337. start[1] = mathSin(startAngle) * ry + y;
  11338. end[0] = mathCos(endAngle) * rx + x;
  11339. end[1] = mathSin(endAngle) * ry + y;
  11340. vec2Min(min, start, end);
  11341. vec2Max(max, start, end);
  11342. // Thresh to [0, Math.PI * 2]
  11343. startAngle = startAngle % (PI2);
  11344. if (startAngle < 0) {
  11345. startAngle = startAngle + PI2;
  11346. }
  11347. endAngle = endAngle % (PI2);
  11348. if (endAngle < 0) {
  11349. endAngle = endAngle + PI2;
  11350. }
  11351. if (startAngle > endAngle && !anticlockwise) {
  11352. endAngle += PI2;
  11353. }
  11354. else if (startAngle < endAngle && anticlockwise) {
  11355. startAngle += PI2;
  11356. }
  11357. if (anticlockwise) {
  11358. var tmp = endAngle;
  11359. endAngle = startAngle;
  11360. startAngle = tmp;
  11361. }
  11362. // var number = 0;
  11363. // var step = (anticlockwise ? -Math.PI : Math.PI) / 2;
  11364. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  11365. if (angle > startAngle) {
  11366. extremity[0] = mathCos(angle) * rx + x;
  11367. extremity[1] = mathSin(angle) * ry + y;
  11368. vec2Min(min, extremity, min);
  11369. vec2Max(max, extremity, max);
  11370. }
  11371. }
  11372. };
  11373. module.exports = bbox;
  11374. /***/ },
  11375. /* 51 */
  11376. /***/ function(module, exports, __webpack_require__) {
  11377. 'use strict';
  11378. var CMD = __webpack_require__(48).CMD;
  11379. var line = __webpack_require__(52);
  11380. var cubic = __webpack_require__(53);
  11381. var quadratic = __webpack_require__(54);
  11382. var arc = __webpack_require__(55);
  11383. var normalizeRadian = __webpack_require__(56).normalizeRadian;
  11384. var curve = __webpack_require__(49);
  11385. var windingLine = __webpack_require__(57);
  11386. var containStroke = line.containStroke;
  11387. var PI2 = Math.PI * 2;
  11388. var EPSILON = 1e-4;
  11389. function isAroundEqual(a, b) {
  11390. return Math.abs(a - b) < EPSILON;
  11391. }
  11392. // 临时数组
  11393. var roots = [-1, -1, -1];
  11394. var extrema = [-1, -1];
  11395. function swapExtrema() {
  11396. var tmp = extrema[0];
  11397. extrema[0] = extrema[1];
  11398. extrema[1] = tmp;
  11399. }
  11400. function windingCubic(x0, y0, x1, y1, x2, y2, x3, y3, x, y) {
  11401. // Quick reject
  11402. if (
  11403. (y > y0 && y > y1 && y > y2 && y > y3)
  11404. || (y < y0 && y < y1 && y < y2 && y < y3)
  11405. ) {
  11406. return 0;
  11407. }
  11408. var nRoots = curve.cubicRootAt(y0, y1, y2, y3, y, roots);
  11409. if (nRoots === 0) {
  11410. return 0;
  11411. }
  11412. else {
  11413. var w = 0;
  11414. var nExtrema = -1;
  11415. var y0_, y1_;
  11416. for (var i = 0; i < nRoots; i++) {
  11417. var t = roots[i];
  11418. var x_ = curve.cubicAt(x0, x1, x2, x3, t);
  11419. if (x_ < x) { // Quick reject
  11420. continue;
  11421. }
  11422. if (nExtrema < 0) {
  11423. nExtrema = curve.cubicExtrema(y0, y1, y2, y3, extrema);
  11424. if (extrema[1] < extrema[0] && nExtrema > 1) {
  11425. swapExtrema();
  11426. }
  11427. y0_ = curve.cubicAt(y0, y1, y2, y3, extrema[0]);
  11428. if (nExtrema > 1) {
  11429. y1_ = curve.cubicAt(y0, y1, y2, y3, extrema[1]);
  11430. }
  11431. }
  11432. if (nExtrema == 2) {
  11433. // 分成三段单调函数
  11434. if (t < extrema[0]) {
  11435. w += y0_ < y0 ? 1 : -1;
  11436. }
  11437. else if (t < extrema[1]) {
  11438. w += y1_ < y0_ ? 1 : -1;
  11439. }
  11440. else {
  11441. w += y3 < y1_ ? 1 : -1;
  11442. }
  11443. }
  11444. else {
  11445. // 分成两段单调函数
  11446. if (t < extrema[0]) {
  11447. w += y0_ < y0 ? 1 : -1;
  11448. }
  11449. else {
  11450. w += y3 < y0_ ? 1 : -1;
  11451. }
  11452. }
  11453. }
  11454. return w;
  11455. }
  11456. }
  11457. function windingQuadratic(x0, y0, x1, y1, x2, y2, x, y) {
  11458. // Quick reject
  11459. if (
  11460. (y > y0 && y > y1 && y > y2)
  11461. || (y < y0 && y < y1 && y < y2)
  11462. ) {
  11463. return 0;
  11464. }
  11465. var nRoots = curve.quadraticRootAt(y0, y1, y2, y, roots);
  11466. if (nRoots === 0) {
  11467. return 0;
  11468. }
  11469. else {
  11470. var t = curve.quadraticExtremum(y0, y1, y2);
  11471. if (t >= 0 && t <= 1) {
  11472. var w = 0;
  11473. var y_ = curve.quadraticAt(y0, y1, y2, t);
  11474. for (var i = 0; i < nRoots; i++) {
  11475. var x_ = curve.quadraticAt(x0, x1, x2, roots[i]);
  11476. if (x_ < x) { // Quick reject
  11477. continue;
  11478. }
  11479. if (roots[i] < t) {
  11480. w += y_ < y0 ? 1 : -1;
  11481. }
  11482. else {
  11483. w += y2 < y_ ? 1 : -1;
  11484. }
  11485. }
  11486. return w;
  11487. }
  11488. else {
  11489. var x_ = curve.quadraticAt(x0, x1, x2, roots[0]);
  11490. if (x_ < x) { // Quick reject
  11491. return 0;
  11492. }
  11493. return y2 < y0 ? 1 : -1;
  11494. }
  11495. }
  11496. }
  11497. // TODO
  11498. // Arc 旋转
  11499. function windingArc(
  11500. cx, cy, r, startAngle, endAngle, anticlockwise, x, y
  11501. ) {
  11502. y -= cy;
  11503. if (y > r || y < -r) {
  11504. return 0;
  11505. }
  11506. var tmp = Math.sqrt(r * r - y * y);
  11507. roots[0] = -tmp;
  11508. roots[1] = tmp;
  11509. var diff = Math.abs(startAngle - endAngle);
  11510. if (diff < 1e-4) {
  11511. return 0;
  11512. }
  11513. if (diff % PI2 < 1e-4) {
  11514. // Is a circle
  11515. startAngle = 0;
  11516. endAngle = PI2;
  11517. var dir = anticlockwise ? 1 : -1;
  11518. if (x >= roots[0] + cx && x <= roots[1] + cx) {
  11519. return dir;
  11520. } else {
  11521. return 0;
  11522. }
  11523. }
  11524. if (anticlockwise) {
  11525. var tmp = startAngle;
  11526. startAngle = normalizeRadian(endAngle);
  11527. endAngle = normalizeRadian(tmp);
  11528. }
  11529. else {
  11530. startAngle = normalizeRadian(startAngle);
  11531. endAngle = normalizeRadian(endAngle);
  11532. }
  11533. if (startAngle > endAngle) {
  11534. endAngle += PI2;
  11535. }
  11536. var w = 0;
  11537. for (var i = 0; i < 2; i++) {
  11538. var x_ = roots[i];
  11539. if (x_ + cx > x) {
  11540. var angle = Math.atan2(y, x_);
  11541. var dir = anticlockwise ? 1 : -1;
  11542. if (angle < 0) {
  11543. angle = PI2 + angle;
  11544. }
  11545. if (
  11546. (angle >= startAngle && angle <= endAngle)
  11547. || (angle + PI2 >= startAngle && angle + PI2 <= endAngle)
  11548. ) {
  11549. if (angle > Math.PI / 2 && angle < Math.PI * 1.5) {
  11550. dir = -dir;
  11551. }
  11552. w += dir;
  11553. }
  11554. }
  11555. }
  11556. return w;
  11557. }
  11558. function containPath(data, lineWidth, isStroke, x, y) {
  11559. var w = 0;
  11560. var xi = 0;
  11561. var yi = 0;
  11562. var x0 = 0;
  11563. var y0 = 0;
  11564. for (var i = 0; i < data.length;) {
  11565. var cmd = data[i++];
  11566. // Begin a new subpath
  11567. if (cmd === CMD.M && i > 1) {
  11568. // Close previous subpath
  11569. if (!isStroke) {
  11570. w += windingLine(xi, yi, x0, y0, x, y);
  11571. }
  11572. // 如果被任何一个 subpath 包含
  11573. if (w !== 0) {
  11574. return true;
  11575. }
  11576. }
  11577. if (i == 1) {
  11578. // 如果第一个命令是 L, C, Q
  11579. // 则 previous point 同绘制命令的第一个 point
  11580. //
  11581. // 第一个命令为 Arc 的情况下会在后面特殊处理
  11582. xi = data[i];
  11583. yi = data[i + 1];
  11584. x0 = xi;
  11585. y0 = yi;
  11586. }
  11587. switch (cmd) {
  11588. case CMD.M:
  11589. // moveTo 命令重新创建一个新的 subpath, 并且更新新的起点
  11590. // 在 closePath 的时候使用
  11591. x0 = data[i++];
  11592. y0 = data[i++];
  11593. xi = x0;
  11594. yi = y0;
  11595. break;
  11596. case CMD.L:
  11597. if (isStroke) {
  11598. if (containStroke(xi, yi, data[i], data[i + 1], lineWidth, x, y)) {
  11599. return true;
  11600. }
  11601. }
  11602. else {
  11603. // NOTE 在第一个命令为 L, C, Q 的时候会计算出 NaN
  11604. w += windingLine(xi, yi, data[i], data[i + 1], x, y) || 0;
  11605. }
  11606. xi = data[i++];
  11607. yi = data[i++];
  11608. break;
  11609. case CMD.C:
  11610. if (isStroke) {
  11611. if (cubic.containStroke(xi, yi,
  11612. data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],
  11613. lineWidth, x, y
  11614. )) {
  11615. return true;
  11616. }
  11617. }
  11618. else {
  11619. w += windingCubic(
  11620. xi, yi,
  11621. data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],
  11622. x, y
  11623. ) || 0;
  11624. }
  11625. xi = data[i++];
  11626. yi = data[i++];
  11627. break;
  11628. case CMD.Q:
  11629. if (isStroke) {
  11630. if (quadratic.containStroke(xi, yi,
  11631. data[i++], data[i++], data[i], data[i + 1],
  11632. lineWidth, x, y
  11633. )) {
  11634. return true;
  11635. }
  11636. }
  11637. else {
  11638. w += windingQuadratic(
  11639. xi, yi,
  11640. data[i++], data[i++], data[i], data[i + 1],
  11641. x, y
  11642. ) || 0;
  11643. }
  11644. xi = data[i++];
  11645. yi = data[i++];
  11646. break;
  11647. case CMD.A:
  11648. // TODO Arc 判断的开销比较大
  11649. var cx = data[i++];
  11650. var cy = data[i++];
  11651. var rx = data[i++];
  11652. var ry = data[i++];
  11653. var theta = data[i++];
  11654. var dTheta = data[i++];
  11655. // TODO Arc 旋转
  11656. var psi = data[i++];
  11657. var anticlockwise = 1 - data[i++];
  11658. var x1 = Math.cos(theta) * rx + cx;
  11659. var y1 = Math.sin(theta) * ry + cy;
  11660. // 不是直接使用 arc 命令
  11661. if (i > 1) {
  11662. w += windingLine(xi, yi, x1, y1, x, y);
  11663. }
  11664. else {
  11665. // 第一个命令起点还未定义
  11666. x0 = x1;
  11667. y0 = y1;
  11668. }
  11669. // zr 使用scale来模拟椭圆, 这里也对x做一定的缩放
  11670. var _x = (x - cx) * ry / rx + cx;
  11671. if (isStroke) {
  11672. if (arc.containStroke(
  11673. cx, cy, ry, theta, theta + dTheta, anticlockwise,
  11674. lineWidth, _x, y
  11675. )) {
  11676. return true;
  11677. }
  11678. }
  11679. else {
  11680. w += windingArc(
  11681. cx, cy, ry, theta, theta + dTheta, anticlockwise,
  11682. _x, y
  11683. );
  11684. }
  11685. xi = Math.cos(theta + dTheta) * rx + cx;
  11686. yi = Math.sin(theta + dTheta) * ry + cy;
  11687. break;
  11688. case CMD.R:
  11689. x0 = xi = data[i++];
  11690. y0 = yi = data[i++];
  11691. var width = data[i++];
  11692. var height = data[i++];
  11693. var x1 = x0 + width;
  11694. var y1 = y0 + height;
  11695. if (isStroke) {
  11696. if (containStroke(x0, y0, x1, y0, lineWidth, x, y)
  11697. || containStroke(x1, y0, x1, y1, lineWidth, x, y)
  11698. || containStroke(x1, y1, x0, y1, lineWidth, x, y)
  11699. || containStroke(x0, y1, x1, y1, lineWidth, x, y)
  11700. ) {
  11701. return true;
  11702. }
  11703. }
  11704. else {
  11705. // FIXME Clockwise ?
  11706. w += windingLine(x1, y0, x1, y1, x, y);
  11707. w += windingLine(x0, y1, x0, y0, x, y);
  11708. }
  11709. break;
  11710. case CMD.Z:
  11711. if (isStroke) {
  11712. if (containStroke(
  11713. xi, yi, x0, y0, lineWidth, x, y
  11714. )) {
  11715. return true;
  11716. }
  11717. }
  11718. else {
  11719. // Close a subpath
  11720. w += windingLine(xi, yi, x0, y0, x, y);
  11721. // 如果被任何一个 subpath 包含
  11722. if (w !== 0) {
  11723. return true;
  11724. }
  11725. }
  11726. xi = x0;
  11727. yi = y0;
  11728. break;
  11729. }
  11730. }
  11731. if (!isStroke && !isAroundEqual(yi, y0)) {
  11732. w += windingLine(xi, yi, x0, y0, x, y) || 0;
  11733. }
  11734. return w !== 0;
  11735. }
  11736. module.exports = {
  11737. contain: function (pathData, x, y) {
  11738. return containPath(pathData, 0, false, x, y);
  11739. },
  11740. containStroke: function (pathData, lineWidth, x, y) {
  11741. return containPath(pathData, lineWidth, true, x, y);
  11742. }
  11743. };
  11744. /***/ },
  11745. /* 52 */
  11746. /***/ function(module, exports) {
  11747. module.exports = {
  11748. /**
  11749. * 线段包含判断
  11750. * @param {number} x0
  11751. * @param {number} y0
  11752. * @param {number} x1
  11753. * @param {number} y1
  11754. * @param {number} lineWidth
  11755. * @param {number} x
  11756. * @param {number} y
  11757. * @return {boolean}
  11758. */
  11759. containStroke: function (x0, y0, x1, y1, lineWidth, x, y) {
  11760. if (lineWidth === 0) {
  11761. return false;
  11762. }
  11763. var _l = lineWidth;
  11764. var _a = 0;
  11765. var _b = x0;
  11766. // Quick reject
  11767. if (
  11768. (y > y0 + _l && y > y1 + _l)
  11769. || (y < y0 - _l && y < y1 - _l)
  11770. || (x > x0 + _l && x > x1 + _l)
  11771. || (x < x0 - _l && x < x1 - _l)
  11772. ) {
  11773. return false;
  11774. }
  11775. if (x0 !== x1) {
  11776. _a = (y0 - y1) / (x0 - x1);
  11777. _b = (x0 * y1 - x1 * y0) / (x0 - x1) ;
  11778. }
  11779. else {
  11780. return Math.abs(x - x0) <= _l / 2;
  11781. }
  11782. var tmp = _a * x - y + _b;
  11783. var _s = tmp * tmp / (_a * _a + 1);
  11784. return _s <= _l / 2 * _l / 2;
  11785. }
  11786. };
  11787. /***/ },
  11788. /* 53 */
  11789. /***/ function(module, exports, __webpack_require__) {
  11790. var curve = __webpack_require__(49);
  11791. module.exports = {
  11792. /**
  11793. * 三次贝塞尔曲线描边包含判断
  11794. * @param {number} x0
  11795. * @param {number} y0
  11796. * @param {number} x1
  11797. * @param {number} y1
  11798. * @param {number} x2
  11799. * @param {number} y2
  11800. * @param {number} x3
  11801. * @param {number} y3
  11802. * @param {number} lineWidth
  11803. * @param {number} x
  11804. * @param {number} y
  11805. * @return {boolean}
  11806. */
  11807. containStroke: function(x0, y0, x1, y1, x2, y2, x3, y3, lineWidth, x, y) {
  11808. if (lineWidth === 0) {
  11809. return false;
  11810. }
  11811. var _l = lineWidth;
  11812. // Quick reject
  11813. if (
  11814. (y > y0 + _l && y > y1 + _l && y > y2 + _l && y > y3 + _l)
  11815. || (y < y0 - _l && y < y1 - _l && y < y2 - _l && y < y3 - _l)
  11816. || (x > x0 + _l && x > x1 + _l && x > x2 + _l && x > x3 + _l)
  11817. || (x < x0 - _l && x < x1 - _l && x < x2 - _l && x < x3 - _l)
  11818. ) {
  11819. return false;
  11820. }
  11821. var d = curve.cubicProjectPoint(
  11822. x0, y0, x1, y1, x2, y2, x3, y3,
  11823. x, y, null
  11824. );
  11825. return d <= _l / 2;
  11826. }
  11827. };
  11828. /***/ },
  11829. /* 54 */
  11830. /***/ function(module, exports, __webpack_require__) {
  11831. var curve = __webpack_require__(49);
  11832. module.exports = {
  11833. /**
  11834. * 二次贝塞尔曲线描边包含判断
  11835. * @param {number} x0
  11836. * @param {number} y0
  11837. * @param {number} x1
  11838. * @param {number} y1
  11839. * @param {number} x2
  11840. * @param {number} y2
  11841. * @param {number} lineWidth
  11842. * @param {number} x
  11843. * @param {number} y
  11844. * @return {boolean}
  11845. */
  11846. containStroke: function (x0, y0, x1, y1, x2, y2, lineWidth, x, y) {
  11847. if (lineWidth === 0) {
  11848. return false;
  11849. }
  11850. var _l = lineWidth;
  11851. // Quick reject
  11852. if (
  11853. (y > y0 + _l && y > y1 + _l && y > y2 + _l)
  11854. || (y < y0 - _l && y < y1 - _l && y < y2 - _l)
  11855. || (x > x0 + _l && x > x1 + _l && x > x2 + _l)
  11856. || (x < x0 - _l && x < x1 - _l && x < x2 - _l)
  11857. ) {
  11858. return false;
  11859. }
  11860. var d = curve.quadraticProjectPoint(
  11861. x0, y0, x1, y1, x2, y2,
  11862. x, y, null
  11863. );
  11864. return d <= _l / 2;
  11865. }
  11866. };
  11867. /***/ },
  11868. /* 55 */
  11869. /***/ function(module, exports, __webpack_require__) {
  11870. var normalizeRadian = __webpack_require__(56).normalizeRadian;
  11871. var PI2 = Math.PI * 2;
  11872. module.exports = {
  11873. /**
  11874. * 圆弧描边包含判断
  11875. * @param {number} cx
  11876. * @param {number} cy
  11877. * @param {number} r
  11878. * @param {number} startAngle
  11879. * @param {number} endAngle
  11880. * @param {boolean} anticlockwise
  11881. * @param {number} lineWidth
  11882. * @param {number} x
  11883. * @param {number} y
  11884. * @return {Boolean}
  11885. */
  11886. containStroke: function (
  11887. cx, cy, r, startAngle, endAngle, anticlockwise,
  11888. lineWidth, x, y
  11889. ) {
  11890. if (lineWidth === 0) {
  11891. return false;
  11892. }
  11893. var _l = lineWidth;
  11894. x -= cx;
  11895. y -= cy;
  11896. var d = Math.sqrt(x * x + y * y);
  11897. if ((d - _l > r) || (d + _l < r)) {
  11898. return false;
  11899. }
  11900. if (Math.abs(startAngle - endAngle) % PI2 < 1e-4) {
  11901. // Is a circle
  11902. return true;
  11903. }
  11904. if (anticlockwise) {
  11905. var tmp = startAngle;
  11906. startAngle = normalizeRadian(endAngle);
  11907. endAngle = normalizeRadian(tmp);
  11908. } else {
  11909. startAngle = normalizeRadian(startAngle);
  11910. endAngle = normalizeRadian(endAngle);
  11911. }
  11912. if (startAngle > endAngle) {
  11913. endAngle += PI2;
  11914. }
  11915. var angle = Math.atan2(y, x);
  11916. if (angle < 0) {
  11917. angle += PI2;
  11918. }
  11919. return (angle >= startAngle && angle <= endAngle)
  11920. || (angle + PI2 >= startAngle && angle + PI2 <= endAngle);
  11921. }
  11922. };
  11923. /***/ },
  11924. /* 56 */
  11925. /***/ function(module, exports) {
  11926. var PI2 = Math.PI * 2;
  11927. module.exports = {
  11928. normalizeRadian: function(angle) {
  11929. angle %= PI2;
  11930. if (angle < 0) {
  11931. angle += PI2;
  11932. }
  11933. return angle;
  11934. }
  11935. };
  11936. /***/ },
  11937. /* 57 */
  11938. /***/ function(module, exports) {
  11939. module.exports = function windingLine(x0, y0, x1, y1, x, y) {
  11940. if ((y > y0 && y > y1) || (y < y0 && y < y1)) {
  11941. return 0;
  11942. }
  11943. if (y1 === y0) {
  11944. return 0;
  11945. }
  11946. var dir = y1 < y0 ? 1 : -1;
  11947. var t = (y - y0) / (y1 - y0);
  11948. var x_ = t * (x1 - x0) + x0;
  11949. return x_ > x ? dir : 0;
  11950. };
  11951. /***/ },
  11952. /* 58 */
  11953. /***/ function(module, exports, __webpack_require__) {
  11954. var CMD = __webpack_require__(48).CMD;
  11955. var vec2 = __webpack_require__(16);
  11956. var v2ApplyTransform = vec2.applyTransform;
  11957. var points = [[], [], []];
  11958. var mathSqrt = Math.sqrt;
  11959. var mathAtan2 = Math.atan2;
  11960. function transformPath(path, m) {
  11961. var data = path.data;
  11962. var cmd;
  11963. var nPoint;
  11964. var i;
  11965. var j;
  11966. var k;
  11967. var p;
  11968. var M = CMD.M;
  11969. var C = CMD.C;
  11970. var L = CMD.L;
  11971. var R = CMD.R;
  11972. var A = CMD.A;
  11973. var Q = CMD.Q;
  11974. for (i = 0, j = 0; i < data.length;) {
  11975. cmd = data[i++];
  11976. j = i;
  11977. nPoint = 0;
  11978. switch (cmd) {
  11979. case M:
  11980. nPoint = 1;
  11981. break;
  11982. case L:
  11983. nPoint = 1;
  11984. break;
  11985. case C:
  11986. nPoint = 3;
  11987. break;
  11988. case Q:
  11989. nPoint = 2;
  11990. break;
  11991. case A:
  11992. var x = m[4];
  11993. var y = m[5];
  11994. var sx = mathSqrt(m[0] * m[0] + m[1] * m[1]);
  11995. var sy = mathSqrt(m[2] * m[2] + m[3] * m[3]);
  11996. var angle = mathAtan2(-m[1] / sy, m[0] / sx);
  11997. // cx
  11998. data[i++] += x;
  11999. // cy
  12000. data[i++] += y;
  12001. // Scale rx and ry
  12002. // FIXME Assume psi is 0 here
  12003. data[i++] *= sx;
  12004. data[i++] *= sy;
  12005. // Start angle
  12006. data[i++] += angle;
  12007. // end angle
  12008. data[i++] += angle;
  12009. // FIXME psi
  12010. i += 2;
  12011. j = i;
  12012. break;
  12013. case R:
  12014. // x0, y0
  12015. p[0] = data[i++];
  12016. p[1] = data[i++];
  12017. v2ApplyTransform(p, p, m);
  12018. data[j++] = p[0];
  12019. data[j++] = p[1];
  12020. // x1, y1
  12021. p[0] += data[i++];
  12022. p[1] += data[i++];
  12023. v2ApplyTransform(p, p, m);
  12024. data[j++] = p[0];
  12025. data[j++] = p[1];
  12026. }
  12027. for (k = 0; k < nPoint; k++) {
  12028. var p = points[k];
  12029. p[0] = data[i++];
  12030. p[1] = data[i++];
  12031. v2ApplyTransform(p, p, m);
  12032. // Write back
  12033. data[j++] = p[0];
  12034. data[j++] = p[1];
  12035. }
  12036. }
  12037. }
  12038. module.exports = transformPath;
  12039. /***/ },
  12040. /* 59 */
  12041. /***/ function(module, exports, __webpack_require__) {
  12042. /**
  12043. * Image element
  12044. * @module zrender/graphic/Image
  12045. */
  12046. var Displayable = __webpack_require__(45);
  12047. var BoundingRect = __webpack_require__(15);
  12048. var zrUtil = __webpack_require__(3);
  12049. var roundRectHelper = __webpack_require__(60);
  12050. var LRU = __webpack_require__(61);
  12051. var globalImageCache = new LRU(50);
  12052. /**
  12053. * @alias zrender/graphic/Image
  12054. * @extends module:zrender/graphic/Displayable
  12055. * @constructor
  12056. * @param {Object} opts
  12057. */
  12058. function ZImage(opts) {
  12059. Displayable.call(this, opts);
  12060. }
  12061. ZImage.prototype = {
  12062. constructor: ZImage,
  12063. type: 'image',
  12064. brush: function (ctx) {
  12065. var style = this.style;
  12066. var src = style.image;
  12067. var image;
  12068. // style.image is a url string
  12069. if (typeof src === 'string') {
  12070. image = this._image;
  12071. }
  12072. // style.image is an HTMLImageElement or HTMLCanvasElement or Canvas
  12073. else {
  12074. image = src;
  12075. }
  12076. // FIXME Case create many images with src
  12077. if (!image && src) {
  12078. // Try get from global image cache
  12079. var cachedImgObj = globalImageCache.get(src);
  12080. if (!cachedImgObj) {
  12081. // Create a new image
  12082. image = new Image();
  12083. image.onload = function () {
  12084. image.onload = null;
  12085. for (var i = 0; i < cachedImgObj.pending.length; i++) {
  12086. cachedImgObj.pending[i].dirty();
  12087. }
  12088. };
  12089. cachedImgObj = {
  12090. image: image,
  12091. pending: [this]
  12092. };
  12093. image.src = src;
  12094. globalImageCache.put(src, cachedImgObj);
  12095. this._image = image;
  12096. return;
  12097. }
  12098. else {
  12099. image = cachedImgObj.image;
  12100. this._image = image;
  12101. // Image is not complete finish, add to pending list
  12102. if (!image.width || !image.height) {
  12103. cachedImgObj.pending.push(this);
  12104. return;
  12105. }
  12106. }
  12107. }
  12108. if (image) {
  12109. // 图片已经加载完成
  12110. // if (image.nodeName.toUpperCase() == 'IMG') {
  12111. // if (!image.complete) {
  12112. // return;
  12113. // }
  12114. // }
  12115. // Else is canvas
  12116. var width = style.width || image.width;
  12117. var height = style.height || image.height;
  12118. var x = style.x || 0;
  12119. var y = style.y || 0;
  12120. // 图片加载失败
  12121. if (!image.width || !image.height) {
  12122. return;
  12123. }
  12124. ctx.save();
  12125. style.bind(ctx);
  12126. // 设置transform
  12127. this.setTransform(ctx);
  12128. if (style.r) {
  12129. // Border radius clipping
  12130. // FIXME
  12131. ctx.beginPath();
  12132. roundRectHelper.buildPath(ctx, style);
  12133. ctx.clip();
  12134. }
  12135. if (style.sWidth && style.sHeight) {
  12136. var sx = style.sx || 0;
  12137. var sy = style.sy || 0;
  12138. ctx.drawImage(
  12139. image,
  12140. sx, sy, style.sWidth, style.sHeight,
  12141. x, y, width, height
  12142. );
  12143. }
  12144. else if (style.sx && style.sy) {
  12145. var sx = style.sx;
  12146. var sy = style.sy;
  12147. var sWidth = width - sx;
  12148. var sHeight = height - sy;
  12149. ctx.drawImage(
  12150. image,
  12151. sx, sy, sWidth, sHeight,
  12152. x, y, width, height
  12153. );
  12154. }
  12155. else {
  12156. ctx.drawImage(image, x, y, width, height);
  12157. }
  12158. // 如果没设置宽和高的话自动根据图片宽高设置
  12159. if (style.width == null) {
  12160. style.width = width;
  12161. }
  12162. if (style.height == null) {
  12163. style.height = height;
  12164. }
  12165. // Draw rect text
  12166. if (style.text != null) {
  12167. this.drawRectText(ctx, this.getBoundingRect());
  12168. }
  12169. ctx.restore();
  12170. }
  12171. },
  12172. getBoundingRect: function () {
  12173. var style = this.style;
  12174. if (! this._rect) {
  12175. this._rect = new BoundingRect(
  12176. style.x || 0, style.y || 0, style.width || 0, style.height || 0
  12177. );
  12178. }
  12179. return this._rect;
  12180. }
  12181. };
  12182. zrUtil.inherits(ZImage, Displayable);
  12183. module.exports = ZImage;
  12184. /***/ },
  12185. /* 60 */
  12186. /***/ function(module, exports) {
  12187. module.exports = {
  12188. buildPath: function (ctx, shape) {
  12189. var x = shape.x;
  12190. var y = shape.y;
  12191. var width = shape.width;
  12192. var height = shape.height;
  12193. var r = shape.r;
  12194. var r1;
  12195. var r2;
  12196. var r3;
  12197. var r4;
  12198. // Convert width and height to positive for better borderRadius
  12199. if (width < 0) {
  12200. x = x + width;
  12201. width = -width;
  12202. }
  12203. if (height < 0) {
  12204. y = y + height;
  12205. height = -height;
  12206. }
  12207. if (typeof r === 'number') {
  12208. r1 = r2 = r3 = r4 = r;
  12209. }
  12210. else if (r instanceof Array) {
  12211. if (r.length === 1) {
  12212. r1 = r2 = r3 = r4 = r[0];
  12213. }
  12214. else if (r.length === 2) {
  12215. r1 = r3 = r[0];
  12216. r2 = r4 = r[1];
  12217. }
  12218. else if (r.length === 3) {
  12219. r1 = r[0];
  12220. r2 = r4 = r[1];
  12221. r3 = r[2];
  12222. }
  12223. else {
  12224. r1 = r[0];
  12225. r2 = r[1];
  12226. r3 = r[2];
  12227. r4 = r[3];
  12228. }
  12229. }
  12230. else {
  12231. r1 = r2 = r3 = r4 = 0;
  12232. }
  12233. var total;
  12234. if (r1 + r2 > width) {
  12235. total = r1 + r2;
  12236. r1 *= width / total;
  12237. r2 *= width / total;
  12238. }
  12239. if (r3 + r4 > width) {
  12240. total = r3 + r4;
  12241. r3 *= width / total;
  12242. r4 *= width / total;
  12243. }
  12244. if (r2 + r3 > height) {
  12245. total = r2 + r3;
  12246. r2 *= height / total;
  12247. r3 *= height / total;
  12248. }
  12249. if (r1 + r4 > height) {
  12250. total = r1 + r4;
  12251. r1 *= height / total;
  12252. r4 *= height / total;
  12253. }
  12254. ctx.moveTo(x + r1, y);
  12255. ctx.lineTo(x + width - r2, y);
  12256. r2 !== 0 && ctx.quadraticCurveTo(
  12257. x + width, y, x + width, y + r2
  12258. );
  12259. ctx.lineTo(x + width, y + height - r3);
  12260. r3 !== 0 && ctx.quadraticCurveTo(
  12261. x + width, y + height, x + width - r3, y + height
  12262. );
  12263. ctx.lineTo(x + r4, y + height);
  12264. r4 !== 0 && ctx.quadraticCurveTo(
  12265. x, y + height, x, y + height - r4
  12266. );
  12267. ctx.lineTo(x, y + r1);
  12268. r1 !== 0 && ctx.quadraticCurveTo(x, y, x + r1, y);
  12269. }
  12270. };
  12271. /***/ },
  12272. /* 61 */
  12273. /***/ function(module, exports) {
  12274. // Simple LRU cache use doubly linked list
  12275. // @module zrender/core/LRU
  12276. /**
  12277. * Simple double linked list. Compared with array, it has O(1) remove operation.
  12278. * @constructor
  12279. */
  12280. var LinkedList = function() {
  12281. /**
  12282. * @type {module:zrender/core/LRU~Entry}
  12283. */
  12284. this.head = null;
  12285. /**
  12286. * @type {module:zrender/core/LRU~Entry}
  12287. */
  12288. this.tail = null;
  12289. this._len = 0;
  12290. };
  12291. var linkedListProto = LinkedList.prototype;
  12292. /**
  12293. * Insert a new value at the tail
  12294. * @param {} val
  12295. * @return {module:zrender/core/LRU~Entry}
  12296. */
  12297. linkedListProto.insert = function(val) {
  12298. var entry = new Entry(val);
  12299. this.insertEntry(entry);
  12300. return entry;
  12301. };
  12302. /**
  12303. * Insert an entry at the tail
  12304. * @param {module:zrender/core/LRU~Entry} entry
  12305. */
  12306. linkedListProto.insertEntry = function(entry) {
  12307. if (!this.head) {
  12308. this.head = this.tail = entry;
  12309. }
  12310. else {
  12311. this.tail.next = entry;
  12312. entry.prev = this.tail;
  12313. this.tail = entry;
  12314. }
  12315. this._len++;
  12316. };
  12317. /**
  12318. * Remove entry.
  12319. * @param {module:zrender/core/LRU~Entry} entry
  12320. */
  12321. linkedListProto.remove = function(entry) {
  12322. var prev = entry.prev;
  12323. var next = entry.next;
  12324. if (prev) {
  12325. prev.next = next;
  12326. }
  12327. else {
  12328. // Is head
  12329. this.head = next;
  12330. }
  12331. if (next) {
  12332. next.prev = prev;
  12333. }
  12334. else {
  12335. // Is tail
  12336. this.tail = prev;
  12337. }
  12338. entry.next = entry.prev = null;
  12339. this._len--;
  12340. };
  12341. /**
  12342. * @return {number}
  12343. */
  12344. linkedListProto.len = function() {
  12345. return this._len;
  12346. };
  12347. /**
  12348. * @constructor
  12349. * @param {} val
  12350. */
  12351. var Entry = function(val) {
  12352. /**
  12353. * @type {}
  12354. */
  12355. this.value = val;
  12356. /**
  12357. * @type {module:zrender/core/LRU~Entry}
  12358. */
  12359. this.next;
  12360. /**
  12361. * @type {module:zrender/core/LRU~Entry}
  12362. */
  12363. this.prev;
  12364. };
  12365. /**
  12366. * LRU Cache
  12367. * @constructor
  12368. * @alias module:zrender/core/LRU
  12369. */
  12370. var LRU = function(maxSize) {
  12371. this._list = new LinkedList();
  12372. this._map = {};
  12373. this._maxSize = maxSize || 10;
  12374. };
  12375. var LRUProto = LRU.prototype;
  12376. /**
  12377. * @param {string} key
  12378. * @param {} value
  12379. */
  12380. LRUProto.put = function(key, value) {
  12381. var list = this._list;
  12382. var map = this._map;
  12383. if (map[key] == null) {
  12384. var len = list.len();
  12385. if (len >= this._maxSize && len > 0) {
  12386. // Remove the least recently used
  12387. var leastUsedEntry = list.head;
  12388. list.remove(leastUsedEntry);
  12389. delete map[leastUsedEntry.key];
  12390. }
  12391. var entry = list.insert(value);
  12392. entry.key = key;
  12393. map[key] = entry;
  12394. }
  12395. };
  12396. /**
  12397. * @param {string} key
  12398. * @return {}
  12399. */
  12400. LRUProto.get = function(key) {
  12401. var entry = this._map[key];
  12402. var list = this._list;
  12403. if (entry != null) {
  12404. // Put the latest used entry in the tail
  12405. if (entry !== list.tail) {
  12406. list.remove(entry);
  12407. list.insertEntry(entry);
  12408. }
  12409. return entry.value;
  12410. }
  12411. };
  12412. /**
  12413. * Clear the cache
  12414. */
  12415. LRUProto.clear = function() {
  12416. this._list.clear();
  12417. this._map = {};
  12418. };
  12419. module.exports = LRU;
  12420. /***/ },
  12421. /* 62 */
  12422. /***/ function(module, exports, __webpack_require__) {
  12423. /**
  12424. * Text element
  12425. * @module zrender/graphic/Text
  12426. *
  12427. * TODO Wrapping
  12428. *
  12429. * Text not support gradient
  12430. */
  12431. var Displayable = __webpack_require__(45);
  12432. var zrUtil = __webpack_require__(3);
  12433. var textContain = __webpack_require__(14);
  12434. /**
  12435. * @alias zrender/graphic/Text
  12436. * @extends module:zrender/graphic/Displayable
  12437. * @constructor
  12438. * @param {Object} opts
  12439. */
  12440. var Text = function (opts) {
  12441. Displayable.call(this, opts);
  12442. };
  12443. Text.prototype = {
  12444. constructor: Text,
  12445. type: 'text',
  12446. brush: function (ctx) {
  12447. var style = this.style;
  12448. var x = style.x || 0;
  12449. var y = style.y || 0;
  12450. // Convert to string
  12451. var text = style.text;
  12452. var textFill = style.fill;
  12453. var textStroke = style.stroke;
  12454. // Convert to string
  12455. text != null && (text += '');
  12456. if (text) {
  12457. ctx.save();
  12458. this.style.bind(ctx);
  12459. this.setTransform(ctx);
  12460. textFill && (ctx.fillStyle = textFill);
  12461. textStroke && (ctx.strokeStyle = textStroke);
  12462. ctx.font = style.textFont || style.font;
  12463. ctx.textAlign = style.textAlign;
  12464. if (style.textVerticalAlign) {
  12465. var rect = textContain.getBoundingRect(
  12466. text, ctx.font, style.textAlign, 'top'
  12467. );
  12468. // Ignore textBaseline
  12469. ctx.textBaseline = 'middle';
  12470. switch (style.textVerticalAlign) {
  12471. case 'middle':
  12472. y -= rect.height / 2 - rect.lineHeight / 2;
  12473. break;
  12474. case 'bottom':
  12475. y -= rect.height - rect.lineHeight / 2;
  12476. break;
  12477. default:
  12478. y += rect.lineHeight / 2;
  12479. }
  12480. }
  12481. else {
  12482. ctx.textBaseline = style.textBaseline;
  12483. }
  12484. var lineHeight = textContain.measureText('国', ctx.font).width;
  12485. var textLines = text.split('\n');
  12486. for (var i = 0; i < textLines.length; i++) {
  12487. textFill && ctx.fillText(textLines[i], x, y);
  12488. textStroke && ctx.strokeText(textLines[i], x, y);
  12489. y += lineHeight;
  12490. }
  12491. ctx.restore();
  12492. }
  12493. },
  12494. getBoundingRect: function () {
  12495. if (!this._rect) {
  12496. var style = this.style;
  12497. var textVerticalAlign = style.textVerticalAlign;
  12498. var rect = textContain.getBoundingRect(
  12499. style.text + '', style.textFont || style.font, style.textAlign,
  12500. textVerticalAlign ? 'top' : style.textBaseline
  12501. );
  12502. switch (textVerticalAlign) {
  12503. case 'middle':
  12504. rect.y -= rect.height / 2;
  12505. break;
  12506. case 'bottom':
  12507. rect.y -= rect.height;
  12508. break;
  12509. }
  12510. rect.x += style.x || 0;
  12511. rect.y += style.y || 0;
  12512. this._rect = rect;
  12513. }
  12514. return this._rect;
  12515. }
  12516. };
  12517. zrUtil.inherits(Text, Displayable);
  12518. module.exports = Text;
  12519. /***/ },
  12520. /* 63 */
  12521. /***/ function(module, exports, __webpack_require__) {
  12522. 'use strict';
  12523. /**
  12524. * 圆形
  12525. * @module zrender/shape/Circle
  12526. */
  12527. module.exports = __webpack_require__(44).extend({
  12528. type: 'circle',
  12529. shape: {
  12530. cx: 0,
  12531. cy: 0,
  12532. r: 0
  12533. },
  12534. buildPath : function (ctx, shape) {
  12535. // Better stroking in ShapeBundle
  12536. ctx.moveTo(shape.cx + shape.r, shape.cy);
  12537. ctx.arc(shape.cx, shape.cy, shape.r, 0, Math.PI * 2, true);
  12538. return;
  12539. }
  12540. });
  12541. /***/ },
  12542. /* 64 */
  12543. /***/ function(module, exports, __webpack_require__) {
  12544. /**
  12545. * 扇形
  12546. * @module zrender/graphic/shape/Sector
  12547. */
  12548. // FIXME clockwise seems wrong
  12549. module.exports = __webpack_require__(44).extend({
  12550. type: 'sector',
  12551. shape: {
  12552. cx: 0,
  12553. cy: 0,
  12554. r0: 0,
  12555. r: 0,
  12556. startAngle: 0,
  12557. endAngle: Math.PI * 2,
  12558. clockwise: true
  12559. },
  12560. buildPath: function (ctx, shape) {
  12561. var x = shape.cx;
  12562. var y = shape.cy;
  12563. var r0 = Math.max(shape.r0 || 0, 0);
  12564. var r = Math.max(shape.r, 0);
  12565. var startAngle = shape.startAngle;
  12566. var endAngle = shape.endAngle;
  12567. var clockwise = shape.clockwise;
  12568. var unitX = Math.cos(startAngle);
  12569. var unitY = Math.sin(startAngle);
  12570. ctx.moveTo(unitX * r0 + x, unitY * r0 + y);
  12571. ctx.lineTo(unitX * r + x, unitY * r + y);
  12572. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  12573. ctx.lineTo(
  12574. Math.cos(endAngle) * r0 + x,
  12575. Math.sin(endAngle) * r0 + y
  12576. );
  12577. if (r0 !== 0) {
  12578. ctx.arc(x, y, r0, endAngle, startAngle, clockwise);
  12579. }
  12580. ctx.closePath();
  12581. }
  12582. });
  12583. /***/ },
  12584. /* 65 */
  12585. /***/ function(module, exports, __webpack_require__) {
  12586. /**
  12587. * 圆环
  12588. * @module zrender/graphic/shape/Ring
  12589. */
  12590. module.exports = __webpack_require__(44).extend({
  12591. type: 'ring',
  12592. shape: {
  12593. cx: 0,
  12594. cy: 0,
  12595. r: 0,
  12596. r0: 0
  12597. },
  12598. buildPath: function (ctx, shape) {
  12599. var x = shape.cx;
  12600. var y = shape.cy;
  12601. var PI2 = Math.PI * 2;
  12602. ctx.moveTo(x + shape.r, y);
  12603. ctx.arc(x, y, shape.r, 0, PI2, false);
  12604. ctx.moveTo(x + shape.r0, y);
  12605. ctx.arc(x, y, shape.r0, 0, PI2, true);
  12606. }
  12607. });
  12608. /***/ },
  12609. /* 66 */
  12610. /***/ function(module, exports, __webpack_require__) {
  12611. /**
  12612. * 多边形
  12613. * @module zrender/shape/Polygon
  12614. */
  12615. var polyHelper = __webpack_require__(67);
  12616. module.exports = __webpack_require__(44).extend({
  12617. type: 'polygon',
  12618. shape: {
  12619. points: null,
  12620. smooth: false,
  12621. smoothConstraint: null
  12622. },
  12623. buildPath: function (ctx, shape) {
  12624. polyHelper.buildPath(ctx, shape, true);
  12625. }
  12626. });
  12627. /***/ },
  12628. /* 67 */
  12629. /***/ function(module, exports, __webpack_require__) {
  12630. var smoothSpline = __webpack_require__(68);
  12631. var smoothBezier = __webpack_require__(69);
  12632. module.exports = {
  12633. buildPath: function (ctx, shape, closePath) {
  12634. var points = shape.points;
  12635. var smooth = shape.smooth;
  12636. if (points && points.length >= 2) {
  12637. if (smooth && smooth !== 'spline') {
  12638. var controlPoints = smoothBezier(
  12639. points, smooth, closePath, shape.smoothConstraint
  12640. );
  12641. ctx.moveTo(points[0][0], points[0][1]);
  12642. var len = points.length;
  12643. for (var i = 0; i < (closePath ? len : len - 1); i++) {
  12644. var cp1 = controlPoints[i * 2];
  12645. var cp2 = controlPoints[i * 2 + 1];
  12646. var p = points[(i + 1) % len];
  12647. ctx.bezierCurveTo(
  12648. cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]
  12649. );
  12650. }
  12651. }
  12652. else {
  12653. if (smooth === 'spline') {
  12654. points = smoothSpline(points, closePath);
  12655. }
  12656. ctx.moveTo(points[0][0], points[0][1]);
  12657. for (var i = 1, l = points.length; i < l; i++) {
  12658. ctx.lineTo(points[i][0], points[i][1]);
  12659. }
  12660. }
  12661. closePath && ctx.closePath();
  12662. }
  12663. }
  12664. };
  12665. /***/ },
  12666. /* 68 */
  12667. /***/ function(module, exports, __webpack_require__) {
  12668. /**
  12669. * Catmull-Rom spline 插值折线
  12670. * @module zrender/shape/util/smoothSpline
  12671. * @author pissang (https://www.github.com/pissang)
  12672. * Kener (@Kener-林峰, kener.linfeng@gmail.com)
  12673. * errorrik (errorrik@gmail.com)
  12674. */
  12675. var vec2 = __webpack_require__(16);
  12676. /**
  12677. * @inner
  12678. */
  12679. function interpolate(p0, p1, p2, p3, t, t2, t3) {
  12680. var v0 = (p2 - p0) * 0.5;
  12681. var v1 = (p3 - p1) * 0.5;
  12682. return (2 * (p1 - p2) + v0 + v1) * t3
  12683. + (-3 * (p1 - p2) - 2 * v0 - v1) * t2
  12684. + v0 * t + p1;
  12685. }
  12686. /**
  12687. * @alias module:zrender/shape/util/smoothSpline
  12688. * @param {Array} points 线段顶点数组
  12689. * @param {boolean} isLoop
  12690. * @return {Array}
  12691. */
  12692. module.exports = function (points, isLoop) {
  12693. var len = points.length;
  12694. var ret = [];
  12695. var distance = 0;
  12696. for (var i = 1; i < len; i++) {
  12697. distance += vec2.distance(points[i - 1], points[i]);
  12698. }
  12699. var segs = distance / 2;
  12700. segs = segs < len ? len : segs;
  12701. for (var i = 0; i < segs; i++) {
  12702. var pos = i / (segs - 1) * (isLoop ? len : len - 1);
  12703. var idx = Math.floor(pos);
  12704. var w = pos - idx;
  12705. var p0;
  12706. var p1 = points[idx % len];
  12707. var p2;
  12708. var p3;
  12709. if (!isLoop) {
  12710. p0 = points[idx === 0 ? idx : idx - 1];
  12711. p2 = points[idx > len - 2 ? len - 1 : idx + 1];
  12712. p3 = points[idx > len - 3 ? len - 1 : idx + 2];
  12713. }
  12714. else {
  12715. p0 = points[(idx - 1 + len) % len];
  12716. p2 = points[(idx + 1) % len];
  12717. p3 = points[(idx + 2) % len];
  12718. }
  12719. var w2 = w * w;
  12720. var w3 = w * w2;
  12721. ret.push([
  12722. interpolate(p0[0], p1[0], p2[0], p3[0], w, w2, w3),
  12723. interpolate(p0[1], p1[1], p2[1], p3[1], w, w2, w3)
  12724. ]);
  12725. }
  12726. return ret;
  12727. };
  12728. /***/ },
  12729. /* 69 */
  12730. /***/ function(module, exports, __webpack_require__) {
  12731. /**
  12732. * 贝塞尔平滑曲线
  12733. * @module zrender/shape/util/smoothBezier
  12734. * @author pissang (https://www.github.com/pissang)
  12735. * Kener (@Kener-林峰, kener.linfeng@gmail.com)
  12736. * errorrik (errorrik@gmail.com)
  12737. */
  12738. var vec2 = __webpack_require__(16);
  12739. var v2Min = vec2.min;
  12740. var v2Max = vec2.max;
  12741. var v2Scale = vec2.scale;
  12742. var v2Distance = vec2.distance;
  12743. var v2Add = vec2.add;
  12744. /**
  12745. * 贝塞尔平滑曲线
  12746. * @alias module:zrender/shape/util/smoothBezier
  12747. * @param {Array} points 线段顶点数组
  12748. * @param {number} smooth 平滑等级, 0-1
  12749. * @param {boolean} isLoop
  12750. * @param {Array} constraint 将计算出来的控制点约束在一个包围盒内
  12751. * 比如 [[0, 0], [100, 100]], 这个包围盒会与
  12752. * 整个折线的包围盒做一个并集用来约束控制点。
  12753. * @param {Array} 计算出来的控制点数组
  12754. */
  12755. module.exports = function (points, smooth, isLoop, constraint) {
  12756. var cps = [];
  12757. var v = [];
  12758. var v1 = [];
  12759. var v2 = [];
  12760. var prevPoint;
  12761. var nextPoint;
  12762. var min, max;
  12763. if (constraint) {
  12764. min = [Infinity, Infinity];
  12765. max = [-Infinity, -Infinity];
  12766. for (var i = 0, len = points.length; i < len; i++) {
  12767. v2Min(min, min, points[i]);
  12768. v2Max(max, max, points[i]);
  12769. }
  12770. // 与指定的包围盒做并集
  12771. v2Min(min, min, constraint[0]);
  12772. v2Max(max, max, constraint[1]);
  12773. }
  12774. for (var i = 0, len = points.length; i < len; i++) {
  12775. var point = points[i];
  12776. if (isLoop) {
  12777. prevPoint = points[i ? i - 1 : len - 1];
  12778. nextPoint = points[(i + 1) % len];
  12779. }
  12780. else {
  12781. if (i === 0 || i === len - 1) {
  12782. cps.push(vec2.clone(points[i]));
  12783. continue;
  12784. }
  12785. else {
  12786. prevPoint = points[i - 1];
  12787. nextPoint = points[i + 1];
  12788. }
  12789. }
  12790. vec2.sub(v, nextPoint, prevPoint);
  12791. // use degree to scale the handle length
  12792. v2Scale(v, v, smooth);
  12793. var d0 = v2Distance(point, prevPoint);
  12794. var d1 = v2Distance(point, nextPoint);
  12795. var sum = d0 + d1;
  12796. if (sum !== 0) {
  12797. d0 /= sum;
  12798. d1 /= sum;
  12799. }
  12800. v2Scale(v1, v, -d0);
  12801. v2Scale(v2, v, d1);
  12802. var cp0 = v2Add([], point, v1);
  12803. var cp1 = v2Add([], point, v2);
  12804. if (constraint) {
  12805. v2Max(cp0, cp0, min);
  12806. v2Min(cp0, cp0, max);
  12807. v2Max(cp1, cp1, min);
  12808. v2Min(cp1, cp1, max);
  12809. }
  12810. cps.push(cp0);
  12811. cps.push(cp1);
  12812. }
  12813. if (isLoop) {
  12814. cps.push(cps.shift());
  12815. }
  12816. return cps;
  12817. };
  12818. /***/ },
  12819. /* 70 */
  12820. /***/ function(module, exports, __webpack_require__) {
  12821. /**
  12822. * @module zrender/graphic/shape/Polyline
  12823. */
  12824. var polyHelper = __webpack_require__(67);
  12825. module.exports = __webpack_require__(44).extend({
  12826. type: 'polyline',
  12827. shape: {
  12828. points: null,
  12829. smooth: false,
  12830. smoothConstraint: null
  12831. },
  12832. style: {
  12833. stroke: '#000',
  12834. fill: null
  12835. },
  12836. buildPath: function (ctx, shape) {
  12837. polyHelper.buildPath(ctx, shape, false);
  12838. }
  12839. });
  12840. /***/ },
  12841. /* 71 */
  12842. /***/ function(module, exports, __webpack_require__) {
  12843. /**
  12844. * 矩形
  12845. * @module zrender/graphic/shape/Rect
  12846. */
  12847. var roundRectHelper = __webpack_require__(60);
  12848. module.exports = __webpack_require__(44).extend({
  12849. type: 'rect',
  12850. shape: {
  12851. // 左上、右上、右下、左下角的半径依次为r1、r2、r3、r4
  12852. // r缩写为1 相当于 [1, 1, 1, 1]
  12853. // r缩写为[1] 相当于 [1, 1, 1, 1]
  12854. // r缩写为[1, 2] 相当于 [1, 2, 1, 2]
  12855. // r缩写为[1, 2, 3] 相当于 [1, 2, 3, 2]
  12856. r: 0,
  12857. x: 0,
  12858. y: 0,
  12859. width: 0,
  12860. height: 0
  12861. },
  12862. buildPath: function (ctx, shape) {
  12863. var x = shape.x;
  12864. var y = shape.y;
  12865. var width = shape.width;
  12866. var height = shape.height;
  12867. if (!shape.r) {
  12868. ctx.rect(x, y, width, height);
  12869. }
  12870. else {
  12871. roundRectHelper.buildPath(ctx, shape);
  12872. }
  12873. ctx.closePath();
  12874. return;
  12875. }
  12876. });
  12877. /***/ },
  12878. /* 72 */
  12879. /***/ function(module, exports, __webpack_require__) {
  12880. /**
  12881. * 直线
  12882. * @module zrender/graphic/shape/Line
  12883. */
  12884. module.exports = __webpack_require__(44).extend({
  12885. type: 'line',
  12886. shape: {
  12887. // Start point
  12888. x1: 0,
  12889. y1: 0,
  12890. // End point
  12891. x2: 0,
  12892. y2: 0,
  12893. percent: 1
  12894. },
  12895. style: {
  12896. stroke: '#000',
  12897. fill: null
  12898. },
  12899. buildPath: function (ctx, shape) {
  12900. var x1 = shape.x1;
  12901. var y1 = shape.y1;
  12902. var x2 = shape.x2;
  12903. var y2 = shape.y2;
  12904. var percent = shape.percent;
  12905. if (percent === 0) {
  12906. return;
  12907. }
  12908. ctx.moveTo(x1, y1);
  12909. if (percent < 1) {
  12910. x2 = x1 * (1 - percent) + x2 * percent;
  12911. y2 = y1 * (1 - percent) + y2 * percent;
  12912. }
  12913. ctx.lineTo(x2, y2);
  12914. },
  12915. /**
  12916. * Get point at percent
  12917. * @param {number} percent
  12918. * @return {Array.<number>}
  12919. */
  12920. pointAt: function (p) {
  12921. var shape = this.shape;
  12922. return [
  12923. shape.x1 * (1 - p) + shape.x2 * p,
  12924. shape.y1 * (1 - p) + shape.y2 * p
  12925. ];
  12926. }
  12927. });
  12928. /***/ },
  12929. /* 73 */
  12930. /***/ function(module, exports, __webpack_require__) {
  12931. 'use strict';
  12932. /**
  12933. * 贝塞尔曲线
  12934. * @module zrender/shape/BezierCurve
  12935. */
  12936. var curveTool = __webpack_require__(49);
  12937. var vec2 = __webpack_require__(16);
  12938. var quadraticSubdivide = curveTool.quadraticSubdivide;
  12939. var cubicSubdivide = curveTool.cubicSubdivide;
  12940. var quadraticAt = curveTool.quadraticAt;
  12941. var cubicAt = curveTool.cubicAt;
  12942. var quadraticDerivativeAt = curveTool.quadraticDerivativeAt;
  12943. var cubicDerivativeAt = curveTool.cubicDerivativeAt;
  12944. var out = [];
  12945. function someVectorAt(shape, t, isTangent) {
  12946. var cpx2 = shape.cpx2;
  12947. var cpy2 = shape.cpy2;
  12948. if (cpx2 === null || cpy2 === null) {
  12949. return [
  12950. (isTangent ? cubicDerivativeAt : cubicAt)(shape.x1, shape.cpx1, shape.cpx2, shape.x2, t),
  12951. (isTangent ? cubicDerivativeAt : cubicAt)(shape.y1, shape.cpy1, shape.cpy2, shape.y2, t)
  12952. ];
  12953. }
  12954. else {
  12955. return [
  12956. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.x1, shape.cpx1, shape.x2, t),
  12957. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.y1, shape.cpy1, shape.y2, t)
  12958. ];
  12959. }
  12960. }
  12961. module.exports = __webpack_require__(44).extend({
  12962. type: 'bezier-curve',
  12963. shape: {
  12964. x1: 0,
  12965. y1: 0,
  12966. x2: 0,
  12967. y2: 0,
  12968. cpx1: 0,
  12969. cpy1: 0,
  12970. // cpx2: 0,
  12971. // cpy2: 0
  12972. // Curve show percent, for animating
  12973. percent: 1
  12974. },
  12975. style: {
  12976. stroke: '#000',
  12977. fill: null
  12978. },
  12979. buildPath: function (ctx, shape) {
  12980. var x1 = shape.x1;
  12981. var y1 = shape.y1;
  12982. var x2 = shape.x2;
  12983. var y2 = shape.y2;
  12984. var cpx1 = shape.cpx1;
  12985. var cpy1 = shape.cpy1;
  12986. var cpx2 = shape.cpx2;
  12987. var cpy2 = shape.cpy2;
  12988. var percent = shape.percent;
  12989. if (percent === 0) {
  12990. return;
  12991. }
  12992. ctx.moveTo(x1, y1);
  12993. if (cpx2 == null || cpy2 == null) {
  12994. if (percent < 1) {
  12995. quadraticSubdivide(
  12996. x1, cpx1, x2, percent, out
  12997. );
  12998. cpx1 = out[1];
  12999. x2 = out[2];
  13000. quadraticSubdivide(
  13001. y1, cpy1, y2, percent, out
  13002. );
  13003. cpy1 = out[1];
  13004. y2 = out[2];
  13005. }
  13006. ctx.quadraticCurveTo(
  13007. cpx1, cpy1,
  13008. x2, y2
  13009. );
  13010. }
  13011. else {
  13012. if (percent < 1) {
  13013. cubicSubdivide(
  13014. x1, cpx1, cpx2, x2, percent, out
  13015. );
  13016. cpx1 = out[1];
  13017. cpx2 = out[2];
  13018. x2 = out[3];
  13019. cubicSubdivide(
  13020. y1, cpy1, cpy2, y2, percent, out
  13021. );
  13022. cpy1 = out[1];
  13023. cpy2 = out[2];
  13024. y2 = out[3];
  13025. }
  13026. ctx.bezierCurveTo(
  13027. cpx1, cpy1,
  13028. cpx2, cpy2,
  13029. x2, y2
  13030. );
  13031. }
  13032. },
  13033. /**
  13034. * Get point at percent
  13035. * @param {number} t
  13036. * @return {Array.<number>}
  13037. */
  13038. pointAt: function (t) {
  13039. return someVectorAt(this.shape, t, false);
  13040. },
  13041. /**
  13042. * Get tangent at percent
  13043. * @param {number} t
  13044. * @return {Array.<number>}
  13045. */
  13046. tangentAt: function (t) {
  13047. var p = someVectorAt(this.shape, t, true);
  13048. return vec2.normalize(p, p);
  13049. }
  13050. });
  13051. /***/ },
  13052. /* 74 */
  13053. /***/ function(module, exports, __webpack_require__) {
  13054. /**
  13055. * 圆弧
  13056. * @module zrender/graphic/shape/Arc
  13057. */
  13058. module.exports = __webpack_require__(44).extend({
  13059. type: 'arc',
  13060. shape: {
  13061. cx: 0,
  13062. cy: 0,
  13063. r: 0,
  13064. startAngle: 0,
  13065. endAngle: Math.PI * 2,
  13066. clockwise: true
  13067. },
  13068. style: {
  13069. stroke: '#000',
  13070. fill: null
  13071. },
  13072. buildPath: function (ctx, shape) {
  13073. var x = shape.cx;
  13074. var y = shape.cy;
  13075. var r = Math.max(shape.r, 0);
  13076. var startAngle = shape.startAngle;
  13077. var endAngle = shape.endAngle;
  13078. var clockwise = shape.clockwise;
  13079. var unitX = Math.cos(startAngle);
  13080. var unitY = Math.sin(startAngle);
  13081. ctx.moveTo(unitX * r + x, unitY * r + y);
  13082. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  13083. }
  13084. });
  13085. /***/ },
  13086. /* 75 */
  13087. /***/ function(module, exports, __webpack_require__) {
  13088. // CompoundPath to improve performance
  13089. var Path = __webpack_require__(44);
  13090. module.exports = Path.extend({
  13091. type: 'compound',
  13092. shape: {
  13093. paths: null
  13094. },
  13095. _updatePathDirty: function () {
  13096. var dirtyPath = this.__dirtyPath;
  13097. var paths = this.shape.paths;
  13098. for (var i = 0; i < paths.length; i++) {
  13099. // Mark as dirty if any subpath is dirty
  13100. dirtyPath = dirtyPath || paths[i].__dirtyPath;
  13101. }
  13102. this.__dirtyPath = dirtyPath;
  13103. this.__dirty = this.__dirty || dirtyPath;
  13104. },
  13105. beforeBrush: function () {
  13106. this._updatePathDirty();
  13107. var paths = this.shape.paths || [];
  13108. var scale = this.getGlobalScale();
  13109. // Update path scale
  13110. for (var i = 0; i < paths.length; i++) {
  13111. paths[i].path.setScale(scale[0], scale[1]);
  13112. }
  13113. },
  13114. buildPath: function (ctx, shape) {
  13115. var paths = shape.paths || [];
  13116. for (var i = 0; i < paths.length; i++) {
  13117. paths[i].buildPath(ctx, paths[i].shape);
  13118. }
  13119. },
  13120. afterBrush: function () {
  13121. var paths = this.shape.paths;
  13122. for (var i = 0; i < paths.length; i++) {
  13123. paths[i].__dirtyPath = false;
  13124. }
  13125. },
  13126. getBoundingRect: function () {
  13127. this._updatePathDirty();
  13128. return Path.prototype.getBoundingRect.call(this);
  13129. }
  13130. });
  13131. /***/ },
  13132. /* 76 */
  13133. /***/ function(module, exports, __webpack_require__) {
  13134. 'use strict';
  13135. var zrUtil = __webpack_require__(3);
  13136. var Gradient = __webpack_require__(4);
  13137. /**
  13138. * x, y, x2, y2 are all percent from 0 to 1
  13139. * @param {number} [x=0]
  13140. * @param {number} [y=0]
  13141. * @param {number} [x2=1]
  13142. * @param {number} [y2=0]
  13143. * @param {Array.<Object>} colorStops
  13144. */
  13145. var LinearGradient = function (x, y, x2, y2, colorStops) {
  13146. this.x = x == null ? 0 : x;
  13147. this.y = y == null ? 0 : y;
  13148. this.x2 = x2 == null ? 1 : x2;
  13149. this.y2 = y2 == null ? 0 : y2;
  13150. Gradient.call(this, colorStops);
  13151. };
  13152. LinearGradient.prototype = {
  13153. constructor: LinearGradient,
  13154. type: 'linear'
  13155. };
  13156. zrUtil.inherits(LinearGradient, Gradient);
  13157. module.exports = LinearGradient;
  13158. /***/ },
  13159. /* 77 */
  13160. /***/ function(module, exports, __webpack_require__) {
  13161. 'use strict';
  13162. var zrUtil = __webpack_require__(3);
  13163. var Gradient = __webpack_require__(4);
  13164. /**
  13165. * x, y, r are all percent from 0 to 1
  13166. * @param {number} [x=0.5]
  13167. * @param {number} [y=0.5]
  13168. * @param {number} [r=0.5]
  13169. * @param {Array.<Object>} [colorStops]
  13170. */
  13171. var RadialGradient = function (x, y, r, colorStops) {
  13172. this.x = x == null ? 0.5 : x;
  13173. this.y = y == null ? 0.5 : y;
  13174. this.r = r == null ? 0.5 : r;
  13175. Gradient.call(this, colorStops);
  13176. };
  13177. RadialGradient.prototype = {
  13178. constructor: RadialGradient,
  13179. type: 'radial'
  13180. };
  13181. zrUtil.inherits(RadialGradient, Gradient);
  13182. module.exports = RadialGradient;
  13183. /***/ },
  13184. /* 78 */
  13185. /***/ function(module, exports, __webpack_require__) {
  13186. /*!
  13187. * ZRender, a high performance 2d drawing library.
  13188. *
  13189. * Copyright (c) 2013, Baidu Inc.
  13190. * All rights reserved.
  13191. *
  13192. * LICENSE
  13193. * https://github.com/ecomfe/zrender/blob/master/LICENSE.txt
  13194. */
  13195. // Global defines
  13196. var guid = __webpack_require__(31);
  13197. var env = __webpack_require__(79);
  13198. var Handler = __webpack_require__(80);
  13199. var Storage = __webpack_require__(84);
  13200. var Animation = __webpack_require__(85);
  13201. var useVML = !env.canvasSupported;
  13202. var painterCtors = {
  13203. canvas: __webpack_require__(86)
  13204. };
  13205. var instances = {}; // ZRender实例map索引
  13206. var zrender = {};
  13207. /**
  13208. * @type {string}
  13209. */
  13210. zrender.version = '3.1.0';
  13211. /**
  13212. * Initializing a zrender instance
  13213. * @param {HTMLElement} dom
  13214. * @param {Object} opts
  13215. * @param {string} [opts.renderer='canvas'] 'canvas' or 'svg'
  13216. * @param {number} [opts.devicePixelRatio]
  13217. * @return {module:zrender/ZRender}
  13218. */
  13219. zrender.init = function(dom, opts) {
  13220. var zr = new ZRender(guid(), dom, opts);
  13221. instances[zr.id] = zr;
  13222. return zr;
  13223. };
  13224. /**
  13225. * Dispose zrender instance
  13226. * @param {module:zrender/ZRender} zr
  13227. */
  13228. zrender.dispose = function (zr) {
  13229. if (zr) {
  13230. zr.dispose();
  13231. }
  13232. else {
  13233. for (var key in instances) {
  13234. instances[key].dispose();
  13235. }
  13236. instances = {};
  13237. }
  13238. return zrender;
  13239. };
  13240. /**
  13241. * Get zrender instance by id
  13242. * @param {string} id zrender instance id
  13243. * @return {module:zrender/ZRender}
  13244. */
  13245. zrender.getInstance = function (id) {
  13246. return instances[id];
  13247. };
  13248. zrender.registerPainter = function (name, Ctor) {
  13249. painterCtors[name] = Ctor;
  13250. };
  13251. function delInstance(id) {
  13252. delete instances[id];
  13253. }
  13254. /**
  13255. * @module zrender/ZRender
  13256. */
  13257. /**
  13258. * @constructor
  13259. * @alias module:zrender/ZRender
  13260. * @param {string} id
  13261. * @param {HTMLDomElement} dom
  13262. * @param {Object} opts
  13263. * @param {string} [opts.renderer='canvas'] 'canvas' or 'svg'
  13264. * @param {number} [opts.devicePixelRatio]
  13265. */
  13266. var ZRender = function(id, dom, opts) {
  13267. opts = opts || {};
  13268. /**
  13269. * @type {HTMLDomElement}
  13270. */
  13271. this.dom = dom;
  13272. /**
  13273. * @type {string}
  13274. */
  13275. this.id = id;
  13276. var self = this;
  13277. var storage = new Storage();
  13278. var rendererType = opts.renderer;
  13279. if (useVML) {
  13280. if (!painterCtors.vml) {
  13281. throw new Error('You need to require \'zrender/vml/vml\' to support IE8');
  13282. }
  13283. rendererType = 'vml';
  13284. }
  13285. else if (!rendererType || !painterCtors[rendererType]) {
  13286. rendererType = 'canvas';
  13287. }
  13288. var painter = new painterCtors[rendererType](dom, storage, opts);
  13289. this.storage = storage;
  13290. this.painter = painter;
  13291. if (!env.node) {
  13292. this.handler = new Handler(painter.getViewportRoot(), storage, painter);
  13293. }
  13294. /**
  13295. * @type {module:zrender/animation/Animation}
  13296. */
  13297. this.animation = new Animation({
  13298. stage: {
  13299. update: function () {
  13300. if (self._needsRefresh) {
  13301. self.refreshImmediately();
  13302. }
  13303. }
  13304. }
  13305. });
  13306. this.animation.start();
  13307. /**
  13308. * @type {boolean}
  13309. * @private
  13310. */
  13311. this._needsRefresh;
  13312. // 修改 storage.delFromMap, 每次删除元素之前删除动画
  13313. // FIXME 有点ugly
  13314. var oldDelFromMap = storage.delFromMap;
  13315. var oldAddToMap = storage.addToMap;
  13316. storage.delFromMap = function (elId) {
  13317. var el = storage.get(elId);
  13318. oldDelFromMap.call(storage, elId);
  13319. el && el.removeSelfFromZr(self);
  13320. };
  13321. storage.addToMap = function (el) {
  13322. oldAddToMap.call(storage, el);
  13323. el.addSelfToZr(self);
  13324. };
  13325. };
  13326. ZRender.prototype = {
  13327. constructor: ZRender,
  13328. /**
  13329. * 获取实例唯一标识
  13330. * @return {string}
  13331. */
  13332. getId: function () {
  13333. return this.id;
  13334. },
  13335. /**
  13336. * 添加元素
  13337. * @param {string|module:zrender/Element} el
  13338. */
  13339. add: function (el) {
  13340. this.storage.addRoot(el);
  13341. this._needsRefresh = true;
  13342. },
  13343. /**
  13344. * 删除元素
  13345. * @param {string|module:zrender/Element} el
  13346. */
  13347. remove: function (el) {
  13348. this.storage.delRoot(el);
  13349. this._needsRefresh = true;
  13350. },
  13351. /**
  13352. * Change configuration of layer
  13353. * @param {string} zLevel
  13354. * @param {Object} config
  13355. * @param {string} [config.clearColor=0] Clear color
  13356. * @param {string} [config.motionBlur=false] If enable motion blur
  13357. * @param {number} [config.lastFrameAlpha=0.7] Motion blur factor. Larger value cause longer trailer
  13358. */
  13359. configLayer: function (zLevel, config) {
  13360. this.painter.configLayer(zLevel, config);
  13361. this._needsRefresh = true;
  13362. },
  13363. /**
  13364. * Repaint the canvas immediately
  13365. */
  13366. refreshImmediately: function () {
  13367. // Clear needsRefresh ahead to avoid something wrong happens in refresh
  13368. // Or it will cause zrender refreshes again and again.
  13369. this._needsRefresh = false;
  13370. this.painter.refresh();
  13371. /**
  13372. * Avoid trigger zr.refresh in Element#beforeUpdate hook
  13373. */
  13374. this._needsRefresh = false;
  13375. },
  13376. /**
  13377. * Mark and repaint the canvas in the next frame of browser
  13378. */
  13379. refresh: function() {
  13380. this._needsRefresh = true;
  13381. },
  13382. /**
  13383. * Resize the canvas.
  13384. * Should be invoked when container size is changed
  13385. */
  13386. resize: function() {
  13387. this.painter.resize();
  13388. this.handler && this.handler.resize();
  13389. },
  13390. /**
  13391. * Stop and clear all animation immediately
  13392. */
  13393. clearAnimation: function () {
  13394. this.animation.clear();
  13395. },
  13396. /**
  13397. * Get container width
  13398. */
  13399. getWidth: function() {
  13400. return this.painter.getWidth();
  13401. },
  13402. /**
  13403. * Get container height
  13404. */
  13405. getHeight: function() {
  13406. return this.painter.getHeight();
  13407. },
  13408. /**
  13409. * Export the canvas as Base64 URL
  13410. * @param {string} type
  13411. * @param {string} [backgroundColor='#fff']
  13412. * @return {string} Base64 URL
  13413. */
  13414. // toDataURL: function(type, backgroundColor) {
  13415. // return this.painter.getRenderedCanvas({
  13416. // backgroundColor: backgroundColor
  13417. // }).toDataURL(type);
  13418. // },
  13419. /**
  13420. * Converting a path to image.
  13421. * It has much better performance of drawing image rather than drawing a vector path.
  13422. * @param {module:zrender/graphic/Path} e
  13423. * @param {number} width
  13424. * @param {number} height
  13425. */
  13426. pathToImage: function(e, width, height) {
  13427. var id = guid();
  13428. return this.painter.pathToImage(id, e, width, height);
  13429. },
  13430. /**
  13431. * Set default cursor
  13432. * @param {string} cursorStyle 例如 crosshair
  13433. */
  13434. setDefaultCursorStyle: function (cursorStyle) {
  13435. this.handler.setDefaultCursorStyle(cursorStyle);
  13436. },
  13437. /**
  13438. * Bind event
  13439. *
  13440. * @param {string} eventName Event name
  13441. * @param {Function} eventHandler Handler function
  13442. * @param {Object} [context] Context object
  13443. */
  13444. on: function(eventName, eventHandler, context) {
  13445. this.handler && this.handler.on(eventName, eventHandler, context);
  13446. },
  13447. /**
  13448. * Unbind event
  13449. * @param {string} eventName Event name
  13450. * @param {Function} [eventHandler] Handler function
  13451. */
  13452. off: function(eventName, eventHandler) {
  13453. this.handler && this.handler.off(eventName, eventHandler);
  13454. },
  13455. /**
  13456. * Trigger event manually
  13457. *
  13458. * @param {string} eventName Event name
  13459. * @param {event=} event Event object
  13460. */
  13461. trigger: function (eventName, event) {
  13462. this.handler && this.handler.trigger(eventName, event);
  13463. },
  13464. /**
  13465. * Clear all objects and the canvas.
  13466. */
  13467. clear: function () {
  13468. this.storage.delRoot();
  13469. this.painter.clear();
  13470. },
  13471. /**
  13472. * Dispose self.
  13473. */
  13474. dispose: function () {
  13475. this.animation.stop();
  13476. this.clear();
  13477. this.storage.dispose();
  13478. this.painter.dispose();
  13479. this.handler && this.handler.dispose();
  13480. this.animation =
  13481. this.storage =
  13482. this.painter =
  13483. this.handler = null;
  13484. delInstance(this.id);
  13485. }
  13486. };
  13487. module.exports = zrender;
  13488. /***/ },
  13489. /* 79 */
  13490. /***/ function(module, exports) {
  13491. /**
  13492. * echarts设备环境识别
  13493. *
  13494. * @desc echarts基于Canvas,纯Javascript图表库,提供直观,生动,可交互,可个性化定制的数据统计图表。
  13495. * @author firede[firede@firede.us]
  13496. * @desc thanks zepto.
  13497. */
  13498. var env = {};
  13499. if (typeof navigator === 'undefined') {
  13500. // In node
  13501. env = {
  13502. browser: {},
  13503. os: {},
  13504. node: true,
  13505. // Assume canvas is supported
  13506. canvasSupported: true
  13507. };
  13508. }
  13509. else {
  13510. env = detect(navigator.userAgent);
  13511. }
  13512. module.exports = env;
  13513. // Zepto.js
  13514. // (c) 2010-2013 Thomas Fuchs
  13515. // Zepto.js may be freely distributed under the MIT license.
  13516. function detect(ua) {
  13517. var os = {};
  13518. var browser = {};
  13519. var webkit = ua.match(/Web[kK]it[\/]{0,1}([\d.]+)/);
  13520. var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
  13521. var ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
  13522. var ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
  13523. var iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/);
  13524. var webos = ua.match(/(webOS|hpwOS)[\s\/]([\d.]+)/);
  13525. var touchpad = webos && ua.match(/TouchPad/);
  13526. var kindle = ua.match(/Kindle\/([\d.]+)/);
  13527. var silk = ua.match(/Silk\/([\d._]+)/);
  13528. var blackberry = ua.match(/(BlackBerry).*Version\/([\d.]+)/);
  13529. var bb10 = ua.match(/(BB10).*Version\/([\d.]+)/);
  13530. var rimtabletos = ua.match(/(RIM\sTablet\sOS)\s([\d.]+)/);
  13531. var playbook = ua.match(/PlayBook/);
  13532. var chrome = ua.match(/Chrome\/([\d.]+)/) || ua.match(/CriOS\/([\d.]+)/);
  13533. var firefox = ua.match(/Firefox\/([\d.]+)/);
  13534. var safari = webkit && ua.match(/Mobile\//) && !chrome;
  13535. var webview = ua.match(/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/) && !chrome;
  13536. var ie = ua.match(/MSIE\s([\d.]+)/)
  13537. // IE 11 Trident/7.0; rv:11.0
  13538. || ua.match(/Trident\/.+?rv:(([\d.]+))/);
  13539. var edge = ua.match(/Edge\/([\d.]+)/); // IE 12 and 12+
  13540. // Todo: clean this up with a better OS/browser seperation:
  13541. // - discern (more) between multiple browsers on android
  13542. // - decide if kindle fire in silk mode is android or not
  13543. // - Firefox on Android doesn't specify the Android version
  13544. // - possibly devide in os, device and browser hashes
  13545. if (browser.webkit = !!webkit) browser.version = webkit[1];
  13546. if (android) os.android = true, os.version = android[2];
  13547. if (iphone && !ipod) os.ios = os.iphone = true, os.version = iphone[2].replace(/_/g, '.');
  13548. if (ipad) os.ios = os.ipad = true, os.version = ipad[2].replace(/_/g, '.');
  13549. if (ipod) os.ios = os.ipod = true, os.version = ipod[3] ? ipod[3].replace(/_/g, '.') : null;
  13550. if (webos) os.webos = true, os.version = webos[2];
  13551. if (touchpad) os.touchpad = true;
  13552. if (blackberry) os.blackberry = true, os.version = blackberry[2];
  13553. if (bb10) os.bb10 = true, os.version = bb10[2];
  13554. if (rimtabletos) os.rimtabletos = true, os.version = rimtabletos[2];
  13555. if (playbook) browser.playbook = true;
  13556. if (kindle) os.kindle = true, os.version = kindle[1];
  13557. if (silk) browser.silk = true, browser.version = silk[1];
  13558. if (!silk && os.android && ua.match(/Kindle Fire/)) browser.silk = true;
  13559. if (chrome) browser.chrome = true, browser.version = chrome[1];
  13560. if (firefox) browser.firefox = true, browser.version = firefox[1];
  13561. if (ie) browser.ie = true, browser.version = ie[1];
  13562. if (safari && (ua.match(/Safari/) || !!os.ios)) browser.safari = true;
  13563. if (webview) browser.webview = true;
  13564. if (ie) browser.ie = true, browser.version = ie[1];
  13565. if (edge) browser.edge = true, browser.version = edge[1];
  13566. os.tablet = !!(ipad || playbook || (android && !ua.match(/Mobile/)) ||
  13567. (firefox && ua.match(/Tablet/)) || (ie && !ua.match(/Phone/) && ua.match(/Touch/)));
  13568. os.phone = !!(!os.tablet && !os.ipod && (android || iphone || webos || blackberry || bb10 ||
  13569. (chrome && ua.match(/Android/)) || (chrome && ua.match(/CriOS\/([\d.]+)/)) ||
  13570. (firefox && ua.match(/Mobile/)) || (ie && ua.match(/Touch/))));
  13571. return {
  13572. browser: browser,
  13573. os: os,
  13574. node: false,
  13575. // 原生canvas支持,改极端点了
  13576. // canvasSupported : !(browser.ie && parseFloat(browser.version) < 9)
  13577. canvasSupported : document.createElement('canvas').getContext ? true : false,
  13578. // @see <http://stackoverflow.com/questions/4817029/whats-the-best-way-to-detect-a-touch-screen-device-using-javascript>
  13579. // works on most browsers
  13580. // IE10/11 does not support touch event, and MS Edge supports them but not by
  13581. // default, so we dont check navigator.maxTouchPoints for them here.
  13582. touchEventsSupported: 'ontouchstart' in window && !browser.ie && !browser.edge,
  13583. // <http://caniuse.com/#search=pointer%20event>.
  13584. pointerEventsSupported: 'onpointerdown' in window
  13585. // Firefox supports pointer but not by default,
  13586. // only MS browsers are reliable on pointer events currently.
  13587. && (browser.edge || (browser.ie && browser.version >= 10))
  13588. };
  13589. }
  13590. /***/ },
  13591. /* 80 */
  13592. /***/ function(module, exports, __webpack_require__) {
  13593. 'use strict';
  13594. /**
  13595. * Handler
  13596. * @module zrender/Handler
  13597. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  13598. * errorrik (errorrik@gmail.com)
  13599. * pissang (shenyi.914@gmail.com)
  13600. */
  13601. var env = __webpack_require__(79);
  13602. var eventTool = __webpack_require__(81);
  13603. var util = __webpack_require__(3);
  13604. var Draggable = __webpack_require__(82);
  13605. var GestureMgr = __webpack_require__(83);
  13606. var Eventful = __webpack_require__(32);
  13607. var mouseHandlerNames = [
  13608. 'click', 'dblclick', 'mousewheel', 'mouseout'
  13609. ];
  13610. !usePointerEvent() && mouseHandlerNames.push(
  13611. 'mouseup', 'mousedown', 'mousemove'
  13612. );
  13613. var touchHandlerNames = [
  13614. 'touchstart', 'touchend', 'touchmove'
  13615. ];
  13616. var pointerHandlerNames = [
  13617. 'pointerdown', 'pointerup', 'pointermove'
  13618. ];
  13619. var TOUCH_CLICK_DELAY = 300;
  13620. var addEventListener = eventTool.addEventListener;
  13621. var removeEventListener = eventTool.removeEventListener;
  13622. var normalizeEvent = eventTool.normalizeEvent;
  13623. function makeEventPacket(eveType, target, event) {
  13624. return {
  13625. type: eveType,
  13626. event: event,
  13627. target: target,
  13628. cancelBubble: false,
  13629. offsetX: event.zrX,
  13630. offsetY: event.zrY,
  13631. gestureEvent: event.gestureEvent,
  13632. pinchX: event.pinchX,
  13633. pinchY: event.pinchY,
  13634. pinchScale: event.pinchScale,
  13635. wheelDelta: event.zrDelta
  13636. };
  13637. }
  13638. var domHandlers = {
  13639. /**
  13640. * Mouse move handler
  13641. * @inner
  13642. * @param {Event} event
  13643. */
  13644. mousemove: function (event) {
  13645. event = normalizeEvent(this.root, event);
  13646. var x = event.zrX;
  13647. var y = event.zrY;
  13648. var hovered = this.findHover(x, y, null);
  13649. var lastHovered = this._hovered;
  13650. this._hovered = hovered;
  13651. this.root.style.cursor = hovered ? hovered.cursor : this._defaultCursorStyle;
  13652. // Mouse out on previous hovered element
  13653. if (lastHovered && hovered !== lastHovered && lastHovered.__zr) {
  13654. this._dispatchProxy(lastHovered, 'mouseout', event);
  13655. }
  13656. // Mouse moving on one element
  13657. this._dispatchProxy(hovered, 'mousemove', event);
  13658. // Mouse over on a new element
  13659. if (hovered && hovered !== lastHovered) {
  13660. this._dispatchProxy(hovered, 'mouseover', event);
  13661. }
  13662. },
  13663. /**
  13664. * Mouse out handler
  13665. * @inner
  13666. * @param {Event} event
  13667. */
  13668. mouseout: function (event) {
  13669. event = normalizeEvent(this.root, event);
  13670. var element = event.toElement || event.relatedTarget;
  13671. if (element != this.root) {
  13672. while (element && element.nodeType != 9) {
  13673. // 忽略包含在root中的dom引起的mouseOut
  13674. if (element === this.root) {
  13675. return;
  13676. }
  13677. element = element.parentNode;
  13678. }
  13679. }
  13680. this._dispatchProxy(this._hovered, 'mouseout', event);
  13681. this.trigger('globalout', {
  13682. event: event
  13683. });
  13684. },
  13685. /**
  13686. * Touch开始响应函数
  13687. * @inner
  13688. * @param {Event} event
  13689. */
  13690. touchstart: function (event) {
  13691. // Default mouse behaviour should not be disabled here.
  13692. // For example, page may needs to be slided.
  13693. // eventTool.stop(event);
  13694. event = normalizeEvent(this.root, event);
  13695. this._lastTouchMoment = new Date();
  13696. processGesture(this, event, 'start');
  13697. // 平板补充一次findHover
  13698. // this._mobileFindFixed(event);
  13699. // Trigger mousemove and mousedown
  13700. domHandlers.mousemove.call(this, event);
  13701. domHandlers.mousedown.call(this, event);
  13702. setTouchTimer(this);
  13703. },
  13704. /**
  13705. * Touch移动响应函数
  13706. * @inner
  13707. * @param {Event} event
  13708. */
  13709. touchmove: function (event) {
  13710. // eventTool.stop(event);// 阻止浏览器默认事件,重要
  13711. event = normalizeEvent(this.root, event);
  13712. processGesture(this, event, 'change');
  13713. // Mouse move should always be triggered no matter whether
  13714. // there is gestrue event, because mouse move and pinch may
  13715. // be used at the same time.
  13716. domHandlers.mousemove.call(this, event);
  13717. setTouchTimer(this);
  13718. },
  13719. /**
  13720. * Touch结束响应函数
  13721. * @inner
  13722. * @param {Event} event
  13723. */
  13724. touchend: function (event) {
  13725. // eventTool.stop(event);// 阻止浏览器默认事件,重要
  13726. event = normalizeEvent(this.root, event);
  13727. processGesture(this, event, 'end');
  13728. domHandlers.mouseup.call(this, event);
  13729. // click event should always be triggered no matter whether
  13730. // there is gestrue event. System click can not be prevented.
  13731. if (+new Date() - this._lastTouchMoment < TOUCH_CLICK_DELAY) {
  13732. // this._mobileFindFixed(event);
  13733. domHandlers.click.call(this, event);
  13734. }
  13735. setTouchTimer(this);
  13736. }
  13737. };
  13738. // Common handlers
  13739. util.each(['click', 'mousedown', 'mouseup', 'mousewheel', 'dblclick'], function (name) {
  13740. domHandlers[name] = function (event) {
  13741. event = normalizeEvent(this.root, event);
  13742. // Find hover again to avoid click event is dispatched manually. Or click is triggered without mouseover
  13743. var hovered = this.findHover(event.zrX, event.zrY, null);
  13744. if (name === 'mousedown') {
  13745. this._downel = hovered;
  13746. // In case click triggered before mouseup
  13747. this._upel = hovered;
  13748. }
  13749. else if (name === 'mosueup') {
  13750. this._upel = hovered;
  13751. }
  13752. else if (name === 'click') {
  13753. if (this._downel !== this._upel) {
  13754. return;
  13755. }
  13756. }
  13757. this._dispatchProxy(hovered, name, event);
  13758. };
  13759. });
  13760. // Pointer event handlers
  13761. // util.each(['pointerdown', 'pointermove', 'pointerup'], function (name) {
  13762. // domHandlers[name] = function (event) {
  13763. // var mouseName = name.replace('pointer', 'mouse');
  13764. // domHandlers[mouseName].call(this, event);
  13765. // };
  13766. // });
  13767. function processGesture(zrHandler, event, stage) {
  13768. var gestureMgr = zrHandler._gestureMgr;
  13769. stage === 'start' && gestureMgr.clear();
  13770. var gestureInfo = gestureMgr.recognize(
  13771. event,
  13772. zrHandler.findHover(event.zrX, event.zrY, null)
  13773. );
  13774. stage === 'end' && gestureMgr.clear();
  13775. if (gestureInfo) {
  13776. // eventTool.stop(event);
  13777. var type = gestureInfo.type;
  13778. event.gestureEvent = type;
  13779. zrHandler._dispatchProxy(gestureInfo.target, type, gestureInfo.event);
  13780. }
  13781. }
  13782. /**
  13783. * 为控制类实例初始化dom 事件处理函数
  13784. *
  13785. * @inner
  13786. * @param {module:zrender/Handler} instance 控制类实例
  13787. */
  13788. function initDomHandler(instance) {
  13789. var handlerNames = touchHandlerNames.concat(pointerHandlerNames);
  13790. for (var i = 0; i < handlerNames.length; i++) {
  13791. var name = handlerNames[i];
  13792. instance._handlers[name] = util.bind(domHandlers[name], instance);
  13793. }
  13794. for (var i = 0; i < mouseHandlerNames.length; i++) {
  13795. var name = mouseHandlerNames[i];
  13796. instance._handlers[name] = makeMouseHandler(domHandlers[name], instance);
  13797. }
  13798. function makeMouseHandler(fn, instance) {
  13799. return function () {
  13800. if (instance._touching) {
  13801. return;
  13802. }
  13803. return fn.apply(instance, arguments);
  13804. };
  13805. }
  13806. }
  13807. /**
  13808. * @alias module:zrender/Handler
  13809. * @constructor
  13810. * @extends module:zrender/mixin/Eventful
  13811. * @param {HTMLElement} root Main HTML element for painting.
  13812. * @param {module:zrender/Storage} storage Storage instance.
  13813. * @param {module:zrender/Painter} painter Painter instance.
  13814. */
  13815. var Handler = function(root, storage, painter) {
  13816. Eventful.call(this);
  13817. this.root = root;
  13818. this.storage = storage;
  13819. this.painter = painter;
  13820. /**
  13821. * @private
  13822. * @type {boolean}
  13823. */
  13824. this._hovered;
  13825. /**
  13826. * @private
  13827. * @type {Date}
  13828. */
  13829. this._lastTouchMoment;
  13830. /**
  13831. * @private
  13832. * @type {number}
  13833. */
  13834. this._lastX;
  13835. /**
  13836. * @private
  13837. * @type {number}
  13838. */
  13839. this._lastY;
  13840. /**
  13841. * @private
  13842. * @type {string}
  13843. */
  13844. this._defaultCursorStyle = 'default';
  13845. /**
  13846. * @private
  13847. * @type {module:zrender/core/GestureMgr}
  13848. */
  13849. this._gestureMgr = new GestureMgr();
  13850. /**
  13851. * @private
  13852. * @type {Array.<Function>}
  13853. */
  13854. this._handlers = [];
  13855. /**
  13856. * @private
  13857. * @type {boolean}
  13858. */
  13859. this._touching = false;
  13860. /**
  13861. * @private
  13862. * @type {number}
  13863. */
  13864. this._touchTimer;
  13865. initDomHandler(this);
  13866. if (usePointerEvent()) {
  13867. mountHandlers(pointerHandlerNames, this);
  13868. }
  13869. else if (useTouchEvent()) {
  13870. mountHandlers(touchHandlerNames, this);
  13871. // Handler of 'mouseout' event is needed in touch mode, which will be mounted below.
  13872. // addEventListener(root, 'mouseout', this._mouseoutHandler);
  13873. }
  13874. // Considering some devices that both enable touch and mouse event (like MS Surface
  13875. // and lenovo X240, @see #2350), we make mouse event be always listened, otherwise
  13876. // mouse event can not be handle in those devices.
  13877. mountHandlers(mouseHandlerNames, this);
  13878. Draggable.call(this);
  13879. function mountHandlers(handlerNames, instance) {
  13880. util.each(handlerNames, function (name) {
  13881. addEventListener(root, eventNameFix(name), instance._handlers[name]);
  13882. }, instance);
  13883. }
  13884. };
  13885. Handler.prototype = {
  13886. constructor: Handler,
  13887. /**
  13888. * Resize
  13889. */
  13890. resize: function (event) {
  13891. this._hovered = null;
  13892. },
  13893. /**
  13894. * Dispatch event
  13895. * @param {string} eventName
  13896. * @param {event=} eventArgs
  13897. */
  13898. dispatch: function (eventName, eventArgs) {
  13899. var handler = this._handlers[eventName];
  13900. handler && handler.call(this, eventArgs);
  13901. },
  13902. /**
  13903. * Dispose
  13904. */
  13905. dispose: function () {
  13906. var root = this.root;
  13907. var handlerNames = mouseHandlerNames.concat(touchHandlerNames);
  13908. for (var i = 0; i < handlerNames.length; i++) {
  13909. var name = handlerNames[i];
  13910. removeEventListener(root, eventNameFix(name), this._handlers[name]);
  13911. }
  13912. this.root =
  13913. this.storage =
  13914. this.painter = null;
  13915. },
  13916. /**
  13917. * 设置默认的cursor style
  13918. * @param {string} cursorStyle 例如 crosshair
  13919. */
  13920. setDefaultCursorStyle: function (cursorStyle) {
  13921. this._defaultCursorStyle = cursorStyle;
  13922. },
  13923. /**
  13924. * 事件分发代理
  13925. *
  13926. * @private
  13927. * @param {Object} targetEl 目标图形元素
  13928. * @param {string} eventName 事件名称
  13929. * @param {Object} event 事件对象
  13930. */
  13931. _dispatchProxy: function (targetEl, eventName, event) {
  13932. var eventHandler = 'on' + eventName;
  13933. var eventPacket = makeEventPacket(eventName, targetEl, event);
  13934. var el = targetEl;
  13935. while (el) {
  13936. el[eventHandler]
  13937. && (eventPacket.cancelBubble = el[eventHandler].call(el, eventPacket));
  13938. el.trigger(eventName, eventPacket);
  13939. el = el.parent;
  13940. if (eventPacket.cancelBubble) {
  13941. break;
  13942. }
  13943. }
  13944. if (!eventPacket.cancelBubble) {
  13945. // 冒泡到顶级 zrender 对象
  13946. this.trigger(eventName, eventPacket);
  13947. // 分发事件到用户自定义层
  13948. // 用户有可能在全局 click 事件中 dispose,所以需要判断下 painter 是否存在
  13949. this.painter && this.painter.eachOtherLayer(function (layer) {
  13950. if (typeof(layer[eventHandler]) == 'function') {
  13951. layer[eventHandler].call(layer, eventPacket);
  13952. }
  13953. if (layer.trigger) {
  13954. layer.trigger(eventName, eventPacket);
  13955. }
  13956. });
  13957. }
  13958. },
  13959. /**
  13960. * @private
  13961. * @param {number} x
  13962. * @param {number} y
  13963. * @param {module:zrender/graphic/Displayable} exclude
  13964. * @method
  13965. */
  13966. findHover: function(x, y, exclude) {
  13967. var list = this.storage.getDisplayList();
  13968. for (var i = list.length - 1; i >= 0 ; i--) {
  13969. if (!list[i].silent
  13970. && list[i] !== exclude
  13971. // getDisplayList may include ignored item in VML mode
  13972. && !list[i].ignore
  13973. && isHover(list[i], x, y)) {
  13974. return list[i];
  13975. }
  13976. }
  13977. }
  13978. };
  13979. function isHover(displayable, x, y) {
  13980. if (displayable[displayable.rectHover ? 'rectContain' : 'contain'](x, y)) {
  13981. var el = displayable;
  13982. while (el) {
  13983. // If ancestor is silent or clipped by ancestor
  13984. if (el.silent || (el.clipPath && !el.clipPath.contain(x, y))) {
  13985. return false;
  13986. }
  13987. el = el.parent;
  13988. }
  13989. return true;
  13990. }
  13991. return false;
  13992. }
  13993. /**
  13994. * Prevent mouse event from being dispatched after Touch Events action
  13995. * @see <https://github.com/deltakosh/handjs/blob/master/src/hand.base.js>
  13996. * 1. Mobile browsers dispatch mouse events 300ms after touchend.
  13997. * 2. Chrome for Android dispatch mousedown for long-touch about 650ms
  13998. * Result: Blocking Mouse Events for 700ms.
  13999. */
  14000. function setTouchTimer(instance) {
  14001. instance._touching = true;
  14002. clearTimeout(instance._touchTimer);
  14003. instance._touchTimer = setTimeout(function () {
  14004. instance._touching = false;
  14005. }, 700);
  14006. }
  14007. /**
  14008. * Althought MS Surface support screen touch, IE10/11 do not support
  14009. * touch event and MS Edge supported them but not by default (but chrome
  14010. * and firefox do). Thus we use Pointer event on MS browsers to handle touch.
  14011. */
  14012. function usePointerEvent() {
  14013. // TODO
  14014. // pointermove event dont trigger when using finger.
  14015. // We may figger it out latter.
  14016. return false;
  14017. // return env.pointerEventsSupported
  14018. // In no-touch device we dont use pointer evnets but just
  14019. // use mouse event for avoiding problems.
  14020. // && window.navigator.maxTouchPoints;
  14021. }
  14022. function useTouchEvent() {
  14023. return env.touchEventsSupported;
  14024. }
  14025. function eventNameFix(name) {
  14026. return (name === 'mousewheel' && env.browser.firefox) ? 'DOMMouseScroll' : name;
  14027. }
  14028. util.mixin(Handler, Eventful);
  14029. util.mixin(Handler, Draggable);
  14030. module.exports = Handler;
  14031. /***/ },
  14032. /* 81 */
  14033. /***/ function(module, exports, __webpack_require__) {
  14034. 'use strict';
  14035. /**
  14036. * 事件辅助类
  14037. * @module zrender/core/event
  14038. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  14039. */
  14040. var Eventful = __webpack_require__(32);
  14041. var isDomLevel2 = (typeof window !== 'undefined') && !!window.addEventListener;
  14042. function getBoundingClientRect(el) {
  14043. // BlackBerry 5, iOS 3 (original iPhone) don't have getBoundingRect
  14044. return el.getBoundingClientRect ? el.getBoundingClientRect() : { left: 0, top: 0};
  14045. }
  14046. /**
  14047. * 如果存在第三方嵌入的一些dom触发的事件,或touch事件,需要转换一下事件坐标
  14048. */
  14049. function normalizeEvent(el, e) {
  14050. e = e || window.event;
  14051. if (e.zrX != null) {
  14052. return e;
  14053. }
  14054. var eventType = e.type;
  14055. var isTouch = eventType && eventType.indexOf('touch') >= 0;
  14056. if (!isTouch) {
  14057. var box = getBoundingClientRect(el);
  14058. e.zrX = e.clientX - box.left;
  14059. e.zrY = e.clientY - box.top;
  14060. e.zrDelta = (e.wheelDelta) ? e.wheelDelta / 120 : -(e.detail || 0) / 3;
  14061. }
  14062. else {
  14063. var touch = eventType != 'touchend'
  14064. ? e.targetTouches[0]
  14065. : e.changedTouches[0];
  14066. if (touch) {
  14067. var rBounding = getBoundingClientRect(el);
  14068. // touch事件坐标是全屏的~
  14069. e.zrX = touch.clientX - rBounding.left;
  14070. e.zrY = touch.clientY - rBounding.top;
  14071. }
  14072. }
  14073. return e;
  14074. }
  14075. function addEventListener(el, name, handler) {
  14076. if (isDomLevel2) {
  14077. el.addEventListener(name, handler);
  14078. }
  14079. else {
  14080. el.attachEvent('on' + name, handler);
  14081. }
  14082. }
  14083. function removeEventListener(el, name, handler) {
  14084. if (isDomLevel2) {
  14085. el.removeEventListener(name, handler);
  14086. }
  14087. else {
  14088. el.detachEvent('on' + name, handler);
  14089. }
  14090. }
  14091. /**
  14092. * 停止冒泡和阻止默认行为
  14093. * @memberOf module:zrender/core/event
  14094. * @method
  14095. * @param {Event} e : event对象
  14096. */
  14097. var stop = isDomLevel2
  14098. ? function (e) {
  14099. e.preventDefault();
  14100. e.stopPropagation();
  14101. e.cancelBubble = true;
  14102. }
  14103. : function (e) {
  14104. e.returnValue = false;
  14105. e.cancelBubble = true;
  14106. };
  14107. module.exports = {
  14108. normalizeEvent: normalizeEvent,
  14109. addEventListener: addEventListener,
  14110. removeEventListener: removeEventListener,
  14111. stop: stop,
  14112. // 做向上兼容
  14113. Dispatcher: Eventful
  14114. };
  14115. /***/ },
  14116. /* 82 */
  14117. /***/ function(module, exports) {
  14118. // TODO Draggable for group
  14119. // FIXME Draggable on element which has parent rotation or scale
  14120. function Draggable() {
  14121. this.on('mousedown', this._dragStart, this);
  14122. this.on('mousemove', this._drag, this);
  14123. this.on('mouseup', this._dragEnd, this);
  14124. this.on('globalout', this._dragEnd, this);
  14125. // this._dropTarget = null;
  14126. // this._draggingTarget = null;
  14127. // this._x = 0;
  14128. // this._y = 0;
  14129. }
  14130. Draggable.prototype = {
  14131. constructor: Draggable,
  14132. _dragStart: function (e) {
  14133. var draggingTarget = e.target;
  14134. if (draggingTarget && draggingTarget.draggable) {
  14135. this._draggingTarget = draggingTarget;
  14136. draggingTarget.dragging = true;
  14137. this._x = e.offsetX;
  14138. this._y = e.offsetY;
  14139. this._dispatchProxy(draggingTarget, 'dragstart', e.event);
  14140. }
  14141. },
  14142. _drag: function (e) {
  14143. var draggingTarget = this._draggingTarget;
  14144. if (draggingTarget) {
  14145. var x = e.offsetX;
  14146. var y = e.offsetY;
  14147. var dx = x - this._x;
  14148. var dy = y - this._y;
  14149. this._x = x;
  14150. this._y = y;
  14151. draggingTarget.drift(dx, dy, e);
  14152. this._dispatchProxy(draggingTarget, 'drag', e.event);
  14153. var dropTarget = this.findHover(x, y, draggingTarget);
  14154. var lastDropTarget = this._dropTarget;
  14155. this._dropTarget = dropTarget;
  14156. if (draggingTarget !== dropTarget) {
  14157. if (lastDropTarget && dropTarget !== lastDropTarget) {
  14158. this._dispatchProxy(lastDropTarget, 'dragleave', e.event);
  14159. }
  14160. if (dropTarget && dropTarget !== lastDropTarget) {
  14161. this._dispatchProxy(dropTarget, 'dragenter', e.event);
  14162. }
  14163. }
  14164. }
  14165. },
  14166. _dragEnd: function (e) {
  14167. var draggingTarget = this._draggingTarget;
  14168. if (draggingTarget) {
  14169. draggingTarget.dragging = false;
  14170. }
  14171. this._dispatchProxy(draggingTarget, 'dragend', e.event);
  14172. if (this._dropTarget) {
  14173. this._dispatchProxy(this._dropTarget, 'drop', e.event);
  14174. }
  14175. this._draggingTarget = null;
  14176. this._dropTarget = null;
  14177. }
  14178. };
  14179. module.exports = Draggable;
  14180. /***/ },
  14181. /* 83 */
  14182. /***/ function(module, exports) {
  14183. 'use strict';
  14184. /**
  14185. * Only implements needed gestures for mobile.
  14186. */
  14187. var GestureMgr = function () {
  14188. /**
  14189. * @private
  14190. * @type {Array.<Object>}
  14191. */
  14192. this._track = [];
  14193. };
  14194. GestureMgr.prototype = {
  14195. constructor: GestureMgr,
  14196. recognize: function (event, target) {
  14197. this._doTrack(event, target);
  14198. return this._recognize(event);
  14199. },
  14200. clear: function () {
  14201. this._track.length = 0;
  14202. return this;
  14203. },
  14204. _doTrack: function (event, target) {
  14205. var touches = event.touches;
  14206. if (!touches) {
  14207. return;
  14208. }
  14209. var trackItem = {
  14210. points: [],
  14211. touches: [],
  14212. target: target,
  14213. event: event
  14214. };
  14215. for (var i = 0, len = touches.length; i < len; i++) {
  14216. var touch = touches[i];
  14217. trackItem.points.push([touch.clientX, touch.clientY]);
  14218. trackItem.touches.push(touch);
  14219. }
  14220. this._track.push(trackItem);
  14221. },
  14222. _recognize: function (event) {
  14223. for (var eventName in recognizers) {
  14224. if (recognizers.hasOwnProperty(eventName)) {
  14225. var gestureInfo = recognizers[eventName](this._track, event);
  14226. if (gestureInfo) {
  14227. return gestureInfo;
  14228. }
  14229. }
  14230. }
  14231. }
  14232. };
  14233. function dist(pointPair) {
  14234. var dx = pointPair[1][0] - pointPair[0][0];
  14235. var dy = pointPair[1][1] - pointPair[0][1];
  14236. return Math.sqrt(dx * dx + dy * dy);
  14237. }
  14238. function center(pointPair) {
  14239. return [
  14240. (pointPair[0][0] + pointPair[1][0]) / 2,
  14241. (pointPair[0][1] + pointPair[1][1]) / 2
  14242. ];
  14243. }
  14244. var recognizers = {
  14245. pinch: function (track, event) {
  14246. var trackLen = track.length;
  14247. if (!trackLen) {
  14248. return;
  14249. }
  14250. var pinchEnd = (track[trackLen - 1] || {}).points;
  14251. var pinchPre = (track[trackLen - 2] || {}).points || pinchEnd;
  14252. if (pinchPre
  14253. && pinchPre.length > 1
  14254. && pinchEnd
  14255. && pinchEnd.length > 1
  14256. ) {
  14257. var pinchScale = dist(pinchEnd) / dist(pinchPre);
  14258. !isFinite(pinchScale) && (pinchScale = 1);
  14259. event.pinchScale = pinchScale;
  14260. var pinchCenter = center(pinchEnd);
  14261. event.pinchX = pinchCenter[0];
  14262. event.pinchY = pinchCenter[1];
  14263. return {
  14264. type: 'pinch',
  14265. target: track[0].target,
  14266. event: event
  14267. };
  14268. }
  14269. }
  14270. // Only pinch currently.
  14271. };
  14272. module.exports = GestureMgr;
  14273. /***/ },
  14274. /* 84 */
  14275. /***/ function(module, exports, __webpack_require__) {
  14276. 'use strict';
  14277. /**
  14278. * Storage内容仓库模块
  14279. * @module zrender/Storage
  14280. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  14281. * @author errorrik (errorrik@gmail.com)
  14282. * @author pissang (https://github.com/pissang/)
  14283. */
  14284. var util = __webpack_require__(3);
  14285. var Group = __webpack_require__(29);
  14286. function shapeCompareFunc(a, b) {
  14287. if (a.zlevel === b.zlevel) {
  14288. if (a.z === b.z) {
  14289. if (a.z2 === b.z2) {
  14290. return a.__renderidx - b.__renderidx;
  14291. }
  14292. return a.z2 - b.z2;
  14293. }
  14294. return a.z - b.z;
  14295. }
  14296. return a.zlevel - b.zlevel;
  14297. }
  14298. /**
  14299. * 内容仓库 (M)
  14300. * @alias module:zrender/Storage
  14301. * @constructor
  14302. */
  14303. var Storage = function () {
  14304. // 所有常规形状,id索引的map
  14305. this._elements = {};
  14306. this._roots = [];
  14307. this._displayList = [];
  14308. this._displayListLen = 0;
  14309. };
  14310. Storage.prototype = {
  14311. constructor: Storage,
  14312. /**
  14313. * 返回所有图形的绘制队列
  14314. * @param {boolean} [update=false] 是否在返回前更新该数组
  14315. * @param {boolean} [includeIgnore=false] 是否包含 ignore 的数组, 在 update 为 true 的时候有效
  14316. *
  14317. * 详见{@link module:zrender/graphic/Displayable.prototype.updateDisplayList}
  14318. * @return {Array.<module:zrender/graphic/Displayable>}
  14319. */
  14320. getDisplayList: function (update, includeIgnore) {
  14321. includeIgnore = includeIgnore || false;
  14322. if (update) {
  14323. this.updateDisplayList(includeIgnore);
  14324. }
  14325. return this._displayList;
  14326. },
  14327. /**
  14328. * 更新图形的绘制队列。
  14329. * 每次绘制前都会调用,该方法会先深度优先遍历整个树,更新所有Group和Shape的变换并且把所有可见的Shape保存到数组中,
  14330. * 最后根据绘制的优先级(zlevel > z > 插入顺序)排序得到绘制队列
  14331. * @param {boolean} [includeIgnore=false] 是否包含 ignore 的数组
  14332. */
  14333. updateDisplayList: function (includeIgnore) {
  14334. this._displayListLen = 0;
  14335. var roots = this._roots;
  14336. var displayList = this._displayList;
  14337. for (var i = 0, len = roots.length; i < len; i++) {
  14338. this._updateAndAddDisplayable(roots[i], null, includeIgnore);
  14339. }
  14340. displayList.length = this._displayListLen;
  14341. for (var i = 0, len = displayList.length; i < len; i++) {
  14342. displayList[i].__renderidx = i;
  14343. }
  14344. displayList.sort(shapeCompareFunc);
  14345. },
  14346. _updateAndAddDisplayable: function (el, clipPaths, includeIgnore) {
  14347. if (el.ignore && !includeIgnore) {
  14348. return;
  14349. }
  14350. el.beforeUpdate();
  14351. el.update();
  14352. el.afterUpdate();
  14353. var clipPath = el.clipPath;
  14354. if (clipPath) {
  14355. // clipPath 的变换是基于 group 的变换
  14356. clipPath.parent = el;
  14357. clipPath.updateTransform();
  14358. // FIXME 效率影响
  14359. if (clipPaths) {
  14360. clipPaths = clipPaths.slice();
  14361. clipPaths.push(clipPath);
  14362. }
  14363. else {
  14364. clipPaths = [clipPath];
  14365. }
  14366. }
  14367. if (el.type == 'group') {
  14368. var children = el._children;
  14369. for (var i = 0; i < children.length; i++) {
  14370. var child = children[i];
  14371. // Force to mark as dirty if group is dirty
  14372. // FIXME __dirtyPath ?
  14373. child.__dirty = el.__dirty || child.__dirty;
  14374. this._updateAndAddDisplayable(child, clipPaths, includeIgnore);
  14375. }
  14376. // Mark group clean here
  14377. el.__dirty = false;
  14378. }
  14379. else {
  14380. el.__clipPaths = clipPaths;
  14381. this._displayList[this._displayListLen++] = el;
  14382. }
  14383. },
  14384. /**
  14385. * 添加图形(Shape)或者组(Group)到根节点
  14386. * @param {module:zrender/Element} el
  14387. */
  14388. addRoot: function (el) {
  14389. // Element has been added
  14390. if (this._elements[el.id]) {
  14391. return;
  14392. }
  14393. if (el instanceof Group) {
  14394. el.addChildrenToStorage(this);
  14395. }
  14396. this.addToMap(el);
  14397. this._roots.push(el);
  14398. },
  14399. /**
  14400. * 删除指定的图形(Shape)或者组(Group)
  14401. * @param {string|Array.<string>} [elId] 如果为空清空整个Storage
  14402. */
  14403. delRoot: function (elId) {
  14404. if (elId == null) {
  14405. // 不指定elId清空
  14406. for (var i = 0; i < this._roots.length; i++) {
  14407. var root = this._roots[i];
  14408. if (root instanceof Group) {
  14409. root.delChildrenFromStorage(this);
  14410. }
  14411. }
  14412. this._elements = {};
  14413. this._roots = [];
  14414. this._displayList = [];
  14415. this._displayListLen = 0;
  14416. return;
  14417. }
  14418. if (elId instanceof Array) {
  14419. for (var i = 0, l = elId.length; i < l; i++) {
  14420. this.delRoot(elId[i]);
  14421. }
  14422. return;
  14423. }
  14424. var el;
  14425. if (typeof(elId) == 'string') {
  14426. el = this._elements[elId];
  14427. }
  14428. else {
  14429. el = elId;
  14430. }
  14431. var idx = util.indexOf(this._roots, el);
  14432. if (idx >= 0) {
  14433. this.delFromMap(el.id);
  14434. this._roots.splice(idx, 1);
  14435. if (el instanceof Group) {
  14436. el.delChildrenFromStorage(this);
  14437. }
  14438. }
  14439. },
  14440. addToMap: function (el) {
  14441. if (el instanceof Group) {
  14442. el.__storage = this;
  14443. }
  14444. el.dirty();
  14445. this._elements[el.id] = el;
  14446. return this;
  14447. },
  14448. get: function (elId) {
  14449. return this._elements[elId];
  14450. },
  14451. delFromMap: function (elId) {
  14452. var elements = this._elements;
  14453. var el = elements[elId];
  14454. if (el) {
  14455. delete elements[elId];
  14456. if (el instanceof Group) {
  14457. el.__storage = null;
  14458. }
  14459. }
  14460. return this;
  14461. },
  14462. /**
  14463. * 清空并且释放Storage
  14464. */
  14465. dispose: function () {
  14466. this._elements =
  14467. this._renderList =
  14468. this._roots = null;
  14469. }
  14470. };
  14471. module.exports = Storage;
  14472. /***/ },
  14473. /* 85 */
  14474. /***/ function(module, exports, __webpack_require__) {
  14475. 'use strict';
  14476. /**
  14477. * 动画主类, 调度和管理所有动画控制器
  14478. *
  14479. * @module zrender/animation/Animation
  14480. * @author pissang(https://github.com/pissang)
  14481. */
  14482. // TODO Additive animation
  14483. // http://iosoteric.com/additive-animations-animatewithduration-in-ios-8/
  14484. // https://developer.apple.com/videos/wwdc2014/#236
  14485. var util = __webpack_require__(3);
  14486. var Dispatcher = __webpack_require__(81).Dispatcher;
  14487. var requestAnimationFrame = (typeof window !== 'undefined' &&
  14488. (window.requestAnimationFrame
  14489. || window.msRequestAnimationFrame
  14490. || window.mozRequestAnimationFrame
  14491. || window.webkitRequestAnimationFrame))
  14492. || function (func) {
  14493. setTimeout(func, 16);
  14494. };
  14495. var Animator = __webpack_require__(35);
  14496. /**
  14497. * @typedef {Object} IZRenderStage
  14498. * @property {Function} update
  14499. */
  14500. /**
  14501. * @alias module:zrender/animation/Animation
  14502. * @constructor
  14503. * @param {Object} [options]
  14504. * @param {Function} [options.onframe]
  14505. * @param {IZRenderStage} [options.stage]
  14506. * @example
  14507. * var animation = new Animation();
  14508. * var obj = {
  14509. * x: 100,
  14510. * y: 100
  14511. * };
  14512. * animation.animate(node.position)
  14513. * .when(1000, {
  14514. * x: 500,
  14515. * y: 500
  14516. * })
  14517. * .when(2000, {
  14518. * x: 100,
  14519. * y: 100
  14520. * })
  14521. * .start('spline');
  14522. */
  14523. var Animation = function (options) {
  14524. options = options || {};
  14525. this.stage = options.stage || {};
  14526. this.onframe = options.onframe || function() {};
  14527. // private properties
  14528. this._clips = [];
  14529. this._running = false;
  14530. this._time = 0;
  14531. Dispatcher.call(this);
  14532. };
  14533. Animation.prototype = {
  14534. constructor: Animation,
  14535. /**
  14536. * 添加 clip
  14537. * @param {module:zrender/animation/Clip} clip
  14538. */
  14539. addClip: function (clip) {
  14540. this._clips.push(clip);
  14541. },
  14542. /**
  14543. * 添加 animator
  14544. * @param {module:zrender/animation/Animator} animator
  14545. */
  14546. addAnimator: function (animator) {
  14547. animator.animation = this;
  14548. var clips = animator.getClips();
  14549. for (var i = 0; i < clips.length; i++) {
  14550. this.addClip(clips[i]);
  14551. }
  14552. },
  14553. /**
  14554. * 删除动画片段
  14555. * @param {module:zrender/animation/Clip} clip
  14556. */
  14557. removeClip: function(clip) {
  14558. var idx = util.indexOf(this._clips, clip);
  14559. if (idx >= 0) {
  14560. this._clips.splice(idx, 1);
  14561. }
  14562. },
  14563. /**
  14564. * 删除动画片段
  14565. * @param {module:zrender/animation/Animator} animator
  14566. */
  14567. removeAnimator: function (animator) {
  14568. var clips = animator.getClips();
  14569. for (var i = 0; i < clips.length; i++) {
  14570. this.removeClip(clips[i]);
  14571. }
  14572. animator.animation = null;
  14573. },
  14574. _update: function() {
  14575. var time = new Date().getTime();
  14576. var delta = time - this._time;
  14577. var clips = this._clips;
  14578. var len = clips.length;
  14579. var deferredEvents = [];
  14580. var deferredClips = [];
  14581. for (var i = 0; i < len; i++) {
  14582. var clip = clips[i];
  14583. var e = clip.step(time);
  14584. // Throw out the events need to be called after
  14585. // stage.update, like destroy
  14586. if (e) {
  14587. deferredEvents.push(e);
  14588. deferredClips.push(clip);
  14589. }
  14590. }
  14591. // Remove the finished clip
  14592. for (var i = 0; i < len;) {
  14593. if (clips[i]._needsRemove) {
  14594. clips[i] = clips[len - 1];
  14595. clips.pop();
  14596. len--;
  14597. }
  14598. else {
  14599. i++;
  14600. }
  14601. }
  14602. len = deferredEvents.length;
  14603. for (var i = 0; i < len; i++) {
  14604. deferredClips[i].fire(deferredEvents[i]);
  14605. }
  14606. this._time = time;
  14607. this.onframe(delta);
  14608. this.trigger('frame', delta);
  14609. if (this.stage.update) {
  14610. this.stage.update();
  14611. }
  14612. },
  14613. /**
  14614. * 开始运行动画
  14615. */
  14616. start: function () {
  14617. var self = this;
  14618. this._running = true;
  14619. function step() {
  14620. if (self._running) {
  14621. requestAnimationFrame(step);
  14622. self._update();
  14623. }
  14624. }
  14625. this._time = new Date().getTime();
  14626. requestAnimationFrame(step);
  14627. },
  14628. /**
  14629. * 停止运行动画
  14630. */
  14631. stop: function () {
  14632. this._running = false;
  14633. },
  14634. /**
  14635. * 清除所有动画片段
  14636. */
  14637. clear: function () {
  14638. this._clips = [];
  14639. },
  14640. /**
  14641. * 对一个目标创建一个animator对象,可以指定目标中的属性使用动画
  14642. * @param {Object} target
  14643. * @param {Object} options
  14644. * @param {boolean} [options.loop=false] 是否循环播放动画
  14645. * @param {Function} [options.getter=null]
  14646. * 如果指定getter函数,会通过getter函数取属性值
  14647. * @param {Function} [options.setter=null]
  14648. * 如果指定setter函数,会通过setter函数设置属性值
  14649. * @return {module:zrender/animation/Animation~Animator}
  14650. */
  14651. animate: function (target, options) {
  14652. options = options || {};
  14653. var animator = new Animator(
  14654. target,
  14655. options.loop,
  14656. options.getter,
  14657. options.setter
  14658. );
  14659. return animator;
  14660. }
  14661. };
  14662. util.mixin(Animation, Dispatcher);
  14663. module.exports = Animation;
  14664. /***/ },
  14665. /* 86 */
  14666. /***/ function(module, exports, __webpack_require__) {
  14667. 'use strict';
  14668. /**
  14669. * Default canvas painter
  14670. * @module zrender/Painter
  14671. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  14672. * errorrik (errorrik@gmail.com)
  14673. * pissang (https://www.github.com/pissang)
  14674. */
  14675. var config = __webpack_require__(40);
  14676. var util = __webpack_require__(3);
  14677. var log = __webpack_require__(39);
  14678. var BoundingRect = __webpack_require__(15);
  14679. var Layer = __webpack_require__(87);
  14680. function parseInt10(val) {
  14681. return parseInt(val, 10);
  14682. }
  14683. function isLayerValid(layer) {
  14684. if (!layer) {
  14685. return false;
  14686. }
  14687. if (layer.isBuildin) {
  14688. return true;
  14689. }
  14690. if (typeof(layer.resize) !== 'function'
  14691. || typeof(layer.refresh) !== 'function'
  14692. ) {
  14693. return false;
  14694. }
  14695. return true;
  14696. }
  14697. function preProcessLayer(layer) {
  14698. layer.__unusedCount++;
  14699. }
  14700. function postProcessLayer(layer) {
  14701. layer.__dirty = false;
  14702. if (layer.__unusedCount == 1) {
  14703. layer.clear();
  14704. }
  14705. }
  14706. var tmpRect = new BoundingRect(0, 0, 0, 0);
  14707. var viewRect = new BoundingRect(0, 0, 0, 0);
  14708. function isDisplayableCulled(el, width, height) {
  14709. tmpRect.copy(el.getBoundingRect());
  14710. if (el.transform) {
  14711. tmpRect.applyTransform(el.transform);
  14712. }
  14713. viewRect.width = width;
  14714. viewRect.height = height;
  14715. return !tmpRect.intersect(viewRect);
  14716. }
  14717. function isClipPathChanged(clipPaths, prevClipPaths) {
  14718. if (!clipPaths || !prevClipPaths || (clipPaths.length !== prevClipPaths.length)) {
  14719. return true;
  14720. }
  14721. for (var i = 0; i < clipPaths.length; i++) {
  14722. if (clipPaths[i] !== prevClipPaths[i]) {
  14723. return true;
  14724. }
  14725. }
  14726. }
  14727. function doClip(clipPaths, ctx) {
  14728. for (var i = 0; i < clipPaths.length; i++) {
  14729. var clipPath = clipPaths[i];
  14730. var m;
  14731. if (clipPath.transform) {
  14732. m = clipPath.transform;
  14733. ctx.transform(
  14734. m[0], m[1],
  14735. m[2], m[3],
  14736. m[4], m[5]
  14737. );
  14738. }
  14739. var path = clipPath.path;
  14740. path.beginPath(ctx);
  14741. clipPath.buildPath(path, clipPath.shape);
  14742. ctx.clip();
  14743. // Transform back
  14744. if (clipPath.transform) {
  14745. m = clipPath.invTransform;
  14746. ctx.transform(
  14747. m[0], m[1],
  14748. m[2], m[3],
  14749. m[4], m[5]
  14750. );
  14751. }
  14752. }
  14753. }
  14754. /**
  14755. * @alias module:zrender/Painter
  14756. * @constructor
  14757. * @param {HTMLElement} root 绘图容器
  14758. * @param {module:zrender/Storage} storage
  14759. * @param {Ojbect} opts
  14760. */
  14761. var Painter = function (root, storage, opts) {
  14762. var singleCanvas = !root.nodeName // In node ?
  14763. || root.nodeName.toUpperCase() === 'CANVAS';
  14764. opts = opts || {};
  14765. /**
  14766. * @type {number}
  14767. */
  14768. this.dpr = opts.devicePixelRatio || config.devicePixelRatio;
  14769. /**
  14770. * @type {boolean}
  14771. * @private
  14772. */
  14773. this._singleCanvas = singleCanvas;
  14774. /**
  14775. * 绘图容器
  14776. * @type {HTMLElement}
  14777. */
  14778. this.root = root;
  14779. var rootStyle = root.style;
  14780. // In node environment using node-canvas
  14781. if (rootStyle) {
  14782. rootStyle['-webkit-tap-highlight-color'] = 'transparent';
  14783. rootStyle['-webkit-user-select'] = 'none';
  14784. rootStyle['user-select'] = 'none';
  14785. rootStyle['-webkit-touch-callout'] = 'none';
  14786. root.innerHTML = '';
  14787. }
  14788. /**
  14789. * @type {module:zrender/Storage}
  14790. */
  14791. this.storage = storage;
  14792. if (!singleCanvas) {
  14793. var width = this._getWidth();
  14794. var height = this._getHeight();
  14795. this._width = width;
  14796. this._height = height;
  14797. var domRoot = document.createElement('div');
  14798. this._domRoot = domRoot;
  14799. var domRootStyle = domRoot.style;
  14800. // domRoot.onselectstart = returnFalse; // 避免页面选中的尴尬
  14801. domRootStyle.position = 'relative';
  14802. domRootStyle.overflow = 'hidden';
  14803. domRootStyle.width = this._width + 'px';
  14804. domRootStyle.height = this._height + 'px';
  14805. root.appendChild(domRoot);
  14806. /**
  14807. * @type {Object.<key, module:zrender/Layer>}
  14808. * @private
  14809. */
  14810. this._layers = {};
  14811. /**
  14812. * @type {Array.<number>}
  14813. * @private
  14814. */
  14815. this._zlevelList = [];
  14816. }
  14817. else {
  14818. // Use canvas width and height directly
  14819. var width = root.width;
  14820. var height = root.height;
  14821. this._width = width;
  14822. this._height = height;
  14823. // Create layer if only one given canvas
  14824. // Device pixel ratio is fixed to 1 because given canvas has its specified width and height
  14825. var mainLayer = new Layer(root, this, 1);
  14826. mainLayer.initContext();
  14827. // FIXME Use canvas width and height
  14828. // mainLayer.resize(width, height);
  14829. this._layers = {
  14830. 0: mainLayer
  14831. };
  14832. this._zlevelList = [0];
  14833. }
  14834. this._layerConfig = {};
  14835. this.pathToImage = this._createPathToImage();
  14836. };
  14837. Painter.prototype = {
  14838. constructor: Painter,
  14839. /**
  14840. * If painter use a single canvas
  14841. * @return {boolean}
  14842. */
  14843. isSingleCanvas: function () {
  14844. return this._singleCanvas;
  14845. },
  14846. /**
  14847. * @return {HTMLDivElement}
  14848. */
  14849. getViewportRoot: function () {
  14850. return this._singleCanvas ? this._layers[0].dom : this._domRoot;
  14851. },
  14852. /**
  14853. * 刷新
  14854. * @param {boolean} [paintAll=false] 强制绘制所有displayable
  14855. */
  14856. refresh: function (paintAll) {
  14857. var list = this.storage.getDisplayList(true);
  14858. var zlevelList = this._zlevelList;
  14859. this._paintList(list, paintAll);
  14860. // Paint custum layers
  14861. for (var i = 0; i < zlevelList.length; i++) {
  14862. var z = zlevelList[i];
  14863. var layer = this._layers[z];
  14864. if (!layer.isBuildin && layer.refresh) {
  14865. layer.refresh();
  14866. }
  14867. }
  14868. return this;
  14869. },
  14870. _paintList: function (list, paintAll) {
  14871. if (paintAll == null) {
  14872. paintAll = false;
  14873. }
  14874. this._updateLayerStatus(list);
  14875. var currentLayer;
  14876. var currentZLevel;
  14877. var ctx;
  14878. var viewWidth = this._width;
  14879. var viewHeight = this._height;
  14880. this.eachBuildinLayer(preProcessLayer);
  14881. // var invTransform = [];
  14882. var prevElClipPaths = null;
  14883. for (var i = 0, l = list.length; i < l; i++) {
  14884. var el = list[i];
  14885. var elZLevel = this._singleCanvas ? 0 : el.zlevel;
  14886. // Change draw layer
  14887. if (currentZLevel !== elZLevel) {
  14888. // Only 0 zlevel if only has one canvas
  14889. currentZLevel = elZLevel;
  14890. currentLayer = this.getLayer(currentZLevel);
  14891. if (!currentLayer.isBuildin) {
  14892. log(
  14893. 'ZLevel ' + currentZLevel
  14894. + ' has been used by unkown layer ' + currentLayer.id
  14895. );
  14896. }
  14897. ctx = currentLayer.ctx;
  14898. // Reset the count
  14899. currentLayer.__unusedCount = 0;
  14900. if (currentLayer.__dirty || paintAll) {
  14901. currentLayer.clear();
  14902. }
  14903. }
  14904. if (
  14905. (currentLayer.__dirty || paintAll)
  14906. // Ignore invisible element
  14907. && !el.invisible
  14908. // Ignore transparent element
  14909. && el.style.opacity !== 0
  14910. // Ignore scale 0 element, in some environment like node-canvas
  14911. // Draw a scale 0 element can cause all following draw wrong
  14912. && el.scale[0] && el.scale[1]
  14913. // Ignore culled element
  14914. && !(el.culling && isDisplayableCulled(el, viewWidth, viewHeight))
  14915. ) {
  14916. var clipPaths = el.__clipPaths;
  14917. // Optimize when clipping on group with several elements
  14918. if (isClipPathChanged(clipPaths, prevElClipPaths)) {
  14919. // If has previous clipping state, restore from it
  14920. if (prevElClipPaths) {
  14921. ctx.restore();
  14922. }
  14923. // New clipping state
  14924. if (clipPaths) {
  14925. ctx.save();
  14926. doClip(clipPaths, ctx);
  14927. }
  14928. prevElClipPaths = clipPaths;
  14929. }
  14930. el.beforeBrush && el.beforeBrush(ctx);
  14931. el.brush(ctx, false);
  14932. el.afterBrush && el.afterBrush(ctx);
  14933. }
  14934. el.__dirty = false;
  14935. }
  14936. // If still has clipping state
  14937. if (prevElClipPaths) {
  14938. ctx.restore();
  14939. }
  14940. this.eachBuildinLayer(postProcessLayer);
  14941. },
  14942. /**
  14943. * 获取 zlevel 所在层,如果不存在则会创建一个新的层
  14944. * @param {number} zlevel
  14945. * @return {module:zrender/Layer}
  14946. */
  14947. getLayer: function (zlevel) {
  14948. if (this._singleCanvas) {
  14949. return this._layers[0];
  14950. }
  14951. var layer = this._layers[zlevel];
  14952. if (!layer) {
  14953. // Create a new layer
  14954. layer = new Layer('zr_' + zlevel, this, this.dpr);
  14955. layer.isBuildin = true;
  14956. if (this._layerConfig[zlevel]) {
  14957. util.merge(layer, this._layerConfig[zlevel], true);
  14958. }
  14959. this.insertLayer(zlevel, layer);
  14960. // Context is created after dom inserted to document
  14961. // Or excanvas will get 0px clientWidth and clientHeight
  14962. layer.initContext();
  14963. }
  14964. return layer;
  14965. },
  14966. insertLayer: function (zlevel, layer) {
  14967. var layersMap = this._layers;
  14968. var zlevelList = this._zlevelList;
  14969. var len = zlevelList.length;
  14970. var prevLayer = null;
  14971. var i = -1;
  14972. var domRoot = this._domRoot;
  14973. if (layersMap[zlevel]) {
  14974. log('ZLevel ' + zlevel + ' has been used already');
  14975. return;
  14976. }
  14977. // Check if is a valid layer
  14978. if (!isLayerValid(layer)) {
  14979. log('Layer of zlevel ' + zlevel + ' is not valid');
  14980. return;
  14981. }
  14982. if (len > 0 && zlevel > zlevelList[0]) {
  14983. for (i = 0; i < len - 1; i++) {
  14984. if (
  14985. zlevelList[i] < zlevel
  14986. && zlevelList[i + 1] > zlevel
  14987. ) {
  14988. break;
  14989. }
  14990. }
  14991. prevLayer = layersMap[zlevelList[i]];
  14992. }
  14993. zlevelList.splice(i + 1, 0, zlevel);
  14994. if (prevLayer) {
  14995. var prevDom = prevLayer.dom;
  14996. if (prevDom.nextSibling) {
  14997. domRoot.insertBefore(
  14998. layer.dom,
  14999. prevDom.nextSibling
  15000. );
  15001. }
  15002. else {
  15003. domRoot.appendChild(layer.dom);
  15004. }
  15005. }
  15006. else {
  15007. if (domRoot.firstChild) {
  15008. domRoot.insertBefore(layer.dom, domRoot.firstChild);
  15009. }
  15010. else {
  15011. domRoot.appendChild(layer.dom);
  15012. }
  15013. }
  15014. layersMap[zlevel] = layer;
  15015. },
  15016. // Iterate each layer
  15017. eachLayer: function (cb, context) {
  15018. var zlevelList = this._zlevelList;
  15019. var z;
  15020. var i;
  15021. for (i = 0; i < zlevelList.length; i++) {
  15022. z = zlevelList[i];
  15023. cb.call(context, this._layers[z], z);
  15024. }
  15025. },
  15026. // Iterate each buildin layer
  15027. eachBuildinLayer: function (cb, context) {
  15028. var zlevelList = this._zlevelList;
  15029. var layer;
  15030. var z;
  15031. var i;
  15032. for (i = 0; i < zlevelList.length; i++) {
  15033. z = zlevelList[i];
  15034. layer = this._layers[z];
  15035. if (layer.isBuildin) {
  15036. cb.call(context, layer, z);
  15037. }
  15038. }
  15039. },
  15040. // Iterate each other layer except buildin layer
  15041. eachOtherLayer: function (cb, context) {
  15042. var zlevelList = this._zlevelList;
  15043. var layer;
  15044. var z;
  15045. var i;
  15046. for (i = 0; i < zlevelList.length; i++) {
  15047. z = zlevelList[i];
  15048. layer = this._layers[z];
  15049. if (! layer.isBuildin) {
  15050. cb.call(context, layer, z);
  15051. }
  15052. }
  15053. },
  15054. /**
  15055. * 获取所有已创建的层
  15056. * @param {Array.<module:zrender/Layer>} [prevLayer]
  15057. */
  15058. getLayers: function () {
  15059. return this._layers;
  15060. },
  15061. _updateLayerStatus: function (list) {
  15062. var layers = this._layers;
  15063. var elCounts = {};
  15064. this.eachBuildinLayer(function (layer, z) {
  15065. elCounts[z] = layer.elCount;
  15066. layer.elCount = 0;
  15067. });
  15068. for (var i = 0, l = list.length; i < l; i++) {
  15069. var el = list[i];
  15070. var zlevel = this._singleCanvas ? 0 : el.zlevel;
  15071. var layer = layers[zlevel];
  15072. if (layer) {
  15073. layer.elCount++;
  15074. // 已经被标记为需要刷新
  15075. if (layer.__dirty) {
  15076. continue;
  15077. }
  15078. layer.__dirty = el.__dirty;
  15079. }
  15080. }
  15081. // 层中的元素数量有发生变化
  15082. this.eachBuildinLayer(function (layer, z) {
  15083. if (elCounts[z] !== layer.elCount) {
  15084. layer.__dirty = true;
  15085. }
  15086. });
  15087. },
  15088. /**
  15089. * 清除hover层外所有内容
  15090. */
  15091. clear: function () {
  15092. this.eachBuildinLayer(this._clearLayer);
  15093. return this;
  15094. },
  15095. _clearLayer: function (layer) {
  15096. layer.clear();
  15097. },
  15098. /**
  15099. * 修改指定zlevel的绘制参数
  15100. *
  15101. * @param {string} zlevel
  15102. * @param {Object} config 配置对象
  15103. * @param {string} [config.clearColor=0] 每次清空画布的颜色
  15104. * @param {string} [config.motionBlur=false] 是否开启动态模糊
  15105. * @param {number} [config.lastFrameAlpha=0.7]
  15106. * 在开启动态模糊的时候使用,与上一帧混合的alpha值,值越大尾迹越明显
  15107. */
  15108. configLayer: function (zlevel, config) {
  15109. if (config) {
  15110. var layerConfig = this._layerConfig;
  15111. if (!layerConfig[zlevel]) {
  15112. layerConfig[zlevel] = config;
  15113. }
  15114. else {
  15115. util.merge(layerConfig[zlevel], config, true);
  15116. }
  15117. var layer = this._layers[zlevel];
  15118. if (layer) {
  15119. util.merge(layer, layerConfig[zlevel], true);
  15120. }
  15121. }
  15122. },
  15123. /**
  15124. * 删除指定层
  15125. * @param {number} zlevel 层所在的zlevel
  15126. */
  15127. delLayer: function (zlevel) {
  15128. var layers = this._layers;
  15129. var zlevelList = this._zlevelList;
  15130. var layer = layers[zlevel];
  15131. if (!layer) {
  15132. return;
  15133. }
  15134. layer.dom.parentNode.removeChild(layer.dom);
  15135. delete layers[zlevel];
  15136. zlevelList.splice(util.indexOf(zlevelList, zlevel), 1);
  15137. },
  15138. /**
  15139. * 区域大小变化后重绘
  15140. */
  15141. resize: function (width, height) {
  15142. var domRoot = this._domRoot;
  15143. // FIXME Why ?
  15144. domRoot.style.display = 'none';
  15145. width = width || this._getWidth();
  15146. height = height || this._getHeight();
  15147. domRoot.style.display = '';
  15148. // 优化没有实际改变的resize
  15149. if (this._width != width || height != this._height) {
  15150. domRoot.style.width = width + 'px';
  15151. domRoot.style.height = height + 'px';
  15152. for (var id in this._layers) {
  15153. this._layers[id].resize(width, height);
  15154. }
  15155. this.refresh(true);
  15156. }
  15157. this._width = width;
  15158. this._height = height;
  15159. return this;
  15160. },
  15161. /**
  15162. * 清除单独的一个层
  15163. * @param {number} zlevel
  15164. */
  15165. clearLayer: function (zlevel) {
  15166. var layer = this._layers[zlevel];
  15167. if (layer) {
  15168. layer.clear();
  15169. }
  15170. },
  15171. /**
  15172. * 释放
  15173. */
  15174. dispose: function () {
  15175. this.root.innerHTML = '';
  15176. this.root =
  15177. this.storage =
  15178. this._domRoot =
  15179. this._layers = null;
  15180. },
  15181. /**
  15182. * Get canvas which has all thing rendered
  15183. * @param {Object} opts
  15184. * @param {string} [opts.backgroundColor]
  15185. */
  15186. getRenderedCanvas: function (opts) {
  15187. opts = opts || {};
  15188. if (this._singleCanvas) {
  15189. return this._layers[0].dom;
  15190. }
  15191. var imageLayer = new Layer('image', this, opts.pixelRatio || this.dpr);
  15192. imageLayer.initContext();
  15193. var ctx = imageLayer.ctx;
  15194. imageLayer.clearColor = opts.backgroundColor;
  15195. imageLayer.clear();
  15196. var displayList = this.storage.getDisplayList(true);
  15197. for (var i = 0; i < displayList.length; i++) {
  15198. var el = displayList[i];
  15199. if (!el.invisible) {
  15200. el.beforeBrush && el.beforeBrush(ctx);
  15201. // TODO Check image cross origin
  15202. el.brush(ctx, false);
  15203. el.afterBrush && el.afterBrush(ctx);
  15204. }
  15205. }
  15206. return imageLayer.dom;
  15207. },
  15208. /**
  15209. * 获取绘图区域宽度
  15210. */
  15211. getWidth: function () {
  15212. return this._width;
  15213. },
  15214. /**
  15215. * 获取绘图区域高度
  15216. */
  15217. getHeight: function () {
  15218. return this._height;
  15219. },
  15220. _getWidth: function () {
  15221. var root = this.root;
  15222. var stl = document.defaultView.getComputedStyle(root);
  15223. // FIXME Better way to get the width and height when element has not been append to the document
  15224. return ((root.clientWidth || parseInt10(stl.width) || parseInt10(root.style.width))
  15225. - (parseInt10(stl.paddingLeft) || 0)
  15226. - (parseInt10(stl.paddingRight) || 0)) | 0;
  15227. },
  15228. _getHeight: function () {
  15229. var root = this.root;
  15230. var stl = document.defaultView.getComputedStyle(root);
  15231. return ((root.clientHeight || parseInt10(stl.height) || parseInt10(root.style.height))
  15232. - (parseInt10(stl.paddingTop) || 0)
  15233. - (parseInt10(stl.paddingBottom) || 0)) | 0;
  15234. },
  15235. _pathToImage: function (id, path, width, height, dpr) {
  15236. var canvas = document.createElement('canvas');
  15237. var ctx = canvas.getContext('2d');
  15238. canvas.width = width * dpr;
  15239. canvas.height = height * dpr;
  15240. ctx.clearRect(0, 0, width * dpr, height * dpr);
  15241. var pathTransform = {
  15242. position: path.position,
  15243. rotation: path.rotation,
  15244. scale: path.scale
  15245. };
  15246. path.position = [0, 0, 0];
  15247. path.rotation = 0;
  15248. path.scale = [1, 1];
  15249. if (path) {
  15250. path.brush(ctx);
  15251. }
  15252. var ImageShape = __webpack_require__(59);
  15253. var imgShape = new ImageShape({
  15254. id: id,
  15255. style: {
  15256. x: 0,
  15257. y: 0,
  15258. image: canvas
  15259. }
  15260. });
  15261. if (pathTransform.position != null) {
  15262. imgShape.position = path.position = pathTransform.position;
  15263. }
  15264. if (pathTransform.rotation != null) {
  15265. imgShape.rotation = path.rotation = pathTransform.rotation;
  15266. }
  15267. if (pathTransform.scale != null) {
  15268. imgShape.scale = path.scale = pathTransform.scale;
  15269. }
  15270. return imgShape;
  15271. },
  15272. _createPathToImage: function () {
  15273. var me = this;
  15274. return function (id, e, width, height) {
  15275. return me._pathToImage(
  15276. id, e, width, height, me.dpr
  15277. );
  15278. };
  15279. }
  15280. };
  15281. module.exports = Painter;
  15282. /***/ },
  15283. /* 87 */
  15284. /***/ function(module, exports, __webpack_require__) {
  15285. /**
  15286. * @module zrender/Layer
  15287. * @author pissang(https://www.github.com/pissang)
  15288. */
  15289. var util = __webpack_require__(3);
  15290. var config = __webpack_require__(40);
  15291. function returnFalse() {
  15292. return false;
  15293. }
  15294. /**
  15295. * 创建dom
  15296. *
  15297. * @inner
  15298. * @param {string} id dom id 待用
  15299. * @param {string} type dom type,such as canvas, div etc.
  15300. * @param {Painter} painter painter instance
  15301. * @param {number} number
  15302. */
  15303. function createDom(id, type, painter, dpr) {
  15304. var newDom = document.createElement(type);
  15305. var width = painter.getWidth();
  15306. var height = painter.getHeight();
  15307. var newDomStyle = newDom.style;
  15308. // 没append呢,请原谅我这样写,清晰~
  15309. newDomStyle.position = 'absolute';
  15310. newDomStyle.left = 0;
  15311. newDomStyle.top = 0;
  15312. newDomStyle.width = width + 'px';
  15313. newDomStyle.height = height + 'px';
  15314. newDom.width = width * dpr;
  15315. newDom.height = height * dpr;
  15316. // id不作为索引用,避免可能造成的重名,定义为私有属性
  15317. newDom.setAttribute('data-zr-dom-id', id);
  15318. return newDom;
  15319. }
  15320. /**
  15321. * @alias module:zrender/Layer
  15322. * @constructor
  15323. * @extends module:zrender/mixin/Transformable
  15324. * @param {string} id
  15325. * @param {module:zrender/Painter} painter
  15326. * @param {number} [dpr]
  15327. */
  15328. var Layer = function(id, painter, dpr) {
  15329. var dom;
  15330. dpr = dpr || config.devicePixelRatio;
  15331. if (typeof id === 'string') {
  15332. dom = createDom(id, 'canvas', painter, dpr);
  15333. }
  15334. // Not using isDom because in node it will return false
  15335. else if (util.isObject(id)) {
  15336. dom = id;
  15337. id = dom.id;
  15338. }
  15339. this.id = id;
  15340. this.dom = dom;
  15341. var domStyle = dom.style;
  15342. if (domStyle) { // Not in node
  15343. dom.onselectstart = returnFalse; // 避免页面选中的尴尬
  15344. domStyle['-webkit-user-select'] = 'none';
  15345. domStyle['user-select'] = 'none';
  15346. domStyle['-webkit-touch-callout'] = 'none';
  15347. domStyle['-webkit-tap-highlight-color'] = 'rgba(0,0,0,0)';
  15348. }
  15349. this.domBack = null;
  15350. this.ctxBack = null;
  15351. this.painter = painter;
  15352. this.config = null;
  15353. // Configs
  15354. /**
  15355. * 每次清空画布的颜色
  15356. * @type {string}
  15357. * @default 0
  15358. */
  15359. this.clearColor = 0;
  15360. /**
  15361. * 是否开启动态模糊
  15362. * @type {boolean}
  15363. * @default false
  15364. */
  15365. this.motionBlur = false;
  15366. /**
  15367. * 在开启动态模糊的时候使用,与上一帧混合的alpha值,值越大尾迹越明显
  15368. * @type {number}
  15369. * @default 0.7
  15370. */
  15371. this.lastFrameAlpha = 0.7;
  15372. /**
  15373. * Layer dpr
  15374. * @type {number}
  15375. */
  15376. this.dpr = dpr;
  15377. };
  15378. Layer.prototype = {
  15379. constructor: Layer,
  15380. elCount: 0,
  15381. __dirty: true,
  15382. initContext: function () {
  15383. this.ctx = this.dom.getContext('2d');
  15384. var dpr = this.dpr;
  15385. if (dpr != 1) {
  15386. this.ctx.scale(dpr, dpr);
  15387. }
  15388. },
  15389. createBackBuffer: function () {
  15390. var dpr = this.dpr;
  15391. this.domBack = createDom('back-' + this.id, 'canvas', this.painter, dpr);
  15392. this.ctxBack = this.domBack.getContext('2d');
  15393. if (dpr != 1) {
  15394. this.ctxBack.scale(dpr, dpr);
  15395. }
  15396. },
  15397. /**
  15398. * @param {number} width
  15399. * @param {number} height
  15400. */
  15401. resize: function (width, height) {
  15402. var dpr = this.dpr;
  15403. var dom = this.dom;
  15404. var domStyle = dom.style;
  15405. var domBack = this.domBack;
  15406. domStyle.width = width + 'px';
  15407. domStyle.height = height + 'px';
  15408. dom.width = width * dpr;
  15409. dom.height = height * dpr;
  15410. if (dpr != 1) {
  15411. this.ctx.scale(dpr, dpr);
  15412. }
  15413. if (domBack) {
  15414. domBack.width = width * dpr;
  15415. domBack.height = height * dpr;
  15416. if (dpr != 1) {
  15417. this.ctxBack.scale(dpr, dpr);
  15418. }
  15419. }
  15420. },
  15421. /**
  15422. * 清空该层画布
  15423. * @param {boolean} clearAll Clear all with out motion blur
  15424. */
  15425. clear: function (clearAll) {
  15426. var dom = this.dom;
  15427. var ctx = this.ctx;
  15428. var width = dom.width;
  15429. var height = dom.height;
  15430. var haveClearColor = this.clearColor;
  15431. var haveMotionBLur = this.motionBlur && !clearAll;
  15432. var lastFrameAlpha = this.lastFrameAlpha;
  15433. var dpr = this.dpr;
  15434. if (haveMotionBLur) {
  15435. if (!this.domBack) {
  15436. this.createBackBuffer();
  15437. }
  15438. this.ctxBack.globalCompositeOperation = 'copy';
  15439. this.ctxBack.drawImage(
  15440. dom, 0, 0,
  15441. width / dpr,
  15442. height / dpr
  15443. );
  15444. }
  15445. ctx.clearRect(0, 0, width / dpr, height / dpr);
  15446. if (haveClearColor) {
  15447. ctx.save();
  15448. ctx.fillStyle = this.clearColor;
  15449. ctx.fillRect(0, 0, width / dpr, height / dpr);
  15450. ctx.restore();
  15451. }
  15452. if (haveMotionBLur) {
  15453. var domBack = this.domBack;
  15454. ctx.save();
  15455. ctx.globalAlpha = lastFrameAlpha;
  15456. ctx.drawImage(domBack, 0, 0, width / dpr, height / dpr);
  15457. ctx.restore();
  15458. }
  15459. }
  15460. };
  15461. module.exports = Layer;
  15462. /***/ },
  15463. /* 88 */
  15464. /***/ function(module, exports, __webpack_require__) {
  15465. var graphic = __webpack_require__(42);
  15466. var zrUtil = __webpack_require__(3);
  15467. var PI = Math.PI;
  15468. /**
  15469. * @param {module:echarts/ExtensionAPI} api
  15470. * @param {Object} [opts]
  15471. * @param {string} [opts.text]
  15472. * @param {string} [opts.color]
  15473. * @param {string} [opts.textColor]
  15474. * @return {module:zrender/Element}
  15475. */
  15476. module.exports = function (api, opts) {
  15477. opts = opts || {};
  15478. zrUtil.defaults(opts, {
  15479. text: 'loading',
  15480. color: '#c23531',
  15481. textColor: '#000',
  15482. maskColor: 'rgba(255, 255, 255, 0.8)',
  15483. zlevel: 0
  15484. });
  15485. var mask = new graphic.Rect({
  15486. style: {
  15487. fill: opts.maskColor
  15488. },
  15489. zlevel: opts.zlevel,
  15490. z: 10000
  15491. });
  15492. var arc = new graphic.Arc({
  15493. shape: {
  15494. startAngle: -PI / 2,
  15495. endAngle: -PI / 2 + 0.1,
  15496. r: 10
  15497. },
  15498. style: {
  15499. stroke: opts.color,
  15500. lineCap: 'round',
  15501. lineWidth: 5
  15502. },
  15503. zlevel: opts.zlevel,
  15504. z: 10001
  15505. });
  15506. var labelRect = new graphic.Rect({
  15507. style: {
  15508. fill: 'none',
  15509. text: opts.text,
  15510. textPosition: 'right',
  15511. textDistance: 10,
  15512. textFill: opts.textColor
  15513. },
  15514. zlevel: opts.zlevel,
  15515. z: 10001
  15516. });
  15517. arc.animateShape(true)
  15518. .when(1000, {
  15519. endAngle: PI * 3 / 2
  15520. })
  15521. .start('circularInOut');
  15522. arc.animateShape(true)
  15523. .when(1000, {
  15524. startAngle: PI * 3 / 2
  15525. })
  15526. .delay(300)
  15527. .start('circularInOut');
  15528. var group = new graphic.Group();
  15529. group.add(arc);
  15530. group.add(labelRect);
  15531. group.add(mask);
  15532. // Inject resize
  15533. group.resize = function () {
  15534. var cx = api.getWidth() / 2;
  15535. var cy = api.getHeight() / 2;
  15536. arc.setShape({
  15537. cx: cx,
  15538. cy: cy
  15539. });
  15540. var r = arc.shape.r;
  15541. labelRect.setShape({
  15542. x: cx - r,
  15543. y: cy - r,
  15544. width: r * 2,
  15545. height: r * 2
  15546. });
  15547. mask.setShape({
  15548. x: 0,
  15549. y: 0,
  15550. width: api.getWidth(),
  15551. height: api.getHeight()
  15552. });
  15553. };
  15554. group.resize();
  15555. return group;
  15556. };
  15557. /***/ },
  15558. /* 89 */
  15559. /***/ function(module, exports, __webpack_require__) {
  15560. var Gradient = __webpack_require__(4);
  15561. module.exports = function (seriesType, styleType, ecModel) {
  15562. function encodeColor(seriesModel) {
  15563. var colorAccessPath = [styleType, 'normal', 'color'];
  15564. var colorList = ecModel.get('color');
  15565. var data = seriesModel.getData();
  15566. var color = seriesModel.get(colorAccessPath) // Set in itemStyle
  15567. || colorList[seriesModel.seriesIndex % colorList.length]; // Default color
  15568. // FIXME Set color function or use the platte color
  15569. data.setVisual('color', color);
  15570. // Only visible series has each data be visual encoded
  15571. if (!ecModel.isSeriesFiltered(seriesModel)) {
  15572. if (typeof color === 'function' && !(color instanceof Gradient)) {
  15573. data.each(function (idx) {
  15574. data.setItemVisual(
  15575. idx, 'color', color(seriesModel.getDataParams(idx))
  15576. );
  15577. });
  15578. }
  15579. data.each(function (idx) {
  15580. var itemModel = data.getItemModel(idx);
  15581. var color = itemModel.get(colorAccessPath, true);
  15582. if (color != null) {
  15583. data.setItemVisual(idx, 'color', color);
  15584. }
  15585. });
  15586. }
  15587. }
  15588. seriesType ? ecModel.eachSeriesByType(seriesType, encodeColor)
  15589. : ecModel.eachSeries(encodeColor);
  15590. };
  15591. /***/ },
  15592. /* 90 */
  15593. /***/ function(module, exports, __webpack_require__) {
  15594. // Compatitable with 2.0
  15595. var zrUtil = __webpack_require__(3);
  15596. var compatStyle = __webpack_require__(91);
  15597. function get(opt, path) {
  15598. path = path.split(',');
  15599. var obj = opt;
  15600. for (var i = 0; i < path.length; i++) {
  15601. obj = obj && obj[path[i]];
  15602. if (obj == null) {
  15603. break;
  15604. }
  15605. }
  15606. return obj;
  15607. }
  15608. function set(opt, path, val, overwrite) {
  15609. path = path.split(',');
  15610. var obj = opt;
  15611. var key;
  15612. for (var i = 0; i < path.length - 1; i++) {
  15613. key = path[i];
  15614. if (obj[key] == null) {
  15615. obj[key] = {};
  15616. }
  15617. obj = obj[key];
  15618. }
  15619. if (overwrite || obj[path[i]] == null) {
  15620. obj[path[i]] = val;
  15621. }
  15622. }
  15623. function compatLayoutProperties(option) {
  15624. each(LAYOUT_PROPERTIES, function (prop) {
  15625. if (prop[0] in option && !(prop[1] in option)) {
  15626. option[prop[1]] = option[prop[0]];
  15627. }
  15628. });
  15629. }
  15630. var LAYOUT_PROPERTIES = [
  15631. ['x', 'left'], ['y', 'top'], ['x2', 'right'], ['y2', 'bottom']
  15632. ];
  15633. var COMPATITABLE_COMPONENTS = [
  15634. 'grid', 'geo', 'parallel', 'legend', 'toolbox', 'title', 'visualMap', 'dataZoom', 'timeline'
  15635. ];
  15636. var COMPATITABLE_SERIES = [
  15637. 'bar', 'boxplot', 'candlestick', 'chord', 'effectScatter',
  15638. 'funnel', 'gauge', 'lines', 'graph', 'heatmap', 'line', 'map', 'parallel',
  15639. 'pie', 'radar', 'sankey', 'scatter', 'treemap'
  15640. ];
  15641. var each = zrUtil.each;
  15642. module.exports = function (option) {
  15643. each(option.series, function (seriesOpt) {
  15644. if (!zrUtil.isObject(seriesOpt)) {
  15645. return;
  15646. }
  15647. var seriesType = seriesOpt.type;
  15648. compatStyle(seriesOpt);
  15649. if (seriesType === 'pie' || seriesType === 'gauge') {
  15650. if (seriesOpt.clockWise != null) {
  15651. seriesOpt.clockwise = seriesOpt.clockWise;
  15652. }
  15653. }
  15654. if (seriesType === 'gauge') {
  15655. var pointerColor = get(seriesOpt, 'pointer.color');
  15656. pointerColor != null
  15657. && set(seriesOpt, 'itemStyle.normal.color', pointerColor);
  15658. }
  15659. for (var i = 0; i < COMPATITABLE_SERIES.length; i++) {
  15660. if (COMPATITABLE_SERIES[i] === seriesOpt.type) {
  15661. compatLayoutProperties(seriesOpt);
  15662. break;
  15663. }
  15664. }
  15665. });
  15666. // dataRange has changed to visualMap
  15667. if (option.dataRange) {
  15668. option.visualMap = option.dataRange;
  15669. }
  15670. each(COMPATITABLE_COMPONENTS, function (componentName) {
  15671. var options = option[componentName];
  15672. if (options) {
  15673. if (!zrUtil.isArray(options)) {
  15674. options = [options];
  15675. }
  15676. each(options, function (option) {
  15677. compatLayoutProperties(option);
  15678. });
  15679. }
  15680. });
  15681. };
  15682. /***/ },
  15683. /* 91 */
  15684. /***/ function(module, exports, __webpack_require__) {
  15685. var zrUtil = __webpack_require__(3);
  15686. var POSSIBLE_STYLES = [
  15687. 'areaStyle', 'lineStyle', 'nodeStyle', 'linkStyle',
  15688. 'chordStyle', 'label', 'labelLine'
  15689. ];
  15690. function compatItemStyle(opt) {
  15691. var itemStyleOpt = opt && opt.itemStyle;
  15692. if (itemStyleOpt) {
  15693. zrUtil.each(POSSIBLE_STYLES, function (styleName) {
  15694. var normalItemStyleOpt = itemStyleOpt.normal;
  15695. var emphasisItemStyleOpt = itemStyleOpt.emphasis;
  15696. if (normalItemStyleOpt && normalItemStyleOpt[styleName]) {
  15697. opt[styleName] = opt[styleName] || {};
  15698. if (!opt[styleName].normal) {
  15699. opt[styleName].normal = normalItemStyleOpt[styleName];
  15700. }
  15701. else {
  15702. zrUtil.merge(opt[styleName].normal, normalItemStyleOpt[styleName]);
  15703. }
  15704. normalItemStyleOpt[styleName] = null;
  15705. }
  15706. if (emphasisItemStyleOpt && emphasisItemStyleOpt[styleName]) {
  15707. opt[styleName] = opt[styleName] || {};
  15708. if (!opt[styleName].emphasis) {
  15709. opt[styleName].emphasis = emphasisItemStyleOpt[styleName];
  15710. }
  15711. else {
  15712. zrUtil.merge(opt[styleName].emphasis, emphasisItemStyleOpt[styleName]);
  15713. }
  15714. emphasisItemStyleOpt[styleName] = null;
  15715. }
  15716. });
  15717. }
  15718. }
  15719. module.exports = function (seriesOpt) {
  15720. if (!seriesOpt) {
  15721. return;
  15722. }
  15723. compatItemStyle(seriesOpt);
  15724. compatItemStyle(seriesOpt.markPoint);
  15725. compatItemStyle(seriesOpt.markLine);
  15726. var data = seriesOpt.data;
  15727. if (data) {
  15728. for (var i = 0; i < data.length; i++) {
  15729. compatItemStyle(data[i]);
  15730. }
  15731. // mark point data
  15732. var markPoint = seriesOpt.markPoint;
  15733. if (markPoint && markPoint.data) {
  15734. var mpData = markPoint.data;
  15735. for (var i = 0; i < mpData.length; i++) {
  15736. compatItemStyle(mpData[i]);
  15737. }
  15738. }
  15739. // mark line data
  15740. var markLine = seriesOpt.markLine;
  15741. if (markLine && markLine.data) {
  15742. var mlData = markLine.data;
  15743. for (var i = 0; i < mlData.length; i++) {
  15744. if (zrUtil.isArray(mlData[i])) {
  15745. compatItemStyle(mlData[i][0]);
  15746. compatItemStyle(mlData[i][1]);
  15747. }
  15748. else {
  15749. compatItemStyle(mlData[i]);
  15750. }
  15751. }
  15752. }
  15753. }
  15754. };
  15755. /***/ },
  15756. /* 92 */
  15757. /***/ function(module, exports, __webpack_require__) {
  15758. var zrUtil = __webpack_require__(3);
  15759. var echarts = __webpack_require__(1);
  15760. __webpack_require__(93);
  15761. __webpack_require__(98);
  15762. echarts.registerVisualCoding('chart', zrUtil.curry(
  15763. __webpack_require__(104), 'line', 'circle', 'line'
  15764. ));
  15765. echarts.registerLayout(zrUtil.curry(
  15766. __webpack_require__(105), 'line'
  15767. ));
  15768. // Down sample after filter
  15769. echarts.registerProcessor('statistic', zrUtil.curry(
  15770. __webpack_require__(106), 'line'
  15771. ));
  15772. // In case developer forget to include grid component
  15773. __webpack_require__(107);
  15774. /***/ },
  15775. /* 93 */
  15776. /***/ function(module, exports, __webpack_require__) {
  15777. 'use strict';
  15778. var createListFromArray = __webpack_require__(94);
  15779. var SeriesModel = __webpack_require__(27);
  15780. module.exports = SeriesModel.extend({
  15781. type: 'series.line',
  15782. dependencies: ['grid', 'polar'],
  15783. getInitialData: function (option, ecModel) {
  15784. return createListFromArray(option.data, this, ecModel);
  15785. },
  15786. defaultOption: {
  15787. zlevel: 0, // 一级层叠
  15788. z: 2, // 二级层叠
  15789. coordinateSystem: 'cartesian2d',
  15790. legendHoverLink: true,
  15791. hoverAnimation: true,
  15792. // stack: null
  15793. xAxisIndex: 0,
  15794. yAxisIndex: 0,
  15795. polarIndex: 0,
  15796. // If clip the overflow value
  15797. clipOverflow: true,
  15798. label: {
  15799. normal: {
  15800. position: 'top'
  15801. }
  15802. },
  15803. // itemStyle: {
  15804. // normal: {},
  15805. // emphasis: {}
  15806. // },
  15807. lineStyle: {
  15808. normal: {
  15809. width: 2,
  15810. type: 'solid'
  15811. }
  15812. },
  15813. // areaStyle: {},
  15814. smooth: false,
  15815. smoothMonotone: null,
  15816. // 拐点图形类型
  15817. symbol: 'emptyCircle',
  15818. // 拐点图形大小
  15819. symbolSize: 4,
  15820. // 拐点图形旋转控制
  15821. symbolRotate: null,
  15822. // 是否显示 symbol, 只有在 tooltip hover 的时候显示
  15823. showSymbol: true,
  15824. // 标志图形默认只有主轴显示(随主轴标签间隔隐藏策略)
  15825. showAllSymbol: false,
  15826. // 是否连接断点
  15827. connectNulls: false,
  15828. // 数据过滤,'average', 'max', 'min', 'sum'
  15829. sampling: 'none',
  15830. animationEasing: 'linear'
  15831. }
  15832. });
  15833. /***/ },
  15834. /* 94 */
  15835. /***/ function(module, exports, __webpack_require__) {
  15836. 'use strict';
  15837. var List = __webpack_require__(95);
  15838. var completeDimensions = __webpack_require__(97);
  15839. var zrUtil = __webpack_require__(3);
  15840. var modelUtil = __webpack_require__(5);
  15841. var CoordinateSystem = __webpack_require__(25);
  15842. var getDataItemValue = modelUtil.getDataItemValue;
  15843. var converDataValue = modelUtil.converDataValue;
  15844. function firstDataNotNull(data) {
  15845. var i = 0;
  15846. while (i < data.length && data[i] == null) {
  15847. i++;
  15848. }
  15849. return data[i];
  15850. }
  15851. function ifNeedCompleteOrdinalData(data) {
  15852. var sampleItem = firstDataNotNull(data);
  15853. return sampleItem != null
  15854. && !zrUtil.isArray(getDataItemValue(sampleItem));
  15855. }
  15856. /**
  15857. * Helper function to create a list from option data
  15858. */
  15859. function createListFromArray(data, seriesModel, ecModel) {
  15860. // If data is undefined
  15861. data = data || [];
  15862. if (!zrUtil.isArray(data)) {
  15863. throw new Error('Invalid data.');
  15864. }
  15865. var coordSysName = seriesModel.get('coordinateSystem');
  15866. var creator = creators[coordSysName];
  15867. var registeredCoordSys = CoordinateSystem.get(coordSysName);
  15868. // FIXME
  15869. var result = creator && creator(data, seriesModel, ecModel);
  15870. var dimensions = result && result.dimensions;
  15871. if (!dimensions) {
  15872. // Get dimensions from registered coordinate system
  15873. dimensions = (registeredCoordSys && registeredCoordSys.dimensions) || ['x', 'y'];
  15874. dimensions = completeDimensions(dimensions, data, dimensions.concat(['value']));
  15875. }
  15876. var categoryAxisModel = result && result.categoryAxisModel;
  15877. var categories;
  15878. var categoryDimIndex = dimensions[0].type === 'ordinal'
  15879. ? 0 : (dimensions[1].type === 'ordinal' ? 1 : -1);
  15880. var list = new List(dimensions, seriesModel);
  15881. var nameList = createNameList(result, data);
  15882. var dimValueGetter = (categoryAxisModel && ifNeedCompleteOrdinalData(data))
  15883. ? function (itemOpt, dimName, dataIndex, dimIndex) {
  15884. // Use dataIndex as ordinal value in categoryAxis
  15885. return dimIndex === categoryDimIndex
  15886. ? dataIndex
  15887. : converDataValue(getDataItemValue(itemOpt), dimensions[dimIndex]);
  15888. }
  15889. : function (itemOpt, dimName, dataIndex, dimIndex) {
  15890. var value = getDataItemValue(itemOpt);
  15891. var val = converDataValue(value && value[dimIndex], dimensions[dimIndex]);
  15892. if (categoryDimIndex === dimIndex) {
  15893. // If given value is a category string
  15894. if (typeof val === 'string') {
  15895. // Lazy get categories
  15896. categories = categories || categoryAxisModel.getCategories();
  15897. val = zrUtil.indexOf(categories, val);
  15898. if (val < 0 && !isNaN(val)) {
  15899. // In case some one write '1', '2' istead of 1, 2
  15900. val = +val;
  15901. }
  15902. }
  15903. }
  15904. return val;
  15905. };
  15906. list.initData(data, nameList, dimValueGetter);
  15907. return list;
  15908. }
  15909. function isStackable(axisType) {
  15910. return axisType !== 'category' && axisType !== 'time';
  15911. }
  15912. function getDimTypeByAxis(axisType) {
  15913. return axisType === 'category'
  15914. ? 'ordinal'
  15915. : axisType === 'time'
  15916. ? 'time'
  15917. : 'float';
  15918. }
  15919. /**
  15920. * Creaters for each coord system.
  15921. * @return {Object} {dimensions, categoryAxisModel};
  15922. */
  15923. var creators = {
  15924. cartesian2d: function (data, seriesModel, ecModel) {
  15925. var xAxisModel = ecModel.getComponent('xAxis', seriesModel.get('xAxisIndex'));
  15926. var yAxisModel = ecModel.getComponent('yAxis', seriesModel.get('yAxisIndex'));
  15927. if (!xAxisModel || !yAxisModel) {
  15928. throw new Error('Axis option not found');
  15929. }
  15930. var xAxisType = xAxisModel.get('type');
  15931. var yAxisType = yAxisModel.get('type');
  15932. var dimensions = [
  15933. {
  15934. name: 'x',
  15935. type: getDimTypeByAxis(xAxisType),
  15936. stackable: isStackable(xAxisType)
  15937. },
  15938. {
  15939. name: 'y',
  15940. // If two category axes
  15941. type: getDimTypeByAxis(yAxisType),
  15942. stackable: isStackable(yAxisType)
  15943. }
  15944. ];
  15945. var isXAxisCateogry = xAxisType === 'category';
  15946. completeDimensions(dimensions, data, ['x', 'y', 'z']);
  15947. return {
  15948. dimensions: dimensions,
  15949. categoryIndex: isXAxisCateogry ? 0 : 1,
  15950. categoryAxisModel: isXAxisCateogry
  15951. ? xAxisModel
  15952. : (yAxisType === 'category' ? yAxisModel : null)
  15953. };
  15954. },
  15955. polar: function (data, seriesModel, ecModel) {
  15956. var polarIndex = seriesModel.get('polarIndex') || 0;
  15957. var axisFinder = function (axisModel) {
  15958. return axisModel.get('polarIndex') === polarIndex;
  15959. };
  15960. var angleAxisModel = ecModel.findComponents({
  15961. mainType: 'angleAxis', filter: axisFinder
  15962. })[0];
  15963. var radiusAxisModel = ecModel.findComponents({
  15964. mainType: 'radiusAxis', filter: axisFinder
  15965. })[0];
  15966. if (!angleAxisModel || !radiusAxisModel) {
  15967. throw new Error('Axis option not found');
  15968. }
  15969. var radiusAxisType = radiusAxisModel.get('type');
  15970. var angleAxisType = angleAxisModel.get('type');
  15971. var dimensions = [
  15972. {
  15973. name: 'radius',
  15974. type: getDimTypeByAxis(radiusAxisType),
  15975. stackable: isStackable(radiusAxisType)
  15976. },
  15977. {
  15978. name: 'angle',
  15979. type: getDimTypeByAxis(angleAxisType),
  15980. stackable: isStackable(angleAxisType)
  15981. }
  15982. ];
  15983. var isAngleAxisCateogry = angleAxisType === 'category';
  15984. completeDimensions(dimensions, data, ['radius', 'angle', 'value']);
  15985. return {
  15986. dimensions: dimensions,
  15987. categoryIndex: isAngleAxisCateogry ? 1 : 0,
  15988. categoryAxisModel: isAngleAxisCateogry
  15989. ? angleAxisModel
  15990. : (radiusAxisType === 'category' ? radiusAxisModel : null)
  15991. };
  15992. },
  15993. geo: function (data, seriesModel, ecModel) {
  15994. // TODO Region
  15995. // 多个散点图系列在同一个地区的时候
  15996. return {
  15997. dimensions: completeDimensions([
  15998. {name: 'lng'},
  15999. {name: 'lat'}
  16000. ], data, ['lng', 'lat', 'value'])
  16001. };
  16002. }
  16003. };
  16004. function createNameList(result, data) {
  16005. var nameList = [];
  16006. if (result && result.categoryAxisModel) {
  16007. // FIXME Two category axis
  16008. var categories = result.categoryAxisModel.getCategories();
  16009. if (categories) {
  16010. var dataLen = data.length;
  16011. // Ordered data is given explicitly like
  16012. // [[3, 0.2], [1, 0.3], [2, 0.15]]
  16013. // or given scatter data,
  16014. // pick the category
  16015. if (zrUtil.isArray(data[0]) && data[0].length > 1) {
  16016. nameList = [];
  16017. for (var i = 0; i < dataLen; i++) {
  16018. nameList[i] = categories[data[i][result.categoryIndex || 0]];
  16019. }
  16020. }
  16021. else {
  16022. nameList = categories.slice(0);
  16023. }
  16024. }
  16025. }
  16026. return nameList;
  16027. }
  16028. module.exports = createListFromArray;
  16029. /***/ },
  16030. /* 95 */
  16031. /***/ function(module, exports, __webpack_require__) {
  16032. /* WEBPACK VAR INJECTION */(function(global) {/**
  16033. * List for data storage
  16034. * @module echarts/data/List
  16035. */
  16036. var UNDEFINED = 'undefined';
  16037. var globalObj = typeof window === 'undefined' ? global : window;
  16038. var Float64Array = typeof globalObj.Float64Array === UNDEFINED
  16039. ? Array : globalObj.Float64Array;
  16040. var Int32Array = typeof globalObj.Int32Array === UNDEFINED
  16041. ? Array : globalObj.Int32Array;
  16042. var dataCtors = {
  16043. 'float': Float64Array,
  16044. 'int': Int32Array,
  16045. // Ordinal data type can be string or int
  16046. 'ordinal': Array,
  16047. 'number': Array,
  16048. 'time': Array
  16049. };
  16050. var Model = __webpack_require__(8);
  16051. var DataDiffer = __webpack_require__(96);
  16052. var zrUtil = __webpack_require__(3);
  16053. var modelUtil = __webpack_require__(5);
  16054. var isObject = zrUtil.isObject;
  16055. var IMMUTABLE_PROPERTIES = [
  16056. 'stackedOn', '_nameList', '_idList', '_rawData'
  16057. ];
  16058. var transferImmuProperties = function (a, b) {
  16059. zrUtil.each(IMMUTABLE_PROPERTIES.concat(b.__wrappedMethods || []), function (propName) {
  16060. if (b.hasOwnProperty(propName)) {
  16061. a[propName] = b[propName];
  16062. }
  16063. });
  16064. a.__wrappedMethods = b.__wrappedMethods;
  16065. };
  16066. /**
  16067. * @constructor
  16068. * @alias module:echarts/data/List
  16069. *
  16070. * @param {Array.<string>} dimensions
  16071. * Dimensions should be concrete names like x, y, z, lng, lat, angle, radius
  16072. * @param {module:echarts/model/Model} hostModel
  16073. */
  16074. var List = function (dimensions, hostModel) {
  16075. dimensions = dimensions || ['x', 'y'];
  16076. var dimensionInfos = {};
  16077. var dimensionNames = [];
  16078. for (var i = 0; i < dimensions.length; i++) {
  16079. var dimensionName;
  16080. var dimensionInfo = {};
  16081. if (typeof dimensions[i] === 'string') {
  16082. dimensionName = dimensions[i];
  16083. dimensionInfo = {
  16084. name: dimensionName,
  16085. stackable: false,
  16086. // Type can be 'float', 'int', 'number'
  16087. // Default is number, Precision of float may not enough
  16088. type: 'number'
  16089. };
  16090. }
  16091. else {
  16092. dimensionInfo = dimensions[i];
  16093. dimensionName = dimensionInfo.name;
  16094. dimensionInfo.type = dimensionInfo.type || 'number';
  16095. }
  16096. dimensionNames.push(dimensionName);
  16097. dimensionInfos[dimensionName] = dimensionInfo;
  16098. }
  16099. /**
  16100. * @readOnly
  16101. * @type {Array.<string>}
  16102. */
  16103. this.dimensions = dimensionNames;
  16104. /**
  16105. * Infomation of each data dimension, like data type.
  16106. * @type {Object}
  16107. */
  16108. this._dimensionInfos = dimensionInfos;
  16109. /**
  16110. * @type {module:echarts/model/Model}
  16111. */
  16112. this.hostModel = hostModel;
  16113. /**
  16114. * @type {module:echarts/model/Model}
  16115. */
  16116. this.dataType;
  16117. /**
  16118. * Indices stores the indices of data subset after filtered.
  16119. * This data subset will be used in chart.
  16120. * @type {Array.<number>}
  16121. * @readOnly
  16122. */
  16123. this.indices = [];
  16124. /**
  16125. * Data storage
  16126. * @type {Object.<key, TypedArray|Array>}
  16127. * @private
  16128. */
  16129. this._storage = {};
  16130. /**
  16131. * @type {Array.<string>}
  16132. */
  16133. this._nameList = [];
  16134. /**
  16135. * @type {Array.<string>}
  16136. */
  16137. this._idList = [];
  16138. /**
  16139. * Models of data option is stored sparse for optimizing memory cost
  16140. * @type {Array.<module:echarts/model/Model>}
  16141. * @private
  16142. */
  16143. this._optionModels = [];
  16144. /**
  16145. * @param {module:echarts/data/List}
  16146. */
  16147. this.stackedOn = null;
  16148. /**
  16149. * Global visual properties after visual coding
  16150. * @type {Object}
  16151. * @private
  16152. */
  16153. this._visual = {};
  16154. /**
  16155. * Globel layout properties.
  16156. * @type {Object}
  16157. * @private
  16158. */
  16159. this._layout = {};
  16160. /**
  16161. * Item visual properties after visual coding
  16162. * @type {Array.<Object>}
  16163. * @private
  16164. */
  16165. this._itemVisuals = [];
  16166. /**
  16167. * Item layout properties after layout
  16168. * @type {Array.<Object>}
  16169. * @private
  16170. */
  16171. this._itemLayouts = [];
  16172. /**
  16173. * Graphic elemnents
  16174. * @type {Array.<module:zrender/Element>}
  16175. * @private
  16176. */
  16177. this._graphicEls = [];
  16178. /**
  16179. * @type {Array.<Array|Object>}
  16180. * @private
  16181. */
  16182. this._rawData;
  16183. /**
  16184. * @type {Object}
  16185. * @private
  16186. */
  16187. this._extent;
  16188. };
  16189. var listProto = List.prototype;
  16190. listProto.type = 'list';
  16191. /**
  16192. * Get dimension name
  16193. * @param {string|number} dim
  16194. * Dimension can be concrete names like x, y, z, lng, lat, angle, radius
  16195. * Or a ordinal number. For example getDimensionInfo(0) will return 'x' or 'lng' or 'radius'
  16196. * @return {string} Concrete dim name.
  16197. */
  16198. listProto.getDimension = function (dim) {
  16199. if (!isNaN(dim)) {
  16200. dim = this.dimensions[dim] || dim;
  16201. }
  16202. return dim;
  16203. };
  16204. /**
  16205. * Get type and stackable info of particular dimension
  16206. * @param {string|number} dim
  16207. * Dimension can be concrete names like x, y, z, lng, lat, angle, radius
  16208. * Or a ordinal number. For example getDimensionInfo(0) will return 'x' or 'lng' or 'radius'
  16209. */
  16210. listProto.getDimensionInfo = function (dim) {
  16211. return zrUtil.clone(this._dimensionInfos[this.getDimension(dim)]);
  16212. };
  16213. /**
  16214. * Initialize from data
  16215. * @param {Array.<Object|number|Array>} data
  16216. * @param {Array.<string>} [nameList]
  16217. * @param {Function} [dimValueGetter] (dataItem, dimName, dataIndex, dimIndex) => number
  16218. */
  16219. listProto.initData = function (data, nameList, dimValueGetter) {
  16220. data = data || [];
  16221. if (!zrUtil.isArray(data)) {
  16222. throw new Error('Invalid data.');
  16223. }
  16224. this._rawData = data;
  16225. // Clear
  16226. var storage = this._storage = {};
  16227. var indices = this.indices = [];
  16228. var dimensions = this.dimensions;
  16229. var size = data.length;
  16230. var dimensionInfoMap = this._dimensionInfos;
  16231. var idList = [];
  16232. var nameRepeatCount = {};
  16233. nameList = nameList || [];
  16234. // Init storage
  16235. for (var i = 0; i < dimensions.length; i++) {
  16236. var dimInfo = dimensionInfoMap[dimensions[i]];
  16237. var DataCtor = dataCtors[dimInfo.type];
  16238. storage[dimensions[i]] = new DataCtor(size);
  16239. }
  16240. // Default dim value getter
  16241. dimValueGetter = dimValueGetter || function (dataItem, dimName, dataIndex, dimIndex) {
  16242. var value = modelUtil.getDataItemValue(dataItem);
  16243. return modelUtil.converDataValue(
  16244. zrUtil.isArray(value)
  16245. ? value[dimIndex]
  16246. // If value is a single number or something else not array.
  16247. : value,
  16248. dimensionInfoMap[dimName]
  16249. );
  16250. };
  16251. for (var idx = 0; idx < data.length; idx++) {
  16252. var dataItem = data[idx];
  16253. // Each data item is value
  16254. // [1, 2]
  16255. // 2
  16256. // Bar chart, line chart which uses category axis
  16257. // only gives the 'y' value. 'x' value is the indices of cateogry
  16258. // Use a tempValue to normalize the value to be a (x, y) value
  16259. // Store the data by dimensions
  16260. for (var k = 0; k < dimensions.length; k++) {
  16261. var dim = dimensions[k];
  16262. var dimStorage = storage[dim];
  16263. // PENDING NULL is empty or zero
  16264. dimStorage[idx] = dimValueGetter(dataItem, dim, idx, k);
  16265. }
  16266. indices.push(idx);
  16267. }
  16268. // Use the name in option and create id
  16269. for (var i = 0; i < data.length; i++) {
  16270. var id = '';
  16271. if (!nameList[i]) {
  16272. nameList[i] = data[i].name;
  16273. // Try using the id in option
  16274. id = data[i].id;
  16275. }
  16276. var name = nameList[i] || '';
  16277. if (!id && name) {
  16278. // Use name as id and add counter to avoid same name
  16279. nameRepeatCount[name] = nameRepeatCount[name] || 0;
  16280. id = name;
  16281. if (nameRepeatCount[name] > 0) {
  16282. id += '__ec__' + nameRepeatCount[name];
  16283. }
  16284. nameRepeatCount[name]++;
  16285. }
  16286. id && (idList[i] = id);
  16287. }
  16288. this._nameList = nameList;
  16289. this._idList = idList;
  16290. };
  16291. /**
  16292. * @return {number}
  16293. */
  16294. listProto.count = function () {
  16295. return this.indices.length;
  16296. };
  16297. /**
  16298. * Get value. Return NaN if idx is out of range.
  16299. * @param {string} dim Dim must be concrete name.
  16300. * @param {number} idx
  16301. * @param {boolean} stack
  16302. * @return {number}
  16303. */
  16304. listProto.get = function (dim, idx, stack) {
  16305. var storage = this._storage;
  16306. var dataIndex = this.indices[idx];
  16307. // If value not exists
  16308. if (dataIndex == null) {
  16309. return NaN;
  16310. }
  16311. var value = storage[dim] && storage[dim][dataIndex];
  16312. // FIXME ordinal data type is not stackable
  16313. if (stack) {
  16314. var dimensionInfo = this._dimensionInfos[dim];
  16315. if (dimensionInfo && dimensionInfo.stackable) {
  16316. var stackedOn = this.stackedOn;
  16317. while (stackedOn) {
  16318. // Get no stacked data of stacked on
  16319. var stackedValue = stackedOn.get(dim, idx);
  16320. // Considering positive stack, negative stack and empty data
  16321. if ((value >= 0 && stackedValue > 0) // Positive stack
  16322. || (value <= 0 && stackedValue < 0) // Negative stack
  16323. ) {
  16324. value += stackedValue;
  16325. }
  16326. stackedOn = stackedOn.stackedOn;
  16327. }
  16328. }
  16329. }
  16330. return value;
  16331. };
  16332. /**
  16333. * Get value for multi dimensions.
  16334. * @param {Array.<string>} [dimensions] If ignored, using all dimensions.
  16335. * @param {number} idx
  16336. * @param {boolean} stack
  16337. * @return {number}
  16338. */
  16339. listProto.getValues = function (dimensions, idx, stack) {
  16340. var values = [];
  16341. if (!zrUtil.isArray(dimensions)) {
  16342. stack = idx;
  16343. idx = dimensions;
  16344. dimensions = this.dimensions;
  16345. }
  16346. for (var i = 0, len = dimensions.length; i < len; i++) {
  16347. values.push(this.get(dimensions[i], idx, stack));
  16348. }
  16349. return values;
  16350. };
  16351. /**
  16352. * If value is NaN. Inlcuding '-'
  16353. * @param {string} dim
  16354. * @param {number} idx
  16355. * @return {number}
  16356. */
  16357. listProto.hasValue = function (idx) {
  16358. var dimensions = this.dimensions;
  16359. var dimensionInfos = this._dimensionInfos;
  16360. for (var i = 0, len = dimensions.length; i < len; i++) {
  16361. if (
  16362. // Ordinal type can be string or number
  16363. dimensionInfos[dimensions[i]].type !== 'ordinal'
  16364. && isNaN(this.get(dimensions[i], idx))
  16365. ) {
  16366. return false;
  16367. }
  16368. }
  16369. return true;
  16370. };
  16371. /**
  16372. * Get extent of data in one dimension
  16373. * @param {string} dim
  16374. * @param {boolean} stack
  16375. */
  16376. listProto.getDataExtent = function (dim, stack) {
  16377. var dimData = this._storage[dim];
  16378. var dimInfo = this.getDimensionInfo(dim);
  16379. stack = (dimInfo && dimInfo.stackable) && stack;
  16380. var dimExtent = (this._extent || (this._extent = {}))[dim + (!!stack)];
  16381. var value;
  16382. if (dimExtent) {
  16383. return dimExtent;
  16384. }
  16385. // var dimInfo = this._dimensionInfos[dim];
  16386. if (dimData) {
  16387. var min = Infinity;
  16388. var max = -Infinity;
  16389. // var isOrdinal = dimInfo.type === 'ordinal';
  16390. for (var i = 0, len = this.count(); i < len; i++) {
  16391. value = this.get(dim, i, stack);
  16392. // FIXME
  16393. // if (isOrdinal && typeof value === 'string') {
  16394. // value = zrUtil.indexOf(dimData, value);
  16395. // }
  16396. value < min && (min = value);
  16397. value > max && (max = value);
  16398. }
  16399. return (this._extent[dim + stack] = [min, max]);
  16400. }
  16401. else {
  16402. return [Infinity, -Infinity];
  16403. }
  16404. };
  16405. /**
  16406. * Get sum of data in one dimension
  16407. * @param {string} dim
  16408. * @param {boolean} stack
  16409. */
  16410. listProto.getSum = function (dim, stack) {
  16411. var dimData = this._storage[dim];
  16412. var sum = 0;
  16413. if (dimData) {
  16414. for (var i = 0, len = this.count(); i < len; i++) {
  16415. var value = this.get(dim, i, stack);
  16416. if (!isNaN(value)) {
  16417. sum += value;
  16418. }
  16419. }
  16420. }
  16421. return sum;
  16422. };
  16423. /**
  16424. * Retreive the index with given value
  16425. * @param {number} idx
  16426. * @param {number} value
  16427. * @return {number}
  16428. */
  16429. // FIXME Precision of float value
  16430. listProto.indexOf = function (dim, value) {
  16431. var storage = this._storage;
  16432. var dimData = storage[dim];
  16433. var indices = this.indices;
  16434. if (dimData) {
  16435. for (var i = 0, len = indices.length; i < len; i++) {
  16436. var rawIndex = indices[i];
  16437. if (dimData[rawIndex] === value) {
  16438. return i;
  16439. }
  16440. }
  16441. }
  16442. return -1;
  16443. };
  16444. /**
  16445. * Retreive the index with given name
  16446. * @param {number} idx
  16447. * @param {number} name
  16448. * @return {number}
  16449. */
  16450. listProto.indexOfName = function (name) {
  16451. var indices = this.indices;
  16452. var nameList = this._nameList;
  16453. for (var i = 0, len = indices.length; i < len; i++) {
  16454. var rawIndex = indices[i];
  16455. if (nameList[rawIndex] === name) {
  16456. return i;
  16457. }
  16458. }
  16459. return -1;
  16460. };
  16461. /**
  16462. * Retreive the index of nearest value
  16463. * @param {string} dim
  16464. * @param {number} value
  16465. * @param {boolean} stack If given value is after stacked
  16466. * @return {number}
  16467. */
  16468. listProto.indexOfNearest = function (dim, value, stack) {
  16469. var storage = this._storage;
  16470. var dimData = storage[dim];
  16471. if (dimData) {
  16472. var minDist = Number.MAX_VALUE;
  16473. var nearestIdx = -1;
  16474. for (var i = 0, len = this.count(); i < len; i++) {
  16475. var diff = value - this.get(dim, i, stack);
  16476. var dist = Math.abs(diff);
  16477. if (dist < minDist
  16478. // For the case of two data are same on xAxis, which has sequence data.
  16479. // Show the nearest index
  16480. // https://github.com/ecomfe/echarts/issues/2869
  16481. || (dist === minDist && diff > 0)
  16482. ) {
  16483. minDist = dist;
  16484. nearestIdx = i;
  16485. }
  16486. }
  16487. return nearestIdx;
  16488. }
  16489. return -1;
  16490. };
  16491. /**
  16492. * Get raw data index
  16493. * @param {number} idx
  16494. * @return {number}
  16495. */
  16496. listProto.getRawIndex = function (idx) {
  16497. var rawIdx = this.indices[idx];
  16498. return rawIdx == null ? -1 : rawIdx;
  16499. };
  16500. /**
  16501. * Get raw data item
  16502. * @param {number} idx
  16503. * @return {number}
  16504. */
  16505. listProto.getRawDataItem = function (idx) {
  16506. return this._rawData[this.getRawIndex(idx)];
  16507. };
  16508. /**
  16509. * @param {number} idx
  16510. * @param {boolean} [notDefaultIdx=false]
  16511. * @return {string}
  16512. */
  16513. listProto.getName = function (idx) {
  16514. return this._nameList[this.indices[idx]] || '';
  16515. };
  16516. /**
  16517. * @param {number} idx
  16518. * @param {boolean} [notDefaultIdx=false]
  16519. * @return {string}
  16520. */
  16521. listProto.getId = function (idx) {
  16522. return this._idList[this.indices[idx]] || (this.getRawIndex(idx) + '');
  16523. };
  16524. function normalizeDimensions(dimensions) {
  16525. if (!zrUtil.isArray(dimensions)) {
  16526. dimensions = [dimensions];
  16527. }
  16528. return dimensions;
  16529. }
  16530. /**
  16531. * Data iteration
  16532. * @param {string|Array.<string>}
  16533. * @param {Function} cb
  16534. * @param {boolean} [stack=false]
  16535. * @param {*} [context=this]
  16536. *
  16537. * @example
  16538. * list.each('x', function (x, idx) {});
  16539. * list.each(['x', 'y'], function (x, y, idx) {});
  16540. * list.each(function (idx) {})
  16541. */
  16542. listProto.each = function (dimensions, cb, stack, context) {
  16543. if (typeof dimensions === 'function') {
  16544. context = stack;
  16545. stack = cb;
  16546. cb = dimensions;
  16547. dimensions = [];
  16548. }
  16549. dimensions = zrUtil.map(
  16550. normalizeDimensions(dimensions), this.getDimension, this
  16551. );
  16552. var value = [];
  16553. var dimSize = dimensions.length;
  16554. var indices = this.indices;
  16555. context = context || this;
  16556. for (var i = 0; i < indices.length; i++) {
  16557. if (dimSize === 0) {
  16558. cb.call(context, i);
  16559. }
  16560. // Simple optimization
  16561. else if (dimSize === 1) {
  16562. cb.call(context, this.get(dimensions[0], i, stack), i);
  16563. }
  16564. else {
  16565. for (var k = 0; k < dimSize; k++) {
  16566. value[k] = this.get(dimensions[k], i, stack);
  16567. }
  16568. // Index
  16569. value[k] = i;
  16570. cb.apply(context, value);
  16571. }
  16572. }
  16573. };
  16574. /**
  16575. * Data filter
  16576. * @param {string|Array.<string>}
  16577. * @param {Function} cb
  16578. * @param {boolean} [stack=false]
  16579. * @param {*} [context=this]
  16580. */
  16581. listProto.filterSelf = function (dimensions, cb, stack, context) {
  16582. if (typeof dimensions === 'function') {
  16583. context = stack;
  16584. stack = cb;
  16585. cb = dimensions;
  16586. dimensions = [];
  16587. }
  16588. dimensions = zrUtil.map(
  16589. normalizeDimensions(dimensions), this.getDimension, this
  16590. );
  16591. var newIndices = [];
  16592. var value = [];
  16593. var dimSize = dimensions.length;
  16594. var indices = this.indices;
  16595. context = context || this;
  16596. for (var i = 0; i < indices.length; i++) {
  16597. var keep;
  16598. // Simple optimization
  16599. if (dimSize === 1) {
  16600. keep = cb.call(
  16601. context, this.get(dimensions[0], i, stack), i
  16602. );
  16603. }
  16604. else {
  16605. for (var k = 0; k < dimSize; k++) {
  16606. value[k] = this.get(dimensions[k], i, stack);
  16607. }
  16608. value[k] = i;
  16609. keep = cb.apply(context, value);
  16610. }
  16611. if (keep) {
  16612. newIndices.push(indices[i]);
  16613. }
  16614. }
  16615. this.indices = newIndices;
  16616. // Reset data extent
  16617. this._extent = {};
  16618. return this;
  16619. };
  16620. /**
  16621. * Data mapping to a plain array
  16622. * @param {string|Array.<string>} [dimensions]
  16623. * @param {Function} cb
  16624. * @param {boolean} [stack=false]
  16625. * @param {*} [context=this]
  16626. * @return {Array}
  16627. */
  16628. listProto.mapArray = function (dimensions, cb, stack, context) {
  16629. if (typeof dimensions === 'function') {
  16630. context = stack;
  16631. stack = cb;
  16632. cb = dimensions;
  16633. dimensions = [];
  16634. }
  16635. var result = [];
  16636. this.each(dimensions, function () {
  16637. result.push(cb && cb.apply(this, arguments));
  16638. }, stack, context);
  16639. return result;
  16640. };
  16641. function cloneListForMapAndSample(original, excludeDimensions) {
  16642. var allDimensions = original.dimensions;
  16643. var list = new List(
  16644. zrUtil.map(allDimensions, original.getDimensionInfo, original),
  16645. original.hostModel
  16646. );
  16647. // FIXME If needs stackedOn, value may already been stacked
  16648. transferImmuProperties(list, original);
  16649. var storage = list._storage = {};
  16650. var originalStorage = original._storage;
  16651. // Init storage
  16652. for (var i = 0; i < allDimensions.length; i++) {
  16653. var dim = allDimensions[i];
  16654. var dimStore = originalStorage[dim];
  16655. if (zrUtil.indexOf(excludeDimensions, dim) >= 0) {
  16656. storage[dim] = new dimStore.constructor(
  16657. originalStorage[dim].length
  16658. );
  16659. }
  16660. else {
  16661. // Direct reference for other dimensions
  16662. storage[dim] = originalStorage[dim];
  16663. }
  16664. }
  16665. return list;
  16666. }
  16667. /**
  16668. * Data mapping to a new List with given dimensions
  16669. * @param {string|Array.<string>} dimensions
  16670. * @param {Function} cb
  16671. * @param {boolean} [stack=false]
  16672. * @param {*} [context=this]
  16673. * @return {Array}
  16674. */
  16675. listProto.map = function (dimensions, cb, stack, context) {
  16676. dimensions = zrUtil.map(
  16677. normalizeDimensions(dimensions), this.getDimension, this
  16678. );
  16679. var list = cloneListForMapAndSample(this, dimensions);
  16680. // Following properties are all immutable.
  16681. // So we can reference to the same value
  16682. var indices = list.indices = this.indices;
  16683. var storage = list._storage;
  16684. var tmpRetValue = [];
  16685. this.each(dimensions, function () {
  16686. var idx = arguments[arguments.length - 1];
  16687. var retValue = cb && cb.apply(this, arguments);
  16688. if (retValue != null) {
  16689. // a number
  16690. if (typeof retValue === 'number') {
  16691. tmpRetValue[0] = retValue;
  16692. retValue = tmpRetValue;
  16693. }
  16694. for (var i = 0; i < retValue.length; i++) {
  16695. var dim = dimensions[i];
  16696. var dimStore = storage[dim];
  16697. var rawIdx = indices[idx];
  16698. if (dimStore) {
  16699. dimStore[rawIdx] = retValue[i];
  16700. }
  16701. }
  16702. }
  16703. }, stack, context);
  16704. return list;
  16705. };
  16706. /**
  16707. * Large data down sampling on given dimension
  16708. * @param {string} dimension
  16709. * @param {number} rate
  16710. * @param {Function} sampleValue
  16711. * @param {Function} sampleIndex Sample index for name and id
  16712. */
  16713. listProto.downSample = function (dimension, rate, sampleValue, sampleIndex) {
  16714. var list = cloneListForMapAndSample(this, [dimension]);
  16715. var storage = this._storage;
  16716. var targetStorage = list._storage;
  16717. var originalIndices = this.indices;
  16718. var indices = list.indices = [];
  16719. var frameValues = [];
  16720. var frameIndices = [];
  16721. var frameSize = Math.floor(1 / rate);
  16722. var dimStore = targetStorage[dimension];
  16723. var len = this.count();
  16724. // Copy data from original data
  16725. for (var i = 0; i < storage[dimension].length; i++) {
  16726. targetStorage[dimension][i] = storage[dimension][i];
  16727. }
  16728. for (var i = 0; i < len; i += frameSize) {
  16729. // Last frame
  16730. if (frameSize > len - i) {
  16731. frameSize = len - i;
  16732. frameValues.length = frameSize;
  16733. }
  16734. for (var k = 0; k < frameSize; k++) {
  16735. var idx = originalIndices[i + k];
  16736. frameValues[k] = dimStore[idx];
  16737. frameIndices[k] = idx;
  16738. }
  16739. var value = sampleValue(frameValues);
  16740. var idx = frameIndices[sampleIndex(frameValues, value) || 0];
  16741. // Only write value on the filtered data
  16742. dimStore[idx] = value;
  16743. indices.push(idx);
  16744. }
  16745. return list;
  16746. };
  16747. /**
  16748. * Get model of one data item.
  16749. *
  16750. * @param {number} idx
  16751. */
  16752. // FIXME Model proxy ?
  16753. listProto.getItemModel = function (idx) {
  16754. var hostModel = this.hostModel;
  16755. idx = this.indices[idx];
  16756. return new Model(this._rawData[idx], hostModel, hostModel && hostModel.ecModel);
  16757. };
  16758. /**
  16759. * Create a data differ
  16760. * @param {module:echarts/data/List} otherList
  16761. * @return {module:echarts/data/DataDiffer}
  16762. */
  16763. listProto.diff = function (otherList) {
  16764. var idList = this._idList;
  16765. var otherIdList = otherList && otherList._idList;
  16766. return new DataDiffer(
  16767. otherList ? otherList.indices : [], this.indices, function (idx) {
  16768. return otherIdList[idx] || (idx + '');
  16769. }, function (idx) {
  16770. return idList[idx] || (idx + '');
  16771. }
  16772. );
  16773. };
  16774. /**
  16775. * Get visual property.
  16776. * @param {string} key
  16777. */
  16778. listProto.getVisual = function (key) {
  16779. var visual = this._visual;
  16780. return visual && visual[key];
  16781. };
  16782. /**
  16783. * Set visual property
  16784. * @param {string|Object} key
  16785. * @param {*} [value]
  16786. *
  16787. * @example
  16788. * setVisual('color', color);
  16789. * setVisual({
  16790. * 'color': color
  16791. * });
  16792. */
  16793. listProto.setVisual = function (key, val) {
  16794. if (isObject(key)) {
  16795. for (var name in key) {
  16796. if (key.hasOwnProperty(name)) {
  16797. this.setVisual(name, key[name]);
  16798. }
  16799. }
  16800. return;
  16801. }
  16802. this._visual = this._visual || {};
  16803. this._visual[key] = val;
  16804. };
  16805. /**
  16806. * Set layout property.
  16807. * @param {string} key
  16808. * @param {*} [val]
  16809. */
  16810. listProto.setLayout = function (key, val) {
  16811. if (isObject(key)) {
  16812. for (var name in key) {
  16813. if (key.hasOwnProperty(name)) {
  16814. this.setLayout(name, key[name]);
  16815. }
  16816. }
  16817. return;
  16818. }
  16819. this._layout[key] = val;
  16820. };
  16821. /**
  16822. * Get layout property.
  16823. * @param {string} key.
  16824. * @return {*}
  16825. */
  16826. listProto.getLayout = function (key) {
  16827. return this._layout[key];
  16828. };
  16829. /**
  16830. * Get layout of single data item
  16831. * @param {number} idx
  16832. */
  16833. listProto.getItemLayout = function (idx) {
  16834. return this._itemLayouts[idx];
  16835. };
  16836. /**
  16837. * Set layout of single data item
  16838. * @param {number} idx
  16839. * @param {Object} layout
  16840. * @param {boolean=} [merge=false]
  16841. */
  16842. listProto.setItemLayout = function (idx, layout, merge) {
  16843. this._itemLayouts[idx] = merge
  16844. ? zrUtil.extend(this._itemLayouts[idx] || {}, layout)
  16845. : layout;
  16846. };
  16847. /**
  16848. * Clear all layout of single data item
  16849. */
  16850. listProto.clearItemLayouts = function () {
  16851. this._itemLayouts.length = 0;
  16852. };
  16853. /**
  16854. * Get visual property of single data item
  16855. * @param {number} idx
  16856. * @param {string} key
  16857. * @param {boolean} ignoreParent
  16858. */
  16859. listProto.getItemVisual = function (idx, key, ignoreParent) {
  16860. var itemVisual = this._itemVisuals[idx];
  16861. var val = itemVisual && itemVisual[key];
  16862. if (val == null && !ignoreParent) {
  16863. // Use global visual property
  16864. return this.getVisual(key);
  16865. }
  16866. return val;
  16867. };
  16868. /**
  16869. * Set visual property of single data item
  16870. *
  16871. * @param {number} idx
  16872. * @param {string|Object} key
  16873. * @param {*} [value]
  16874. *
  16875. * @example
  16876. * setItemVisual(0, 'color', color);
  16877. * setItemVisual(0, {
  16878. * 'color': color
  16879. * });
  16880. */
  16881. listProto.setItemVisual = function (idx, key, value) {
  16882. var itemVisual = this._itemVisuals[idx] || {};
  16883. this._itemVisuals[idx] = itemVisual;
  16884. if (isObject(key)) {
  16885. for (var name in key) {
  16886. if (key.hasOwnProperty(name)) {
  16887. itemVisual[name] = key[name];
  16888. }
  16889. }
  16890. return;
  16891. }
  16892. itemVisual[key] = value;
  16893. };
  16894. var setItemDataAndSeriesIndex = function (child) {
  16895. child.seriesIndex = this.seriesIndex;
  16896. child.dataIndex = this.dataIndex;
  16897. child.dataType = this.dataType;
  16898. };
  16899. /**
  16900. * Set graphic element relative to data. It can be set as null
  16901. * @param {number} idx
  16902. * @param {module:zrender/Element} [el]
  16903. */
  16904. listProto.setItemGraphicEl = function (idx, el) {
  16905. var hostModel = this.hostModel;
  16906. if (el) {
  16907. // Add data index and series index for indexing the data by element
  16908. // Useful in tooltip
  16909. el.dataIndex = idx;
  16910. el.dataType = this.dataType;
  16911. el.seriesIndex = hostModel && hostModel.seriesIndex;
  16912. if (el.type === 'group') {
  16913. el.traverse(setItemDataAndSeriesIndex, el);
  16914. }
  16915. }
  16916. this._graphicEls[idx] = el;
  16917. };
  16918. /**
  16919. * @param {number} idx
  16920. * @return {module:zrender/Element}
  16921. */
  16922. listProto.getItemGraphicEl = function (idx) {
  16923. return this._graphicEls[idx];
  16924. };
  16925. /**
  16926. * @param {Function} cb
  16927. * @param {*} context
  16928. */
  16929. listProto.eachItemGraphicEl = function (cb, context) {
  16930. zrUtil.each(this._graphicEls, function (el, idx) {
  16931. if (el) {
  16932. cb && cb.call(context, el, idx);
  16933. }
  16934. });
  16935. };
  16936. /**
  16937. * Shallow clone a new list except visual and layout properties, and graph elements.
  16938. * New list only change the indices.
  16939. */
  16940. listProto.cloneShallow = function () {
  16941. var dimensionInfoList = zrUtil.map(this.dimensions, this.getDimensionInfo, this);
  16942. var list = new List(dimensionInfoList, this.hostModel);
  16943. // FIXME
  16944. list._storage = this._storage;
  16945. transferImmuProperties(list, this);
  16946. list.indices = this.indices.slice();
  16947. return list;
  16948. };
  16949. /**
  16950. * Wrap some method to add more feature
  16951. * @param {string} methodName
  16952. * @param {Function} injectFunction
  16953. */
  16954. listProto.wrapMethod = function (methodName, injectFunction) {
  16955. var originalMethod = this[methodName];
  16956. if (typeof originalMethod !== 'function') {
  16957. return;
  16958. }
  16959. this.__wrappedMethods = this.__wrappedMethods || [];
  16960. this.__wrappedMethods.push(methodName);
  16961. this[methodName] = function () {
  16962. var res = originalMethod.apply(this, arguments);
  16963. return injectFunction.apply(this, [res].concat(zrUtil.slice(arguments)));
  16964. };
  16965. };
  16966. // Methods that create a new list based on this list should be listed here.
  16967. // Notice that those method should `RETURN` the new list.
  16968. listProto.TRANSFERABLE_METHODS = ['cloneShallow', 'downSample', 'map'];
  16969. // Methods that change indices of this list should be listed here.
  16970. listProto.CHANGABLE_METHODS = ['filterSelf'];
  16971. module.exports = List;
  16972. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  16973. /***/ },
  16974. /* 96 */
  16975. /***/ function(module, exports) {
  16976. 'use strict';
  16977. function defaultKeyGetter(item) {
  16978. return item;
  16979. }
  16980. function DataDiffer(oldArr, newArr, oldKeyGetter, newKeyGetter) {
  16981. this._old = oldArr;
  16982. this._new = newArr;
  16983. this._oldKeyGetter = oldKeyGetter || defaultKeyGetter;
  16984. this._newKeyGetter = newKeyGetter || defaultKeyGetter;
  16985. }
  16986. DataDiffer.prototype = {
  16987. constructor: DataDiffer,
  16988. /**
  16989. * Callback function when add a data
  16990. */
  16991. add: function (func) {
  16992. this._add = func;
  16993. return this;
  16994. },
  16995. /**
  16996. * Callback function when update a data
  16997. */
  16998. update: function (func) {
  16999. this._update = func;
  17000. return this;
  17001. },
  17002. /**
  17003. * Callback function when remove a data
  17004. */
  17005. remove: function (func) {
  17006. this._remove = func;
  17007. return this;
  17008. },
  17009. execute: function () {
  17010. var oldArr = this._old;
  17011. var newArr = this._new;
  17012. var oldKeyGetter = this._oldKeyGetter;
  17013. var newKeyGetter = this._newKeyGetter;
  17014. var oldDataIndexMap = {};
  17015. var newDataIndexMap = {};
  17016. var i;
  17017. initIndexMap(oldArr, oldDataIndexMap, oldKeyGetter);
  17018. initIndexMap(newArr, newDataIndexMap, newKeyGetter);
  17019. // Travel by inverted order to make sure order consistency
  17020. // when duplicate keys exists (consider newDataIndex.pop() below).
  17021. // For performance consideration, these code below do not look neat.
  17022. for (i = 0; i < oldArr.length; i++) {
  17023. var key = oldKeyGetter(oldArr[i]);
  17024. var idx = newDataIndexMap[key];
  17025. // idx can never be empty array here. see 'set null' logic below.
  17026. if (idx != null) {
  17027. // Consider there is duplicate key (for example, use dataItem.name as key).
  17028. // We should make sure every item in newArr and oldArr can be visited.
  17029. var len = idx.length;
  17030. if (len) {
  17031. len === 1 && (newDataIndexMap[key] = null);
  17032. idx = idx.unshift();
  17033. }
  17034. else {
  17035. newDataIndexMap[key] = null;
  17036. }
  17037. this._update && this._update(idx, i);
  17038. }
  17039. else {
  17040. this._remove && this._remove(i);
  17041. }
  17042. }
  17043. for (var key in newDataIndexMap) {
  17044. if (newDataIndexMap.hasOwnProperty(key)) {
  17045. var idx = newDataIndexMap[key];
  17046. if (idx == null) {
  17047. continue;
  17048. }
  17049. // idx can never be empty array here. see 'set null' logic above.
  17050. if (!idx.length) {
  17051. this._add && this._add(idx);
  17052. }
  17053. else {
  17054. for (var i = 0, len = idx.length; i < len; i++) {
  17055. this._add && this._add(idx[i]);
  17056. }
  17057. }
  17058. }
  17059. }
  17060. }
  17061. };
  17062. function initIndexMap(arr, map, keyGetter) {
  17063. for (var i = 0; i < arr.length; i++) {
  17064. var key = keyGetter(arr[i]);
  17065. var existence = map[key];
  17066. if (existence == null) {
  17067. map[key] = i;
  17068. }
  17069. else {
  17070. if (!existence.length) {
  17071. map[key] = existence = [existence];
  17072. }
  17073. existence.push(i);
  17074. }
  17075. }
  17076. }
  17077. module.exports = DataDiffer;
  17078. /***/ },
  17079. /* 97 */
  17080. /***/ function(module, exports, __webpack_require__) {
  17081. /**
  17082. * Complete dimensions by data (guess dimension).
  17083. */
  17084. var zrUtil = __webpack_require__(3);
  17085. /**
  17086. * Complete the dimensions array guessed from the data structure.
  17087. * @param {Array.<string>} dimensions Necessary dimensions, like ['x', 'y']
  17088. * @param {Array} data Data list. [[1, 2, 3], [2, 3, 4]]
  17089. * @param {Array.<string>} defaultNames Default names to fill not necessary dimensions, like ['value']
  17090. * @param {string} extraPrefix Prefix of name when filling the left dimensions.
  17091. * @return {Array.<string>}
  17092. */
  17093. function completeDimensions(dimensions, data, defaultNames, extraPrefix) {
  17094. if (!data) {
  17095. return dimensions;
  17096. }
  17097. var value0 = retrieveValue(data[0]);
  17098. var dimSize = zrUtil.isArray(value0) && value0.length || 1;
  17099. defaultNames = defaultNames || [];
  17100. extraPrefix = extraPrefix || 'extra';
  17101. for (var i = 0; i < dimSize; i++) {
  17102. if (!dimensions[i]) {
  17103. var name = defaultNames[i] || (extraPrefix + (i - defaultNames.length));
  17104. dimensions[i] = guessOrdinal(data, i)
  17105. ? {type: 'ordinal', name: name}
  17106. : name;
  17107. }
  17108. }
  17109. return dimensions;
  17110. }
  17111. // The rule should not be complex, otherwise user might not
  17112. // be able to known where the data is wrong.
  17113. function guessOrdinal(data, dimIndex) {
  17114. for (var i = 0, len = data.length; i < len; i++) {
  17115. var value = retrieveValue(data[i]);
  17116. if (!zrUtil.isArray(value)) {
  17117. return false;
  17118. }
  17119. var value = value[dimIndex];
  17120. if (value != null && isFinite(value)) {
  17121. return false;
  17122. }
  17123. else if (zrUtil.isString(value) && value !== '-') {
  17124. return true;
  17125. }
  17126. }
  17127. return false;
  17128. }
  17129. function retrieveValue(o) {
  17130. return zrUtil.isArray(o) ? o : zrUtil.isObject(o) ? o.value: o;
  17131. }
  17132. module.exports = completeDimensions;
  17133. /***/ },
  17134. /* 98 */
  17135. /***/ function(module, exports, __webpack_require__) {
  17136. 'use strict';
  17137. var zrUtil = __webpack_require__(3);
  17138. var SymbolDraw = __webpack_require__(99);
  17139. var Symbol = __webpack_require__(100);
  17140. var lineAnimationDiff = __webpack_require__(102);
  17141. var graphic = __webpack_require__(42);
  17142. var polyHelper = __webpack_require__(103);
  17143. var ChartView = __webpack_require__(41);
  17144. function isPointsSame(points1, points2) {
  17145. if (points1.length !== points2.length) {
  17146. return;
  17147. }
  17148. for (var i = 0; i < points1.length; i++) {
  17149. var p1 = points1[i];
  17150. var p2 = points2[i];
  17151. if (p1[0] !== p2[0] || p1[1] !== p2[1]) {
  17152. return;
  17153. }
  17154. }
  17155. return true;
  17156. }
  17157. function getSmooth(smooth) {
  17158. return typeof (smooth) === 'number' ? smooth : (smooth ? 0.3 : 0);
  17159. }
  17160. function getAxisExtentWithGap(axis) {
  17161. var extent = axis.getGlobalExtent();
  17162. if (axis.onBand) {
  17163. // Remove extra 1px to avoid line miter in clipped edge
  17164. var halfBandWidth = axis.getBandWidth() / 2 - 1;
  17165. var dir = extent[1] > extent[0] ? 1 : -1;
  17166. extent[0] += dir * halfBandWidth;
  17167. extent[1] -= dir * halfBandWidth;
  17168. }
  17169. return extent;
  17170. }
  17171. function sign(val) {
  17172. return val >= 0 ? 1 : -1;
  17173. }
  17174. /**
  17175. * @param {module:echarts/coord/cartesian/Cartesian2D|module:echarts/coord/polar/Polar} coordSys
  17176. * @param {module:echarts/data/List} data
  17177. * @param {Array.<Array.<number>>} points
  17178. * @private
  17179. */
  17180. function getStackedOnPoints(coordSys, data) {
  17181. var baseAxis = coordSys.getBaseAxis();
  17182. var valueAxis = coordSys.getOtherAxis(baseAxis);
  17183. var valueStart = baseAxis.onZero
  17184. ? 0 : valueAxis.scale.getExtent()[0];
  17185. var valueDim = valueAxis.dim;
  17186. var baseDataOffset = valueDim === 'x' || valueDim === 'radius' ? 1 : 0;
  17187. return data.mapArray([valueDim], function (val, idx) {
  17188. var stackedOnSameSign;
  17189. var stackedOn = data.stackedOn;
  17190. // Find first stacked value with same sign
  17191. while (stackedOn &&
  17192. sign(stackedOn.get(valueDim, idx)) === sign(val)
  17193. ) {
  17194. stackedOnSameSign = stackedOn;
  17195. break;
  17196. }
  17197. var stackedData = [];
  17198. stackedData[baseDataOffset] = data.get(baseAxis.dim, idx);
  17199. stackedData[1 - baseDataOffset] = stackedOnSameSign
  17200. ? stackedOnSameSign.get(valueDim, idx, true) : valueStart;
  17201. return coordSys.dataToPoint(stackedData);
  17202. }, true);
  17203. }
  17204. function queryDataIndex(data, payload) {
  17205. if (payload.dataIndex != null) {
  17206. return payload.dataIndex;
  17207. }
  17208. else if (payload.name != null) {
  17209. return data.indexOfName(payload.name);
  17210. }
  17211. }
  17212. function createGridClipShape(cartesian, hasAnimation, seriesModel) {
  17213. var xExtent = getAxisExtentWithGap(cartesian.getAxis('x'));
  17214. var yExtent = getAxisExtentWithGap(cartesian.getAxis('y'));
  17215. var isHorizontal = cartesian.getBaseAxis().isHorizontal();
  17216. var x = Math.min(xExtent[0], xExtent[1]);
  17217. var y = Math.min(yExtent[0], yExtent[1]);
  17218. var width = Math.max(xExtent[0], xExtent[1]) - x;
  17219. var height = Math.max(yExtent[0], yExtent[1]) - y;
  17220. var lineWidth = seriesModel.get('lineStyle.normal.width') || 2;
  17221. // Expand clip shape to avoid clipping when line value exceeds axis
  17222. var expandSize = seriesModel.get('clipOverflow') ? lineWidth / 2 : Math.max(width, height);
  17223. if (isHorizontal) {
  17224. y -= expandSize;
  17225. height += expandSize * 2;
  17226. }
  17227. else {
  17228. x -= expandSize;
  17229. width += expandSize * 2;
  17230. }
  17231. var clipPath = new graphic.Rect({
  17232. shape: {
  17233. x: x,
  17234. y: y,
  17235. width: width,
  17236. height: height
  17237. }
  17238. });
  17239. if (hasAnimation) {
  17240. clipPath.shape[isHorizontal ? 'width' : 'height'] = 0;
  17241. graphic.initProps(clipPath, {
  17242. shape: {
  17243. width: width,
  17244. height: height
  17245. }
  17246. }, seriesModel);
  17247. }
  17248. return clipPath;
  17249. }
  17250. function createPolarClipShape(polar, hasAnimation, seriesModel) {
  17251. var angleAxis = polar.getAngleAxis();
  17252. var radiusAxis = polar.getRadiusAxis();
  17253. var radiusExtent = radiusAxis.getExtent();
  17254. var angleExtent = angleAxis.getExtent();
  17255. var RADIAN = Math.PI / 180;
  17256. var clipPath = new graphic.Sector({
  17257. shape: {
  17258. cx: polar.cx,
  17259. cy: polar.cy,
  17260. r0: radiusExtent[0],
  17261. r: radiusExtent[1],
  17262. startAngle: -angleExtent[0] * RADIAN,
  17263. endAngle: -angleExtent[1] * RADIAN,
  17264. clockwise: angleAxis.inverse
  17265. }
  17266. });
  17267. if (hasAnimation) {
  17268. clipPath.shape.endAngle = -angleExtent[0] * RADIAN;
  17269. graphic.initProps(clipPath, {
  17270. shape: {
  17271. endAngle: -angleExtent[1] * RADIAN
  17272. }
  17273. }, seriesModel);
  17274. }
  17275. return clipPath;
  17276. }
  17277. function createClipShape(coordSys, hasAnimation, seriesModel) {
  17278. return coordSys.type === 'polar'
  17279. ? createPolarClipShape(coordSys, hasAnimation, seriesModel)
  17280. : createGridClipShape(coordSys, hasAnimation, seriesModel);
  17281. }
  17282. module.exports = ChartView.extend({
  17283. type: 'line',
  17284. init: function () {
  17285. var lineGroup = new graphic.Group();
  17286. var symbolDraw = new SymbolDraw();
  17287. this.group.add(symbolDraw.group);
  17288. this._symbolDraw = symbolDraw;
  17289. this._lineGroup = lineGroup;
  17290. },
  17291. render: function (seriesModel, ecModel, api) {
  17292. var coordSys = seriesModel.coordinateSystem;
  17293. var group = this.group;
  17294. var data = seriesModel.getData();
  17295. var lineStyleModel = seriesModel.getModel('lineStyle.normal');
  17296. var areaStyleModel = seriesModel.getModel('areaStyle.normal');
  17297. var points = data.mapArray(data.getItemLayout, true);
  17298. var isCoordSysPolar = coordSys.type === 'polar';
  17299. var prevCoordSys = this._coordSys;
  17300. var symbolDraw = this._symbolDraw;
  17301. var polyline = this._polyline;
  17302. var polygon = this._polygon;
  17303. var lineGroup = this._lineGroup;
  17304. var hasAnimation = seriesModel.get('animation');
  17305. var isAreaChart = !areaStyleModel.isEmpty();
  17306. var stackedOnPoints = getStackedOnPoints(coordSys, data);
  17307. var showSymbol = seriesModel.get('showSymbol');
  17308. var isSymbolIgnore = showSymbol && !isCoordSysPolar && !seriesModel.get('showAllSymbol')
  17309. && this._getSymbolIgnoreFunc(data, coordSys);
  17310. // Remove temporary symbols
  17311. var oldData = this._data;
  17312. oldData && oldData.eachItemGraphicEl(function (el, idx) {
  17313. if (el.__temp) {
  17314. group.remove(el);
  17315. oldData.setItemGraphicEl(idx, null);
  17316. }
  17317. });
  17318. // Remove previous created symbols if showSymbol changed to false
  17319. if (!showSymbol) {
  17320. symbolDraw.remove();
  17321. }
  17322. group.add(lineGroup);
  17323. // Initialization animation or coordinate system changed
  17324. if (
  17325. !(polyline && prevCoordSys.type === coordSys.type)
  17326. ) {
  17327. showSymbol && symbolDraw.updateData(data, isSymbolIgnore);
  17328. polyline = this._newPolyline(points, coordSys, hasAnimation);
  17329. if (isAreaChart) {
  17330. polygon = this._newPolygon(
  17331. points, stackedOnPoints,
  17332. coordSys, hasAnimation
  17333. );
  17334. }
  17335. lineGroup.setClipPath(createClipShape(coordSys, true, seriesModel));
  17336. }
  17337. else {
  17338. if (isAreaChart && !polygon) {
  17339. // If areaStyle is added
  17340. polygon = this._newPolygon(
  17341. points, stackedOnPoints,
  17342. coordSys, hasAnimation
  17343. );
  17344. }
  17345. else if (polygon && !isAreaChart) {
  17346. // If areaStyle is removed
  17347. lineGroup.remove(polygon);
  17348. polygon = this._polygon = null;
  17349. }
  17350. // Update clipPath
  17351. lineGroup.setClipPath(createClipShape(coordSys, false, seriesModel));
  17352. // Always update, or it is wrong in the case turning on legend
  17353. // because points are not changed
  17354. showSymbol && symbolDraw.updateData(data, isSymbolIgnore);
  17355. // Stop symbol animation and sync with line points
  17356. // FIXME performance?
  17357. data.eachItemGraphicEl(function (el) {
  17358. el.stopAnimation(true);
  17359. });
  17360. // In the case data zoom triggerred refreshing frequently
  17361. // Data may not change if line has a category axis. So it should animate nothing
  17362. if (!isPointsSame(this._stackedOnPoints, stackedOnPoints)
  17363. || !isPointsSame(this._points, points)
  17364. ) {
  17365. if (hasAnimation) {
  17366. this._updateAnimation(
  17367. data, stackedOnPoints, coordSys, api
  17368. );
  17369. }
  17370. else {
  17371. polyline.setShape({
  17372. points: points
  17373. });
  17374. polygon && polygon.setShape({
  17375. points: points,
  17376. stackedOnPoints: stackedOnPoints
  17377. });
  17378. }
  17379. }
  17380. }
  17381. polyline.useStyle(zrUtil.defaults(
  17382. // Use color in lineStyle first
  17383. lineStyleModel.getLineStyle(),
  17384. {
  17385. fill: 'none',
  17386. stroke: data.getVisual('color'),
  17387. lineJoin: 'bevel'
  17388. }
  17389. ));
  17390. var smooth = seriesModel.get('smooth');
  17391. smooth = getSmooth(seriesModel.get('smooth'));
  17392. polyline.setShape({
  17393. smooth: smooth,
  17394. smoothMonotone: seriesModel.get('smoothMonotone'),
  17395. connectNulls: seriesModel.get('connectNulls')
  17396. });
  17397. if (polygon) {
  17398. var stackedOn = data.stackedOn;
  17399. var stackedOnSmooth = 0;
  17400. polygon.useStyle(zrUtil.defaults(
  17401. areaStyleModel.getAreaStyle(),
  17402. {
  17403. fill: data.getVisual('color'),
  17404. opacity: 0.7,
  17405. lineJoin: 'bevel'
  17406. }
  17407. ));
  17408. if (stackedOn) {
  17409. var stackedOnSeries = stackedOn.hostModel;
  17410. stackedOnSmooth = getSmooth(stackedOnSeries.get('smooth'));
  17411. }
  17412. polygon.setShape({
  17413. smooth: smooth,
  17414. stackedOnSmooth: stackedOnSmooth,
  17415. smoothMonotone: seriesModel.get('smoothMonotone'),
  17416. connectNulls: seriesModel.get('connectNulls')
  17417. });
  17418. }
  17419. this._data = data;
  17420. // Save the coordinate system for transition animation when data changed
  17421. this._coordSys = coordSys;
  17422. this._stackedOnPoints = stackedOnPoints;
  17423. this._points = points;
  17424. },
  17425. highlight: function (seriesModel, ecModel, api, payload) {
  17426. var data = seriesModel.getData();
  17427. var dataIndex = queryDataIndex(data, payload);
  17428. if (dataIndex != null && dataIndex >= 0) {
  17429. var symbol = data.getItemGraphicEl(dataIndex);
  17430. if (!symbol) {
  17431. // Create a temporary symbol if it is not exists
  17432. var pt = data.getItemLayout(dataIndex);
  17433. symbol = new Symbol(data, dataIndex, api);
  17434. symbol.position = pt;
  17435. symbol.setZ(
  17436. seriesModel.get('zlevel'),
  17437. seriesModel.get('z')
  17438. );
  17439. symbol.ignore = isNaN(pt[0]) || isNaN(pt[1]);
  17440. symbol.__temp = true;
  17441. data.setItemGraphicEl(dataIndex, symbol);
  17442. // Stop scale animation
  17443. symbol.stopSymbolAnimation(true);
  17444. this.group.add(symbol);
  17445. }
  17446. symbol.highlight();
  17447. }
  17448. else {
  17449. // Highlight whole series
  17450. ChartView.prototype.highlight.call(
  17451. this, seriesModel, ecModel, api, payload
  17452. );
  17453. }
  17454. },
  17455. downplay: function (seriesModel, ecModel, api, payload) {
  17456. var data = seriesModel.getData();
  17457. var dataIndex = queryDataIndex(data, payload);
  17458. if (dataIndex != null && dataIndex >= 0) {
  17459. var symbol = data.getItemGraphicEl(dataIndex);
  17460. if (symbol) {
  17461. if (symbol.__temp) {
  17462. data.setItemGraphicEl(dataIndex, null);
  17463. this.group.remove(symbol);
  17464. }
  17465. else {
  17466. symbol.downplay();
  17467. }
  17468. }
  17469. }
  17470. else {
  17471. // Downplay whole series
  17472. ChartView.prototype.downplay.call(
  17473. this, seriesModel, ecModel, api, payload
  17474. );
  17475. }
  17476. },
  17477. /**
  17478. * @param {module:zrender/container/Group} group
  17479. * @param {Array.<Array.<number>>} points
  17480. * @private
  17481. */
  17482. _newPolyline: function (points) {
  17483. var polyline = this._polyline;
  17484. // Remove previous created polyline
  17485. if (polyline) {
  17486. this._lineGroup.remove(polyline);
  17487. }
  17488. polyline = new polyHelper.Polyline({
  17489. shape: {
  17490. points: points
  17491. },
  17492. silent: true,
  17493. z2: 10
  17494. });
  17495. this._lineGroup.add(polyline);
  17496. this._polyline = polyline;
  17497. return polyline;
  17498. },
  17499. /**
  17500. * @param {module:zrender/container/Group} group
  17501. * @param {Array.<Array.<number>>} stackedOnPoints
  17502. * @param {Array.<Array.<number>>} points
  17503. * @private
  17504. */
  17505. _newPolygon: function (points, stackedOnPoints) {
  17506. var polygon = this._polygon;
  17507. // Remove previous created polygon
  17508. if (polygon) {
  17509. this._lineGroup.remove(polygon);
  17510. }
  17511. polygon = new polyHelper.Polygon({
  17512. shape: {
  17513. points: points,
  17514. stackedOnPoints: stackedOnPoints
  17515. },
  17516. silent: true
  17517. });
  17518. this._lineGroup.add(polygon);
  17519. this._polygon = polygon;
  17520. return polygon;
  17521. },
  17522. /**
  17523. * @private
  17524. */
  17525. _getSymbolIgnoreFunc: function (data, coordSys) {
  17526. var categoryAxis = coordSys.getAxesByScale('ordinal')[0];
  17527. // `getLabelInterval` is provided by echarts/component/axis
  17528. if (categoryAxis && categoryAxis.isLabelIgnored) {
  17529. return zrUtil.bind(categoryAxis.isLabelIgnored, categoryAxis);
  17530. }
  17531. },
  17532. /**
  17533. * @private
  17534. */
  17535. // FIXME Two value axis
  17536. _updateAnimation: function (data, stackedOnPoints, coordSys, api) {
  17537. var polyline = this._polyline;
  17538. var polygon = this._polygon;
  17539. var seriesModel = data.hostModel;
  17540. var diff = lineAnimationDiff(
  17541. this._data, data,
  17542. this._stackedOnPoints, stackedOnPoints,
  17543. this._coordSys, coordSys
  17544. );
  17545. polyline.shape.points = diff.current;
  17546. graphic.updateProps(polyline, {
  17547. shape: {
  17548. points: diff.next
  17549. }
  17550. }, seriesModel);
  17551. if (polygon) {
  17552. polygon.setShape({
  17553. points: diff.current,
  17554. stackedOnPoints: diff.stackedOnCurrent
  17555. });
  17556. graphic.updateProps(polygon, {
  17557. shape: {
  17558. points: diff.next,
  17559. stackedOnPoints: diff.stackedOnNext
  17560. }
  17561. }, seriesModel);
  17562. }
  17563. var updatedDataInfo = [];
  17564. var diffStatus = diff.status;
  17565. for (var i = 0; i < diffStatus.length; i++) {
  17566. var cmd = diffStatus[i].cmd;
  17567. if (cmd === '=') {
  17568. var el = data.getItemGraphicEl(diffStatus[i].idx1);
  17569. if (el) {
  17570. updatedDataInfo.push({
  17571. el: el,
  17572. ptIdx: i // Index of points
  17573. });
  17574. }
  17575. }
  17576. }
  17577. if (polyline.animators && polyline.animators.length) {
  17578. polyline.animators[0].during(function () {
  17579. for (var i = 0; i < updatedDataInfo.length; i++) {
  17580. var el = updatedDataInfo[i].el;
  17581. el.attr('position', polyline.shape.points[updatedDataInfo[i].ptIdx]);
  17582. }
  17583. });
  17584. }
  17585. },
  17586. remove: function (ecModel) {
  17587. var group = this.group;
  17588. var oldData = this._data;
  17589. this._lineGroup.removeAll();
  17590. this._symbolDraw.remove(true);
  17591. // Remove temporary created elements when highlighting
  17592. oldData && oldData.eachItemGraphicEl(function (el, idx) {
  17593. if (el.__temp) {
  17594. group.remove(el);
  17595. oldData.setItemGraphicEl(idx, null);
  17596. }
  17597. });
  17598. this._polyline =
  17599. this._polygon =
  17600. this._coordSys =
  17601. this._points =
  17602. this._stackedOnPoints =
  17603. this._data = null;
  17604. }
  17605. });
  17606. /***/ },
  17607. /* 99 */
  17608. /***/ function(module, exports, __webpack_require__) {
  17609. /**
  17610. * @module echarts/chart/helper/SymbolDraw
  17611. */
  17612. var graphic = __webpack_require__(42);
  17613. var Symbol = __webpack_require__(100);
  17614. /**
  17615. * @constructor
  17616. * @alias module:echarts/chart/helper/SymbolDraw
  17617. * @param {module:zrender/graphic/Group} [symbolCtor]
  17618. */
  17619. function SymbolDraw(symbolCtor) {
  17620. this.group = new graphic.Group();
  17621. this._symbolCtor = symbolCtor || Symbol;
  17622. }
  17623. var symbolDrawProto = SymbolDraw.prototype;
  17624. function symbolNeedsDraw(data, idx, isIgnore) {
  17625. var point = data.getItemLayout(idx);
  17626. return point && !isNaN(point[0]) && !isNaN(point[1]) && !(isIgnore && isIgnore(idx))
  17627. && data.getItemVisual(idx, 'symbol') !== 'none';
  17628. }
  17629. /**
  17630. * Update symbols draw by new data
  17631. * @param {module:echarts/data/List} data
  17632. * @param {Array.<boolean>} [isIgnore]
  17633. */
  17634. symbolDrawProto.updateData = function (data, isIgnore) {
  17635. var group = this.group;
  17636. var seriesModel = data.hostModel;
  17637. var oldData = this._data;
  17638. var SymbolCtor = this._symbolCtor;
  17639. data.diff(oldData)
  17640. .add(function (newIdx) {
  17641. var point = data.getItemLayout(newIdx);
  17642. if (symbolNeedsDraw(data, newIdx, isIgnore)) {
  17643. var symbolEl = new SymbolCtor(data, newIdx);
  17644. symbolEl.attr('position', point);
  17645. data.setItemGraphicEl(newIdx, symbolEl);
  17646. group.add(symbolEl);
  17647. }
  17648. })
  17649. .update(function (newIdx, oldIdx) {
  17650. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  17651. var point = data.getItemLayout(newIdx);
  17652. if (!symbolNeedsDraw(data, newIdx, isIgnore)) {
  17653. group.remove(symbolEl);
  17654. return;
  17655. }
  17656. if (!symbolEl) {
  17657. symbolEl = new SymbolCtor(data, newIdx);
  17658. symbolEl.attr('position', point);
  17659. }
  17660. else {
  17661. symbolEl.updateData(data, newIdx);
  17662. graphic.updateProps(symbolEl, {
  17663. position: point
  17664. }, seriesModel);
  17665. }
  17666. // Add back
  17667. group.add(symbolEl);
  17668. data.setItemGraphicEl(newIdx, symbolEl);
  17669. })
  17670. .remove(function (oldIdx) {
  17671. var el = oldData.getItemGraphicEl(oldIdx);
  17672. el && el.fadeOut(function () {
  17673. group.remove(el);
  17674. });
  17675. })
  17676. .execute();
  17677. this._data = data;
  17678. };
  17679. symbolDrawProto.updateLayout = function () {
  17680. var data = this._data;
  17681. if (data) {
  17682. // Not use animation
  17683. data.eachItemGraphicEl(function (el, idx) {
  17684. el.attr('position', data.getItemLayout(idx));
  17685. });
  17686. }
  17687. };
  17688. symbolDrawProto.remove = function (enableAnimation) {
  17689. var group = this.group;
  17690. var data = this._data;
  17691. if (data) {
  17692. if (enableAnimation) {
  17693. data.eachItemGraphicEl(function (el) {
  17694. el.fadeOut(function () {
  17695. group.remove(el);
  17696. });
  17697. });
  17698. }
  17699. else {
  17700. group.removeAll();
  17701. }
  17702. }
  17703. };
  17704. module.exports = SymbolDraw;
  17705. /***/ },
  17706. /* 100 */
  17707. /***/ function(module, exports, __webpack_require__) {
  17708. /**
  17709. * @module echarts/chart/helper/Symbol
  17710. */
  17711. var zrUtil = __webpack_require__(3);
  17712. var symbolUtil = __webpack_require__(101);
  17713. var graphic = __webpack_require__(42);
  17714. var numberUtil = __webpack_require__(7);
  17715. function normalizeSymbolSize(symbolSize) {
  17716. if (!zrUtil.isArray(symbolSize)) {
  17717. symbolSize = [+symbolSize, +symbolSize];
  17718. }
  17719. return symbolSize;
  17720. }
  17721. /**
  17722. * @constructor
  17723. * @alias {module:echarts/chart/helper/Symbol}
  17724. * @param {module:echarts/data/List} data
  17725. * @param {number} idx
  17726. * @extends {module:zrender/graphic/Group}
  17727. */
  17728. function Symbol(data, idx) {
  17729. graphic.Group.call(this);
  17730. this.updateData(data, idx);
  17731. }
  17732. var symbolProto = Symbol.prototype;
  17733. function driftSymbol(dx, dy) {
  17734. this.parent.drift(dx, dy);
  17735. }
  17736. symbolProto._createSymbol = function (symbolType, data, idx) {
  17737. // Remove paths created before
  17738. this.removeAll();
  17739. var seriesModel = data.hostModel;
  17740. var color = data.getItemVisual(idx, 'color');
  17741. var symbolPath = symbolUtil.createSymbol(
  17742. symbolType, -0.5, -0.5, 1, 1, color
  17743. );
  17744. symbolPath.attr({
  17745. z2: 100,
  17746. culling: true,
  17747. scale: [0, 0]
  17748. });
  17749. // Rewrite drift method
  17750. symbolPath.drift = driftSymbol;
  17751. var size = normalizeSymbolSize(data.getItemVisual(idx, 'symbolSize'));
  17752. graphic.initProps(symbolPath, {
  17753. scale: size
  17754. }, seriesModel, idx);
  17755. this._symbolType = symbolType;
  17756. this.add(symbolPath);
  17757. };
  17758. /**
  17759. * Stop animation
  17760. * @param {boolean} toLastFrame
  17761. */
  17762. symbolProto.stopSymbolAnimation = function (toLastFrame) {
  17763. this.childAt(0).stopAnimation(toLastFrame);
  17764. };
  17765. /**
  17766. * Get scale(aka, current symbol size).
  17767. * Including the change caused by animation
  17768. */
  17769. symbolProto.getScale = function () {
  17770. return this.childAt(0).scale;
  17771. };
  17772. /**
  17773. * Highlight symbol
  17774. */
  17775. symbolProto.highlight = function () {
  17776. this.childAt(0).trigger('emphasis');
  17777. };
  17778. /**
  17779. * Downplay symbol
  17780. */
  17781. symbolProto.downplay = function () {
  17782. this.childAt(0).trigger('normal');
  17783. };
  17784. /**
  17785. * @param {number} zlevel
  17786. * @param {number} z
  17787. */
  17788. symbolProto.setZ = function (zlevel, z) {
  17789. var symbolPath = this.childAt(0);
  17790. symbolPath.zlevel = zlevel;
  17791. symbolPath.z = z;
  17792. };
  17793. symbolProto.setDraggable = function (draggable) {
  17794. var symbolPath = this.childAt(0);
  17795. symbolPath.draggable = draggable;
  17796. symbolPath.cursor = draggable ? 'move' : 'pointer';
  17797. };
  17798. /**
  17799. * Update symbol properties
  17800. * @param {module:echarts/data/List} data
  17801. * @param {number} idx
  17802. */
  17803. symbolProto.updateData = function (data, idx) {
  17804. var symbolType = data.getItemVisual(idx, 'symbol') || 'circle';
  17805. var seriesModel = data.hostModel;
  17806. var symbolSize = normalizeSymbolSize(data.getItemVisual(idx, 'symbolSize'));
  17807. if (symbolType !== this._symbolType) {
  17808. this._createSymbol(symbolType, data, idx);
  17809. }
  17810. else {
  17811. var symbolPath = this.childAt(0);
  17812. graphic.updateProps(symbolPath, {
  17813. scale: symbolSize
  17814. }, seriesModel, idx);
  17815. }
  17816. this._updateCommon(data, idx, symbolSize);
  17817. this._seriesModel = seriesModel;
  17818. };
  17819. // Update common properties
  17820. var normalStyleAccessPath = ['itemStyle', 'normal'];
  17821. var emphasisStyleAccessPath = ['itemStyle', 'emphasis'];
  17822. var normalLabelAccessPath = ['label', 'normal'];
  17823. var emphasisLabelAccessPath = ['label', 'emphasis'];
  17824. symbolProto._updateCommon = function (data, idx, symbolSize) {
  17825. var symbolPath = this.childAt(0);
  17826. var seriesModel = data.hostModel;
  17827. var itemModel = data.getItemModel(idx);
  17828. var normalItemStyleModel = itemModel.getModel(normalStyleAccessPath);
  17829. var color = data.getItemVisual(idx, 'color');
  17830. // Reset style
  17831. if (symbolPath.type !== 'image') {
  17832. symbolPath.useStyle({
  17833. strokeNoScale: true
  17834. });
  17835. }
  17836. var elStyle = symbolPath.style;
  17837. var hoverStyle = itemModel.getModel(emphasisStyleAccessPath).getItemStyle();
  17838. symbolPath.rotation = (itemModel.getShallow('symbolRotate') || 0) * Math.PI / 180 || 0;
  17839. var symbolOffset = itemModel.getShallow('symbolOffset');
  17840. if (symbolOffset) {
  17841. var pos = symbolPath.position;
  17842. pos[0] = numberUtil.parsePercent(symbolOffset[0], symbolSize[0]);
  17843. pos[1] = numberUtil.parsePercent(symbolOffset[1], symbolSize[1]);
  17844. }
  17845. symbolPath.setColor(color);
  17846. zrUtil.extend(
  17847. elStyle,
  17848. // Color must be excluded.
  17849. // Because symbol provide setColor individually to set fill and stroke
  17850. normalItemStyleModel.getItemStyle(['color'])
  17851. );
  17852. var opacity = data.getItemVisual(idx, 'opacity');
  17853. if (opacity != null) {
  17854. elStyle.opacity = opacity;
  17855. }
  17856. var labelModel = itemModel.getModel(normalLabelAccessPath);
  17857. var hoverLabelModel = itemModel.getModel(emphasisLabelAccessPath);
  17858. // Get last value dim
  17859. var dimensions = data.dimensions.slice();
  17860. var valueDim;
  17861. var dataType;
  17862. while (dimensions.length && (
  17863. valueDim = dimensions.pop(),
  17864. dataType = data.getDimensionInfo(valueDim).type,
  17865. dataType === 'ordinal' || dataType === 'time'
  17866. )) {} // jshint ignore:line
  17867. if (valueDim != null && labelModel.get('show')) {
  17868. graphic.setText(elStyle, labelModel, color);
  17869. elStyle.text = zrUtil.retrieve(
  17870. seriesModel.getFormattedLabel(idx, 'normal'),
  17871. data.get(valueDim, idx)
  17872. );
  17873. }
  17874. else {
  17875. elStyle.text = '';
  17876. }
  17877. if (valueDim != null && hoverLabelModel.getShallow('show')) {
  17878. graphic.setText(hoverStyle, hoverLabelModel, color);
  17879. hoverStyle.text = zrUtil.retrieve(
  17880. seriesModel.getFormattedLabel(idx, 'emphasis'),
  17881. data.get(valueDim, idx)
  17882. );
  17883. }
  17884. else {
  17885. hoverStyle.text = '';
  17886. }
  17887. var size = normalizeSymbolSize(data.getItemVisual(idx, 'symbolSize'));
  17888. symbolPath.off('mouseover')
  17889. .off('mouseout')
  17890. .off('emphasis')
  17891. .off('normal');
  17892. graphic.setHoverStyle(symbolPath, hoverStyle);
  17893. if (itemModel.getShallow('hoverAnimation')) {
  17894. var onEmphasis = function() {
  17895. var ratio = size[1] / size[0];
  17896. this.animateTo({
  17897. scale: [
  17898. Math.max(size[0] * 1.1, size[0] + 3),
  17899. Math.max(size[1] * 1.1, size[1] + 3 * ratio)
  17900. ]
  17901. }, 400, 'elasticOut');
  17902. };
  17903. var onNormal = function() {
  17904. this.animateTo({
  17905. scale: size
  17906. }, 400, 'elasticOut');
  17907. };
  17908. symbolPath.on('mouseover', onEmphasis)
  17909. .on('mouseout', onNormal)
  17910. .on('emphasis', onEmphasis)
  17911. .on('normal', onNormal);
  17912. }
  17913. };
  17914. symbolProto.fadeOut = function (cb) {
  17915. var symbolPath = this.childAt(0);
  17916. // Avoid trigger hoverAnimation when fading
  17917. symbolPath.off('mouseover')
  17918. .off('mouseout')
  17919. .off('emphasis')
  17920. .off('normal');
  17921. // Not show text when animating
  17922. symbolPath.style.text = '';
  17923. graphic.updateProps(symbolPath, {
  17924. scale: [0, 0]
  17925. }, this._seriesModel, this.dataIndex, cb);
  17926. };
  17927. zrUtil.inherits(Symbol, graphic.Group);
  17928. module.exports = Symbol;
  17929. /***/ },
  17930. /* 101 */
  17931. /***/ function(module, exports, __webpack_require__) {
  17932. 'use strict';
  17933. // Symbol factory
  17934. var graphic = __webpack_require__(42);
  17935. var BoundingRect = __webpack_require__(15);
  17936. /**
  17937. * Triangle shape
  17938. * @inner
  17939. */
  17940. var Triangle = graphic.extendShape({
  17941. type: 'triangle',
  17942. shape: {
  17943. cx: 0,
  17944. cy: 0,
  17945. width: 0,
  17946. height: 0
  17947. },
  17948. buildPath: function (path, shape) {
  17949. var cx = shape.cx;
  17950. var cy = shape.cy;
  17951. var width = shape.width / 2;
  17952. var height = shape.height / 2;
  17953. path.moveTo(cx, cy - height);
  17954. path.lineTo(cx + width, cy + height);
  17955. path.lineTo(cx - width, cy + height);
  17956. path.closePath();
  17957. }
  17958. });
  17959. /**
  17960. * Diamond shape
  17961. * @inner
  17962. */
  17963. var Diamond = graphic.extendShape({
  17964. type: 'diamond',
  17965. shape: {
  17966. cx: 0,
  17967. cy: 0,
  17968. width: 0,
  17969. height: 0
  17970. },
  17971. buildPath: function (path, shape) {
  17972. var cx = shape.cx;
  17973. var cy = shape.cy;
  17974. var width = shape.width / 2;
  17975. var height = shape.height / 2;
  17976. path.moveTo(cx, cy - height);
  17977. path.lineTo(cx + width, cy);
  17978. path.lineTo(cx, cy + height);
  17979. path.lineTo(cx - width, cy);
  17980. path.closePath();
  17981. }
  17982. });
  17983. /**
  17984. * Pin shape
  17985. * @inner
  17986. */
  17987. var Pin = graphic.extendShape({
  17988. type: 'pin',
  17989. shape: {
  17990. // x, y on the cusp
  17991. x: 0,
  17992. y: 0,
  17993. width: 0,
  17994. height: 0
  17995. },
  17996. buildPath: function (path, shape) {
  17997. var x = shape.x;
  17998. var y = shape.y;
  17999. var w = shape.width / 5 * 3;
  18000. // Height must be larger than width
  18001. var h = Math.max(w, shape.height);
  18002. var r = w / 2;
  18003. // Dist on y with tangent point and circle center
  18004. var dy = r * r / (h - r);
  18005. var cy = y - h + r + dy;
  18006. var angle = Math.asin(dy / r);
  18007. // Dist on x with tangent point and circle center
  18008. var dx = Math.cos(angle) * r;
  18009. var tanX = Math.sin(angle);
  18010. var tanY = Math.cos(angle);
  18011. path.arc(
  18012. x, cy, r,
  18013. Math.PI - angle,
  18014. Math.PI * 2 + angle
  18015. );
  18016. var cpLen = r * 0.6;
  18017. var cpLen2 = r * 0.7;
  18018. path.bezierCurveTo(
  18019. x + dx - tanX * cpLen, cy + dy + tanY * cpLen,
  18020. x, y - cpLen2,
  18021. x, y
  18022. );
  18023. path.bezierCurveTo(
  18024. x, y - cpLen2,
  18025. x - dx + tanX * cpLen, cy + dy + tanY * cpLen,
  18026. x - dx, cy + dy
  18027. );
  18028. path.closePath();
  18029. }
  18030. });
  18031. /**
  18032. * Arrow shape
  18033. * @inner
  18034. */
  18035. var Arrow = graphic.extendShape({
  18036. type: 'arrow',
  18037. shape: {
  18038. x: 0,
  18039. y: 0,
  18040. width: 0,
  18041. height: 0
  18042. },
  18043. buildPath: function (ctx, shape) {
  18044. var height = shape.height;
  18045. var width = shape.width;
  18046. var x = shape.x;
  18047. var y = shape.y;
  18048. var dx = width / 3 * 2;
  18049. ctx.moveTo(x, y);
  18050. ctx.lineTo(x + dx, y + height);
  18051. ctx.lineTo(x, y + height / 4 * 3);
  18052. ctx.lineTo(x - dx, y + height);
  18053. ctx.lineTo(x, y);
  18054. ctx.closePath();
  18055. }
  18056. });
  18057. /**
  18058. * Map of path contructors
  18059. * @type {Object.<string, module:zrender/graphic/Path>}
  18060. */
  18061. var symbolCtors = {
  18062. line: graphic.Line,
  18063. rect: graphic.Rect,
  18064. roundRect: graphic.Rect,
  18065. square: graphic.Rect,
  18066. circle: graphic.Circle,
  18067. diamond: Diamond,
  18068. pin: Pin,
  18069. arrow: Arrow,
  18070. triangle: Triangle
  18071. };
  18072. var symbolShapeMakers = {
  18073. line: function (x, y, w, h, shape) {
  18074. // FIXME
  18075. shape.x1 = x;
  18076. shape.y1 = y + h / 2;
  18077. shape.x2 = x + w;
  18078. shape.y2 = y + h / 2;
  18079. },
  18080. rect: function (x, y, w, h, shape) {
  18081. shape.x = x;
  18082. shape.y = y;
  18083. shape.width = w;
  18084. shape.height = h;
  18085. },
  18086. roundRect: function (x, y, w, h, shape) {
  18087. shape.x = x;
  18088. shape.y = y;
  18089. shape.width = w;
  18090. shape.height = h;
  18091. shape.r = Math.min(w, h) / 4;
  18092. },
  18093. square: function (x, y, w, h, shape) {
  18094. var size = Math.min(w, h);
  18095. shape.x = x;
  18096. shape.y = y;
  18097. shape.width = size;
  18098. shape.height = size;
  18099. },
  18100. circle: function (x, y, w, h, shape) {
  18101. // Put circle in the center of square
  18102. shape.cx = x + w / 2;
  18103. shape.cy = y + h / 2;
  18104. shape.r = Math.min(w, h) / 2;
  18105. },
  18106. diamond: function (x, y, w, h, shape) {
  18107. shape.cx = x + w / 2;
  18108. shape.cy = y + h / 2;
  18109. shape.width = w;
  18110. shape.height = h;
  18111. },
  18112. pin: function (x, y, w, h, shape) {
  18113. shape.x = x + w / 2;
  18114. shape.y = y + h / 2;
  18115. shape.width = w;
  18116. shape.height = h;
  18117. },
  18118. arrow: function (x, y, w, h, shape) {
  18119. shape.x = x + w / 2;
  18120. shape.y = y + h / 2;
  18121. shape.width = w;
  18122. shape.height = h;
  18123. },
  18124. triangle: function (x, y, w, h, shape) {
  18125. shape.cx = x + w / 2;
  18126. shape.cy = y + h / 2;
  18127. shape.width = w;
  18128. shape.height = h;
  18129. }
  18130. };
  18131. var symbolBuildProxies = {};
  18132. for (var name in symbolCtors) {
  18133. symbolBuildProxies[name] = new symbolCtors[name]();
  18134. }
  18135. var Symbol = graphic.extendShape({
  18136. type: 'symbol',
  18137. shape: {
  18138. symbolType: '',
  18139. x: 0,
  18140. y: 0,
  18141. width: 0,
  18142. height: 0
  18143. },
  18144. beforeBrush: function () {
  18145. var style = this.style;
  18146. var shape = this.shape;
  18147. // FIXME
  18148. if (shape.symbolType === 'pin' && style.textPosition === 'inside') {
  18149. style.textPosition = ['50%', '40%'];
  18150. style.textAlign = 'center';
  18151. style.textVerticalAlign = 'middle';
  18152. }
  18153. },
  18154. buildPath: function (ctx, shape) {
  18155. var symbolType = shape.symbolType;
  18156. var proxySymbol = symbolBuildProxies[symbolType];
  18157. if (shape.symbolType !== 'none') {
  18158. if (!proxySymbol) {
  18159. // Default rect
  18160. symbolType = 'rect';
  18161. proxySymbol = symbolBuildProxies[symbolType];
  18162. }
  18163. symbolShapeMakers[symbolType](
  18164. shape.x, shape.y, shape.width, shape.height, proxySymbol.shape
  18165. );
  18166. proxySymbol.buildPath(ctx, proxySymbol.shape);
  18167. }
  18168. }
  18169. });
  18170. // Provide setColor helper method to avoid determine if set the fill or stroke outside
  18171. var symbolPathSetColor = function (color) {
  18172. if (this.type !== 'image') {
  18173. var symbolStyle = this.style;
  18174. var symbolShape = this.shape;
  18175. if (symbolShape && symbolShape.symbolType === 'line') {
  18176. symbolStyle.stroke = color;
  18177. }
  18178. else if (this.__isEmptyBrush) {
  18179. symbolStyle.stroke = color;
  18180. symbolStyle.fill = '#fff';
  18181. }
  18182. else {
  18183. // FIXME 判断图形默认是填充还是描边,使用 onlyStroke ?
  18184. symbolStyle.fill && (symbolStyle.fill = color);
  18185. symbolStyle.stroke && (symbolStyle.stroke = color);
  18186. }
  18187. this.dirty();
  18188. }
  18189. };
  18190. var symbolUtil = {
  18191. /**
  18192. * Create a symbol element with given symbol configuration: shape, x, y, width, height, color
  18193. * @param {string} symbolType
  18194. * @param {number} x
  18195. * @param {number} y
  18196. * @param {number} w
  18197. * @param {number} h
  18198. * @param {string} color
  18199. */
  18200. createSymbol: function (symbolType, x, y, w, h, color) {
  18201. var isEmpty = symbolType.indexOf('empty') === 0;
  18202. if (isEmpty) {
  18203. symbolType = symbolType.substr(5, 1).toLowerCase() + symbolType.substr(6);
  18204. }
  18205. var symbolPath;
  18206. if (symbolType.indexOf('image://') === 0) {
  18207. symbolPath = new graphic.Image({
  18208. style: {
  18209. image: symbolType.slice(8),
  18210. x: x,
  18211. y: y,
  18212. width: w,
  18213. height: h
  18214. }
  18215. });
  18216. }
  18217. else if (symbolType.indexOf('path://') === 0) {
  18218. symbolPath = graphic.makePath(symbolType.slice(7), {}, new BoundingRect(x, y, w, h));
  18219. }
  18220. else {
  18221. symbolPath = new Symbol({
  18222. shape: {
  18223. symbolType: symbolType,
  18224. x: x,
  18225. y: y,
  18226. width: w,
  18227. height: h
  18228. }
  18229. });
  18230. }
  18231. symbolPath.__isEmptyBrush = isEmpty;
  18232. symbolPath.setColor = symbolPathSetColor;
  18233. symbolPath.setColor(color);
  18234. return symbolPath;
  18235. }
  18236. };
  18237. module.exports = symbolUtil;
  18238. /***/ },
  18239. /* 102 */
  18240. /***/ function(module, exports) {
  18241. // var arrayDiff = require('zrender/lib/core/arrayDiff');
  18242. // 'zrender/core/arrayDiff' has been used before, but it did
  18243. // not do well in performance when roam with fixed dataZoom window.
  18244. function sign(val) {
  18245. return val >= 0 ? 1 : -1;
  18246. }
  18247. function getStackedOnPoint(coordSys, data, idx) {
  18248. var baseAxis = coordSys.getBaseAxis();
  18249. var valueAxis = coordSys.getOtherAxis(baseAxis);
  18250. var valueStart = baseAxis.onZero
  18251. ? 0 : valueAxis.scale.getExtent()[0];
  18252. var valueDim = valueAxis.dim;
  18253. var baseDataOffset = valueDim === 'x' || valueDim === 'radius' ? 1 : 0;
  18254. var stackedOnSameSign;
  18255. var stackedOn = data.stackedOn;
  18256. var val = data.get(valueDim, idx);
  18257. // Find first stacked value with same sign
  18258. while (stackedOn &&
  18259. sign(stackedOn.get(valueDim, idx)) === sign(val)
  18260. ) {
  18261. stackedOnSameSign = stackedOn;
  18262. break;
  18263. }
  18264. var stackedData = [];
  18265. stackedData[baseDataOffset] = data.get(baseAxis.dim, idx);
  18266. stackedData[1 - baseDataOffset] = stackedOnSameSign
  18267. ? stackedOnSameSign.get(valueDim, idx, true) : valueStart;
  18268. return coordSys.dataToPoint(stackedData);
  18269. }
  18270. // function convertToIntId(newIdList, oldIdList) {
  18271. // // Generate int id instead of string id.
  18272. // // Compare string maybe slow in score function of arrDiff
  18273. // // Assume id in idList are all unique
  18274. // var idIndicesMap = {};
  18275. // var idx = 0;
  18276. // for (var i = 0; i < newIdList.length; i++) {
  18277. // idIndicesMap[newIdList[i]] = idx;
  18278. // newIdList[i] = idx++;
  18279. // }
  18280. // for (var i = 0; i < oldIdList.length; i++) {
  18281. // var oldId = oldIdList[i];
  18282. // // Same with newIdList
  18283. // if (idIndicesMap[oldId]) {
  18284. // oldIdList[i] = idIndicesMap[oldId];
  18285. // }
  18286. // else {
  18287. // oldIdList[i] = idx++;
  18288. // }
  18289. // }
  18290. // }
  18291. function diffData(oldData, newData) {
  18292. var diffResult = [];
  18293. newData.diff(oldData)
  18294. .add(function (idx) {
  18295. diffResult.push({cmd: '+', idx: idx});
  18296. })
  18297. .update(function (newIdx, oldIdx) {
  18298. diffResult.push({cmd: '=', idx: oldIdx, idx1: newIdx});
  18299. })
  18300. .remove(function (idx) {
  18301. diffResult.push({cmd: '-', idx: idx});
  18302. })
  18303. .execute();
  18304. return diffResult;
  18305. }
  18306. module.exports = function (
  18307. oldData, newData,
  18308. oldStackedOnPoints, newStackedOnPoints,
  18309. oldCoordSys, newCoordSys
  18310. ) {
  18311. var diff = diffData(oldData, newData);
  18312. // var newIdList = newData.mapArray(newData.getId);
  18313. // var oldIdList = oldData.mapArray(oldData.getId);
  18314. // convertToIntId(newIdList, oldIdList);
  18315. // // FIXME One data ?
  18316. // diff = arrayDiff(oldIdList, newIdList);
  18317. var currPoints = [];
  18318. var nextPoints = [];
  18319. // Points for stacking base line
  18320. var currStackedPoints = [];
  18321. var nextStackedPoints = [];
  18322. var status = [];
  18323. var sortedIndices = [];
  18324. var rawIndices = [];
  18325. var dims = newCoordSys.dimensions;
  18326. for (var i = 0; i < diff.length; i++) {
  18327. var diffItem = diff[i];
  18328. var pointAdded = true;
  18329. // FIXME, animation is not so perfect when dataZoom window moves fast
  18330. // Which is in case remvoing or add more than one data in the tail or head
  18331. switch (diffItem.cmd) {
  18332. case '=':
  18333. var currentPt = oldData.getItemLayout(diffItem.idx);
  18334. var nextPt = newData.getItemLayout(diffItem.idx1);
  18335. // If previous data is NaN, use next point directly
  18336. if (isNaN(currentPt[0]) || isNaN(currentPt[1])) {
  18337. currentPt = nextPt.slice();
  18338. }
  18339. currPoints.push(currentPt);
  18340. nextPoints.push(nextPt);
  18341. currStackedPoints.push(oldStackedOnPoints[diffItem.idx]);
  18342. nextStackedPoints.push(newStackedOnPoints[diffItem.idx1]);
  18343. rawIndices.push(newData.getRawIndex(diffItem.idx1));
  18344. break;
  18345. case '+':
  18346. var idx = diffItem.idx;
  18347. currPoints.push(
  18348. oldCoordSys.dataToPoint([
  18349. newData.get(dims[0], idx, true), newData.get(dims[1], idx, true)
  18350. ])
  18351. );
  18352. nextPoints.push(newData.getItemLayout(idx).slice());
  18353. currStackedPoints.push(
  18354. getStackedOnPoint(oldCoordSys, newData, idx)
  18355. );
  18356. nextStackedPoints.push(newStackedOnPoints[idx]);
  18357. rawIndices.push(newData.getRawIndex(idx));
  18358. break;
  18359. case '-':
  18360. var idx = diffItem.idx;
  18361. var rawIndex = oldData.getRawIndex(idx);
  18362. // Data is replaced. In the case of dynamic data queue
  18363. // FIXME FIXME FIXME
  18364. if (rawIndex !== idx) {
  18365. currPoints.push(oldData.getItemLayout(idx));
  18366. nextPoints.push(newCoordSys.dataToPoint([
  18367. oldData.get(dims[0], idx, true), oldData.get(dims[1], idx, true)
  18368. ]));
  18369. currStackedPoints.push(oldStackedOnPoints[idx]);
  18370. nextStackedPoints.push(
  18371. getStackedOnPoint(
  18372. newCoordSys, oldData, idx
  18373. )
  18374. );
  18375. rawIndices.push(rawIndex);
  18376. }
  18377. else {
  18378. pointAdded = false;
  18379. }
  18380. }
  18381. // Original indices
  18382. if (pointAdded) {
  18383. status.push(diffItem);
  18384. sortedIndices.push(sortedIndices.length);
  18385. }
  18386. }
  18387. // Diff result may be crossed if all items are changed
  18388. // Sort by data index
  18389. sortedIndices.sort(function (a, b) {
  18390. return rawIndices[a] - rawIndices[b];
  18391. });
  18392. var sortedCurrPoints = [];
  18393. var sortedNextPoints = [];
  18394. var sortedCurrStackedPoints = [];
  18395. var sortedNextStackedPoints = [];
  18396. var sortedStatus = [];
  18397. for (var i = 0; i < sortedIndices.length; i++) {
  18398. var idx = sortedIndices[i];
  18399. sortedCurrPoints[i] = currPoints[idx];
  18400. sortedNextPoints[i] = nextPoints[idx];
  18401. sortedCurrStackedPoints[i] = currStackedPoints[idx];
  18402. sortedNextStackedPoints[i] = nextStackedPoints[idx];
  18403. sortedStatus[i] = status[idx];
  18404. }
  18405. return {
  18406. current: sortedCurrPoints,
  18407. next: sortedNextPoints,
  18408. stackedOnCurrent: sortedCurrStackedPoints,
  18409. stackedOnNext: sortedNextStackedPoints,
  18410. status: sortedStatus
  18411. };
  18412. };
  18413. /***/ },
  18414. /* 103 */
  18415. /***/ function(module, exports, __webpack_require__) {
  18416. // Poly path support NaN point
  18417. var Path = __webpack_require__(44);
  18418. var vec2 = __webpack_require__(16);
  18419. var vec2Min = vec2.min;
  18420. var vec2Max = vec2.max;
  18421. var scaleAndAdd = vec2.scaleAndAdd;
  18422. var v2Copy = vec2.copy;
  18423. // Temporary variable
  18424. var v = [];
  18425. var cp0 = [];
  18426. var cp1 = [];
  18427. function isPointNull(p) {
  18428. return isNaN(p[0]) || isNaN(p[1]);
  18429. }
  18430. function drawSegment(
  18431. ctx, points, start, segLen, allLen,
  18432. dir, smoothMin, smoothMax, smooth, smoothMonotone, connectNulls
  18433. ) {
  18434. var prevIdx = 0;
  18435. var idx = start;
  18436. for (var k = 0; k < segLen; k++) {
  18437. var p = points[idx];
  18438. if (idx >= allLen || idx < 0) {
  18439. break;
  18440. }
  18441. if (isPointNull(p)) {
  18442. if (connectNulls) {
  18443. idx += dir;
  18444. continue;
  18445. }
  18446. break;
  18447. }
  18448. if (idx === start) {
  18449. ctx[dir > 0 ? 'moveTo' : 'lineTo'](p[0], p[1]);
  18450. v2Copy(cp0, p);
  18451. }
  18452. else {
  18453. if (smooth > 0) {
  18454. var nextIdx = idx + dir;
  18455. var nextP = points[nextIdx];
  18456. if (connectNulls) {
  18457. // Find next point not null
  18458. while (nextP && isPointNull(points[nextIdx])) {
  18459. nextIdx += dir;
  18460. nextP = points[nextIdx];
  18461. }
  18462. }
  18463. var ratioNextSeg = 0.5;
  18464. var prevP = points[prevIdx];
  18465. var nextP = points[nextIdx];
  18466. // Last point
  18467. if (!nextP || isPointNull(nextP)) {
  18468. v2Copy(cp1, p);
  18469. }
  18470. else {
  18471. // If next data is null in not connect case
  18472. if (isPointNull(nextP) && !connectNulls) {
  18473. nextP = p;
  18474. }
  18475. vec2.sub(v, nextP, prevP);
  18476. var lenPrevSeg;
  18477. var lenNextSeg;
  18478. if (smoothMonotone === 'x' || smoothMonotone === 'y') {
  18479. var dim = smoothMonotone === 'x' ? 0 : 1;
  18480. lenPrevSeg = Math.abs(p[dim] - prevP[dim]);
  18481. lenNextSeg = Math.abs(p[dim] - nextP[dim]);
  18482. }
  18483. else {
  18484. lenPrevSeg = vec2.dist(p, prevP);
  18485. lenNextSeg = vec2.dist(p, nextP);
  18486. }
  18487. // Use ratio of seg length
  18488. ratioNextSeg = lenNextSeg / (lenNextSeg + lenPrevSeg);
  18489. scaleAndAdd(cp1, p, v, -smooth * (1 - ratioNextSeg));
  18490. }
  18491. // Smooth constraint
  18492. vec2Min(cp0, cp0, smoothMax);
  18493. vec2Max(cp0, cp0, smoothMin);
  18494. vec2Min(cp1, cp1, smoothMax);
  18495. vec2Max(cp1, cp1, smoothMin);
  18496. ctx.bezierCurveTo(
  18497. cp0[0], cp0[1],
  18498. cp1[0], cp1[1],
  18499. p[0], p[1]
  18500. );
  18501. // cp0 of next segment
  18502. scaleAndAdd(cp0, p, v, smooth * ratioNextSeg);
  18503. }
  18504. else {
  18505. ctx.lineTo(p[0], p[1]);
  18506. }
  18507. }
  18508. prevIdx = idx;
  18509. idx += dir;
  18510. }
  18511. return k;
  18512. }
  18513. function getBoundingBox(points, smoothConstraint) {
  18514. var ptMin = [Infinity, Infinity];
  18515. var ptMax = [-Infinity, -Infinity];
  18516. if (smoothConstraint) {
  18517. for (var i = 0; i < points.length; i++) {
  18518. var pt = points[i];
  18519. if (pt[0] < ptMin[0]) { ptMin[0] = pt[0]; }
  18520. if (pt[1] < ptMin[1]) { ptMin[1] = pt[1]; }
  18521. if (pt[0] > ptMax[0]) { ptMax[0] = pt[0]; }
  18522. if (pt[1] > ptMax[1]) { ptMax[1] = pt[1]; }
  18523. }
  18524. }
  18525. return {
  18526. min: smoothConstraint ? ptMin : ptMax,
  18527. max: smoothConstraint ? ptMax : ptMin
  18528. };
  18529. }
  18530. module.exports = {
  18531. Polyline: Path.extend({
  18532. type: 'ec-polyline',
  18533. shape: {
  18534. points: [],
  18535. smooth: 0,
  18536. smoothConstraint: true,
  18537. smoothMonotone: null,
  18538. connectNulls: false
  18539. },
  18540. style: {
  18541. fill: null,
  18542. stroke: '#000'
  18543. },
  18544. buildPath: function (ctx, shape) {
  18545. var points = shape.points;
  18546. var i = 0;
  18547. var len = points.length;
  18548. var result = getBoundingBox(points, shape.smoothConstraint);
  18549. if (shape.connectNulls) {
  18550. // Must remove first and last null values avoid draw error in polygon
  18551. for (; len > 0; len--) {
  18552. if (!isPointNull(points[len - 1])) {
  18553. break;
  18554. }
  18555. }
  18556. for (; i < len; i++) {
  18557. if (!isPointNull(points[i])) {
  18558. break;
  18559. }
  18560. }
  18561. }
  18562. while (i < len) {
  18563. i += drawSegment(
  18564. ctx, points, i, len, len,
  18565. 1, result.min, result.max, shape.smooth,
  18566. shape.smoothMonotone, shape.connectNulls
  18567. ) + 1;
  18568. }
  18569. }
  18570. }),
  18571. Polygon: Path.extend({
  18572. type: 'ec-polygon',
  18573. shape: {
  18574. points: [],
  18575. // Offset between stacked base points and points
  18576. stackedOnPoints: [],
  18577. smooth: 0,
  18578. stackedOnSmooth: 0,
  18579. smoothConstraint: true,
  18580. smoothMonotone: null,
  18581. connectNulls: false
  18582. },
  18583. buildPath: function (ctx, shape) {
  18584. var points = shape.points;
  18585. var stackedOnPoints = shape.stackedOnPoints;
  18586. var i = 0;
  18587. var len = points.length;
  18588. var smoothMonotone = shape.smoothMonotone;
  18589. var bbox = getBoundingBox(points, shape.smoothConstraint);
  18590. var stackedOnBBox = getBoundingBox(stackedOnPoints, shape.smoothConstraint);
  18591. if (shape.connectNulls) {
  18592. // Must remove first and last null values avoid draw error in polygon
  18593. for (; len > 0; len--) {
  18594. if (!isPointNull(points[len - 1])) {
  18595. break;
  18596. }
  18597. }
  18598. for (; i < len; i++) {
  18599. if (!isPointNull(points[i])) {
  18600. break;
  18601. }
  18602. }
  18603. }
  18604. while (i < len) {
  18605. var k = drawSegment(
  18606. ctx, points, i, len, len,
  18607. 1, bbox.min, bbox.max, shape.smooth,
  18608. smoothMonotone, shape.connectNulls
  18609. );
  18610. drawSegment(
  18611. ctx, stackedOnPoints, i + k - 1, k, len,
  18612. -1, stackedOnBBox.min, stackedOnBBox.max, shape.stackedOnSmooth,
  18613. smoothMonotone, shape.connectNulls
  18614. );
  18615. i += k + 1;
  18616. ctx.closePath();
  18617. }
  18618. }
  18619. })
  18620. };
  18621. /***/ },
  18622. /* 104 */
  18623. /***/ function(module, exports) {
  18624. module.exports = function (seriesType, defaultSymbolType, legendSymbol, ecModel, api) {
  18625. // Encoding visual for all series include which is filtered for legend drawing
  18626. ecModel.eachRawSeriesByType(seriesType, function (seriesModel) {
  18627. var data = seriesModel.getData();
  18628. var symbolType = seriesModel.get('symbol') || defaultSymbolType;
  18629. var symbolSize = seriesModel.get('symbolSize');
  18630. data.setVisual({
  18631. legendSymbol: legendSymbol || symbolType,
  18632. symbol: symbolType,
  18633. symbolSize: symbolSize
  18634. });
  18635. // Only visible series has each data be visual encoded
  18636. if (!ecModel.isSeriesFiltered(seriesModel)) {
  18637. if (typeof symbolSize === 'function') {
  18638. data.each(function (idx) {
  18639. var rawValue = seriesModel.getRawValue(idx);
  18640. // FIXME
  18641. var params = seriesModel.getDataParams(idx);
  18642. data.setItemVisual(idx, 'symbolSize', symbolSize(rawValue, params));
  18643. });
  18644. }
  18645. data.each(function (idx) {
  18646. var itemModel = data.getItemModel(idx);
  18647. var itemSymbolType = itemModel.get('symbol', true);
  18648. var itemSymbolSize = itemModel.get('symbolSize', true);
  18649. // If has item symbol
  18650. if (itemSymbolType != null) {
  18651. data.setItemVisual(idx, 'symbol', itemSymbolType);
  18652. }
  18653. if (itemSymbolSize != null) {
  18654. // PENDING Transform symbolSize ?
  18655. data.setItemVisual(idx, 'symbolSize', itemSymbolSize);
  18656. }
  18657. });
  18658. }
  18659. });
  18660. };
  18661. /***/ },
  18662. /* 105 */
  18663. /***/ function(module, exports) {
  18664. module.exports = function (seriesType, ecModel, api) {
  18665. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  18666. var data = seriesModel.getData();
  18667. var coordSys = seriesModel.coordinateSystem;
  18668. if (coordSys) {
  18669. var dims = coordSys.dimensions;
  18670. data.each(dims, function (x, y, idx) {
  18671. var point;
  18672. if (!isNaN(x) && !isNaN(y)) {
  18673. point = coordSys.dataToPoint([x, y]);
  18674. }
  18675. else {
  18676. // Also {Array.<number>}, not undefined to avoid if...else... statement
  18677. point = [NaN, NaN];
  18678. }
  18679. data.setItemLayout(idx, point);
  18680. }, true);
  18681. }
  18682. });
  18683. };
  18684. /***/ },
  18685. /* 106 */
  18686. /***/ function(module, exports) {
  18687. var samplers = {
  18688. average: function (frame) {
  18689. var sum = 0;
  18690. var count = 0;
  18691. for (var i = 0; i < frame.length; i++) {
  18692. if (!isNaN(frame[i])) {
  18693. sum += frame[i];
  18694. count++;
  18695. }
  18696. }
  18697. // Return NaN if count is 0
  18698. return count === 0 ? NaN : sum / count;
  18699. },
  18700. sum: function (frame) {
  18701. var sum = 0;
  18702. for (var i = 0; i < frame.length; i++) {
  18703. // Ignore NaN
  18704. sum += frame[i] || 0;
  18705. }
  18706. return sum;
  18707. },
  18708. max: function (frame) {
  18709. var max = -Infinity;
  18710. for (var i = 0; i < frame.length; i++) {
  18711. frame[i] > max && (max = frame[i]);
  18712. }
  18713. return max;
  18714. },
  18715. min: function (frame) {
  18716. var min = Infinity;
  18717. for (var i = 0; i < frame.length; i++) {
  18718. frame[i] < min && (min = frame[i]);
  18719. }
  18720. return min;
  18721. },
  18722. // TODO
  18723. // Median
  18724. nearest: function (frame) {
  18725. return frame[0];
  18726. }
  18727. };
  18728. var indexSampler = function (frame, value) {
  18729. return Math.round(frame.length / 2);
  18730. };
  18731. module.exports = function (seriesType, ecModel, api) {
  18732. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  18733. var data = seriesModel.getData();
  18734. var sampling = seriesModel.get('sampling');
  18735. var coordSys = seriesModel.coordinateSystem;
  18736. // Only cartesian2d support down sampling
  18737. if (coordSys.type === 'cartesian2d' && sampling) {
  18738. var baseAxis = coordSys.getBaseAxis();
  18739. var valueAxis = coordSys.getOtherAxis(baseAxis);
  18740. var extent = baseAxis.getExtent();
  18741. // Coordinste system has been resized
  18742. var size = extent[1] - extent[0];
  18743. var rate = Math.round(data.count() / size);
  18744. if (rate > 1) {
  18745. var sampler;
  18746. if (typeof sampling === 'string') {
  18747. sampler = samplers[sampling];
  18748. }
  18749. else if (typeof sampling === 'function') {
  18750. sampler = sampling;
  18751. }
  18752. if (sampler) {
  18753. data = data.downSample(
  18754. valueAxis.dim, 1 / rate, sampler, indexSampler
  18755. );
  18756. seriesModel.setData(data);
  18757. }
  18758. }
  18759. }
  18760. }, this);
  18761. };
  18762. /***/ },
  18763. /* 107 */
  18764. /***/ function(module, exports, __webpack_require__) {
  18765. 'use strict';
  18766. var graphic = __webpack_require__(42);
  18767. var zrUtil = __webpack_require__(3);
  18768. __webpack_require__(108);
  18769. __webpack_require__(125);
  18770. // Grid view
  18771. __webpack_require__(1).extendComponentView({
  18772. type: 'grid',
  18773. render: function (gridModel, ecModel) {
  18774. this.group.removeAll();
  18775. if (gridModel.get('show')) {
  18776. this.group.add(new graphic.Rect({
  18777. shape:gridModel.coordinateSystem.getRect(),
  18778. style: zrUtil.defaults({
  18779. fill: gridModel.get('backgroundColor')
  18780. }, gridModel.getItemStyle()),
  18781. silent: true
  18782. }));
  18783. }
  18784. }
  18785. });
  18786. /***/ },
  18787. /* 108 */
  18788. /***/ function(module, exports, __webpack_require__) {
  18789. /**
  18790. * Grid is a region which contains at most 4 cartesian systems
  18791. *
  18792. * TODO Default cartesian
  18793. */
  18794. var factory = exports;
  18795. var layout = __webpack_require__(21);
  18796. var axisHelper = __webpack_require__(109);
  18797. var zrUtil = __webpack_require__(3);
  18798. var Cartesian2D = __webpack_require__(115);
  18799. var Axis2D = __webpack_require__(117);
  18800. var each = zrUtil.each;
  18801. var ifAxisCrossZero = axisHelper.ifAxisCrossZero;
  18802. var niceScaleExtent = axisHelper.niceScaleExtent;
  18803. // 依赖 GridModel, AxisModel 做预处理
  18804. __webpack_require__(120);
  18805. /**
  18806. * Check if the axis is used in the specified grid
  18807. * @inner
  18808. */
  18809. function isAxisUsedInTheGrid(axisModel, gridModel, ecModel) {
  18810. return ecModel.getComponent('grid', axisModel.get('gridIndex')) === gridModel;
  18811. }
  18812. function getLabelUnionRect(axis) {
  18813. var axisModel = axis.model;
  18814. var labels = axisModel.getFormattedLabels();
  18815. var rect;
  18816. var step = 1;
  18817. var labelCount = labels.length;
  18818. if (labelCount > 40) {
  18819. // Simple optimization for large amount of labels
  18820. step = Math.ceil(labelCount / 40);
  18821. }
  18822. for (var i = 0; i < labelCount; i += step) {
  18823. if (!axis.isLabelIgnored(i)) {
  18824. var singleRect = axisModel.getTextRect(labels[i]);
  18825. // FIXME consider label rotate
  18826. rect ? rect.union(singleRect) : (rect = singleRect);
  18827. }
  18828. }
  18829. return rect;
  18830. }
  18831. function Grid(gridModel, ecModel, api) {
  18832. /**
  18833. * @type {Object.<string, module:echarts/coord/cartesian/Cartesian2D>}
  18834. * @private
  18835. */
  18836. this._coordsMap = {};
  18837. /**
  18838. * @type {Array.<module:echarts/coord/cartesian/Cartesian>}
  18839. * @private
  18840. */
  18841. this._coordsList = [];
  18842. /**
  18843. * @type {Object.<string, module:echarts/coord/cartesian/Axis2D>}
  18844. * @private
  18845. */
  18846. this._axesMap = {};
  18847. /**
  18848. * @type {Array.<module:echarts/coord/cartesian/Axis2D>}
  18849. * @private
  18850. */
  18851. this._axesList = [];
  18852. this._initCartesian(gridModel, ecModel, api);
  18853. this._model = gridModel;
  18854. }
  18855. var gridProto = Grid.prototype;
  18856. gridProto.type = 'grid';
  18857. gridProto.getRect = function () {
  18858. return this._rect;
  18859. };
  18860. gridProto.update = function (ecModel, api) {
  18861. var axesMap = this._axesMap;
  18862. this._updateScale(ecModel, this._model);
  18863. function ifAxisCanNotOnZero(otherAxisDim) {
  18864. var axes = axesMap[otherAxisDim];
  18865. for (var idx in axes) {
  18866. var axis = axes[idx];
  18867. if (axis && (axis.type === 'category' || !ifAxisCrossZero(axis))) {
  18868. return true;
  18869. }
  18870. }
  18871. return false;
  18872. }
  18873. each(axesMap.x, function (xAxis) {
  18874. niceScaleExtent(xAxis, xAxis.model);
  18875. });
  18876. each(axesMap.y, function (yAxis) {
  18877. niceScaleExtent(yAxis, yAxis.model);
  18878. });
  18879. // Fix configuration
  18880. each(axesMap.x, function (xAxis) {
  18881. // onZero can not be enabled in these two situations
  18882. // 1. When any other axis is a category axis
  18883. // 2. When any other axis not across 0 point
  18884. if (ifAxisCanNotOnZero('y')) {
  18885. xAxis.onZero = false;
  18886. }
  18887. });
  18888. each(axesMap.y, function (yAxis) {
  18889. if (ifAxisCanNotOnZero('x')) {
  18890. yAxis.onZero = false;
  18891. }
  18892. });
  18893. // Resize again if containLabel is enabled
  18894. // FIXME It may cause getting wrong grid size in data processing stage
  18895. this.resize(this._model, api);
  18896. };
  18897. /**
  18898. * Resize the grid
  18899. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  18900. * @param {module:echarts/ExtensionAPI} api
  18901. */
  18902. gridProto.resize = function (gridModel, api) {
  18903. var gridRect = layout.getLayoutRect(
  18904. gridModel.getBoxLayoutParams(), {
  18905. width: api.getWidth(),
  18906. height: api.getHeight()
  18907. });
  18908. this._rect = gridRect;
  18909. var axesList = this._axesList;
  18910. adjustAxes();
  18911. // Minus label size
  18912. if (gridModel.get('containLabel')) {
  18913. each(axesList, function (axis) {
  18914. if (!axis.model.get('axisLabel.inside')) {
  18915. var labelUnionRect = getLabelUnionRect(axis);
  18916. if (labelUnionRect) {
  18917. var dim = axis.isHorizontal() ? 'height' : 'width';
  18918. var margin = axis.model.get('axisLabel.margin');
  18919. gridRect[dim] -= labelUnionRect[dim] + margin;
  18920. if (axis.position === 'top') {
  18921. gridRect.y += labelUnionRect.height + margin;
  18922. }
  18923. else if (axis.position === 'left') {
  18924. gridRect.x += labelUnionRect.width + margin;
  18925. }
  18926. }
  18927. }
  18928. });
  18929. adjustAxes();
  18930. }
  18931. function adjustAxes() {
  18932. each(axesList, function (axis) {
  18933. var isHorizontal = axis.isHorizontal();
  18934. var extent = isHorizontal ? [0, gridRect.width] : [0, gridRect.height];
  18935. var idx = axis.inverse ? 1 : 0;
  18936. axis.setExtent(extent[idx], extent[1 - idx]);
  18937. updateAxisTransfrom(axis, isHorizontal ? gridRect.x : gridRect.y);
  18938. });
  18939. }
  18940. };
  18941. /**
  18942. * @param {string} axisType
  18943. * @param {ndumber} [axisIndex]
  18944. */
  18945. gridProto.getAxis = function (axisType, axisIndex) {
  18946. var axesMapOnDim = this._axesMap[axisType];
  18947. if (axesMapOnDim != null) {
  18948. if (axisIndex == null) {
  18949. // Find first axis
  18950. for (var name in axesMapOnDim) {
  18951. return axesMapOnDim[name];
  18952. }
  18953. }
  18954. return axesMapOnDim[axisIndex];
  18955. }
  18956. };
  18957. gridProto.getCartesian = function (xAxisIndex, yAxisIndex) {
  18958. var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
  18959. return this._coordsMap[key];
  18960. };
  18961. /**
  18962. * Initialize cartesian coordinate systems
  18963. * @private
  18964. */
  18965. gridProto._initCartesian = function (gridModel, ecModel, api) {
  18966. var axisPositionUsed = {
  18967. left: false,
  18968. right: false,
  18969. top: false,
  18970. bottom: false
  18971. };
  18972. var axesMap = {
  18973. x: {},
  18974. y: {}
  18975. };
  18976. var axesCount = {
  18977. x: 0,
  18978. y: 0
  18979. };
  18980. /// Create axis
  18981. ecModel.eachComponent('xAxis', createAxisCreator('x'), this);
  18982. ecModel.eachComponent('yAxis', createAxisCreator('y'), this);
  18983. if (!axesCount.x || !axesCount.y) {
  18984. // Roll back when there no either x or y axis
  18985. this._axesMap = {};
  18986. this._axesList = [];
  18987. return;
  18988. }
  18989. this._axesMap = axesMap;
  18990. /// Create cartesian2d
  18991. each(axesMap.x, function (xAxis, xAxisIndex) {
  18992. each(axesMap.y, function (yAxis, yAxisIndex) {
  18993. var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
  18994. var cartesian = new Cartesian2D(key);
  18995. cartesian.grid = this;
  18996. this._coordsMap[key] = cartesian;
  18997. this._coordsList.push(cartesian);
  18998. cartesian.addAxis(xAxis);
  18999. cartesian.addAxis(yAxis);
  19000. }, this);
  19001. }, this);
  19002. function createAxisCreator(axisType) {
  19003. return function (axisModel, idx) {
  19004. if (!isAxisUsedInTheGrid(axisModel, gridModel, ecModel)) {
  19005. return;
  19006. }
  19007. var axisPosition = axisModel.get('position');
  19008. if (axisType === 'x') {
  19009. // Fix position
  19010. if (axisPosition !== 'top' && axisPosition !== 'bottom') {
  19011. // Default bottom of X
  19012. axisPosition = 'bottom';
  19013. }
  19014. if (axisPositionUsed[axisPosition]) {
  19015. axisPosition = axisPosition === 'top' ? 'bottom' : 'top';
  19016. }
  19017. }
  19018. else {
  19019. // Fix position
  19020. if (axisPosition !== 'left' && axisPosition !== 'right') {
  19021. // Default left of Y
  19022. axisPosition = 'left';
  19023. }
  19024. if (axisPositionUsed[axisPosition]) {
  19025. axisPosition = axisPosition === 'left' ? 'right' : 'left';
  19026. }
  19027. }
  19028. axisPositionUsed[axisPosition] = true;
  19029. var axis = new Axis2D(
  19030. axisType, axisHelper.createScaleByModel(axisModel),
  19031. [0, 0],
  19032. axisModel.get('type'),
  19033. axisPosition
  19034. );
  19035. var isCategory = axis.type === 'category';
  19036. axis.onBand = isCategory && axisModel.get('boundaryGap');
  19037. axis.inverse = axisModel.get('inverse');
  19038. axis.onZero = axisModel.get('axisLine.onZero');
  19039. // Inject axis into axisModel
  19040. axisModel.axis = axis;
  19041. // Inject axisModel into axis
  19042. axis.model = axisModel;
  19043. // Index of axis, can be used as key
  19044. axis.index = idx;
  19045. this._axesList.push(axis);
  19046. axesMap[axisType][idx] = axis;
  19047. axesCount[axisType]++;
  19048. };
  19049. }
  19050. };
  19051. /**
  19052. * Update cartesian properties from series
  19053. * @param {module:echarts/model/Option} option
  19054. * @private
  19055. */
  19056. gridProto._updateScale = function (ecModel, gridModel) {
  19057. // Reset scale
  19058. zrUtil.each(this._axesList, function (axis) {
  19059. axis.scale.setExtent(Infinity, -Infinity);
  19060. });
  19061. ecModel.eachSeries(function (seriesModel) {
  19062. if (seriesModel.get('coordinateSystem') === 'cartesian2d') {
  19063. var xAxisIndex = seriesModel.get('xAxisIndex');
  19064. var yAxisIndex = seriesModel.get('yAxisIndex');
  19065. var xAxisModel = ecModel.getComponent('xAxis', xAxisIndex);
  19066. var yAxisModel = ecModel.getComponent('yAxis', yAxisIndex);
  19067. if (!isAxisUsedInTheGrid(xAxisModel, gridModel, ecModel)
  19068. || !isAxisUsedInTheGrid(yAxisModel, gridModel, ecModel)
  19069. ) {
  19070. return;
  19071. }
  19072. var cartesian = this.getCartesian(xAxisIndex, yAxisIndex);
  19073. var data = seriesModel.getData();
  19074. var xAxis = cartesian.getAxis('x');
  19075. var yAxis = cartesian.getAxis('y');
  19076. if (data.type === 'list') {
  19077. unionExtent(data, xAxis, seriesModel);
  19078. unionExtent(data, yAxis, seriesModel);
  19079. }
  19080. }
  19081. }, this);
  19082. function unionExtent(data, axis, seriesModel) {
  19083. each(seriesModel.coordDimToDataDim(axis.dim), function (dim) {
  19084. axis.scale.unionExtent(data.getDataExtent(
  19085. dim, axis.scale.type !== 'ordinal'
  19086. ));
  19087. });
  19088. }
  19089. };
  19090. /**
  19091. * @inner
  19092. */
  19093. function updateAxisTransfrom(axis, coordBase) {
  19094. var axisExtent = axis.getExtent();
  19095. var axisExtentSum = axisExtent[0] + axisExtent[1];
  19096. // Fast transform
  19097. axis.toGlobalCoord = axis.dim === 'x'
  19098. ? function (coord) {
  19099. return coord + coordBase;
  19100. }
  19101. : function (coord) {
  19102. return axisExtentSum - coord + coordBase;
  19103. };
  19104. axis.toLocalCoord = axis.dim === 'x'
  19105. ? function (coord) {
  19106. return coord - coordBase;
  19107. }
  19108. : function (coord) {
  19109. return axisExtentSum - coord + coordBase;
  19110. };
  19111. }
  19112. Grid.create = function (ecModel, api) {
  19113. var grids = [];
  19114. ecModel.eachComponent('grid', function (gridModel, idx) {
  19115. var grid = new Grid(gridModel, ecModel, api);
  19116. grid.name = 'grid_' + idx;
  19117. grid.resize(gridModel, api);
  19118. gridModel.coordinateSystem = grid;
  19119. grids.push(grid);
  19120. });
  19121. // Inject the coordinateSystems into seriesModel
  19122. ecModel.eachSeries(function (seriesModel) {
  19123. if (seriesModel.get('coordinateSystem') !== 'cartesian2d') {
  19124. return;
  19125. }
  19126. var xAxisIndex = seriesModel.get('xAxisIndex');
  19127. // TODO Validate
  19128. var xAxisModel = ecModel.getComponent('xAxis', xAxisIndex);
  19129. var grid = grids[xAxisModel.get('gridIndex')];
  19130. seriesModel.coordinateSystem = grid.getCartesian(
  19131. xAxisIndex, seriesModel.get('yAxisIndex')
  19132. );
  19133. });
  19134. return grids;
  19135. };
  19136. // For deciding which dimensions to use when creating list data
  19137. Grid.dimensions = Cartesian2D.prototype.dimensions;
  19138. __webpack_require__(25).register('cartesian2d', Grid);
  19139. module.exports = Grid;
  19140. /***/ },
  19141. /* 109 */
  19142. /***/ function(module, exports, __webpack_require__) {
  19143. var OrdinalScale = __webpack_require__(110);
  19144. var IntervalScale = __webpack_require__(112);
  19145. __webpack_require__(113);
  19146. __webpack_require__(114);
  19147. var Scale = __webpack_require__(111);
  19148. var numberUtil = __webpack_require__(7);
  19149. var zrUtil = __webpack_require__(3);
  19150. var textContain = __webpack_require__(14);
  19151. var axisHelper = {};
  19152. /**
  19153. * Get axis scale extent before niced.
  19154. */
  19155. axisHelper.getScaleExtent = function (axis, model) {
  19156. var scale = axis.scale;
  19157. var originalExtent = scale.getExtent();
  19158. var span = originalExtent[1] - originalExtent[0];
  19159. if (scale.type === 'ordinal') {
  19160. // If series has no data, scale extent may be wrong
  19161. if (!isFinite(span)) {
  19162. return [0, 0];
  19163. }
  19164. else {
  19165. return originalExtent;
  19166. }
  19167. }
  19168. var min = model.getMin ? model.getMin() : model.get('min');
  19169. var max = model.getMax ? model.getMax() : model.get('max');
  19170. var crossZero = model.getNeedCrossZero
  19171. ? model.getNeedCrossZero() : !model.get('scale');
  19172. var boundaryGap = model.get('boundaryGap');
  19173. if (!zrUtil.isArray(boundaryGap)) {
  19174. boundaryGap = [boundaryGap || 0, boundaryGap || 0];
  19175. }
  19176. boundaryGap[0] = numberUtil.parsePercent(boundaryGap[0], 1);
  19177. boundaryGap[1] = numberUtil.parsePercent(boundaryGap[1], 1);
  19178. var fixMin = true;
  19179. var fixMax = true;
  19180. // Add boundary gap
  19181. if (min == null) {
  19182. min = originalExtent[0] - boundaryGap[0] * span;
  19183. fixMin = false;
  19184. }
  19185. if (max == null) {
  19186. max = originalExtent[1] + boundaryGap[1] * span;
  19187. fixMax = false;
  19188. }
  19189. if (min === 'dataMin') {
  19190. min = originalExtent[0];
  19191. }
  19192. if (max === 'dataMax') {
  19193. max = originalExtent[1];
  19194. }
  19195. // Evaluate if axis needs cross zero
  19196. if (crossZero) {
  19197. // Axis is over zero and min is not set
  19198. if (min > 0 && max > 0 && !fixMin) {
  19199. min = 0;
  19200. }
  19201. // Axis is under zero and max is not set
  19202. if (min < 0 && max < 0 && !fixMax) {
  19203. max = 0;
  19204. }
  19205. }
  19206. return [min, max];
  19207. };
  19208. axisHelper.niceScaleExtent = function (axis, model) {
  19209. var scale = axis.scale;
  19210. var extent = axisHelper.getScaleExtent(axis, model);
  19211. var fixMin = (model.getMin ? model.getMin() : model.get('min')) != null;
  19212. var fixMax = (model.getMax ? model.getMax() : model.get('max')) != null;
  19213. var splitNumber = model.get('splitNumber');
  19214. scale.setExtent(extent[0], extent[1]);
  19215. scale.niceExtent(splitNumber, fixMin, fixMax);
  19216. // Use minInterval to constraint the calculated interval.
  19217. // If calculated interval is less than minInterval. increase the interval quantity until
  19218. // it is larger than minInterval.
  19219. // For example:
  19220. // minInterval is 1, calculated interval is 0.2, so increase it to be 1. In this way we can get
  19221. // an integer axis.
  19222. var minInterval = model.get('minInterval');
  19223. if (isFinite(minInterval) && !fixMin && !fixMax && scale.type === 'interval') {
  19224. var interval = scale.getInterval();
  19225. var intervalScale = Math.max(Math.abs(interval), minInterval) / interval;
  19226. // while (interval < minInterval) {
  19227. // var quantity = numberUtil.quantity(interval);
  19228. // interval = quantity * 10;
  19229. // scaleQuantity *= 10;
  19230. // }
  19231. extent = scale.getExtent();
  19232. scale.setExtent(intervalScale * extent[0], extent[1] * intervalScale);
  19233. scale.niceExtent(splitNumber);
  19234. }
  19235. // If some one specified the min, max. And the default calculated interval
  19236. // is not good enough. He can specify the interval. It is often appeared
  19237. // in angle axis with angle 0 - 360. Interval calculated in interval scale is hard
  19238. // to be 60.
  19239. // FIXME
  19240. var interval = model.get('interval');
  19241. if (interval != null) {
  19242. scale.setInterval && scale.setInterval(interval);
  19243. }
  19244. };
  19245. /**
  19246. * @param {module:echarts/model/Model} model
  19247. * @param {string} [axisType] Default retrieve from model.type
  19248. * @return {module:echarts/scale/*}
  19249. */
  19250. axisHelper.createScaleByModel = function(model, axisType) {
  19251. axisType = axisType || model.get('type');
  19252. if (axisType) {
  19253. switch (axisType) {
  19254. // Buildin scale
  19255. case 'category':
  19256. return new OrdinalScale(
  19257. model.getCategories(), [Infinity, -Infinity]
  19258. );
  19259. case 'value':
  19260. return new IntervalScale();
  19261. // Extended scale, like time and log
  19262. default:
  19263. return (Scale.getClass(axisType) || IntervalScale).create(model);
  19264. }
  19265. }
  19266. };
  19267. /**
  19268. * Check if the axis corss 0
  19269. */
  19270. axisHelper.ifAxisCrossZero = function (axis) {
  19271. var dataExtent = axis.scale.getExtent();
  19272. var min = dataExtent[0];
  19273. var max = dataExtent[1];
  19274. return !((min > 0 && max > 0) || (min < 0 && max < 0));
  19275. };
  19276. /**
  19277. * @param {Array.<number>} tickCoords In axis self coordinate.
  19278. * @param {Array.<string>} labels
  19279. * @param {string} font
  19280. * @param {boolean} isAxisHorizontal
  19281. * @return {number}
  19282. */
  19283. axisHelper.getAxisLabelInterval = function (tickCoords, labels, font, isAxisHorizontal) {
  19284. // FIXME
  19285. // 不同角的axis和label,不只是horizontal和vertical.
  19286. var textSpaceTakenRect;
  19287. var autoLabelInterval = 0;
  19288. var accumulatedLabelInterval = 0;
  19289. var step = 1;
  19290. if (labels.length > 40) {
  19291. // Simple optimization for large amount of labels
  19292. step = Math.round(labels.length / 40);
  19293. }
  19294. for (var i = 0; i < tickCoords.length; i += step) {
  19295. var tickCoord = tickCoords[i];
  19296. var rect = textContain.getBoundingRect(
  19297. labels[i], font, 'center', 'top'
  19298. );
  19299. rect[isAxisHorizontal ? 'x' : 'y'] += tickCoord;
  19300. rect[isAxisHorizontal ? 'width' : 'height'] *= 1.5;
  19301. if (!textSpaceTakenRect) {
  19302. textSpaceTakenRect = rect.clone();
  19303. }
  19304. // There is no space for current label;
  19305. else if (textSpaceTakenRect.intersect(rect)) {
  19306. accumulatedLabelInterval++;
  19307. autoLabelInterval = Math.max(autoLabelInterval, accumulatedLabelInterval);
  19308. }
  19309. else {
  19310. textSpaceTakenRect.union(rect);
  19311. // Reset
  19312. accumulatedLabelInterval = 0;
  19313. }
  19314. }
  19315. if (autoLabelInterval === 0 && step > 1) {
  19316. return step;
  19317. }
  19318. return autoLabelInterval * step;
  19319. };
  19320. /**
  19321. * @param {Object} axis
  19322. * @param {Function} labelFormatter
  19323. * @return {Array.<string>}
  19324. */
  19325. axisHelper.getFormattedLabels = function (axis, labelFormatter) {
  19326. var scale = axis.scale;
  19327. var labels = scale.getTicksLabels();
  19328. var ticks = scale.getTicks();
  19329. if (typeof labelFormatter === 'string') {
  19330. labelFormatter = (function (tpl) {
  19331. return function (val) {
  19332. return tpl.replace('{value}', val);
  19333. };
  19334. })(labelFormatter);
  19335. return zrUtil.map(labels, labelFormatter);
  19336. }
  19337. else if (typeof labelFormatter === 'function') {
  19338. return zrUtil.map(ticks, function (tick, idx) {
  19339. return labelFormatter(
  19340. axis.type === 'category' ? scale.getLabel(tick) : tick,
  19341. idx
  19342. );
  19343. }, this);
  19344. }
  19345. else {
  19346. return labels;
  19347. }
  19348. };
  19349. module.exports = axisHelper;
  19350. /***/ },
  19351. /* 110 */
  19352. /***/ function(module, exports, __webpack_require__) {
  19353. /**
  19354. * Linear continuous scale
  19355. * @module echarts/coord/scale/Ordinal
  19356. *
  19357. * http://en.wikipedia.org/wiki/Level_of_measurement
  19358. */
  19359. // FIXME only one data
  19360. var zrUtil = __webpack_require__(3);
  19361. var Scale = __webpack_require__(111);
  19362. var scaleProto = Scale.prototype;
  19363. var OrdinalScale = Scale.extend({
  19364. type: 'ordinal',
  19365. init: function (data, extent) {
  19366. this._data = data;
  19367. this._extent = extent || [0, data.length - 1];
  19368. },
  19369. parse: function (val) {
  19370. return typeof val === 'string'
  19371. ? zrUtil.indexOf(this._data, val)
  19372. // val might be float.
  19373. : Math.round(val);
  19374. },
  19375. contain: function (rank) {
  19376. rank = this.parse(rank);
  19377. return scaleProto.contain.call(this, rank)
  19378. && this._data[rank] != null;
  19379. },
  19380. /**
  19381. * Normalize given rank or name to linear [0, 1]
  19382. * @param {number|string} [val]
  19383. * @return {number}
  19384. */
  19385. normalize: function (val) {
  19386. return scaleProto.normalize.call(this, this.parse(val));
  19387. },
  19388. scale: function (val) {
  19389. return Math.round(scaleProto.scale.call(this, val));
  19390. },
  19391. /**
  19392. * @return {Array}
  19393. */
  19394. getTicks: function () {
  19395. var ticks = [];
  19396. var extent = this._extent;
  19397. var rank = extent[0];
  19398. while (rank <= extent[1]) {
  19399. ticks.push(rank);
  19400. rank++;
  19401. }
  19402. return ticks;
  19403. },
  19404. /**
  19405. * Get item on rank n
  19406. * @param {number} n
  19407. * @return {string}
  19408. */
  19409. getLabel: function (n) {
  19410. return this._data[n];
  19411. },
  19412. /**
  19413. * @return {number}
  19414. */
  19415. count: function () {
  19416. return this._extent[1] - this._extent[0] + 1;
  19417. },
  19418. niceTicks: zrUtil.noop,
  19419. niceExtent: zrUtil.noop
  19420. });
  19421. /**
  19422. * @return {module:echarts/scale/Time}
  19423. */
  19424. OrdinalScale.create = function () {
  19425. return new OrdinalScale();
  19426. };
  19427. module.exports = OrdinalScale;
  19428. /***/ },
  19429. /* 111 */
  19430. /***/ function(module, exports, __webpack_require__) {
  19431. /**
  19432. * // Scale class management
  19433. * @module echarts/scale/Scale
  19434. */
  19435. var clazzUtil = __webpack_require__(9);
  19436. function Scale() {
  19437. /**
  19438. * Extent
  19439. * @type {Array.<number>}
  19440. * @protected
  19441. */
  19442. this._extent = [Infinity, -Infinity];
  19443. /**
  19444. * Step is calculated in adjustExtent
  19445. * @type {Array.<number>}
  19446. * @protected
  19447. */
  19448. this._interval = 0;
  19449. this.init && this.init.apply(this, arguments);
  19450. }
  19451. var scaleProto = Scale.prototype;
  19452. /**
  19453. * Parse input val to valid inner number.
  19454. * @param {*} val
  19455. * @return {number}
  19456. */
  19457. scaleProto.parse = function (val) {
  19458. // Notice: This would be a trap here, If the implementation
  19459. // of this method depends on extent, and this method is used
  19460. // before extent set (like in dataZoom), it would be wrong.
  19461. // Nevertheless, parse does not depend on extent generally.
  19462. return val;
  19463. };
  19464. scaleProto.contain = function (val) {
  19465. var extent = this._extent;
  19466. return val >= extent[0] && val <= extent[1];
  19467. };
  19468. /**
  19469. * Normalize value to linear [0, 1], return 0.5 if extent span is 0
  19470. * @param {number} val
  19471. * @return {number}
  19472. */
  19473. scaleProto.normalize = function (val) {
  19474. var extent = this._extent;
  19475. if (extent[1] === extent[0]) {
  19476. return 0.5;
  19477. }
  19478. return (val - extent[0]) / (extent[1] - extent[0]);
  19479. };
  19480. /**
  19481. * Scale normalized value
  19482. * @param {number} val
  19483. * @return {number}
  19484. */
  19485. scaleProto.scale = function (val) {
  19486. var extent = this._extent;
  19487. return val * (extent[1] - extent[0]) + extent[0];
  19488. };
  19489. /**
  19490. * Set extent from data
  19491. * @param {Array.<number>} other
  19492. */
  19493. scaleProto.unionExtent = function (other) {
  19494. var extent = this._extent;
  19495. other[0] < extent[0] && (extent[0] = other[0]);
  19496. other[1] > extent[1] && (extent[1] = other[1]);
  19497. // not setExtent because in log axis it may transformed to power
  19498. // this.setExtent(extent[0], extent[1]);
  19499. };
  19500. /**
  19501. * Get extent
  19502. * @return {Array.<number>}
  19503. */
  19504. scaleProto.getExtent = function () {
  19505. return this._extent.slice();
  19506. };
  19507. /**
  19508. * Set extent
  19509. * @param {number} start
  19510. * @param {number} end
  19511. */
  19512. scaleProto.setExtent = function (start, end) {
  19513. var thisExtent = this._extent;
  19514. if (!isNaN(start)) {
  19515. thisExtent[0] = start;
  19516. }
  19517. if (!isNaN(end)) {
  19518. thisExtent[1] = end;
  19519. }
  19520. };
  19521. /**
  19522. * @return {Array.<string>}
  19523. */
  19524. scaleProto.getTicksLabels = function () {
  19525. var labels = [];
  19526. var ticks = this.getTicks();
  19527. for (var i = 0; i < ticks.length; i++) {
  19528. labels.push(this.getLabel(ticks[i]));
  19529. }
  19530. return labels;
  19531. };
  19532. clazzUtil.enableClassExtend(Scale);
  19533. clazzUtil.enableClassManagement(Scale, {
  19534. registerWhenExtend: true
  19535. });
  19536. module.exports = Scale;
  19537. /***/ },
  19538. /* 112 */
  19539. /***/ function(module, exports, __webpack_require__) {
  19540. /**
  19541. * Interval scale
  19542. * @module echarts/scale/Interval
  19543. */
  19544. var numberUtil = __webpack_require__(7);
  19545. var formatUtil = __webpack_require__(6);
  19546. var Scale = __webpack_require__(111);
  19547. var mathFloor = Math.floor;
  19548. var mathCeil = Math.ceil;
  19549. /**
  19550. * @alias module:echarts/coord/scale/Interval
  19551. * @constructor
  19552. */
  19553. var IntervalScale = Scale.extend({
  19554. type: 'interval',
  19555. _interval: 0,
  19556. setExtent: function (start, end) {
  19557. var thisExtent = this._extent;
  19558. //start,end may be a Number like '25',so...
  19559. if (!isNaN(start)) {
  19560. thisExtent[0] = parseFloat(start);
  19561. }
  19562. if (!isNaN(end)) {
  19563. thisExtent[1] = parseFloat(end);
  19564. }
  19565. },
  19566. unionExtent: function (other) {
  19567. var extent = this._extent;
  19568. other[0] < extent[0] && (extent[0] = other[0]);
  19569. other[1] > extent[1] && (extent[1] = other[1]);
  19570. // unionExtent may called by it's sub classes
  19571. IntervalScale.prototype.setExtent.call(this, extent[0], extent[1]);
  19572. },
  19573. /**
  19574. * Get interval
  19575. */
  19576. getInterval: function () {
  19577. if (!this._interval) {
  19578. this.niceTicks();
  19579. }
  19580. return this._interval;
  19581. },
  19582. /**
  19583. * Set interval
  19584. */
  19585. setInterval: function (interval) {
  19586. this._interval = interval;
  19587. // Dropped auto calculated niceExtent and use user setted extent
  19588. // We assume user wan't to set both interval, min, max to get a better result
  19589. this._niceExtent = this._extent.slice();
  19590. },
  19591. /**
  19592. * @return {Array.<number>}
  19593. */
  19594. getTicks: function () {
  19595. if (!this._interval) {
  19596. this.niceTicks();
  19597. }
  19598. var interval = this._interval;
  19599. var extent = this._extent;
  19600. var ticks = [];
  19601. // Consider this case: using dataZoom toolbox, zoom and zoom.
  19602. var safeLimit = 10000;
  19603. if (interval) {
  19604. var niceExtent = this._niceExtent;
  19605. if (extent[0] < niceExtent[0]) {
  19606. ticks.push(extent[0]);
  19607. }
  19608. var tick = niceExtent[0];
  19609. while (tick <= niceExtent[1]) {
  19610. ticks.push(tick);
  19611. // Avoid rounding error
  19612. tick = numberUtil.round(tick + interval);
  19613. if (ticks.length > safeLimit) {
  19614. return [];
  19615. }
  19616. }
  19617. if (extent[1] > niceExtent[1]) {
  19618. ticks.push(extent[1]);
  19619. }
  19620. }
  19621. return ticks;
  19622. },
  19623. /**
  19624. * @return {Array.<string>}
  19625. */
  19626. getTicksLabels: function () {
  19627. var labels = [];
  19628. var ticks = this.getTicks();
  19629. for (var i = 0; i < ticks.length; i++) {
  19630. labels.push(this.getLabel(ticks[i]));
  19631. }
  19632. return labels;
  19633. },
  19634. /**
  19635. * @param {number} n
  19636. * @return {number}
  19637. */
  19638. getLabel: function (data) {
  19639. return formatUtil.addCommas(data);
  19640. },
  19641. /**
  19642. * Update interval and extent of intervals for nice ticks
  19643. *
  19644. * @param {number} [splitNumber = 5] Desired number of ticks
  19645. */
  19646. niceTicks: function (splitNumber) {
  19647. splitNumber = splitNumber || 5;
  19648. var extent = this._extent;
  19649. var span = extent[1] - extent[0];
  19650. if (!isFinite(span)) {
  19651. return;
  19652. }
  19653. // User may set axis min 0 and data are all negative
  19654. // FIXME If it needs to reverse ?
  19655. if (span < 0) {
  19656. span = -span;
  19657. extent.reverse();
  19658. }
  19659. // From "Nice Numbers for Graph Labels" of Graphic Gems
  19660. // var niceSpan = numberUtil.nice(span, false);
  19661. var step = numberUtil.nice(span / splitNumber, true);
  19662. // Niced extent inside original extent
  19663. var niceExtent = [
  19664. numberUtil.round(mathCeil(extent[0] / step) * step),
  19665. numberUtil.round(mathFloor(extent[1] / step) * step)
  19666. ];
  19667. this._interval = step;
  19668. this._niceExtent = niceExtent;
  19669. },
  19670. /**
  19671. * Nice extent.
  19672. * @param {number} [splitNumber = 5] Given approx tick number
  19673. * @param {boolean} [fixMin=false]
  19674. * @param {boolean} [fixMax=false]
  19675. */
  19676. niceExtent: function (splitNumber, fixMin, fixMax) {
  19677. var extent = this._extent;
  19678. // If extent start and end are same, expand them
  19679. if (extent[0] === extent[1]) {
  19680. if (extent[0] !== 0) {
  19681. // Expand extent
  19682. var expandSize = extent[0] / 2;
  19683. extent[0] -= expandSize;
  19684. extent[1] += expandSize;
  19685. }
  19686. else {
  19687. extent[1] = 1;
  19688. }
  19689. }
  19690. var span = extent[1] - extent[0];
  19691. // If there are no data and extent are [Infinity, -Infinity]
  19692. if (!isFinite(span)) {
  19693. extent[0] = 0;
  19694. extent[1] = 1;
  19695. }
  19696. this.niceTicks(splitNumber);
  19697. // var extent = this._extent;
  19698. var interval = this._interval;
  19699. if (!fixMin) {
  19700. extent[0] = numberUtil.round(mathFloor(extent[0] / interval) * interval);
  19701. }
  19702. if (!fixMax) {
  19703. extent[1] = numberUtil.round(mathCeil(extent[1] / interval) * interval);
  19704. }
  19705. }
  19706. });
  19707. /**
  19708. * @return {module:echarts/scale/Time}
  19709. */
  19710. IntervalScale.create = function () {
  19711. return new IntervalScale();
  19712. };
  19713. module.exports = IntervalScale;
  19714. /***/ },
  19715. /* 113 */
  19716. /***/ function(module, exports, __webpack_require__) {
  19717. /**
  19718. * Interval scale
  19719. * @module echarts/coord/scale/Time
  19720. */
  19721. var zrUtil = __webpack_require__(3);
  19722. var numberUtil = __webpack_require__(7);
  19723. var formatUtil = __webpack_require__(6);
  19724. var IntervalScale = __webpack_require__(112);
  19725. var intervalScaleProto = IntervalScale.prototype;
  19726. var mathCeil = Math.ceil;
  19727. var mathFloor = Math.floor;
  19728. var ONE_SECOND = 1000;
  19729. var ONE_MINUTE = ONE_SECOND * 60;
  19730. var ONE_HOUR = ONE_MINUTE * 60;
  19731. var ONE_DAY = ONE_HOUR * 24;
  19732. // FIXME 公用?
  19733. var bisect = function (a, x, lo, hi) {
  19734. while (lo < hi) {
  19735. var mid = lo + hi >>> 1;
  19736. if (a[mid][2] < x) {
  19737. lo = mid + 1;
  19738. }
  19739. else {
  19740. hi = mid;
  19741. }
  19742. }
  19743. return lo;
  19744. };
  19745. /**
  19746. * @alias module:echarts/coord/scale/Time
  19747. * @constructor
  19748. */
  19749. var TimeScale = IntervalScale.extend({
  19750. type: 'time',
  19751. // Overwrite
  19752. getLabel: function (val) {
  19753. var stepLvl = this._stepLvl;
  19754. var date = new Date(val);
  19755. return formatUtil.formatTime(stepLvl[0], date);
  19756. },
  19757. // Overwrite
  19758. niceExtent: function (approxTickNum, fixMin, fixMax) {
  19759. var extent = this._extent;
  19760. // If extent start and end are same, expand them
  19761. if (extent[0] === extent[1]) {
  19762. // Expand extent
  19763. extent[0] -= ONE_DAY;
  19764. extent[1] += ONE_DAY;
  19765. }
  19766. // If there are no data and extent are [Infinity, -Infinity]
  19767. if (extent[1] === -Infinity && extent[0] === Infinity) {
  19768. var d = new Date();
  19769. extent[1] = new Date(d.getFullYear(), d.getMonth(), d.getDate());
  19770. extent[0] = extent[1] - ONE_DAY;
  19771. }
  19772. this.niceTicks(approxTickNum);
  19773. // var extent = this._extent;
  19774. var interval = this._interval;
  19775. if (!fixMin) {
  19776. extent[0] = numberUtil.round(mathFloor(extent[0] / interval) * interval);
  19777. }
  19778. if (!fixMax) {
  19779. extent[1] = numberUtil.round(mathCeil(extent[1] / interval) * interval);
  19780. }
  19781. },
  19782. // Overwrite
  19783. niceTicks: function (approxTickNum) {
  19784. approxTickNum = approxTickNum || 10;
  19785. var extent = this._extent;
  19786. var span = extent[1] - extent[0];
  19787. var approxInterval = span / approxTickNum;
  19788. var scaleLevelsLen = scaleLevels.length;
  19789. var idx = bisect(scaleLevels, approxInterval, 0, scaleLevelsLen);
  19790. var level = scaleLevels[Math.min(idx, scaleLevelsLen - 1)];
  19791. var interval = level[2];
  19792. // Same with interval scale if span is much larger than 1 year
  19793. if (level[0] === 'year') {
  19794. var yearSpan = span / interval;
  19795. // From "Nice Numbers for Graph Labels" of Graphic Gems
  19796. // var niceYearSpan = numberUtil.nice(yearSpan, false);
  19797. var yearStep = numberUtil.nice(yearSpan / approxTickNum, true);
  19798. interval *= yearStep;
  19799. }
  19800. var niceExtent = [
  19801. mathCeil(extent[0] / interval) * interval,
  19802. mathFloor(extent[1] / interval) * interval
  19803. ];
  19804. this._stepLvl = level;
  19805. // Interval will be used in getTicks
  19806. this._interval = interval;
  19807. this._niceExtent = niceExtent;
  19808. },
  19809. parse: function (val) {
  19810. // val might be float.
  19811. return +numberUtil.parseDate(val);
  19812. }
  19813. });
  19814. zrUtil.each(['contain', 'normalize'], function (methodName) {
  19815. TimeScale.prototype[methodName] = function (val) {
  19816. return intervalScaleProto[methodName].call(this, this.parse(val));
  19817. };
  19818. });
  19819. // Steps from d3
  19820. var scaleLevels = [
  19821. // Format step interval
  19822. ['hh:mm:ss', 1, ONE_SECOND], // 1s
  19823. ['hh:mm:ss', 5, ONE_SECOND * 5], // 5s
  19824. ['hh:mm:ss', 10, ONE_SECOND * 10], // 10s
  19825. ['hh:mm:ss', 15, ONE_SECOND * 15], // 15s
  19826. ['hh:mm:ss', 30, ONE_SECOND * 30], // 30s
  19827. ['hh:mm\nMM-dd',1, ONE_MINUTE], // 1m
  19828. ['hh:mm\nMM-dd',5, ONE_MINUTE * 5], // 5m
  19829. ['hh:mm\nMM-dd',10, ONE_MINUTE * 10], // 10m
  19830. ['hh:mm\nMM-dd',15, ONE_MINUTE * 15], // 15m
  19831. ['hh:mm\nMM-dd',30, ONE_MINUTE * 30], // 30m
  19832. ['hh:mm\nMM-dd',1, ONE_HOUR], // 1h
  19833. ['hh:mm\nMM-dd',2, ONE_HOUR * 2], // 2h
  19834. ['hh:mm\nMM-dd',6, ONE_HOUR * 6], // 6h
  19835. ['hh:mm\nMM-dd',12, ONE_HOUR * 12], // 12h
  19836. ['MM-dd\nyyyy', 1, ONE_DAY], // 1d
  19837. ['week', 7, ONE_DAY * 7], // 7d
  19838. ['month', 1, ONE_DAY * 31], // 1M
  19839. ['quarter', 3, ONE_DAY * 380 / 4], // 3M
  19840. ['half-year', 6, ONE_DAY * 380 / 2], // 6M
  19841. ['year', 1, ONE_DAY * 380] // 1Y
  19842. ];
  19843. /**
  19844. * @return {module:echarts/scale/Time}
  19845. */
  19846. TimeScale.create = function () {
  19847. return new TimeScale();
  19848. };
  19849. module.exports = TimeScale;
  19850. /***/ },
  19851. /* 114 */
  19852. /***/ function(module, exports, __webpack_require__) {
  19853. /**
  19854. * Log scale
  19855. * @module echarts/scale/Log
  19856. */
  19857. var zrUtil = __webpack_require__(3);
  19858. var Scale = __webpack_require__(111);
  19859. var numberUtil = __webpack_require__(7);
  19860. // Use some method of IntervalScale
  19861. var IntervalScale = __webpack_require__(112);
  19862. var scaleProto = Scale.prototype;
  19863. var intervalScaleProto = IntervalScale.prototype;
  19864. var mathFloor = Math.floor;
  19865. var mathCeil = Math.ceil;
  19866. var mathPow = Math.pow;
  19867. var LOG_BASE = 10;
  19868. var mathLog = Math.log;
  19869. var LogScale = Scale.extend({
  19870. type: 'log',
  19871. /**
  19872. * @return {Array.<number>}
  19873. */
  19874. getTicks: function () {
  19875. return zrUtil.map(intervalScaleProto.getTicks.call(this), function (val) {
  19876. return numberUtil.round(mathPow(LOG_BASE, val));
  19877. });
  19878. },
  19879. /**
  19880. * @param {number} val
  19881. * @return {string}
  19882. */
  19883. getLabel: intervalScaleProto.getLabel,
  19884. /**
  19885. * @param {number} val
  19886. * @return {number}
  19887. */
  19888. scale: function (val) {
  19889. val = scaleProto.scale.call(this, val);
  19890. return mathPow(LOG_BASE, val);
  19891. },
  19892. /**
  19893. * @param {number} start
  19894. * @param {number} end
  19895. */
  19896. setExtent: function (start, end) {
  19897. start = mathLog(start) / mathLog(LOG_BASE);
  19898. end = mathLog(end) / mathLog(LOG_BASE);
  19899. intervalScaleProto.setExtent.call(this, start, end);
  19900. },
  19901. /**
  19902. * @return {number} end
  19903. */
  19904. getExtent: function () {
  19905. var extent = scaleProto.getExtent.call(this);
  19906. extent[0] = mathPow(LOG_BASE, extent[0]);
  19907. extent[1] = mathPow(LOG_BASE, extent[1]);
  19908. return extent;
  19909. },
  19910. /**
  19911. * @param {Array.<number>} extent
  19912. */
  19913. unionExtent: function (extent) {
  19914. extent[0] = mathLog(extent[0]) / mathLog(LOG_BASE);
  19915. extent[1] = mathLog(extent[1]) / mathLog(LOG_BASE);
  19916. scaleProto.unionExtent.call(this, extent);
  19917. },
  19918. /**
  19919. * Update interval and extent of intervals for nice ticks
  19920. * @param {number} [approxTickNum = 10] Given approx tick number
  19921. */
  19922. niceTicks: function (approxTickNum) {
  19923. approxTickNum = approxTickNum || 10;
  19924. var extent = this._extent;
  19925. var span = extent[1] - extent[0];
  19926. if (span === Infinity || span <= 0) {
  19927. return;
  19928. }
  19929. var interval = mathPow(10, mathFloor(mathLog(span / approxTickNum) / Math.LN10));
  19930. var err = approxTickNum / span * interval;
  19931. // Filter ticks to get closer to the desired count.
  19932. if (err <= 0.5) {
  19933. interval *= 10;
  19934. }
  19935. var niceExtent = [
  19936. numberUtil.round(mathCeil(extent[0] / interval) * interval),
  19937. numberUtil.round(mathFloor(extent[1] / interval) * interval)
  19938. ];
  19939. this._interval = interval;
  19940. this._niceExtent = niceExtent;
  19941. },
  19942. /**
  19943. * Nice extent.
  19944. * @param {number} [approxTickNum = 10] Given approx tick number
  19945. * @param {boolean} [fixMin=false]
  19946. * @param {boolean} [fixMax=false]
  19947. */
  19948. niceExtent: intervalScaleProto.niceExtent
  19949. });
  19950. zrUtil.each(['contain', 'normalize'], function (methodName) {
  19951. LogScale.prototype[methodName] = function (val) {
  19952. val = mathLog(val) / mathLog(LOG_BASE);
  19953. return scaleProto[methodName].call(this, val);
  19954. };
  19955. });
  19956. LogScale.create = function () {
  19957. return new LogScale();
  19958. };
  19959. module.exports = LogScale;
  19960. /***/ },
  19961. /* 115 */
  19962. /***/ function(module, exports, __webpack_require__) {
  19963. 'use strict';
  19964. var zrUtil = __webpack_require__(3);
  19965. var Cartesian = __webpack_require__(116);
  19966. function Cartesian2D(name) {
  19967. Cartesian.call(this, name);
  19968. }
  19969. Cartesian2D.prototype = {
  19970. constructor: Cartesian2D,
  19971. type: 'cartesian2d',
  19972. /**
  19973. * @type {Array.<string>}
  19974. * @readOnly
  19975. */
  19976. dimensions: ['x', 'y'],
  19977. /**
  19978. * Base axis will be used on stacking.
  19979. *
  19980. * @return {module:echarts/coord/cartesian/Axis2D}
  19981. */
  19982. getBaseAxis: function () {
  19983. return this.getAxesByScale('ordinal')[0]
  19984. || this.getAxesByScale('time')[0]
  19985. || this.getAxis('x');
  19986. },
  19987. /**
  19988. * If contain point
  19989. * @param {Array.<number>} point
  19990. * @return {boolean}
  19991. */
  19992. containPoint: function (point) {
  19993. var axisX = this.getAxis('x');
  19994. var axisY = this.getAxis('y');
  19995. return axisX.contain(axisX.toLocalCoord(point[0]))
  19996. && axisY.contain(axisY.toLocalCoord(point[1]));
  19997. },
  19998. /**
  19999. * If contain data
  20000. * @param {Array.<number>} data
  20001. * @return {boolean}
  20002. */
  20003. containData: function (data) {
  20004. return this.getAxis('x').containData(data[0])
  20005. && this.getAxis('y').containData(data[1]);
  20006. },
  20007. /**
  20008. * Convert series data to an array of points
  20009. * @param {module:echarts/data/List} data
  20010. * @param {boolean} stack
  20011. * @return {Array}
  20012. * Return array of points. For example:
  20013. * `[[10, 10], [20, 20], [30, 30]]`
  20014. */
  20015. dataToPoints: function (data, stack) {
  20016. return data.mapArray(['x', 'y'], function (x, y) {
  20017. return this.dataToPoint([x, y]);
  20018. }, stack, this);
  20019. },
  20020. /**
  20021. * @param {Array.<number>} data
  20022. * @param {boolean} [clamp=false]
  20023. * @return {Array.<number>}
  20024. */
  20025. dataToPoint: function (data, clamp) {
  20026. var xAxis = this.getAxis('x');
  20027. var yAxis = this.getAxis('y');
  20028. return [
  20029. xAxis.toGlobalCoord(xAxis.dataToCoord(data[0], clamp)),
  20030. yAxis.toGlobalCoord(yAxis.dataToCoord(data[1], clamp))
  20031. ];
  20032. },
  20033. /**
  20034. * @param {Array.<number>} point
  20035. * @param {boolean} [clamp=false]
  20036. * @return {Array.<number>}
  20037. */
  20038. pointToData: function (point, clamp) {
  20039. var xAxis = this.getAxis('x');
  20040. var yAxis = this.getAxis('y');
  20041. return [
  20042. xAxis.coordToData(xAxis.toLocalCoord(point[0]), clamp),
  20043. yAxis.coordToData(yAxis.toLocalCoord(point[1]), clamp)
  20044. ];
  20045. },
  20046. /**
  20047. * Get other axis
  20048. * @param {module:echarts/coord/cartesian/Axis2D} axis
  20049. */
  20050. getOtherAxis: function (axis) {
  20051. return this.getAxis(axis.dim === 'x' ? 'y' : 'x');
  20052. }
  20053. };
  20054. zrUtil.inherits(Cartesian2D, Cartesian);
  20055. module.exports = Cartesian2D;
  20056. /***/ },
  20057. /* 116 */
  20058. /***/ function(module, exports, __webpack_require__) {
  20059. 'use strict';
  20060. /**
  20061. * Cartesian coordinate system
  20062. * @module echarts/coord/Cartesian
  20063. *
  20064. */
  20065. var zrUtil = __webpack_require__(3);
  20066. function dimAxisMapper(dim) {
  20067. return this._axes[dim];
  20068. }
  20069. /**
  20070. * @alias module:echarts/coord/Cartesian
  20071. * @constructor
  20072. */
  20073. var Cartesian = function (name) {
  20074. this._axes = {};
  20075. this._dimList = [];
  20076. /**
  20077. * @type {string}
  20078. */
  20079. this.name = name || '';
  20080. };
  20081. Cartesian.prototype = {
  20082. constructor: Cartesian,
  20083. type: 'cartesian',
  20084. /**
  20085. * Get axis
  20086. * @param {number|string} dim
  20087. * @return {module:echarts/coord/Cartesian~Axis}
  20088. */
  20089. getAxis: function (dim) {
  20090. return this._axes[dim];
  20091. },
  20092. /**
  20093. * Get axes list
  20094. * @return {Array.<module:echarts/coord/Cartesian~Axis>}
  20095. */
  20096. getAxes: function () {
  20097. return zrUtil.map(this._dimList, dimAxisMapper, this);
  20098. },
  20099. /**
  20100. * Get axes list by given scale type
  20101. */
  20102. getAxesByScale: function (scaleType) {
  20103. scaleType = scaleType.toLowerCase();
  20104. return zrUtil.filter(
  20105. this.getAxes(),
  20106. function (axis) {
  20107. return axis.scale.type === scaleType;
  20108. }
  20109. );
  20110. },
  20111. /**
  20112. * Add axis
  20113. * @param {module:echarts/coord/Cartesian.Axis}
  20114. */
  20115. addAxis: function (axis) {
  20116. var dim = axis.dim;
  20117. this._axes[dim] = axis;
  20118. this._dimList.push(dim);
  20119. },
  20120. /**
  20121. * Convert data to coord in nd space
  20122. * @param {Array.<number>|Object.<string, number>} val
  20123. * @return {Array.<number>|Object.<string, number>}
  20124. */
  20125. dataToCoord: function (val) {
  20126. return this._dataCoordConvert(val, 'dataToCoord');
  20127. },
  20128. /**
  20129. * Convert coord in nd space to data
  20130. * @param {Array.<number>|Object.<string, number>} val
  20131. * @return {Array.<number>|Object.<string, number>}
  20132. */
  20133. coordToData: function (val) {
  20134. return this._dataCoordConvert(val, 'coordToData');
  20135. },
  20136. _dataCoordConvert: function (input, method) {
  20137. var dimList = this._dimList;
  20138. var output = input instanceof Array ? [] : {};
  20139. for (var i = 0; i < dimList.length; i++) {
  20140. var dim = dimList[i];
  20141. var axis = this._axes[dim];
  20142. output[dim] = axis[method](input[dim]);
  20143. }
  20144. return output;
  20145. }
  20146. };
  20147. module.exports = Cartesian;
  20148. /***/ },
  20149. /* 117 */
  20150. /***/ function(module, exports, __webpack_require__) {
  20151. var zrUtil = __webpack_require__(3);
  20152. var Axis = __webpack_require__(118);
  20153. var axisLabelInterval = __webpack_require__(119);
  20154. /**
  20155. * Extend axis 2d
  20156. * @constructor module:echarts/coord/cartesian/Axis2D
  20157. * @extends {module:echarts/coord/cartesian/Axis}
  20158. * @param {string} dim
  20159. * @param {*} scale
  20160. * @param {Array.<number>} coordExtent
  20161. * @param {string} axisType
  20162. * @param {string} position
  20163. */
  20164. var Axis2D = function (dim, scale, coordExtent, axisType, position) {
  20165. Axis.call(this, dim, scale, coordExtent);
  20166. /**
  20167. * Axis type
  20168. * - 'category'
  20169. * - 'value'
  20170. * - 'time'
  20171. * - 'log'
  20172. * @type {string}
  20173. */
  20174. this.type = axisType || 'value';
  20175. /**
  20176. * Axis position
  20177. * - 'top'
  20178. * - 'bottom'
  20179. * - 'left'
  20180. * - 'right'
  20181. */
  20182. this.position = position || 'bottom';
  20183. };
  20184. Axis2D.prototype = {
  20185. constructor: Axis2D,
  20186. /**
  20187. * Index of axis, can be used as key
  20188. */
  20189. index: 0,
  20190. /**
  20191. * If axis is on the zero position of the other axis
  20192. * @type {boolean}
  20193. */
  20194. onZero: false,
  20195. /**
  20196. * Axis model
  20197. * @param {module:echarts/coord/cartesian/AxisModel}
  20198. */
  20199. model: null,
  20200. isHorizontal: function () {
  20201. var position = this.position;
  20202. return position === 'top' || position === 'bottom';
  20203. },
  20204. getGlobalExtent: function () {
  20205. var ret = this.getExtent();
  20206. ret[0] = this.toGlobalCoord(ret[0]);
  20207. ret[1] = this.toGlobalCoord(ret[1]);
  20208. return ret;
  20209. },
  20210. /**
  20211. * @return {number}
  20212. */
  20213. getLabelInterval: function () {
  20214. var labelInterval = this._labelInterval;
  20215. if (!labelInterval) {
  20216. labelInterval = this._labelInterval = axisLabelInterval(this);
  20217. }
  20218. return labelInterval;
  20219. },
  20220. /**
  20221. * If label is ignored.
  20222. * Automatically used when axis is category and label can not be all shown
  20223. * @param {number} idx
  20224. * @return {boolean}
  20225. */
  20226. isLabelIgnored: function (idx) {
  20227. if (this.type === 'category') {
  20228. var labelInterval = this.getLabelInterval();
  20229. return ((typeof labelInterval === 'function')
  20230. && !labelInterval(idx, this.scale.getLabel(idx)))
  20231. || idx % (labelInterval + 1);
  20232. }
  20233. },
  20234. /**
  20235. * Transform global coord to local coord,
  20236. * i.e. var localCoord = axis.toLocalCoord(80);
  20237. * designate by module:echarts/coord/cartesian/Grid.
  20238. * @type {Function}
  20239. */
  20240. toLocalCoord: null,
  20241. /**
  20242. * Transform global coord to local coord,
  20243. * i.e. var globalCoord = axis.toLocalCoord(40);
  20244. * designate by module:echarts/coord/cartesian/Grid.
  20245. * @type {Function}
  20246. */
  20247. toGlobalCoord: null
  20248. };
  20249. zrUtil.inherits(Axis2D, Axis);
  20250. module.exports = Axis2D;
  20251. /***/ },
  20252. /* 118 */
  20253. /***/ function(module, exports, __webpack_require__) {
  20254. var numberUtil = __webpack_require__(7);
  20255. var linearMap = numberUtil.linearMap;
  20256. var zrUtil = __webpack_require__(3);
  20257. function fixExtentWithBands(extent, nTick) {
  20258. var size = extent[1] - extent[0];
  20259. var len = nTick;
  20260. var margin = size / len / 2;
  20261. extent[0] += margin;
  20262. extent[1] -= margin;
  20263. }
  20264. var normalizedExtent = [0, 1];
  20265. /**
  20266. * @name module:echarts/coord/CartesianAxis
  20267. * @constructor
  20268. */
  20269. var Axis = function (dim, scale, extent) {
  20270. /**
  20271. * Axis dimension. Such as 'x', 'y', 'z', 'angle', 'radius'
  20272. * @type {string}
  20273. */
  20274. this.dim = dim;
  20275. /**
  20276. * Axis scale
  20277. * @type {module:echarts/coord/scale/*}
  20278. */
  20279. this.scale = scale;
  20280. /**
  20281. * @type {Array.<number>}
  20282. * @private
  20283. */
  20284. this._extent = extent || [0, 0];
  20285. /**
  20286. * @type {boolean}
  20287. */
  20288. this.inverse = false;
  20289. /**
  20290. * Usually true when axis has a ordinal scale
  20291. * @type {boolean}
  20292. */
  20293. this.onBand = false;
  20294. };
  20295. Axis.prototype = {
  20296. constructor: Axis,
  20297. /**
  20298. * If axis extent contain given coord
  20299. * @param {number} coord
  20300. * @return {boolean}
  20301. */
  20302. contain: function (coord) {
  20303. var extent = this._extent;
  20304. var min = Math.min(extent[0], extent[1]);
  20305. var max = Math.max(extent[0], extent[1]);
  20306. return coord >= min && coord <= max;
  20307. },
  20308. /**
  20309. * If axis extent contain given data
  20310. * @param {number} data
  20311. * @return {boolean}
  20312. */
  20313. containData: function (data) {
  20314. return this.contain(this.dataToCoord(data));
  20315. },
  20316. /**
  20317. * Get coord extent.
  20318. * @return {Array.<number>}
  20319. */
  20320. getExtent: function () {
  20321. var ret = this._extent.slice();
  20322. return ret;
  20323. },
  20324. /**
  20325. * Get precision used for formatting
  20326. * @param {Array.<number>} [dataExtent]
  20327. * @return {number}
  20328. */
  20329. getPixelPrecision: function (dataExtent) {
  20330. return numberUtil.getPixelPrecision(
  20331. dataExtent || this.scale.getExtent(),
  20332. this._extent
  20333. );
  20334. },
  20335. /**
  20336. * Set coord extent
  20337. * @param {number} start
  20338. * @param {number} end
  20339. */
  20340. setExtent: function (start, end) {
  20341. var extent = this._extent;
  20342. extent[0] = start;
  20343. extent[1] = end;
  20344. },
  20345. /**
  20346. * Convert data to coord. Data is the rank if it has a ordinal scale
  20347. * @param {number} data
  20348. * @param {boolean} clamp
  20349. * @return {number}
  20350. */
  20351. dataToCoord: function (data, clamp) {
  20352. var extent = this._extent;
  20353. var scale = this.scale;
  20354. data = scale.normalize(data);
  20355. if (this.onBand && scale.type === 'ordinal') {
  20356. extent = extent.slice();
  20357. fixExtentWithBands(extent, scale.count());
  20358. }
  20359. return linearMap(data, normalizedExtent, extent, clamp);
  20360. },
  20361. /**
  20362. * Convert coord to data. Data is the rank if it has a ordinal scale
  20363. * @param {number} coord
  20364. * @param {boolean} clamp
  20365. * @return {number}
  20366. */
  20367. coordToData: function (coord, clamp) {
  20368. var extent = this._extent;
  20369. var scale = this.scale;
  20370. if (this.onBand && scale.type === 'ordinal') {
  20371. extent = extent.slice();
  20372. fixExtentWithBands(extent, scale.count());
  20373. }
  20374. var t = linearMap(coord, extent, normalizedExtent, clamp);
  20375. return this.scale.scale(t);
  20376. },
  20377. /**
  20378. * @return {Array.<number>}
  20379. */
  20380. getTicksCoords: function () {
  20381. if (this.onBand) {
  20382. var bands = this.getBands();
  20383. var coords = [];
  20384. for (var i = 0; i < bands.length; i++) {
  20385. coords.push(bands[i][0]);
  20386. }
  20387. if (bands[i - 1]) {
  20388. coords.push(bands[i - 1][1]);
  20389. }
  20390. return coords;
  20391. }
  20392. else {
  20393. return zrUtil.map(this.scale.getTicks(), this.dataToCoord, this);
  20394. }
  20395. },
  20396. /**
  20397. * Coords of labels are on the ticks or on the middle of bands
  20398. * @return {Array.<number>}
  20399. */
  20400. getLabelsCoords: function () {
  20401. if (this.onBand) {
  20402. var bands = this.getBands();
  20403. var coords = [];
  20404. var band;
  20405. for (var i = 0; i < bands.length; i++) {
  20406. band = bands[i];
  20407. coords.push((band[0] + band[1]) / 2);
  20408. }
  20409. return coords;
  20410. }
  20411. else {
  20412. return zrUtil.map(this.scale.getTicks(), this.dataToCoord, this);
  20413. }
  20414. },
  20415. /**
  20416. * Get bands.
  20417. *
  20418. * If axis has labels [1, 2, 3, 4]. Bands on the axis are
  20419. * |---1---|---2---|---3---|---4---|.
  20420. *
  20421. * @return {Array}
  20422. */
  20423. // FIXME Situation when labels is on ticks
  20424. getBands: function () {
  20425. var extent = this.getExtent();
  20426. var bands = [];
  20427. var len = this.scale.count();
  20428. var start = extent[0];
  20429. var end = extent[1];
  20430. var span = end - start;
  20431. for (var i = 0; i < len; i++) {
  20432. bands.push([
  20433. span * i / len + start,
  20434. span * (i + 1) / len + start
  20435. ]);
  20436. }
  20437. return bands;
  20438. },
  20439. /**
  20440. * Get width of band
  20441. * @return {number}
  20442. */
  20443. getBandWidth: function () {
  20444. var axisExtent = this._extent;
  20445. var dataExtent = this.scale.getExtent();
  20446. var len = dataExtent[1] - dataExtent[0] + (this.onBand ? 1 : 0);
  20447. // Fix #2728, avoid NaN when only one data.
  20448. len === 0 && (len = 1);
  20449. var size = Math.abs(axisExtent[1] - axisExtent[0]);
  20450. return Math.abs(size) / len;
  20451. }
  20452. };
  20453. module.exports = Axis;
  20454. /***/ },
  20455. /* 119 */
  20456. /***/ function(module, exports, __webpack_require__) {
  20457. 'use strict';
  20458. /**
  20459. * Helper function for axisLabelInterval calculation
  20460. */
  20461. var zrUtil = __webpack_require__(3);
  20462. var axisHelper = __webpack_require__(109);
  20463. module.exports = function (axis) {
  20464. var axisModel = axis.model;
  20465. var labelModel = axisModel.getModel('axisLabel');
  20466. var labelInterval = labelModel.get('interval');
  20467. if (!(axis.type === 'category' && labelInterval === 'auto')) {
  20468. return labelInterval === 'auto' ? 0 : labelInterval;
  20469. }
  20470. return axisHelper.getAxisLabelInterval(
  20471. zrUtil.map(axis.scale.getTicks(), axis.dataToCoord, axis),
  20472. axisModel.getFormattedLabels(),
  20473. labelModel.getModel('textStyle').getFont(),
  20474. axis.isHorizontal()
  20475. );
  20476. };
  20477. /***/ },
  20478. /* 120 */
  20479. /***/ function(module, exports, __webpack_require__) {
  20480. 'use strict';
  20481. // Grid 是在有直角坐标系的时候必须要存在的
  20482. // 所以这里也要被 Cartesian2D 依赖
  20483. __webpack_require__(121);
  20484. var ComponentModel = __webpack_require__(19);
  20485. module.exports = ComponentModel.extend({
  20486. type: 'grid',
  20487. dependencies: ['xAxis', 'yAxis'],
  20488. layoutMode: 'box',
  20489. /**
  20490. * @type {module:echarts/coord/cartesian/Grid}
  20491. */
  20492. coordinateSystem: null,
  20493. defaultOption: {
  20494. show: false,
  20495. zlevel: 0,
  20496. z: 0,
  20497. left: '10%',
  20498. top: 60,
  20499. right: '10%',
  20500. bottom: 60,
  20501. // If grid size contain label
  20502. containLabel: false,
  20503. // width: {totalWidth} - left - right,
  20504. // height: {totalHeight} - top - bottom,
  20505. backgroundColor: 'rgba(0,0,0,0)',
  20506. borderWidth: 1,
  20507. borderColor: '#ccc'
  20508. }
  20509. });
  20510. /***/ },
  20511. /* 121 */
  20512. /***/ function(module, exports, __webpack_require__) {
  20513. 'use strict';
  20514. var ComponentModel = __webpack_require__(19);
  20515. var zrUtil = __webpack_require__(3);
  20516. var axisModelCreator = __webpack_require__(122);
  20517. var AxisModel = ComponentModel.extend({
  20518. type: 'cartesian2dAxis',
  20519. /**
  20520. * @type {module:echarts/coord/cartesian/Axis2D}
  20521. */
  20522. axis: null,
  20523. /**
  20524. * @override
  20525. */
  20526. init: function () {
  20527. AxisModel.superApply(this, 'init', arguments);
  20528. this._resetRange();
  20529. },
  20530. /**
  20531. * @override
  20532. */
  20533. mergeOption: function () {
  20534. AxisModel.superApply(this, 'mergeOption', arguments);
  20535. this._resetRange();
  20536. },
  20537. /**
  20538. * @override
  20539. */
  20540. restoreData: function () {
  20541. AxisModel.superApply(this, 'restoreData', arguments);
  20542. this._resetRange();
  20543. },
  20544. /**
  20545. * @public
  20546. * @param {number} rangeStart
  20547. * @param {number} rangeEnd
  20548. */
  20549. setRange: function (rangeStart, rangeEnd) {
  20550. this.option.rangeStart = rangeStart;
  20551. this.option.rangeEnd = rangeEnd;
  20552. },
  20553. /**
  20554. * @public
  20555. * @return {Array.<number|string|Date>}
  20556. */
  20557. getMin: function () {
  20558. var option = this.option;
  20559. return option.rangeStart != null ? option.rangeStart : option.min;
  20560. },
  20561. /**
  20562. * @public
  20563. * @return {Array.<number|string|Date>}
  20564. */
  20565. getMax: function () {
  20566. var option = this.option;
  20567. return option.rangeEnd != null ? option.rangeEnd : option.max;
  20568. },
  20569. /**
  20570. * @public
  20571. * @return {boolean}
  20572. */
  20573. getNeedCrossZero: function () {
  20574. var option = this.option;
  20575. return (option.rangeStart != null || option.rangeEnd != null)
  20576. ? false : !option.scale;
  20577. },
  20578. /**
  20579. * @private
  20580. */
  20581. _resetRange: function () {
  20582. // rangeStart and rangeEnd is readonly.
  20583. this.option.rangeStart = this.option.rangeEnd = null;
  20584. }
  20585. });
  20586. function getAxisType(axisDim, option) {
  20587. // Default axis with data is category axis
  20588. return option.type || (option.data ? 'category' : 'value');
  20589. }
  20590. zrUtil.merge(AxisModel.prototype, __webpack_require__(124));
  20591. var extraOption = {
  20592. gridIndex: 0
  20593. };
  20594. axisModelCreator('x', AxisModel, getAxisType, extraOption);
  20595. axisModelCreator('y', AxisModel, getAxisType, extraOption);
  20596. module.exports = AxisModel;
  20597. /***/ },
  20598. /* 122 */
  20599. /***/ function(module, exports, __webpack_require__) {
  20600. var axisDefault = __webpack_require__(123);
  20601. var zrUtil = __webpack_require__(3);
  20602. var ComponentModel = __webpack_require__(19);
  20603. var layout = __webpack_require__(21);
  20604. // FIXME axisType is fixed ?
  20605. var AXIS_TYPES = ['value', 'category', 'time', 'log'];
  20606. /**
  20607. * Generate sub axis model class
  20608. * @param {string} axisName 'x' 'y' 'radius' 'angle' 'parallel'
  20609. * @param {module:echarts/model/Component} BaseAxisModelClass
  20610. * @param {Function} axisTypeDefaulter
  20611. * @param {Object} [extraDefaultOption]
  20612. */
  20613. module.exports = function (axisName, BaseAxisModelClass, axisTypeDefaulter, extraDefaultOption) {
  20614. zrUtil.each(AXIS_TYPES, function (axisType) {
  20615. BaseAxisModelClass.extend({
  20616. type: axisName + 'Axis.' + axisType,
  20617. mergeDefaultAndTheme: function (option, ecModel) {
  20618. var layoutMode = this.layoutMode;
  20619. var inputPositionParams = layoutMode
  20620. ? layout.getLayoutParams(option) : {};
  20621. var themeModel = ecModel.getTheme();
  20622. zrUtil.merge(option, themeModel.get(axisType + 'Axis'));
  20623. zrUtil.merge(option, this.getDefaultOption());
  20624. option.type = axisTypeDefaulter(axisName, option);
  20625. if (layoutMode) {
  20626. layout.mergeLayoutParam(option, inputPositionParams, layoutMode);
  20627. }
  20628. },
  20629. defaultOption: zrUtil.mergeAll(
  20630. [
  20631. {},
  20632. axisDefault[axisType + 'Axis'],
  20633. extraDefaultOption
  20634. ],
  20635. true
  20636. )
  20637. });
  20638. });
  20639. ComponentModel.registerSubTypeDefaulter(
  20640. axisName + 'Axis',
  20641. zrUtil.curry(axisTypeDefaulter, axisName)
  20642. );
  20643. };
  20644. /***/ },
  20645. /* 123 */
  20646. /***/ function(module, exports, __webpack_require__) {
  20647. var zrUtil = __webpack_require__(3);
  20648. var defaultOption = {
  20649. show: true,
  20650. zlevel: 0, // 一级层叠
  20651. z: 0, // 二级层叠
  20652. // 反向坐标轴
  20653. inverse: false,
  20654. // 坐标轴名字,默认为空
  20655. name: '',
  20656. // 坐标轴名字位置,支持'start' | 'middle' | 'end'
  20657. nameLocation: 'end',
  20658. // 坐标轴文字样式,默认取全局样式
  20659. nameTextStyle: {},
  20660. // 文字与轴线距离
  20661. nameGap: 15,
  20662. // 是否能触发鼠标事件
  20663. silent: true,
  20664. // 坐标轴线
  20665. axisLine: {
  20666. // 默认显示,属性show控制显示与否
  20667. show: true,
  20668. onZero: true,
  20669. // 属性lineStyle控制线条样式
  20670. lineStyle: {
  20671. color: '#333',
  20672. width: 1,
  20673. type: 'solid'
  20674. }
  20675. },
  20676. // 坐标轴小标记
  20677. axisTick: {
  20678. // 属性show控制显示与否,默认显示
  20679. show: true,
  20680. // 控制小标记是否在grid里
  20681. inside: false,
  20682. // 属性length控制线长
  20683. length: 5,
  20684. // 属性lineStyle控制线条样式
  20685. lineStyle: {
  20686. color: '#333',
  20687. width: 1
  20688. }
  20689. },
  20690. // 坐标轴文本标签,详见axis.axisLabel
  20691. axisLabel: {
  20692. show: true,
  20693. // 控制文本标签是否在grid里
  20694. inside: false,
  20695. rotate: 0,
  20696. margin: 8,
  20697. // formatter: null,
  20698. // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  20699. textStyle: {
  20700. color: '#333',
  20701. fontSize: 12
  20702. }
  20703. },
  20704. // 分隔线
  20705. splitLine: {
  20706. // 默认显示,属性show控制显示与否
  20707. show: true,
  20708. // 属性lineStyle(详见lineStyle)控制线条样式
  20709. lineStyle: {
  20710. color: ['#ccc'],
  20711. width: 1,
  20712. type: 'solid'
  20713. }
  20714. },
  20715. // 分隔区域
  20716. splitArea: {
  20717. // 默认不显示,属性show控制显示与否
  20718. show: false,
  20719. // 属性areaStyle(详见areaStyle)控制区域样式
  20720. areaStyle: {
  20721. color: ['rgba(250,250,250,0.3)','rgba(200,200,200,0.3)']
  20722. }
  20723. }
  20724. };
  20725. var categoryAxis = zrUtil.merge({
  20726. // 类目起始和结束两端空白策略
  20727. boundaryGap: true,
  20728. // 坐标轴小标记
  20729. axisTick: {
  20730. interval: 'auto'
  20731. },
  20732. // 坐标轴文本标签,详见axis.axisLabel
  20733. axisLabel: {
  20734. interval: 'auto'
  20735. }
  20736. }, defaultOption);
  20737. var valueAxis = zrUtil.defaults({
  20738. // 数值起始和结束两端空白策略
  20739. boundaryGap: [0, 0],
  20740. // 最小值, 设置成 'dataMin' 则从数据中计算最小值
  20741. // min: null,
  20742. // 最大值,设置成 'dataMax' 则从数据中计算最大值
  20743. // max: null,
  20744. // Readonly prop, specifies start value of the range when using data zoom.
  20745. // rangeStart: null
  20746. // Readonly prop, specifies end value of the range when using data zoom.
  20747. // rangeEnd: null
  20748. // 脱离0值比例,放大聚焦到最终_min,_max区间
  20749. // scale: false,
  20750. // 分割段数,默认为5
  20751. splitNumber: 5
  20752. // Minimum interval
  20753. // minInterval: null
  20754. }, defaultOption);
  20755. // FIXME
  20756. var timeAxis = zrUtil.defaults({
  20757. scale: true,
  20758. min: 'dataMin',
  20759. max: 'dataMax'
  20760. }, valueAxis);
  20761. var logAxis = zrUtil.defaults({}, valueAxis);
  20762. logAxis.scale = true;
  20763. module.exports = {
  20764. categoryAxis: categoryAxis,
  20765. valueAxis: valueAxis,
  20766. timeAxis: timeAxis,
  20767. logAxis: logAxis
  20768. };
  20769. /***/ },
  20770. /* 124 */
  20771. /***/ function(module, exports, __webpack_require__) {
  20772. var zrUtil = __webpack_require__(3);
  20773. var axisHelper = __webpack_require__(109);
  20774. function getName(obj) {
  20775. if (zrUtil.isObject(obj) && obj.value != null) {
  20776. return obj.value;
  20777. }
  20778. else {
  20779. return obj;
  20780. }
  20781. }
  20782. /**
  20783. * Get categories
  20784. */
  20785. function getCategories() {
  20786. return this.get('type') === 'category'
  20787. && zrUtil.map(this.get('data'), getName);
  20788. }
  20789. /**
  20790. * Format labels
  20791. * @return {Array.<string>}
  20792. */
  20793. function getFormattedLabels() {
  20794. return axisHelper.getFormattedLabels(
  20795. this.axis,
  20796. this.get('axisLabel.formatter')
  20797. );
  20798. }
  20799. module.exports = {
  20800. getFormattedLabels: getFormattedLabels,
  20801. getCategories: getCategories
  20802. };
  20803. /***/ },
  20804. /* 125 */
  20805. /***/ function(module, exports, __webpack_require__) {
  20806. 'use strict';
  20807. // TODO boundaryGap
  20808. __webpack_require__(121);
  20809. __webpack_require__(126);
  20810. /***/ },
  20811. /* 126 */
  20812. /***/ function(module, exports, __webpack_require__) {
  20813. var zrUtil = __webpack_require__(3);
  20814. var graphic = __webpack_require__(42);
  20815. var AxisBuilder = __webpack_require__(127);
  20816. var ifIgnoreOnTick = AxisBuilder.ifIgnoreOnTick;
  20817. var getInterval = AxisBuilder.getInterval;
  20818. var axisBuilderAttrs = [
  20819. 'axisLine', 'axisLabel', 'axisTick', 'axisName'
  20820. ];
  20821. var selfBuilderAttrs = [
  20822. 'splitLine', 'splitArea'
  20823. ];
  20824. var AxisView = __webpack_require__(1).extendComponentView({
  20825. type: 'axis',
  20826. render: function (axisModel, ecModel) {
  20827. this.group.removeAll();
  20828. if (!axisModel.get('show')) {
  20829. return;
  20830. }
  20831. var gridModel = ecModel.getComponent('grid', axisModel.get('gridIndex'));
  20832. var layout = layoutAxis(gridModel, axisModel);
  20833. var axisBuilder = new AxisBuilder(axisModel, layout);
  20834. zrUtil.each(axisBuilderAttrs, axisBuilder.add, axisBuilder);
  20835. this.group.add(axisBuilder.getGroup());
  20836. zrUtil.each(selfBuilderAttrs, function (name) {
  20837. if (axisModel.get(name +'.show')) {
  20838. this['_' + name](axisModel, gridModel, layout.labelInterval);
  20839. }
  20840. }, this);
  20841. },
  20842. /**
  20843. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  20844. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  20845. * @param {number|Function} labelInterval
  20846. * @private
  20847. */
  20848. _splitLine: function (axisModel, gridModel, labelInterval) {
  20849. var axis = axisModel.axis;
  20850. var splitLineModel = axisModel.getModel('splitLine');
  20851. var lineStyleModel = splitLineModel.getModel('lineStyle');
  20852. var lineWidth = lineStyleModel.get('width');
  20853. var lineColors = lineStyleModel.get('color');
  20854. var lineInterval = getInterval(splitLineModel, labelInterval);
  20855. lineColors = zrUtil.isArray(lineColors) ? lineColors : [lineColors];
  20856. var gridRect = gridModel.coordinateSystem.getRect();
  20857. var isHorizontal = axis.isHorizontal();
  20858. var splitLines = [];
  20859. var lineCount = 0;
  20860. var ticksCoords = axis.getTicksCoords();
  20861. var p1 = [];
  20862. var p2 = [];
  20863. for (var i = 0; i < ticksCoords.length; i++) {
  20864. if (ifIgnoreOnTick(axis, i, lineInterval)) {
  20865. continue;
  20866. }
  20867. var tickCoord = axis.toGlobalCoord(ticksCoords[i]);
  20868. if (isHorizontal) {
  20869. p1[0] = tickCoord;
  20870. p1[1] = gridRect.y;
  20871. p2[0] = tickCoord;
  20872. p2[1] = gridRect.y + gridRect.height;
  20873. }
  20874. else {
  20875. p1[0] = gridRect.x;
  20876. p1[1] = tickCoord;
  20877. p2[0] = gridRect.x + gridRect.width;
  20878. p2[1] = tickCoord;
  20879. }
  20880. var colorIndex = (lineCount++) % lineColors.length;
  20881. splitLines[colorIndex] = splitLines[colorIndex] || [];
  20882. splitLines[colorIndex].push(new graphic.Line(graphic.subPixelOptimizeLine({
  20883. shape: {
  20884. x1: p1[0],
  20885. y1: p1[1],
  20886. x2: p2[0],
  20887. y2: p2[1]
  20888. },
  20889. style: {
  20890. lineWidth: lineWidth
  20891. },
  20892. silent: true
  20893. })));
  20894. }
  20895. // Simple optimization
  20896. // Batching the lines if color are the same
  20897. var lineStyle = lineStyleModel.getLineStyle();
  20898. for (var i = 0; i < splitLines.length; i++) {
  20899. this.group.add(graphic.mergePath(splitLines[i], {
  20900. style: zrUtil.defaults({
  20901. stroke: lineColors[i % lineColors.length]
  20902. }, lineStyle),
  20903. silent: true
  20904. }));
  20905. }
  20906. },
  20907. /**
  20908. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  20909. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  20910. * @param {number|Function} labelInterval
  20911. * @private
  20912. */
  20913. _splitArea: function (axisModel, gridModel, labelInterval) {
  20914. var axis = axisModel.axis;
  20915. var splitAreaModel = axisModel.getModel('splitArea');
  20916. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  20917. var areaColors = areaStyleModel.get('color');
  20918. var gridRect = gridModel.coordinateSystem.getRect();
  20919. var ticksCoords = axis.getTicksCoords();
  20920. var prevX = axis.toGlobalCoord(ticksCoords[0]);
  20921. var prevY = axis.toGlobalCoord(ticksCoords[0]);
  20922. var splitAreaRects = [];
  20923. var count = 0;
  20924. var areaInterval = getInterval(splitAreaModel, labelInterval);
  20925. areaColors = zrUtil.isArray(areaColors) ? areaColors : [areaColors];
  20926. for (var i = 1; i < ticksCoords.length; i++) {
  20927. if (ifIgnoreOnTick(axis, i, areaInterval)) {
  20928. continue;
  20929. }
  20930. var tickCoord = axis.toGlobalCoord(ticksCoords[i]);
  20931. var x;
  20932. var y;
  20933. var width;
  20934. var height;
  20935. if (axis.isHorizontal()) {
  20936. x = prevX;
  20937. y = gridRect.y;
  20938. width = tickCoord - x;
  20939. height = gridRect.height;
  20940. }
  20941. else {
  20942. x = gridRect.x;
  20943. y = prevY;
  20944. width = gridRect.width;
  20945. height = tickCoord - y;
  20946. }
  20947. var colorIndex = (count++) % areaColors.length;
  20948. splitAreaRects[colorIndex] = splitAreaRects[colorIndex] || [];
  20949. splitAreaRects[colorIndex].push(new graphic.Rect({
  20950. shape: {
  20951. x: x,
  20952. y: y,
  20953. width: width,
  20954. height: height
  20955. },
  20956. silent: true
  20957. }));
  20958. prevX = x + width;
  20959. prevY = y + height;
  20960. }
  20961. // Simple optimization
  20962. // Batching the rects if color are the same
  20963. var areaStyle = areaStyleModel.getAreaStyle();
  20964. for (var i = 0; i < splitAreaRects.length; i++) {
  20965. this.group.add(graphic.mergePath(splitAreaRects[i], {
  20966. style: zrUtil.defaults({
  20967. fill: areaColors[i % areaColors.length]
  20968. }, areaStyle),
  20969. silent: true
  20970. }));
  20971. }
  20972. }
  20973. });
  20974. AxisView.extend({
  20975. type: 'xAxis'
  20976. });
  20977. AxisView.extend({
  20978. type: 'yAxis'
  20979. });
  20980. /**
  20981. * @inner
  20982. */
  20983. function layoutAxis(gridModel, axisModel) {
  20984. var grid = gridModel.coordinateSystem;
  20985. var axis = axisModel.axis;
  20986. var layout = {};
  20987. var rawAxisPosition = axis.position;
  20988. var axisPosition = axis.onZero ? 'onZero' : rawAxisPosition;
  20989. var axisDim = axis.dim;
  20990. // [left, right, top, bottom]
  20991. var rect = grid.getRect();
  20992. var rectBound = [rect.x, rect.x + rect.width, rect.y, rect.y + rect.height];
  20993. var posMap = {
  20994. x: {top: rectBound[2], bottom: rectBound[3]},
  20995. y: {left: rectBound[0], right: rectBound[1]}
  20996. };
  20997. posMap.x.onZero = Math.max(Math.min(getZero('y'), posMap.x.bottom), posMap.x.top);
  20998. posMap.y.onZero = Math.max(Math.min(getZero('x'), posMap.y.right), posMap.y.left);
  20999. function getZero(dim, val) {
  21000. var theAxis = grid.getAxis(dim);
  21001. return theAxis.toGlobalCoord(theAxis.dataToCoord(0));
  21002. }
  21003. // Axis position
  21004. layout.position = [
  21005. axisDim === 'y' ? posMap.y[axisPosition] : rectBound[0],
  21006. axisDim === 'x' ? posMap.x[axisPosition] : rectBound[3]
  21007. ];
  21008. // Axis rotation
  21009. var r = {x: 0, y: 1};
  21010. layout.rotation = Math.PI / 2 * r[axisDim];
  21011. // Tick and label direction, x y is axisDim
  21012. var dirMap = {top: -1, bottom: 1, left: -1, right: 1};
  21013. layout.labelDirection = layout.tickDirection = layout.nameDirection = dirMap[rawAxisPosition];
  21014. if (axis.onZero) {
  21015. layout.labelOffset = posMap[axisDim][rawAxisPosition] - posMap[axisDim].onZero;
  21016. }
  21017. if (axisModel.getModel('axisTick').get('inside')) {
  21018. layout.tickDirection = -layout.tickDirection;
  21019. }
  21020. if (axisModel.getModel('axisLabel').get('inside')) {
  21021. layout.labelDirection = -layout.labelDirection;
  21022. }
  21023. // Special label rotation
  21024. var labelRotation = axisModel.getModel('axisLabel').get('rotate');
  21025. layout.labelRotation = axisPosition === 'top' ? -labelRotation : labelRotation;
  21026. // label interval when auto mode.
  21027. layout.labelInterval = axis.getLabelInterval();
  21028. // Over splitLine and splitArea
  21029. layout.z2 = 1;
  21030. return layout;
  21031. }
  21032. /***/ },
  21033. /* 127 */
  21034. /***/ function(module, exports, __webpack_require__) {
  21035. var zrUtil = __webpack_require__(3);
  21036. var graphic = __webpack_require__(42);
  21037. var Model = __webpack_require__(8);
  21038. var numberUtil = __webpack_require__(7);
  21039. var remRadian = numberUtil.remRadian;
  21040. var isRadianAroundZero = numberUtil.isRadianAroundZero;
  21041. var PI = Math.PI;
  21042. function makeAxisEventDataBase(axisModel) {
  21043. var eventData = {
  21044. componentType: axisModel.mainType
  21045. };
  21046. eventData[axisModel.mainType + 'Index'] = axisModel.componentIndex;
  21047. return eventData;
  21048. }
  21049. /**
  21050. * A final axis is translated and rotated from a "standard axis".
  21051. * So opt.position and opt.rotation is required.
  21052. *
  21053. * A standard axis is and axis from [0, 0] to [0, axisExtent[1]],
  21054. * for example: (0, 0) ------------> (0, 50)
  21055. *
  21056. * nameDirection or tickDirection or labelDirection is 1 means tick
  21057. * or label is below the standard axis, whereas is -1 means above
  21058. * the standard axis. labelOffset means offset between label and axis,
  21059. * which is useful when 'onZero', where axisLabel is in the grid and
  21060. * label in outside grid.
  21061. *
  21062. * Tips: like always,
  21063. * positive rotation represents anticlockwise, and negative rotation
  21064. * represents clockwise.
  21065. * The direction of position coordinate is the same as the direction
  21066. * of screen coordinate.
  21067. *
  21068. * Do not need to consider axis 'inverse', which is auto processed by
  21069. * axis extent.
  21070. *
  21071. * @param {module:zrender/container/Group} group
  21072. * @param {Object} axisModel
  21073. * @param {Object} opt Standard axis parameters.
  21074. * @param {Array.<number>} opt.position [x, y]
  21075. * @param {number} opt.rotation by radian
  21076. * @param {number} [opt.nameDirection=1] 1 or -1 Used when nameLocation is 'middle'.
  21077. * @param {number} [opt.tickDirection=1] 1 or -1
  21078. * @param {number} [opt.labelDirection=1] 1 or -1
  21079. * @param {number} [opt.labelOffset=0] Usefull when onZero.
  21080. * @param {string} [opt.axisName] default get from axisModel.
  21081. * @param {number} [opt.labelRotation] by degree, default get from axisModel.
  21082. * @param {number} [opt.labelInterval] Default label interval when label
  21083. * interval from model is null or 'auto'.
  21084. * @param {number} [opt.strokeContainThreshold] Default label interval when label
  21085. * @param {number} [opt.axisLineSilent=true] If axis line is silent
  21086. */
  21087. var AxisBuilder = function (axisModel, opt) {
  21088. /**
  21089. * @readOnly
  21090. */
  21091. this.opt = opt;
  21092. /**
  21093. * @readOnly
  21094. */
  21095. this.axisModel = axisModel;
  21096. // Default value
  21097. zrUtil.defaults(
  21098. opt,
  21099. {
  21100. labelOffset: 0,
  21101. nameDirection: 1,
  21102. tickDirection: 1,
  21103. labelDirection: 1,
  21104. silent: true
  21105. }
  21106. );
  21107. /**
  21108. * @readOnly
  21109. */
  21110. this.group = new graphic.Group({
  21111. position: opt.position.slice(),
  21112. rotation: opt.rotation
  21113. });
  21114. };
  21115. AxisBuilder.prototype = {
  21116. constructor: AxisBuilder,
  21117. hasBuilder: function (name) {
  21118. return !!builders[name];
  21119. },
  21120. add: function (name) {
  21121. builders[name].call(this);
  21122. },
  21123. getGroup: function () {
  21124. return this.group;
  21125. }
  21126. };
  21127. var builders = {
  21128. /**
  21129. * @private
  21130. */
  21131. axisLine: function () {
  21132. var opt = this.opt;
  21133. var axisModel = this.axisModel;
  21134. if (!axisModel.get('axisLine.show')) {
  21135. return;
  21136. }
  21137. var extent = this.axisModel.axis.getExtent();
  21138. this.group.add(new graphic.Line({
  21139. shape: {
  21140. x1: extent[0],
  21141. y1: 0,
  21142. x2: extent[1],
  21143. y2: 0
  21144. },
  21145. style: zrUtil.extend(
  21146. {lineCap: 'round'},
  21147. axisModel.getModel('axisLine.lineStyle').getLineStyle()
  21148. ),
  21149. strokeContainThreshold: opt.strokeContainThreshold,
  21150. silent: !!opt.axisLineSilent,
  21151. z2: 1
  21152. }));
  21153. },
  21154. /**
  21155. * @private
  21156. */
  21157. axisTick: function () {
  21158. var axisModel = this.axisModel;
  21159. if (!axisModel.get('axisTick.show')) {
  21160. return;
  21161. }
  21162. var axis = axisModel.axis;
  21163. var tickModel = axisModel.getModel('axisTick');
  21164. var opt = this.opt;
  21165. var lineStyleModel = tickModel.getModel('lineStyle');
  21166. var tickLen = tickModel.get('length');
  21167. var tickInterval = getInterval(tickModel, opt.labelInterval);
  21168. var ticksCoords = axis.getTicksCoords();
  21169. var tickLines = [];
  21170. for (var i = 0; i < ticksCoords.length; i++) {
  21171. // Only ordinal scale support tick interval
  21172. if (ifIgnoreOnTick(axis, i, tickInterval)) {
  21173. continue;
  21174. }
  21175. var tickCoord = ticksCoords[i];
  21176. // Tick line
  21177. tickLines.push(new graphic.Line(graphic.subPixelOptimizeLine({
  21178. shape: {
  21179. x1: tickCoord,
  21180. y1: 0,
  21181. x2: tickCoord,
  21182. y2: opt.tickDirection * tickLen
  21183. },
  21184. style: {
  21185. lineWidth: lineStyleModel.get('width')
  21186. },
  21187. silent: true
  21188. })));
  21189. }
  21190. this.group.add(graphic.mergePath(tickLines, {
  21191. style: lineStyleModel.getLineStyle(),
  21192. z2: 2,
  21193. silent: true
  21194. }));
  21195. },
  21196. /**
  21197. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  21198. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  21199. * @private
  21200. */
  21201. axisLabel: function () {
  21202. var axisModel = this.axisModel;
  21203. if (!axisModel.get('axisLabel.show')) {
  21204. return;
  21205. }
  21206. var opt = this.opt;
  21207. var axis = axisModel.axis;
  21208. var labelModel = axisModel.getModel('axisLabel');
  21209. var textStyleModel = labelModel.getModel('textStyle');
  21210. var labelMargin = labelModel.get('margin');
  21211. var ticks = axis.scale.getTicks();
  21212. var labels = axisModel.getFormattedLabels();
  21213. // Special label rotate.
  21214. var labelRotation = opt.labelRotation;
  21215. if (labelRotation == null) {
  21216. labelRotation = labelModel.get('rotate') || 0;
  21217. }
  21218. // To radian.
  21219. labelRotation = labelRotation * PI / 180;
  21220. var labelLayout = innerTextLayout(opt, labelRotation, opt.labelDirection);
  21221. var categoryData = axisModel.get('data');
  21222. var textEls = [];
  21223. var isSilent = axisModel.get('silent');
  21224. for (var i = 0; i < ticks.length; i++) {
  21225. if (ifIgnoreOnTick(axis, i, opt.labelInterval)) {
  21226. continue;
  21227. }
  21228. var itemTextStyleModel = textStyleModel;
  21229. if (categoryData && categoryData[i] && categoryData[i].textStyle) {
  21230. itemTextStyleModel = new Model(
  21231. categoryData[i].textStyle, textStyleModel, axisModel.ecModel
  21232. );
  21233. }
  21234. var textColor = itemTextStyleModel.getTextColor();
  21235. var tickCoord = axis.dataToCoord(ticks[i]);
  21236. var pos = [
  21237. tickCoord,
  21238. opt.labelOffset + opt.labelDirection * labelMargin
  21239. ];
  21240. var labelBeforeFormat = axis.scale.getLabel(ticks[i]);
  21241. var textEl = new graphic.Text({
  21242. style: {
  21243. text: labels[i],
  21244. textAlign: itemTextStyleModel.get('align', true) || labelLayout.textAlign,
  21245. textVerticalAlign: itemTextStyleModel.get('baseline', true) || labelLayout.verticalAlign,
  21246. textFont: itemTextStyleModel.getFont(),
  21247. fill: typeof textColor === 'function' ? textColor(labelBeforeFormat) : textColor
  21248. },
  21249. position: pos,
  21250. rotation: labelLayout.rotation,
  21251. silent: isSilent,
  21252. z2: 10
  21253. });
  21254. // Pack data for mouse event
  21255. textEl.eventData = makeAxisEventDataBase(axisModel);
  21256. textEl.eventData.targetType = 'axisLabel';
  21257. textEl.eventData.value = labelBeforeFormat;
  21258. textEls.push(textEl);
  21259. this.group.add(textEl);
  21260. }
  21261. function isTwoLabelOverlapped(current, next) {
  21262. var firstRect = current && current.getBoundingRect().clone();
  21263. var nextRect = next && next.getBoundingRect().clone();
  21264. if (firstRect && nextRect) {
  21265. firstRect.applyTransform(current.getLocalTransform());
  21266. nextRect.applyTransform(next.getLocalTransform());
  21267. return firstRect.intersect(nextRect);
  21268. }
  21269. }
  21270. if (axis.type !== 'category') {
  21271. // If min or max are user set, we need to check
  21272. // If the tick on min(max) are overlap on their neighbour tick
  21273. // If they are overlapped, we need to hide the min(max) tick label
  21274. if (axisModel.getMin ? axisModel.getMin() : axisModel.get('min')) {
  21275. var firstLabel = textEls[0];
  21276. var nextLabel = textEls[1];
  21277. if (isTwoLabelOverlapped(firstLabel, nextLabel)) {
  21278. firstLabel.ignore = true;
  21279. }
  21280. }
  21281. if (axisModel.getMax ? axisModel.getMax() : axisModel.get('max')) {
  21282. var lastLabel = textEls[textEls.length - 1];
  21283. var prevLabel = textEls[textEls.length - 2];
  21284. if (isTwoLabelOverlapped(prevLabel, lastLabel)) {
  21285. lastLabel.ignore = true;
  21286. }
  21287. }
  21288. }
  21289. },
  21290. /**
  21291. * @private
  21292. */
  21293. axisName: function () {
  21294. var opt = this.opt;
  21295. var axisModel = this.axisModel;
  21296. var name = this.opt.axisName;
  21297. // If name is '', do not get name from axisMode.
  21298. if (name == null) {
  21299. name = axisModel.get('name');
  21300. }
  21301. if (!name) {
  21302. return;
  21303. }
  21304. var nameLocation = axisModel.get('nameLocation');
  21305. var nameDirection = opt.nameDirection;
  21306. var textStyleModel = axisModel.getModel('nameTextStyle');
  21307. var gap = axisModel.get('nameGap') || 0;
  21308. var extent = this.axisModel.axis.getExtent();
  21309. var gapSignal = extent[0] > extent[1] ? -1 : 1;
  21310. var pos = [
  21311. nameLocation === 'start'
  21312. ? extent[0] - gapSignal * gap
  21313. : nameLocation === 'end'
  21314. ? extent[1] + gapSignal * gap
  21315. : (extent[0] + extent[1]) / 2, // 'middle'
  21316. // Reuse labelOffset.
  21317. nameLocation === 'middle' ? opt.labelOffset + nameDirection * gap : 0
  21318. ];
  21319. var labelLayout;
  21320. if (nameLocation === 'middle') {
  21321. labelLayout = innerTextLayout(opt, opt.rotation, nameDirection);
  21322. }
  21323. else {
  21324. labelLayout = endTextLayout(opt, nameLocation, extent);
  21325. }
  21326. var textEl = new graphic.Text({
  21327. style: {
  21328. text: name,
  21329. textFont: textStyleModel.getFont(),
  21330. fill: textStyleModel.getTextColor()
  21331. || axisModel.get('axisLine.lineStyle.color'),
  21332. textAlign: labelLayout.textAlign,
  21333. textVerticalAlign: labelLayout.verticalAlign
  21334. },
  21335. position: pos,
  21336. rotation: labelLayout.rotation,
  21337. silent: axisModel.get('silent'),
  21338. z2: 1
  21339. });
  21340. textEl.eventData = makeAxisEventDataBase(axisModel);
  21341. textEl.eventData.targetType = 'axisName';
  21342. textEl.eventData.name = name;
  21343. this.group.add(textEl);
  21344. }
  21345. };
  21346. /**
  21347. * @inner
  21348. */
  21349. function innerTextLayout(opt, textRotation, direction) {
  21350. var rotationDiff = remRadian(textRotation - opt.rotation);
  21351. var textAlign;
  21352. var verticalAlign;
  21353. if (isRadianAroundZero(rotationDiff)) { // Label is parallel with axis line.
  21354. verticalAlign = direction > 0 ? 'top' : 'bottom';
  21355. textAlign = 'center';
  21356. }
  21357. else if (isRadianAroundZero(rotationDiff - PI)) { // Label is inverse parallel with axis line.
  21358. verticalAlign = direction > 0 ? 'bottom' : 'top';
  21359. textAlign = 'center';
  21360. }
  21361. else {
  21362. verticalAlign = 'middle';
  21363. if (rotationDiff > 0 && rotationDiff < PI) {
  21364. textAlign = direction > 0 ? 'right' : 'left';
  21365. }
  21366. else {
  21367. textAlign = direction > 0 ? 'left' : 'right';
  21368. }
  21369. }
  21370. return {
  21371. rotation: rotationDiff,
  21372. textAlign: textAlign,
  21373. verticalAlign: verticalAlign
  21374. };
  21375. }
  21376. /**
  21377. * @inner
  21378. */
  21379. function endTextLayout(opt, textPosition, extent) {
  21380. var rotationDiff = remRadian(-opt.rotation);
  21381. var textAlign;
  21382. var verticalAlign;
  21383. var inverse = extent[0] > extent[1];
  21384. var onLeft = (textPosition === 'start' && !inverse)
  21385. || (textPosition !== 'start' && inverse);
  21386. if (isRadianAroundZero(rotationDiff - PI / 2)) {
  21387. verticalAlign = onLeft ? 'bottom' : 'top';
  21388. textAlign = 'center';
  21389. }
  21390. else if (isRadianAroundZero(rotationDiff - PI * 1.5)) {
  21391. verticalAlign = onLeft ? 'top' : 'bottom';
  21392. textAlign = 'center';
  21393. }
  21394. else {
  21395. verticalAlign = 'middle';
  21396. if (rotationDiff < PI * 1.5 && rotationDiff > PI / 2) {
  21397. textAlign = onLeft ? 'left' : 'right';
  21398. }
  21399. else {
  21400. textAlign = onLeft ? 'right' : 'left';
  21401. }
  21402. }
  21403. return {
  21404. rotation: rotationDiff,
  21405. textAlign: textAlign,
  21406. verticalAlign: verticalAlign
  21407. };
  21408. }
  21409. /**
  21410. * @static
  21411. */
  21412. var ifIgnoreOnTick = AxisBuilder.ifIgnoreOnTick = function (axis, i, interval) {
  21413. var rawTick;
  21414. var scale = axis.scale;
  21415. return scale.type === 'ordinal'
  21416. && (
  21417. typeof interval === 'function'
  21418. ? (
  21419. rawTick = scale.getTicks()[i],
  21420. !interval(rawTick, scale.getLabel(rawTick))
  21421. )
  21422. : i % (interval + 1)
  21423. );
  21424. };
  21425. /**
  21426. * @static
  21427. */
  21428. var getInterval = AxisBuilder.getInterval = function (model, labelInterval) {
  21429. var interval = model.get('interval');
  21430. if (interval == null || interval == 'auto') {
  21431. interval = labelInterval;
  21432. }
  21433. return interval;
  21434. };
  21435. module.exports = AxisBuilder;
  21436. /***/ },
  21437. /* 128 */
  21438. /***/ function(module, exports, __webpack_require__) {
  21439. var zrUtil = __webpack_require__(3);
  21440. __webpack_require__(108);
  21441. __webpack_require__(129);
  21442. __webpack_require__(130);
  21443. var barLayoutGrid = __webpack_require__(132);
  21444. var echarts = __webpack_require__(1);
  21445. echarts.registerLayout(zrUtil.curry(barLayoutGrid, 'bar'));
  21446. // Visual coding for legend
  21447. echarts.registerVisualCoding('chart', function (ecModel) {
  21448. ecModel.eachSeriesByType('bar', function (seriesModel) {
  21449. var data = seriesModel.getData();
  21450. data.setVisual('legendSymbol', 'roundRect');
  21451. });
  21452. });
  21453. // In case developer forget to include grid component
  21454. __webpack_require__(107);
  21455. /***/ },
  21456. /* 129 */
  21457. /***/ function(module, exports, __webpack_require__) {
  21458. 'use strict';
  21459. var SeriesModel = __webpack_require__(27);
  21460. var createListFromArray = __webpack_require__(94);
  21461. module.exports = SeriesModel.extend({
  21462. type: 'series.bar',
  21463. dependencies: ['grid', 'polar'],
  21464. getInitialData: function (option, ecModel) {
  21465. return createListFromArray(option.data, this, ecModel);
  21466. },
  21467. getMarkerPosition: function (value) {
  21468. var coordSys = this.coordinateSystem;
  21469. if (coordSys) {
  21470. var pt = coordSys.dataToPoint(value);
  21471. var data = this.getData();
  21472. var offset = data.getLayout('offset');
  21473. var size = data.getLayout('size');
  21474. var offsetIndex = coordSys.getBaseAxis().isHorizontal() ? 0 : 1;
  21475. pt[offsetIndex] += offset + size / 2;
  21476. return pt;
  21477. }
  21478. return [NaN, NaN];
  21479. },
  21480. defaultOption: {
  21481. zlevel: 0, // 一级层叠
  21482. z: 2, // 二级层叠
  21483. coordinateSystem: 'cartesian2d',
  21484. legendHoverLink: true,
  21485. // stack: null
  21486. // Cartesian coordinate system
  21487. xAxisIndex: 0,
  21488. yAxisIndex: 0,
  21489. // 最小高度改为0
  21490. barMinHeight: 0,
  21491. // barMaxWidth: null,
  21492. // 默认自适应
  21493. // barWidth: null,
  21494. // 柱间距离,默认为柱形宽度的30%,可设固定值
  21495. // barGap: '30%',
  21496. // 类目间柱形距离,默认为类目间距的20%,可设固定值
  21497. // barCategoryGap: '20%',
  21498. // label: {
  21499. // normal: {
  21500. // show: false
  21501. // }
  21502. // },
  21503. itemStyle: {
  21504. normal: {
  21505. // color: '各异',
  21506. // 柱条边线
  21507. barBorderColor: '#fff',
  21508. // 柱条边线线宽,单位px,默认为1
  21509. barBorderWidth: 0
  21510. },
  21511. emphasis: {
  21512. // color: '各异',
  21513. // 柱条边线
  21514. barBorderColor: '#fff',
  21515. // 柱条边线线宽,单位px,默认为1
  21516. barBorderWidth: 0
  21517. }
  21518. }
  21519. }
  21520. });
  21521. /***/ },
  21522. /* 130 */
  21523. /***/ function(module, exports, __webpack_require__) {
  21524. 'use strict';
  21525. var zrUtil = __webpack_require__(3);
  21526. var graphic = __webpack_require__(42);
  21527. zrUtil.extend(__webpack_require__(8).prototype, __webpack_require__(131));
  21528. function fixLayoutWithLineWidth(layout, lineWidth) {
  21529. var signX = layout.width > 0 ? 1 : -1;
  21530. var signY = layout.height > 0 ? 1 : -1;
  21531. // In case width or height are too small.
  21532. lineWidth = Math.min(lineWidth, Math.abs(layout.width), Math.abs(layout.height));
  21533. layout.x += signX * lineWidth / 2;
  21534. layout.y += signY * lineWidth / 2;
  21535. layout.width -= signX * lineWidth;
  21536. layout.height -= signY * lineWidth;
  21537. }
  21538. module.exports = __webpack_require__(1).extendChartView({
  21539. type: 'bar',
  21540. render: function (seriesModel, ecModel, api) {
  21541. var coordinateSystemType = seriesModel.get('coordinateSystem');
  21542. if (coordinateSystemType === 'cartesian2d') {
  21543. this._renderOnCartesian(seriesModel, ecModel, api);
  21544. }
  21545. return this.group;
  21546. },
  21547. _renderOnCartesian: function (seriesModel, ecModel, api) {
  21548. var group = this.group;
  21549. var data = seriesModel.getData();
  21550. var oldData = this._data;
  21551. var cartesian = seriesModel.coordinateSystem;
  21552. var baseAxis = cartesian.getBaseAxis();
  21553. var isHorizontal = baseAxis.isHorizontal();
  21554. var enableAnimation = seriesModel.get('animation');
  21555. var barBorderWidthQuery = ['itemStyle', 'normal', 'barBorderWidth'];
  21556. function createRect(dataIndex, isUpdate) {
  21557. var layout = data.getItemLayout(dataIndex);
  21558. var lineWidth = data.getItemModel(dataIndex).get(barBorderWidthQuery) || 0;
  21559. fixLayoutWithLineWidth(layout, lineWidth);
  21560. var rect = new graphic.Rect({
  21561. shape: zrUtil.extend({}, layout)
  21562. });
  21563. // Animation
  21564. if (enableAnimation) {
  21565. var rectShape = rect.shape;
  21566. var animateProperty = isHorizontal ? 'height' : 'width';
  21567. var animateTarget = {};
  21568. rectShape[animateProperty] = 0;
  21569. animateTarget[animateProperty] = layout[animateProperty];
  21570. graphic[isUpdate? 'updateProps' : 'initProps'](rect, {
  21571. shape: animateTarget
  21572. }, seriesModel, dataIndex);
  21573. }
  21574. return rect;
  21575. }
  21576. data.diff(oldData)
  21577. .add(function (dataIndex) {
  21578. // 空数据
  21579. if (!data.hasValue(dataIndex)) {
  21580. return;
  21581. }
  21582. var rect = createRect(dataIndex);
  21583. data.setItemGraphicEl(dataIndex, rect);
  21584. group.add(rect);
  21585. })
  21586. .update(function (newIndex, oldIndex) {
  21587. var rect = oldData.getItemGraphicEl(oldIndex);
  21588. // 空数据
  21589. if (!data.hasValue(newIndex)) {
  21590. group.remove(rect);
  21591. return;
  21592. }
  21593. if (!rect) {
  21594. rect = createRect(newIndex, true);
  21595. }
  21596. var layout = data.getItemLayout(newIndex);
  21597. var lineWidth = data.getItemModel(newIndex).get(barBorderWidthQuery) || 0;
  21598. fixLayoutWithLineWidth(layout, lineWidth);
  21599. graphic.updateProps(rect, {
  21600. shape: layout
  21601. }, seriesModel, newIndex);
  21602. data.setItemGraphicEl(newIndex, rect);
  21603. // Add back
  21604. group.add(rect);
  21605. })
  21606. .remove(function (idx) {
  21607. var rect = oldData.getItemGraphicEl(idx);
  21608. if (rect) {
  21609. // Not show text when animating
  21610. rect.style.text = '';
  21611. graphic.updateProps(rect, {
  21612. shape: {
  21613. width: 0
  21614. }
  21615. }, seriesModel, idx, function () {
  21616. group.remove(rect);
  21617. });
  21618. }
  21619. })
  21620. .execute();
  21621. this._updateStyle(seriesModel, data, isHorizontal);
  21622. this._data = data;
  21623. },
  21624. _updateStyle: function (seriesModel, data, isHorizontal) {
  21625. function setLabel(style, model, color, labelText, labelPositionOutside) {
  21626. graphic.setText(style, model, color);
  21627. style.text = labelText;
  21628. if (style.textPosition === 'outside') {
  21629. style.textPosition = labelPositionOutside;
  21630. }
  21631. }
  21632. data.eachItemGraphicEl(function (rect, idx) {
  21633. var itemModel = data.getItemModel(idx);
  21634. var color = data.getItemVisual(idx, 'color');
  21635. var opacity = data.getItemVisual(idx, 'opacity');
  21636. var layout = data.getItemLayout(idx);
  21637. var itemStyleModel = itemModel.getModel('itemStyle.normal');
  21638. var hoverStyle = itemModel.getModel('itemStyle.emphasis').getBarItemStyle();
  21639. rect.setShape('r', itemStyleModel.get('barBorderRadius') || 0);
  21640. rect.useStyle(zrUtil.defaults(
  21641. {
  21642. fill: color,
  21643. opacity: opacity
  21644. },
  21645. itemStyleModel.getBarItemStyle()
  21646. ));
  21647. var labelPositionOutside = isHorizontal
  21648. ? (layout.height > 0 ? 'bottom' : 'top')
  21649. : (layout.width > 0 ? 'left' : 'right');
  21650. var labelModel = itemModel.getModel('label.normal');
  21651. var hoverLabelModel = itemModel.getModel('label.emphasis');
  21652. var rectStyle = rect.style;
  21653. if (labelModel.get('show')) {
  21654. setLabel(
  21655. rectStyle, labelModel, color,
  21656. zrUtil.retrieve(
  21657. seriesModel.getFormattedLabel(idx, 'normal'),
  21658. seriesModel.getRawValue(idx)
  21659. ),
  21660. labelPositionOutside
  21661. );
  21662. }
  21663. else {
  21664. rectStyle.text = '';
  21665. }
  21666. if (hoverLabelModel.get('show')) {
  21667. setLabel(
  21668. hoverStyle, hoverLabelModel, color,
  21669. zrUtil.retrieve(
  21670. seriesModel.getFormattedLabel(idx, 'emphasis'),
  21671. seriesModel.getRawValue(idx)
  21672. ),
  21673. labelPositionOutside
  21674. );
  21675. }
  21676. else {
  21677. hoverStyle.text = '';
  21678. }
  21679. graphic.setHoverStyle(rect, hoverStyle);
  21680. });
  21681. },
  21682. remove: function (ecModel, api) {
  21683. var group = this.group;
  21684. if (ecModel.get('animation')) {
  21685. if (this._data) {
  21686. this._data.eachItemGraphicEl(function (el) {
  21687. // Not show text when animating
  21688. el.style.text = '';
  21689. graphic.updateProps(el, {
  21690. shape: {
  21691. width: 0
  21692. }
  21693. }, ecModel, el.dataIndex, function () {
  21694. group.remove(el);
  21695. });
  21696. });
  21697. }
  21698. }
  21699. else {
  21700. group.removeAll();
  21701. }
  21702. }
  21703. });
  21704. /***/ },
  21705. /* 131 */
  21706. /***/ function(module, exports, __webpack_require__) {
  21707. module.exports = {
  21708. getBarItemStyle: __webpack_require__(11)(
  21709. [
  21710. ['fill', 'color'],
  21711. ['stroke', 'borderColor'],
  21712. ['lineWidth', 'borderWidth'],
  21713. // Compatitable with 2
  21714. ['stroke', 'barBorderColor'],
  21715. ['lineWidth', 'barBorderWidth'],
  21716. ['opacity'],
  21717. ['shadowBlur'],
  21718. ['shadowOffsetX'],
  21719. ['shadowOffsetY'],
  21720. ['shadowColor']
  21721. ]
  21722. )
  21723. };
  21724. /***/ },
  21725. /* 132 */
  21726. /***/ function(module, exports, __webpack_require__) {
  21727. 'use strict';
  21728. var zrUtil = __webpack_require__(3);
  21729. var numberUtil = __webpack_require__(7);
  21730. var parsePercent = numberUtil.parsePercent;
  21731. function getSeriesStackId(seriesModel) {
  21732. return seriesModel.get('stack') || '__ec_stack_' + seriesModel.seriesIndex;
  21733. }
  21734. function calBarWidthAndOffset(barSeries, api) {
  21735. // Columns info on each category axis. Key is cartesian name
  21736. var columnsMap = {};
  21737. zrUtil.each(barSeries, function (seriesModel, idx) {
  21738. var cartesian = seriesModel.coordinateSystem;
  21739. var baseAxis = cartesian.getBaseAxis();
  21740. var columnsOnAxis = columnsMap[baseAxis.index] || {
  21741. remainedWidth: baseAxis.getBandWidth(),
  21742. autoWidthCount: 0,
  21743. categoryGap: '20%',
  21744. gap: '30%',
  21745. axis: baseAxis,
  21746. stacks: {}
  21747. };
  21748. var stacks = columnsOnAxis.stacks;
  21749. columnsMap[baseAxis.index] = columnsOnAxis;
  21750. var stackId = getSeriesStackId(seriesModel);
  21751. if (!stacks[stackId]) {
  21752. columnsOnAxis.autoWidthCount++;
  21753. }
  21754. stacks[stackId] = stacks[stackId] || {
  21755. width: 0,
  21756. maxWidth: 0
  21757. };
  21758. var barWidth = seriesModel.get('barWidth');
  21759. var barMaxWidth = seriesModel.get('barMaxWidth');
  21760. var barGap = seriesModel.get('barGap');
  21761. var barCategoryGap = seriesModel.get('barCategoryGap');
  21762. // TODO
  21763. if (barWidth && ! stacks[stackId].width) {
  21764. barWidth = Math.min(columnsOnAxis.remainedWidth, barWidth);
  21765. stacks[stackId].width = barWidth;
  21766. columnsOnAxis.remainedWidth -= barWidth;
  21767. }
  21768. barMaxWidth && (stacks[stackId].maxWidth = barMaxWidth);
  21769. (barGap != null) && (columnsOnAxis.gap = barGap);
  21770. (barCategoryGap != null) && (columnsOnAxis.categoryGap = barCategoryGap);
  21771. });
  21772. var result = {};
  21773. zrUtil.each(columnsMap, function (columnsOnAxis, coordSysName) {
  21774. result[coordSysName] = {};
  21775. var stacks = columnsOnAxis.stacks;
  21776. var baseAxis = columnsOnAxis.axis;
  21777. var bandWidth = baseAxis.getBandWidth();
  21778. var categoryGap = parsePercent(columnsOnAxis.categoryGap, bandWidth);
  21779. var barGapPercent = parsePercent(columnsOnAxis.gap, 1);
  21780. var remainedWidth = columnsOnAxis.remainedWidth;
  21781. var autoWidthCount = columnsOnAxis.autoWidthCount;
  21782. var autoWidth = (remainedWidth - categoryGap)
  21783. / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  21784. autoWidth = Math.max(autoWidth, 0);
  21785. // Find if any auto calculated bar exceeded maxBarWidth
  21786. zrUtil.each(stacks, function (column, stack) {
  21787. var maxWidth = column.maxWidth;
  21788. if (!column.width && maxWidth && maxWidth < autoWidth) {
  21789. maxWidth = Math.min(maxWidth, remainedWidth);
  21790. remainedWidth -= maxWidth;
  21791. column.width = maxWidth;
  21792. autoWidthCount--;
  21793. }
  21794. });
  21795. // Recalculate width again
  21796. autoWidth = (remainedWidth - categoryGap)
  21797. / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  21798. autoWidth = Math.max(autoWidth, 0);
  21799. var widthSum = 0;
  21800. var lastColumn;
  21801. zrUtil.each(stacks, function (column, idx) {
  21802. if (!column.width) {
  21803. column.width = autoWidth;
  21804. }
  21805. lastColumn = column;
  21806. widthSum += column.width * (1 + barGapPercent);
  21807. });
  21808. if (lastColumn) {
  21809. widthSum -= lastColumn.width * barGapPercent;
  21810. }
  21811. var offset = -widthSum / 2;
  21812. zrUtil.each(stacks, function (column, stackId) {
  21813. result[coordSysName][stackId] = result[coordSysName][stackId] || {
  21814. offset: offset,
  21815. width: column.width
  21816. };
  21817. offset += column.width * (1 + barGapPercent);
  21818. });
  21819. });
  21820. return result;
  21821. }
  21822. /**
  21823. * @param {string} seriesType
  21824. * @param {module:echarts/model/Global} ecModel
  21825. * @param {module:echarts/ExtensionAPI} api
  21826. */
  21827. function barLayoutGrid(seriesType, ecModel, api) {
  21828. var barWidthAndOffset = calBarWidthAndOffset(
  21829. zrUtil.filter(
  21830. ecModel.getSeriesByType(seriesType),
  21831. function (seriesModel) {
  21832. return !ecModel.isSeriesFiltered(seriesModel)
  21833. && seriesModel.coordinateSystem
  21834. && seriesModel.coordinateSystem.type === 'cartesian2d';
  21835. }
  21836. )
  21837. );
  21838. var lastStackCoords = {};
  21839. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  21840. var data = seriesModel.getData();
  21841. var cartesian = seriesModel.coordinateSystem;
  21842. var baseAxis = cartesian.getBaseAxis();
  21843. var stackId = getSeriesStackId(seriesModel);
  21844. var columnLayoutInfo = barWidthAndOffset[baseAxis.index][stackId];
  21845. var columnOffset = columnLayoutInfo.offset;
  21846. var columnWidth = columnLayoutInfo.width;
  21847. var valueAxis = cartesian.getOtherAxis(baseAxis);
  21848. var barMinHeight = seriesModel.get('barMinHeight') || 0;
  21849. var valueAxisStart = baseAxis.onZero
  21850. ? valueAxis.toGlobalCoord(valueAxis.dataToCoord(0))
  21851. : valueAxis.getGlobalExtent()[0];
  21852. var coords = cartesian.dataToPoints(data, true);
  21853. lastStackCoords[stackId] = lastStackCoords[stackId] || [];
  21854. data.setLayout({
  21855. offset: columnOffset,
  21856. size: columnWidth
  21857. });
  21858. data.each(valueAxis.dim, function (value, idx) {
  21859. // 空数据
  21860. if (isNaN(value)) {
  21861. return;
  21862. }
  21863. if (!lastStackCoords[stackId][idx]) {
  21864. lastStackCoords[stackId][idx] = {
  21865. // Positive stack
  21866. p: valueAxisStart,
  21867. // Negative stack
  21868. n: valueAxisStart
  21869. };
  21870. }
  21871. var sign = value >= 0 ? 'p' : 'n';
  21872. var coord = coords[idx];
  21873. var lastCoord = lastStackCoords[stackId][idx][sign];
  21874. var x, y, width, height;
  21875. if (valueAxis.isHorizontal()) {
  21876. x = lastCoord;
  21877. y = coord[1] + columnOffset;
  21878. width = coord[0] - lastCoord;
  21879. height = columnWidth;
  21880. if (Math.abs(width) < barMinHeight) {
  21881. width = (width < 0 ? -1 : 1) * barMinHeight;
  21882. }
  21883. lastStackCoords[stackId][idx][sign] += width;
  21884. }
  21885. else {
  21886. x = coord[0] + columnOffset;
  21887. y = lastCoord;
  21888. width = columnWidth;
  21889. height = coord[1] - lastCoord;
  21890. if (Math.abs(height) < barMinHeight) {
  21891. // Include zero to has a positive bar
  21892. height = (height <= 0 ? -1 : 1) * barMinHeight;
  21893. }
  21894. lastStackCoords[stackId][idx][sign] += height;
  21895. }
  21896. data.setItemLayout(idx, {
  21897. x: x,
  21898. y: y,
  21899. width: width,
  21900. height: height
  21901. });
  21902. }, true);
  21903. }, this);
  21904. }
  21905. module.exports = barLayoutGrid;
  21906. /***/ },
  21907. /* 133 */
  21908. /***/ function(module, exports, __webpack_require__) {
  21909. var zrUtil = __webpack_require__(3);
  21910. var echarts = __webpack_require__(1);
  21911. __webpack_require__(134);
  21912. __webpack_require__(136);
  21913. __webpack_require__(137)('pie', [{
  21914. type: 'pieToggleSelect',
  21915. event: 'pieselectchanged',
  21916. method: 'toggleSelected'
  21917. }, {
  21918. type: 'pieSelect',
  21919. event: 'pieselected',
  21920. method: 'select'
  21921. }, {
  21922. type: 'pieUnSelect',
  21923. event: 'pieunselected',
  21924. method: 'unSelect'
  21925. }]);
  21926. echarts.registerVisualCoding(
  21927. 'chart', zrUtil.curry(__webpack_require__(138), 'pie')
  21928. );
  21929. echarts.registerLayout(zrUtil.curry(
  21930. __webpack_require__(139), 'pie'
  21931. ));
  21932. echarts.registerProcessor(
  21933. 'filter', zrUtil.curry(__webpack_require__(141), 'pie')
  21934. );
  21935. /***/ },
  21936. /* 134 */
  21937. /***/ function(module, exports, __webpack_require__) {
  21938. 'use strict';
  21939. var List = __webpack_require__(95);
  21940. var zrUtil = __webpack_require__(3);
  21941. var modelUtil = __webpack_require__(5);
  21942. var completeDimensions = __webpack_require__(97);
  21943. var dataSelectableMixin = __webpack_require__(135);
  21944. var PieSeries = __webpack_require__(1).extendSeriesModel({
  21945. type: 'series.pie',
  21946. // Overwrite
  21947. init: function (option) {
  21948. PieSeries.superApply(this, 'init', arguments);
  21949. // Enable legend selection for each data item
  21950. // Use a function instead of direct access because data reference may changed
  21951. this.legendDataProvider = function () {
  21952. return this._dataBeforeProcessed;
  21953. };
  21954. this.updateSelectedMap(option.data);
  21955. this._defaultLabelLine(option);
  21956. },
  21957. // Overwrite
  21958. mergeOption: function (newOption) {
  21959. PieSeries.superCall(this, 'mergeOption', newOption);
  21960. this.updateSelectedMap(this.option.data);
  21961. },
  21962. getInitialData: function (option, ecModel) {
  21963. var dimensions = completeDimensions(['value'], option.data);
  21964. var list = new List(dimensions, this);
  21965. list.initData(option.data);
  21966. return list;
  21967. },
  21968. // Overwrite
  21969. getDataParams: function (dataIndex) {
  21970. var data = this._data;
  21971. var params = PieSeries.superCall(this, 'getDataParams', dataIndex);
  21972. var sum = data.getSum('value');
  21973. // FIXME toFixed?
  21974. //
  21975. // Percent is 0 if sum is 0
  21976. params.percent = !sum ? 0 : +(data.get('value', dataIndex) / sum * 100).toFixed(2);
  21977. params.$vars.push('percent');
  21978. return params;
  21979. },
  21980. _defaultLabelLine: function (option) {
  21981. // Extend labelLine emphasis
  21982. modelUtil.defaultEmphasis(option.labelLine, ['show']);
  21983. var labelLineNormalOpt = option.labelLine.normal;
  21984. var labelLineEmphasisOpt = option.labelLine.emphasis;
  21985. // Not show label line if `label.normal.show = false`
  21986. labelLineNormalOpt.show = labelLineNormalOpt.show
  21987. && option.label.normal.show;
  21988. labelLineEmphasisOpt.show = labelLineEmphasisOpt.show
  21989. && option.label.emphasis.show;
  21990. },
  21991. defaultOption: {
  21992. zlevel: 0,
  21993. z: 2,
  21994. legendHoverLink: true,
  21995. hoverAnimation: true,
  21996. // 默认全局居中
  21997. center: ['50%', '50%'],
  21998. radius: [0, '75%'],
  21999. // 默认顺时针
  22000. clockwise: true,
  22001. startAngle: 90,
  22002. // 最小角度改为0
  22003. minAngle: 0,
  22004. // 选中是扇区偏移量
  22005. selectedOffset: 10,
  22006. // If use strategy to avoid label overlapping
  22007. avoidLabelOverlap: true,
  22008. // 选择模式,默认关闭,可选single,multiple
  22009. // selectedMode: false,
  22010. // 南丁格尔玫瑰图模式,'radius'(半径) | 'area'(面积)
  22011. // roseType: null,
  22012. label: {
  22013. normal: {
  22014. // If rotate around circle
  22015. rotate: false,
  22016. show: true,
  22017. // 'outer', 'inside', 'center'
  22018. position: 'outer'
  22019. // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  22020. // textStyle: null // 默认使用全局文本样式,详见TEXTSTYLE
  22021. // distance: 当position为inner时有效,为label位置到圆心的距离与圆半径(环状图为内外半径和)的比例系数
  22022. },
  22023. emphasis: {}
  22024. },
  22025. // Enabled when label.normal.position is 'outer'
  22026. labelLine: {
  22027. normal: {
  22028. show: true,
  22029. // 引导线两段中的第一段长度
  22030. length: 15,
  22031. // 引导线两段中的第二段长度
  22032. length2: 15,
  22033. smooth: false,
  22034. lineStyle: {
  22035. // color: 各异,
  22036. width: 1,
  22037. type: 'solid'
  22038. }
  22039. }
  22040. },
  22041. itemStyle: {
  22042. normal: {
  22043. // color: 各异,
  22044. borderColor: 'rgba(0,0,0,0)',
  22045. borderWidth: 1
  22046. },
  22047. emphasis: {
  22048. // color: 各异,
  22049. borderColor: 'rgba(0,0,0,0)',
  22050. borderWidth: 1
  22051. }
  22052. },
  22053. animationEasing: 'cubicOut',
  22054. data: []
  22055. }
  22056. });
  22057. zrUtil.mixin(PieSeries, dataSelectableMixin);
  22058. module.exports = PieSeries;
  22059. /***/ },
  22060. /* 135 */
  22061. /***/ function(module, exports, __webpack_require__) {
  22062. /**
  22063. * Data selectable mixin for chart series.
  22064. * To eanble data select, option of series must have `selectedMode`.
  22065. * And each data item will use `selected` to toggle itself selected status
  22066. *
  22067. * @module echarts/chart/helper/DataSelectable
  22068. */
  22069. var zrUtil = __webpack_require__(3);
  22070. module.exports = {
  22071. updateSelectedMap: function (targetList) {
  22072. this._selectTargetMap = zrUtil.reduce(targetList || [], function (targetMap, target) {
  22073. targetMap[target.name] = target;
  22074. return targetMap;
  22075. }, {});
  22076. },
  22077. /**
  22078. * @param {string} name
  22079. */
  22080. // PENGING If selectedMode is null ?
  22081. select: function (name) {
  22082. var targetMap = this._selectTargetMap;
  22083. var target = targetMap[name];
  22084. var selectedMode = this.get('selectedMode');
  22085. if (selectedMode === 'single') {
  22086. zrUtil.each(targetMap, function (target) {
  22087. target.selected = false;
  22088. });
  22089. }
  22090. target && (target.selected = true);
  22091. },
  22092. /**
  22093. * @param {string} name
  22094. */
  22095. unSelect: function (name) {
  22096. var target = this._selectTargetMap[name];
  22097. // var selectedMode = this.get('selectedMode');
  22098. // selectedMode !== 'single' && target && (target.selected = false);
  22099. target && (target.selected = false);
  22100. },
  22101. /**
  22102. * @param {string} name
  22103. */
  22104. toggleSelected: function (name) {
  22105. var target = this._selectTargetMap[name];
  22106. if (target != null) {
  22107. this[target.selected ? 'unSelect' : 'select'](name);
  22108. return target.selected;
  22109. }
  22110. },
  22111. /**
  22112. * @param {string} name
  22113. */
  22114. isSelected: function (name) {
  22115. var target = this._selectTargetMap[name];
  22116. return target && target.selected;
  22117. }
  22118. };
  22119. /***/ },
  22120. /* 136 */
  22121. /***/ function(module, exports, __webpack_require__) {
  22122. var graphic = __webpack_require__(42);
  22123. var zrUtil = __webpack_require__(3);
  22124. /**
  22125. * @param {module:echarts/model/Series} seriesModel
  22126. * @param {boolean} hasAnimation
  22127. * @inner
  22128. */
  22129. function updateDataSelected(uid, seriesModel, hasAnimation, api) {
  22130. var data = seriesModel.getData();
  22131. var dataIndex = this.dataIndex;
  22132. var name = data.getName(dataIndex);
  22133. var selectedOffset = seriesModel.get('selectedOffset');
  22134. api.dispatchAction({
  22135. type: 'pieToggleSelect',
  22136. from: uid,
  22137. name: name,
  22138. seriesId: seriesModel.id
  22139. });
  22140. data.each(function (idx) {
  22141. toggleItemSelected(
  22142. data.getItemGraphicEl(idx),
  22143. data.getItemLayout(idx),
  22144. seriesModel.isSelected(data.getName(idx)),
  22145. selectedOffset,
  22146. hasAnimation
  22147. );
  22148. });
  22149. }
  22150. /**
  22151. * @param {module:zrender/graphic/Sector} el
  22152. * @param {Object} layout
  22153. * @param {boolean} isSelected
  22154. * @param {number} selectedOffset
  22155. * @param {boolean} hasAnimation
  22156. * @inner
  22157. */
  22158. function toggleItemSelected(el, layout, isSelected, selectedOffset, hasAnimation) {
  22159. var midAngle = (layout.startAngle + layout.endAngle) / 2;
  22160. var dx = Math.cos(midAngle);
  22161. var dy = Math.sin(midAngle);
  22162. var offset = isSelected ? selectedOffset : 0;
  22163. var position = [dx * offset, dy * offset];
  22164. hasAnimation
  22165. // animateTo will stop revious animation like update transition
  22166. ? el.animate()
  22167. .when(200, {
  22168. position: position
  22169. })
  22170. .start('bounceOut')
  22171. : el.attr('position', position);
  22172. }
  22173. /**
  22174. * Piece of pie including Sector, Label, LabelLine
  22175. * @constructor
  22176. * @extends {module:zrender/graphic/Group}
  22177. */
  22178. function PiePiece(data, idx) {
  22179. graphic.Group.call(this);
  22180. var sector = new graphic.Sector({
  22181. z2: 2
  22182. });
  22183. var polyline = new graphic.Polyline();
  22184. var text = new graphic.Text();
  22185. this.add(sector);
  22186. this.add(polyline);
  22187. this.add(text);
  22188. this.updateData(data, idx, true);
  22189. // Hover to change label and labelLine
  22190. function onEmphasis() {
  22191. polyline.ignore = polyline.hoverIgnore;
  22192. text.ignore = text.hoverIgnore;
  22193. }
  22194. function onNormal() {
  22195. polyline.ignore = polyline.normalIgnore;
  22196. text.ignore = text.normalIgnore;
  22197. }
  22198. this.on('emphasis', onEmphasis)
  22199. .on('normal', onNormal)
  22200. .on('mouseover', onEmphasis)
  22201. .on('mouseout', onNormal);
  22202. }
  22203. var piePieceProto = PiePiece.prototype;
  22204. function getLabelStyle(data, idx, state, labelModel, labelPosition) {
  22205. var textStyleModel = labelModel.getModel('textStyle');
  22206. var isLabelInside = labelPosition === 'inside' || labelPosition === 'inner';
  22207. return {
  22208. fill: textStyleModel.getTextColor()
  22209. || (isLabelInside ? '#fff' : data.getItemVisual(idx, 'color')),
  22210. opacity: data.getItemVisual(idx, 'opacity'),
  22211. textFont: textStyleModel.getFont(),
  22212. text: zrUtil.retrieve(
  22213. data.hostModel.getFormattedLabel(idx, state), data.getName(idx)
  22214. )
  22215. };
  22216. }
  22217. piePieceProto.updateData = function (data, idx, firstCreate) {
  22218. var sector = this.childAt(0);
  22219. var seriesModel = data.hostModel;
  22220. var itemModel = data.getItemModel(idx);
  22221. var layout = data.getItemLayout(idx);
  22222. var sectorShape = zrUtil.extend({}, layout);
  22223. sectorShape.label = null;
  22224. if (firstCreate) {
  22225. sector.setShape(sectorShape);
  22226. sector.shape.endAngle = layout.startAngle;
  22227. graphic.updateProps(sector, {
  22228. shape: {
  22229. endAngle: layout.endAngle
  22230. }
  22231. }, seriesModel, idx);
  22232. }
  22233. else {
  22234. graphic.updateProps(sector, {
  22235. shape: sectorShape
  22236. }, seriesModel, idx);
  22237. }
  22238. // Update common style
  22239. var itemStyleModel = itemModel.getModel('itemStyle');
  22240. var visualColor = data.getItemVisual(idx, 'color');
  22241. sector.useStyle(
  22242. zrUtil.defaults(
  22243. {
  22244. fill: visualColor
  22245. },
  22246. itemStyleModel.getModel('normal').getItemStyle()
  22247. )
  22248. );
  22249. sector.hoverStyle = itemStyleModel.getModel('emphasis').getItemStyle();
  22250. // Toggle selected
  22251. toggleItemSelected(
  22252. this,
  22253. data.getItemLayout(idx),
  22254. itemModel.get('selected'),
  22255. seriesModel.get('selectedOffset'),
  22256. seriesModel.get('animation')
  22257. );
  22258. function onEmphasis() {
  22259. // Sector may has animation of updating data. Force to move to the last frame
  22260. // Or it may stopped on the wrong shape
  22261. sector.stopAnimation(true);
  22262. sector.animateTo({
  22263. shape: {
  22264. r: layout.r + 10
  22265. }
  22266. }, 300, 'elasticOut');
  22267. }
  22268. function onNormal() {
  22269. sector.stopAnimation(true);
  22270. sector.animateTo({
  22271. shape: {
  22272. r: layout.r
  22273. }
  22274. }, 300, 'elasticOut');
  22275. }
  22276. sector.off('mouseover').off('mouseout').off('emphasis').off('normal');
  22277. if (itemModel.get('hoverAnimation')) {
  22278. sector
  22279. .on('mouseover', onEmphasis)
  22280. .on('mouseout', onNormal)
  22281. .on('emphasis', onEmphasis)
  22282. .on('normal', onNormal);
  22283. }
  22284. this._updateLabel(data, idx);
  22285. graphic.setHoverStyle(this);
  22286. };
  22287. piePieceProto._updateLabel = function (data, idx) {
  22288. var labelLine = this.childAt(1);
  22289. var labelText = this.childAt(2);
  22290. var seriesModel = data.hostModel;
  22291. var itemModel = data.getItemModel(idx);
  22292. var layout = data.getItemLayout(idx);
  22293. var labelLayout = layout.label;
  22294. var visualColor = data.getItemVisual(idx, 'color');
  22295. graphic.updateProps(labelLine, {
  22296. shape: {
  22297. points: labelLayout.linePoints || [
  22298. [labelLayout.x, labelLayout.y], [labelLayout.x, labelLayout.y], [labelLayout.x, labelLayout.y]
  22299. ]
  22300. }
  22301. }, seriesModel, idx);
  22302. graphic.updateProps(labelText, {
  22303. style: {
  22304. x: labelLayout.x,
  22305. y: labelLayout.y
  22306. }
  22307. }, seriesModel, idx);
  22308. labelText.attr({
  22309. style: {
  22310. textVerticalAlign: labelLayout.verticalAlign,
  22311. textAlign: labelLayout.textAlign,
  22312. textFont: labelLayout.font
  22313. },
  22314. rotation: labelLayout.rotation,
  22315. origin: [labelLayout.x, labelLayout.y],
  22316. z2: 10
  22317. });
  22318. var labelModel = itemModel.getModel('label.normal');
  22319. var labelHoverModel = itemModel.getModel('label.emphasis');
  22320. var labelLineModel = itemModel.getModel('labelLine.normal');
  22321. var labelLineHoverModel = itemModel.getModel('labelLine.emphasis');
  22322. var labelPosition = labelModel.get('position') || labelHoverModel.get('position');
  22323. labelText.setStyle(getLabelStyle(data, idx, 'normal', labelModel, labelPosition));
  22324. labelText.ignore = labelText.normalIgnore = !labelModel.get('show');
  22325. labelText.hoverIgnore = !labelHoverModel.get('show');
  22326. labelLine.ignore = labelLine.normalIgnore = !labelLineModel.get('show');
  22327. labelLine.hoverIgnore = !labelLineHoverModel.get('show');
  22328. // Default use item visual color
  22329. labelLine.setStyle({
  22330. stroke: visualColor,
  22331. opacity: data.getItemVisual(idx, 'opacity')
  22332. });
  22333. labelLine.setStyle(labelLineModel.getModel('lineStyle').getLineStyle());
  22334. labelText.hoverStyle = getLabelStyle(data, idx, 'emphasis', labelHoverModel, labelPosition);
  22335. labelLine.hoverStyle = labelLineHoverModel.getModel('lineStyle').getLineStyle();
  22336. var smooth = labelLineModel.get('smooth');
  22337. if (smooth && smooth === true) {
  22338. smooth = 0.4;
  22339. }
  22340. labelLine.setShape({
  22341. smooth: smooth
  22342. });
  22343. };
  22344. zrUtil.inherits(PiePiece, graphic.Group);
  22345. // Pie view
  22346. var Pie = __webpack_require__(41).extend({
  22347. type: 'pie',
  22348. init: function () {
  22349. var sectorGroup = new graphic.Group();
  22350. this._sectorGroup = sectorGroup;
  22351. },
  22352. render: function (seriesModel, ecModel, api, payload) {
  22353. if (payload && (payload.from === this.uid)) {
  22354. return;
  22355. }
  22356. var data = seriesModel.getData();
  22357. var oldData = this._data;
  22358. var group = this.group;
  22359. var hasAnimation = ecModel.get('animation');
  22360. var isFirstRender = !oldData;
  22361. var onSectorClick = zrUtil.curry(
  22362. updateDataSelected, this.uid, seriesModel, hasAnimation, api
  22363. );
  22364. var selectedMode = seriesModel.get('selectedMode');
  22365. data.diff(oldData)
  22366. .add(function (idx) {
  22367. var piePiece = new PiePiece(data, idx);
  22368. if (isFirstRender) {
  22369. piePiece.eachChild(function (child) {
  22370. child.stopAnimation(true);
  22371. });
  22372. }
  22373. selectedMode && piePiece.on('click', onSectorClick);
  22374. data.setItemGraphicEl(idx, piePiece);
  22375. group.add(piePiece);
  22376. })
  22377. .update(function (newIdx, oldIdx) {
  22378. var piePiece = oldData.getItemGraphicEl(oldIdx);
  22379. piePiece.updateData(data, newIdx);
  22380. piePiece.off('click');
  22381. selectedMode && piePiece.on('click', onSectorClick);
  22382. group.add(piePiece);
  22383. data.setItemGraphicEl(newIdx, piePiece);
  22384. })
  22385. .remove(function (idx) {
  22386. var piePiece = oldData.getItemGraphicEl(idx);
  22387. group.remove(piePiece);
  22388. })
  22389. .execute();
  22390. if (hasAnimation && isFirstRender && data.count() > 0) {
  22391. var shape = data.getItemLayout(0);
  22392. var r = Math.max(api.getWidth(), api.getHeight()) / 2;
  22393. var removeClipPath = zrUtil.bind(group.removeClipPath, group);
  22394. group.setClipPath(this._createClipPath(
  22395. shape.cx, shape.cy, r, shape.startAngle, shape.clockwise, removeClipPath, seriesModel
  22396. ));
  22397. }
  22398. this._data = data;
  22399. },
  22400. _createClipPath: function (
  22401. cx, cy, r, startAngle, clockwise, cb, seriesModel
  22402. ) {
  22403. var clipPath = new graphic.Sector({
  22404. shape: {
  22405. cx: cx,
  22406. cy: cy,
  22407. r0: 0,
  22408. r: r,
  22409. startAngle: startAngle,
  22410. endAngle: startAngle,
  22411. clockwise: clockwise
  22412. }
  22413. });
  22414. graphic.initProps(clipPath, {
  22415. shape: {
  22416. endAngle: startAngle + (clockwise ? 1 : -1) * Math.PI * 2
  22417. }
  22418. }, seriesModel, cb);
  22419. return clipPath;
  22420. }
  22421. });
  22422. module.exports = Pie;
  22423. /***/ },
  22424. /* 137 */
  22425. /***/ function(module, exports, __webpack_require__) {
  22426. var echarts = __webpack_require__(1);
  22427. var zrUtil = __webpack_require__(3);
  22428. module.exports = function (seriesType, actionInfos) {
  22429. zrUtil.each(actionInfos, function (actionInfo) {
  22430. actionInfo.update = 'updateView';
  22431. /**
  22432. * @payload
  22433. * @property {string} seriesName
  22434. * @property {string} name
  22435. */
  22436. echarts.registerAction(actionInfo, function (payload, ecModel) {
  22437. var selected = {};
  22438. ecModel.eachComponent(
  22439. {mainType: 'series', subType: seriesType, query: payload},
  22440. function (seriesModel) {
  22441. if (seriesModel[actionInfo.method]) {
  22442. seriesModel[actionInfo.method](payload.name);
  22443. }
  22444. var data = seriesModel.getData();
  22445. // Create selected map
  22446. data.each(function (idx) {
  22447. var name = data.getName(idx);
  22448. selected[name] = seriesModel.isSelected(name) || false;
  22449. });
  22450. }
  22451. );
  22452. return {
  22453. name: payload.name,
  22454. selected: selected
  22455. };
  22456. });
  22457. });
  22458. };
  22459. /***/ },
  22460. /* 138 */
  22461. /***/ function(module, exports) {
  22462. // Pick color from palette for each data item
  22463. module.exports = function (seriesType, ecModel) {
  22464. var globalColorList = ecModel.get('color');
  22465. var offset = 0;
  22466. ecModel.eachRawSeriesByType(seriesType, function (seriesModel) {
  22467. var colorList = seriesModel.get('color', true);
  22468. var dataAll = seriesModel.getRawData();
  22469. if (!ecModel.isSeriesFiltered(seriesModel)) {
  22470. var data = seriesModel.getData();
  22471. data.each(function (idx) {
  22472. var itemModel = data.getItemModel(idx);
  22473. var rawIdx = data.getRawIndex(idx);
  22474. // If series.itemStyle.normal.color is a function. itemVisual may be encoded
  22475. var singleDataColor = data.getItemVisual(idx, 'color', true);
  22476. if (!singleDataColor) {
  22477. var paletteColor = colorList ? colorList[rawIdx % colorList.length]
  22478. : globalColorList[(rawIdx + offset) % globalColorList.length];
  22479. var color = itemModel.get('itemStyle.normal.color') || paletteColor;
  22480. // Legend may use the visual info in data before processed
  22481. dataAll.setItemVisual(rawIdx, 'color', color);
  22482. data.setItemVisual(idx, 'color', color);
  22483. }
  22484. else {
  22485. // Set data all color for legend
  22486. dataAll.setItemVisual(rawIdx, 'color', singleDataColor);
  22487. }
  22488. });
  22489. }
  22490. offset += dataAll.count();
  22491. });
  22492. };
  22493. /***/ },
  22494. /* 139 */
  22495. /***/ function(module, exports, __webpack_require__) {
  22496. // TODO minAngle
  22497. var numberUtil = __webpack_require__(7);
  22498. var parsePercent = numberUtil.parsePercent;
  22499. var labelLayout = __webpack_require__(140);
  22500. var zrUtil = __webpack_require__(3);
  22501. var PI2 = Math.PI * 2;
  22502. var RADIAN = Math.PI / 180;
  22503. module.exports = function (seriesType, ecModel, api) {
  22504. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  22505. var center = seriesModel.get('center');
  22506. var radius = seriesModel.get('radius');
  22507. if (!zrUtil.isArray(radius)) {
  22508. radius = [0, radius];
  22509. }
  22510. if (!zrUtil.isArray(center)) {
  22511. center = [center, center];
  22512. }
  22513. var width = api.getWidth();
  22514. var height = api.getHeight();
  22515. var size = Math.min(width, height);
  22516. var cx = parsePercent(center[0], width);
  22517. var cy = parsePercent(center[1], height);
  22518. var r0 = parsePercent(radius[0], size / 2);
  22519. var r = parsePercent(radius[1], size / 2);
  22520. var data = seriesModel.getData();
  22521. var startAngle = -seriesModel.get('startAngle') * RADIAN;
  22522. var minAngle = seriesModel.get('minAngle') * RADIAN;
  22523. var sum = data.getSum('value');
  22524. // Sum may be 0
  22525. var unitRadian = Math.PI / (sum || data.count()) * 2;
  22526. var clockwise = seriesModel.get('clockwise');
  22527. var roseType = seriesModel.get('roseType');
  22528. // [0...max]
  22529. var extent = data.getDataExtent('value');
  22530. extent[0] = 0;
  22531. // In the case some sector angle is smaller than minAngle
  22532. var restAngle = PI2;
  22533. var valueSumLargerThanMinAngle = 0;
  22534. var currentAngle = startAngle;
  22535. var dir = clockwise ? 1 : -1;
  22536. data.each('value', function (value, idx) {
  22537. var angle;
  22538. // FIXME 兼容 2.0 但是 roseType 是 area 的时候才是这样?
  22539. if (roseType !== 'area') {
  22540. angle = sum === 0 ? unitRadian : (value * unitRadian);
  22541. }
  22542. else {
  22543. angle = PI2 / (data.count() || 1);
  22544. }
  22545. if (angle < minAngle) {
  22546. angle = minAngle;
  22547. restAngle -= minAngle;
  22548. }
  22549. else {
  22550. valueSumLargerThanMinAngle += value;
  22551. }
  22552. var endAngle = currentAngle + dir * angle;
  22553. data.setItemLayout(idx, {
  22554. angle: angle,
  22555. startAngle: currentAngle,
  22556. endAngle: endAngle,
  22557. clockwise: clockwise,
  22558. cx: cx,
  22559. cy: cy,
  22560. r0: r0,
  22561. r: roseType
  22562. ? numberUtil.linearMap(value, extent, [r0, r])
  22563. : r
  22564. });
  22565. currentAngle = endAngle;
  22566. }, true);
  22567. // Some sector is constrained by minAngle
  22568. // Rest sectors needs recalculate angle
  22569. if (restAngle < PI2) {
  22570. // Average the angle if rest angle is not enough after all angles is
  22571. // Constrained by minAngle
  22572. if (restAngle <= 1e-3) {
  22573. var angle = PI2 / data.count();
  22574. data.each(function (idx) {
  22575. var layout = data.getItemLayout(idx);
  22576. layout.startAngle = startAngle + dir * idx * angle;
  22577. layout.endAngle = startAngle + dir * (idx + 1) * angle;
  22578. });
  22579. }
  22580. else {
  22581. unitRadian = restAngle / valueSumLargerThanMinAngle;
  22582. currentAngle = startAngle;
  22583. data.each('value', function (value, idx) {
  22584. var layout = data.getItemLayout(idx);
  22585. var angle = layout.angle === minAngle
  22586. ? minAngle : value * unitRadian;
  22587. layout.startAngle = currentAngle;
  22588. layout.endAngle = currentAngle + dir * angle;
  22589. currentAngle += angle;
  22590. });
  22591. }
  22592. }
  22593. labelLayout(seriesModel, r, width, height);
  22594. });
  22595. };
  22596. /***/ },
  22597. /* 140 */
  22598. /***/ function(module, exports, __webpack_require__) {
  22599. 'use strict';
  22600. // FIXME emphasis label position is not same with normal label position
  22601. var textContain = __webpack_require__(14);
  22602. function adjustSingleSide(list, cx, cy, r, dir, viewWidth, viewHeight) {
  22603. list.sort(function (a, b) {
  22604. return a.y - b.y;
  22605. });
  22606. // 压
  22607. function shiftDown(start, end, delta, dir) {
  22608. for (var j = start; j < end; j++) {
  22609. list[j].y += delta;
  22610. if (j > start
  22611. && j + 1 < end
  22612. && list[j + 1].y > list[j].y + list[j].height
  22613. ) {
  22614. shiftUp(j, delta / 2);
  22615. return;
  22616. }
  22617. }
  22618. shiftUp(end - 1, delta / 2);
  22619. }
  22620. // 弹
  22621. function shiftUp(end, delta) {
  22622. for (var j = end; j >= 0; j--) {
  22623. list[j].y -= delta;
  22624. if (j > 0
  22625. && list[j].y > list[j - 1].y + list[j - 1].height
  22626. ) {
  22627. break;
  22628. }
  22629. }
  22630. }
  22631. function changeX(list, isDownList, cx, cy, r, dir) {
  22632. var lastDeltaX = dir > 0
  22633. ? isDownList // 右侧
  22634. ? Number.MAX_VALUE // 下
  22635. : 0 // 上
  22636. : isDownList // 左侧
  22637. ? Number.MAX_VALUE // 下
  22638. : 0; // 上
  22639. for (var i = 0, l = list.length; i < l; i++) {
  22640. // Not change x for center label
  22641. if (list[i].position === 'center') {
  22642. continue;
  22643. }
  22644. var deltaY = Math.abs(list[i].y - cy);
  22645. var length = list[i].len;
  22646. var length2 = list[i].len2;
  22647. var deltaX = (deltaY < r + length)
  22648. ? Math.sqrt(
  22649. (r + length + length2) * (r + length + length2)
  22650. - deltaY * deltaY
  22651. )
  22652. : Math.abs(list[i].x - cx);
  22653. if (isDownList && deltaX >= lastDeltaX) {
  22654. // 右下,左下
  22655. deltaX = lastDeltaX - 10;
  22656. }
  22657. if (!isDownList && deltaX <= lastDeltaX) {
  22658. // 右上,左上
  22659. deltaX = lastDeltaX + 10;
  22660. }
  22661. list[i].x = cx + deltaX * dir;
  22662. lastDeltaX = deltaX;
  22663. }
  22664. }
  22665. var lastY = 0;
  22666. var delta;
  22667. var len = list.length;
  22668. var upList = [];
  22669. var downList = [];
  22670. for (var i = 0; i < len; i++) {
  22671. delta = list[i].y - lastY;
  22672. if (delta < 0) {
  22673. shiftDown(i, len, -delta, dir);
  22674. }
  22675. lastY = list[i].y + list[i].height;
  22676. }
  22677. if (viewHeight - lastY < 0) {
  22678. shiftUp(len - 1, lastY - viewHeight);
  22679. }
  22680. for (var i = 0; i < len; i++) {
  22681. if (list[i].y >= cy) {
  22682. downList.push(list[i]);
  22683. }
  22684. else {
  22685. upList.push(list[i]);
  22686. }
  22687. }
  22688. changeX(upList, false, cx, cy, r, dir);
  22689. changeX(downList, true, cx, cy, r, dir);
  22690. }
  22691. function avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight) {
  22692. var leftList = [];
  22693. var rightList = [];
  22694. for (var i = 0; i < labelLayoutList.length; i++) {
  22695. if (labelLayoutList[i].x < cx) {
  22696. leftList.push(labelLayoutList[i]);
  22697. }
  22698. else {
  22699. rightList.push(labelLayoutList[i]);
  22700. }
  22701. }
  22702. adjustSingleSide(rightList, cx, cy, r, 1, viewWidth, viewHeight);
  22703. adjustSingleSide(leftList, cx, cy, r, -1, viewWidth, viewHeight);
  22704. for (var i = 0; i < labelLayoutList.length; i++) {
  22705. var linePoints = labelLayoutList[i].linePoints;
  22706. if (linePoints) {
  22707. var dist = linePoints[1][0] - linePoints[2][0];
  22708. if (labelLayoutList[i].x < cx) {
  22709. linePoints[2][0] = labelLayoutList[i].x + 3;
  22710. }
  22711. else {
  22712. linePoints[2][0] = labelLayoutList[i].x - 3;
  22713. }
  22714. linePoints[1][1] = linePoints[2][1] = labelLayoutList[i].y;
  22715. linePoints[1][0] = linePoints[2][0] + dist;
  22716. }
  22717. }
  22718. }
  22719. module.exports = function (seriesModel, r, viewWidth, viewHeight) {
  22720. var data = seriesModel.getData();
  22721. var labelLayoutList = [];
  22722. var cx;
  22723. var cy;
  22724. var hasLabelRotate = false;
  22725. data.each(function (idx) {
  22726. var layout = data.getItemLayout(idx);
  22727. var itemModel = data.getItemModel(idx);
  22728. var labelModel = itemModel.getModel('label.normal');
  22729. // Use position in normal or emphasis
  22730. var labelPosition = labelModel.get('position') || itemModel.get('label.emphasis.position');
  22731. var labelLineModel = itemModel.getModel('labelLine.normal');
  22732. var labelLineLen = labelLineModel.get('length');
  22733. var labelLineLen2 = labelLineModel.get('length2');
  22734. var midAngle = (layout.startAngle + layout.endAngle) / 2;
  22735. var dx = Math.cos(midAngle);
  22736. var dy = Math.sin(midAngle);
  22737. var textX;
  22738. var textY;
  22739. var linePoints;
  22740. var textAlign;
  22741. cx = layout.cx;
  22742. cy = layout.cy;
  22743. var isLabelInside = labelPosition === 'inside' || labelPosition === 'inner';
  22744. if (labelPosition === 'center') {
  22745. textX = layout.cx;
  22746. textY = layout.cy;
  22747. textAlign = 'center';
  22748. }
  22749. else {
  22750. var x1 = (isLabelInside ? (layout.r + layout.r0) / 2 * dx : layout.r * dx) + cx;
  22751. var y1 = (isLabelInside ? (layout.r + layout.r0) / 2 * dy : layout.r * dy) + cy;
  22752. textX = x1 + dx * 3;
  22753. textY = y1 + dy * 3;
  22754. if (!isLabelInside) {
  22755. // For roseType
  22756. var x2 = x1 + dx * (labelLineLen + r - layout.r);
  22757. var y2 = y1 + dy * (labelLineLen + r - layout.r);
  22758. var x3 = x2 + ((dx < 0 ? -1 : 1) * labelLineLen2);
  22759. var y3 = y2;
  22760. textX = x3 + (dx < 0 ? -5 : 5);
  22761. textY = y3;
  22762. linePoints = [[x1, y1], [x2, y2], [x3, y3]];
  22763. }
  22764. textAlign = isLabelInside ? 'center' : (dx > 0 ? 'left' : 'right');
  22765. }
  22766. var font = labelModel.getModel('textStyle').getFont();
  22767. var labelRotate = labelModel.get('rotate')
  22768. ? (dx < 0 ? -midAngle + Math.PI : -midAngle) : 0;
  22769. var text = seriesModel.getFormattedLabel(idx, 'normal')
  22770. || data.getName(idx);
  22771. var textRect = textContain.getBoundingRect(
  22772. text, font, textAlign, 'top'
  22773. );
  22774. hasLabelRotate = !!labelRotate;
  22775. layout.label = {
  22776. x: textX,
  22777. y: textY,
  22778. position: labelPosition,
  22779. height: textRect.height,
  22780. len: labelLineLen,
  22781. len2: labelLineLen2,
  22782. linePoints: linePoints,
  22783. textAlign: textAlign,
  22784. verticalAlign: 'middle',
  22785. font: font,
  22786. rotation: labelRotate
  22787. };
  22788. // Not layout the inside label
  22789. if (!isLabelInside) {
  22790. labelLayoutList.push(layout.label);
  22791. }
  22792. });
  22793. if (!hasLabelRotate && seriesModel.get('avoidLabelOverlap')) {
  22794. avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight);
  22795. }
  22796. };
  22797. /***/ },
  22798. /* 141 */
  22799. /***/ function(module, exports) {
  22800. module.exports = function (seriesType, ecModel) {
  22801. var legendModels = ecModel.findComponents({
  22802. mainType: 'legend'
  22803. });
  22804. if (!legendModels || !legendModels.length) {
  22805. return;
  22806. }
  22807. ecModel.eachSeriesByType(seriesType, function (series) {
  22808. var data = series.getData();
  22809. data.filterSelf(function (idx) {
  22810. var name = data.getName(idx);
  22811. // If in any legend component the status is not selected.
  22812. for (var i = 0; i < legendModels.length; i++) {
  22813. if (!legendModels[i].isSelected(name)) {
  22814. return false;
  22815. }
  22816. }
  22817. return true;
  22818. }, this);
  22819. }, this);
  22820. };
  22821. /***/ },
  22822. /* 142 */
  22823. /***/ function(module, exports, __webpack_require__) {
  22824. var zrUtil = __webpack_require__(3);
  22825. var echarts = __webpack_require__(1);
  22826. __webpack_require__(143);
  22827. __webpack_require__(144);
  22828. echarts.registerVisualCoding('chart', zrUtil.curry(
  22829. __webpack_require__(104), 'scatter', 'circle', null
  22830. ));
  22831. echarts.registerLayout(zrUtil.curry(
  22832. __webpack_require__(105), 'scatter'
  22833. ));
  22834. // In case developer forget to include grid component
  22835. __webpack_require__(107);
  22836. /***/ },
  22837. /* 143 */
  22838. /***/ function(module, exports, __webpack_require__) {
  22839. 'use strict';
  22840. var createListFromArray = __webpack_require__(94);
  22841. var SeriesModel = __webpack_require__(27);
  22842. module.exports = SeriesModel.extend({
  22843. type: 'series.scatter',
  22844. dependencies: ['grid', 'polar'],
  22845. getInitialData: function (option, ecModel) {
  22846. var list = createListFromArray(option.data, this, ecModel);
  22847. return list;
  22848. },
  22849. defaultOption: {
  22850. coordinateSystem: 'cartesian2d',
  22851. zlevel: 0,
  22852. z: 2,
  22853. legendHoverLink: true,
  22854. hoverAnimation: true,
  22855. // Cartesian coordinate system
  22856. xAxisIndex: 0,
  22857. yAxisIndex: 0,
  22858. // Polar coordinate system
  22859. polarIndex: 0,
  22860. // Geo coordinate system
  22861. geoIndex: 0,
  22862. // symbol: null, // 图形类型
  22863. symbolSize: 10, // 图形大小,半宽(半径)参数,当图形为方向或菱形则总宽度为symbolSize * 2
  22864. // symbolRotate: null, // 图形旋转控制
  22865. large: false,
  22866. // Available when large is true
  22867. largeThreshold: 2000,
  22868. // label: {
  22869. // normal: {
  22870. // show: false
  22871. // distance: 5,
  22872. // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  22873. // position: 默认自适应,水平布局为'top',垂直布局为'right',可选为
  22874. // 'inside'|'left'|'right'|'top'|'bottom'
  22875. // textStyle: null // 默认使用全局文本样式,详见TEXTSTYLE
  22876. // }
  22877. // },
  22878. itemStyle: {
  22879. normal: {
  22880. opacity: 0.8
  22881. // color: 各异
  22882. }
  22883. }
  22884. }
  22885. });
  22886. /***/ },
  22887. /* 144 */
  22888. /***/ function(module, exports, __webpack_require__) {
  22889. var SymbolDraw = __webpack_require__(99);
  22890. var LargeSymbolDraw = __webpack_require__(145);
  22891. __webpack_require__(1).extendChartView({
  22892. type: 'scatter',
  22893. init: function () {
  22894. this._normalSymbolDraw = new SymbolDraw();
  22895. this._largeSymbolDraw = new LargeSymbolDraw();
  22896. },
  22897. render: function (seriesModel, ecModel, api) {
  22898. var data = seriesModel.getData();
  22899. var largeSymbolDraw = this._largeSymbolDraw;
  22900. var normalSymbolDraw = this._normalSymbolDraw;
  22901. var group = this.group;
  22902. var symbolDraw = seriesModel.get('large') && data.count() > seriesModel.get('largeThreshold')
  22903. ? largeSymbolDraw : normalSymbolDraw;
  22904. this._symbolDraw = symbolDraw;
  22905. symbolDraw.updateData(data);
  22906. group.add(symbolDraw.group);
  22907. group.remove(
  22908. symbolDraw === largeSymbolDraw
  22909. ? normalSymbolDraw.group : largeSymbolDraw.group
  22910. );
  22911. },
  22912. updateLayout: function (seriesModel) {
  22913. this._symbolDraw.updateLayout(seriesModel);
  22914. },
  22915. remove: function (ecModel, api) {
  22916. this._symbolDraw && this._symbolDraw.remove(api, true);
  22917. }
  22918. });
  22919. /***/ },
  22920. /* 145 */
  22921. /***/ function(module, exports, __webpack_require__) {
  22922. var graphic = __webpack_require__(42);
  22923. var symbolUtil = __webpack_require__(101);
  22924. var zrUtil = __webpack_require__(3);
  22925. var LargeSymbolPath = graphic.extendShape({
  22926. shape: {
  22927. points: null,
  22928. sizes: null
  22929. },
  22930. symbolProxy: null,
  22931. buildPath: function (path, shape) {
  22932. var points = shape.points;
  22933. var sizes = shape.sizes;
  22934. var symbolProxy = this.symbolProxy;
  22935. var symbolProxyShape = symbolProxy.shape;
  22936. for (var i = 0; i < points.length; i++) {
  22937. var pt = points[i];
  22938. var size = sizes[i];
  22939. if (size[0] < 4) {
  22940. // Optimize for small symbol
  22941. path.rect(
  22942. pt[0] - size[0] / 2, pt[1] - size[1] / 2,
  22943. size[0], size[1]
  22944. );
  22945. }
  22946. else {
  22947. symbolProxyShape.x = pt[0] - size[0] / 2;
  22948. symbolProxyShape.y = pt[1] - size[1] / 2;
  22949. symbolProxyShape.width = size[0];
  22950. symbolProxyShape.height = size[1];
  22951. symbolProxy.buildPath(path, symbolProxyShape);
  22952. }
  22953. }
  22954. }
  22955. });
  22956. function LargeSymbolDraw() {
  22957. this.group = new graphic.Group();
  22958. this._symbolEl = new LargeSymbolPath({
  22959. silent: true
  22960. });
  22961. }
  22962. var largeSymbolProto = LargeSymbolDraw.prototype;
  22963. /**
  22964. * Update symbols draw by new data
  22965. * @param {module:echarts/data/List} data
  22966. */
  22967. largeSymbolProto.updateData = function (data) {
  22968. this.group.removeAll();
  22969. var symbolEl = this._symbolEl;
  22970. var seriesModel = data.hostModel;
  22971. symbolEl.setShape({
  22972. points: data.mapArray(data.getItemLayout),
  22973. sizes: data.mapArray(
  22974. function (idx) {
  22975. var size = data.getItemVisual(idx, 'symbolSize');
  22976. if (!zrUtil.isArray(size)) {
  22977. size = [size, size];
  22978. }
  22979. return size;
  22980. }
  22981. )
  22982. });
  22983. // Create symbolProxy to build path for each data
  22984. symbolEl.symbolProxy = symbolUtil.createSymbol(
  22985. data.getVisual('symbol'), 0, 0, 0, 0
  22986. );
  22987. // Use symbolProxy setColor method
  22988. symbolEl.setColor = symbolEl.symbolProxy.setColor;
  22989. symbolEl.useStyle(
  22990. seriesModel.getModel('itemStyle.normal').getItemStyle(['color'])
  22991. );
  22992. var visualColor = data.getVisual('color');
  22993. if (visualColor) {
  22994. symbolEl.setColor(visualColor);
  22995. }
  22996. // Add back
  22997. this.group.add(this._symbolEl);
  22998. };
  22999. largeSymbolProto.updateLayout = function (seriesModel) {
  23000. var data = seriesModel.getData();
  23001. this._symbolEl.setShape({
  23002. points: data.mapArray(data.getItemLayout)
  23003. });
  23004. };
  23005. largeSymbolProto.remove = function () {
  23006. this.group.removeAll();
  23007. };
  23008. module.exports = LargeSymbolDraw;
  23009. /***/ },
  23010. /* 146 */,
  23011. /* 147 */,
  23012. /* 148 */,
  23013. /* 149 */,
  23014. /* 150 */,
  23015. /* 151 */,
  23016. /* 152 */,
  23017. /* 153 */,
  23018. /* 154 */,
  23019. /* 155 */,
  23020. /* 156 */,
  23021. /* 157 */,
  23022. /* 158 */,
  23023. /* 159 */,
  23024. /* 160 */,
  23025. /* 161 */,
  23026. /* 162 */,
  23027. /* 163 */,
  23028. /* 164 */,
  23029. /* 165 */,
  23030. /* 166 */,
  23031. /* 167 */,
  23032. /* 168 */,
  23033. /* 169 */
  23034. /***/ function(module, exports, __webpack_require__) {
  23035. /**
  23036. * @module echarts/component/helper/RoamController
  23037. */
  23038. var Eventful = __webpack_require__(32);
  23039. var zrUtil = __webpack_require__(3);
  23040. var eventTool = __webpack_require__(81);
  23041. var interactionMutex = __webpack_require__(170);
  23042. function mousedown(e) {
  23043. if (e.target && e.target.draggable) {
  23044. return;
  23045. }
  23046. var x = e.offsetX;
  23047. var y = e.offsetY;
  23048. var rect = this.rectProvider && this.rectProvider();
  23049. if (rect && rect.contain(x, y)) {
  23050. this._x = x;
  23051. this._y = y;
  23052. this._dragging = true;
  23053. }
  23054. }
  23055. function mousemove(e) {
  23056. if (!this._dragging) {
  23057. return;
  23058. }
  23059. eventTool.stop(e.event);
  23060. if (e.gestureEvent !== 'pinch') {
  23061. if (interactionMutex.isTaken('globalPan', this._zr)) {
  23062. return;
  23063. }
  23064. var x = e.offsetX;
  23065. var y = e.offsetY;
  23066. var dx = x - this._x;
  23067. var dy = y - this._y;
  23068. this._x = x;
  23069. this._y = y;
  23070. var target = this.target;
  23071. if (target) {
  23072. var pos = target.position;
  23073. pos[0] += dx;
  23074. pos[1] += dy;
  23075. target.dirty();
  23076. }
  23077. eventTool.stop(e.event);
  23078. this.trigger('pan', dx, dy);
  23079. }
  23080. }
  23081. function mouseup(e) {
  23082. this._dragging = false;
  23083. }
  23084. function mousewheel(e) {
  23085. // Convenience:
  23086. // Mac and VM Windows on Mac: scroll up: zoom out.
  23087. // Windows: scroll up: zoom in.
  23088. var zoomDelta = e.wheelDelta > 0 ? 1.1 : 1 / 1.1;
  23089. zoom.call(this, e, zoomDelta, e.offsetX, e.offsetY);
  23090. }
  23091. function pinch(e) {
  23092. if (interactionMutex.isTaken('globalPan', this._zr)) {
  23093. return;
  23094. }
  23095. var zoomDelta = e.pinchScale > 1 ? 1.1 : 1 / 1.1;
  23096. zoom.call(this, e, zoomDelta, e.pinchX, e.pinchY);
  23097. }
  23098. function zoom(e, zoomDelta, zoomX, zoomY) {
  23099. var rect = this.rectProvider && this.rectProvider();
  23100. if (rect && rect.contain(zoomX, zoomY)) {
  23101. // When mouse is out of roamController rect,
  23102. // default befavoius should be be disabled, otherwise
  23103. // page sliding is disabled, contrary to expectation.
  23104. eventTool.stop(e.event);
  23105. var target = this.target;
  23106. var zoomLimit = this.zoomLimit;
  23107. if (target) {
  23108. var pos = target.position;
  23109. var scale = target.scale;
  23110. var newZoom = this.zoom = this.zoom || 1;
  23111. newZoom *= zoomDelta;
  23112. if (zoomLimit) {
  23113. var zoomMin = zoomLimit.min || 0;
  23114. var zoomMax = zoomLimit.max || Infinity;
  23115. newZoom = Math.max(
  23116. Math.min(zoomMax, newZoom),
  23117. zoomMin
  23118. );
  23119. }
  23120. var zoomScale = newZoom / this.zoom;
  23121. this.zoom = newZoom;
  23122. // Keep the mouse center when scaling
  23123. pos[0] -= (zoomX - pos[0]) * (zoomScale - 1);
  23124. pos[1] -= (zoomY - pos[1]) * (zoomScale - 1);
  23125. scale[0] *= zoomScale;
  23126. scale[1] *= zoomScale;
  23127. target.dirty();
  23128. }
  23129. this.trigger('zoom', zoomDelta, zoomX, zoomY);
  23130. }
  23131. }
  23132. /**
  23133. * @alias module:echarts/component/helper/RoamController
  23134. * @constructor
  23135. * @mixin {module:zrender/mixin/Eventful}
  23136. *
  23137. * @param {module:zrender/zrender~ZRender} zr
  23138. * @param {module:zrender/Element} target
  23139. * @param {Function} rectProvider
  23140. */
  23141. function RoamController(zr, target, rectProvider) {
  23142. /**
  23143. * @type {module:zrender/Element}
  23144. */
  23145. this.target = target;
  23146. /**
  23147. * @type {Function}
  23148. */
  23149. this.rectProvider = rectProvider;
  23150. /**
  23151. * { min: 1, max: 2 }
  23152. * @type {Object}
  23153. */
  23154. this.zoomLimit;
  23155. /**
  23156. * @type {number}
  23157. */
  23158. this.zoom;
  23159. /**
  23160. * @type {module:zrender}
  23161. */
  23162. this._zr = zr;
  23163. // Avoid two roamController bind the same handler
  23164. var bind = zrUtil.bind;
  23165. var mousedownHandler = bind(mousedown, this);
  23166. var mousemoveHandler = bind(mousemove, this);
  23167. var mouseupHandler = bind(mouseup, this);
  23168. var mousewheelHandler = bind(mousewheel, this);
  23169. var pinchHandler = bind(pinch, this);
  23170. Eventful.call(this);
  23171. /**
  23172. * Notice: only enable needed types. For example, if 'zoom'
  23173. * is not needed, 'zoom' should not be enabled, otherwise
  23174. * default mousewheel behaviour (scroll page) will be disabled.
  23175. *
  23176. * @param {boolean|string} [controlType=true] Specify the control type,
  23177. * which can be null/undefined or true/false
  23178. * or 'pan/move' or 'zoom'/'scale'
  23179. */
  23180. this.enable = function (controlType) {
  23181. // Disable previous first
  23182. this.disable();
  23183. if (controlType == null) {
  23184. controlType = true;
  23185. }
  23186. if (controlType === true || (controlType === 'move' || controlType === 'pan')) {
  23187. zr.on('mousedown', mousedownHandler);
  23188. zr.on('mousemove', mousemoveHandler);
  23189. zr.on('mouseup', mouseupHandler);
  23190. }
  23191. if (controlType === true || (controlType === 'scale' || controlType === 'zoom')) {
  23192. zr.on('mousewheel', mousewheelHandler);
  23193. zr.on('pinch', pinchHandler);
  23194. }
  23195. };
  23196. this.disable = function () {
  23197. zr.off('mousedown', mousedownHandler);
  23198. zr.off('mousemove', mousemoveHandler);
  23199. zr.off('mouseup', mouseupHandler);
  23200. zr.off('mousewheel', mousewheelHandler);
  23201. zr.off('pinch', pinchHandler);
  23202. };
  23203. this.dispose = this.disable;
  23204. this.isDragging = function () {
  23205. return this._dragging;
  23206. };
  23207. this.isPinching = function () {
  23208. return this._pinching;
  23209. };
  23210. }
  23211. zrUtil.mixin(RoamController, Eventful);
  23212. module.exports = RoamController;
  23213. /***/ },
  23214. /* 170 */
  23215. /***/ function(module, exports) {
  23216. var ATTR = '\0_ec_interaction_mutex';
  23217. var interactionMutex = {
  23218. take: function (key, zr) {
  23219. getStore(zr)[key] = true;
  23220. },
  23221. release: function (key, zr) {
  23222. getStore(zr)[key] = false;
  23223. },
  23224. isTaken: function (key, zr) {
  23225. return !!getStore(zr)[key];
  23226. }
  23227. };
  23228. function getStore(zr) {
  23229. return zr[ATTR] || (zr[ATTR] = {});
  23230. }
  23231. module.exports = interactionMutex;
  23232. /***/ },
  23233. /* 171 */,
  23234. /* 172 */,
  23235. /* 173 */,
  23236. /* 174 */,
  23237. /* 175 */,
  23238. /* 176 */,
  23239. /* 177 */,
  23240. /* 178 */,
  23241. /* 179 */,
  23242. /* 180 */,
  23243. /* 181 */,
  23244. /* 182 */,
  23245. /* 183 */,
  23246. /* 184 */,
  23247. /* 185 */,
  23248. /* 186 */,
  23249. /* 187 */,
  23250. /* 188 */,
  23251. /* 189 */,
  23252. /* 190 */,
  23253. /* 191 */,
  23254. /* 192 */,
  23255. /* 193 */,
  23256. /* 194 */
  23257. /***/ function(module, exports, __webpack_require__) {
  23258. /**
  23259. * @module echarts/chart/helper/LineDraw
  23260. */
  23261. var graphic = __webpack_require__(42);
  23262. var LineGroup = __webpack_require__(195);
  23263. function isPointNaN(pt) {
  23264. return isNaN(pt[0]) || isNaN(pt[1]);
  23265. }
  23266. function lineNeedsDraw(pts) {
  23267. return !isPointNaN(pts[0]) && !isPointNaN(pts[1]);
  23268. }
  23269. /**
  23270. * @alias module:echarts/component/marker/LineDraw
  23271. * @constructor
  23272. */
  23273. function LineDraw(ctor) {
  23274. this._ctor = ctor || LineGroup;
  23275. this.group = new graphic.Group();
  23276. }
  23277. var lineDrawProto = LineDraw.prototype;
  23278. /**
  23279. * @param {module:echarts/data/List} lineData
  23280. */
  23281. lineDrawProto.updateData = function (lineData) {
  23282. var oldLineData = this._lineData;
  23283. var group = this.group;
  23284. var LineCtor = this._ctor;
  23285. lineData.diff(oldLineData)
  23286. .add(function (idx) {
  23287. if (!lineNeedsDraw(lineData.getItemLayout(idx))) {
  23288. return;
  23289. }
  23290. var lineGroup = new LineCtor(lineData, idx);
  23291. lineData.setItemGraphicEl(idx, lineGroup);
  23292. group.add(lineGroup);
  23293. })
  23294. .update(function (newIdx, oldIdx) {
  23295. var lineGroup = oldLineData.getItemGraphicEl(oldIdx);
  23296. if (!lineNeedsDraw(lineData.getItemLayout(newIdx))) {
  23297. group.remove(lineGroup);
  23298. return;
  23299. }
  23300. if (!lineGroup) {
  23301. lineGroup = new LineCtor(lineData, newIdx);
  23302. }
  23303. else {
  23304. lineGroup.updateData(lineData, newIdx);
  23305. }
  23306. lineData.setItemGraphicEl(newIdx, lineGroup);
  23307. group.add(lineGroup);
  23308. })
  23309. .remove(function (idx) {
  23310. group.remove(oldLineData.getItemGraphicEl(idx));
  23311. })
  23312. .execute();
  23313. this._lineData = lineData;
  23314. };
  23315. lineDrawProto.updateLayout = function () {
  23316. var lineData = this._lineData;
  23317. lineData.eachItemGraphicEl(function (el, idx) {
  23318. el.updateLayout(lineData, idx);
  23319. }, this);
  23320. };
  23321. lineDrawProto.remove = function () {
  23322. this.group.removeAll();
  23323. };
  23324. module.exports = LineDraw;
  23325. /***/ },
  23326. /* 195 */
  23327. /***/ function(module, exports, __webpack_require__) {
  23328. /**
  23329. * @module echarts/chart/helper/Line
  23330. */
  23331. var symbolUtil = __webpack_require__(101);
  23332. var vector = __webpack_require__(16);
  23333. // var matrix = require('zrender/lib/core/matrix');
  23334. var LinePath = __webpack_require__(196);
  23335. var graphic = __webpack_require__(42);
  23336. var zrUtil = __webpack_require__(3);
  23337. var numberUtil = __webpack_require__(7);
  23338. var SYMBOL_CATEGORIES = ['fromSymbol', 'toSymbol'];
  23339. function makeSymbolTypeKey(symbolCategory) {
  23340. return '_' + symbolCategory + 'Type';
  23341. }
  23342. /**
  23343. * @inner
  23344. */
  23345. function createSymbol(name, lineData, idx) {
  23346. var color = lineData.getItemVisual(idx, 'color');
  23347. var symbolType = lineData.getItemVisual(idx, name);
  23348. var symbolSize = lineData.getItemVisual(idx, name + 'Size');
  23349. if (!symbolType || symbolType === 'none') {
  23350. return;
  23351. }
  23352. if (!zrUtil.isArray(symbolSize)) {
  23353. symbolSize = [symbolSize, symbolSize];
  23354. }
  23355. var symbolPath = symbolUtil.createSymbol(
  23356. symbolType, -symbolSize[0] / 2, -symbolSize[1] / 2,
  23357. symbolSize[0], symbolSize[1], color
  23358. );
  23359. symbolPath.name = name;
  23360. return symbolPath;
  23361. }
  23362. function createLine(points) {
  23363. var line = new LinePath({
  23364. name: 'line'
  23365. });
  23366. setLinePoints(line.shape, points);
  23367. return line;
  23368. }
  23369. function setLinePoints(targetShape, points) {
  23370. var p1 = points[0];
  23371. var p2 = points[1];
  23372. var cp1 = points[2];
  23373. targetShape.x1 = p1[0];
  23374. targetShape.y1 = p1[1];
  23375. targetShape.x2 = p2[0];
  23376. targetShape.y2 = p2[1];
  23377. targetShape.percent = 1;
  23378. if (cp1) {
  23379. targetShape.cpx1 = cp1[0];
  23380. targetShape.cpy1 = cp1[1];
  23381. }
  23382. }
  23383. function updateSymbolAndLabelBeforeLineUpdate () {
  23384. var lineGroup = this;
  23385. var symbolFrom = lineGroup.childOfName('fromSymbol');
  23386. var symbolTo = lineGroup.childOfName('toSymbol');
  23387. var label = lineGroup.childOfName('label');
  23388. // Quick reject
  23389. if (!symbolFrom && !symbolTo && label.ignore) {
  23390. return;
  23391. }
  23392. var invScale = 1;
  23393. var parentNode = this.parent;
  23394. while (parentNode) {
  23395. if (parentNode.scale) {
  23396. invScale /= parentNode.scale[0];
  23397. }
  23398. parentNode = parentNode.parent;
  23399. }
  23400. var line = lineGroup.childOfName('line');
  23401. // If line not changed
  23402. // FIXME Parent scale changed
  23403. if (!this.__dirty && !line.__dirty) {
  23404. return;
  23405. }
  23406. var percent = line.shape.percent;
  23407. var fromPos = line.pointAt(0);
  23408. var toPos = line.pointAt(percent);
  23409. var d = vector.sub([], toPos, fromPos);
  23410. vector.normalize(d, d);
  23411. if (symbolFrom) {
  23412. symbolFrom.attr('position', fromPos);
  23413. var tangent = line.tangentAt(0);
  23414. symbolFrom.attr('rotation', Math.PI / 2 - Math.atan2(
  23415. tangent[1], tangent[0]
  23416. ));
  23417. symbolFrom.attr('scale', [invScale * percent, invScale * percent]);
  23418. }
  23419. if (symbolTo) {
  23420. symbolTo.attr('position', toPos);
  23421. var tangent = line.tangentAt(1);
  23422. symbolTo.attr('rotation', -Math.PI / 2 - Math.atan2(
  23423. tangent[1], tangent[0]
  23424. ));
  23425. symbolTo.attr('scale', [invScale * percent, invScale * percent]);
  23426. }
  23427. if (!label.ignore) {
  23428. label.attr('position', toPos);
  23429. var textPosition;
  23430. var textAlign;
  23431. var textVerticalAlign;
  23432. var distance = 5 * invScale;
  23433. // End
  23434. if (label.__position === 'end') {
  23435. textPosition = [d[0] * distance + toPos[0], d[1] * distance + toPos[1]];
  23436. textAlign = d[0] > 0.8 ? 'left' : (d[0] < -0.8 ? 'right' : 'center');
  23437. textVerticalAlign = d[1] > 0.8 ? 'top' : (d[1] < -0.8 ? 'bottom' : 'middle');
  23438. }
  23439. // Middle
  23440. else if (label.__position === 'middle') {
  23441. var halfPercent = percent / 2;
  23442. var tangent = line.tangentAt(halfPercent);
  23443. var n = [tangent[1], -tangent[0]];
  23444. var cp = line.pointAt(halfPercent);
  23445. if (n[1] > 0) {
  23446. n[0] = -n[0];
  23447. n[1] = -n[1];
  23448. }
  23449. textPosition = [cp[0] + n[0] * distance, cp[1] + n[1] * distance];
  23450. textAlign = 'center';
  23451. textVerticalAlign = 'bottom';
  23452. var rotation = -Math.atan2(tangent[1], tangent[0]);
  23453. if (toPos[0] < fromPos[0]) {
  23454. rotation = Math.PI + rotation;
  23455. }
  23456. label.attr('rotation', rotation);
  23457. }
  23458. // Start
  23459. else {
  23460. textPosition = [-d[0] * distance + fromPos[0], -d[1] * distance + fromPos[1]];
  23461. textAlign = d[0] > 0.8 ? 'right' : (d[0] < -0.8 ? 'left' : 'center');
  23462. textVerticalAlign = d[1] > 0.8 ? 'bottom' : (d[1] < -0.8 ? 'top' : 'middle');
  23463. }
  23464. label.attr({
  23465. style: {
  23466. // Use the user specified text align and baseline first
  23467. textVerticalAlign: label.__verticalAlign || textVerticalAlign,
  23468. textAlign: label.__textAlign || textAlign
  23469. },
  23470. position: textPosition,
  23471. scale: [invScale, invScale]
  23472. });
  23473. }
  23474. }
  23475. /**
  23476. * @constructor
  23477. * @extends {module:zrender/graphic/Group}
  23478. * @alias {module:echarts/chart/helper/Line}
  23479. */
  23480. function Line(lineData, idx) {
  23481. graphic.Group.call(this);
  23482. this._createLine(lineData, idx);
  23483. }
  23484. var lineProto = Line.prototype;
  23485. // Update symbol position and rotation
  23486. lineProto.beforeUpdate = updateSymbolAndLabelBeforeLineUpdate;
  23487. lineProto._createLine = function (lineData, idx) {
  23488. var seriesModel = lineData.hostModel;
  23489. var linePoints = lineData.getItemLayout(idx);
  23490. var line = createLine(linePoints);
  23491. line.shape.percent = 0;
  23492. graphic.initProps(line, {
  23493. shape: {
  23494. percent: 1
  23495. }
  23496. }, seriesModel, idx);
  23497. this.add(line);
  23498. var label = new graphic.Text({
  23499. name: 'label'
  23500. });
  23501. this.add(label);
  23502. zrUtil.each(SYMBOL_CATEGORIES, function (symbolCategory) {
  23503. var symbol = createSymbol(symbolCategory, lineData, idx);
  23504. // symbols must added after line to make sure
  23505. // it will be updated after line#update.
  23506. // Or symbol position and rotation update in line#beforeUpdate will be one frame slow
  23507. this.add(symbol);
  23508. this[makeSymbolTypeKey(symbolCategory)] = lineData.getItemVisual(idx, symbolCategory);
  23509. }, this);
  23510. this._updateCommonStl(lineData, idx);
  23511. };
  23512. lineProto.updateData = function (lineData, idx) {
  23513. var seriesModel = lineData.hostModel;
  23514. var line = this.childOfName('line');
  23515. var linePoints = lineData.getItemLayout(idx);
  23516. var target = {
  23517. shape: {}
  23518. };
  23519. setLinePoints(target.shape, linePoints);
  23520. graphic.updateProps(line, target, seriesModel, idx);
  23521. zrUtil.each(SYMBOL_CATEGORIES, function (symbolCategory) {
  23522. var symbolType = lineData.getItemVisual(idx, symbolCategory);
  23523. var key = makeSymbolTypeKey(symbolCategory);
  23524. // Symbol changed
  23525. if (this[key] !== symbolType) {
  23526. var symbol = createSymbol(symbolCategory, lineData, idx);
  23527. this.remove(this.childOfName(symbolCategory));
  23528. this.add(symbol);
  23529. }
  23530. this[key] = symbolType;
  23531. }, this);
  23532. this._updateCommonStl(lineData, idx);
  23533. };
  23534. lineProto._updateCommonStl = function (lineData, idx) {
  23535. var seriesModel = lineData.hostModel;
  23536. var line = this.childOfName('line');
  23537. var itemModel = lineData.getItemModel(idx);
  23538. var labelModel = itemModel.getModel('label.normal');
  23539. var textStyleModel = labelModel.getModel('textStyle');
  23540. var labelHoverModel = itemModel.getModel('label.emphasis');
  23541. var textStyleHoverModel = labelHoverModel.getModel('textStyle');
  23542. var defaultText = numberUtil.round(seriesModel.getRawValue(idx));
  23543. if (isNaN(defaultText)) {
  23544. // Use name
  23545. defaultText = lineData.getName(idx);
  23546. }
  23547. line.useStyle(zrUtil.extend(
  23548. {
  23549. strokeNoScale: true,
  23550. fill: 'none',
  23551. stroke: lineData.getItemVisual(idx, 'color')
  23552. },
  23553. itemModel.getModel('lineStyle.normal').getLineStyle()
  23554. ));
  23555. line.hoverStyle = itemModel.getModel('lineStyle.emphasis').getLineStyle();
  23556. var defaultColor = lineData.getItemVisual(idx, 'color') || '#000';
  23557. var label = this.childOfName('label');
  23558. // label.afterUpdate = lineAfterUpdate;
  23559. label.setStyle({
  23560. text: labelModel.get('show')
  23561. ? zrUtil.retrieve(
  23562. seriesModel.getFormattedLabel(idx, 'normal', lineData.dataType),
  23563. defaultText
  23564. )
  23565. : '',
  23566. textFont: textStyleModel.getFont(),
  23567. fill: textStyleModel.getTextColor() || defaultColor
  23568. });
  23569. label.hoverStyle = {
  23570. text: labelHoverModel.get('show')
  23571. ? zrUtil.retrieve(
  23572. seriesModel.getFormattedLabel(idx, 'emphasis', lineData.dataType),
  23573. defaultText
  23574. )
  23575. : '',
  23576. textFont: textStyleHoverModel.getFont(),
  23577. fill: textStyleHoverModel.getTextColor() || defaultColor
  23578. };
  23579. label.__textAlign = textStyleModel.get('align');
  23580. label.__verticalAlign = textStyleModel.get('baseline');
  23581. label.__position = labelModel.get('position');
  23582. label.ignore = !label.style.text && !label.hoverStyle.text;
  23583. graphic.setHoverStyle(this);
  23584. };
  23585. lineProto.updateLayout = function (lineData, idx) {
  23586. var points = lineData.getItemLayout(idx);
  23587. var linePath = this.childOfName('line');
  23588. setLinePoints(linePath.shape, points);
  23589. linePath.dirty(true);
  23590. };
  23591. lineProto.setLinePoints = function (points) {
  23592. var linePath = this.childOfName('line');
  23593. setLinePoints(linePath.shape, points);
  23594. linePath.dirty();
  23595. };
  23596. zrUtil.inherits(Line, graphic.Group);
  23597. module.exports = Line;
  23598. /***/ },
  23599. /* 196 */
  23600. /***/ function(module, exports, __webpack_require__) {
  23601. /**
  23602. * Line path for bezier and straight line draw
  23603. */
  23604. var graphic = __webpack_require__(42);
  23605. var vec2 = __webpack_require__(16);
  23606. var straightLineProto = graphic.Line.prototype;
  23607. var bezierCurveProto = graphic.BezierCurve.prototype;
  23608. function isLine(shape) {
  23609. return shape.cpx1 == null || shape.cpy1 == null;
  23610. }
  23611. module.exports = graphic.extendShape({
  23612. type: 'ec-line',
  23613. style: {
  23614. stroke: '#000',
  23615. fill: null
  23616. },
  23617. shape: {
  23618. x1: 0,
  23619. y1: 0,
  23620. x2: 0,
  23621. y2: 0,
  23622. percent: 1,
  23623. cpx1: null,
  23624. cpy1: null
  23625. },
  23626. buildPath: function (ctx, shape) {
  23627. (isLine(shape) ? straightLineProto : bezierCurveProto).buildPath(ctx, shape);
  23628. },
  23629. pointAt: function (t) {
  23630. return isLine(this.shape)
  23631. ? straightLineProto.pointAt.call(this, t)
  23632. : bezierCurveProto.pointAt.call(this, t);
  23633. },
  23634. tangentAt: function (t) {
  23635. var shape = this.shape;
  23636. var p = isLine(shape)
  23637. ? [shape.x2 - shape.x1, shape.y2 - shape.y1]
  23638. : bezierCurveProto.tangentAt.call(this, t);
  23639. return vec2.normalize(p, p);
  23640. }
  23641. });
  23642. /***/ },
  23643. /* 197 */,
  23644. /* 198 */,
  23645. /* 199 */,
  23646. /* 200 */,
  23647. /* 201 */,
  23648. /* 202 */,
  23649. /* 203 */,
  23650. /* 204 */,
  23651. /* 205 */,
  23652. /* 206 */,
  23653. /* 207 */,
  23654. /* 208 */,
  23655. /* 209 */,
  23656. /* 210 */,
  23657. /* 211 */,
  23658. /* 212 */,
  23659. /* 213 */,
  23660. /* 214 */,
  23661. /* 215 */,
  23662. /* 216 */,
  23663. /* 217 */,
  23664. /* 218 */,
  23665. /* 219 */,
  23666. /* 220 */,
  23667. /* 221 */,
  23668. /* 222 */,
  23669. /* 223 */,
  23670. /* 224 */,
  23671. /* 225 */,
  23672. /* 226 */,
  23673. /* 227 */,
  23674. /* 228 */
  23675. /***/ function(module, exports, __webpack_require__) {
  23676. /**
  23677. * Box selection tool.
  23678. *
  23679. * @module echarts/component/helper/SelectController
  23680. */
  23681. var Eventful = __webpack_require__(32);
  23682. var zrUtil = __webpack_require__(3);
  23683. var graphic = __webpack_require__(42);
  23684. var bind = zrUtil.bind;
  23685. var each = zrUtil.each;
  23686. var mathMin = Math.min;
  23687. var mathMax = Math.max;
  23688. var mathPow = Math.pow;
  23689. var COVER_Z = 10000;
  23690. var UNSELECT_THRESHOLD = 2;
  23691. var EVENTS = ['mousedown', 'mousemove', 'mouseup'];
  23692. /**
  23693. * @alias module:echarts/component/helper/SelectController
  23694. * @constructor
  23695. * @mixin {module:zrender/mixin/Eventful}
  23696. *
  23697. * @param {string} type 'line', 'rect'
  23698. * @param {module:zrender/zrender~ZRender} zr
  23699. * @param {Object} [opt]
  23700. * @param {number} [opt.width]
  23701. * @param {number} [opt.lineWidth]
  23702. * @param {string} [opt.stroke]
  23703. * @param {string} [opt.fill]
  23704. */
  23705. function SelectController(type, zr, opt) {
  23706. Eventful.call(this);
  23707. /**
  23708. * @type {string}
  23709. * @readOnly
  23710. */
  23711. this.type = type;
  23712. /**
  23713. * @type {module:zrender/zrender~ZRender}
  23714. */
  23715. this.zr = zr;
  23716. /**
  23717. * @type {Object}
  23718. * @readOnly
  23719. */
  23720. this.opt = zrUtil.clone(opt);
  23721. /**
  23722. * @type {module:zrender/container/Group}
  23723. * @readOnly
  23724. */
  23725. this.group = new graphic.Group();
  23726. /**
  23727. * @type {module:zrender/core/BoundingRect}
  23728. */
  23729. this._containerRect = null;
  23730. /**
  23731. * @type {Array.<nubmer>}
  23732. * @private
  23733. */
  23734. this._track = [];
  23735. /**
  23736. * @type {boolean}
  23737. */
  23738. this._dragging;
  23739. /**
  23740. * @type {module:zrender/Element}
  23741. * @private
  23742. */
  23743. this._cover;
  23744. /**
  23745. * @type {boolean}
  23746. * @private
  23747. */
  23748. this._disabled = true;
  23749. /**
  23750. * @type {Object}
  23751. * @private
  23752. */
  23753. this._handlers = {
  23754. mousedown: bind(mousedown, this),
  23755. mousemove: bind(mousemove, this),
  23756. mouseup: bind(mouseup, this)
  23757. };
  23758. each(EVENTS, function (eventName) {
  23759. this.zr.on(eventName, this._handlers[eventName]);
  23760. }, this);
  23761. }
  23762. SelectController.prototype = {
  23763. constructor: SelectController,
  23764. /**
  23765. * @param {module:zrender/mixin/Transformable} container
  23766. * @param {module:zrender/core/BoundingRect|boolean} [rect] If not specified,
  23767. * use container.getBoundingRect().
  23768. * If false, do not use containerRect.
  23769. */
  23770. enable: function (container, rect) {
  23771. this._disabled = false;
  23772. // Remove from old container.
  23773. removeGroup.call(this);
  23774. // boundingRect will change when dragging, so we have
  23775. // to keep initial boundingRect.
  23776. this._containerRect = rect !== false
  23777. ? (rect || container.getBoundingRect()) : null;
  23778. // Add to new container.
  23779. container.add(this.group);
  23780. },
  23781. /**
  23782. * Update cover location.
  23783. * @param {Array.<number>|Object} ranges If null/undefined, remove cover.
  23784. */
  23785. update: function (ranges) {
  23786. // TODO
  23787. // Only support one interval yet.
  23788. renderCover.call(this, ranges && zrUtil.clone(ranges));
  23789. },
  23790. disable: function () {
  23791. this._disabled = true;
  23792. removeGroup.call(this);
  23793. },
  23794. dispose: function () {
  23795. this.disable();
  23796. each(EVENTS, function (eventName) {
  23797. this.zr.off(eventName, this._handlers[eventName]);
  23798. }, this);
  23799. }
  23800. };
  23801. zrUtil.mixin(SelectController, Eventful);
  23802. function updateZ(group) {
  23803. group.traverse(function (el) {
  23804. el.z = COVER_Z;
  23805. });
  23806. }
  23807. function isInContainer(x, y) {
  23808. var localPos = this.group.transformCoordToLocal(x, y);
  23809. return !this._containerRect
  23810. || this._containerRect.contain(localPos[0], localPos[1]);
  23811. }
  23812. function preventDefault(e) {
  23813. var rawE = e.event;
  23814. rawE.preventDefault && rawE.preventDefault();
  23815. }
  23816. function mousedown(e) {
  23817. if (this._disabled || (e.target && e.target.draggable)) {
  23818. return;
  23819. }
  23820. preventDefault(e);
  23821. var x = e.offsetX;
  23822. var y = e.offsetY;
  23823. if (isInContainer.call(this, x, y)) {
  23824. this._dragging = true;
  23825. this._track = [[x, y]];
  23826. }
  23827. }
  23828. function mousemove(e) {
  23829. if (!this._dragging || this._disabled) {
  23830. return;
  23831. }
  23832. preventDefault(e);
  23833. updateViewByCursor.call(this, e);
  23834. }
  23835. function mouseup(e) {
  23836. if (!this._dragging || this._disabled) {
  23837. return;
  23838. }
  23839. preventDefault(e);
  23840. updateViewByCursor.call(this, e, true);
  23841. this._dragging = false;
  23842. this._track = [];
  23843. }
  23844. function updateViewByCursor(e, isEnd) {
  23845. var x = e.offsetX;
  23846. var y = e.offsetY;
  23847. if (isInContainer.call(this, x, y)) {
  23848. this._track.push([x, y]);
  23849. // Create or update cover.
  23850. var ranges = shouldShowCover.call(this)
  23851. ? coverRenderers[this.type].getRanges.call(this)
  23852. // Remove cover.
  23853. : [];
  23854. renderCover.call(this, ranges);
  23855. this.trigger('selected', zrUtil.clone(ranges));
  23856. if (isEnd) {
  23857. this.trigger('selectEnd', zrUtil.clone(ranges));
  23858. }
  23859. }
  23860. }
  23861. function shouldShowCover() {
  23862. var track = this._track;
  23863. if (!track.length) {
  23864. return false;
  23865. }
  23866. var p2 = track[track.length - 1];
  23867. var p1 = track[0];
  23868. var dx = p2[0] - p1[0];
  23869. var dy = p2[1] - p1[1];
  23870. var dist = mathPow(dx * dx + dy * dy, 0.5);
  23871. return dist > UNSELECT_THRESHOLD;
  23872. }
  23873. function renderCover(ranges) {
  23874. var coverRenderer = coverRenderers[this.type];
  23875. if (ranges && ranges.length) {
  23876. if (!this._cover) {
  23877. this._cover = coverRenderer.create.call(this);
  23878. this.group.add(this._cover);
  23879. }
  23880. coverRenderer.update.call(this, ranges);
  23881. }
  23882. else {
  23883. this.group.remove(this._cover);
  23884. this._cover = null;
  23885. }
  23886. updateZ(this.group);
  23887. }
  23888. function removeGroup() {
  23889. // container may 'removeAll' outside.
  23890. var group = this.group;
  23891. var container = group.parent;
  23892. if (container) {
  23893. container.remove(group);
  23894. }
  23895. }
  23896. function createRectCover() {
  23897. var opt = this.opt;
  23898. return new graphic.Rect({
  23899. // FIXME
  23900. // customize style.
  23901. style: {
  23902. stroke: opt.stroke,
  23903. fill: opt.fill,
  23904. lineWidth: opt.lineWidth,
  23905. opacity: opt.opacity
  23906. }
  23907. });
  23908. }
  23909. function getLocalTrack() {
  23910. return zrUtil.map(this._track, function (point) {
  23911. return this.group.transformCoordToLocal(point[0], point[1]);
  23912. }, this);
  23913. }
  23914. function getLocalTrackEnds() {
  23915. var localTrack = getLocalTrack.call(this);
  23916. var tail = localTrack.length - 1;
  23917. tail < 0 && (tail = 0);
  23918. return [localTrack[0], localTrack[tail]];
  23919. }
  23920. /**
  23921. * key: this.type
  23922. * @type {Object}
  23923. */
  23924. var coverRenderers = {
  23925. line: {
  23926. create: createRectCover,
  23927. getRanges: function () {
  23928. var ends = getLocalTrackEnds.call(this);
  23929. var min = mathMin(ends[0][0], ends[1][0]);
  23930. var max = mathMax(ends[0][0], ends[1][0]);
  23931. return [[min, max]];
  23932. },
  23933. update: function (ranges) {
  23934. var range = ranges[0];
  23935. var width = this.opt.width;
  23936. this._cover.setShape({
  23937. x: range[0],
  23938. y: -width / 2,
  23939. width: range[1] - range[0],
  23940. height: width
  23941. });
  23942. }
  23943. },
  23944. rect: {
  23945. create: createRectCover,
  23946. getRanges: function () {
  23947. var ends = getLocalTrackEnds.call(this);
  23948. var min = [
  23949. mathMin(ends[1][0], ends[0][0]),
  23950. mathMin(ends[1][1], ends[0][1])
  23951. ];
  23952. var max = [
  23953. mathMax(ends[1][0], ends[0][0]),
  23954. mathMax(ends[1][1], ends[0][1])
  23955. ];
  23956. return [[
  23957. [min[0], max[0]], // x range
  23958. [min[1], max[1]] // y range
  23959. ]];
  23960. },
  23961. update: function (ranges) {
  23962. var range = ranges[0];
  23963. this._cover.setShape({
  23964. x: range[0][0],
  23965. y: range[1][0],
  23966. width: range[0][1] - range[0][0],
  23967. height: range[1][1] - range[1][0]
  23968. });
  23969. }
  23970. }
  23971. };
  23972. module.exports = SelectController;
  23973. /***/ },
  23974. /* 229 */,
  23975. /* 230 */,
  23976. /* 231 */,
  23977. /* 232 */,
  23978. /* 233 */,
  23979. /* 234 */,
  23980. /* 235 */,
  23981. /* 236 */,
  23982. /* 237 */,
  23983. /* 238 */,
  23984. /* 239 */,
  23985. /* 240 */,
  23986. /* 241 */,
  23987. /* 242 */,
  23988. /* 243 */,
  23989. /* 244 */,
  23990. /* 245 */,
  23991. /* 246 */,
  23992. /* 247 */,
  23993. /* 248 */,
  23994. /* 249 */,
  23995. /* 250 */,
  23996. /* 251 */,
  23997. /* 252 */,
  23998. /* 253 */,
  23999. /* 254 */,
  24000. /* 255 */,
  24001. /* 256 */,
  24002. /* 257 */,
  24003. /* 258 */,
  24004. /* 259 */,
  24005. /* 260 */,
  24006. /* 261 */,
  24007. /* 262 */,
  24008. /* 263 */,
  24009. /* 264 */,
  24010. /* 265 */
  24011. /***/ function(module, exports, __webpack_require__) {
  24012. /**
  24013. * Legend component entry file8
  24014. */
  24015. __webpack_require__(266);
  24016. __webpack_require__(267);
  24017. __webpack_require__(268);
  24018. var echarts = __webpack_require__(1);
  24019. // Series Filter
  24020. echarts.registerProcessor('filter', __webpack_require__(270));
  24021. /***/ },
  24022. /* 266 */
  24023. /***/ function(module, exports, __webpack_require__) {
  24024. 'use strict';
  24025. var zrUtil = __webpack_require__(3);
  24026. var Model = __webpack_require__(8);
  24027. var LegendModel = __webpack_require__(1).extendComponentModel({
  24028. type: 'legend',
  24029. dependencies: ['series'],
  24030. layoutMode: {
  24031. type: 'box',
  24032. ignoreSize: true
  24033. },
  24034. init: function (option, parentModel, ecModel) {
  24035. this.mergeDefaultAndTheme(option, ecModel);
  24036. option.selected = option.selected || {};
  24037. this._updateData(ecModel);
  24038. var legendData = this._data;
  24039. // If has any selected in option.selected
  24040. var selectedMap = this.option.selected;
  24041. // If selectedMode is single, try to select one
  24042. if (legendData[0] && this.get('selectedMode') === 'single') {
  24043. var hasSelected = false;
  24044. for (var name in selectedMap) {
  24045. if (selectedMap[name]) {
  24046. this.select(name);
  24047. hasSelected = true;
  24048. }
  24049. }
  24050. // Try select the first if selectedMode is single
  24051. !hasSelected && this.select(legendData[0].get('name'));
  24052. }
  24053. },
  24054. mergeOption: function (option) {
  24055. LegendModel.superCall(this, 'mergeOption', option);
  24056. this._updateData(this.ecModel);
  24057. },
  24058. _updateData: function (ecModel) {
  24059. var legendData = zrUtil.map(this.get('data') || [], function (dataItem) {
  24060. if (typeof dataItem === 'string') {
  24061. dataItem = {
  24062. name: dataItem
  24063. };
  24064. }
  24065. return new Model(dataItem, this, this.ecModel);
  24066. }, this);
  24067. this._data = legendData;
  24068. var availableNames = zrUtil.map(ecModel.getSeries(), function (series) {
  24069. return series.name;
  24070. });
  24071. ecModel.eachSeries(function (seriesModel) {
  24072. if (seriesModel.legendDataProvider) {
  24073. var data = seriesModel.legendDataProvider();
  24074. availableNames = availableNames.concat(data.mapArray(data.getName));
  24075. }
  24076. });
  24077. /**
  24078. * @type {Array.<string>}
  24079. * @private
  24080. */
  24081. this._availableNames = availableNames;
  24082. },
  24083. /**
  24084. * @return {Array.<module:echarts/model/Model>}
  24085. */
  24086. getData: function () {
  24087. return this._data;
  24088. },
  24089. /**
  24090. * @param {string} name
  24091. */
  24092. select: function (name) {
  24093. var selected = this.option.selected;
  24094. var selectedMode = this.get('selectedMode');
  24095. if (selectedMode === 'single') {
  24096. var data = this._data;
  24097. zrUtil.each(data, function (dataItem) {
  24098. selected[dataItem.get('name')] = false;
  24099. });
  24100. }
  24101. selected[name] = true;
  24102. },
  24103. /**
  24104. * @param {string} name
  24105. */
  24106. unSelect: function (name) {
  24107. if (this.get('selectedMode') !== 'single') {
  24108. this.option.selected[name] = false;
  24109. }
  24110. },
  24111. /**
  24112. * @param {string} name
  24113. */
  24114. toggleSelected: function (name) {
  24115. var selected = this.option.selected;
  24116. // Default is true
  24117. if (!(name in selected)) {
  24118. selected[name] = true;
  24119. }
  24120. this[selected[name] ? 'unSelect' : 'select'](name);
  24121. },
  24122. /**
  24123. * @param {string} name
  24124. */
  24125. isSelected: function (name) {
  24126. var selected = this.option.selected;
  24127. return !((name in selected) && !selected[name])
  24128. && zrUtil.indexOf(this._availableNames, name) >= 0;
  24129. },
  24130. defaultOption: {
  24131. // 一级层叠
  24132. zlevel: 0,
  24133. // 二级层叠
  24134. z: 4,
  24135. show: true,
  24136. // 布局方式,默认为水平布局,可选为:
  24137. // 'horizontal' | 'vertical'
  24138. orient: 'horizontal',
  24139. left: 'center',
  24140. // right: 'center',
  24141. top: 'top',
  24142. // bottom: 'top',
  24143. // 水平对齐
  24144. // 'auto' | 'left' | 'right'
  24145. // 默认为 'auto', 根据 x 的位置判断是左对齐还是右对齐
  24146. align: 'auto',
  24147. backgroundColor: 'rgba(0,0,0,0)',
  24148. // 图例边框颜色
  24149. borderColor: '#ccc',
  24150. // 图例边框线宽,单位px,默认为0(无边框)
  24151. borderWidth: 0,
  24152. // 图例内边距,单位px,默认各方向内边距为5,
  24153. // 接受数组分别设定上右下左边距,同css
  24154. padding: 5,
  24155. // 各个item之间的间隔,单位px,默认为10,
  24156. // 横向布局时为水平间隔,纵向布局时为纵向间隔
  24157. itemGap: 10,
  24158. // 图例图形宽度
  24159. itemWidth: 25,
  24160. // 图例图形高度
  24161. itemHeight: 14,
  24162. textStyle: {
  24163. // 图例文字颜色
  24164. color: '#333'
  24165. },
  24166. // formatter: '',
  24167. // 选择模式,默认开启图例开关
  24168. selectedMode: true
  24169. // 配置默认选中状态,可配合LEGEND.SELECTED事件做动态数据载入
  24170. // selected: null,
  24171. // 图例内容(详见legend.data,数组中每一项代表一个item
  24172. // data: [],
  24173. }
  24174. });
  24175. module.exports = LegendModel;
  24176. /***/ },
  24177. /* 267 */
  24178. /***/ function(module, exports, __webpack_require__) {
  24179. /**
  24180. * @file Legend action
  24181. */
  24182. var echarts = __webpack_require__(1);
  24183. var zrUtil = __webpack_require__(3);
  24184. function legendSelectActionHandler(methodName, payload, ecModel) {
  24185. var selectedMap = {};
  24186. var isToggleSelect = methodName === 'toggleSelected';
  24187. var isSelected;
  24188. // Update all legend components
  24189. ecModel.eachComponent('legend', function (legendModel) {
  24190. if (isToggleSelect && isSelected != null) {
  24191. // Force other legend has same selected status
  24192. // Or the first is toggled to true and other are toggled to false
  24193. // In the case one legend has some item unSelected in option. And if other legend
  24194. // doesn't has the item, they will assume it is selected.
  24195. legendModel[isSelected ? 'select' : 'unSelect'](payload.name);
  24196. }
  24197. else {
  24198. legendModel[methodName](payload.name);
  24199. isSelected = legendModel.isSelected(payload.name);
  24200. }
  24201. var legendData = legendModel.getData();
  24202. zrUtil.each(legendData, function (model) {
  24203. var name = model.get('name');
  24204. // Wrap element
  24205. if (name === '\n' || name === '') {
  24206. return;
  24207. }
  24208. var isItemSelected = legendModel.isSelected(name);
  24209. if (name in selectedMap) {
  24210. // Unselected if any legend is unselected
  24211. selectedMap[name] = selectedMap[name] && isItemSelected;
  24212. }
  24213. else {
  24214. selectedMap[name] = isItemSelected;
  24215. }
  24216. });
  24217. });
  24218. // Return the event explicitly
  24219. return {
  24220. name: payload.name,
  24221. selected: selectedMap
  24222. };
  24223. }
  24224. /**
  24225. * @event legendToggleSelect
  24226. * @type {Object}
  24227. * @property {string} type 'legendToggleSelect'
  24228. * @property {string} [from]
  24229. * @property {string} name Series name or data item name
  24230. */
  24231. echarts.registerAction(
  24232. 'legendToggleSelect', 'legendselectchanged',
  24233. zrUtil.curry(legendSelectActionHandler, 'toggleSelected')
  24234. );
  24235. /**
  24236. * @event legendSelect
  24237. * @type {Object}
  24238. * @property {string} type 'legendSelect'
  24239. * @property {string} name Series name or data item name
  24240. */
  24241. echarts.registerAction(
  24242. 'legendSelect', 'legendselected',
  24243. zrUtil.curry(legendSelectActionHandler, 'select')
  24244. );
  24245. /**
  24246. * @event legendUnSelect
  24247. * @type {Object}
  24248. * @property {string} type 'legendUnSelect'
  24249. * @property {string} name Series name or data item name
  24250. */
  24251. echarts.registerAction(
  24252. 'legendUnSelect', 'legendunselected',
  24253. zrUtil.curry(legendSelectActionHandler, 'unSelect')
  24254. );
  24255. /***/ },
  24256. /* 268 */
  24257. /***/ function(module, exports, __webpack_require__) {
  24258. var zrUtil = __webpack_require__(3);
  24259. var symbolCreator = __webpack_require__(101);
  24260. var graphic = __webpack_require__(42);
  24261. var listComponentHelper = __webpack_require__(269);
  24262. var curry = zrUtil.curry;
  24263. var LEGEND_DISABLE_COLOR = '#ccc';
  24264. function dispatchSelectAction(name, api) {
  24265. api.dispatchAction({
  24266. type: 'legendToggleSelect',
  24267. name: name
  24268. });
  24269. }
  24270. function dispatchHighlightAction(seriesModel, dataName, api) {
  24271. seriesModel.get('legendHoverLink') && api.dispatchAction({
  24272. type: 'highlight',
  24273. seriesName: seriesModel.name,
  24274. name: dataName
  24275. });
  24276. }
  24277. function dispatchDownplayAction(seriesModel, dataName, api) {
  24278. seriesModel.get('legendHoverLink') && api.dispatchAction({
  24279. type: 'downplay',
  24280. seriesName: seriesModel.name,
  24281. name: dataName
  24282. });
  24283. }
  24284. module.exports = __webpack_require__(1).extendComponentView({
  24285. type: 'legend',
  24286. init: function () {
  24287. this._symbolTypeStore = {};
  24288. },
  24289. render: function (legendModel, ecModel, api) {
  24290. var group = this.group;
  24291. group.removeAll();
  24292. if (!legendModel.get('show')) {
  24293. return;
  24294. }
  24295. var selectMode = legendModel.get('selectedMode');
  24296. var itemAlign = legendModel.get('align');
  24297. if (itemAlign === 'auto') {
  24298. itemAlign = (legendModel.get('left') === 'right'
  24299. && legendModel.get('orient') === 'vertical')
  24300. ? 'right' : 'left';
  24301. }
  24302. var legendDrawedMap = {};
  24303. zrUtil.each(legendModel.getData(), function (itemModel) {
  24304. var name = itemModel.get('name');
  24305. // Use empty string or \n as a newline string
  24306. if (name === '' || name === '\n') {
  24307. group.add(new graphic.Group({
  24308. newline: true
  24309. }));
  24310. return;
  24311. }
  24312. var seriesModel = ecModel.getSeriesByName(name)[0];
  24313. if (legendDrawedMap[name]) {
  24314. // Series not exists
  24315. return;
  24316. }
  24317. // Series legend
  24318. if (seriesModel) {
  24319. var data = seriesModel.getData();
  24320. var color = data.getVisual('color');
  24321. // If color is a callback function
  24322. if (typeof color === 'function') {
  24323. // Use the first data
  24324. color = color(seriesModel.getDataParams(0));
  24325. }
  24326. // Using rect symbol defaultly
  24327. var legendSymbolType = data.getVisual('legendSymbol') || 'roundRect';
  24328. var symbolType = data.getVisual('symbol');
  24329. var itemGroup = this._createItem(
  24330. name, itemModel, legendModel,
  24331. legendSymbolType, symbolType,
  24332. itemAlign, color,
  24333. selectMode
  24334. );
  24335. itemGroup.on('click', curry(dispatchSelectAction, name, api))
  24336. .on('mouseover', curry(dispatchHighlightAction, seriesModel, '', api))
  24337. .on('mouseout', curry(dispatchDownplayAction, seriesModel, '', api));
  24338. legendDrawedMap[name] = true;
  24339. }
  24340. else {
  24341. // Data legend of pie, funnel
  24342. ecModel.eachRawSeries(function (seriesModel) {
  24343. // In case multiple series has same data name
  24344. if (legendDrawedMap[name]) {
  24345. return;
  24346. }
  24347. if (seriesModel.legendDataProvider) {
  24348. var data = seriesModel.legendDataProvider();
  24349. var idx = data.indexOfName(name);
  24350. if (idx < 0) {
  24351. return;
  24352. }
  24353. var color = data.getItemVisual(idx, 'color');
  24354. var legendSymbolType = 'roundRect';
  24355. var itemGroup = this._createItem(
  24356. name, itemModel, legendModel,
  24357. legendSymbolType, null,
  24358. itemAlign, color,
  24359. selectMode
  24360. );
  24361. itemGroup.on('click', curry(dispatchSelectAction, name, api))
  24362. // FIXME Should not specify the series name
  24363. .on('mouseover', curry(dispatchHighlightAction, seriesModel, name, api))
  24364. .on('mouseout', curry(dispatchDownplayAction, seriesModel, name, api));
  24365. legendDrawedMap[name] = true;
  24366. }
  24367. }, this);
  24368. }
  24369. }, this);
  24370. listComponentHelper.layout(group, legendModel, api);
  24371. // Render background after group is layout
  24372. // FIXME
  24373. listComponentHelper.addBackground(group, legendModel);
  24374. },
  24375. _createItem: function (
  24376. name, itemModel, legendModel,
  24377. legendSymbolType, symbolType,
  24378. itemAlign, color, selectMode
  24379. ) {
  24380. var itemWidth = legendModel.get('itemWidth');
  24381. var itemHeight = legendModel.get('itemHeight');
  24382. var isSelected = legendModel.isSelected(name);
  24383. var itemGroup = new graphic.Group();
  24384. var textStyleModel = itemModel.getModel('textStyle');
  24385. var itemIcon = itemModel.get('icon');
  24386. // Use user given icon first
  24387. legendSymbolType = itemIcon || legendSymbolType;
  24388. itemGroup.add(symbolCreator.createSymbol(
  24389. legendSymbolType, 0, 0, itemWidth, itemHeight, isSelected ? color : LEGEND_DISABLE_COLOR
  24390. ));
  24391. // Compose symbols
  24392. // PENDING
  24393. if (!itemIcon && symbolType
  24394. // At least show one symbol, can't be all none
  24395. && ((symbolType !== legendSymbolType) || symbolType == 'none')
  24396. ) {
  24397. var size = itemHeight * 0.8;
  24398. if (symbolType === 'none') {
  24399. symbolType = 'circle';
  24400. }
  24401. // Put symbol in the center
  24402. itemGroup.add(symbolCreator.createSymbol(
  24403. symbolType, (itemWidth - size) / 2, (itemHeight - size) / 2, size, size,
  24404. isSelected ? color : LEGEND_DISABLE_COLOR
  24405. ));
  24406. }
  24407. // Text
  24408. var textX = itemAlign === 'left' ? itemWidth + 5 : -5;
  24409. var textAlign = itemAlign;
  24410. var formatter = legendModel.get('formatter');
  24411. if (typeof formatter === 'string' && formatter) {
  24412. name = formatter.replace('{name}', name);
  24413. }
  24414. else if (typeof formatter === 'function') {
  24415. name = formatter(name);
  24416. }
  24417. var text = new graphic.Text({
  24418. style: {
  24419. text: name,
  24420. x: textX,
  24421. y: itemHeight / 2,
  24422. fill: isSelected ? textStyleModel.getTextColor() : LEGEND_DISABLE_COLOR,
  24423. textFont: textStyleModel.getFont(),
  24424. textAlign: textAlign,
  24425. textVerticalAlign: 'middle'
  24426. }
  24427. });
  24428. itemGroup.add(text);
  24429. // Add a invisible rect to increase the area of mouse hover
  24430. itemGroup.add(new graphic.Rect({
  24431. shape: itemGroup.getBoundingRect(),
  24432. invisible: true
  24433. }));
  24434. itemGroup.eachChild(function (child) {
  24435. child.silent = !selectMode;
  24436. });
  24437. this.group.add(itemGroup);
  24438. graphic.setHoverStyle(itemGroup);
  24439. return itemGroup;
  24440. }
  24441. });
  24442. /***/ },
  24443. /* 269 */
  24444. /***/ function(module, exports, __webpack_require__) {
  24445. // List layout
  24446. var layout = __webpack_require__(21);
  24447. var formatUtil = __webpack_require__(6);
  24448. var graphic = __webpack_require__(42);
  24449. function positionGroup(group, model, api) {
  24450. layout.positionGroup(
  24451. group, model.getBoxLayoutParams(),
  24452. {
  24453. width: api.getWidth(),
  24454. height: api.getHeight()
  24455. },
  24456. model.get('padding')
  24457. );
  24458. }
  24459. module.exports = {
  24460. /**
  24461. * Layout list like component.
  24462. * It will box layout each items in group of component and then position the whole group in the viewport
  24463. * @param {module:zrender/group/Group} group
  24464. * @param {module:echarts/model/Component} componentModel
  24465. * @param {module:echarts/ExtensionAPI}
  24466. */
  24467. layout: function (group, componentModel, api) {
  24468. var rect = layout.getLayoutRect(componentModel.getBoxLayoutParams(), {
  24469. width: api.getWidth(),
  24470. height: api.getHeight()
  24471. }, componentModel.get('padding'));
  24472. layout.box(
  24473. componentModel.get('orient'),
  24474. group,
  24475. componentModel.get('itemGap'),
  24476. rect.width,
  24477. rect.height
  24478. );
  24479. positionGroup(group, componentModel, api);
  24480. },
  24481. addBackground: function (group, componentModel) {
  24482. var padding = formatUtil.normalizeCssArray(
  24483. componentModel.get('padding')
  24484. );
  24485. var boundingRect = group.getBoundingRect();
  24486. var style = componentModel.getItemStyle(['color', 'opacity']);
  24487. style.fill = componentModel.get('backgroundColor');
  24488. var rect = new graphic.Rect({
  24489. shape: {
  24490. x: boundingRect.x - padding[3],
  24491. y: boundingRect.y - padding[0],
  24492. width: boundingRect.width + padding[1] + padding[3],
  24493. height: boundingRect.height + padding[0] + padding[2]
  24494. },
  24495. style: style,
  24496. silent: true,
  24497. z2: -1
  24498. });
  24499. graphic.subPixelOptimizeRect(rect);
  24500. group.add(rect);
  24501. }
  24502. };
  24503. /***/ },
  24504. /* 270 */
  24505. /***/ function(module, exports) {
  24506. module.exports = function (ecModel) {
  24507. var legendModels = ecModel.findComponents({
  24508. mainType: 'legend'
  24509. });
  24510. if (legendModels && legendModels.length) {
  24511. ecModel.filterSeries(function (series) {
  24512. // If in any legend component the status is not selected.
  24513. // Because in legend series is assumed selected when it is not in the legend data.
  24514. for (var i = 0; i < legendModels.length; i++) {
  24515. if (!legendModels[i].isSelected(series.name)) {
  24516. return false;
  24517. }
  24518. }
  24519. return true;
  24520. });
  24521. }
  24522. };
  24523. /***/ },
  24524. /* 271 */
  24525. /***/ function(module, exports, __webpack_require__) {
  24526. // FIXME Better way to pack data in graphic element
  24527. __webpack_require__(272);
  24528. __webpack_require__(273);
  24529. // Show tip action
  24530. /**
  24531. * @action
  24532. * @property {string} type
  24533. * @property {number} seriesIndex
  24534. * @property {number} dataIndex
  24535. * @property {number} [x]
  24536. * @property {number} [y]
  24537. */
  24538. __webpack_require__(1).registerAction(
  24539. {
  24540. type: 'showTip',
  24541. event: 'showTip',
  24542. update: 'none'
  24543. },
  24544. // noop
  24545. function () {}
  24546. );
  24547. // Hide tip action
  24548. __webpack_require__(1).registerAction(
  24549. {
  24550. type: 'hideTip',
  24551. event: 'hideTip',
  24552. update: 'none'
  24553. },
  24554. // noop
  24555. function () {}
  24556. );
  24557. /***/ },
  24558. /* 272 */
  24559. /***/ function(module, exports, __webpack_require__) {
  24560. __webpack_require__(1).extendComponentModel({
  24561. type: 'tooltip',
  24562. defaultOption: {
  24563. zlevel: 0,
  24564. z: 8,
  24565. show: true,
  24566. // tooltip主体内容
  24567. showContent: true,
  24568. // 触发类型,默认数据触发,见下图,可选为:'item' ¦ 'axis'
  24569. trigger: 'item',
  24570. // 触发条件,支持 'click' | 'mousemove'
  24571. triggerOn: 'mousemove',
  24572. // 是否永远显示 content
  24573. alwaysShowContent: false,
  24574. // 位置 {Array} | {Function}
  24575. // position: null
  24576. // 内容格式器:{string}(Template) ¦ {Function}
  24577. // formatter: null
  24578. showDelay: 0,
  24579. // 隐藏延迟,单位ms
  24580. hideDelay: 100,
  24581. // 动画变换时间,单位s
  24582. transitionDuration: 0.4,
  24583. enterable: false,
  24584. // 提示背景颜色,默认为透明度为0.7的黑色
  24585. backgroundColor: 'rgba(50,50,50,0.7)',
  24586. // 提示边框颜色
  24587. borderColor: '#333',
  24588. // 提示边框圆角,单位px,默认为4
  24589. borderRadius: 4,
  24590. // 提示边框线宽,单位px,默认为0(无边框)
  24591. borderWidth: 0,
  24592. // 提示内边距,单位px,默认各方向内边距为5,
  24593. // 接受数组分别设定上右下左边距,同css
  24594. padding: 5,
  24595. // Extra css text
  24596. extraCssText: '',
  24597. // 坐标轴指示器,坐标轴触发有效
  24598. axisPointer: {
  24599. // 默认为直线
  24600. // 可选为:'line' | 'shadow' | 'cross'
  24601. type: 'line',
  24602. // type 为 line 的时候有效,指定 tooltip line 所在的轴,可选
  24603. // 可选 'x' | 'y' | 'angle' | 'radius' | 'auto'
  24604. // 默认 'auto',会选择类型为 cateogry 的轴,对于双数值轴,笛卡尔坐标系会默认选择 x 轴
  24605. // 极坐标系会默认选择 angle 轴
  24606. axis: 'auto',
  24607. animation: true,
  24608. animationDurationUpdate: 200,
  24609. animationEasingUpdate: 'exponentialOut',
  24610. // 直线指示器样式设置
  24611. lineStyle: {
  24612. color: '#555',
  24613. width: 1,
  24614. type: 'solid'
  24615. },
  24616. crossStyle: {
  24617. color: '#555',
  24618. width: 1,
  24619. type: 'dashed',
  24620. // TODO formatter
  24621. textStyle: {}
  24622. },
  24623. // 阴影指示器样式设置
  24624. shadowStyle: {
  24625. color: 'rgba(150,150,150,0.3)'
  24626. }
  24627. },
  24628. textStyle: {
  24629. color: '#fff',
  24630. fontSize: 14
  24631. }
  24632. }
  24633. });
  24634. /***/ },
  24635. /* 273 */
  24636. /***/ function(module, exports, __webpack_require__) {
  24637. var TooltipContent = __webpack_require__(274);
  24638. var graphic = __webpack_require__(42);
  24639. var zrUtil = __webpack_require__(3);
  24640. var formatUtil = __webpack_require__(6);
  24641. var numberUtil = __webpack_require__(7);
  24642. var parsePercent = numberUtil.parsePercent;
  24643. var env = __webpack_require__(79);
  24644. function dataEqual(a, b) {
  24645. if (!a || !b) {
  24646. return false;
  24647. }
  24648. var round = numberUtil.round;
  24649. return round(a[0]) === round(b[0])
  24650. && round(a[1]) === round(b[1]);
  24651. }
  24652. /**
  24653. * @inner
  24654. */
  24655. function makeLineShape(x1, y1, x2, y2) {
  24656. return {
  24657. x1: x1,
  24658. y1: y1,
  24659. x2: x2,
  24660. y2: y2
  24661. };
  24662. }
  24663. /**
  24664. * @inner
  24665. */
  24666. function makeRectShape(x, y, width, height) {
  24667. return {
  24668. x: x,
  24669. y: y,
  24670. width: width,
  24671. height: height
  24672. };
  24673. }
  24674. /**
  24675. * @inner
  24676. */
  24677. function makeSectorShape(cx, cy, r0, r, startAngle, endAngle) {
  24678. return {
  24679. cx: cx,
  24680. cy: cy,
  24681. r0: r0,
  24682. r: r,
  24683. startAngle: startAngle,
  24684. endAngle: endAngle,
  24685. clockwise: true
  24686. };
  24687. }
  24688. function refixTooltipPosition(x, y, el, viewWidth, viewHeight) {
  24689. var width = el.clientWidth;
  24690. var height = el.clientHeight;
  24691. var gap = 20;
  24692. if (x + width + gap > viewWidth) {
  24693. x -= width + gap;
  24694. }
  24695. else {
  24696. x += gap;
  24697. }
  24698. if (y + height + gap > viewHeight) {
  24699. y -= height + gap;
  24700. }
  24701. else {
  24702. y += gap;
  24703. }
  24704. return [x, y];
  24705. }
  24706. function calcTooltipPosition(position, rect, dom) {
  24707. var domWidth = dom.clientWidth;
  24708. var domHeight = dom.clientHeight;
  24709. var gap = 5;
  24710. var x = 0;
  24711. var y = 0;
  24712. var rectWidth = rect.width;
  24713. var rectHeight = rect.height;
  24714. switch (position) {
  24715. case 'inside':
  24716. x = rect.x + rectWidth / 2 - domWidth / 2;
  24717. y = rect.y + rectHeight / 2 - domHeight / 2;
  24718. break;
  24719. case 'top':
  24720. x = rect.x + rectWidth / 2 - domWidth / 2;
  24721. y = rect.y - domHeight - gap;
  24722. break;
  24723. case 'bottom':
  24724. x = rect.x + rectWidth / 2 - domWidth / 2;
  24725. y = rect.y + rectHeight + gap;
  24726. break;
  24727. case 'left':
  24728. x = rect.x - domWidth - gap;
  24729. y = rect.y + rectHeight / 2 - domHeight / 2;
  24730. break;
  24731. case 'right':
  24732. x = rect.x + rectWidth + gap;
  24733. y = rect.y + rectHeight / 2 - domHeight / 2;
  24734. }
  24735. return [x, y];
  24736. }
  24737. /**
  24738. * @param {string|Function|Array.<number>} positionExpr
  24739. * @param {number} x Mouse x
  24740. * @param {number} y Mouse y
  24741. * @param {module:echarts/component/tooltip/TooltipContent} content
  24742. * @param {Object|<Array.<Object>} params
  24743. * @param {module:zrender/Element} el target element
  24744. * @param {module:echarts/ExtensionAPI} api
  24745. * @return {Array.<number>}
  24746. */
  24747. function updatePosition(positionExpr, x, y, content, params, el, api) {
  24748. var viewWidth = api.getWidth();
  24749. var viewHeight = api.getHeight();
  24750. var rect = el && el.getBoundingRect().clone();
  24751. el && rect.applyTransform(el.transform);
  24752. if (typeof positionExpr === 'function') {
  24753. // Callback of position can be an array or a string specify the position
  24754. positionExpr = positionExpr([x, y], params, content.el, rect);
  24755. }
  24756. if (zrUtil.isArray(positionExpr)) {
  24757. x = parsePercent(positionExpr[0], viewWidth);
  24758. y = parsePercent(positionExpr[1], viewHeight);
  24759. }
  24760. // Specify tooltip position by string 'top' 'bottom' 'left' 'right' around graphic element
  24761. else if (typeof positionExpr === 'string' && el) {
  24762. var pos = calcTooltipPosition(
  24763. positionExpr, rect, content.el
  24764. );
  24765. x = pos[0];
  24766. y = pos[1];
  24767. }
  24768. else {
  24769. var pos = refixTooltipPosition(
  24770. x, y, content.el, viewWidth, viewHeight
  24771. );
  24772. x = pos[0];
  24773. y = pos[1];
  24774. }
  24775. content.moveTo(x, y);
  24776. }
  24777. function ifSeriesSupportAxisTrigger(seriesModel) {
  24778. var coordSys = seriesModel.coordinateSystem;
  24779. var trigger = seriesModel.get('tooltip.trigger', true);
  24780. // Ignore series use item tooltip trigger and series coordinate system is not cartesian or
  24781. return !(!coordSys
  24782. || (coordSys.type !== 'cartesian2d' && coordSys.type !== 'polar' && coordSys.type !== 'single')
  24783. || trigger === 'item');
  24784. }
  24785. __webpack_require__(1).extendComponentView({
  24786. type: 'tooltip',
  24787. _axisPointers: {},
  24788. init: function (ecModel, api) {
  24789. if (env.node) {
  24790. return;
  24791. }
  24792. var tooltipContent = new TooltipContent(api.getDom(), api);
  24793. this._tooltipContent = tooltipContent;
  24794. api.on('showTip', this._manuallyShowTip, this);
  24795. api.on('hideTip', this._manuallyHideTip, this);
  24796. },
  24797. render: function (tooltipModel, ecModel, api) {
  24798. if (env.node) {
  24799. return;
  24800. }
  24801. // Reset
  24802. this.group.removeAll();
  24803. /**
  24804. * @type {Object}
  24805. * @private
  24806. */
  24807. this._axisPointers = {};
  24808. /**
  24809. * @private
  24810. * @type {module:echarts/component/tooltip/TooltipModel}
  24811. */
  24812. this._tooltipModel = tooltipModel;
  24813. /**
  24814. * @private
  24815. * @type {module:echarts/model/Global}
  24816. */
  24817. this._ecModel = ecModel;
  24818. /**
  24819. * @private
  24820. * @type {module:echarts/ExtensionAPI}
  24821. */
  24822. this._api = api;
  24823. /**
  24824. * @type {Object}
  24825. * @private
  24826. */
  24827. this._lastHover = {
  24828. // data
  24829. // payloadBatch
  24830. };
  24831. var tooltipContent = this._tooltipContent;
  24832. tooltipContent.update();
  24833. tooltipContent.enterable = tooltipModel.get('enterable');
  24834. this._alwaysShowContent = tooltipModel.get('alwaysShowContent');
  24835. /**
  24836. * @type {Object.<string, Array>}
  24837. */
  24838. this._seriesGroupByAxis = this._prepareAxisTriggerData(
  24839. tooltipModel, ecModel
  24840. );
  24841. var crossText = this._crossText;
  24842. if (crossText) {
  24843. this.group.add(crossText);
  24844. }
  24845. // Try to keep the tooltip show when refreshing
  24846. if (this._lastX != null && this._lastY != null) {
  24847. var self = this;
  24848. clearTimeout(this._refreshUpdateTimeout);
  24849. this._refreshUpdateTimeout = setTimeout(function () {
  24850. // Show tip next tick after other charts are rendered
  24851. // In case highlight action has wrong result
  24852. // FIXME
  24853. self._manuallyShowTip({
  24854. x: self._lastX,
  24855. y: self._lastY
  24856. });
  24857. });
  24858. }
  24859. var zr = this._api.getZr();
  24860. zr.off('click', this._tryShow);
  24861. zr.off('mousemove', this._mousemove);
  24862. zr.off('mouseout', this._hide);
  24863. zr.off('globalout', this._hide);
  24864. if (tooltipModel.get('triggerOn') === 'click') {
  24865. zr.on('click', this._tryShow, this);
  24866. }
  24867. else {
  24868. zr.on('mousemove', this._mousemove, this);
  24869. zr.on('mouseout', this._hide, this);
  24870. zr.on('globalout', this._hide, this);
  24871. }
  24872. },
  24873. _mousemove: function (e) {
  24874. var showDelay = this._tooltipModel.get('showDelay');
  24875. var self = this;
  24876. clearTimeout(this._showTimeout);
  24877. if (showDelay > 0) {
  24878. this._showTimeout = setTimeout(function () {
  24879. self._tryShow(e);
  24880. }, showDelay);
  24881. }
  24882. else {
  24883. this._tryShow(e);
  24884. }
  24885. },
  24886. /**
  24887. * Show tip manually by
  24888. * dispatchAction({
  24889. * type: 'showTip',
  24890. * x: 10,
  24891. * y: 10
  24892. * });
  24893. * Or
  24894. * dispatchAction({
  24895. * type: 'showTip',
  24896. * seriesIndex: 0,
  24897. * dataIndex: 1
  24898. * });
  24899. *
  24900. * TODO Batch
  24901. */
  24902. _manuallyShowTip: function (event) {
  24903. // From self
  24904. if (event.from === this.uid) {
  24905. return;
  24906. }
  24907. var ecModel = this._ecModel;
  24908. var seriesIndex = event.seriesIndex;
  24909. var dataIndex = event.dataIndex;
  24910. var seriesModel = ecModel.getSeriesByIndex(seriesIndex);
  24911. var api = this._api;
  24912. if (event.x == null || event.y == null) {
  24913. if (!seriesModel) {
  24914. // Find the first series can use axis trigger
  24915. ecModel.eachSeries(function (_series) {
  24916. if (ifSeriesSupportAxisTrigger(_series) && !seriesModel) {
  24917. seriesModel = _series;
  24918. }
  24919. });
  24920. }
  24921. if (seriesModel) {
  24922. var data = seriesModel.getData();
  24923. if (dataIndex == null) {
  24924. dataIndex = data.indexOfName(event.name);
  24925. }
  24926. var el = data.getItemGraphicEl(dataIndex);
  24927. var cx, cy;
  24928. // Try to get the point in coordinate system
  24929. var coordSys = seriesModel.coordinateSystem;
  24930. if (coordSys && coordSys.dataToPoint) {
  24931. var point = coordSys.dataToPoint(
  24932. data.getValues(
  24933. zrUtil.map(coordSys.dimensions, function (dim) {
  24934. return seriesModel.coordDimToDataDim(dim)[0];
  24935. }), dataIndex, true
  24936. )
  24937. );
  24938. cx = point && point[0];
  24939. cy = point && point[1];
  24940. }
  24941. else if (el) {
  24942. // Use graphic bounding rect
  24943. var rect = el.getBoundingRect().clone();
  24944. rect.applyTransform(el.transform);
  24945. cx = rect.x + rect.width / 2;
  24946. cy = rect.y + rect.height / 2;
  24947. }
  24948. if (cx != null && cy != null) {
  24949. this._tryShow({
  24950. offsetX: cx,
  24951. offsetY: cy,
  24952. target: el,
  24953. event: {}
  24954. });
  24955. }
  24956. }
  24957. }
  24958. else {
  24959. var el = api.getZr().handler.findHover(event.x, event.y);
  24960. this._tryShow({
  24961. offsetX: event.x,
  24962. offsetY: event.y,
  24963. target: el,
  24964. event: {}
  24965. });
  24966. }
  24967. },
  24968. _manuallyHideTip: function (e) {
  24969. if (e.from === this.uid) {
  24970. return;
  24971. }
  24972. this._hide();
  24973. },
  24974. _prepareAxisTriggerData: function (tooltipModel, ecModel) {
  24975. // Prepare data for axis trigger
  24976. var seriesGroupByAxis = {};
  24977. ecModel.eachSeries(function (seriesModel) {
  24978. if (ifSeriesSupportAxisTrigger(seriesModel)) {
  24979. var coordSys = seriesModel.coordinateSystem;
  24980. var baseAxis;
  24981. var key;
  24982. // Only cartesian2d, polar and single support axis trigger
  24983. if (coordSys.type === 'cartesian2d') {
  24984. // FIXME `axisPointer.axis` is not baseAxis
  24985. baseAxis = coordSys.getBaseAxis();
  24986. key = baseAxis.dim + baseAxis.index;
  24987. }
  24988. else if (coordSys.type === 'single') {
  24989. baseAxis = coordSys.getAxis();
  24990. key = baseAxis.dim + baseAxis.type;
  24991. }
  24992. else {
  24993. baseAxis = coordSys.getBaseAxis();
  24994. key = baseAxis.dim + coordSys.name;
  24995. }
  24996. seriesGroupByAxis[key] = seriesGroupByAxis[key] || {
  24997. coordSys: [],
  24998. series: []
  24999. };
  25000. seriesGroupByAxis[key].coordSys.push(coordSys);
  25001. seriesGroupByAxis[key].series.push(seriesModel);
  25002. }
  25003. }, this);
  25004. return seriesGroupByAxis;
  25005. },
  25006. /**
  25007. * mousemove handler
  25008. * @param {Object} e
  25009. * @private
  25010. */
  25011. _tryShow: function (e) {
  25012. var el = e.target;
  25013. var tooltipModel = this._tooltipModel;
  25014. var globalTrigger = tooltipModel.get('trigger');
  25015. var ecModel = this._ecModel;
  25016. var api = this._api;
  25017. if (!tooltipModel) {
  25018. return;
  25019. }
  25020. // Save mouse x, mouse y. So we can try to keep showing the tip if chart is refreshed
  25021. this._lastX = e.offsetX;
  25022. this._lastY = e.offsetY;
  25023. // Always show item tooltip if mouse is on the element with dataIndex
  25024. if (el && el.dataIndex != null) {
  25025. // Use dataModel in element if possible
  25026. // Used when mouseover on a element like markPoint or edge
  25027. // In which case, the data is not main data in series.
  25028. var dataModel = el.dataModel || ecModel.getSeriesByIndex(el.seriesIndex);
  25029. var dataIndex = el.dataIndex;
  25030. var itemModel = dataModel.getData().getItemModel(dataIndex);
  25031. // Series or single data may use item trigger when global is axis trigger
  25032. if ((itemModel.get('tooltip.trigger') || globalTrigger) === 'axis') {
  25033. this._showAxisTooltip(tooltipModel, ecModel, e);
  25034. }
  25035. else {
  25036. // Reset ticket
  25037. this._ticket = '';
  25038. // If either single data or series use item trigger
  25039. this._hideAxisPointer();
  25040. // Reset last hover and dispatch downplay action
  25041. this._resetLastHover();
  25042. this._showItemTooltipContent(dataModel, dataIndex, el.dataType, e);
  25043. }
  25044. api.dispatchAction({
  25045. type: 'showTip',
  25046. from: this.uid,
  25047. dataIndex: el.dataIndex,
  25048. seriesIndex: el.seriesIndex
  25049. });
  25050. }
  25051. else {
  25052. if (globalTrigger === 'item') {
  25053. this._hide();
  25054. }
  25055. else {
  25056. // Try show axis tooltip
  25057. this._showAxisTooltip(tooltipModel, ecModel, e);
  25058. }
  25059. // Action of cross pointer
  25060. // other pointer types will trigger action in _dispatchAndShowSeriesTooltipContent method
  25061. if (tooltipModel.get('axisPointer.type') === 'cross') {
  25062. api.dispatchAction({
  25063. type: 'showTip',
  25064. from: this.uid,
  25065. x: e.offsetX,
  25066. y: e.offsetY
  25067. });
  25068. }
  25069. }
  25070. },
  25071. /**
  25072. * Show tooltip on axis
  25073. * @param {module:echarts/component/tooltip/TooltipModel} tooltipModel
  25074. * @param {module:echarts/model/Global} ecModel
  25075. * @param {Object} e
  25076. * @private
  25077. */
  25078. _showAxisTooltip: function (tooltipModel, ecModel, e) {
  25079. var axisPointerModel = tooltipModel.getModel('axisPointer');
  25080. var axisPointerType = axisPointerModel.get('type');
  25081. if (axisPointerType === 'cross') {
  25082. var el = e.target;
  25083. if (el && el.dataIndex != null) {
  25084. var seriesModel = ecModel.getSeriesByIndex(el.seriesIndex);
  25085. var dataIndex = el.dataIndex;
  25086. this._showItemTooltipContent(seriesModel, dataIndex, el.dataType, e);
  25087. }
  25088. }
  25089. this._showAxisPointer();
  25090. var allNotShow = true;
  25091. zrUtil.each(this._seriesGroupByAxis, function (seriesCoordSysSameAxis) {
  25092. // Try show the axis pointer
  25093. var allCoordSys = seriesCoordSysSameAxis.coordSys;
  25094. var coordSys = allCoordSys[0];
  25095. // If mouse position is not in the grid or polar
  25096. var point = [e.offsetX, e.offsetY];
  25097. if (!coordSys.containPoint(point)) {
  25098. // Hide axis pointer
  25099. this._hideAxisPointer(coordSys.name);
  25100. return;
  25101. }
  25102. allNotShow = false;
  25103. // Make sure point is discrete on cateogry axis
  25104. var dimensions = coordSys.dimensions;
  25105. var value = coordSys.pointToData(point, true);
  25106. point = coordSys.dataToPoint(value);
  25107. var baseAxis = coordSys.getBaseAxis();
  25108. var axisType = axisPointerModel.get('axis');
  25109. if (axisType === 'auto') {
  25110. axisType = baseAxis.dim;
  25111. }
  25112. var contentNotChange = false;
  25113. var lastHover = this._lastHover;
  25114. if (axisPointerType === 'cross') {
  25115. // If hover data not changed
  25116. // Possible when two axes are all category
  25117. if (dataEqual(lastHover.data, value)) {
  25118. contentNotChange = true;
  25119. }
  25120. lastHover.data = value;
  25121. }
  25122. else {
  25123. var valIndex = zrUtil.indexOf(dimensions, axisType);
  25124. // If hover data not changed on the axis dimension
  25125. if (lastHover.data === value[valIndex]) {
  25126. contentNotChange = true;
  25127. }
  25128. lastHover.data = value[valIndex];
  25129. }
  25130. if (coordSys.type === 'cartesian2d' && !contentNotChange) {
  25131. this._showCartesianPointer(
  25132. axisPointerModel, coordSys, axisType, point
  25133. );
  25134. }
  25135. else if (coordSys.type === 'polar' && !contentNotChange) {
  25136. this._showPolarPointer(
  25137. axisPointerModel, coordSys, axisType, point
  25138. );
  25139. }
  25140. else if (coordSys.type === 'single' && !contentNotChange) {
  25141. this._showSinglePointer(
  25142. axisPointerModel, coordSys, axisType, point
  25143. );
  25144. }
  25145. if (axisPointerType !== 'cross') {
  25146. this._dispatchAndShowSeriesTooltipContent(
  25147. coordSys, seriesCoordSysSameAxis.series, point, value, contentNotChange
  25148. );
  25149. }
  25150. }, this);
  25151. if (!this._tooltipModel.get('show')) {
  25152. this._hideAxisPointer();
  25153. }
  25154. if (allNotShow) {
  25155. this._hide();
  25156. }
  25157. },
  25158. /**
  25159. * Show tooltip on axis of cartesian coordinate
  25160. * @param {module:echarts/model/Model} axisPointerModel
  25161. * @param {module:echarts/coord/cartesian/Cartesian2D} cartesians
  25162. * @param {string} axisType
  25163. * @param {Array.<number>} point
  25164. * @private
  25165. */
  25166. _showCartesianPointer: function (axisPointerModel, cartesian, axisType, point) {
  25167. var self = this;
  25168. var axisPointerType = axisPointerModel.get('type');
  25169. var moveAnimation = axisPointerType !== 'cross';
  25170. if (axisPointerType === 'cross') {
  25171. moveGridLine('x', point, cartesian.getAxis('y').getGlobalExtent());
  25172. moveGridLine('y', point, cartesian.getAxis('x').getGlobalExtent());
  25173. this._updateCrossText(cartesian, point, axisPointerModel);
  25174. }
  25175. else {
  25176. var otherAxis = cartesian.getAxis(axisType === 'x' ? 'y' : 'x');
  25177. var otherExtent = otherAxis.getGlobalExtent();
  25178. if (cartesian.type === 'cartesian2d') {
  25179. (axisPointerType === 'line' ? moveGridLine : moveGridShadow)(
  25180. axisType, point, otherExtent
  25181. );
  25182. }
  25183. }
  25184. /**
  25185. * @inner
  25186. */
  25187. function moveGridLine(axisType, point, otherExtent) {
  25188. var targetShape = axisType === 'x'
  25189. ? makeLineShape(point[0], otherExtent[0], point[0], otherExtent[1])
  25190. : makeLineShape(otherExtent[0], point[1], otherExtent[1], point[1]);
  25191. var pointerEl = self._getPointerElement(
  25192. cartesian, axisPointerModel, axisType, targetShape
  25193. );
  25194. moveAnimation
  25195. ? graphic.updateProps(pointerEl, {
  25196. shape: targetShape
  25197. }, axisPointerModel)
  25198. : pointerEl.attr({
  25199. shape: targetShape
  25200. });
  25201. }
  25202. /**
  25203. * @inner
  25204. */
  25205. function moveGridShadow(axisType, point, otherExtent) {
  25206. var axis = cartesian.getAxis(axisType);
  25207. var bandWidth = axis.getBandWidth();
  25208. var span = otherExtent[1] - otherExtent[0];
  25209. var targetShape = axisType === 'x'
  25210. ? makeRectShape(point[0] - bandWidth / 2, otherExtent[0], bandWidth, span)
  25211. : makeRectShape(otherExtent[0], point[1] - bandWidth / 2, span, bandWidth);
  25212. var pointerEl = self._getPointerElement(
  25213. cartesian, axisPointerModel, axisType, targetShape
  25214. );
  25215. moveAnimation
  25216. ? graphic.updateProps(pointerEl, {
  25217. shape: targetShape
  25218. }, axisPointerModel)
  25219. : pointerEl.attr({
  25220. shape: targetShape
  25221. });
  25222. }
  25223. },
  25224. _showSinglePointer: function (axisPointerModel, single, axisType, point) {
  25225. var self = this;
  25226. var axisPointerType = axisPointerModel.get('type');
  25227. var moveAnimation = axisPointerType !== 'cross';
  25228. var rect = single.getRect();
  25229. var otherExtent = [rect.y, rect.y + rect.height];
  25230. moveSingleLine(axisType, point, otherExtent);
  25231. /**
  25232. * @inner
  25233. */
  25234. function moveSingleLine(axisType, point, otherExtent) {
  25235. var axis = single.getAxis();
  25236. var orient = axis.orient;
  25237. var targetShape = orient === 'horizontal'
  25238. ? makeLineShape(point[0], otherExtent[0], point[0], otherExtent[1])
  25239. : makeLineShape(otherExtent[0], point[1], otherExtent[1], point[1]);
  25240. var pointerEl = self._getPointerElement(
  25241. single, axisPointerModel, axisType, targetShape
  25242. );
  25243. moveAnimation
  25244. ? graphic.updateProps(pointerEl, {
  25245. shape: targetShape
  25246. }, axisPointerModel)
  25247. : pointerEl.attr({
  25248. shape: targetShape
  25249. });
  25250. }
  25251. },
  25252. /**
  25253. * Show tooltip on axis of polar coordinate
  25254. * @param {module:echarts/model/Model} axisPointerModel
  25255. * @param {Array.<module:echarts/coord/polar/Polar>} polar
  25256. * @param {string} axisType
  25257. * @param {Array.<number>} point
  25258. */
  25259. _showPolarPointer: function (axisPointerModel, polar, axisType, point) {
  25260. var self = this;
  25261. var axisPointerType = axisPointerModel.get('type');
  25262. var angleAxis = polar.getAngleAxis();
  25263. var radiusAxis = polar.getRadiusAxis();
  25264. var moveAnimation = axisPointerType !== 'cross';
  25265. if (axisPointerType === 'cross') {
  25266. movePolarLine('angle', point, radiusAxis.getExtent());
  25267. movePolarLine('radius', point, angleAxis.getExtent());
  25268. this._updateCrossText(polar, point, axisPointerModel);
  25269. }
  25270. else {
  25271. var otherAxis = polar.getAxis(axisType === 'radius' ? 'angle' : 'radius');
  25272. var otherExtent = otherAxis.getExtent();
  25273. (axisPointerType === 'line' ? movePolarLine : movePolarShadow)(
  25274. axisType, point, otherExtent
  25275. );
  25276. }
  25277. /**
  25278. * @inner
  25279. */
  25280. function movePolarLine(axisType, point, otherExtent) {
  25281. var mouseCoord = polar.pointToCoord(point);
  25282. var targetShape;
  25283. if (axisType === 'angle') {
  25284. var p1 = polar.coordToPoint([otherExtent[0], mouseCoord[1]]);
  25285. var p2 = polar.coordToPoint([otherExtent[1], mouseCoord[1]]);
  25286. targetShape = makeLineShape(p1[0], p1[1], p2[0], p2[1]);
  25287. }
  25288. else {
  25289. targetShape = {
  25290. cx: polar.cx,
  25291. cy: polar.cy,
  25292. r: mouseCoord[0]
  25293. };
  25294. }
  25295. var pointerEl = self._getPointerElement(
  25296. polar, axisPointerModel, axisType, targetShape
  25297. );
  25298. moveAnimation
  25299. ? graphic.updateProps(pointerEl, {
  25300. shape: targetShape
  25301. }, axisPointerModel)
  25302. : pointerEl.attr({
  25303. shape: targetShape
  25304. });
  25305. }
  25306. /**
  25307. * @inner
  25308. */
  25309. function movePolarShadow(axisType, point, otherExtent) {
  25310. var axis = polar.getAxis(axisType);
  25311. var bandWidth = axis.getBandWidth();
  25312. var mouseCoord = polar.pointToCoord(point);
  25313. var targetShape;
  25314. var radian = Math.PI / 180;
  25315. if (axisType === 'angle') {
  25316. targetShape = makeSectorShape(
  25317. polar.cx, polar.cy,
  25318. otherExtent[0], otherExtent[1],
  25319. // In ECharts y is negative if angle is positive
  25320. (-mouseCoord[1] - bandWidth / 2) * radian,
  25321. (-mouseCoord[1] + bandWidth / 2) * radian
  25322. );
  25323. }
  25324. else {
  25325. targetShape = makeSectorShape(
  25326. polar.cx, polar.cy,
  25327. mouseCoord[0] - bandWidth / 2,
  25328. mouseCoord[0] + bandWidth / 2,
  25329. 0, Math.PI * 2
  25330. );
  25331. }
  25332. var pointerEl = self._getPointerElement(
  25333. polar, axisPointerModel, axisType, targetShape
  25334. );
  25335. moveAnimation
  25336. ? graphic.updateProps(pointerEl, {
  25337. shape: targetShape
  25338. }, axisPointerModel)
  25339. : pointerEl.attr({
  25340. shape: targetShape
  25341. });
  25342. }
  25343. },
  25344. _updateCrossText: function (coordSys, point, axisPointerModel) {
  25345. var crossStyleModel = axisPointerModel.getModel('crossStyle');
  25346. var textStyleModel = crossStyleModel.getModel('textStyle');
  25347. var tooltipModel = this._tooltipModel;
  25348. var text = this._crossText;
  25349. if (!text) {
  25350. text = this._crossText = new graphic.Text({
  25351. style: {
  25352. textAlign: 'left',
  25353. textVerticalAlign: 'bottom'
  25354. }
  25355. });
  25356. this.group.add(text);
  25357. }
  25358. var value = coordSys.pointToData(point);
  25359. var dims = coordSys.dimensions;
  25360. value = zrUtil.map(value, function (val, idx) {
  25361. var axis = coordSys.getAxis(dims[idx]);
  25362. if (axis.type === 'category' || axis.type === 'time') {
  25363. val = axis.scale.getLabel(val);
  25364. }
  25365. else {
  25366. val = formatUtil.addCommas(
  25367. val.toFixed(axis.getPixelPrecision())
  25368. );
  25369. }
  25370. return val;
  25371. });
  25372. text.setStyle({
  25373. fill: textStyleModel.getTextColor() || crossStyleModel.get('color'),
  25374. textFont: textStyleModel.getFont(),
  25375. text: value.join(', '),
  25376. x: point[0] + 5,
  25377. y: point[1] - 5
  25378. });
  25379. text.z = tooltipModel.get('z');
  25380. text.zlevel = tooltipModel.get('zlevel');
  25381. },
  25382. _getPointerElement: function (coordSys, pointerModel, axisType, initShape) {
  25383. var tooltipModel = this._tooltipModel;
  25384. var z = tooltipModel.get('z');
  25385. var zlevel = tooltipModel.get('zlevel');
  25386. var axisPointers = this._axisPointers;
  25387. var coordSysName = coordSys.name;
  25388. axisPointers[coordSysName] = axisPointers[coordSysName] || {};
  25389. if (axisPointers[coordSysName][axisType]) {
  25390. return axisPointers[coordSysName][axisType];
  25391. }
  25392. // Create if not exists
  25393. var pointerType = pointerModel.get('type');
  25394. var styleModel = pointerModel.getModel(pointerType + 'Style');
  25395. var isShadow = pointerType === 'shadow';
  25396. var style = styleModel[isShadow ? 'getAreaStyle' : 'getLineStyle']();
  25397. var elementType = coordSys.type === 'polar'
  25398. ? (isShadow ? 'Sector' : (axisType === 'radius' ? 'Circle' : 'Line'))
  25399. : (isShadow ? 'Rect' : 'Line');
  25400. isShadow ? (style.stroke = null) : (style.fill = null);
  25401. var el = axisPointers[coordSysName][axisType] = new graphic[elementType]({
  25402. style: style,
  25403. z: z,
  25404. zlevel: zlevel,
  25405. silent: true,
  25406. shape: initShape
  25407. });
  25408. this.group.add(el);
  25409. return el;
  25410. },
  25411. /**
  25412. * Dispatch actions and show tooltip on series
  25413. * @param {Array.<module:echarts/model/Series>} seriesList
  25414. * @param {Array.<number>} point
  25415. * @param {Array.<number>} value
  25416. * @param {boolean} contentNotChange
  25417. * @param {Object} e
  25418. */
  25419. _dispatchAndShowSeriesTooltipContent: function (
  25420. coordSys, seriesList, point, value, contentNotChange
  25421. ) {
  25422. var rootTooltipModel = this._tooltipModel;
  25423. var tooltipContent = this._tooltipContent;
  25424. var baseAxis = coordSys.getBaseAxis();
  25425. var payloadBatch = zrUtil.map(seriesList, function (series) {
  25426. return {
  25427. seriesIndex: series.seriesIndex,
  25428. dataIndex: series.getAxisTooltipDataIndex
  25429. ? series.getAxisTooltipDataIndex(series.coordDimToDataDim(baseAxis.dim), value, baseAxis)
  25430. : series.getData().indexOfNearest(
  25431. series.coordDimToDataDim(baseAxis.dim)[0],
  25432. value[baseAxis.dim === 'x' || baseAxis.dim === 'radius' ? 0 : 1]
  25433. )
  25434. };
  25435. });
  25436. var lastHover = this._lastHover;
  25437. var api = this._api;
  25438. // Dispatch downplay action
  25439. if (lastHover.payloadBatch && !contentNotChange) {
  25440. api.dispatchAction({
  25441. type: 'downplay',
  25442. batch: lastHover.payloadBatch
  25443. });
  25444. }
  25445. // Dispatch highlight action
  25446. if (!contentNotChange) {
  25447. api.dispatchAction({
  25448. type: 'highlight',
  25449. batch: payloadBatch
  25450. });
  25451. lastHover.payloadBatch = payloadBatch;
  25452. }
  25453. // Dispatch showTip action
  25454. api.dispatchAction({
  25455. type: 'showTip',
  25456. dataIndex: payloadBatch[0].dataIndex,
  25457. seriesIndex: payloadBatch[0].seriesIndex,
  25458. from: this.uid
  25459. });
  25460. if (baseAxis && rootTooltipModel.get('showContent') && rootTooltipModel.get('show')) {
  25461. var formatter = rootTooltipModel.get('formatter');
  25462. var positionExpr = rootTooltipModel.get('position');
  25463. var html;
  25464. var paramsList = zrUtil.map(seriesList, function (series, index) {
  25465. return series.getDataParams(payloadBatch[index].dataIndex);
  25466. });
  25467. // If only one series
  25468. // FIXME
  25469. // if (paramsList.length === 1) {
  25470. // paramsList = paramsList[0];
  25471. // }
  25472. tooltipContent.show(rootTooltipModel);
  25473. // Update html content
  25474. var firstDataIndex = payloadBatch[0].dataIndex;
  25475. if (!contentNotChange) {
  25476. // Reset ticket
  25477. this._ticket = '';
  25478. if (!formatter) {
  25479. // Default tooltip content
  25480. // FIXME
  25481. // (1) shold be the first data which has name?
  25482. // (2) themeRiver, firstDataIndex is array, and first line is unnecessary.
  25483. var firstLine = seriesList[0].getData().getName(firstDataIndex);
  25484. html = (firstLine ? firstLine + '<br />' : '')
  25485. + zrUtil.map(seriesList, function (series, index) {
  25486. return series.formatTooltip(payloadBatch[index].dataIndex, true);
  25487. }).join('<br />');
  25488. }
  25489. else {
  25490. if (typeof formatter === 'string') {
  25491. html = formatUtil.formatTpl(formatter, paramsList);
  25492. }
  25493. else if (typeof formatter === 'function') {
  25494. var self = this;
  25495. var ticket = 'axis_' + coordSys.name + '_' + firstDataIndex;
  25496. var callback = function (cbTicket, html) {
  25497. if (cbTicket === self._ticket) {
  25498. tooltipContent.setContent(html);
  25499. updatePosition(
  25500. positionExpr, point[0], point[1],
  25501. tooltipContent, paramsList, null, api
  25502. );
  25503. }
  25504. };
  25505. self._ticket = ticket;
  25506. html = formatter(paramsList, ticket, callback);
  25507. }
  25508. }
  25509. tooltipContent.setContent(html);
  25510. }
  25511. updatePosition(
  25512. positionExpr, point[0], point[1],
  25513. tooltipContent, paramsList, null, api
  25514. );
  25515. }
  25516. },
  25517. /**
  25518. * Show tooltip on item
  25519. * @param {module:echarts/model/Series} seriesModel
  25520. * @param {number} dataIndex
  25521. * @param {string} dataType
  25522. * @param {Object} e
  25523. */
  25524. _showItemTooltipContent: function (seriesModel, dataIndex, dataType, e) {
  25525. // FIXME Graph data
  25526. var api = this._api;
  25527. var data = seriesModel.getData(dataType);
  25528. var itemModel = data.getItemModel(dataIndex);
  25529. var rootTooltipModel = this._tooltipModel;
  25530. var tooltipContent = this._tooltipContent;
  25531. var tooltipModel = itemModel.getModel('tooltip');
  25532. // If series model
  25533. if (tooltipModel.parentModel) {
  25534. tooltipModel.parentModel.parentModel = rootTooltipModel;
  25535. }
  25536. else {
  25537. tooltipModel.parentModel = this._tooltipModel;
  25538. }
  25539. if (tooltipModel.get('showContent') && tooltipModel.get('show')) {
  25540. var formatter = tooltipModel.get('formatter');
  25541. var positionExpr = tooltipModel.get('position');
  25542. var params = seriesModel.getDataParams(dataIndex, dataType);
  25543. var html;
  25544. if (!formatter) {
  25545. html = seriesModel.formatTooltip(dataIndex, false, dataType);
  25546. }
  25547. else {
  25548. if (typeof formatter === 'string') {
  25549. html = formatUtil.formatTpl(formatter, params);
  25550. }
  25551. else if (typeof formatter === 'function') {
  25552. var self = this;
  25553. var ticket = 'item_' + seriesModel.name + '_' + dataIndex;
  25554. var callback = function (cbTicket, html) {
  25555. if (cbTicket === self._ticket) {
  25556. tooltipContent.setContent(html);
  25557. updatePosition(
  25558. positionExpr, e.offsetX, e.offsetY,
  25559. tooltipContent, params, e.target, api
  25560. );
  25561. }
  25562. };
  25563. self._ticket = ticket;
  25564. html = formatter(params, ticket, callback);
  25565. }
  25566. }
  25567. tooltipContent.show(tooltipModel);
  25568. tooltipContent.setContent(html);
  25569. updatePosition(
  25570. positionExpr, e.offsetX, e.offsetY,
  25571. tooltipContent, params, e.target, api
  25572. );
  25573. }
  25574. },
  25575. /**
  25576. * Show axis pointer
  25577. * @param {string} [coordSysName]
  25578. */
  25579. _showAxisPointer: function (coordSysName) {
  25580. if (coordSysName) {
  25581. var axisPointers = this._axisPointers[coordSysName];
  25582. axisPointers && zrUtil.each(axisPointers, function (el) {
  25583. el.show();
  25584. });
  25585. }
  25586. else {
  25587. this.group.eachChild(function (child) {
  25588. child.show();
  25589. });
  25590. this.group.show();
  25591. }
  25592. },
  25593. _resetLastHover: function () {
  25594. var lastHover = this._lastHover;
  25595. if (lastHover.payloadBatch) {
  25596. this._api.dispatchAction({
  25597. type: 'downplay',
  25598. batch: lastHover.payloadBatch
  25599. });
  25600. }
  25601. // Reset lastHover
  25602. this._lastHover = {};
  25603. },
  25604. /**
  25605. * Hide axis pointer
  25606. * @param {string} [coordSysName]
  25607. */
  25608. _hideAxisPointer: function (coordSysName) {
  25609. if (coordSysName) {
  25610. var axisPointers = this._axisPointers[coordSysName];
  25611. axisPointers && zrUtil.each(axisPointers, function (el) {
  25612. el.hide();
  25613. });
  25614. }
  25615. else {
  25616. this.group.hide();
  25617. }
  25618. },
  25619. _hide: function () {
  25620. clearTimeout(this._showTimeout);
  25621. this._hideAxisPointer();
  25622. this._resetLastHover();
  25623. if (!this._alwaysShowContent) {
  25624. this._tooltipContent.hideLater(this._tooltipModel.get('hideDelay'));
  25625. }
  25626. this._api.dispatchAction({
  25627. type: 'hideTip',
  25628. from: this.uid
  25629. });
  25630. this._lastX = this._lastY = null;
  25631. },
  25632. dispose: function (ecModel, api) {
  25633. if (env.node) {
  25634. return;
  25635. }
  25636. var zr = api.getZr();
  25637. this._tooltipContent.hide();
  25638. zr.off('click', this._tryShow);
  25639. zr.off('mousemove', this._mousemove);
  25640. zr.off('mouseout', this._hide);
  25641. zr.off('globalout', this._hide);
  25642. api.off('showTip', this._manuallyShowTip);
  25643. api.off('hideTip', this._manuallyHideTip);
  25644. }
  25645. });
  25646. /***/ },
  25647. /* 274 */
  25648. /***/ function(module, exports, __webpack_require__) {
  25649. /**
  25650. * @module echarts/component/tooltip/TooltipContent
  25651. */
  25652. var zrUtil = __webpack_require__(3);
  25653. var zrColor = __webpack_require__(38);
  25654. var eventUtil = __webpack_require__(81);
  25655. var formatUtil = __webpack_require__(6);
  25656. var each = zrUtil.each;
  25657. var toCamelCase = formatUtil.toCamelCase;
  25658. var env = __webpack_require__(79);
  25659. var vendors = ['', '-webkit-', '-moz-', '-o-'];
  25660. var gCssText = 'position:absolute;display:block;border-style:solid;white-space:nowrap;z-index:9999999;';
  25661. /**
  25662. * @param {number} duration
  25663. * @return {string}
  25664. * @inner
  25665. */
  25666. function assembleTransition(duration) {
  25667. var transitionCurve = 'cubic-bezier(0.23, 1, 0.32, 1)';
  25668. var transitionText = 'left ' + duration + 's ' + transitionCurve + ','
  25669. + 'top ' + duration + 's ' + transitionCurve;
  25670. return zrUtil.map(vendors, function (vendorPrefix) {
  25671. return vendorPrefix + 'transition:' + transitionText;
  25672. }).join(';');
  25673. }
  25674. /**
  25675. * @param {Object} textStyle
  25676. * @return {string}
  25677. * @inner
  25678. */
  25679. function assembleFont(textStyleModel) {
  25680. var cssText = [];
  25681. var fontSize = textStyleModel.get('fontSize');
  25682. var color = textStyleModel.getTextColor();
  25683. color && cssText.push('color:' + color);
  25684. cssText.push('font:' + textStyleModel.getFont());
  25685. fontSize &&
  25686. cssText.push('line-height:' + Math.round(fontSize * 3 / 2) + 'px');
  25687. each(['decoration', 'align'], function (name) {
  25688. var val = textStyleModel.get(name);
  25689. val && cssText.push('text-' + name + ':' + val);
  25690. });
  25691. return cssText.join(';');
  25692. }
  25693. /**
  25694. * @param {Object} tooltipModel
  25695. * @return {string}
  25696. * @inner
  25697. */
  25698. function assembleCssText(tooltipModel) {
  25699. tooltipModel = tooltipModel;
  25700. var cssText = [];
  25701. var transitionDuration = tooltipModel.get('transitionDuration');
  25702. var backgroundColor = tooltipModel.get('backgroundColor');
  25703. var textStyleModel = tooltipModel.getModel('textStyle');
  25704. var padding = tooltipModel.get('padding');
  25705. // Animation transition
  25706. transitionDuration &&
  25707. cssText.push(assembleTransition(transitionDuration));
  25708. if (backgroundColor) {
  25709. if (env.canvasSupported) {
  25710. cssText.push('background-Color:' + backgroundColor);
  25711. }
  25712. else {
  25713. // for ie
  25714. cssText.push(
  25715. 'background-Color:#' + zrColor.toHex(backgroundColor)
  25716. );
  25717. cssText.push('filter:alpha(opacity=70)');
  25718. }
  25719. }
  25720. // Border style
  25721. each(['width', 'color', 'radius'], function (name) {
  25722. var borderName = 'border-' + name;
  25723. var camelCase = toCamelCase(borderName);
  25724. var val = tooltipModel.get(camelCase);
  25725. val != null &&
  25726. cssText.push(borderName + ':' + val + (name === 'color' ? '' : 'px'));
  25727. });
  25728. // Text style
  25729. cssText.push(assembleFont(textStyleModel));
  25730. // Padding
  25731. if (padding != null) {
  25732. cssText.push('padding:' + formatUtil.normalizeCssArray(padding).join('px ') + 'px');
  25733. }
  25734. return cssText.join(';') + ';';
  25735. }
  25736. /**
  25737. * @alias module:echarts/component/tooltip/TooltipContent
  25738. * @constructor
  25739. */
  25740. function TooltipContent(container, api) {
  25741. var el = document.createElement('div');
  25742. var zr = api.getZr();
  25743. this.el = el;
  25744. this._x = api.getWidth() / 2;
  25745. this._y = api.getHeight() / 2;
  25746. container.appendChild(el);
  25747. this._container = container;
  25748. this._show = false;
  25749. /**
  25750. * @private
  25751. */
  25752. this._hideTimeout;
  25753. var self = this;
  25754. el.onmouseenter = function () {
  25755. // clear the timeout in hideLater and keep showing tooltip
  25756. if (self.enterable) {
  25757. clearTimeout(self._hideTimeout);
  25758. self._show = true;
  25759. }
  25760. self._inContent = true;
  25761. };
  25762. el.onmousemove = function (e) {
  25763. if (!self.enterable) {
  25764. // Try trigger zrender event to avoid mouse
  25765. // in and out shape too frequently
  25766. var handler = zr.handler;
  25767. eventUtil.normalizeEvent(container, e);
  25768. handler.dispatch('mousemove', e);
  25769. }
  25770. };
  25771. el.onmouseleave = function () {
  25772. if (self.enterable) {
  25773. if (self._show) {
  25774. self.hideLater(self._hideDelay);
  25775. }
  25776. }
  25777. self._inContent = false;
  25778. };
  25779. compromiseMobile(el, container);
  25780. }
  25781. function compromiseMobile(tooltipContentEl, container) {
  25782. // Prevent default behavior on mobile. For example,
  25783. // default pinch gesture will cause browser zoom.
  25784. // We do not preventing event on tooltip contnet el,
  25785. // because user may need customization in tooltip el.
  25786. eventUtil.addEventListener(container, 'touchstart', preventDefault);
  25787. eventUtil.addEventListener(container, 'touchmove', preventDefault);
  25788. eventUtil.addEventListener(container, 'touchend', preventDefault);
  25789. function preventDefault(e) {
  25790. if (contains(e.target)) {
  25791. e.preventDefault();
  25792. }
  25793. }
  25794. function contains(targetEl) {
  25795. while (targetEl && targetEl !== container) {
  25796. if (targetEl === tooltipContentEl) {
  25797. return true;
  25798. }
  25799. targetEl = targetEl.parentNode;
  25800. }
  25801. }
  25802. }
  25803. TooltipContent.prototype = {
  25804. constructor: TooltipContent,
  25805. enterable: true,
  25806. /**
  25807. * Update when tooltip is rendered
  25808. */
  25809. update: function () {
  25810. var container = this._container;
  25811. var stl = container.currentStyle
  25812. || document.defaultView.getComputedStyle(container);
  25813. var domStyle = container.style;
  25814. if (domStyle.position !== 'absolute' && stl.position !== 'absolute') {
  25815. domStyle.position = 'relative';
  25816. }
  25817. // Hide the tooltip
  25818. // PENDING
  25819. // this.hide();
  25820. },
  25821. show: function (tooltipModel) {
  25822. clearTimeout(this._hideTimeout);
  25823. this.el.style.cssText = gCssText + assembleCssText(tooltipModel)
  25824. // http://stackoverflow.com/questions/21125587/css3-transition-not-working-in-chrome-anymore
  25825. + ';left:' + this._x + 'px;top:' + this._y + 'px;'
  25826. + (tooltipModel.get('extraCssText') || '');
  25827. this._show = true;
  25828. },
  25829. setContent: function (content) {
  25830. var el = this.el;
  25831. el.innerHTML = content;
  25832. el.style.display = content ? 'block' : 'none';
  25833. },
  25834. moveTo: function (x, y) {
  25835. var style = this.el.style;
  25836. style.left = x + 'px';
  25837. style.top = y + 'px';
  25838. this._x = x;
  25839. this._y = y;
  25840. },
  25841. hide: function () {
  25842. this.el.style.display = 'none';
  25843. this._show = false;
  25844. },
  25845. // showLater: function ()
  25846. hideLater: function (time) {
  25847. if (this._show && !(this._inContent && this.enterable)) {
  25848. if (time) {
  25849. this._hideDelay = time;
  25850. // Set show false to avoid invoke hideLater mutiple times
  25851. this._show = false;
  25852. this._hideTimeout = setTimeout(zrUtil.bind(this.hide, this), time);
  25853. }
  25854. else {
  25855. this.hide();
  25856. }
  25857. }
  25858. },
  25859. isShow: function () {
  25860. return this._show;
  25861. }
  25862. };
  25863. module.exports = TooltipContent;
  25864. /***/ },
  25865. /* 275 */,
  25866. /* 276 */,
  25867. /* 277 */,
  25868. /* 278 */,
  25869. /* 279 */,
  25870. /* 280 */,
  25871. /* 281 */,
  25872. /* 282 */,
  25873. /* 283 */,
  25874. /* 284 */,
  25875. /* 285 */,
  25876. /* 286 */,
  25877. /* 287 */,
  25878. /* 288 */,
  25879. /* 289 */
  25880. /***/ function(module, exports, __webpack_require__) {
  25881. 'use strict';
  25882. var echarts = __webpack_require__(1);
  25883. var graphic = __webpack_require__(42);
  25884. var layout = __webpack_require__(21);
  25885. // Model
  25886. echarts.extendComponentModel({
  25887. type: 'title',
  25888. layoutMode: {type: 'box', ignoreSize: true},
  25889. defaultOption: {
  25890. // 一级层叠
  25891. zlevel: 0,
  25892. // 二级层叠
  25893. z: 6,
  25894. show: true,
  25895. text: '',
  25896. // 超链接跳转
  25897. // link: null,
  25898. // 仅支持self | blank
  25899. target: 'blank',
  25900. subtext: '',
  25901. // 超链接跳转
  25902. // sublink: null,
  25903. // 仅支持self | blank
  25904. subtarget: 'blank',
  25905. // 'center' ¦ 'left' ¦ 'right'
  25906. // ¦ {number}(x坐标,单位px)
  25907. left: 0,
  25908. // 'top' ¦ 'bottom' ¦ 'center'
  25909. // ¦ {number}(y坐标,单位px)
  25910. top: 0,
  25911. // 水平对齐
  25912. // 'auto' | 'left' | 'right'
  25913. // 默认根据 x 的位置判断是左对齐还是右对齐
  25914. //textAlign: null
  25915. backgroundColor: 'rgba(0,0,0,0)',
  25916. // 标题边框颜色
  25917. borderColor: '#ccc',
  25918. // 标题边框线宽,单位px,默认为0(无边框)
  25919. borderWidth: 0,
  25920. // 标题内边距,单位px,默认各方向内边距为5,
  25921. // 接受数组分别设定上右下左边距,同css
  25922. padding: 5,
  25923. // 主副标题纵向间隔,单位px,默认为10,
  25924. itemGap: 10,
  25925. textStyle: {
  25926. fontSize: 18,
  25927. fontWeight: 'bolder',
  25928. // 主标题文字颜色
  25929. color: '#333'
  25930. },
  25931. subtextStyle: {
  25932. // 副标题文字颜色
  25933. color: '#aaa'
  25934. }
  25935. }
  25936. });
  25937. // View
  25938. echarts.extendComponentView({
  25939. type: 'title',
  25940. render: function (titleModel, ecModel, api) {
  25941. this.group.removeAll();
  25942. if (!titleModel.get('show')) {
  25943. return;
  25944. }
  25945. var group = this.group;
  25946. var textStyleModel = titleModel.getModel('textStyle');
  25947. var subtextStyleModel = titleModel.getModel('subtextStyle');
  25948. var textAlign = titleModel.get('textAlign');
  25949. var textEl = new graphic.Text({
  25950. style: {
  25951. text: titleModel.get('text'),
  25952. textFont: textStyleModel.getFont(),
  25953. fill: textStyleModel.getTextColor(),
  25954. textBaseline: 'top'
  25955. },
  25956. z2: 10
  25957. });
  25958. var textRect = textEl.getBoundingRect();
  25959. var subText = titleModel.get('subtext');
  25960. var subTextEl = new graphic.Text({
  25961. style: {
  25962. text: subText,
  25963. textFont: subtextStyleModel.getFont(),
  25964. fill: subtextStyleModel.getTextColor(),
  25965. y: textRect.height + titleModel.get('itemGap'),
  25966. textBaseline: 'top'
  25967. },
  25968. z2: 10
  25969. });
  25970. var link = titleModel.get('link');
  25971. var sublink = titleModel.get('sublink');
  25972. textEl.silent = !link;
  25973. subTextEl.silent = !sublink;
  25974. if (link) {
  25975. textEl.on('click', function () {
  25976. window.open(link, '_' + titleModel.get('target'));
  25977. });
  25978. }
  25979. if (sublink) {
  25980. subTextEl.on('click', function () {
  25981. window.open(sublink, '_' + titleModel.get('subtarget'));
  25982. });
  25983. }
  25984. group.add(textEl);
  25985. subText && group.add(subTextEl);
  25986. // If no subText, but add subTextEl, there will be an empty line.
  25987. var groupRect = group.getBoundingRect();
  25988. var layoutOption = titleModel.getBoxLayoutParams();
  25989. layoutOption.width = groupRect.width;
  25990. layoutOption.height = groupRect.height;
  25991. var layoutRect = layout.getLayoutRect(
  25992. layoutOption, {
  25993. width: api.getWidth(),
  25994. height: api.getHeight()
  25995. }, titleModel.get('padding')
  25996. );
  25997. // Adjust text align based on position
  25998. if (!textAlign) {
  25999. // Align left if title is on the left. center and right is same
  26000. textAlign = titleModel.get('left') || titleModel.get('right');
  26001. if (textAlign === 'middle') {
  26002. textAlign = 'center';
  26003. }
  26004. // Adjust layout by text align
  26005. if (textAlign === 'right') {
  26006. layoutRect.x += layoutRect.width;
  26007. }
  26008. else if (textAlign === 'center') {
  26009. layoutRect.x += layoutRect.width / 2;
  26010. }
  26011. }
  26012. group.position = [layoutRect.x, layoutRect.y];
  26013. textEl.setStyle('textAlign', textAlign);
  26014. subTextEl.setStyle('textAlign', textAlign);
  26015. // Render background
  26016. // Get groupRect again because textAlign has been changed
  26017. groupRect = group.getBoundingRect();
  26018. var padding = layoutRect.margin;
  26019. var style = titleModel.getItemStyle(['color', 'opacity']);
  26020. style.fill = titleModel.get('backgroundColor');
  26021. var rect = new graphic.Rect({
  26022. shape: {
  26023. x: groupRect.x - padding[3],
  26024. y: groupRect.y - padding[0],
  26025. width: groupRect.width + padding[1] + padding[3],
  26026. height: groupRect.height + padding[0] + padding[2]
  26027. },
  26028. style: style,
  26029. silent: true
  26030. });
  26031. graphic.subPixelOptimizeRect(rect);
  26032. group.add(rect);
  26033. }
  26034. });
  26035. /***/ },
  26036. /* 290 */
  26037. /***/ function(module, exports, __webpack_require__) {
  26038. /**
  26039. * DataZoom component entry
  26040. */
  26041. __webpack_require__(291);
  26042. __webpack_require__(292);
  26043. __webpack_require__(294);
  26044. __webpack_require__(295);
  26045. __webpack_require__(296);
  26046. __webpack_require__(299);
  26047. __webpack_require__(300);
  26048. __webpack_require__(302);
  26049. __webpack_require__(303);
  26050. /***/ },
  26051. /* 291 */
  26052. /***/ function(module, exports, __webpack_require__) {
  26053. __webpack_require__(19).registerSubTypeDefaulter('dataZoom', function (option) {
  26054. // Default 'slider' when no type specified.
  26055. return 'slider';
  26056. });
  26057. /***/ },
  26058. /* 292 */
  26059. /***/ function(module, exports, __webpack_require__) {
  26060. /**
  26061. * @file Data zoom model
  26062. */
  26063. var zrUtil = __webpack_require__(3);
  26064. var env = __webpack_require__(79);
  26065. var echarts = __webpack_require__(1);
  26066. var modelUtil = __webpack_require__(5);
  26067. var AxisProxy = __webpack_require__(293);
  26068. var each = zrUtil.each;
  26069. var eachAxisDim = modelUtil.eachAxisDim;
  26070. var DataZoomModel = echarts.extendComponentModel({
  26071. type: 'dataZoom',
  26072. dependencies: [
  26073. 'xAxis', 'yAxis', 'zAxis', 'radiusAxis', 'angleAxis', 'series'
  26074. ],
  26075. /**
  26076. * @protected
  26077. */
  26078. defaultOption: {
  26079. zlevel: 0,
  26080. z: 4, // Higher than normal component (z: 2).
  26081. orient: null, // Default auto by axisIndex. Possible value: 'horizontal', 'vertical'.
  26082. xAxisIndex: null, // Default all horizontal category axis.
  26083. yAxisIndex: null, // Default all vertical category axis.
  26084. angleAxisIndex: null,
  26085. radiusAxisIndex: null,
  26086. filterMode: 'filter', // Possible values: 'filter' or 'empty'.
  26087. // 'filter': data items which are out of window will be removed.
  26088. // This option is applicable when filtering outliers.
  26089. // 'empty': data items which are out of window will be set to empty.
  26090. // This option is applicable when user should not neglect
  26091. // that there are some data items out of window.
  26092. // Taking line chart as an example, line will be broken in
  26093. // the filtered points when filterModel is set to 'empty', but
  26094. // be connected when set to 'filter'.
  26095. throttle: 100, // Dispatch action by the fixed rate, avoid frequency.
  26096. // default 100. Do not throttle when use null/undefined.
  26097. start: 0, // Start percent. 0 ~ 100
  26098. end: 100, // End percent. 0 ~ 100
  26099. startValue: null, // Start value. If startValue specified, start is ignored.
  26100. endValue: null // End value. If endValue specified, end is ignored.
  26101. },
  26102. /**
  26103. * @override
  26104. */
  26105. init: function (option, parentModel, ecModel) {
  26106. /**
  26107. * key like x_0, y_1
  26108. * @private
  26109. * @type {Object}
  26110. */
  26111. this._dataIntervalByAxis = {};
  26112. /**
  26113. * @private
  26114. */
  26115. this._dataInfo = {};
  26116. /**
  26117. * key like x_0, y_1
  26118. * @private
  26119. */
  26120. this._axisProxies = {};
  26121. /**
  26122. * @readOnly
  26123. */
  26124. this.textStyleModel;
  26125. var rawOption = retrieveRaw(option);
  26126. this.mergeDefaultAndTheme(option, ecModel);
  26127. this.doInit(rawOption);
  26128. },
  26129. /**
  26130. * @override
  26131. */
  26132. mergeOption: function (newOption) {
  26133. var rawOption = retrieveRaw(newOption);
  26134. //FIX #2591
  26135. zrUtil.merge(this.option, newOption, true);
  26136. this.doInit(rawOption);
  26137. },
  26138. /**
  26139. * @protected
  26140. */
  26141. doInit: function (rawOption) {
  26142. var thisOption = this.option;
  26143. // Disable realtime view update if canvas is not supported.
  26144. if (!env.canvasSupported) {
  26145. thisOption.realtime = false;
  26146. }
  26147. processRangeProp('start', 'startValue', rawOption, thisOption);
  26148. processRangeProp('end', 'endValue', rawOption, thisOption);
  26149. this.textStyleModel = this.getModel('textStyle');
  26150. this._resetTarget();
  26151. this._giveAxisProxies();
  26152. },
  26153. /**
  26154. * @private
  26155. */
  26156. _giveAxisProxies: function () {
  26157. var axisProxies = this._axisProxies;
  26158. this.eachTargetAxis(function (dimNames, axisIndex, dataZoomModel, ecModel) {
  26159. var axisModel = this.dependentModels[dimNames.axis][axisIndex];
  26160. // If exists, share axisProxy with other dataZoomModels.
  26161. var axisProxy = axisModel.__dzAxisProxy || (
  26162. // Use the first dataZoomModel as the main model of axisProxy.
  26163. axisModel.__dzAxisProxy = new AxisProxy(
  26164. dimNames.name, axisIndex, this, ecModel
  26165. )
  26166. );
  26167. // FIXME
  26168. // dispose __dzAxisProxy
  26169. axisProxies[dimNames.name + '_' + axisIndex] = axisProxy;
  26170. }, this);
  26171. },
  26172. /**
  26173. * @private
  26174. */
  26175. _resetTarget: function () {
  26176. var thisOption = this.option;
  26177. var autoMode = this._judgeAutoMode();
  26178. eachAxisDim(function (dimNames) {
  26179. var axisIndexName = dimNames.axisIndex;
  26180. thisOption[axisIndexName] = modelUtil.normalizeToArray(
  26181. thisOption[axisIndexName]
  26182. );
  26183. }, this);
  26184. if (autoMode === 'axisIndex') {
  26185. this._autoSetAxisIndex();
  26186. }
  26187. else if (autoMode === 'orient') {
  26188. this._autoSetOrient();
  26189. }
  26190. },
  26191. /**
  26192. * @private
  26193. */
  26194. _judgeAutoMode: function () {
  26195. // Auto set only works for setOption at the first time.
  26196. // The following is user's reponsibility. So using merged
  26197. // option is OK.
  26198. var thisOption = this.option;
  26199. var hasIndexSpecified = false;
  26200. eachAxisDim(function (dimNames) {
  26201. // When user set axisIndex as a empty array, we think that user specify axisIndex
  26202. // but do not want use auto mode. Because empty array may be encountered when
  26203. // some error occured.
  26204. if (thisOption[dimNames.axisIndex] != null) {
  26205. hasIndexSpecified = true;
  26206. }
  26207. }, this);
  26208. var orient = thisOption.orient;
  26209. if (orient == null && hasIndexSpecified) {
  26210. return 'orient';
  26211. }
  26212. else if (!hasIndexSpecified) {
  26213. if (orient == null) {
  26214. thisOption.orient = 'horizontal';
  26215. }
  26216. return 'axisIndex';
  26217. }
  26218. },
  26219. /**
  26220. * @private
  26221. */
  26222. _autoSetAxisIndex: function () {
  26223. var autoAxisIndex = true;
  26224. var orient = this.get('orient', true);
  26225. var thisOption = this.option;
  26226. if (autoAxisIndex) {
  26227. // Find axis that parallel to dataZoom as default.
  26228. var dimNames = orient === 'vertical'
  26229. ? {dim: 'y', axisIndex: 'yAxisIndex', axis: 'yAxis'}
  26230. : {dim: 'x', axisIndex: 'xAxisIndex', axis: 'xAxis'};
  26231. if (this.dependentModels[dimNames.axis].length) {
  26232. thisOption[dimNames.axisIndex] = [0];
  26233. autoAxisIndex = false;
  26234. }
  26235. }
  26236. if (autoAxisIndex) {
  26237. // Find the first category axis as default. (consider polar)
  26238. eachAxisDim(function (dimNames) {
  26239. if (!autoAxisIndex) {
  26240. return;
  26241. }
  26242. var axisIndices = [];
  26243. var axisModels = this.dependentModels[dimNames.axis];
  26244. if (axisModels.length && !axisIndices.length) {
  26245. for (var i = 0, len = axisModels.length; i < len; i++) {
  26246. if (axisModels[i].get('type') === 'category') {
  26247. axisIndices.push(i);
  26248. }
  26249. }
  26250. }
  26251. thisOption[dimNames.axisIndex] = axisIndices;
  26252. if (axisIndices.length) {
  26253. autoAxisIndex = false;
  26254. }
  26255. }, this);
  26256. }
  26257. if (autoAxisIndex) {
  26258. // FIXME
  26259. // 这里是兼容ec2的写法(没指定xAxisIndex和yAxisIndex时把scatter和双数值轴折柱纳入dataZoom控制),
  26260. // 但是实际是否需要Grid.js#getScaleByOption来判断(考虑time,log等axis type)?
  26261. // If both dataZoom.xAxisIndex and dataZoom.yAxisIndex is not specified,
  26262. // dataZoom component auto adopts series that reference to
  26263. // both xAxis and yAxis which type is 'value'.
  26264. this.ecModel.eachSeries(function (seriesModel) {
  26265. if (this._isSeriesHasAllAxesTypeOf(seriesModel, 'value')) {
  26266. eachAxisDim(function (dimNames) {
  26267. var axisIndices = thisOption[dimNames.axisIndex];
  26268. var axisIndex = seriesModel.get(dimNames.axisIndex);
  26269. if (zrUtil.indexOf(axisIndices, axisIndex) < 0) {
  26270. axisIndices.push(axisIndex);
  26271. }
  26272. });
  26273. }
  26274. }, this);
  26275. }
  26276. },
  26277. /**
  26278. * @private
  26279. */
  26280. _autoSetOrient: function () {
  26281. var dim;
  26282. // Find the first axis
  26283. this.eachTargetAxis(function (dimNames) {
  26284. !dim && (dim = dimNames.name);
  26285. }, this);
  26286. this.option.orient = dim === 'y' ? 'vertical' : 'horizontal';
  26287. },
  26288. /**
  26289. * @private
  26290. */
  26291. _isSeriesHasAllAxesTypeOf: function (seriesModel, axisType) {
  26292. // FIXME
  26293. // 需要series的xAxisIndex和yAxisIndex都首先自动设置上。
  26294. // 例如series.type === scatter时。
  26295. var is = true;
  26296. eachAxisDim(function (dimNames) {
  26297. var seriesAxisIndex = seriesModel.get(dimNames.axisIndex);
  26298. var axisModel = this.dependentModels[dimNames.axis][seriesAxisIndex];
  26299. if (!axisModel || axisModel.get('type') !== axisType) {
  26300. is = false;
  26301. }
  26302. }, this);
  26303. return is;
  26304. },
  26305. /**
  26306. * @public
  26307. */
  26308. getFirstTargetAxisModel: function () {
  26309. var firstAxisModel;
  26310. eachAxisDim(function (dimNames) {
  26311. if (firstAxisModel == null) {
  26312. var indices = this.get(dimNames.axisIndex);
  26313. if (indices.length) {
  26314. firstAxisModel = this.dependentModels[dimNames.axis][indices[0]];
  26315. }
  26316. }
  26317. }, this);
  26318. return firstAxisModel;
  26319. },
  26320. /**
  26321. * @public
  26322. * @param {Function} callback param: axisModel, dimNames, axisIndex, dataZoomModel, ecModel
  26323. */
  26324. eachTargetAxis: function (callback, context) {
  26325. var ecModel = this.ecModel;
  26326. eachAxisDim(function (dimNames) {
  26327. each(
  26328. this.get(dimNames.axisIndex),
  26329. function (axisIndex) {
  26330. callback.call(context, dimNames, axisIndex, this, ecModel);
  26331. },
  26332. this
  26333. );
  26334. }, this);
  26335. },
  26336. getAxisProxy: function (dimName, axisIndex) {
  26337. return this._axisProxies[dimName + '_' + axisIndex];
  26338. },
  26339. /**
  26340. * If not specified, set to undefined.
  26341. *
  26342. * @public
  26343. * @param {Object} opt
  26344. * @param {number} [opt.start]
  26345. * @param {number} [opt.end]
  26346. * @param {number} [opt.startValue]
  26347. * @param {number} [opt.endValue]
  26348. */
  26349. setRawRange: function (opt) {
  26350. each(['start', 'end', 'startValue', 'endValue'], function (name) {
  26351. // If any of those prop is null/undefined, we should alos set
  26352. // them, because only one pair between start/end and
  26353. // startValue/endValue can work.
  26354. this.option[name] = opt[name];
  26355. }, this);
  26356. },
  26357. /**
  26358. * @public
  26359. * @return {Array.<number>} [startPercent, endPercent]
  26360. */
  26361. getPercentRange: function () {
  26362. var axisProxy = this.findRepresentativeAxisProxy();
  26363. if (axisProxy) {
  26364. return axisProxy.getDataPercentWindow();
  26365. }
  26366. },
  26367. /**
  26368. * @public
  26369. * For example, chart.getModel().getComponent('dataZoom').getValueRange('y', 0);
  26370. *
  26371. * @param {string} [axisDimName]
  26372. * @param {number} [axisIndex]
  26373. * @return {Array.<number>} [startValue, endValue]
  26374. */
  26375. getValueRange: function (axisDimName, axisIndex) {
  26376. if (axisDimName == null && axisIndex == null) {
  26377. var axisProxy = this.findRepresentativeAxisProxy();
  26378. if (axisProxy) {
  26379. return axisProxy.getDataValueWindow();
  26380. }
  26381. }
  26382. else {
  26383. return this.getAxisProxy(axisDimName, axisIndex).getDataValueWindow();
  26384. }
  26385. },
  26386. /**
  26387. * @public
  26388. * @return {module:echarts/component/dataZoom/AxisProxy}
  26389. */
  26390. findRepresentativeAxisProxy: function () {
  26391. // Find the first hosted axisProxy
  26392. var axisProxies = this._axisProxies;
  26393. for (var key in axisProxies) {
  26394. if (axisProxies.hasOwnProperty(key) && axisProxies[key].hostedBy(this)) {
  26395. return axisProxies[key];
  26396. }
  26397. }
  26398. // If no hosted axis find not hosted axisProxy.
  26399. // Consider this case: dataZoomModel1 and dataZoomModel2 control the same axis,
  26400. // and the option.start or option.end settings are different. The percentRange
  26401. // should follow axisProxy.
  26402. // (We encounter this problem in toolbox data zoom.)
  26403. for (var key in axisProxies) {
  26404. if (axisProxies.hasOwnProperty(key) && !axisProxies[key].hostedBy(this)) {
  26405. return axisProxies[key];
  26406. }
  26407. }
  26408. }
  26409. });
  26410. function retrieveRaw(option) {
  26411. var ret = {};
  26412. each(
  26413. ['start', 'end', 'startValue', 'endValue'],
  26414. function (name) {
  26415. ret[name] = option[name];
  26416. }
  26417. );
  26418. return ret;
  26419. }
  26420. function processRangeProp(percentProp, valueProp, rawOption, thisOption) {
  26421. // start/end has higher priority over startValue/endValue,
  26422. // but we should make chart.setOption({endValue: 1000}) effective,
  26423. // rather than chart.setOption({endValue: 1000, end: null}).
  26424. if (rawOption[valueProp] != null && rawOption[percentProp] == null) {
  26425. thisOption[percentProp] = null;
  26426. }
  26427. // Otherwise do nothing and use the merge result.
  26428. }
  26429. module.exports = DataZoomModel;
  26430. /***/ },
  26431. /* 293 */
  26432. /***/ function(module, exports, __webpack_require__) {
  26433. /**
  26434. * @file Axis operator
  26435. */
  26436. var zrUtil = __webpack_require__(3);
  26437. var numberUtil = __webpack_require__(7);
  26438. var each = zrUtil.each;
  26439. var asc = numberUtil.asc;
  26440. /**
  26441. * Operate single axis.
  26442. * One axis can only operated by one axis operator.
  26443. * Different dataZoomModels may be defined to operate the same axis.
  26444. * (i.e. 'inside' data zoom and 'slider' data zoom components)
  26445. * So dataZoomModels share one axisProxy in that case.
  26446. *
  26447. * @class
  26448. */
  26449. var AxisProxy = function (dimName, axisIndex, dataZoomModel, ecModel) {
  26450. /**
  26451. * @private
  26452. * @type {string}
  26453. */
  26454. this._dimName = dimName;
  26455. /**
  26456. * @private
  26457. */
  26458. this._axisIndex = axisIndex;
  26459. /**
  26460. * @private
  26461. * @type {Array.<number>}
  26462. */
  26463. this._valueWindow;
  26464. /**
  26465. * @private
  26466. * @type {Array.<number>}
  26467. */
  26468. this._percentWindow;
  26469. /**
  26470. * @private
  26471. * @type {Array.<number>}
  26472. */
  26473. this._dataExtent;
  26474. /**
  26475. * @readOnly
  26476. * @type {module: echarts/model/Global}
  26477. */
  26478. this.ecModel = ecModel;
  26479. /**
  26480. * @private
  26481. * @type {module: echarts/component/dataZoom/DataZoomModel}
  26482. */
  26483. this._dataZoomModel = dataZoomModel;
  26484. };
  26485. AxisProxy.prototype = {
  26486. constructor: AxisProxy,
  26487. /**
  26488. * Whether the axisProxy is hosted by dataZoomModel.
  26489. *
  26490. * @public
  26491. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  26492. * @return {boolean}
  26493. */
  26494. hostedBy: function (dataZoomModel) {
  26495. return this._dataZoomModel === dataZoomModel;
  26496. },
  26497. /**
  26498. * @return {Array.<number>}
  26499. */
  26500. getDataExtent: function () {
  26501. return this._dataExtent.slice();
  26502. },
  26503. /**
  26504. * @return {Array.<number>}
  26505. */
  26506. getDataValueWindow: function () {
  26507. return this._valueWindow.slice();
  26508. },
  26509. /**
  26510. * @return {Array.<number>}
  26511. */
  26512. getDataPercentWindow: function () {
  26513. return this._percentWindow.slice();
  26514. },
  26515. /**
  26516. * @public
  26517. * @param {number} axisIndex
  26518. * @return {Array} seriesModels
  26519. */
  26520. getTargetSeriesModels: function () {
  26521. var seriesModels = [];
  26522. this.ecModel.eachSeries(function (seriesModel) {
  26523. if (this._axisIndex === seriesModel.get(this._dimName + 'AxisIndex')) {
  26524. seriesModels.push(seriesModel);
  26525. }
  26526. }, this);
  26527. return seriesModels;
  26528. },
  26529. getAxisModel: function () {
  26530. return this.ecModel.getComponent(this._dimName + 'Axis', this._axisIndex);
  26531. },
  26532. getOtherAxisModel: function () {
  26533. var axisDim = this._dimName;
  26534. var ecModel = this.ecModel;
  26535. var axisModel = this.getAxisModel();
  26536. var isCartesian = axisDim === 'x' || axisDim === 'y';
  26537. var otherAxisDim;
  26538. var coordSysIndexName;
  26539. if (isCartesian) {
  26540. coordSysIndexName = 'gridIndex';
  26541. otherAxisDim = axisDim === 'x' ? 'y' : 'x';
  26542. }
  26543. else {
  26544. coordSysIndexName = 'polarIndex';
  26545. otherAxisDim = axisDim === 'angle' ? 'radius' : 'angle';
  26546. }
  26547. var foundOtherAxisModel;
  26548. ecModel.eachComponent(otherAxisDim + 'Axis', function (otherAxisModel) {
  26549. if ((otherAxisModel.get(coordSysIndexName) || 0)
  26550. === (axisModel.get(coordSysIndexName) || 0)
  26551. ) {
  26552. foundOtherAxisModel = otherAxisModel;
  26553. }
  26554. });
  26555. return foundOtherAxisModel;
  26556. },
  26557. /**
  26558. * Notice: reset should not be called before series.restoreData() called,
  26559. * so it is recommanded to be called in "process stage" but not "model init
  26560. * stage".
  26561. *
  26562. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  26563. */
  26564. reset: function (dataZoomModel) {
  26565. if (dataZoomModel !== this._dataZoomModel) {
  26566. return;
  26567. }
  26568. // Culculate data window and data extent, and record them.
  26569. var dataExtent = this._dataExtent = calculateDataExtent(
  26570. this._dimName, this.getTargetSeriesModels()
  26571. );
  26572. var dataWindow = calculateDataWindow(
  26573. dataZoomModel.option, dataExtent, this
  26574. );
  26575. this._valueWindow = dataWindow.valueWindow;
  26576. this._percentWindow = dataWindow.percentWindow;
  26577. // Update axis setting then.
  26578. setAxisModel(this);
  26579. },
  26580. /**
  26581. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  26582. */
  26583. restore: function (dataZoomModel) {
  26584. if (dataZoomModel !== this._dataZoomModel) {
  26585. return;
  26586. }
  26587. this._valueWindow = this._percentWindow = null;
  26588. setAxisModel(this, true);
  26589. },
  26590. /**
  26591. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  26592. */
  26593. filterData: function (dataZoomModel) {
  26594. if (dataZoomModel !== this._dataZoomModel) {
  26595. return;
  26596. }
  26597. var axisDim = this._dimName;
  26598. var seriesModels = this.getTargetSeriesModels();
  26599. var filterMode = dataZoomModel.get('filterMode');
  26600. var valueWindow = this._valueWindow;
  26601. // FIXME
  26602. // Toolbox may has dataZoom injected. And if there are stacked bar chart
  26603. // with NaN data, NaN will be filtered and stack will be wrong.
  26604. // So we need to force the mode to be set empty.
  26605. // In fect, it is not a big deal that do not support filterMode-'filter'
  26606. // when using toolbox#dataZoom, utill tooltip#dataZoom support "single axis
  26607. // selection" some day, which might need "adapt to data extent on the
  26608. // otherAxis", which is disabled by filterMode-'empty'.
  26609. var otherAxisModel = this.getOtherAxisModel();
  26610. if (dataZoomModel.get('$fromToolbox')
  26611. && otherAxisModel
  26612. && otherAxisModel.get('type') === 'category'
  26613. ) {
  26614. filterMode = 'empty';
  26615. }
  26616. // Process series data
  26617. each(seriesModels, function (seriesModel) {
  26618. var seriesData = seriesModel.getData();
  26619. seriesData && each(seriesModel.coordDimToDataDim(axisDim), function (dim) {
  26620. if (filterMode === 'empty') {
  26621. seriesModel.setData(
  26622. seriesData.map(dim, function (value) {
  26623. return !isInWindow(value) ? NaN : value;
  26624. })
  26625. );
  26626. }
  26627. else {
  26628. seriesData.filterSelf(dim, isInWindow);
  26629. }
  26630. });
  26631. });
  26632. function isInWindow(value) {
  26633. return value >= valueWindow[0] && value <= valueWindow[1];
  26634. }
  26635. }
  26636. };
  26637. function calculateDataExtent(axisDim, seriesModels) {
  26638. var dataExtent = [Infinity, -Infinity];
  26639. each(seriesModels, function (seriesModel) {
  26640. var seriesData = seriesModel.getData();
  26641. if (seriesData) {
  26642. each(seriesModel.coordDimToDataDim(axisDim), function (dim) {
  26643. var seriesExtent = seriesData.getDataExtent(dim);
  26644. seriesExtent[0] < dataExtent[0] && (dataExtent[0] = seriesExtent[0]);
  26645. seriesExtent[1] > dataExtent[1] && (dataExtent[1] = seriesExtent[1]);
  26646. });
  26647. }
  26648. }, this);
  26649. return dataExtent;
  26650. }
  26651. function calculateDataWindow(opt, dataExtent, axisProxy) {
  26652. var axisModel = axisProxy.getAxisModel();
  26653. var scale = axisModel.axis.scale;
  26654. var percentExtent = [0, 100];
  26655. var percentWindow = [
  26656. opt.start,
  26657. opt.end
  26658. ];
  26659. var valueWindow = [];
  26660. // In percent range is used and axis min/max/scale is set,
  26661. // window should be based on min/max/0, but should not be
  26662. // based on the extent of filtered data.
  26663. dataExtent = dataExtent.slice();
  26664. fixExtendByAxis(dataExtent, axisModel, scale);
  26665. each(['startValue', 'endValue'], function (prop) {
  26666. valueWindow.push(
  26667. opt[prop] != null
  26668. ? scale.parse(opt[prop])
  26669. : null
  26670. );
  26671. });
  26672. // Normalize bound.
  26673. each([0, 1], function (idx) {
  26674. var boundValue = valueWindow[idx];
  26675. var boundPercent = percentWindow[idx];
  26676. // start/end has higher priority over startValue/endValue,
  26677. // because start/end can be consistent among different type
  26678. // of axis but startValue/endValue not.
  26679. if (boundPercent != null || boundValue == null) {
  26680. if (boundPercent == null) {
  26681. boundPercent = percentExtent[idx];
  26682. }
  26683. // Use scale.parse to math round for category or time axis.
  26684. boundValue = scale.parse(numberUtil.linearMap(
  26685. boundPercent, percentExtent, dataExtent, true
  26686. ));
  26687. }
  26688. else { // boundPercent == null && boundValue != null
  26689. boundPercent = numberUtil.linearMap(
  26690. boundValue, dataExtent, percentExtent, true
  26691. );
  26692. }
  26693. // valueWindow[idx] = round(boundValue);
  26694. // percentWindow[idx] = round(boundPercent);
  26695. valueWindow[idx] = boundValue;
  26696. percentWindow[idx] = boundPercent;
  26697. });
  26698. return {
  26699. valueWindow: asc(valueWindow),
  26700. percentWindow: asc(percentWindow)
  26701. };
  26702. }
  26703. function fixExtendByAxis(dataExtent, axisModel, scale) {
  26704. each(['min', 'max'], function (minMax, index) {
  26705. var axisMax = axisModel.get(minMax, true);
  26706. // Consider 'dataMin', 'dataMax'
  26707. if (axisMax != null && (axisMax + '').toLowerCase() !== 'data' + minMax) {
  26708. dataExtent[index] = scale.parse(axisMax);
  26709. }
  26710. });
  26711. if (!axisModel.get('scale', true)) {
  26712. dataExtent[0] > 0 && (dataExtent[0] = 0);
  26713. dataExtent[1] < 0 && (dataExtent[1] = 0);
  26714. }
  26715. return dataExtent;
  26716. }
  26717. function setAxisModel(axisProxy, isRestore) {
  26718. var axisModel = axisProxy.getAxisModel();
  26719. var percentWindow = axisProxy._percentWindow;
  26720. var valueWindow = axisProxy._valueWindow;
  26721. if (!percentWindow) {
  26722. return;
  26723. }
  26724. var isFull = isRestore || (percentWindow[0] === 0 && percentWindow[1] === 100);
  26725. // [0, 500]: arbitrary value, guess axis extent.
  26726. var precision = !isRestore && numberUtil.getPixelPrecision(valueWindow, [0, 500]);
  26727. // toFixed() digits argument must be between 0 and 20
  26728. var invalidPrecision = !isRestore && !(precision < 20 && precision >= 0);
  26729. var useOrigin = isRestore || isFull || invalidPrecision;
  26730. axisModel.setRange && axisModel.setRange(
  26731. useOrigin ? null : +valueWindow[0].toFixed(precision),
  26732. useOrigin ? null : +valueWindow[1].toFixed(precision)
  26733. );
  26734. }
  26735. module.exports = AxisProxy;
  26736. /***/ },
  26737. /* 294 */
  26738. /***/ function(module, exports, __webpack_require__) {
  26739. var ComponentView = __webpack_require__(28);
  26740. module.exports = ComponentView.extend({
  26741. type: 'dataZoom',
  26742. render: function (dataZoomModel, ecModel, api, payload) {
  26743. this.dataZoomModel = dataZoomModel;
  26744. this.ecModel = ecModel;
  26745. this.api = api;
  26746. },
  26747. /**
  26748. * Find the first target coordinate system.
  26749. *
  26750. * @protected
  26751. * @return {Object} {
  26752. * cartesians: [
  26753. * {model: coord0, axisModels: [axis1, axis3], coordIndex: 1},
  26754. * {model: coord1, axisModels: [axis0, axis2], coordIndex: 0},
  26755. * ...
  26756. * ], // cartesians must not be null/undefined.
  26757. * polars: [
  26758. * {model: coord0, axisModels: [axis4], coordIndex: 0},
  26759. * ...
  26760. * ], // polars must not be null/undefined.
  26761. * axisModels: [axis0, axis1, axis2, axis3, axis4]
  26762. * // axisModels must not be null/undefined.
  26763. * }
  26764. */
  26765. getTargetInfo: function () {
  26766. var dataZoomModel = this.dataZoomModel;
  26767. var ecModel = this.ecModel;
  26768. var cartesians = [];
  26769. var polars = [];
  26770. var axisModels = [];
  26771. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex) {
  26772. var axisModel = ecModel.getComponent(dimNames.axis, axisIndex);
  26773. if (axisModel) {
  26774. axisModels.push(axisModel);
  26775. var gridIndex = axisModel.get('gridIndex');
  26776. var polarIndex = axisModel.get('polarIndex');
  26777. if (gridIndex != null) {
  26778. var coordModel = ecModel.getComponent('grid', gridIndex);
  26779. save(coordModel, axisModel, cartesians, gridIndex);
  26780. }
  26781. else if (polarIndex != null) {
  26782. var coordModel = ecModel.getComponent('polar', polarIndex);
  26783. save(coordModel, axisModel, polars, polarIndex);
  26784. }
  26785. }
  26786. }, this);
  26787. function save(coordModel, axisModel, store, coordIndex) {
  26788. var item;
  26789. for (var i = 0; i < store.length; i++) {
  26790. if (store[i].model === coordModel) {
  26791. item = store[i];
  26792. break;
  26793. }
  26794. }
  26795. if (!item) {
  26796. store.push(item = {
  26797. model: coordModel, axisModels: [], coordIndex: coordIndex
  26798. });
  26799. }
  26800. item.axisModels.push(axisModel);
  26801. }
  26802. return {
  26803. cartesians: cartesians,
  26804. polars: polars,
  26805. axisModels: axisModels
  26806. };
  26807. }
  26808. });
  26809. /***/ },
  26810. /* 295 */
  26811. /***/ function(module, exports, __webpack_require__) {
  26812. /**
  26813. * @file Data zoom model
  26814. */
  26815. var DataZoomModel = __webpack_require__(292);
  26816. var SliderZoomModel = DataZoomModel.extend({
  26817. type: 'dataZoom.slider',
  26818. layoutMode: 'box',
  26819. /**
  26820. * @protected
  26821. */
  26822. defaultOption: {
  26823. show: true,
  26824. // ph => placeholder. Using placehoder here because
  26825. // deault value can only be drived in view stage.
  26826. right: 'ph', // Default align to grid rect.
  26827. top: 'ph', // Default align to grid rect.
  26828. width: 'ph', // Default align to grid rect.
  26829. height: 'ph', // Default align to grid rect.
  26830. left: null, // Default align to grid rect.
  26831. bottom: null, // Default align to grid rect.
  26832. backgroundColor: 'rgba(47,69,84,0)', // Background of slider zoom component.
  26833. dataBackgroundColor: '#ddd', // Background of data shadow.
  26834. fillerColor: 'rgba(47,69,84,0.15)', // Color of selected area.
  26835. handleColor: 'rgba(148,164,165,0.95)', // Color of handle.
  26836. handleSize: 10,
  26837. labelPrecision: null,
  26838. labelFormatter: null,
  26839. showDetail: true,
  26840. showDataShadow: 'auto', // Default auto decision.
  26841. realtime: true,
  26842. zoomLock: false, // Whether disable zoom.
  26843. textStyle: {
  26844. color: '#333'
  26845. }
  26846. },
  26847. /**
  26848. * @override
  26849. */
  26850. mergeOption: function (option) {
  26851. SliderZoomModel.superApply(this, 'mergeOption', arguments);
  26852. }
  26853. });
  26854. module.exports = SliderZoomModel;
  26855. /***/ },
  26856. /* 296 */
  26857. /***/ function(module, exports, __webpack_require__) {
  26858. var zrUtil = __webpack_require__(3);
  26859. var graphic = __webpack_require__(42);
  26860. var throttle = __webpack_require__(297);
  26861. var DataZoomView = __webpack_require__(294);
  26862. var Rect = graphic.Rect;
  26863. var numberUtil = __webpack_require__(7);
  26864. var linearMap = numberUtil.linearMap;
  26865. var layout = __webpack_require__(21);
  26866. var sliderMove = __webpack_require__(298);
  26867. var asc = numberUtil.asc;
  26868. var bind = zrUtil.bind;
  26869. var mathRound = Math.round;
  26870. var mathMax = Math.max;
  26871. var each = zrUtil.each;
  26872. // Constants
  26873. var DEFAULT_LOCATION_EDGE_GAP = 7;
  26874. var DEFAULT_FRAME_BORDER_WIDTH = 1;
  26875. var DEFAULT_FILLER_SIZE = 30;
  26876. var HORIZONTAL = 'horizontal';
  26877. var VERTICAL = 'vertical';
  26878. var LABEL_GAP = 5;
  26879. var SHOW_DATA_SHADOW_SERIES_TYPE = ['line', 'bar', 'candlestick', 'scatter'];
  26880. var SliderZoomView = DataZoomView.extend({
  26881. type: 'dataZoom.slider',
  26882. init: function (ecModel, api) {
  26883. /**
  26884. * @private
  26885. * @type {Object}
  26886. */
  26887. this._displayables = {};
  26888. /**
  26889. * @private
  26890. * @type {string}
  26891. */
  26892. this._orient;
  26893. /**
  26894. * [0, 100]
  26895. * @private
  26896. */
  26897. this._range;
  26898. /**
  26899. * [coord of the first handle, coord of the second handle]
  26900. * @private
  26901. */
  26902. this._handleEnds;
  26903. /**
  26904. * [length, thick]
  26905. * @private
  26906. * @type {Array.<number>}
  26907. */
  26908. this._size;
  26909. /**
  26910. * @private
  26911. * @type {number}
  26912. */
  26913. this._halfHandleSize;
  26914. /**
  26915. * @private
  26916. */
  26917. this._location;
  26918. /**
  26919. * @private
  26920. */
  26921. this._dragging;
  26922. /**
  26923. * @private
  26924. */
  26925. this._dataShadowInfo;
  26926. this.api = api;
  26927. },
  26928. /**
  26929. * @override
  26930. */
  26931. render: function (dataZoomModel, ecModel, api, payload) {
  26932. SliderZoomView.superApply(this, 'render', arguments);
  26933. throttle.createOrUpdate(
  26934. this,
  26935. '_dispatchZoomAction',
  26936. this.dataZoomModel.get('throttle'),
  26937. 'fixRate'
  26938. );
  26939. this._orient = dataZoomModel.get('orient');
  26940. this._halfHandleSize = mathRound(dataZoomModel.get('handleSize') / 2);
  26941. if (this.dataZoomModel.get('show') === false) {
  26942. this.group.removeAll();
  26943. return;
  26944. }
  26945. // Notice: this._resetInterval() should not be executed when payload.type
  26946. // is 'dataZoom', origin this._range should be maintained, otherwise 'pan'
  26947. // or 'zoom' info will be missed because of 'throttle' of this.dispatchAction,
  26948. if (!payload || payload.type !== 'dataZoom' || payload.from !== this.uid) {
  26949. this._buildView();
  26950. }
  26951. this._updateView();
  26952. },
  26953. /**
  26954. * @override
  26955. */
  26956. remove: function () {
  26957. SliderZoomView.superApply(this, 'remove', arguments);
  26958. throttle.clear(this, '_dispatchZoomAction');
  26959. },
  26960. /**
  26961. * @override
  26962. */
  26963. dispose: function () {
  26964. SliderZoomView.superApply(this, 'dispose', arguments);
  26965. throttle.clear(this, '_dispatchZoomAction');
  26966. },
  26967. _buildView: function () {
  26968. var thisGroup = this.group;
  26969. thisGroup.removeAll();
  26970. this._resetLocation();
  26971. this._resetInterval();
  26972. var barGroup = this._displayables.barGroup = new graphic.Group();
  26973. this._renderBackground();
  26974. this._renderDataShadow();
  26975. this._renderHandle();
  26976. thisGroup.add(barGroup);
  26977. this._positionGroup();
  26978. },
  26979. /**
  26980. * @private
  26981. */
  26982. _resetLocation: function () {
  26983. var dataZoomModel = this.dataZoomModel;
  26984. var api = this.api;
  26985. // If some of x/y/width/height are not specified,
  26986. // auto-adapt according to target grid.
  26987. var coordRect = this._findCoordRect();
  26988. var ecSize = {width: api.getWidth(), height: api.getHeight()};
  26989. // Default align by coordinate system rect.
  26990. var positionInfo = this._orient === HORIZONTAL
  26991. ? {
  26992. // Why using 'right', because right should be used in vertical,
  26993. // and it is better to be consistent for dealing with position param merge.
  26994. right: ecSize.width - coordRect.x - coordRect.width,
  26995. top: (ecSize.height - DEFAULT_FILLER_SIZE - DEFAULT_LOCATION_EDGE_GAP),
  26996. width: coordRect.width,
  26997. height: DEFAULT_FILLER_SIZE
  26998. }
  26999. : { // vertical
  27000. right: DEFAULT_LOCATION_EDGE_GAP,
  27001. top: coordRect.y,
  27002. width: DEFAULT_FILLER_SIZE,
  27003. height: coordRect.height
  27004. };
  27005. // Do not write back to option and replace value 'ph', because
  27006. // the 'ph' value should be recalculated when resize.
  27007. var layoutParams = layout.getLayoutParams(dataZoomModel.option);
  27008. // Replace the placeholder value.
  27009. zrUtil.each(['right', 'top', 'width', 'height'], function (name) {
  27010. if (layoutParams[name] === 'ph') {
  27011. layoutParams[name] = positionInfo[name];
  27012. }
  27013. });
  27014. var layoutRect = layout.getLayoutRect(
  27015. layoutParams,
  27016. ecSize,
  27017. dataZoomModel.padding
  27018. );
  27019. this._location = {x: layoutRect.x, y: layoutRect.y};
  27020. this._size = [layoutRect.width, layoutRect.height];
  27021. this._orient === VERTICAL && this._size.reverse();
  27022. },
  27023. /**
  27024. * @private
  27025. */
  27026. _positionGroup: function () {
  27027. var thisGroup = this.group;
  27028. var location = this._location;
  27029. var orient = this._orient;
  27030. // Just use the first axis to determine mapping.
  27031. var targetAxisModel = this.dataZoomModel.getFirstTargetAxisModel();
  27032. var inverse = targetAxisModel && targetAxisModel.get('inverse');
  27033. var barGroup = this._displayables.barGroup;
  27034. var otherAxisInverse = (this._dataShadowInfo || {}).otherAxisInverse;
  27035. // Transform barGroup.
  27036. barGroup.attr(
  27037. (orient === HORIZONTAL && !inverse)
  27038. ? {scale: otherAxisInverse ? [1, 1] : [1, -1]}
  27039. : (orient === HORIZONTAL && inverse)
  27040. ? {scale: otherAxisInverse ? [-1, 1] : [-1, -1]}
  27041. : (orient === VERTICAL && !inverse)
  27042. ? {scale: otherAxisInverse ? [1, -1] : [1, 1], rotation: Math.PI / 2}
  27043. // Dont use Math.PI, considering shadow direction.
  27044. : {scale: otherAxisInverse ? [-1, -1] : [-1, 1], rotation: Math.PI / 2}
  27045. );
  27046. // Position barGroup
  27047. var rect = thisGroup.getBoundingRect([barGroup]);
  27048. thisGroup.position[0] = location.x - rect.x;
  27049. thisGroup.position[1] = location.y - rect.y;
  27050. },
  27051. /**
  27052. * @private
  27053. */
  27054. _getViewExtent: function () {
  27055. // View total length.
  27056. var halfHandleSize = this._halfHandleSize;
  27057. var totalLength = mathMax(this._size[0], halfHandleSize * 4);
  27058. var extent = [halfHandleSize, totalLength - halfHandleSize];
  27059. return extent;
  27060. },
  27061. _renderBackground : function () {
  27062. var dataZoomModel = this.dataZoomModel;
  27063. var size = this._size;
  27064. this._displayables.barGroup.add(new Rect({
  27065. silent: true,
  27066. shape: {
  27067. x: 0, y: 0, width: size[0], height: size[1]
  27068. },
  27069. style: {
  27070. fill: dataZoomModel.get('backgroundColor')
  27071. }
  27072. }));
  27073. },
  27074. _renderDataShadow: function () {
  27075. var info = this._dataShadowInfo = this._prepareDataShadowInfo();
  27076. if (!info) {
  27077. return;
  27078. }
  27079. var size = this._size;
  27080. var seriesModel = info.series;
  27081. var data = seriesModel.getRawData();
  27082. var otherDim = seriesModel.getShadowDim
  27083. ? seriesModel.getShadowDim() // @see candlestick
  27084. : info.otherDim;
  27085. var otherDataExtent = data.getDataExtent(otherDim);
  27086. // Nice extent.
  27087. var otherOffset = (otherDataExtent[1] - otherDataExtent[0]) * 0.3;
  27088. otherDataExtent = [
  27089. otherDataExtent[0] - otherOffset,
  27090. otherDataExtent[1] + otherOffset
  27091. ];
  27092. var otherShadowExtent = [0, size[1]];
  27093. var thisShadowExtent = [0, size[0]];
  27094. var points = [[size[0], 0], [0, 0]];
  27095. var step = thisShadowExtent[1] / (data.count() - 1);
  27096. var thisCoord = 0;
  27097. // Optimize for large data shadow
  27098. var stride = Math.round(data.count() / size[0]);
  27099. data.each([otherDim], function (value, index) {
  27100. if (stride > 0 && (index % stride)) {
  27101. thisCoord += step;
  27102. return;
  27103. }
  27104. // FIXME
  27105. // 应该使用统计的空判断?还是在list里进行空判断?
  27106. var otherCoord = (value == null || isNaN(value) || value === '')
  27107. ? null
  27108. : linearMap(value, otherDataExtent, otherShadowExtent, true);
  27109. otherCoord != null && points.push([thisCoord, otherCoord]);
  27110. thisCoord += step;
  27111. });
  27112. this._displayables.barGroup.add(new graphic.Polyline({
  27113. shape: {points: points},
  27114. style: {fill: this.dataZoomModel.get('dataBackgroundColor'), lineWidth: 0},
  27115. silent: true,
  27116. z2: -20
  27117. }));
  27118. },
  27119. _prepareDataShadowInfo: function () {
  27120. var dataZoomModel = this.dataZoomModel;
  27121. var showDataShadow = dataZoomModel.get('showDataShadow');
  27122. if (showDataShadow === false) {
  27123. return;
  27124. }
  27125. // Find a representative series.
  27126. var result;
  27127. var ecModel = this.ecModel;
  27128. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex) {
  27129. var seriesModels = dataZoomModel
  27130. .getAxisProxy(dimNames.name, axisIndex)
  27131. .getTargetSeriesModels();
  27132. zrUtil.each(seriesModels, function (seriesModel) {
  27133. if (result) {
  27134. return;
  27135. }
  27136. if (showDataShadow !== true && zrUtil.indexOf(
  27137. SHOW_DATA_SHADOW_SERIES_TYPE, seriesModel.get('type')
  27138. ) < 0
  27139. ) {
  27140. return;
  27141. }
  27142. var otherDim = getOtherDim(dimNames.name);
  27143. var thisAxis = ecModel.getComponent(dimNames.axis, axisIndex).axis;
  27144. result = {
  27145. thisAxis: thisAxis,
  27146. series: seriesModel,
  27147. thisDim: dimNames.name,
  27148. otherDim: otherDim,
  27149. otherAxisInverse: seriesModel
  27150. .coordinateSystem.getOtherAxis(thisAxis).inverse
  27151. };
  27152. }, this);
  27153. }, this);
  27154. return result;
  27155. },
  27156. _renderHandle: function () {
  27157. var displaybles = this._displayables;
  27158. var handles = displaybles.handles = [];
  27159. var handleLabels = displaybles.handleLabels = [];
  27160. var barGroup = this._displayables.barGroup;
  27161. var size = this._size;
  27162. barGroup.add(displaybles.filler = new Rect({
  27163. draggable: true,
  27164. cursor: 'move',
  27165. drift: bind(this._onDragMove, this, 'all'),
  27166. ondragend: bind(this._onDragEnd, this),
  27167. onmouseover: bind(this._showDataInfo, this, true),
  27168. onmouseout: bind(this._showDataInfo, this, false),
  27169. style: {
  27170. fill: this.dataZoomModel.get('fillerColor'),
  27171. // text: ':::',
  27172. textPosition : 'inside'
  27173. }
  27174. }));
  27175. // Frame border.
  27176. barGroup.add(new Rect(graphic.subPixelOptimizeRect({
  27177. silent: true,
  27178. shape: {
  27179. x: 0,
  27180. y: 0,
  27181. width: size[0],
  27182. height: size[1]
  27183. },
  27184. style: {
  27185. stroke: this.dataZoomModel.get('dataBackgroundColor'),
  27186. lineWidth: DEFAULT_FRAME_BORDER_WIDTH,
  27187. fill: 'rgba(0,0,0,0)'
  27188. }
  27189. })));
  27190. each([0, 1], function (handleIndex) {
  27191. barGroup.add(handles[handleIndex] = new Rect({
  27192. style: {
  27193. fill: this.dataZoomModel.get('handleColor')
  27194. },
  27195. cursor: 'move',
  27196. draggable: true,
  27197. drift: bind(this._onDragMove, this, handleIndex),
  27198. ondragend: bind(this._onDragEnd, this),
  27199. onmouseover: bind(this._showDataInfo, this, true),
  27200. onmouseout: bind(this._showDataInfo, this, false)
  27201. }));
  27202. var textStyleModel = this.dataZoomModel.textStyleModel;
  27203. this.group.add(
  27204. handleLabels[handleIndex] = new graphic.Text({
  27205. silent: true,
  27206. invisible: true,
  27207. style: {
  27208. x: 0, y: 0, text: '',
  27209. textVerticalAlign: 'middle',
  27210. textAlign: 'center',
  27211. fill: textStyleModel.getTextColor(),
  27212. textFont: textStyleModel.getFont()
  27213. }
  27214. }));
  27215. }, this);
  27216. },
  27217. /**
  27218. * @private
  27219. */
  27220. _resetInterval: function () {
  27221. var range = this._range = this.dataZoomModel.getPercentRange();
  27222. var viewExtent = this._getViewExtent();
  27223. this._handleEnds = [
  27224. linearMap(range[0], [0, 100], viewExtent, true),
  27225. linearMap(range[1], [0, 100], viewExtent, true)
  27226. ];
  27227. },
  27228. /**
  27229. * @private
  27230. * @param {(number|string)} handleIndex 0 or 1 or 'all'
  27231. * @param {number} dx
  27232. * @param {number} dy
  27233. */
  27234. _updateInterval: function (handleIndex, delta) {
  27235. var handleEnds = this._handleEnds;
  27236. var viewExtend = this._getViewExtent();
  27237. sliderMove(
  27238. delta,
  27239. handleEnds,
  27240. viewExtend,
  27241. (handleIndex === 'all' || this.dataZoomModel.get('zoomLock'))
  27242. ? 'rigid' : 'cross',
  27243. handleIndex
  27244. );
  27245. this._range = asc([
  27246. linearMap(handleEnds[0], viewExtend, [0, 100], true),
  27247. linearMap(handleEnds[1], viewExtend, [0, 100], true)
  27248. ]);
  27249. },
  27250. /**
  27251. * @private
  27252. */
  27253. _updateView: function () {
  27254. var displaybles = this._displayables;
  27255. var handleEnds = this._handleEnds;
  27256. var handleInterval = asc(handleEnds.slice());
  27257. var size = this._size;
  27258. var halfHandleSize = this._halfHandleSize;
  27259. each([0, 1], function (handleIndex) {
  27260. // Handles
  27261. var handle = displaybles.handles[handleIndex];
  27262. handle.setShape({
  27263. x: handleEnds[handleIndex] - halfHandleSize,
  27264. y: -1,
  27265. width: halfHandleSize * 2,
  27266. height: size[1] + 2,
  27267. r: 1
  27268. });
  27269. }, this);
  27270. // Filler
  27271. displaybles.filler.setShape({
  27272. x: handleInterval[0],
  27273. y: 0,
  27274. width: handleInterval[1] - handleInterval[0],
  27275. height: this._size[1]
  27276. });
  27277. this._updateDataInfo();
  27278. },
  27279. /**
  27280. * @private
  27281. */
  27282. _updateDataInfo: function () {
  27283. var dataZoomModel = this.dataZoomModel;
  27284. var displaybles = this._displayables;
  27285. var handleLabels = displaybles.handleLabels;
  27286. var orient = this._orient;
  27287. var labelTexts = ['', ''];
  27288. // FIXME
  27289. // date型,支持formatter,autoformatter(ec2 date.getAutoFormatter)
  27290. if (dataZoomModel.get('showDetail')) {
  27291. var dataInterval;
  27292. var axis;
  27293. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex) {
  27294. // Using dataInterval of the first axis.
  27295. if (!dataInterval) {
  27296. dataInterval = dataZoomModel
  27297. .getAxisProxy(dimNames.name, axisIndex)
  27298. .getDataValueWindow();
  27299. axis = this.ecModel.getComponent(dimNames.axis, axisIndex).axis;
  27300. }
  27301. }, this);
  27302. if (dataInterval) {
  27303. labelTexts = [
  27304. this._formatLabel(dataInterval[0], axis),
  27305. this._formatLabel(dataInterval[1], axis)
  27306. ];
  27307. }
  27308. }
  27309. var orderedHandleEnds = asc(this._handleEnds.slice());
  27310. setLabel.call(this, 0);
  27311. setLabel.call(this, 1);
  27312. function setLabel(handleIndex) {
  27313. // Label
  27314. // Text should not transform by barGroup.
  27315. var barTransform = graphic.getTransform(
  27316. displaybles.handles[handleIndex], this.group
  27317. );
  27318. var direction = graphic.transformDirection(
  27319. handleIndex === 0 ? 'right' : 'left', barTransform
  27320. );
  27321. var offset = this._halfHandleSize + LABEL_GAP;
  27322. var textPoint = graphic.applyTransform(
  27323. [
  27324. orderedHandleEnds[handleIndex] + (handleIndex === 0 ? -offset : offset),
  27325. this._size[1] / 2
  27326. ],
  27327. barTransform
  27328. );
  27329. handleLabels[handleIndex].setStyle({
  27330. x: textPoint[0],
  27331. y: textPoint[1],
  27332. textVerticalAlign: orient === HORIZONTAL ? 'middle' : direction,
  27333. textAlign: orient === HORIZONTAL ? direction : 'center',
  27334. text: labelTexts[handleIndex]
  27335. });
  27336. }
  27337. },
  27338. /**
  27339. * @private
  27340. */
  27341. _formatLabel: function (value, axis) {
  27342. var dataZoomModel = this.dataZoomModel;
  27343. var labelFormatter = dataZoomModel.get('labelFormatter');
  27344. if (zrUtil.isFunction(labelFormatter)) {
  27345. return labelFormatter(value);
  27346. }
  27347. var labelPrecision = dataZoomModel.get('labelPrecision');
  27348. if (labelPrecision == null || labelPrecision === 'auto') {
  27349. labelPrecision = axis.getPixelPrecision();
  27350. }
  27351. value = (value == null && isNaN(value))
  27352. ? ''
  27353. // FIXME Glue code
  27354. : (axis.type === 'category' || axis.type === 'time')
  27355. ? axis.scale.getLabel(Math.round(value))
  27356. // param of toFixed should less then 20.
  27357. : value.toFixed(Math.min(labelPrecision, 20));
  27358. if (zrUtil.isString(labelFormatter)) {
  27359. value = labelFormatter.replace('{value}', value);
  27360. }
  27361. return value;
  27362. },
  27363. /**
  27364. * @private
  27365. * @param {boolean} showOrHide true: show, false: hide
  27366. */
  27367. _showDataInfo: function (showOrHide) {
  27368. // Always show when drgging.
  27369. showOrHide = this._dragging || showOrHide;
  27370. var handleLabels = this._displayables.handleLabels;
  27371. handleLabels[0].attr('invisible', !showOrHide);
  27372. handleLabels[1].attr('invisible', !showOrHide);
  27373. },
  27374. _onDragMove: function (handleIndex, dx, dy) {
  27375. this._dragging = true;
  27376. // Transform dx, dy to bar coordination.
  27377. var vertex = this._applyBarTransform([dx, dy], true);
  27378. this._updateInterval(handleIndex, vertex[0]);
  27379. this._updateView();
  27380. if (this.dataZoomModel.get('realtime')) {
  27381. this._dispatchZoomAction();
  27382. }
  27383. },
  27384. _onDragEnd: function () {
  27385. this._dragging = false;
  27386. this._showDataInfo(false);
  27387. this._dispatchZoomAction();
  27388. },
  27389. /**
  27390. * This action will be throttled.
  27391. * @private
  27392. */
  27393. _dispatchZoomAction: function () {
  27394. var range = this._range;
  27395. this.api.dispatchAction({
  27396. type: 'dataZoom',
  27397. from: this.uid,
  27398. dataZoomId: this.dataZoomModel.id,
  27399. start: range[0],
  27400. end: range[1]
  27401. });
  27402. },
  27403. /**
  27404. * @private
  27405. */
  27406. _applyBarTransform: function (vertex, inverse) {
  27407. var barTransform = this._displayables.barGroup.getLocalTransform();
  27408. return graphic.applyTransform(vertex, barTransform, inverse);
  27409. },
  27410. /**
  27411. * @private
  27412. */
  27413. _findCoordRect: function () {
  27414. // Find the grid coresponding to the first axis referred by dataZoom.
  27415. var targetInfo = this.getTargetInfo();
  27416. // FIXME
  27417. // 判断是catesian还是polar
  27418. var rect;
  27419. if (targetInfo.cartesians.length) {
  27420. rect = targetInfo.cartesians[0].model.coordinateSystem.getRect();
  27421. }
  27422. else { // Polar
  27423. // FIXME
  27424. // 暂时随便写的
  27425. var width = this.api.getWidth();
  27426. var height = this.api.getHeight();
  27427. rect = {
  27428. x: width * 0.2,
  27429. y: height * 0.2,
  27430. width: width * 0.6,
  27431. height: height * 0.6
  27432. };
  27433. }
  27434. return rect;
  27435. }
  27436. });
  27437. function getOtherDim(thisDim) {
  27438. // FIXME
  27439. // 这个逻辑和getOtherAxis里一致,但是写在这里是否不好
  27440. return thisDim === 'x' ? 'y' : 'x';
  27441. }
  27442. module.exports = SliderZoomView;
  27443. /***/ },
  27444. /* 297 */
  27445. /***/ function(module, exports) {
  27446. var lib = {};
  27447. var ORIGIN_METHOD = '\0__throttleOriginMethod';
  27448. var RATE = '\0__throttleRate';
  27449. /**
  27450. * 频率控制 返回函数连续调用时,fn 执行频率限定为每多少时间执行一次
  27451. * 例如常见效果:
  27452. * notifyWhenChangesStop
  27453. * 频繁调用时,只保证最后一次执行
  27454. * 配成:trailing:true;debounce:true 即可
  27455. * notifyAtFixRate
  27456. * 频繁调用时,按规律心跳执行
  27457. * 配成:trailing:true;debounce:false 即可
  27458. * 注意:
  27459. * 根据model更新view的时候,可以使用throttle,
  27460. * 但是根据view更新model的时候,避免使用这种延迟更新的方式。
  27461. * 因为这可能导致model和server同步出现问题。
  27462. *
  27463. * @public
  27464. * @param {(Function|Array.<Function>)} fn 需要调用的函数
  27465. * 如果fn为array,则表示可以对多个函数进行throttle。
  27466. * 他们共享同一个timer。
  27467. * @param {number} delay 延迟时间,单位毫秒
  27468. * @param {bool} trailing 是否保证最后一次触发的执行
  27469. * true:表示保证最后一次调用会触发执行。
  27470. * 但任何调用后不可能立即执行,总会delay。
  27471. * false:表示不保证最后一次调用会触发执行。
  27472. * 但只要间隔大于delay,调用就会立即执行。
  27473. * @param {bool} debounce 节流
  27474. * true:表示:频繁调用(间隔小于delay)时,根本不执行
  27475. * false:表示:频繁调用(间隔小于delay)时,按规律心跳执行
  27476. * @return {(Function|Array.<Function>)} 实际调用函数。
  27477. * 当输入的fn为array时,返回值也为array。
  27478. * 每项是Function。
  27479. */
  27480. lib.throttle = function (fn, delay, trailing, debounce) {
  27481. var currCall = (new Date()).getTime();
  27482. var lastCall = 0;
  27483. var lastExec = 0;
  27484. var timer = null;
  27485. var diff;
  27486. var scope;
  27487. var args;
  27488. var isSingle = typeof fn === 'function';
  27489. delay = delay || 0;
  27490. if (isSingle) {
  27491. return createCallback();
  27492. }
  27493. else {
  27494. var ret = [];
  27495. for (var i = 0; i < fn.length; i++) {
  27496. ret[i] = createCallback(i);
  27497. }
  27498. return ret;
  27499. }
  27500. function createCallback(index) {
  27501. function exec() {
  27502. lastExec = (new Date()).getTime();
  27503. timer = null;
  27504. (isSingle ? fn : fn[index]).apply(scope, args || []);
  27505. }
  27506. var cb = function () {
  27507. currCall = (new Date()).getTime();
  27508. scope = this;
  27509. args = arguments;
  27510. diff = currCall - (debounce ? lastCall : lastExec) - delay;
  27511. clearTimeout(timer);
  27512. if (debounce) {
  27513. if (trailing) {
  27514. timer = setTimeout(exec, delay);
  27515. }
  27516. else if (diff >= 0) {
  27517. exec();
  27518. }
  27519. }
  27520. else {
  27521. if (diff >= 0) {
  27522. exec();
  27523. }
  27524. else if (trailing) {
  27525. timer = setTimeout(exec, -diff);
  27526. }
  27527. }
  27528. lastCall = currCall;
  27529. };
  27530. /**
  27531. * Clear throttle.
  27532. * @public
  27533. */
  27534. cb.clear = function () {
  27535. if (timer) {
  27536. clearTimeout(timer);
  27537. timer = null;
  27538. }
  27539. };
  27540. return cb;
  27541. }
  27542. };
  27543. /**
  27544. * 按一定频率执行,最后一次调用总归会执行
  27545. *
  27546. * @public
  27547. */
  27548. lib.fixRate = function (fn, delay) {
  27549. return delay != null
  27550. ? lib.throttle(fn, delay, true, false)
  27551. : fn;
  27552. };
  27553. /**
  27554. * 直到不频繁调用了才会执行,最后一次调用总归会执行
  27555. *
  27556. * @public
  27557. */
  27558. lib.debounce = function (fn, delay) {
  27559. return delay != null
  27560. ? lib.throttle(fn, delay, true, true)
  27561. : fn;
  27562. };
  27563. /**
  27564. * Create throttle method or update throttle rate.
  27565. *
  27566. * @example
  27567. * ComponentView.prototype.render = function () {
  27568. * ...
  27569. * throttle.createOrUpdate(
  27570. * this,
  27571. * '_dispatchAction',
  27572. * this.model.get('throttle'),
  27573. * 'fixRate'
  27574. * );
  27575. * };
  27576. * ComponentView.prototype.remove = function () {
  27577. * throttle.clear(this, '_dispatchAction');
  27578. * };
  27579. * ComponentView.prototype.dispose = function () {
  27580. * throttle.clear(this, '_dispatchAction');
  27581. * };
  27582. *
  27583. * @public
  27584. * @param {Object} obj
  27585. * @param {string} fnAttr
  27586. * @param {number} rate
  27587. * @param {string} throttleType 'fixRate' or 'debounce'
  27588. */
  27589. lib.createOrUpdate = function (obj, fnAttr, rate, throttleType) {
  27590. var fn = obj[fnAttr];
  27591. if (!fn || rate == null || !throttleType) {
  27592. return;
  27593. }
  27594. var originFn = fn[ORIGIN_METHOD] || fn;
  27595. var lastRate = fn[RATE];
  27596. if (lastRate !== rate) {
  27597. fn = obj[fnAttr] = lib[throttleType](originFn, rate);
  27598. fn[ORIGIN_METHOD] = originFn;
  27599. fn[RATE] = rate;
  27600. }
  27601. };
  27602. /**
  27603. * Clear throttle. Example see throttle.createOrUpdate.
  27604. *
  27605. * @public
  27606. * @param {Object} obj
  27607. * @param {string} fnAttr
  27608. */
  27609. lib.clear = function (obj, fnAttr) {
  27610. var fn = obj[fnAttr];
  27611. if (fn && fn[ORIGIN_METHOD]) {
  27612. obj[fnAttr] = fn[ORIGIN_METHOD];
  27613. }
  27614. };
  27615. module.exports = lib;
  27616. /***/ },
  27617. /* 298 */
  27618. /***/ function(module, exports) {
  27619. /**
  27620. * Calculate slider move result.
  27621. *
  27622. * @param {number} delta Move length.
  27623. * @param {Array.<number>} handleEnds handleEnds[0] and be bigger then handleEnds[1].
  27624. * handleEnds will be modified in this method.
  27625. * @param {Array.<number>} extent handleEnds is restricted by extent.
  27626. * extent[0] should less or equals than extent[1].
  27627. * @param {string} mode 'rigid': Math.abs(handleEnds[0] - handleEnds[1]) remain unchanged,
  27628. * 'cross' handleEnds[0] can be bigger then handleEnds[1],
  27629. * 'push' handleEnds[0] can not be bigger then handleEnds[1],
  27630. * when they touch, one push other.
  27631. * @param {number} handleIndex If mode is 'rigid', handleIndex is not required.
  27632. * @param {Array.<number>} The input handleEnds.
  27633. */
  27634. module.exports = function (delta, handleEnds, extent, mode, handleIndex) {
  27635. if (!delta) {
  27636. return handleEnds;
  27637. }
  27638. if (mode === 'rigid') {
  27639. delta = getRealDelta(delta, handleEnds, extent);
  27640. handleEnds[0] += delta;
  27641. handleEnds[1] += delta;
  27642. }
  27643. else {
  27644. delta = getRealDelta(delta, handleEnds[handleIndex], extent);
  27645. handleEnds[handleIndex] += delta;
  27646. if (mode === 'push' && handleEnds[0] > handleEnds[1]) {
  27647. handleEnds[1 - handleIndex] = handleEnds[handleIndex];
  27648. }
  27649. }
  27650. return handleEnds;
  27651. function getRealDelta(delta, handleEnds, extent) {
  27652. var handleMinMax = !handleEnds.length
  27653. ? [handleEnds, handleEnds]
  27654. : handleEnds.slice();
  27655. handleEnds[0] > handleEnds[1] && handleMinMax.reverse();
  27656. if (delta < 0 && handleMinMax[0] + delta < extent[0]) {
  27657. delta = extent[0] - handleMinMax[0];
  27658. }
  27659. if (delta > 0 && handleMinMax[1] + delta > extent[1]) {
  27660. delta = extent[1] - handleMinMax[1];
  27661. }
  27662. return delta;
  27663. }
  27664. };
  27665. /***/ },
  27666. /* 299 */
  27667. /***/ function(module, exports, __webpack_require__) {
  27668. /**
  27669. * @file Data zoom model
  27670. */
  27671. module.exports = __webpack_require__(292).extend({
  27672. type: 'dataZoom.inside',
  27673. /**
  27674. * @protected
  27675. */
  27676. defaultOption: {
  27677. zoomLock: false // Whether disable zoom but only pan.
  27678. }
  27679. });
  27680. /***/ },
  27681. /* 300 */
  27682. /***/ function(module, exports, __webpack_require__) {
  27683. var DataZoomView = __webpack_require__(294);
  27684. var zrUtil = __webpack_require__(3);
  27685. var sliderMove = __webpack_require__(298);
  27686. var roams = __webpack_require__(301);
  27687. var bind = zrUtil.bind;
  27688. var InsideZoomView = DataZoomView.extend({
  27689. type: 'dataZoom.inside',
  27690. /**
  27691. * @override
  27692. */
  27693. init: function (ecModel, api) {
  27694. /**
  27695. * 'throttle' is used in this.dispatchAction, so we save range
  27696. * to avoid missing some 'pan' info.
  27697. * @private
  27698. * @type {Array.<number>}
  27699. */
  27700. this._range;
  27701. },
  27702. /**
  27703. * @override
  27704. */
  27705. render: function (dataZoomModel, ecModel, api, payload) {
  27706. InsideZoomView.superApply(this, 'render', arguments);
  27707. // Notice: origin this._range should be maintained, and should not be re-fetched
  27708. // from dataZoomModel when payload.type is 'dataZoom', otherwise 'pan' or 'zoom'
  27709. // info will be missed because of 'throttle' of this.dispatchAction.
  27710. if (roams.shouldRecordRange(payload, dataZoomModel.id)) {
  27711. this._range = dataZoomModel.getPercentRange();
  27712. }
  27713. // Reset controllers.
  27714. var coordInfoList = this.getTargetInfo().cartesians;
  27715. var allCoordIds = zrUtil.map(coordInfoList, function (coordInfo) {
  27716. return roams.generateCoordId(coordInfo.model);
  27717. });
  27718. zrUtil.each(coordInfoList, function (coordInfo) {
  27719. var coordModel = coordInfo.model;
  27720. roams.register(
  27721. api,
  27722. {
  27723. coordId: roams.generateCoordId(coordModel),
  27724. allCoordIds: allCoordIds,
  27725. coordinateSystem: coordModel.coordinateSystem,
  27726. dataZoomId: dataZoomModel.id,
  27727. throttleRage: dataZoomModel.get('throttle', true),
  27728. panGetRange: bind(this._onPan, this, coordInfo),
  27729. zoomGetRange: bind(this._onZoom, this, coordInfo)
  27730. }
  27731. );
  27732. }, this);
  27733. // TODO
  27734. // polar支持
  27735. },
  27736. /**
  27737. * @override
  27738. */
  27739. remove: function () {
  27740. roams.unregister(this.api, this.dataZoomModel.id);
  27741. InsideZoomView.superApply(this, 'remove', arguments);
  27742. this._range = null;
  27743. },
  27744. /**
  27745. * @override
  27746. */
  27747. dispose: function () {
  27748. roams.unregister(this.api, this.dataZoomModel.id);
  27749. InsideZoomView.superApply(this, 'dispose', arguments);
  27750. this._range = null;
  27751. },
  27752. /**
  27753. * @private
  27754. */
  27755. _onPan: function (coordInfo, controller, dx, dy) {
  27756. return (
  27757. this._range = panCartesian(
  27758. [dx, dy], this._range, controller, coordInfo
  27759. )
  27760. );
  27761. },
  27762. /**
  27763. * @private
  27764. */
  27765. _onZoom: function (coordInfo, controller, scale, mouseX, mouseY) {
  27766. var dataZoomModel = this.dataZoomModel;
  27767. if (dataZoomModel.option.zoomLock) {
  27768. return this._range;
  27769. }
  27770. return (
  27771. this._range = scaleCartesian(
  27772. 1 / scale, [mouseX, mouseY], this._range,
  27773. controller, coordInfo, dataZoomModel
  27774. )
  27775. );
  27776. }
  27777. });
  27778. function panCartesian(pixelDeltas, range, controller, coordInfo) {
  27779. range = range.slice();
  27780. // Calculate transform by the first axis.
  27781. var axisModel = coordInfo.axisModels[0];
  27782. if (!axisModel) {
  27783. return;
  27784. }
  27785. var directionInfo = getDirectionInfo(pixelDeltas, axisModel, controller);
  27786. var percentDelta = directionInfo.signal
  27787. * (range[1] - range[0])
  27788. * directionInfo.pixel / directionInfo.pixelLength;
  27789. sliderMove(
  27790. percentDelta,
  27791. range,
  27792. [0, 100],
  27793. 'rigid'
  27794. );
  27795. return range;
  27796. }
  27797. function scaleCartesian(scale, mousePoint, range, controller, coordInfo, dataZoomModel) {
  27798. range = range.slice();
  27799. // Calculate transform by the first axis.
  27800. var axisModel = coordInfo.axisModels[0];
  27801. if (!axisModel) {
  27802. return;
  27803. }
  27804. var directionInfo = getDirectionInfo(mousePoint, axisModel, controller);
  27805. var mouse = directionInfo.pixel - directionInfo.pixelStart;
  27806. var percentPoint = mouse / directionInfo.pixelLength * (range[1] - range[0]) + range[0];
  27807. scale = Math.max(scale, 0);
  27808. range[0] = (range[0] - percentPoint) * scale + percentPoint;
  27809. range[1] = (range[1] - percentPoint) * scale + percentPoint;
  27810. return fixRange(range);
  27811. }
  27812. function getDirectionInfo(xy, axisModel, controller) {
  27813. var axis = axisModel.axis;
  27814. var rect = controller.rectProvider();
  27815. var ret = {};
  27816. if (axis.dim === 'x') {
  27817. ret.pixel = xy[0];
  27818. ret.pixelLength = rect.width;
  27819. ret.pixelStart = rect.x;
  27820. ret.signal = axis.inverse ? 1 : -1;
  27821. }
  27822. else { // axis.dim === 'y'
  27823. ret.pixel = xy[1];
  27824. ret.pixelLength = rect.height;
  27825. ret.pixelStart = rect.y;
  27826. ret.signal = axis.inverse ? -1 : 1;
  27827. }
  27828. return ret;
  27829. }
  27830. function fixRange(range) {
  27831. // Clamp, using !(<= or >=) to handle NaN.
  27832. // jshint ignore:start
  27833. var bound = [0, 100];
  27834. !(range[0] <= bound[1]) && (range[0] = bound[1]);
  27835. !(range[1] <= bound[1]) && (range[1] = bound[1]);
  27836. !(range[0] >= bound[0]) && (range[0] = bound[0]);
  27837. !(range[1] >= bound[0]) && (range[1] = bound[0]);
  27838. // jshint ignore:end
  27839. return range;
  27840. }
  27841. module.exports = InsideZoomView;
  27842. /***/ },
  27843. /* 301 */
  27844. /***/ function(module, exports, __webpack_require__) {
  27845. /**
  27846. * @file Roam controller manager.
  27847. */
  27848. // Only create one roam controller for each coordinate system.
  27849. // one roam controller might be refered by two inside data zoom
  27850. // components (for example, one for x and one for y). When user
  27851. // pan or zoom, only dispatch one action for those data zoom
  27852. // components.
  27853. var zrUtil = __webpack_require__(3);
  27854. var RoamController = __webpack_require__(169);
  27855. var throttle = __webpack_require__(297);
  27856. var curry = zrUtil.curry;
  27857. var ATTR = '\0_ec_dataZoom_roams';
  27858. var roams = {
  27859. /**
  27860. * @public
  27861. * @param {module:echarts/ExtensionAPI} api
  27862. * @param {Object} dataZoomInfo
  27863. * @param {string} dataZoomInfo.coordId
  27864. * @param {Object} dataZoomInfo.coordinateSystem
  27865. * @param {Array.<string>} dataZoomInfo.allCoordIds
  27866. * @param {string} dataZoomInfo.dataZoomId
  27867. * @param {number} dataZoomInfo.throttleRate
  27868. * @param {Function} dataZoomInfo.panGetRange
  27869. * @param {Function} dataZoomInfo.zoomGetRange
  27870. */
  27871. register: function (api, dataZoomInfo) {
  27872. var store = giveStore(api);
  27873. var theDataZoomId = dataZoomInfo.dataZoomId;
  27874. var theCoordId = dataZoomInfo.coordId;
  27875. // Do clean when a dataZoom changes its target coordnate system.
  27876. zrUtil.each(store, function (record, coordId) {
  27877. var dataZoomInfos = record.dataZoomInfos;
  27878. if (dataZoomInfos[theDataZoomId]
  27879. && zrUtil.indexOf(dataZoomInfo.allCoordIds, theCoordId) < 0
  27880. ) {
  27881. delete dataZoomInfos[theDataZoomId];
  27882. record.count--;
  27883. }
  27884. });
  27885. cleanStore(store);
  27886. var record = store[theCoordId];
  27887. // Create if needed.
  27888. if (!record) {
  27889. record = store[theCoordId] = {
  27890. coordId: theCoordId,
  27891. dataZoomInfos: {},
  27892. count: 0
  27893. };
  27894. record.controller = createController(api, dataZoomInfo, record);
  27895. record.dispatchAction = zrUtil.curry(dispatchAction, api);
  27896. }
  27897. // Consider resize, area should be always updated.
  27898. var rect = dataZoomInfo.coordinateSystem.getRect().clone();
  27899. record.controller.rectProvider = function () {
  27900. return rect;
  27901. };
  27902. // Update throttle.
  27903. throttle.createOrUpdate(
  27904. record,
  27905. 'dispatchAction',
  27906. dataZoomInfo.throttleRate,
  27907. 'fixRate'
  27908. );
  27909. // Update reference of dataZoom.
  27910. !(record.dataZoomInfos[theDataZoomId]) && record.count++;
  27911. record.dataZoomInfos[theDataZoomId] = dataZoomInfo;
  27912. },
  27913. /**
  27914. * @public
  27915. * @param {module:echarts/ExtensionAPI} api
  27916. * @param {string} dataZoomId
  27917. */
  27918. unregister: function (api, dataZoomId) {
  27919. var store = giveStore(api);
  27920. zrUtil.each(store, function (record) {
  27921. var dataZoomInfos = record.dataZoomInfos;
  27922. if (dataZoomInfos[dataZoomId]) {
  27923. delete dataZoomInfos[dataZoomId];
  27924. record.count--;
  27925. }
  27926. });
  27927. cleanStore(store);
  27928. },
  27929. /**
  27930. * @public
  27931. */
  27932. shouldRecordRange: function (payload, dataZoomId) {
  27933. if (payload && payload.type === 'dataZoom' && payload.batch) {
  27934. for (var i = 0, len = payload.batch.length; i < len; i++) {
  27935. if (payload.batch[i].dataZoomId === dataZoomId) {
  27936. return false;
  27937. }
  27938. }
  27939. }
  27940. return true;
  27941. },
  27942. /**
  27943. * @public
  27944. */
  27945. generateCoordId: function (coordModel) {
  27946. return coordModel.type + '\0_' + coordModel.id;
  27947. }
  27948. };
  27949. /**
  27950. * Key: coordId, value: {dataZoomInfos: [], count, controller}
  27951. * @type {Array.<Object>}
  27952. */
  27953. function giveStore(api) {
  27954. // Mount store on zrender instance, so that we do not
  27955. // need to worry about dispose.
  27956. var zr = api.getZr();
  27957. return zr[ATTR] || (zr[ATTR] = {});
  27958. }
  27959. function createController(api, dataZoomInfo, newRecord) {
  27960. var controller = new RoamController(api.getZr());
  27961. controller.enable();
  27962. controller.on('pan', curry(onPan, newRecord));
  27963. controller.on('zoom', curry(onZoom, newRecord));
  27964. return controller;
  27965. }
  27966. function cleanStore(store) {
  27967. zrUtil.each(store, function (record, coordId) {
  27968. if (!record.count) {
  27969. record.controller.off('pan').off('zoom');
  27970. delete store[coordId];
  27971. }
  27972. });
  27973. }
  27974. function onPan(record, dx, dy) {
  27975. wrapAndDispatch(record, function (info) {
  27976. return info.panGetRange(record.controller, dx, dy);
  27977. });
  27978. }
  27979. function onZoom(record, scale, mouseX, mouseY) {
  27980. wrapAndDispatch(record, function (info) {
  27981. return info.zoomGetRange(record.controller, scale, mouseX, mouseY);
  27982. });
  27983. }
  27984. function wrapAndDispatch(record, getRange) {
  27985. var batch = [];
  27986. zrUtil.each(record.dataZoomInfos, function (info) {
  27987. var range = getRange(info);
  27988. range && batch.push({
  27989. dataZoomId: info.dataZoomId,
  27990. start: range[0],
  27991. end: range[1]
  27992. });
  27993. });
  27994. record.dispatchAction(batch);
  27995. }
  27996. /**
  27997. * This action will be throttled.
  27998. */
  27999. function dispatchAction(api, batch) {
  28000. api.dispatchAction({
  28001. type: 'dataZoom',
  28002. batch: batch
  28003. });
  28004. }
  28005. module.exports = roams;
  28006. /***/ },
  28007. /* 302 */
  28008. /***/ function(module, exports, __webpack_require__) {
  28009. /**
  28010. * @file Data zoom processor
  28011. */
  28012. var echarts = __webpack_require__(1);
  28013. echarts.registerProcessor('filter', function (ecModel, api) {
  28014. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  28015. // We calculate window and reset axis here but not in model
  28016. // init stage and not after action dispatch handler, because
  28017. // reset should be called after seriesData.restoreData.
  28018. dataZoomModel.eachTargetAxis(resetSingleAxis);
  28019. // Caution: data zoom filtering is order sensitive when using
  28020. // percent range and no min/max/scale set on axis.
  28021. // For example, we have dataZoom definition:
  28022. // [
  28023. // {xAxisIndex: 0, start: 30, end: 70},
  28024. // {yAxisIndex: 0, start: 20, end: 80}
  28025. // ]
  28026. // In this case, [20, 80] of y-dataZoom should be based on data
  28027. // that have filtered by x-dataZoom using range of [30, 70],
  28028. // but should not be based on full raw data. Thus sliding
  28029. // x-dataZoom will change both ranges of xAxis and yAxis,
  28030. // while sliding y-dataZoom will only change the range of yAxis.
  28031. // So we should filter x-axis after reset x-axis immediately,
  28032. // and then reset y-axis and filter y-axis.
  28033. dataZoomModel.eachTargetAxis(filterSingleAxis);
  28034. });
  28035. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  28036. // Fullfill all of the range props so that user
  28037. // is able to get them from chart.getOption().
  28038. var axisProxy = dataZoomModel.findRepresentativeAxisProxy();
  28039. var percentRange = axisProxy.getDataPercentWindow();
  28040. var valueRange = axisProxy.getDataValueWindow();
  28041. dataZoomModel.setRawRange({
  28042. start: percentRange[0],
  28043. end: percentRange[1],
  28044. startValue: valueRange[0],
  28045. endValue: valueRange[1]
  28046. });
  28047. });
  28048. });
  28049. function resetSingleAxis(dimNames, axisIndex, dataZoomModel) {
  28050. dataZoomModel.getAxisProxy(dimNames.name, axisIndex).reset(dataZoomModel);
  28051. }
  28052. function filterSingleAxis(dimNames, axisIndex, dataZoomModel) {
  28053. dataZoomModel.getAxisProxy(dimNames.name, axisIndex).filterData(dataZoomModel);
  28054. }
  28055. /***/ },
  28056. /* 303 */
  28057. /***/ function(module, exports, __webpack_require__) {
  28058. /**
  28059. * @file Data zoom action
  28060. */
  28061. var zrUtil = __webpack_require__(3);
  28062. var modelUtil = __webpack_require__(5);
  28063. var echarts = __webpack_require__(1);
  28064. echarts.registerAction('dataZoom', function (payload, ecModel) {
  28065. var linkedNodesFinder = modelUtil.createLinkedNodesFinder(
  28066. zrUtil.bind(ecModel.eachComponent, ecModel, 'dataZoom'),
  28067. modelUtil.eachAxisDim,
  28068. function (model, dimNames) {
  28069. return model.get(dimNames.axisIndex);
  28070. }
  28071. );
  28072. var effectedModels = [];
  28073. ecModel.eachComponent(
  28074. {mainType: 'dataZoom', query: payload},
  28075. function (model, index) {
  28076. effectedModels.push.apply(
  28077. effectedModels, linkedNodesFinder(model).nodes
  28078. );
  28079. }
  28080. );
  28081. zrUtil.each(effectedModels, function (dataZoomModel, index) {
  28082. dataZoomModel.setRawRange({
  28083. start: payload.start,
  28084. end: payload.end,
  28085. startValue: payload.startValue,
  28086. endValue: payload.endValue
  28087. });
  28088. });
  28089. });
  28090. /***/ },
  28091. /* 304 */,
  28092. /* 305 */,
  28093. /* 306 */,
  28094. /* 307 */,
  28095. /* 308 */,
  28096. /* 309 */,
  28097. /* 310 */,
  28098. /* 311 */,
  28099. /* 312 */,
  28100. /* 313 */,
  28101. /* 314 */,
  28102. /* 315 */,
  28103. /* 316 */,
  28104. /* 317 */,
  28105. /* 318 */,
  28106. /* 319 */
  28107. /***/ function(module, exports, __webpack_require__) {
  28108. // HINT Markpoint can't be used too much
  28109. __webpack_require__(320);
  28110. __webpack_require__(321);
  28111. __webpack_require__(1).registerPreprocessor(function (opt) {
  28112. // Make sure markPoint component is enabled
  28113. opt.markPoint = opt.markPoint || {};
  28114. });
  28115. /***/ },
  28116. /* 320 */
  28117. /***/ function(module, exports, __webpack_require__) {
  28118. var modelUtil = __webpack_require__(5);
  28119. var zrUtil = __webpack_require__(3);
  28120. function fillLabel(opt) {
  28121. modelUtil.defaultEmphasis(
  28122. opt.label,
  28123. modelUtil.LABEL_OPTIONS
  28124. );
  28125. }
  28126. var MarkPointModel = __webpack_require__(1).extendComponentModel({
  28127. type: 'markPoint',
  28128. dependencies: ['series', 'grid', 'polar'],
  28129. /**
  28130. * @overrite
  28131. */
  28132. init: function (option, parentModel, ecModel, extraOpt) {
  28133. this.mergeDefaultAndTheme(option, ecModel);
  28134. this.mergeOption(option, ecModel, extraOpt.createdBySelf, true);
  28135. },
  28136. mergeOption: function (newOpt, ecModel, createdBySelf, isInit) {
  28137. if (!createdBySelf) {
  28138. ecModel.eachSeries(function (seriesModel) {
  28139. var markPointOpt = seriesModel.get('markPoint');
  28140. var mpModel = seriesModel.markPointModel;
  28141. if (!markPointOpt || !markPointOpt.data) {
  28142. seriesModel.markPointModel = null;
  28143. return;
  28144. }
  28145. if (!mpModel) {
  28146. if (isInit) {
  28147. // Default label emphasis `position` and `show`
  28148. fillLabel(markPointOpt);
  28149. }
  28150. zrUtil.each(markPointOpt.data, fillLabel);
  28151. var opt = {
  28152. mainType: 'markPoint',
  28153. // Use the same series index and name
  28154. seriesIndex: seriesModel.seriesIndex,
  28155. name: seriesModel.name,
  28156. createdBySelf: true
  28157. };
  28158. mpModel = new MarkPointModel(
  28159. markPointOpt, this, ecModel, opt
  28160. );
  28161. }
  28162. else {
  28163. mpModel.mergeOption(markPointOpt, ecModel, true);
  28164. }
  28165. seriesModel.markPointModel = mpModel;
  28166. }, this);
  28167. }
  28168. },
  28169. defaultOption: {
  28170. zlevel: 0,
  28171. z: 5,
  28172. symbol: 'pin',
  28173. symbolSize: 50,
  28174. //symbolRotate: 0,
  28175. //symbolOffset: [0, 0]
  28176. tooltip: {
  28177. trigger: 'item'
  28178. },
  28179. label: {
  28180. normal: {
  28181. show: true,
  28182. position: 'inside'
  28183. },
  28184. emphasis: {
  28185. show: true
  28186. }
  28187. },
  28188. itemStyle: {
  28189. normal: {
  28190. borderWidth: 2
  28191. }
  28192. }
  28193. }
  28194. });
  28195. module.exports = MarkPointModel;
  28196. /***/ },
  28197. /* 321 */
  28198. /***/ function(module, exports, __webpack_require__) {
  28199. var SymbolDraw = __webpack_require__(99);
  28200. var zrUtil = __webpack_require__(3);
  28201. var formatUtil = __webpack_require__(6);
  28202. var modelUtil = __webpack_require__(5);
  28203. var numberUtil = __webpack_require__(7);
  28204. var addCommas = formatUtil.addCommas;
  28205. var encodeHTML = formatUtil.encodeHTML;
  28206. var List = __webpack_require__(95);
  28207. var markerHelper = __webpack_require__(322);
  28208. function updateMarkerLayout(mpData, seriesModel, api) {
  28209. var coordSys = seriesModel.coordinateSystem;
  28210. mpData.each(function (idx) {
  28211. var itemModel = mpData.getItemModel(idx);
  28212. var point;
  28213. var xPx = itemModel.getShallow('x');
  28214. var yPx = itemModel.getShallow('y');
  28215. if (xPx != null && yPx != null) {
  28216. point = [
  28217. numberUtil.parsePercent(xPx, api.getWidth()),
  28218. numberUtil.parsePercent(yPx, api.getHeight())
  28219. ];
  28220. }
  28221. // Chart like bar may have there own marker positioning logic
  28222. else if (seriesModel.getMarkerPosition) {
  28223. // Use the getMarkerPoisition
  28224. point = seriesModel.getMarkerPosition(
  28225. mpData.getValues(mpData.dimensions, idx)
  28226. );
  28227. }
  28228. else if (coordSys) {
  28229. var x = mpData.get(coordSys.dimensions[0], idx);
  28230. var y = mpData.get(coordSys.dimensions[1], idx);
  28231. point = coordSys.dataToPoint([x, y]);
  28232. }
  28233. mpData.setItemLayout(idx, point);
  28234. });
  28235. }
  28236. // FIXME
  28237. var markPointFormatMixin = {
  28238. formatTooltip: function (dataIndex) {
  28239. var data = this.getData();
  28240. var value = this.getRawValue(dataIndex);
  28241. var formattedValue = zrUtil.isArray(value)
  28242. ? zrUtil.map(value, addCommas).join(', ') : addCommas(value);
  28243. var name = data.getName(dataIndex);
  28244. return this.name + '<br />'
  28245. + ((name ? encodeHTML(name) + ' : ' : '') + formattedValue);
  28246. },
  28247. getData: function () {
  28248. return this._data;
  28249. },
  28250. setData: function (data) {
  28251. this._data = data;
  28252. }
  28253. };
  28254. zrUtil.defaults(markPointFormatMixin, modelUtil.dataFormatMixin);
  28255. __webpack_require__(1).extendComponentView({
  28256. type: 'markPoint',
  28257. init: function () {
  28258. this._symbolDrawMap = {};
  28259. },
  28260. render: function (markPointModel, ecModel, api) {
  28261. var symbolDrawMap = this._symbolDrawMap;
  28262. for (var name in symbolDrawMap) {
  28263. symbolDrawMap[name].__keep = false;
  28264. }
  28265. ecModel.eachSeries(function (seriesModel) {
  28266. var mpModel = seriesModel.markPointModel;
  28267. mpModel && this._renderSeriesMP(seriesModel, mpModel, api);
  28268. }, this);
  28269. for (var name in symbolDrawMap) {
  28270. if (!symbolDrawMap[name].__keep) {
  28271. symbolDrawMap[name].remove();
  28272. this.group.remove(symbolDrawMap[name].group);
  28273. }
  28274. }
  28275. },
  28276. updateLayout: function (markPointModel, ecModel, api) {
  28277. ecModel.eachSeries(function (seriesModel) {
  28278. var mpModel = seriesModel.markPointModel;
  28279. if (mpModel) {
  28280. updateMarkerLayout(mpModel.getData(), seriesModel, api);
  28281. this._symbolDrawMap[seriesModel.name].updateLayout(mpModel);
  28282. }
  28283. }, this);
  28284. },
  28285. _renderSeriesMP: function (seriesModel, mpModel, api) {
  28286. var coordSys = seriesModel.coordinateSystem;
  28287. var seriesName = seriesModel.name;
  28288. var seriesData = seriesModel.getData();
  28289. var symbolDrawMap = this._symbolDrawMap;
  28290. var symbolDraw = symbolDrawMap[seriesName];
  28291. if (!symbolDraw) {
  28292. symbolDraw = symbolDrawMap[seriesName] = new SymbolDraw();
  28293. }
  28294. var mpData = createList(coordSys, seriesModel, mpModel);
  28295. // FIXME
  28296. zrUtil.mixin(mpModel, markPointFormatMixin);
  28297. mpModel.setData(mpData);
  28298. updateMarkerLayout(mpModel.getData(), seriesModel, api);
  28299. mpData.each(function (idx) {
  28300. var itemModel = mpData.getItemModel(idx);
  28301. var symbolSize = itemModel.getShallow('symbolSize');
  28302. if (typeof symbolSize === 'function') {
  28303. // FIXME 这里不兼容 ECharts 2.x,2.x 貌似参数是整个数据?
  28304. symbolSize = symbolSize(
  28305. mpModel.getRawValue(idx), mpModel.getDataParams(idx)
  28306. );
  28307. }
  28308. mpData.setItemVisual(idx, {
  28309. symbolSize: symbolSize,
  28310. color: itemModel.get('itemStyle.normal.color')
  28311. || seriesData.getVisual('color'),
  28312. symbol: itemModel.getShallow('symbol')
  28313. });
  28314. });
  28315. // TODO Text are wrong
  28316. symbolDraw.updateData(mpData);
  28317. this.group.add(symbolDraw.group);
  28318. // Set host model for tooltip
  28319. // FIXME
  28320. mpData.eachItemGraphicEl(function (el) {
  28321. el.traverse(function (child) {
  28322. child.dataModel = mpModel;
  28323. });
  28324. });
  28325. symbolDraw.__keep = true;
  28326. }
  28327. });
  28328. /**
  28329. * @inner
  28330. * @param {module:echarts/coord/*} [coordSys]
  28331. * @param {module:echarts/model/Series} seriesModel
  28332. * @param {module:echarts/model/Model} mpModel
  28333. */
  28334. function createList(coordSys, seriesModel, mpModel) {
  28335. var coordDimsInfos;
  28336. if (coordSys) {
  28337. coordDimsInfos = zrUtil.map(coordSys && coordSys.dimensions, function (coordDim) {
  28338. var info = seriesModel.getData().getDimensionInfo(
  28339. seriesModel.coordDimToDataDim(coordDim)[0]
  28340. ) || {}; // In map series data don't have lng and lat dimension. Fallback to same with coordSys
  28341. info.name = coordDim;
  28342. return info;
  28343. });
  28344. }
  28345. else {
  28346. coordDimsInfos =[{
  28347. name: 'value',
  28348. type: 'float'
  28349. }];
  28350. }
  28351. var mpData = new List(coordDimsInfos, mpModel);
  28352. var dataOpt = zrUtil.map(mpModel.get('data'), zrUtil.curry(
  28353. markerHelper.dataTransform, seriesModel
  28354. ));
  28355. if (coordSys) {
  28356. dataOpt = zrUtil.filter(
  28357. dataOpt, zrUtil.curry(markerHelper.dataFilter, coordSys)
  28358. );
  28359. }
  28360. mpData.initData(dataOpt, null,
  28361. coordSys ? markerHelper.dimValueGetter : function (item) {
  28362. return item.value;
  28363. }
  28364. );
  28365. return mpData;
  28366. }
  28367. /***/ },
  28368. /* 322 */
  28369. /***/ function(module, exports, __webpack_require__) {
  28370. var zrUtil = __webpack_require__(3);
  28371. var numberUtil = __webpack_require__(7);
  28372. var indexOf = zrUtil.indexOf;
  28373. function getPrecision(data, valueAxisDim, dataIndex) {
  28374. var precision = -1;
  28375. do {
  28376. precision = Math.max(
  28377. numberUtil.getPrecision(data.get(
  28378. valueAxisDim, dataIndex
  28379. )),
  28380. precision
  28381. );
  28382. data = data.stackedOn;
  28383. } while (data);
  28384. return precision;
  28385. }
  28386. function markerTypeCalculatorWithExtent(
  28387. mlType, data, baseDataDim, valueDataDim, baseCoordIndex, valueCoordIndex
  28388. ) {
  28389. var coordArr = [];
  28390. var value = numCalculate(data, valueDataDim, mlType);
  28391. var dataIndex = data.indexOfNearest(valueDataDim, value, true);
  28392. coordArr[baseCoordIndex] = data.get(baseDataDim, dataIndex, true);
  28393. coordArr[valueCoordIndex] = data.get(valueDataDim, dataIndex, true);
  28394. var precision = getPrecision(data, valueDataDim, dataIndex);
  28395. if (precision >= 0) {
  28396. coordArr[valueCoordIndex] = +coordArr[valueCoordIndex].toFixed(precision);
  28397. }
  28398. return coordArr;
  28399. }
  28400. var curry = zrUtil.curry;
  28401. // TODO Specified percent
  28402. var markerTypeCalculator = {
  28403. /**
  28404. * @method
  28405. * @param {module:echarts/data/List} data
  28406. * @param {string} baseAxisDim
  28407. * @param {string} valueAxisDim
  28408. */
  28409. min: curry(markerTypeCalculatorWithExtent, 'min'),
  28410. /**
  28411. * @method
  28412. * @param {module:echarts/data/List} data
  28413. * @param {string} baseAxisDim
  28414. * @param {string} valueAxisDim
  28415. */
  28416. max: curry(markerTypeCalculatorWithExtent, 'max'),
  28417. /**
  28418. * @method
  28419. * @param {module:echarts/data/List} data
  28420. * @param {string} baseAxisDim
  28421. * @param {string} valueAxisDim
  28422. */
  28423. average: curry(markerTypeCalculatorWithExtent, 'average')
  28424. };
  28425. /**
  28426. * Transform markPoint data item to format used in List by do the following
  28427. * 1. Calculate statistic like `max`, `min`, `average`
  28428. * 2. Convert `item.xAxis`, `item.yAxis` to `item.coord` array
  28429. * @param {module:echarts/model/Series} seriesModel
  28430. * @param {module:echarts/coord/*} [coordSys]
  28431. * @param {Object} item
  28432. * @return {Object}
  28433. */
  28434. var dataTransform = function (seriesModel, item) {
  28435. var data = seriesModel.getData();
  28436. var coordSys = seriesModel.coordinateSystem;
  28437. // 1. If not specify the position with pixel directly
  28438. // 2. If `coord` is not a data array. Which uses `xAxis`,
  28439. // `yAxis` to specify the coord on each dimension
  28440. // parseFloat first because item.x and item.y can be percent string like '20%'
  28441. if (item && (isNaN(parseFloat(item.x)) || isNaN(parseFloat(item.y)))
  28442. && !zrUtil.isArray(item.coord)
  28443. && coordSys
  28444. ) {
  28445. var axisInfo = getAxisInfo(item, data, coordSys, seriesModel);
  28446. // Clone the option
  28447. // Transform the properties xAxis, yAxis, radiusAxis, angleAxis, geoCoord to value
  28448. item = zrUtil.clone(item);
  28449. if (item.type
  28450. && markerTypeCalculator[item.type]
  28451. && axisInfo.baseAxis && axisInfo.valueAxis
  28452. ) {
  28453. var dims = coordSys.dimensions;
  28454. var baseCoordIndex = indexOf(dims, axisInfo.baseAxis.dim);
  28455. var valueCoordIndex = indexOf(dims, axisInfo.valueAxis.dim);
  28456. item.coord = markerTypeCalculator[item.type](
  28457. data, axisInfo.baseDataDim, axisInfo.valueDataDim,
  28458. baseCoordIndex, valueCoordIndex
  28459. );
  28460. // Force to use the value of calculated value.
  28461. item.value = item.coord[valueCoordIndex];
  28462. }
  28463. else {
  28464. // FIXME Only has one of xAxis and yAxis.
  28465. item.coord = [
  28466. item.xAxis != null ? item.xAxis : item.radiusAxis,
  28467. item.yAxis != null ? item.yAxis : item.angleAxis
  28468. ];
  28469. }
  28470. }
  28471. return item;
  28472. };
  28473. var getAxisInfo = function (item, data, coordSys, seriesModel) {
  28474. var ret = {};
  28475. if (item.valueIndex != null || item.valueDim != null) {
  28476. ret.valueDataDim = item.valueIndex != null
  28477. ? data.getDimension(item.valueIndex) : item.valueDim;
  28478. ret.valueAxis = coordSys.getAxis(seriesModel.dataDimToCoordDim(ret.valueDataDim));
  28479. ret.baseAxis = coordSys.getOtherAxis(ret.valueAxis);
  28480. ret.baseDataDim = seriesModel.coordDimToDataDim(ret.baseAxis.dim)[0];
  28481. }
  28482. else {
  28483. ret.baseAxis = seriesModel.getBaseAxis();
  28484. ret.valueAxis = coordSys.getOtherAxis(ret.baseAxis);
  28485. ret.baseDataDim = seriesModel.coordDimToDataDim(ret.baseAxis.dim)[0];
  28486. ret.valueDataDim = seriesModel.coordDimToDataDim(ret.valueAxis.dim)[0];
  28487. }
  28488. return ret;
  28489. };
  28490. /**
  28491. * Filter data which is out of coordinateSystem range
  28492. * [dataFilter description]
  28493. * @param {module:echarts/coord/*} [coordSys]
  28494. * @param {Object} item
  28495. * @return {boolean}
  28496. */
  28497. var dataFilter = function (coordSys, item) {
  28498. // Alwalys return true if there is no coordSys
  28499. return (coordSys && coordSys.containData && item.coord && (item.x == null || item.y == null))
  28500. ? coordSys.containData(item.coord) : true;
  28501. };
  28502. var dimValueGetter = function (item, dimName, dataIndex, dimIndex) {
  28503. // x, y, radius, angle
  28504. if (dimIndex < 2) {
  28505. return item.coord && item.coord[dimIndex];
  28506. }
  28507. return item.value;
  28508. };
  28509. var numCalculate = function (data, valueDataDim, mlType) {
  28510. return mlType === 'average'
  28511. ? data.getSum(valueDataDim, true) / data.count()
  28512. : data.getDataExtent(valueDataDim, true)[mlType === 'max' ? 1 : 0];
  28513. };
  28514. module.exports = {
  28515. dataTransform: dataTransform,
  28516. dataFilter: dataFilter,
  28517. dimValueGetter: dimValueGetter,
  28518. getAxisInfo: getAxisInfo,
  28519. numCalculate: numCalculate
  28520. };
  28521. /***/ },
  28522. /* 323 */
  28523. /***/ function(module, exports, __webpack_require__) {
  28524. __webpack_require__(324);
  28525. __webpack_require__(325);
  28526. __webpack_require__(1).registerPreprocessor(function (opt) {
  28527. // Make sure markLine component is enabled
  28528. opt.markLine = opt.markLine || {};
  28529. });
  28530. /***/ },
  28531. /* 324 */
  28532. /***/ function(module, exports, __webpack_require__) {
  28533. var modelUtil = __webpack_require__(5);
  28534. var zrUtil = __webpack_require__(3);
  28535. function fillLabel(opt) {
  28536. modelUtil.defaultEmphasis(
  28537. opt.label,
  28538. modelUtil.LABEL_OPTIONS
  28539. );
  28540. }
  28541. var MarkLineModel = __webpack_require__(1).extendComponentModel({
  28542. type: 'markLine',
  28543. dependencies: ['series', 'grid', 'polar', 'geo'],
  28544. /**
  28545. * @overrite
  28546. */
  28547. init: function (option, parentModel, ecModel, extraOpt) {
  28548. this.mergeDefaultAndTheme(option, ecModel);
  28549. this.mergeOption(option, ecModel, extraOpt.createdBySelf, true);
  28550. },
  28551. mergeOption: function (newOpt, ecModel, createdBySelf, isInit) {
  28552. if (!createdBySelf) {
  28553. ecModel.eachSeries(function (seriesModel) {
  28554. var markLineOpt = seriesModel.get('markLine');
  28555. var mlModel = seriesModel.markLineModel;
  28556. if (!markLineOpt || !markLineOpt.data) {
  28557. seriesModel.markLineModel = null;
  28558. return;
  28559. }
  28560. if (!mlModel) {
  28561. if (isInit) {
  28562. // Default label emphasis `position` and `show`
  28563. fillLabel(markLineOpt);
  28564. }
  28565. zrUtil.each(markLineOpt.data, function (item) {
  28566. if (item instanceof Array) {
  28567. fillLabel(item[0]);
  28568. fillLabel(item[1]);
  28569. }
  28570. else {
  28571. fillLabel(item);
  28572. }
  28573. });
  28574. var opt = {
  28575. mainType: 'markLine',
  28576. // Use the same series index and name
  28577. seriesIndex: seriesModel.seriesIndex,
  28578. name: seriesModel.name,
  28579. createdBySelf: true
  28580. };
  28581. mlModel = new MarkLineModel(
  28582. markLineOpt, this, ecModel, opt
  28583. );
  28584. }
  28585. else {
  28586. mlModel.mergeOption(markLineOpt, ecModel, true);
  28587. }
  28588. seriesModel.markLineModel = mlModel;
  28589. }, this);
  28590. }
  28591. },
  28592. defaultOption: {
  28593. zlevel: 0,
  28594. z: 5,
  28595. symbol: ['circle', 'arrow'],
  28596. symbolSize: [8, 16],
  28597. //symbolRotate: 0,
  28598. precision: 2,
  28599. tooltip: {
  28600. trigger: 'item'
  28601. },
  28602. label: {
  28603. normal: {
  28604. show: true,
  28605. position: 'end'
  28606. },
  28607. emphasis: {
  28608. show: true
  28609. }
  28610. },
  28611. lineStyle: {
  28612. normal: {
  28613. type: 'dashed'
  28614. },
  28615. emphasis: {
  28616. width: 3
  28617. }
  28618. },
  28619. animationEasing: 'linear'
  28620. }
  28621. });
  28622. module.exports = MarkLineModel;
  28623. /***/ },
  28624. /* 325 */
  28625. /***/ function(module, exports, __webpack_require__) {
  28626. var zrUtil = __webpack_require__(3);
  28627. var List = __webpack_require__(95);
  28628. var formatUtil = __webpack_require__(6);
  28629. var modelUtil = __webpack_require__(5);
  28630. var numberUtil = __webpack_require__(7);
  28631. var addCommas = formatUtil.addCommas;
  28632. var encodeHTML = formatUtil.encodeHTML;
  28633. var markerHelper = __webpack_require__(322);
  28634. var LineDraw = __webpack_require__(194);
  28635. var markLineTransform = function (seriesModel, coordSys, mlModel, item) {
  28636. var data = seriesModel.getData();
  28637. // Special type markLine like 'min', 'max', 'average'
  28638. var mlType = item.type;
  28639. if (!zrUtil.isArray(item)
  28640. && (
  28641. mlType === 'min' || mlType === 'max' || mlType === 'average'
  28642. // In case
  28643. // data: [{
  28644. // yAxis: 10
  28645. // }]
  28646. || (item.xAxis != null || item.yAxis != null)
  28647. )
  28648. ) {
  28649. var valueAxis;
  28650. var valueDataDim;
  28651. var value;
  28652. if (item.yAxis != null || item.xAxis != null) {
  28653. valueDataDim = item.yAxis != null ? 'y' : 'x';
  28654. valueAxis = coordSys.getAxis(valueDataDim);
  28655. value = zrUtil.retrieve(item.yAxis, item.xAxis);
  28656. }
  28657. else {
  28658. var axisInfo = markerHelper.getAxisInfo(item, data, coordSys, seriesModel);
  28659. valueDataDim = axisInfo.valueDataDim;
  28660. valueAxis = axisInfo.valueAxis;
  28661. value = markerHelper.numCalculate(data, valueDataDim, mlType);
  28662. }
  28663. var valueIndex = valueDataDim === 'x' ? 0 : 1;
  28664. var baseIndex = 1 - valueIndex;
  28665. var mlFrom = zrUtil.clone(item);
  28666. var mlTo = {};
  28667. mlFrom.type = null;
  28668. mlFrom.coord = [];
  28669. mlTo.coord = [];
  28670. mlFrom.coord[baseIndex] = -Infinity;
  28671. mlTo.coord[baseIndex] = Infinity;
  28672. var precision = mlModel.get('precision');
  28673. if (precision >= 0) {
  28674. value = +value.toFixed(precision);
  28675. }
  28676. mlFrom.coord[valueIndex] = mlTo.coord[valueIndex] = value;
  28677. item = [mlFrom, mlTo, { // Extra option for tooltip and label
  28678. type: mlType,
  28679. valueIndex: item.valueIndex,
  28680. // Force to use the value of calculated value.
  28681. value: value
  28682. }];
  28683. }
  28684. item = [
  28685. markerHelper.dataTransform(seriesModel, item[0]),
  28686. markerHelper.dataTransform(seriesModel, item[1]),
  28687. zrUtil.extend({}, item[2])
  28688. ];
  28689. // Avoid line data type is extended by from(to) data type
  28690. item[2].type = item[2].type || '';
  28691. // Merge from option and to option into line option
  28692. zrUtil.merge(item[2], item[0]);
  28693. zrUtil.merge(item[2], item[1]);
  28694. return item;
  28695. };
  28696. function isInifinity(val) {
  28697. return !isNaN(val) && !isFinite(val);
  28698. }
  28699. // If a markLine has one dim
  28700. function ifMarkLineHasOnlyDim(dimIndex, fromCoord, toCoord, coordSys) {
  28701. var otherDimIndex = 1 - dimIndex;
  28702. var dimName = coordSys.dimensions[dimIndex];
  28703. return isInifinity(fromCoord[otherDimIndex]) && isInifinity(toCoord[otherDimIndex])
  28704. && fromCoord[dimIndex] === toCoord[dimIndex] && coordSys.getAxis(dimName).containData(fromCoord[dimIndex]);
  28705. }
  28706. function markLineFilter(coordSys, item) {
  28707. if (coordSys.type === 'cartesian2d') {
  28708. var fromCoord = item[0].coord;
  28709. var toCoord = item[1].coord;
  28710. // In case
  28711. // {
  28712. // markLine: {
  28713. // data: [{ yAxis: 2 }]
  28714. // }
  28715. // }
  28716. if (
  28717. fromCoord && toCoord &&
  28718. (ifMarkLineHasOnlyDim(1, fromCoord, toCoord, coordSys)
  28719. || ifMarkLineHasOnlyDim(0, fromCoord, toCoord, coordSys))
  28720. ) {
  28721. return true;
  28722. }
  28723. }
  28724. return markerHelper.dataFilter(coordSys, item[0])
  28725. && markerHelper.dataFilter(coordSys, item[1]);
  28726. }
  28727. function updateSingleMarkerEndLayout(
  28728. data, idx, isFrom, mlType, valueIndex, seriesModel, api
  28729. ) {
  28730. var coordSys = seriesModel.coordinateSystem;
  28731. var itemModel = data.getItemModel(idx);
  28732. var point;
  28733. var xPx = itemModel.get('x');
  28734. var yPx = itemModel.get('y');
  28735. if (xPx != null && yPx != null) {
  28736. point = [
  28737. numberUtil.parsePercent(xPx, api.getWidth()),
  28738. numberUtil.parsePercent(yPx, api.getHeight())
  28739. ];
  28740. }
  28741. else {
  28742. // Chart like bar may have there own marker positioning logic
  28743. if (seriesModel.getMarkerPosition) {
  28744. // Use the getMarkerPoisition
  28745. point = seriesModel.getMarkerPosition(
  28746. data.getValues(data.dimensions, idx)
  28747. );
  28748. }
  28749. else {
  28750. var dims = coordSys.dimensions;
  28751. var x = data.get(dims[0], idx);
  28752. var y = data.get(dims[1], idx);
  28753. point = coordSys.dataToPoint([x, y]);
  28754. }
  28755. // Expand line to the edge of grid if value on one axis is Inifnity
  28756. // In case
  28757. // markLine: {
  28758. // data: [{
  28759. // yAxis: 2
  28760. // // or
  28761. // type: 'average'
  28762. // }]
  28763. // }
  28764. if (coordSys.type === 'cartesian2d') {
  28765. var xAxis = coordSys.getAxis('x');
  28766. var yAxis = coordSys.getAxis('y');
  28767. var dims = coordSys.dimensions;
  28768. if (isInifinity(data.get(dims[0], idx))) {
  28769. point[0] = xAxis.toGlobalCoord(xAxis.getExtent()[isFrom ? 0 : 1]);
  28770. }
  28771. else if (isInifinity(data.get(dims[1], idx))) {
  28772. point[1] = yAxis.toGlobalCoord(yAxis.getExtent()[isFrom ? 0 : 1]);
  28773. }
  28774. }
  28775. }
  28776. data.setItemLayout(idx, point);
  28777. }
  28778. var markLineFormatMixin = {
  28779. formatTooltip: function (dataIndex) {
  28780. var data = this._data;
  28781. var value = this.getRawValue(dataIndex);
  28782. var formattedValue = zrUtil.isArray(value)
  28783. ? zrUtil.map(value, addCommas).join(', ') : addCommas(value);
  28784. var name = data.getName(dataIndex);
  28785. return this.name + '<br />'
  28786. + ((name ? encodeHTML(name) + ' : ' : '') + formattedValue);
  28787. },
  28788. getData: function () {
  28789. return this._data;
  28790. },
  28791. setData: function (data) {
  28792. this._data = data;
  28793. }
  28794. };
  28795. zrUtil.defaults(markLineFormatMixin, modelUtil.dataFormatMixin);
  28796. __webpack_require__(1).extendComponentView({
  28797. type: 'markLine',
  28798. init: function () {
  28799. /**
  28800. * Markline grouped by series
  28801. * @private
  28802. * @type {Object}
  28803. */
  28804. this._markLineMap = {};
  28805. },
  28806. render: function (markLineModel, ecModel, api) {
  28807. var lineDrawMap = this._markLineMap;
  28808. for (var name in lineDrawMap) {
  28809. lineDrawMap[name].__keep = false;
  28810. }
  28811. ecModel.eachSeries(function (seriesModel) {
  28812. var mlModel = seriesModel.markLineModel;
  28813. mlModel && this._renderSeriesML(seriesModel, mlModel, ecModel, api);
  28814. }, this);
  28815. for (var name in lineDrawMap) {
  28816. if (!lineDrawMap[name].__keep) {
  28817. this.group.remove(lineDrawMap[name].group);
  28818. }
  28819. }
  28820. },
  28821. updateLayout: function (markLineModel, ecModel, api) {
  28822. ecModel.eachSeries(function (seriesModel) {
  28823. var mlModel = seriesModel.markLineModel;
  28824. if (mlModel) {
  28825. var mlData = mlModel.getData();
  28826. var fromData = mlModel.__from;
  28827. var toData = mlModel.__to;
  28828. // Update visual and layout of from symbol and to symbol
  28829. fromData.each(function (idx) {
  28830. var lineModel = mlData.getItemModel(idx);
  28831. var mlType = lineModel.get('type');
  28832. var valueIndex = lineModel.get('valueIndex');
  28833. updateSingleMarkerEndLayout(fromData, idx, true, mlType, valueIndex, seriesModel, api);
  28834. updateSingleMarkerEndLayout(toData, idx, false, mlType, valueIndex, seriesModel, api);
  28835. });
  28836. // Update layout of line
  28837. mlData.each(function (idx) {
  28838. mlData.setItemLayout(idx, [
  28839. fromData.getItemLayout(idx),
  28840. toData.getItemLayout(idx)
  28841. ]);
  28842. });
  28843. this._markLineMap[seriesModel.name].updateLayout();
  28844. }
  28845. }, this);
  28846. },
  28847. _renderSeriesML: function (seriesModel, mlModel, ecModel, api) {
  28848. var coordSys = seriesModel.coordinateSystem;
  28849. var seriesName = seriesModel.name;
  28850. var seriesData = seriesModel.getData();
  28851. var lineDrawMap = this._markLineMap;
  28852. var lineDraw = lineDrawMap[seriesName];
  28853. if (!lineDraw) {
  28854. lineDraw = lineDrawMap[seriesName] = new LineDraw();
  28855. }
  28856. this.group.add(lineDraw.group);
  28857. var mlData = createList(coordSys, seriesModel, mlModel);
  28858. var fromData = mlData.from;
  28859. var toData = mlData.to;
  28860. var lineData = mlData.line;
  28861. mlModel.__from = fromData;
  28862. mlModel.__to = toData;
  28863. // Line data for tooltip and formatter
  28864. zrUtil.extend(mlModel, markLineFormatMixin);
  28865. mlModel.setData(lineData);
  28866. var symbolType = mlModel.get('symbol');
  28867. var symbolSize = mlModel.get('symbolSize');
  28868. if (!zrUtil.isArray(symbolType)) {
  28869. symbolType = [symbolType, symbolType];
  28870. }
  28871. if (typeof symbolSize === 'number') {
  28872. symbolSize = [symbolSize, symbolSize];
  28873. }
  28874. // Update visual and layout of from symbol and to symbol
  28875. mlData.from.each(function (idx) {
  28876. var lineModel = lineData.getItemModel(idx);
  28877. var mlType = lineModel.get('type');
  28878. var valueIndex = lineModel.get('valueIndex');
  28879. updateDataVisualAndLayout(fromData, idx, true, mlType, valueIndex);
  28880. updateDataVisualAndLayout(toData, idx, false, mlType, valueIndex);
  28881. });
  28882. // Update visual and layout of line
  28883. lineData.each(function (idx) {
  28884. var lineColor = lineData.getItemModel(idx).get('lineStyle.normal.color');
  28885. lineData.setItemVisual(idx, {
  28886. color: lineColor || fromData.getItemVisual(idx, 'color')
  28887. });
  28888. lineData.setItemLayout(idx, [
  28889. fromData.getItemLayout(idx),
  28890. toData.getItemLayout(idx)
  28891. ]);
  28892. lineData.setItemVisual(idx, {
  28893. 'fromSymbolSize': fromData.getItemVisual(idx, 'symbolSize'),
  28894. 'fromSymbol': fromData.getItemVisual(idx, 'symbol'),
  28895. 'toSymbolSize': toData.getItemVisual(idx, 'symbolSize'),
  28896. 'toSymbol': toData.getItemVisual(idx, 'symbol')
  28897. });
  28898. });
  28899. lineDraw.updateData(lineData);
  28900. // Set host model for tooltip
  28901. // FIXME
  28902. mlData.line.eachItemGraphicEl(function (el, idx) {
  28903. el.traverse(function (child) {
  28904. child.dataModel = mlModel;
  28905. });
  28906. });
  28907. function updateDataVisualAndLayout(data, idx, isFrom, mlType, valueIndex) {
  28908. var itemModel = data.getItemModel(idx);
  28909. updateSingleMarkerEndLayout(
  28910. data, idx, isFrom, mlType, valueIndex, seriesModel, api
  28911. );
  28912. data.setItemVisual(idx, {
  28913. symbolSize: itemModel.get('symbolSize') || symbolSize[isFrom ? 0 : 1],
  28914. symbol: itemModel.get('symbol', true) || symbolType[isFrom ? 0 : 1],
  28915. color: itemModel.get('itemStyle.normal.color') || seriesData.getVisual('color')
  28916. });
  28917. }
  28918. lineDraw.__keep = true;
  28919. }
  28920. });
  28921. /**
  28922. * @inner
  28923. * @param {module:echarts/coord/*} coordSys
  28924. * @param {module:echarts/model/Series} seriesModel
  28925. * @param {module:echarts/model/Model} mpModel
  28926. */
  28927. function createList(coordSys, seriesModel, mlModel) {
  28928. var coordDimsInfos;
  28929. if (coordSys) {
  28930. coordDimsInfos = zrUtil.map(coordSys && coordSys.dimensions, function (coordDim) {
  28931. var info = seriesModel.getData().getDimensionInfo(
  28932. seriesModel.coordDimToDataDim(coordDim)[0]
  28933. ) || {}; // In map series data don't have lng and lat dimension. Fallback to same with coordSys
  28934. info.name = coordDim;
  28935. return info;
  28936. });
  28937. }
  28938. else {
  28939. coordDimsInfos =[{
  28940. name: 'value',
  28941. type: 'float'
  28942. }];
  28943. }
  28944. var fromData = new List(coordDimsInfos, mlModel);
  28945. var toData = new List(coordDimsInfos, mlModel);
  28946. // No dimensions
  28947. var lineData = new List([], mlModel);
  28948. var optData = zrUtil.map(mlModel.get('data'), zrUtil.curry(
  28949. markLineTransform, seriesModel, coordSys, mlModel
  28950. ));
  28951. if (coordSys) {
  28952. optData = zrUtil.filter(
  28953. optData, zrUtil.curry(markLineFilter, coordSys)
  28954. );
  28955. }
  28956. var dimValueGetter = coordSys ? markerHelper.dimValueGetter : function (item) {
  28957. return item.value;
  28958. };
  28959. fromData.initData(
  28960. zrUtil.map(optData, function (item) { return item[0]; }),
  28961. null, dimValueGetter
  28962. );
  28963. toData.initData(
  28964. zrUtil.map(optData, function (item) { return item[1]; }),
  28965. null, dimValueGetter
  28966. );
  28967. lineData.initData(
  28968. zrUtil.map(optData, function (item) { return item[2]; })
  28969. );
  28970. return {
  28971. from: fromData,
  28972. to: toData,
  28973. line: lineData
  28974. };
  28975. }
  28976. /***/ },
  28977. /* 326 */,
  28978. /* 327 */,
  28979. /* 328 */,
  28980. /* 329 */,
  28981. /* 330 */,
  28982. /* 331 */,
  28983. /* 332 */,
  28984. /* 333 */,
  28985. /* 334 */,
  28986. /* 335 */
  28987. /***/ function(module, exports, __webpack_require__) {
  28988. __webpack_require__(336);
  28989. __webpack_require__(338);
  28990. __webpack_require__(340);
  28991. __webpack_require__(341);
  28992. __webpack_require__(342);
  28993. __webpack_require__(343);
  28994. __webpack_require__(348);
  28995. /***/ },
  28996. /* 336 */
  28997. /***/ function(module, exports, __webpack_require__) {
  28998. var featureManager = __webpack_require__(337);
  28999. var zrUtil = __webpack_require__(3);
  29000. var ToolboxModel = __webpack_require__(1).extendComponentModel({
  29001. type: 'toolbox',
  29002. layoutMode: {
  29003. type: 'box',
  29004. ignoreSize: true
  29005. },
  29006. mergeDefaultAndTheme: function (option) {
  29007. ToolboxModel.superApply(this, 'mergeDefaultAndTheme', arguments);
  29008. zrUtil.each(this.option.feature, function (featureOpt, featureName) {
  29009. var Feature = featureManager.get(featureName);
  29010. Feature && zrUtil.merge(featureOpt, Feature.defaultOption);
  29011. });
  29012. },
  29013. defaultOption: {
  29014. show: true,
  29015. z: 6,
  29016. zlevel: 0,
  29017. orient: 'horizontal',
  29018. left: 'right',
  29019. top: 'top',
  29020. // right
  29021. // bottom
  29022. backgroundColor: 'transparent',
  29023. borderColor: '#ccc',
  29024. borderWidth: 0,
  29025. padding: 5,
  29026. itemSize: 15,
  29027. itemGap: 8,
  29028. showTitle: true,
  29029. iconStyle: {
  29030. normal: {
  29031. borderColor: '#666',
  29032. color: 'none'
  29033. },
  29034. emphasis: {
  29035. borderColor: '#3E98C5'
  29036. }
  29037. }
  29038. // textStyle: {},
  29039. // feature
  29040. }
  29041. });
  29042. module.exports = ToolboxModel;
  29043. /***/ },
  29044. /* 337 */
  29045. /***/ function(module, exports) {
  29046. 'use strict';
  29047. var features = {};
  29048. module.exports = {
  29049. register: function (name, ctor) {
  29050. features[name] = ctor;
  29051. },
  29052. get: function (name) {
  29053. return features[name];
  29054. }
  29055. };
  29056. /***/ },
  29057. /* 338 */
  29058. /***/ function(module, exports, __webpack_require__) {
  29059. /* WEBPACK VAR INJECTION */(function(process) {
  29060. var featureManager = __webpack_require__(337);
  29061. var zrUtil = __webpack_require__(3);
  29062. var graphic = __webpack_require__(42);
  29063. var Model = __webpack_require__(8);
  29064. var DataDiffer = __webpack_require__(96);
  29065. var listComponentHelper = __webpack_require__(269);
  29066. var textContain = __webpack_require__(14);
  29067. module.exports = __webpack_require__(1).extendComponentView({
  29068. type: 'toolbox',
  29069. render: function (toolboxModel, ecModel, api) {
  29070. var group = this.group;
  29071. group.removeAll();
  29072. if (!toolboxModel.get('show')) {
  29073. return;
  29074. }
  29075. var itemSize = +toolboxModel.get('itemSize');
  29076. var featureOpts = toolboxModel.get('feature') || {};
  29077. var features = this._features || (this._features = {});
  29078. var featureNames = [];
  29079. zrUtil.each(featureOpts, function (opt, name) {
  29080. featureNames.push(name);
  29081. });
  29082. (new DataDiffer(this._featureNames || [], featureNames))
  29083. .add(process)
  29084. .update(process)
  29085. .remove(zrUtil.curry(process, null))
  29086. .execute();
  29087. // Keep for diff.
  29088. this._featureNames = featureNames;
  29089. function process(newIndex, oldIndex) {
  29090. var featureName = featureNames[newIndex];
  29091. var oldName = featureNames[oldIndex];
  29092. var featureOpt = featureOpts[featureName];
  29093. var featureModel = new Model(featureOpt, toolboxModel, toolboxModel.ecModel);
  29094. var feature;
  29095. if (featureName && !oldName) { // Create
  29096. if (isUserFeatureName(featureName)) {
  29097. feature = {
  29098. model: featureModel,
  29099. onclick: featureModel.option.onclick,
  29100. featureName: featureName
  29101. };
  29102. }
  29103. else {
  29104. var Feature = featureManager.get(featureName);
  29105. if (!Feature) {
  29106. return;
  29107. }
  29108. feature = new Feature(featureModel);
  29109. }
  29110. features[featureName] = feature;
  29111. }
  29112. else {
  29113. feature = features[oldName];
  29114. // If feature does not exsit.
  29115. if (!feature) {
  29116. return;
  29117. }
  29118. feature.model = featureModel;
  29119. }
  29120. if (!featureName && oldName) {
  29121. feature.dispose && feature.dispose(ecModel, api);
  29122. return;
  29123. }
  29124. if (!featureModel.get('show') || feature.unusable) {
  29125. feature.remove && feature.remove(ecModel, api);
  29126. return;
  29127. }
  29128. createIconPaths(featureModel, feature, featureName);
  29129. featureModel.setIconStatus = function (iconName, status) {
  29130. var option = this.option;
  29131. var iconPaths = this.iconPaths;
  29132. option.iconStatus = option.iconStatus || {};
  29133. option.iconStatus[iconName] = status;
  29134. // FIXME
  29135. iconPaths[iconName] && iconPaths[iconName].trigger(status);
  29136. };
  29137. if (feature.render) {
  29138. feature.render(featureModel, ecModel, api);
  29139. }
  29140. }
  29141. function createIconPaths(featureModel, feature, featureName) {
  29142. var iconStyleModel = featureModel.getModel('iconStyle');
  29143. // If one feature has mutiple icon. they are orginaized as
  29144. // {
  29145. // icon: {
  29146. // foo: '',
  29147. // bar: ''
  29148. // },
  29149. // title: {
  29150. // foo: '',
  29151. // bar: ''
  29152. // }
  29153. // }
  29154. var icons = feature.getIcons ? feature.getIcons() : featureModel.get('icon');
  29155. var titles = featureModel.get('title') || {};
  29156. if (typeof icons === 'string') {
  29157. var icon = icons;
  29158. var title = titles;
  29159. icons = {};
  29160. titles = {};
  29161. icons[featureName] = icon;
  29162. titles[featureName] = title;
  29163. }
  29164. var iconPaths = featureModel.iconPaths = {};
  29165. zrUtil.each(icons, function (icon, iconName) {
  29166. var normalStyle = iconStyleModel.getModel('normal').getItemStyle();
  29167. var hoverStyle = iconStyleModel.getModel('emphasis').getItemStyle();
  29168. var style = {
  29169. x: -itemSize / 2,
  29170. y: -itemSize / 2,
  29171. width: itemSize,
  29172. height: itemSize
  29173. };
  29174. var path = icon.indexOf('image://') === 0
  29175. ? (
  29176. style.image = icon.slice(8),
  29177. new graphic.Image({style: style})
  29178. )
  29179. : graphic.makePath(
  29180. icon.replace('path://', ''),
  29181. {
  29182. style: normalStyle,
  29183. hoverStyle: hoverStyle,
  29184. rectHover: true
  29185. },
  29186. style,
  29187. 'center'
  29188. );
  29189. graphic.setHoverStyle(path);
  29190. if (toolboxModel.get('showTitle')) {
  29191. path.__title = titles[iconName];
  29192. path.on('mouseover', function () {
  29193. path.setStyle({
  29194. text: titles[iconName],
  29195. textPosition: hoverStyle.textPosition || 'bottom',
  29196. textFill: hoverStyle.fill || hoverStyle.stroke || '#000',
  29197. textAlign: hoverStyle.textAlign || 'center'
  29198. });
  29199. })
  29200. .on('mouseout', function () {
  29201. path.setStyle({
  29202. textFill: null
  29203. });
  29204. });
  29205. }
  29206. path.trigger(featureModel.get('iconStatus.' + iconName) || 'normal');
  29207. group.add(path);
  29208. path.on('click', zrUtil.bind(
  29209. feature.onclick, feature, ecModel, api, iconName
  29210. ));
  29211. iconPaths[iconName] = path;
  29212. });
  29213. }
  29214. listComponentHelper.layout(group, toolboxModel, api);
  29215. // Render background after group is layout
  29216. // FIXME
  29217. listComponentHelper.addBackground(group, toolboxModel);
  29218. // Adjust icon title positions to avoid them out of screen
  29219. group.eachChild(function (icon) {
  29220. var titleText = icon.__title;
  29221. var hoverStyle = icon.hoverStyle;
  29222. // May be background element
  29223. if (hoverStyle && titleText) {
  29224. var rect = textContain.getBoundingRect(
  29225. titleText, hoverStyle.font
  29226. );
  29227. var offsetX = icon.position[0] + group.position[0];
  29228. var offsetY = icon.position[1] + group.position[1] + itemSize;
  29229. var needPutOnTop = false;
  29230. if (offsetY + rect.height > api.getHeight()) {
  29231. hoverStyle.textPosition = 'top';
  29232. needPutOnTop = true;
  29233. }
  29234. var topOffset = needPutOnTop ? (-5 - rect.height) : (itemSize + 8);
  29235. if (offsetX + rect.width / 2 > api.getWidth()) {
  29236. hoverStyle.textPosition = ['100%', topOffset];
  29237. hoverStyle.textAlign = 'right';
  29238. }
  29239. else if (offsetX - rect.width / 2 < 0) {
  29240. hoverStyle.textPosition = [0, topOffset];
  29241. hoverStyle.textAlign = 'left';
  29242. }
  29243. }
  29244. });
  29245. },
  29246. remove: function (ecModel, api) {
  29247. zrUtil.each(this._features, function (feature) {
  29248. feature.remove && feature.remove(ecModel, api);
  29249. });
  29250. this.group.removeAll();
  29251. },
  29252. dispose: function (ecModel, api) {
  29253. zrUtil.each(this._features, function (feature) {
  29254. feature.dispose && feature.dispose(ecModel, api);
  29255. });
  29256. }
  29257. });
  29258. function isUserFeatureName(featureName) {
  29259. return featureName.indexOf('my') === 0;
  29260. }
  29261. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(339)))
  29262. /***/ },
  29263. /* 339 */
  29264. /***/ function(module, exports) {
  29265. // shim for using process in browser
  29266. var process = module.exports = {};
  29267. var queue = [];
  29268. var draining = false;
  29269. var currentQueue;
  29270. var queueIndex = -1;
  29271. function cleanUpNextTick() {
  29272. draining = false;
  29273. if (currentQueue.length) {
  29274. queue = currentQueue.concat(queue);
  29275. } else {
  29276. queueIndex = -1;
  29277. }
  29278. if (queue.length) {
  29279. drainQueue();
  29280. }
  29281. }
  29282. function drainQueue() {
  29283. if (draining) {
  29284. return;
  29285. }
  29286. var timeout = setTimeout(cleanUpNextTick);
  29287. draining = true;
  29288. var len = queue.length;
  29289. while(len) {
  29290. currentQueue = queue;
  29291. queue = [];
  29292. while (++queueIndex < len) {
  29293. if (currentQueue) {
  29294. currentQueue[queueIndex].run();
  29295. }
  29296. }
  29297. queueIndex = -1;
  29298. len = queue.length;
  29299. }
  29300. currentQueue = null;
  29301. draining = false;
  29302. clearTimeout(timeout);
  29303. }
  29304. process.nextTick = function (fun) {
  29305. var args = new Array(arguments.length - 1);
  29306. if (arguments.length > 1) {
  29307. for (var i = 1; i < arguments.length; i++) {
  29308. args[i - 1] = arguments[i];
  29309. }
  29310. }
  29311. queue.push(new Item(fun, args));
  29312. if (queue.length === 1 && !draining) {
  29313. setTimeout(drainQueue, 0);
  29314. }
  29315. };
  29316. // v8 likes predictible objects
  29317. function Item(fun, array) {
  29318. this.fun = fun;
  29319. this.array = array;
  29320. }
  29321. Item.prototype.run = function () {
  29322. this.fun.apply(null, this.array);
  29323. };
  29324. process.title = 'browser';
  29325. process.browser = true;
  29326. process.env = {};
  29327. process.argv = [];
  29328. process.version = ''; // empty string to avoid regexp issues
  29329. process.versions = {};
  29330. function noop() {}
  29331. process.on = noop;
  29332. process.addListener = noop;
  29333. process.once = noop;
  29334. process.off = noop;
  29335. process.removeListener = noop;
  29336. process.removeAllListeners = noop;
  29337. process.emit = noop;
  29338. process.binding = function (name) {
  29339. throw new Error('process.binding is not supported');
  29340. };
  29341. process.cwd = function () { return '/' };
  29342. process.chdir = function (dir) {
  29343. throw new Error('process.chdir is not supported');
  29344. };
  29345. process.umask = function() { return 0; };
  29346. /***/ },
  29347. /* 340 */
  29348. /***/ function(module, exports, __webpack_require__) {
  29349. var env = __webpack_require__(79);
  29350. function SaveAsImage (model) {
  29351. this.model = model;
  29352. }
  29353. SaveAsImage.defaultOption = {
  29354. show: true,
  29355. 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',
  29356. title: '保存为图片',
  29357. type: 'png',
  29358. // Default use option.backgroundColor
  29359. // backgroundColor: '#fff',
  29360. name: '',
  29361. excludeComponents: ['toolbox'],
  29362. pixelRatio: 1,
  29363. lang: ['右键另存为图片']
  29364. };
  29365. SaveAsImage.prototype.unusable = !env.canvasSupported;
  29366. var proto = SaveAsImage.prototype;
  29367. proto.onclick = function (ecModel, api) {
  29368. var model = this.model;
  29369. var title = model.get('name') || ecModel.get('title.0.text') || 'echarts';
  29370. var $a = document.createElement('a');
  29371. var type = model.get('type', true) || 'png';
  29372. $a.download = title + '.' + type;
  29373. $a.target = '_blank';
  29374. var url = api.getConnectedDataURL({
  29375. type: type,
  29376. backgroundColor: model.get('backgroundColor', true)
  29377. || ecModel.get('backgroundColor') || '#fff',
  29378. excludeComponents: model.get('excludeComponents'),
  29379. pixelRatio: model.get('pixelRatio')
  29380. });
  29381. $a.href = url;
  29382. // Chrome and Firefox
  29383. if (typeof MouseEvent === 'function') {
  29384. var evt = new MouseEvent('click', {
  29385. view: window,
  29386. bubbles: true,
  29387. cancelable: false
  29388. });
  29389. $a.dispatchEvent(evt);
  29390. }
  29391. // IE
  29392. else {
  29393. var lang = model.get('lang');
  29394. var html = ''
  29395. + '<body style="margin:0;">'
  29396. + '<img src="' + url + '" style="max-width:100%;" title="' + ((lang && lang[0]) || '') + '" />'
  29397. + '</body>';
  29398. var tab = window.open();
  29399. tab.document.write(html);
  29400. }
  29401. };
  29402. __webpack_require__(337).register(
  29403. 'saveAsImage', SaveAsImage
  29404. );
  29405. module.exports = SaveAsImage;
  29406. /***/ },
  29407. /* 341 */
  29408. /***/ function(module, exports, __webpack_require__) {
  29409. 'use strict';
  29410. var zrUtil = __webpack_require__(3);
  29411. function MagicType(model) {
  29412. this.model = model;
  29413. }
  29414. MagicType.defaultOption = {
  29415. show: true,
  29416. type: [],
  29417. // Icon group
  29418. icon: {
  29419. line: 'M4.1,28.9h7.1l9.3-22l7.4,38l9.7-19.7l3,12.8h14.9M4.1,58h51.4',
  29420. bar: 'M6.7,22.9h10V48h-10V22.9zM24.9,13h10v35h-10V13zM43.2,2h10v46h-10V2zM3.1,58h53.7',
  29421. 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
  29422. tiled: 'M2.3,2.2h22.8V25H2.3V2.2z M35,2.2h22.8V25H35V2.2zM2.3,35h22.8v22.8H2.3V35z M35,35h22.8v22.8H35V35z'
  29423. },
  29424. title: {
  29425. line: '切换为折线图',
  29426. bar: '切换为柱状图',
  29427. stack: '切换为堆叠',
  29428. tiled: '切换为平铺'
  29429. },
  29430. option: {},
  29431. seriesIndex: {}
  29432. };
  29433. var proto = MagicType.prototype;
  29434. proto.getIcons = function () {
  29435. var model = this.model;
  29436. var availableIcons = model.get('icon');
  29437. var icons = {};
  29438. zrUtil.each(model.get('type'), function (type) {
  29439. if (availableIcons[type]) {
  29440. icons[type] = availableIcons[type];
  29441. }
  29442. });
  29443. return icons;
  29444. };
  29445. var seriesOptGenreator = {
  29446. 'line': function (seriesType, seriesId, seriesModel, model) {
  29447. if (seriesType === 'bar') {
  29448. return zrUtil.merge({
  29449. id: seriesId,
  29450. type: 'line',
  29451. // Preserve data related option
  29452. data: seriesModel.get('data'),
  29453. stack: seriesModel.get('stack'),
  29454. markPoint: seriesModel.get('markPoint'),
  29455. markLine: seriesModel.get('markLine')
  29456. }, model.get('option.line') || {}, true);
  29457. }
  29458. },
  29459. 'bar': function (seriesType, seriesId, seriesModel, model) {
  29460. if (seriesType === 'line') {
  29461. return zrUtil.merge({
  29462. id: seriesId,
  29463. type: 'bar',
  29464. // Preserve data related option
  29465. data: seriesModel.get('data'),
  29466. stack: seriesModel.get('stack'),
  29467. markPoint: seriesModel.get('markPoint'),
  29468. markLine: seriesModel.get('markLine')
  29469. }, model.get('option.bar') || {}, true);
  29470. }
  29471. },
  29472. 'stack': function (seriesType, seriesId, seriesModel, model) {
  29473. if (seriesType === 'line' || seriesType === 'bar') {
  29474. return zrUtil.merge({
  29475. id: seriesId,
  29476. stack: '__ec_magicType_stack__'
  29477. }, model.get('option.stack') || {}, true);
  29478. }
  29479. },
  29480. 'tiled': function (seriesType, seriesId, seriesModel, model) {
  29481. if (seriesType === 'line' || seriesType === 'bar') {
  29482. return zrUtil.merge({
  29483. id: seriesId,
  29484. stack: ''
  29485. }, model.get('option.tiled') || {}, true);
  29486. }
  29487. }
  29488. };
  29489. var radioTypes = [
  29490. ['line', 'bar'],
  29491. ['stack', 'tiled']
  29492. ];
  29493. proto.onclick = function (ecModel, api, type) {
  29494. var model = this.model;
  29495. var seriesIndex = model.get('seriesIndex.' + type);
  29496. // Not supported magicType
  29497. if (!seriesOptGenreator[type]) {
  29498. return;
  29499. }
  29500. var newOption = {
  29501. series: []
  29502. };
  29503. var generateNewSeriesTypes = function (seriesModel) {
  29504. var seriesType = seriesModel.subType;
  29505. var seriesId = seriesModel.id;
  29506. var newSeriesOpt = seriesOptGenreator[type](
  29507. seriesType, seriesId, seriesModel, model
  29508. );
  29509. if (newSeriesOpt) {
  29510. // PENDING If merge original option?
  29511. zrUtil.defaults(newSeriesOpt, seriesModel.option);
  29512. newOption.series.push(newSeriesOpt);
  29513. }
  29514. // Modify boundaryGap
  29515. var coordSys = seriesModel.coordinateSystem;
  29516. if (coordSys && coordSys.type === 'cartesian2d' && (type === 'line' || type === 'bar')) {
  29517. var categoryAxis = coordSys.getAxesByScale('ordinal')[0];
  29518. if (categoryAxis) {
  29519. var axisDim = categoryAxis.dim;
  29520. var axisIndex = seriesModel.get(axisDim + 'AxisIndex');
  29521. var axisKey = axisDim + 'Axis';
  29522. newOption[axisKey] = newOption[axisKey] || [];
  29523. for (var i = 0; i <= axisIndex; i++) {
  29524. newOption[axisKey][axisIndex] = newOption[axisKey][axisIndex] || {};
  29525. }
  29526. newOption[axisKey][axisIndex].boundaryGap = type === 'bar' ? true : false;
  29527. }
  29528. }
  29529. };
  29530. zrUtil.each(radioTypes, function (radio) {
  29531. if (zrUtil.indexOf(radio, type) >= 0) {
  29532. zrUtil.each(radio, function (item) {
  29533. model.setIconStatus(item, 'normal');
  29534. });
  29535. }
  29536. });
  29537. model.setIconStatus(type, 'emphasis');
  29538. ecModel.eachComponent(
  29539. {
  29540. mainType: 'series',
  29541. query: seriesIndex == null ? null : {
  29542. seriesIndex: seriesIndex
  29543. }
  29544. }, generateNewSeriesTypes
  29545. );
  29546. api.dispatchAction({
  29547. type: 'changeMagicType',
  29548. currentType: type,
  29549. newOption: newOption
  29550. });
  29551. };
  29552. var echarts = __webpack_require__(1);
  29553. echarts.registerAction({
  29554. type: 'changeMagicType',
  29555. event: 'magicTypeChanged',
  29556. update: 'prepareAndUpdate'
  29557. }, function (payload, ecModel) {
  29558. ecModel.mergeOption(payload.newOption);
  29559. });
  29560. __webpack_require__(337).register('magicType', MagicType);
  29561. module.exports = MagicType;
  29562. /***/ },
  29563. /* 342 */
  29564. /***/ function(module, exports, __webpack_require__) {
  29565. /**
  29566. * @module echarts/component/toolbox/feature/DataView
  29567. */
  29568. var zrUtil = __webpack_require__(3);
  29569. var eventTool = __webpack_require__(81);
  29570. var BLOCK_SPLITER = new Array(60).join('-');
  29571. var ITEM_SPLITER = '\t';
  29572. /**
  29573. * Group series into two types
  29574. * 1. on category axis, like line, bar
  29575. * 2. others, like scatter, pie
  29576. * @param {module:echarts/model/Global} ecModel
  29577. * @return {Object}
  29578. * @inner
  29579. */
  29580. function groupSeries(ecModel) {
  29581. var seriesGroupByCategoryAxis = {};
  29582. var otherSeries = [];
  29583. var meta = [];
  29584. ecModel.eachRawSeries(function (seriesModel) {
  29585. var coordSys = seriesModel.coordinateSystem;
  29586. if (coordSys && (coordSys.type === 'cartesian2d' || coordSys.type === 'polar')) {
  29587. var baseAxis = coordSys.getBaseAxis();
  29588. if (baseAxis.type === 'category') {
  29589. var key = baseAxis.dim + '_' + baseAxis.index;
  29590. if (!seriesGroupByCategoryAxis[key]) {
  29591. seriesGroupByCategoryAxis[key] = {
  29592. categoryAxis: baseAxis,
  29593. valueAxis: coordSys.getOtherAxis(baseAxis),
  29594. series: []
  29595. };
  29596. meta.push({
  29597. axisDim: baseAxis.dim,
  29598. axisIndex: baseAxis.index
  29599. });
  29600. }
  29601. seriesGroupByCategoryAxis[key].series.push(seriesModel);
  29602. }
  29603. else {
  29604. otherSeries.push(seriesModel);
  29605. }
  29606. }
  29607. else {
  29608. otherSeries.push(seriesModel);
  29609. }
  29610. });
  29611. return {
  29612. seriesGroupByCategoryAxis: seriesGroupByCategoryAxis,
  29613. other: otherSeries,
  29614. meta: meta
  29615. };
  29616. }
  29617. /**
  29618. * Assemble content of series on cateogory axis
  29619. * @param {Array.<module:echarts/model/Series>} series
  29620. * @return {string}
  29621. * @inner
  29622. */
  29623. function assembleSeriesWithCategoryAxis(series) {
  29624. var tables = [];
  29625. zrUtil.each(series, function (group, key) {
  29626. var categoryAxis = group.categoryAxis;
  29627. var valueAxis = group.valueAxis;
  29628. var valueAxisDim = valueAxis.dim;
  29629. var headers = [' '].concat(zrUtil.map(group.series, function (series) {
  29630. return series.name;
  29631. }));
  29632. var columns = [categoryAxis.model.getCategories()];
  29633. zrUtil.each(group.series, function (series) {
  29634. columns.push(series.getRawData().mapArray(valueAxisDim, function (val) {
  29635. return val;
  29636. }));
  29637. });
  29638. // Assemble table content
  29639. var lines = [headers.join(ITEM_SPLITER)];
  29640. for (var i = 0; i < columns[0].length; i++) {
  29641. var items = [];
  29642. for (var j = 0; j < columns.length; j++) {
  29643. items.push(columns[j][i]);
  29644. }
  29645. lines.push(items.join(ITEM_SPLITER));
  29646. }
  29647. tables.push(lines.join('\n'));
  29648. });
  29649. return tables.join('\n\n' + BLOCK_SPLITER + '\n\n');
  29650. }
  29651. /**
  29652. * Assemble content of other series
  29653. * @param {Array.<module:echarts/model/Series>} series
  29654. * @return {string}
  29655. * @inner
  29656. */
  29657. function assembleOtherSeries(series) {
  29658. return zrUtil.map(series, function (series) {
  29659. var data = series.getRawData();
  29660. var lines = [series.name];
  29661. var vals = [];
  29662. data.each(data.dimensions, function () {
  29663. var argLen = arguments.length;
  29664. var dataIndex = arguments[argLen - 1];
  29665. var name = data.getName(dataIndex);
  29666. for (var i = 0; i < argLen - 1; i++) {
  29667. vals[i] = arguments[i];
  29668. }
  29669. lines.push((name ? (name + ITEM_SPLITER) : '') + vals.join(ITEM_SPLITER));
  29670. });
  29671. return lines.join('\n');
  29672. }).join('\n\n' + BLOCK_SPLITER + '\n\n');
  29673. }
  29674. /**
  29675. * @param {module:echarts/model/Global}
  29676. * @return {string}
  29677. * @inner
  29678. */
  29679. function getContentFromModel(ecModel) {
  29680. var result = groupSeries(ecModel);
  29681. return {
  29682. value: zrUtil.filter([
  29683. assembleSeriesWithCategoryAxis(result.seriesGroupByCategoryAxis),
  29684. assembleOtherSeries(result.other)
  29685. ], function (str) {
  29686. return str.replace(/[\n\t\s]/g, '');
  29687. }).join('\n\n' + BLOCK_SPLITER + '\n\n'),
  29688. meta: result.meta
  29689. };
  29690. }
  29691. function trim(str) {
  29692. return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
  29693. }
  29694. /**
  29695. * If a block is tsv format
  29696. */
  29697. function isTSVFormat(block) {
  29698. // Simple method to find out if a block is tsv format
  29699. var firstLine = block.slice(0, block.indexOf('\n'));
  29700. if (firstLine.indexOf(ITEM_SPLITER) >= 0) {
  29701. return true;
  29702. }
  29703. }
  29704. var itemSplitRegex = new RegExp('[' + ITEM_SPLITER + ']+', 'g');
  29705. /**
  29706. * @param {string} tsv
  29707. * @return {Array.<Object>}
  29708. */
  29709. function parseTSVContents(tsv) {
  29710. var tsvLines = tsv.split(/\n+/g);
  29711. var headers = trim(tsvLines.shift()).split(itemSplitRegex);
  29712. var categories = [];
  29713. var series = zrUtil.map(headers, function (header) {
  29714. return {
  29715. name: header,
  29716. data: []
  29717. };
  29718. });
  29719. for (var i = 0; i < tsvLines.length; i++) {
  29720. var items = trim(tsvLines[i]).split(itemSplitRegex);
  29721. categories.push(items.shift());
  29722. for (var j = 0; j < items.length; j++) {
  29723. series[j] && (series[j].data[i] = items[j]);
  29724. }
  29725. }
  29726. return {
  29727. series: series,
  29728. categories: categories
  29729. };
  29730. }
  29731. /**
  29732. * @param {string} str
  29733. * @return {Array.<Object>}
  29734. * @inner
  29735. */
  29736. function parseListContents(str) {
  29737. var lines = str.split(/\n+/g);
  29738. var seriesName = trim(lines.shift());
  29739. var data = [];
  29740. for (var i = 0; i < lines.length; i++) {
  29741. var items = trim(lines[i]).split(itemSplitRegex);
  29742. var name = '';
  29743. var value;
  29744. var hasName = false;
  29745. if (isNaN(items[0])) { // First item is name
  29746. hasName = true;
  29747. name = items[0];
  29748. items = items.slice(1);
  29749. data[i] = {
  29750. name: name,
  29751. value: []
  29752. };
  29753. value = data[i].value;
  29754. }
  29755. else {
  29756. value = data[i] = [];
  29757. }
  29758. for (var j = 0; j < items.length; j++) {
  29759. value.push(+items[j]);
  29760. }
  29761. if (value.length === 1) {
  29762. hasName ? (data[i].value = value[0]) : (data[i] = value[0]);
  29763. }
  29764. }
  29765. return {
  29766. name: seriesName,
  29767. data: data
  29768. };
  29769. }
  29770. /**
  29771. * @param {string} str
  29772. * @param {Array.<Object>} blockMetaList
  29773. * @return {Object}
  29774. * @inner
  29775. */
  29776. function parseContents(str, blockMetaList) {
  29777. var blocks = str.split(new RegExp('\n*' + BLOCK_SPLITER + '\n*', 'g'));
  29778. var newOption = {
  29779. series: []
  29780. };
  29781. zrUtil.each(blocks, function (block, idx) {
  29782. if (isTSVFormat(block)) {
  29783. var result = parseTSVContents(block);
  29784. var blockMeta = blockMetaList[idx];
  29785. var axisKey = blockMeta.axisDim + 'Axis';
  29786. if (blockMeta) {
  29787. newOption[axisKey] = newOption[axisKey] || [];
  29788. newOption[axisKey][blockMeta.axisIndex] = {
  29789. data: result.categories
  29790. };
  29791. newOption.series = newOption.series.concat(result.series);
  29792. }
  29793. }
  29794. else {
  29795. var result = parseListContents(block);
  29796. newOption.series.push(result);
  29797. }
  29798. });
  29799. return newOption;
  29800. }
  29801. /**
  29802. * @alias {module:echarts/component/toolbox/feature/DataView}
  29803. * @constructor
  29804. * @param {module:echarts/model/Model} model
  29805. */
  29806. function DataView(model) {
  29807. this._dom = null;
  29808. this.model = model;
  29809. }
  29810. DataView.defaultOption = {
  29811. show: true,
  29812. readOnly: false,
  29813. optionToContent: null,
  29814. contentToOption: null,
  29815. 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',
  29816. title: '数据视图',
  29817. lang: ['数据视图', '关闭', '刷新'],
  29818. backgroundColor: '#fff',
  29819. textColor: '#000',
  29820. textareaColor: '#fff',
  29821. textareaBorderColor: '#333',
  29822. buttonColor: '#c23531',
  29823. buttonTextColor: '#fff'
  29824. };
  29825. DataView.prototype.onclick = function (ecModel, api) {
  29826. var container = api.getDom();
  29827. var model = this.model;
  29828. if (this._dom) {
  29829. container.removeChild(this._dom);
  29830. }
  29831. var root = document.createElement('div');
  29832. root.style.cssText = 'position:absolute;left:5px;top:5px;bottom:5px;right:5px;';
  29833. root.style.backgroundColor = model.get('backgroundColor') || '#fff';
  29834. // Create elements
  29835. var header = document.createElement('h4');
  29836. var lang = model.get('lang') || [];
  29837. header.innerHTML = lang[0] || model.get('title');
  29838. header.style.cssText = 'margin: 10px 20px;';
  29839. header.style.color = model.get('textColor');
  29840. var viewMain = document.createElement('div');
  29841. var textarea = document.createElement('textarea');
  29842. viewMain.style.cssText = 'display:block;width:100%;overflow:hidden;';
  29843. var optionToContent = model.get('optionToContent');
  29844. var contentToOption = model.get('contentToOption');
  29845. var result = getContentFromModel(ecModel);
  29846. if (typeof optionToContent === 'function') {
  29847. var htmlOrDom = optionToContent(api.getOption());
  29848. if (typeof htmlOrDom === 'string') {
  29849. viewMain.innerHTML = htmlOrDom;
  29850. }
  29851. else if (zrUtil.isDom(htmlOrDom)) {
  29852. viewMain.appendChild(htmlOrDom);
  29853. }
  29854. }
  29855. else {
  29856. // Use default textarea
  29857. viewMain.appendChild(textarea);
  29858. textarea.readOnly = model.get('readOnly');
  29859. textarea.style.cssText = 'width:100%;height:100%;font-family:monospace;font-size:14px;line-height:1.6rem;';
  29860. textarea.style.color = model.get('textColor');
  29861. textarea.style.borderColor = model.get('textareaBorderColor');
  29862. textarea.style.backgroundColor = model.get('textareaColor');
  29863. textarea.value = result.value;
  29864. }
  29865. var blockMetaList = result.meta;
  29866. var buttonContainer = document.createElement('div');
  29867. buttonContainer.style.cssText = 'position:absolute;bottom:0;left:0;right:0;';
  29868. var buttonStyle = 'float:right;margin-right:20px;border:none;'
  29869. + 'cursor:pointer;padding:2px 5px;font-size:12px;border-radius:3px';
  29870. var closeButton = document.createElement('div');
  29871. var refreshButton = document.createElement('div');
  29872. buttonStyle += ';background-color:' + model.get('buttonColor');
  29873. buttonStyle += ';color:' + model.get('buttonTextColor');
  29874. var self = this;
  29875. function close() {
  29876. container.removeChild(root);
  29877. self._dom = null;
  29878. }
  29879. eventTool.addEventListener(closeButton, 'click', close);
  29880. eventTool.addEventListener(refreshButton, 'click', function () {
  29881. var newOption;
  29882. try {
  29883. if (typeof contentToOption === 'function') {
  29884. newOption = contentToOption(viewMain, api.getOption());
  29885. }
  29886. else {
  29887. newOption = parseContents(textarea.value, blockMetaList);
  29888. }
  29889. }
  29890. catch (e) {
  29891. close();
  29892. throw new Error('Data view format error ' + e);
  29893. }
  29894. if (newOption) {
  29895. api.dispatchAction({
  29896. type: 'changeDataView',
  29897. newOption: newOption
  29898. });
  29899. }
  29900. close();
  29901. });
  29902. closeButton.innerHTML = lang[1];
  29903. refreshButton.innerHTML = lang[2];
  29904. refreshButton.style.cssText = buttonStyle;
  29905. closeButton.style.cssText = buttonStyle;
  29906. !model.get('readOnly') && buttonContainer.appendChild(refreshButton);
  29907. buttonContainer.appendChild(closeButton);
  29908. // http://stackoverflow.com/questions/6637341/use-tab-to-indent-in-textarea
  29909. eventTool.addEventListener(textarea, 'keydown', function (e) {
  29910. if ((e.keyCode || e.which) === 9) {
  29911. // get caret position/selection
  29912. var val = this.value;
  29913. var start = this.selectionStart;
  29914. var end = this.selectionEnd;
  29915. // set textarea value to: text before caret + tab + text after caret
  29916. this.value = val.substring(0, start) + ITEM_SPLITER + val.substring(end);
  29917. // put caret at right position again
  29918. this.selectionStart = this.selectionEnd = start + 1;
  29919. // prevent the focus lose
  29920. eventTool.stop(e);
  29921. }
  29922. });
  29923. root.appendChild(header);
  29924. root.appendChild(viewMain);
  29925. root.appendChild(buttonContainer);
  29926. viewMain.style.height = (container.clientHeight - 80) + 'px';
  29927. container.appendChild(root);
  29928. this._dom = root;
  29929. };
  29930. DataView.prototype.remove = function (ecModel, api) {
  29931. this._dom && api.getDom().removeChild(this._dom);
  29932. };
  29933. DataView.prototype.dispose = function (ecModel, api) {
  29934. this.remove(ecModel, api);
  29935. };
  29936. /**
  29937. * @inner
  29938. */
  29939. function tryMergeDataOption(newData, originalData) {
  29940. return zrUtil.map(newData, function (newVal, idx) {
  29941. var original = originalData && originalData[idx];
  29942. if (zrUtil.isObject(original) && !zrUtil.isArray(original)) {
  29943. if (zrUtil.isObject(newVal) && !zrUtil.isArray(newVal)) {
  29944. newVal = newVal.value;
  29945. }
  29946. // Original data has option
  29947. return zrUtil.defaults({
  29948. value: newVal
  29949. }, original);
  29950. }
  29951. else {
  29952. return newVal;
  29953. }
  29954. });
  29955. }
  29956. __webpack_require__(337).register('dataView', DataView);
  29957. __webpack_require__(1).registerAction({
  29958. type: 'changeDataView',
  29959. event: 'dataViewChanged',
  29960. update: 'prepareAndUpdate'
  29961. }, function (payload, ecModel) {
  29962. var newSeriesOptList = [];
  29963. zrUtil.each(payload.newOption.series, function (seriesOpt) {
  29964. var seriesModel = ecModel.getSeriesByName(seriesOpt.name)[0];
  29965. if (!seriesModel) {
  29966. // New created series
  29967. // Geuss the series type
  29968. newSeriesOptList.push(zrUtil.extend({
  29969. // Default is scatter
  29970. type: 'scatter'
  29971. }, seriesOpt));
  29972. }
  29973. else {
  29974. var originalData = seriesModel.get('data');
  29975. newSeriesOptList.push({
  29976. name: seriesOpt.name,
  29977. data: tryMergeDataOption(seriesOpt.data, originalData)
  29978. });
  29979. }
  29980. });
  29981. ecModel.mergeOption(zrUtil.defaults({
  29982. series: newSeriesOptList
  29983. }, payload.newOption));
  29984. });
  29985. module.exports = DataView;
  29986. /***/ },
  29987. /* 343 */
  29988. /***/ function(module, exports, __webpack_require__) {
  29989. 'use strict';
  29990. var zrUtil = __webpack_require__(3);
  29991. var numberUtil = __webpack_require__(7);
  29992. var SelectController = __webpack_require__(228);
  29993. var BoundingRect = __webpack_require__(15);
  29994. var Group = __webpack_require__(29);
  29995. var history = __webpack_require__(344);
  29996. var interactionMutex = __webpack_require__(170);
  29997. var each = zrUtil.each;
  29998. var asc = numberUtil.asc;
  29999. // Use dataZoomSelect
  30000. __webpack_require__(345);
  30001. // Spectial component id start with \0ec\0, see echarts/model/Global.js~hasInnerId
  30002. var DATA_ZOOM_ID_BASE = '\0_ec_\0toolbox-dataZoom_';
  30003. function DataZoom(model) {
  30004. this.model = model;
  30005. /**
  30006. * @private
  30007. * @type {module:zrender/container/Group}
  30008. */
  30009. this._controllerGroup;
  30010. /**
  30011. * @private
  30012. * @type {module:echarts/component/helper/SelectController}
  30013. */
  30014. this._controller;
  30015. /**
  30016. * Is zoom active.
  30017. * @private
  30018. * @type {Object}
  30019. */
  30020. this._isZoomActive;
  30021. }
  30022. DataZoom.defaultOption = {
  30023. show: true,
  30024. // Icon group
  30025. icon: {
  30026. zoom: 'M0,13.5h26.9 M13.5,26.9V0 M32.1,13.5H58V58H13.5 V32.1',
  30027. back: 'M22,1.4L9.9,13.5l12.3,12.3 M10.3,13.5H54.9v44.6 H10.3v-26'
  30028. },
  30029. title: {
  30030. zoom: '区域缩放',
  30031. back: '区域缩放还原'
  30032. }
  30033. };
  30034. var proto = DataZoom.prototype;
  30035. proto.render = function (featureModel, ecModel, api) {
  30036. updateBackBtnStatus(featureModel, ecModel);
  30037. };
  30038. proto.onclick = function (ecModel, api, type) {
  30039. var controllerGroup = this._controllerGroup;
  30040. if (!this._controllerGroup) {
  30041. controllerGroup = this._controllerGroup = new Group();
  30042. api.getZr().add(controllerGroup);
  30043. }
  30044. handlers[type].call(this, controllerGroup, this.model, ecModel, api);
  30045. };
  30046. proto.remove = function (ecModel, api) {
  30047. this._disposeController();
  30048. interactionMutex.release('globalPan', api.getZr());
  30049. };
  30050. proto.dispose = function (ecModel, api) {
  30051. var zr = api.getZr();
  30052. interactionMutex.release('globalPan', zr);
  30053. this._disposeController();
  30054. this._controllerGroup && zr.remove(this._controllerGroup);
  30055. };
  30056. /**
  30057. * @private
  30058. */
  30059. var handlers = {
  30060. zoom: function (controllerGroup, featureModel, ecModel, api) {
  30061. var isZoomActive = this._isZoomActive = !this._isZoomActive;
  30062. var zr = api.getZr();
  30063. interactionMutex[isZoomActive ? 'take' : 'release']('globalPan', zr);
  30064. featureModel.setIconStatus('zoom', isZoomActive ? 'emphasis' : 'normal');
  30065. if (isZoomActive) {
  30066. zr.setDefaultCursorStyle('crosshair');
  30067. this._createController(
  30068. controllerGroup, featureModel, ecModel, api
  30069. );
  30070. }
  30071. else {
  30072. zr.setDefaultCursorStyle('default');
  30073. this._disposeController();
  30074. }
  30075. },
  30076. back: function (controllerGroup, featureModel, ecModel, api) {
  30077. this._dispatchAction(history.pop(ecModel), api);
  30078. }
  30079. };
  30080. /**
  30081. * @private
  30082. */
  30083. proto._createController = function (
  30084. controllerGroup, featureModel, ecModel, api
  30085. ) {
  30086. var controller = this._controller = new SelectController(
  30087. 'rect',
  30088. api.getZr(),
  30089. {
  30090. // FIXME
  30091. lineWidth: 3,
  30092. stroke: '#333',
  30093. fill: 'rgba(0,0,0,0.2)'
  30094. }
  30095. );
  30096. controller.on(
  30097. 'selectEnd',
  30098. zrUtil.bind(
  30099. this._onSelected, this, controller,
  30100. featureModel, ecModel, api
  30101. )
  30102. );
  30103. controller.enable(controllerGroup, false);
  30104. };
  30105. proto._disposeController = function () {
  30106. var controller = this._controller;
  30107. if (controller) {
  30108. controller.off('selected');
  30109. controller.dispose();
  30110. }
  30111. };
  30112. function prepareCoordInfo(grid, ecModel) {
  30113. // Default use the first axis.
  30114. // FIXME
  30115. var coordInfo = [
  30116. {axisModel: grid.getAxis('x').model, axisIndex: 0}, // x
  30117. {axisModel: grid.getAxis('y').model, axisIndex: 0} // y
  30118. ];
  30119. coordInfo.grid = grid;
  30120. ecModel.eachComponent(
  30121. {mainType: 'dataZoom', subType: 'select'},
  30122. function (dzModel, dataZoomIndex) {
  30123. if (isTheAxis('xAxis', coordInfo[0].axisModel, dzModel, ecModel)) {
  30124. coordInfo[0].dataZoomModel = dzModel;
  30125. }
  30126. if (isTheAxis('yAxis', coordInfo[1].axisModel, dzModel, ecModel)) {
  30127. coordInfo[1].dataZoomModel = dzModel;
  30128. }
  30129. }
  30130. );
  30131. return coordInfo;
  30132. }
  30133. function isTheAxis(axisName, axisModel, dataZoomModel, ecModel) {
  30134. var axisIndex = dataZoomModel.get(axisName + 'Index');
  30135. return axisIndex != null
  30136. && ecModel.getComponent(axisName, axisIndex) === axisModel;
  30137. }
  30138. /**
  30139. * @private
  30140. */
  30141. proto._onSelected = function (controller, featureModel, ecModel, api, selRanges) {
  30142. if (!selRanges.length) {
  30143. return;
  30144. }
  30145. var selRange = selRanges[0];
  30146. controller.update(); // remove cover
  30147. var snapshot = {};
  30148. // FIXME
  30149. // polar
  30150. ecModel.eachComponent('grid', function (gridModel, gridIndex) {
  30151. var grid = gridModel.coordinateSystem;
  30152. var coordInfo = prepareCoordInfo(grid, ecModel);
  30153. var selDataRange = pointToDataInCartesian(selRange, coordInfo);
  30154. if (selDataRange) {
  30155. var xBatchItem = scaleCartesianAxis(selDataRange, coordInfo, 0, 'x');
  30156. var yBatchItem = scaleCartesianAxis(selDataRange, coordInfo, 1, 'y');
  30157. xBatchItem && (snapshot[xBatchItem.dataZoomId] = xBatchItem);
  30158. yBatchItem && (snapshot[yBatchItem.dataZoomId] = yBatchItem);
  30159. }
  30160. }, this);
  30161. history.push(ecModel, snapshot);
  30162. this._dispatchAction(snapshot, api);
  30163. };
  30164. function pointToDataInCartesian(selRange, coordInfo) {
  30165. var grid = coordInfo.grid;
  30166. var selRect = new BoundingRect(
  30167. selRange[0][0],
  30168. selRange[1][0],
  30169. selRange[0][1] - selRange[0][0],
  30170. selRange[1][1] - selRange[1][0]
  30171. );
  30172. if (!selRect.intersect(grid.getRect())) {
  30173. return;
  30174. }
  30175. var cartesian = grid.getCartesian(coordInfo[0].axisIndex, coordInfo[1].axisIndex);
  30176. var dataLeftTop = cartesian.pointToData([selRange[0][0], selRange[1][0]], true);
  30177. var dataRightBottom = cartesian.pointToData([selRange[0][1], selRange[1][1]], true);
  30178. return [
  30179. asc([dataLeftTop[0], dataRightBottom[0]]), // x, using asc to handle inverse
  30180. asc([dataLeftTop[1], dataRightBottom[1]]) // y, using asc to handle inverse
  30181. ];
  30182. }
  30183. function scaleCartesianAxis(selDataRange, coordInfo, dimIdx, dimName) {
  30184. var dimCoordInfo = coordInfo[dimIdx];
  30185. var dataZoomModel = dimCoordInfo.dataZoomModel;
  30186. if (dataZoomModel) {
  30187. return {
  30188. dataZoomId: dataZoomModel.id,
  30189. startValue: selDataRange[dimIdx][0],
  30190. endValue: selDataRange[dimIdx][1]
  30191. };
  30192. }
  30193. }
  30194. /**
  30195. * @private
  30196. */
  30197. proto._dispatchAction = function (snapshot, api) {
  30198. var batch = [];
  30199. each(snapshot, function (batchItem) {
  30200. batch.push(batchItem);
  30201. });
  30202. batch.length && api.dispatchAction({
  30203. type: 'dataZoom',
  30204. from: this.uid,
  30205. batch: zrUtil.clone(batch, true)
  30206. });
  30207. };
  30208. function updateBackBtnStatus(featureModel, ecModel) {
  30209. featureModel.setIconStatus(
  30210. 'back',
  30211. history.count(ecModel) > 1 ? 'emphasis' : 'normal'
  30212. );
  30213. }
  30214. __webpack_require__(337).register('dataZoom', DataZoom);
  30215. // Create special dataZoom option for select
  30216. __webpack_require__(1).registerPreprocessor(function (option) {
  30217. if (!option) {
  30218. return;
  30219. }
  30220. var dataZoomOpts = option.dataZoom || (option.dataZoom = []);
  30221. if (!zrUtil.isArray(dataZoomOpts)) {
  30222. option.dataZoom = dataZoomOpts = [dataZoomOpts];
  30223. }
  30224. var toolboxOpt = option.toolbox;
  30225. if (toolboxOpt) {
  30226. // Assume there is only one toolbox
  30227. if (zrUtil.isArray(toolboxOpt)) {
  30228. toolboxOpt = toolboxOpt[0];
  30229. }
  30230. if (toolboxOpt && toolboxOpt.feature) {
  30231. var dataZoomOpt = toolboxOpt.feature.dataZoom;
  30232. addForAxis('xAxis', dataZoomOpt);
  30233. addForAxis('yAxis', dataZoomOpt);
  30234. }
  30235. }
  30236. function addForAxis(axisName, dataZoomOpt) {
  30237. if (!dataZoomOpt) {
  30238. return;
  30239. }
  30240. var axisIndicesName = axisName + 'Index';
  30241. var givenAxisIndices = dataZoomOpt[axisIndicesName];
  30242. if (givenAxisIndices != null && !zrUtil.isArray(givenAxisIndices)) {
  30243. givenAxisIndices = givenAxisIndices === false ? [] : [givenAxisIndices];
  30244. }
  30245. forEachComponent(axisName, function (axisOpt, axisIndex) {
  30246. if (givenAxisIndices != null
  30247. && zrUtil.indexOf(givenAxisIndices, axisIndex) === -1
  30248. ) {
  30249. return;
  30250. }
  30251. var newOpt = {
  30252. type: 'select',
  30253. $fromToolbox: true,
  30254. // Id for merge mapping.
  30255. id: DATA_ZOOM_ID_BASE + axisName + axisIndex
  30256. };
  30257. // FIXME
  30258. // Only support one axis now.
  30259. newOpt[axisIndicesName] = axisIndex;
  30260. dataZoomOpts.push(newOpt);
  30261. });
  30262. }
  30263. function forEachComponent(mainType, cb) {
  30264. var opts = option[mainType];
  30265. if (!zrUtil.isArray(opts)) {
  30266. opts = opts ? [opts] : [];
  30267. }
  30268. each(opts, cb);
  30269. }
  30270. });
  30271. module.exports = DataZoom;
  30272. /***/ },
  30273. /* 344 */
  30274. /***/ function(module, exports, __webpack_require__) {
  30275. /**
  30276. * @file History manager.
  30277. */
  30278. var zrUtil = __webpack_require__(3);
  30279. var each = zrUtil.each;
  30280. var ATTR = '\0_ec_hist_store';
  30281. var history = {
  30282. /**
  30283. * @public
  30284. * @param {module:echarts/model/Global} ecModel
  30285. * @param {Object} newSnapshot {dataZoomId, batch: [payloadInfo, ...]}
  30286. */
  30287. push: function (ecModel, newSnapshot) {
  30288. var store = giveStore(ecModel);
  30289. // If previous dataZoom can not be found,
  30290. // complete an range with current range.
  30291. each(newSnapshot, function (batchItem, dataZoomId) {
  30292. var i = store.length - 1;
  30293. for (; i >= 0; i--) {
  30294. var snapshot = store[i];
  30295. if (snapshot[dataZoomId]) {
  30296. break;
  30297. }
  30298. }
  30299. if (i < 0) {
  30300. // No origin range set, create one by current range.
  30301. var dataZoomModel = ecModel.queryComponents(
  30302. {mainType: 'dataZoom', subType: 'select', id: dataZoomId}
  30303. )[0];
  30304. if (dataZoomModel) {
  30305. var percentRange = dataZoomModel.getPercentRange();
  30306. store[0][dataZoomId] = {
  30307. dataZoomId: dataZoomId,
  30308. start: percentRange[0],
  30309. end: percentRange[1]
  30310. };
  30311. }
  30312. }
  30313. });
  30314. store.push(newSnapshot);
  30315. },
  30316. /**
  30317. * @public
  30318. * @param {module:echarts/model/Global} ecModel
  30319. * @return {Object} snapshot
  30320. */
  30321. pop: function (ecModel) {
  30322. var store = giveStore(ecModel);
  30323. var head = store[store.length - 1];
  30324. store.length > 1 && store.pop();
  30325. // Find top for all dataZoom.
  30326. var snapshot = {};
  30327. each(head, function (batchItem, dataZoomId) {
  30328. for (var i = store.length - 1; i >= 0; i--) {
  30329. var batchItem = store[i][dataZoomId];
  30330. if (batchItem) {
  30331. snapshot[dataZoomId] = batchItem;
  30332. break;
  30333. }
  30334. }
  30335. });
  30336. return snapshot;
  30337. },
  30338. /**
  30339. * @public
  30340. */
  30341. clear: function (ecModel) {
  30342. ecModel[ATTR] = null;
  30343. },
  30344. /**
  30345. * @public
  30346. * @param {module:echarts/model/Global} ecModel
  30347. * @return {number} records. always >= 1.
  30348. */
  30349. count: function (ecModel) {
  30350. return giveStore(ecModel).length;
  30351. }
  30352. };
  30353. /**
  30354. * [{key: dataZoomId, value: {dataZoomId, range}}, ...]
  30355. * History length of each dataZoom may be different.
  30356. * this._history[0] is used to store origin range.
  30357. * @type {Array.<Object>}
  30358. */
  30359. function giveStore(ecModel) {
  30360. var store = ecModel[ATTR];
  30361. if (!store) {
  30362. store = ecModel[ATTR] = [{}];
  30363. }
  30364. return store;
  30365. }
  30366. module.exports = history;
  30367. /***/ },
  30368. /* 345 */
  30369. /***/ function(module, exports, __webpack_require__) {
  30370. /**
  30371. * DataZoom component entry
  30372. */
  30373. __webpack_require__(291);
  30374. __webpack_require__(292);
  30375. __webpack_require__(294);
  30376. __webpack_require__(346);
  30377. __webpack_require__(347);
  30378. __webpack_require__(302);
  30379. __webpack_require__(303);
  30380. /***/ },
  30381. /* 346 */
  30382. /***/ function(module, exports, __webpack_require__) {
  30383. /**
  30384. * @file Data zoom model
  30385. */
  30386. var DataZoomModel = __webpack_require__(292);
  30387. module.exports = DataZoomModel.extend({
  30388. type: 'dataZoom.select'
  30389. });
  30390. /***/ },
  30391. /* 347 */
  30392. /***/ function(module, exports, __webpack_require__) {
  30393. module.exports = __webpack_require__(294).extend({
  30394. type: 'dataZoom.select'
  30395. });
  30396. /***/ },
  30397. /* 348 */
  30398. /***/ function(module, exports, __webpack_require__) {
  30399. 'use strict';
  30400. var history = __webpack_require__(344);
  30401. function Restore(model) {
  30402. this.model = model;
  30403. }
  30404. Restore.defaultOption = {
  30405. show: true,
  30406. 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',
  30407. title: '还原'
  30408. };
  30409. var proto = Restore.prototype;
  30410. proto.onclick = function (ecModel, api, type) {
  30411. history.clear(ecModel);
  30412. api.dispatchAction({
  30413. type: 'restore',
  30414. from: this.uid
  30415. });
  30416. };
  30417. __webpack_require__(337).register('restore', Restore);
  30418. __webpack_require__(1).registerAction(
  30419. {type: 'restore', event: 'restore', update: 'prepareAndUpdate'},
  30420. function (payload, ecModel) {
  30421. ecModel.resetOption('recreate');
  30422. }
  30423. );
  30424. module.exports = Restore;
  30425. /***/ },
  30426. /* 349 */
  30427. /***/ function(module, exports, __webpack_require__) {
  30428. __webpack_require__(350);
  30429. __webpack_require__(78).registerPainter('vml', __webpack_require__(352));
  30430. /***/ },
  30431. /* 350 */
  30432. /***/ function(module, exports, __webpack_require__) {
  30433. // http://www.w3.org/TR/NOTE-VML
  30434. // TODO Use proxy like svg instead of overwrite brush methods
  30435. if (!__webpack_require__(79).canvasSupported) {
  30436. var vec2 = __webpack_require__(16);
  30437. var BoundingRect = __webpack_require__(15);
  30438. var CMD = __webpack_require__(48).CMD;
  30439. var colorTool = __webpack_require__(38);
  30440. var textContain = __webpack_require__(14);
  30441. var RectText = __webpack_require__(47);
  30442. var Displayable = __webpack_require__(45);
  30443. var ZImage = __webpack_require__(59);
  30444. var Text = __webpack_require__(62);
  30445. var Path = __webpack_require__(44);
  30446. var Gradient = __webpack_require__(4);
  30447. var vmlCore = __webpack_require__(351);
  30448. var round = Math.round;
  30449. var sqrt = Math.sqrt;
  30450. var abs = Math.abs;
  30451. var cos = Math.cos;
  30452. var sin = Math.sin;
  30453. var mathMax = Math.max;
  30454. var applyTransform = vec2.applyTransform;
  30455. var comma = ',';
  30456. var imageTransformPrefix = 'progid:DXImageTransform.Microsoft';
  30457. var Z = 21600;
  30458. var Z2 = Z / 2;
  30459. var ZLEVEL_BASE = 100000;
  30460. var Z_BASE = 1000;
  30461. var initRootElStyle = function (el) {
  30462. el.style.cssText = 'position:absolute;left:0;top:0;width:1px;height:1px;';
  30463. el.coordsize = Z + ',' + Z;
  30464. el.coordorigin = '0,0';
  30465. };
  30466. var encodeHtmlAttribute = function (s) {
  30467. return String(s).replace(/&/g, '&amp;').replace(/"/g, '&quot;');
  30468. };
  30469. var rgb2Str = function (r, g, b) {
  30470. return 'rgb(' + [r, g, b].join(',') + ')';
  30471. };
  30472. var append = function (parent, child) {
  30473. if (child && parent && child.parentNode !== parent) {
  30474. parent.appendChild(child);
  30475. }
  30476. };
  30477. var remove = function (parent, child) {
  30478. if (child && parent && child.parentNode === parent) {
  30479. parent.removeChild(child);
  30480. }
  30481. };
  30482. var getZIndex = function (zlevel, z, z2) {
  30483. // z 的取值范围为 [0, 1000]
  30484. return (parseFloat(zlevel) || 0) * ZLEVEL_BASE + (parseFloat(z) || 0) * Z_BASE + z2;
  30485. };
  30486. var parsePercent = function (value, maxValue) {
  30487. if (typeof value === 'string') {
  30488. if (value.lastIndexOf('%') >= 0) {
  30489. return parseFloat(value) / 100 * maxValue;
  30490. }
  30491. return parseFloat(value);
  30492. }
  30493. return value;
  30494. };
  30495. /***************************************************
  30496. * PATH
  30497. **************************************************/
  30498. var setColorAndOpacity = function (el, color, opacity) {
  30499. var colorArr = colorTool.parse(color);
  30500. opacity = +opacity;
  30501. if (isNaN(opacity)) {
  30502. opacity = 1;
  30503. }
  30504. if (colorArr) {
  30505. el.color = rgb2Str(colorArr[0], colorArr[1], colorArr[2]);
  30506. el.opacity = opacity * colorArr[3];
  30507. }
  30508. };
  30509. var getColorAndAlpha = function (color) {
  30510. var colorArr = colorTool.parse(color);
  30511. return [
  30512. rgb2Str(colorArr[0], colorArr[1], colorArr[2]),
  30513. colorArr[3]
  30514. ];
  30515. };
  30516. var updateFillNode = function (el, style, zrEl) {
  30517. // TODO pattern
  30518. var fill = style.fill;
  30519. if (fill != null) {
  30520. // Modified from excanvas
  30521. if (fill instanceof Gradient) {
  30522. var gradientType;
  30523. var angle = 0;
  30524. var focus = [0, 0];
  30525. // additional offset
  30526. var shift = 0;
  30527. // scale factor for offset
  30528. var expansion = 1;
  30529. var rect = zrEl.getBoundingRect();
  30530. var rectWidth = rect.width;
  30531. var rectHeight = rect.height;
  30532. if (fill.type === 'linear') {
  30533. gradientType = 'gradient';
  30534. var transform = zrEl.transform;
  30535. var p0 = [fill.x * rectWidth, fill.y * rectHeight];
  30536. var p1 = [fill.x2 * rectWidth, fill.y2 * rectHeight];
  30537. if (transform) {
  30538. applyTransform(p0, p0, transform);
  30539. applyTransform(p1, p1, transform);
  30540. }
  30541. var dx = p1[0] - p0[0];
  30542. var dy = p1[1] - p0[1];
  30543. angle = Math.atan2(dx, dy) * 180 / Math.PI;
  30544. // The angle should be a non-negative number.
  30545. if (angle < 0) {
  30546. angle += 360;
  30547. }
  30548. // Very small angles produce an unexpected result because they are
  30549. // converted to a scientific notation string.
  30550. if (angle < 1e-6) {
  30551. angle = 0;
  30552. }
  30553. }
  30554. else {
  30555. gradientType = 'gradientradial';
  30556. var p0 = [fill.x * rectWidth, fill.y * rectHeight];
  30557. var transform = zrEl.transform;
  30558. var scale = zrEl.scale;
  30559. var width = rectWidth;
  30560. var height = rectHeight;
  30561. focus = [
  30562. // Percent in bounding rect
  30563. (p0[0] - rect.x) / width,
  30564. (p0[1] - rect.y) / height
  30565. ];
  30566. if (transform) {
  30567. applyTransform(p0, p0, transform);
  30568. }
  30569. width /= scale[0] * Z;
  30570. height /= scale[1] * Z;
  30571. var dimension = mathMax(width, height);
  30572. shift = 2 * 0 / dimension;
  30573. expansion = 2 * fill.r / dimension - shift;
  30574. }
  30575. // We need to sort the color stops in ascending order by offset,
  30576. // otherwise IE won't interpret it correctly.
  30577. var stops = fill.colorStops.slice();
  30578. stops.sort(function(cs1, cs2) {
  30579. return cs1.offset - cs2.offset;
  30580. });
  30581. var length = stops.length;
  30582. // Color and alpha list of first and last stop
  30583. var colorAndAlphaList = [];
  30584. var colors = [];
  30585. for (var i = 0; i < length; i++) {
  30586. var stop = stops[i];
  30587. var colorAndAlpha = getColorAndAlpha(stop.color);
  30588. colors.push(stop.offset * expansion + shift + ' ' + colorAndAlpha[0]);
  30589. if (i === 0 || i === length - 1) {
  30590. colorAndAlphaList.push(colorAndAlpha);
  30591. }
  30592. }
  30593. if (length >= 2) {
  30594. var color1 = colorAndAlphaList[0][0];
  30595. var color2 = colorAndAlphaList[1][0];
  30596. var opacity1 = colorAndAlphaList[0][1] * style.opacity;
  30597. var opacity2 = colorAndAlphaList[1][1] * style.opacity;
  30598. el.type = gradientType;
  30599. el.method = 'none';
  30600. el.focus = '100%';
  30601. el.angle = angle;
  30602. el.color = color1;
  30603. el.color2 = color2;
  30604. el.colors = colors.join(',');
  30605. // When colors attribute is used, the meanings of opacity and o:opacity2
  30606. // are reversed.
  30607. el.opacity = opacity2;
  30608. // FIXME g_o_:opacity ?
  30609. el.opacity2 = opacity1;
  30610. }
  30611. if (gradientType === 'radial') {
  30612. el.focusposition = focus.join(',');
  30613. }
  30614. }
  30615. else {
  30616. // FIXME Change from Gradient fill to color fill
  30617. setColorAndOpacity(el, fill, style.opacity);
  30618. }
  30619. }
  30620. };
  30621. var updateStrokeNode = function (el, style) {
  30622. if (style.lineJoin != null) {
  30623. el.joinstyle = style.lineJoin;
  30624. }
  30625. if (style.miterLimit != null) {
  30626. el.miterlimit = style.miterLimit * Z;
  30627. }
  30628. if (style.lineCap != null) {
  30629. el.endcap = style.lineCap;
  30630. }
  30631. if (style.lineDash != null) {
  30632. el.dashstyle = style.lineDash.join(' ');
  30633. }
  30634. if (style.stroke != null && !(style.stroke instanceof Gradient)) {
  30635. setColorAndOpacity(el, style.stroke, style.opacity);
  30636. }
  30637. };
  30638. var updateFillAndStroke = function (vmlEl, type, style, zrEl) {
  30639. var isFill = type == 'fill';
  30640. var el = vmlEl.getElementsByTagName(type)[0];
  30641. // Stroke must have lineWidth
  30642. if (style[type] != null && style[type] !== 'none' && (isFill || (!isFill && style.lineWidth))) {
  30643. vmlEl[isFill ? 'filled' : 'stroked'] = 'true';
  30644. // FIXME Remove before updating, or set `colors` will throw error
  30645. if (style[type] instanceof Gradient) {
  30646. remove(vmlEl, el);
  30647. }
  30648. if (!el) {
  30649. el = vmlCore.createNode(type);
  30650. }
  30651. isFill ? updateFillNode(el, style, zrEl) : updateStrokeNode(el, style);
  30652. append(vmlEl, el);
  30653. }
  30654. else {
  30655. vmlEl[isFill ? 'filled' : 'stroked'] = 'false';
  30656. remove(vmlEl, el);
  30657. }
  30658. };
  30659. var points = [[], [], []];
  30660. var pathDataToString = function (data, m) {
  30661. var M = CMD.M;
  30662. var C = CMD.C;
  30663. var L = CMD.L;
  30664. var A = CMD.A;
  30665. var Q = CMD.Q;
  30666. var str = [];
  30667. var nPoint;
  30668. var cmdStr;
  30669. var cmd;
  30670. var i;
  30671. var xi;
  30672. var yi;
  30673. for (i = 0; i < data.length;) {
  30674. cmd = data[i++];
  30675. cmdStr = '';
  30676. nPoint = 0;
  30677. switch (cmd) {
  30678. case M:
  30679. cmdStr = ' m ';
  30680. nPoint = 1;
  30681. xi = data[i++];
  30682. yi = data[i++];
  30683. points[0][0] = xi;
  30684. points[0][1] = yi;
  30685. break;
  30686. case L:
  30687. cmdStr = ' l ';
  30688. nPoint = 1;
  30689. xi = data[i++];
  30690. yi = data[i++];
  30691. points[0][0] = xi;
  30692. points[0][1] = yi;
  30693. break;
  30694. case Q:
  30695. case C:
  30696. cmdStr = ' c ';
  30697. nPoint = 3;
  30698. var x1 = data[i++];
  30699. var y1 = data[i++];
  30700. var x2 = data[i++];
  30701. var y2 = data[i++];
  30702. var x3;
  30703. var y3;
  30704. if (cmd === Q) {
  30705. // Convert quadratic to cubic using degree elevation
  30706. x3 = x2;
  30707. y3 = y2;
  30708. x2 = (x2 + 2 * x1) / 3;
  30709. y2 = (y2 + 2 * y1) / 3;
  30710. x1 = (xi + 2 * x1) / 3;
  30711. y1 = (yi + 2 * y1) / 3;
  30712. }
  30713. else {
  30714. x3 = data[i++];
  30715. y3 = data[i++];
  30716. }
  30717. points[0][0] = x1;
  30718. points[0][1] = y1;
  30719. points[1][0] = x2;
  30720. points[1][1] = y2;
  30721. points[2][0] = x3;
  30722. points[2][1] = y3;
  30723. xi = x3;
  30724. yi = y3;
  30725. break;
  30726. case A:
  30727. var x = 0;
  30728. var y = 0;
  30729. var sx = 1;
  30730. var sy = 1;
  30731. var angle = 0;
  30732. if (m) {
  30733. // Extract SRT from matrix
  30734. x = m[4];
  30735. y = m[5];
  30736. sx = sqrt(m[0] * m[0] + m[1] * m[1]);
  30737. sy = sqrt(m[2] * m[2] + m[3] * m[3]);
  30738. angle = Math.atan2(-m[1] / sy, m[0] / sx);
  30739. }
  30740. var cx = data[i++];
  30741. var cy = data[i++];
  30742. var rx = data[i++];
  30743. var ry = data[i++];
  30744. var startAngle = data[i++] + angle;
  30745. var endAngle = data[i++] + startAngle + angle;
  30746. // FIXME
  30747. // var psi = data[i++];
  30748. i++;
  30749. var clockwise = data[i++];
  30750. var x0 = cx + cos(startAngle) * rx;
  30751. var y0 = cy + sin(startAngle) * ry;
  30752. var x1 = cx + cos(endAngle) * rx;
  30753. var y1 = cy + sin(endAngle) * ry;
  30754. var type = clockwise ? ' wa ' : ' at ';
  30755. if (Math.abs(x0 - x1) < 1e-10) {
  30756. // IE won't render arches drawn counter clockwise if x0 == x1.
  30757. if (Math.abs(endAngle - startAngle) > 1e-2) {
  30758. // Offset x0 by 1/80 of a pixel. Use something
  30759. // that can be represented in binary
  30760. if (clockwise) {
  30761. x0 += 270 / Z;
  30762. }
  30763. }
  30764. else {
  30765. // Avoid case draw full circle
  30766. if (Math.abs(y0 - cy) < 1e-10) {
  30767. if ((clockwise && x0 < cx) || (!clockwise && x0 > cx)) {
  30768. y1 -= 270 / Z;
  30769. }
  30770. else {
  30771. y1 += 270 / Z;
  30772. }
  30773. }
  30774. else if ((clockwise && y0 < cy) || (!clockwise && y0 > cy)) {
  30775. x1 += 270 / Z;
  30776. }
  30777. else {
  30778. x1 -= 270 / Z;
  30779. }
  30780. }
  30781. }
  30782. str.push(
  30783. type,
  30784. round(((cx - rx) * sx + x) * Z - Z2), comma,
  30785. round(((cy - ry) * sy + y) * Z - Z2), comma,
  30786. round(((cx + rx) * sx + x) * Z - Z2), comma,
  30787. round(((cy + ry) * sy + y) * Z - Z2), comma,
  30788. round((x0 * sx + x) * Z - Z2), comma,
  30789. round((y0 * sy + y) * Z - Z2), comma,
  30790. round((x1 * sx + x) * Z - Z2), comma,
  30791. round((y1 * sy + y) * Z - Z2)
  30792. );
  30793. xi = x1;
  30794. yi = y1;
  30795. break;
  30796. case CMD.R:
  30797. var p0 = points[0];
  30798. var p1 = points[1];
  30799. // x0, y0
  30800. p0[0] = data[i++];
  30801. p0[1] = data[i++];
  30802. // x1, y1
  30803. p1[0] = p0[0] + data[i++];
  30804. p1[1] = p0[1] + data[i++];
  30805. if (m) {
  30806. applyTransform(p0, p0, m);
  30807. applyTransform(p1, p1, m);
  30808. }
  30809. p0[0] = round(p0[0] * Z - Z2);
  30810. p1[0] = round(p1[0] * Z - Z2);
  30811. p0[1] = round(p0[1] * Z - Z2);
  30812. p1[1] = round(p1[1] * Z - Z2);
  30813. str.push(
  30814. // x0, y0
  30815. ' m ', p0[0], comma, p0[1],
  30816. // x1, y0
  30817. ' l ', p1[0], comma, p0[1],
  30818. // x1, y1
  30819. ' l ', p1[0], comma, p1[1],
  30820. // x0, y1
  30821. ' l ', p0[0], comma, p1[1]
  30822. );
  30823. break;
  30824. case CMD.Z:
  30825. // FIXME Update xi, yi
  30826. str.push(' x ');
  30827. }
  30828. if (nPoint > 0) {
  30829. str.push(cmdStr);
  30830. for (var k = 0; k < nPoint; k++) {
  30831. var p = points[k];
  30832. m && applyTransform(p, p, m);
  30833. // 不 round 会非常慢
  30834. str.push(
  30835. round(p[0] * Z - Z2), comma, round(p[1] * Z - Z2),
  30836. k < nPoint - 1 ? comma : ''
  30837. );
  30838. }
  30839. }
  30840. }
  30841. return str.join('');
  30842. };
  30843. // Rewrite the original path method
  30844. Path.prototype.brushVML = function (vmlRoot) {
  30845. var style = this.style;
  30846. var vmlEl = this._vmlEl;
  30847. if (!vmlEl) {
  30848. vmlEl = vmlCore.createNode('shape');
  30849. initRootElStyle(vmlEl);
  30850. this._vmlEl = vmlEl;
  30851. }
  30852. updateFillAndStroke(vmlEl, 'fill', style, this);
  30853. updateFillAndStroke(vmlEl, 'stroke', style, this);
  30854. var m = this.transform;
  30855. var needTransform = m != null;
  30856. var strokeEl = vmlEl.getElementsByTagName('stroke')[0];
  30857. if (strokeEl) {
  30858. var lineWidth = style.lineWidth;
  30859. // Get the line scale.
  30860. // Determinant of this.m_ means how much the area is enlarged by the
  30861. // transformation. So its square root can be used as a scale factor
  30862. // for width.
  30863. if (needTransform && !style.strokeNoScale) {
  30864. var det = m[0] * m[3] - m[1] * m[2];
  30865. lineWidth *= sqrt(abs(det));
  30866. }
  30867. strokeEl.weight = lineWidth + 'px';
  30868. }
  30869. var path = this.path;
  30870. if (this.__dirtyPath) {
  30871. path.beginPath();
  30872. this.buildPath(path, this.shape);
  30873. path.toStatic();
  30874. this.__dirtyPath = false;
  30875. }
  30876. vmlEl.path = pathDataToString(path.data, this.transform);
  30877. vmlEl.style.zIndex = getZIndex(this.zlevel, this.z, this.z2);
  30878. // Append to root
  30879. append(vmlRoot, vmlEl);
  30880. // Text
  30881. if (style.text) {
  30882. this.drawRectText(vmlRoot, this.getBoundingRect());
  30883. }
  30884. else {
  30885. this.removeRectText(vmlRoot);
  30886. }
  30887. };
  30888. Path.prototype.onRemove = function (vmlRoot) {
  30889. remove(vmlRoot, this._vmlEl);
  30890. this.removeRectText(vmlRoot);
  30891. };
  30892. Path.prototype.onAdd = function (vmlRoot) {
  30893. append(vmlRoot, this._vmlEl);
  30894. this.appendRectText(vmlRoot);
  30895. };
  30896. /***************************************************
  30897. * IMAGE
  30898. **************************************************/
  30899. var isImage = function (img) {
  30900. // FIXME img instanceof Image 如果 img 是一个字符串的时候,IE8 下会报错
  30901. return (typeof img === 'object') && img.tagName && img.tagName.toUpperCase() === 'IMG';
  30902. // return img instanceof Image;
  30903. };
  30904. // Rewrite the original path method
  30905. ZImage.prototype.brushVML = function (vmlRoot) {
  30906. var style = this.style;
  30907. var image = style.image;
  30908. // Image original width, height
  30909. var ow;
  30910. var oh;
  30911. if (isImage(image)) {
  30912. var src = image.src;
  30913. if (src === this._imageSrc) {
  30914. ow = this._imageWidth;
  30915. oh = this._imageHeight;
  30916. }
  30917. else {
  30918. var imageRuntimeStyle = image.runtimeStyle;
  30919. var oldRuntimeWidth = imageRuntimeStyle.width;
  30920. var oldRuntimeHeight = imageRuntimeStyle.height;
  30921. imageRuntimeStyle.width = 'auto';
  30922. imageRuntimeStyle.height = 'auto';
  30923. // get the original size
  30924. ow = image.width;
  30925. oh = image.height;
  30926. // and remove overides
  30927. imageRuntimeStyle.width = oldRuntimeWidth;
  30928. imageRuntimeStyle.height = oldRuntimeHeight;
  30929. // Caching image original width, height and src
  30930. this._imageSrc = src;
  30931. this._imageWidth = ow;
  30932. this._imageHeight = oh;
  30933. }
  30934. image = src;
  30935. }
  30936. else {
  30937. if (image === this._imageSrc) {
  30938. ow = this._imageWidth;
  30939. oh = this._imageHeight;
  30940. }
  30941. }
  30942. if (!image) {
  30943. return;
  30944. }
  30945. var x = style.x || 0;
  30946. var y = style.y || 0;
  30947. var dw = style.width;
  30948. var dh = style.height;
  30949. var sw = style.sWidth;
  30950. var sh = style.sHeight;
  30951. var sx = style.sx || 0;
  30952. var sy = style.sy || 0;
  30953. var hasCrop = sw && sh;
  30954. var vmlEl = this._vmlEl;
  30955. if (!vmlEl) {
  30956. // FIXME 使用 group 在 left, top 都不是 0 的时候就无法显示了。
  30957. // vmlEl = vmlCore.createNode('group');
  30958. vmlEl = vmlCore.doc.createElement('div');
  30959. initRootElStyle(vmlEl);
  30960. this._vmlEl = vmlEl;
  30961. }
  30962. var vmlElStyle = vmlEl.style;
  30963. var hasRotation = false;
  30964. var m;
  30965. var scaleX = 1;
  30966. var scaleY = 1;
  30967. if (this.transform) {
  30968. m = this.transform;
  30969. scaleX = sqrt(m[0] * m[0] + m[1] * m[1]);
  30970. scaleY = sqrt(m[2] * m[2] + m[3] * m[3]);
  30971. hasRotation = m[1] || m[2];
  30972. }
  30973. if (hasRotation) {
  30974. // If filters are necessary (rotation exists), create them
  30975. // filters are bog-slow, so only create them if abbsolutely necessary
  30976. // The following check doesn't account for skews (which don't exist
  30977. // in the canvas spec (yet) anyway.
  30978. // From excanvas
  30979. var p0 = [x, y];
  30980. var p1 = [x + dw, y];
  30981. var p2 = [x, y + dh];
  30982. var p3 = [x + dw, y + dh];
  30983. applyTransform(p0, p0, m);
  30984. applyTransform(p1, p1, m);
  30985. applyTransform(p2, p2, m);
  30986. applyTransform(p3, p3, m);
  30987. var maxX = mathMax(p0[0], p1[0], p2[0], p3[0]);
  30988. var maxY = mathMax(p0[1], p1[1], p2[1], p3[1]);
  30989. var transformFilter = [];
  30990. transformFilter.push('M11=', m[0] / scaleX, comma,
  30991. 'M12=', m[2] / scaleY, comma,
  30992. 'M21=', m[1] / scaleX, comma,
  30993. 'M22=', m[3] / scaleY, comma,
  30994. 'Dx=', round(x * scaleX + m[4]), comma,
  30995. 'Dy=', round(y * scaleY + m[5]));
  30996. vmlElStyle.padding = '0 ' + round(maxX) + 'px ' + round(maxY) + 'px 0';
  30997. // FIXME DXImageTransform 在 IE11 的兼容模式下不起作用
  30998. vmlElStyle.filter = imageTransformPrefix + '.Matrix('
  30999. + transformFilter.join('') + ', SizingMethod=clip)';
  31000. }
  31001. else {
  31002. if (m) {
  31003. x = x * scaleX + m[4];
  31004. y = y * scaleY + m[5];
  31005. }
  31006. vmlElStyle.filter = '';
  31007. vmlElStyle.left = round(x) + 'px';
  31008. vmlElStyle.top = round(y) + 'px';
  31009. }
  31010. var imageEl = this._imageEl;
  31011. var cropEl = this._cropEl;
  31012. if (!imageEl) {
  31013. imageEl = vmlCore.doc.createElement('div');
  31014. this._imageEl = imageEl;
  31015. }
  31016. var imageELStyle = imageEl.style;
  31017. if (hasCrop) {
  31018. // Needs know image original width and height
  31019. if (! (ow && oh)) {
  31020. var tmpImage = new Image();
  31021. var self = this;
  31022. tmpImage.onload = function () {
  31023. tmpImage.onload = null;
  31024. ow = tmpImage.width;
  31025. oh = tmpImage.height;
  31026. // Adjust image width and height to fit the ratio destinationSize / sourceSize
  31027. imageELStyle.width = round(scaleX * ow * dw / sw) + 'px';
  31028. imageELStyle.height = round(scaleY * oh * dh / sh) + 'px';
  31029. // Caching image original width, height and src
  31030. self._imageWidth = ow;
  31031. self._imageHeight = oh;
  31032. self._imageSrc = image;
  31033. };
  31034. tmpImage.src = image;
  31035. }
  31036. else {
  31037. imageELStyle.width = round(scaleX * ow * dw / sw) + 'px';
  31038. imageELStyle.height = round(scaleY * oh * dh / sh) + 'px';
  31039. }
  31040. if (! cropEl) {
  31041. cropEl = vmlCore.doc.createElement('div');
  31042. cropEl.style.overflow = 'hidden';
  31043. this._cropEl = cropEl;
  31044. }
  31045. var cropElStyle = cropEl.style;
  31046. cropElStyle.width = round((dw + sx * dw / sw) * scaleX);
  31047. cropElStyle.height = round((dh + sy * dh / sh) * scaleY);
  31048. cropElStyle.filter = imageTransformPrefix + '.Matrix(Dx='
  31049. + (-sx * dw / sw * scaleX) + ',Dy=' + (-sy * dh / sh * scaleY) + ')';
  31050. if (! cropEl.parentNode) {
  31051. vmlEl.appendChild(cropEl);
  31052. }
  31053. if (imageEl.parentNode != cropEl) {
  31054. cropEl.appendChild(imageEl);
  31055. }
  31056. }
  31057. else {
  31058. imageELStyle.width = round(scaleX * dw) + 'px';
  31059. imageELStyle.height = round(scaleY * dh) + 'px';
  31060. vmlEl.appendChild(imageEl);
  31061. if (cropEl && cropEl.parentNode) {
  31062. vmlEl.removeChild(cropEl);
  31063. this._cropEl = null;
  31064. }
  31065. }
  31066. var filterStr = '';
  31067. var alpha = style.opacity;
  31068. if (alpha < 1) {
  31069. filterStr += '.Alpha(opacity=' + round(alpha * 100) + ') ';
  31070. }
  31071. filterStr += imageTransformPrefix + '.AlphaImageLoader(src=' + image + ', SizingMethod=scale)';
  31072. imageELStyle.filter = filterStr;
  31073. vmlEl.style.zIndex = getZIndex(this.zlevel, this.z, this.z2);
  31074. // Append to root
  31075. append(vmlRoot, vmlEl);
  31076. // Text
  31077. if (style.text) {
  31078. this.drawRectText(vmlRoot, this.getBoundingRect());
  31079. }
  31080. };
  31081. ZImage.prototype.onRemove = function (vmlRoot) {
  31082. remove(vmlRoot, this._vmlEl);
  31083. this._vmlEl = null;
  31084. this._cropEl = null;
  31085. this._imageEl = null;
  31086. this.removeRectText(vmlRoot);
  31087. };
  31088. ZImage.prototype.onAdd = function (vmlRoot) {
  31089. append(vmlRoot, this._vmlEl);
  31090. this.appendRectText(vmlRoot);
  31091. };
  31092. /***************************************************
  31093. * TEXT
  31094. **************************************************/
  31095. var DEFAULT_STYLE_NORMAL = 'normal';
  31096. var fontStyleCache = {};
  31097. var fontStyleCacheCount = 0;
  31098. var MAX_FONT_CACHE_SIZE = 100;
  31099. var fontEl = document.createElement('div');
  31100. var getFontStyle = function (fontString) {
  31101. var fontStyle = fontStyleCache[fontString];
  31102. if (!fontStyle) {
  31103. // Clear cache
  31104. if (fontStyleCacheCount > MAX_FONT_CACHE_SIZE) {
  31105. fontStyleCacheCount = 0;
  31106. fontStyleCache = {};
  31107. }
  31108. var style = fontEl.style;
  31109. var fontFamily;
  31110. try {
  31111. style.font = fontString;
  31112. fontFamily = style.fontFamily.split(',')[0];
  31113. }
  31114. catch (e) {
  31115. }
  31116. fontStyle = {
  31117. style: style.fontStyle || DEFAULT_STYLE_NORMAL,
  31118. variant: style.fontVariant || DEFAULT_STYLE_NORMAL,
  31119. weight: style.fontWeight || DEFAULT_STYLE_NORMAL,
  31120. size: parseFloat(style.fontSize || 12) | 0,
  31121. family: fontFamily || 'Microsoft YaHei'
  31122. };
  31123. fontStyleCache[fontString] = fontStyle;
  31124. fontStyleCacheCount++;
  31125. }
  31126. return fontStyle;
  31127. };
  31128. var textMeasureEl;
  31129. // Overwrite measure text method
  31130. textContain.measureText = function (text, textFont) {
  31131. var doc = vmlCore.doc;
  31132. if (!textMeasureEl) {
  31133. textMeasureEl = doc.createElement('div');
  31134. textMeasureEl.style.cssText = 'position:absolute;top:-20000px;left:0;'
  31135. + 'padding:0;margin:0;border:none;white-space:pre;';
  31136. vmlCore.doc.body.appendChild(textMeasureEl);
  31137. }
  31138. try {
  31139. textMeasureEl.style.font = textFont;
  31140. } catch (ex) {
  31141. // Ignore failures to set to invalid font.
  31142. }
  31143. textMeasureEl.innerHTML = '';
  31144. // Don't use innerHTML or innerText because they allow markup/whitespace.
  31145. textMeasureEl.appendChild(doc.createTextNode(text));
  31146. return {
  31147. width: textMeasureEl.offsetWidth
  31148. };
  31149. };
  31150. var tmpRect = new BoundingRect();
  31151. var drawRectText = function (vmlRoot, rect, textRect, fromTextEl) {
  31152. var style = this.style;
  31153. var text = style.text;
  31154. if (!text) {
  31155. return;
  31156. }
  31157. var x;
  31158. var y;
  31159. var align = style.textAlign;
  31160. var fontStyle = getFontStyle(style.textFont);
  31161. // FIXME encodeHtmlAttribute ?
  31162. var font = fontStyle.style + ' ' + fontStyle.variant + ' ' + fontStyle.weight + ' '
  31163. + fontStyle.size + 'px "' + fontStyle.family + '"';
  31164. var baseline = style.textBaseline;
  31165. var verticalAlign = style.textVerticalAlign;
  31166. textRect = textRect || textContain.getBoundingRect(text, font, align, baseline);
  31167. // Transform rect to view space
  31168. var m = this.transform;
  31169. // Ignore transform for text in other element
  31170. if (m && !fromTextEl) {
  31171. tmpRect.copy(rect);
  31172. tmpRect.applyTransform(m);
  31173. rect = tmpRect;
  31174. }
  31175. if (!fromTextEl) {
  31176. var textPosition = style.textPosition;
  31177. var distance = style.textDistance;
  31178. // Text position represented by coord
  31179. if (textPosition instanceof Array) {
  31180. x = rect.x + parsePercent(textPosition[0], rect.width);
  31181. y = rect.y + parsePercent(textPosition[1], rect.height);
  31182. align = align || 'left';
  31183. baseline = baseline || 'top';
  31184. }
  31185. else {
  31186. var res = textContain.adjustTextPositionOnRect(
  31187. textPosition, rect, textRect, distance
  31188. );
  31189. x = res.x;
  31190. y = res.y;
  31191. // Default align and baseline when has textPosition
  31192. align = align || res.textAlign;
  31193. baseline = baseline || res.textBaseline;
  31194. }
  31195. }
  31196. else {
  31197. x = rect.x;
  31198. y = rect.y;
  31199. }
  31200. if (verticalAlign) {
  31201. switch (verticalAlign) {
  31202. case 'middle':
  31203. y -= textRect.height / 2;
  31204. break;
  31205. case 'bottom':
  31206. y -= textRect.height;
  31207. break;
  31208. // 'top'
  31209. }
  31210. // Ignore baseline
  31211. baseline = 'top';
  31212. }
  31213. var fontSize = fontStyle.size;
  31214. // 1.75 is an arbitrary number, as there is no info about the text baseline
  31215. switch (baseline) {
  31216. case 'hanging':
  31217. case 'top':
  31218. y += fontSize / 1.75;
  31219. break;
  31220. case 'middle':
  31221. break;
  31222. default:
  31223. // case null:
  31224. // case 'alphabetic':
  31225. // case 'ideographic':
  31226. // case 'bottom':
  31227. y -= fontSize / 2.25;
  31228. break;
  31229. }
  31230. switch (align) {
  31231. case 'left':
  31232. break;
  31233. case 'center':
  31234. x -= textRect.width / 2;
  31235. break;
  31236. case 'right':
  31237. x -= textRect.width;
  31238. break;
  31239. // case 'end':
  31240. // align = elementStyle.direction == 'ltr' ? 'right' : 'left';
  31241. // break;
  31242. // case 'start':
  31243. // align = elementStyle.direction == 'rtl' ? 'right' : 'left';
  31244. // break;
  31245. // default:
  31246. // align = 'left';
  31247. }
  31248. var createNode = vmlCore.createNode;
  31249. var textVmlEl = this._textVmlEl;
  31250. var pathEl;
  31251. var textPathEl;
  31252. var skewEl;
  31253. if (!textVmlEl) {
  31254. textVmlEl = createNode('line');
  31255. pathEl = createNode('path');
  31256. textPathEl = createNode('textpath');
  31257. skewEl = createNode('skew');
  31258. // FIXME Why here is not cammel case
  31259. // Align 'center' seems wrong
  31260. textPathEl.style['v-text-align'] = 'left';
  31261. initRootElStyle(textVmlEl);
  31262. pathEl.textpathok = true;
  31263. textPathEl.on = true;
  31264. textVmlEl.from = '0 0';
  31265. textVmlEl.to = '1000 0.05';
  31266. append(textVmlEl, skewEl);
  31267. append(textVmlEl, pathEl);
  31268. append(textVmlEl, textPathEl);
  31269. this._textVmlEl = textVmlEl;
  31270. }
  31271. else {
  31272. // 这里是在前面 appendChild 保证顺序的前提下
  31273. skewEl = textVmlEl.firstChild;
  31274. pathEl = skewEl.nextSibling;
  31275. textPathEl = pathEl.nextSibling;
  31276. }
  31277. var coords = [x, y];
  31278. var textVmlElStyle = textVmlEl.style;
  31279. // Ignore transform for text in other element
  31280. if (m && fromTextEl) {
  31281. applyTransform(coords, coords, m);
  31282. skewEl.on = true;
  31283. skewEl.matrix = m[0].toFixed(3) + comma + m[2].toFixed(3) + comma +
  31284. m[1].toFixed(3) + comma + m[3].toFixed(3) + ',0,0';
  31285. // Text position
  31286. skewEl.offset = (round(coords[0]) || 0) + ',' + (round(coords[1]) || 0);
  31287. // Left top point as origin
  31288. skewEl.origin = '0 0';
  31289. textVmlElStyle.left = '0px';
  31290. textVmlElStyle.top = '0px';
  31291. }
  31292. else {
  31293. skewEl.on = false;
  31294. textVmlElStyle.left = round(x) + 'px';
  31295. textVmlElStyle.top = round(y) + 'px';
  31296. }
  31297. textPathEl.string = encodeHtmlAttribute(text);
  31298. // TODO
  31299. try {
  31300. textPathEl.style.font = font;
  31301. }
  31302. // Error font format
  31303. catch (e) {}
  31304. updateFillAndStroke(textVmlEl, 'fill', {
  31305. fill: fromTextEl ? style.fill : style.textFill,
  31306. opacity: style.opacity
  31307. }, this);
  31308. updateFillAndStroke(textVmlEl, 'stroke', {
  31309. stroke: fromTextEl ? style.stroke : style.textStroke,
  31310. opacity: style.opacity,
  31311. lineDash: style.lineDash
  31312. }, this);
  31313. textVmlEl.style.zIndex = getZIndex(this.zlevel, this.z, this.z2);
  31314. // Attached to root
  31315. append(vmlRoot, textVmlEl);
  31316. };
  31317. var removeRectText = function (vmlRoot) {
  31318. remove(vmlRoot, this._textVmlEl);
  31319. this._textVmlEl = null;
  31320. };
  31321. var appendRectText = function (vmlRoot) {
  31322. append(vmlRoot, this._textVmlEl);
  31323. };
  31324. var list = [RectText, Displayable, ZImage, Path, Text];
  31325. // In case Displayable has been mixed in RectText
  31326. for (var i = 0; i < list.length; i++) {
  31327. var proto = list[i].prototype;
  31328. proto.drawRectText = drawRectText;
  31329. proto.removeRectText = removeRectText;
  31330. proto.appendRectText = appendRectText;
  31331. }
  31332. Text.prototype.brushVML = function (vmlRoot) {
  31333. var style = this.style;
  31334. if (style.text) {
  31335. this.drawRectText(vmlRoot, {
  31336. x: style.x || 0, y: style.y || 0,
  31337. width: 0, height: 0
  31338. }, this.getBoundingRect(), true);
  31339. }
  31340. else {
  31341. this.removeRectText(vmlRoot);
  31342. }
  31343. };
  31344. Text.prototype.onRemove = function (vmlRoot) {
  31345. this.removeRectText(vmlRoot);
  31346. };
  31347. Text.prototype.onAdd = function (vmlRoot) {
  31348. this.appendRectText(vmlRoot);
  31349. };
  31350. }
  31351. /***/ },
  31352. /* 351 */
  31353. /***/ function(module, exports, __webpack_require__) {
  31354. if (!__webpack_require__(79).canvasSupported) {
  31355. var urn = 'urn:schemas-microsoft-com:vml';
  31356. var createNode;
  31357. var win = window;
  31358. var doc = win.document;
  31359. var vmlInited = false;
  31360. try {
  31361. !doc.namespaces.zrvml && doc.namespaces.add('zrvml', urn);
  31362. createNode = function (tagName) {
  31363. return doc.createElement('<zrvml:' + tagName + ' class="zrvml">');
  31364. };
  31365. }
  31366. catch (e) {
  31367. createNode = function (tagName) {
  31368. return doc.createElement('<' + tagName + ' xmlns="' + urn + '" class="zrvml">');
  31369. };
  31370. }
  31371. // From raphael
  31372. var initVML = function () {
  31373. if (vmlInited) {
  31374. return;
  31375. }
  31376. vmlInited = true;
  31377. var styleSheets = doc.styleSheets;
  31378. if (styleSheets.length < 31) {
  31379. doc.createStyleSheet().addRule('.zrvml', 'behavior:url(#default#VML)');
  31380. }
  31381. else {
  31382. // http://msdn.microsoft.com/en-us/library/ms531194%28VS.85%29.aspx
  31383. styleSheets[0].addRule('.zrvml', 'behavior:url(#default#VML)');
  31384. }
  31385. };
  31386. // Not useing return to avoid error when converting to CommonJS module
  31387. module.exports = {
  31388. doc: doc,
  31389. initVML: initVML,
  31390. createNode: createNode
  31391. };
  31392. }
  31393. /***/ },
  31394. /* 352 */
  31395. /***/ function(module, exports, __webpack_require__) {
  31396. /**
  31397. * VML Painter.
  31398. *
  31399. * @module zrender/vml/Painter
  31400. */
  31401. var zrLog = __webpack_require__(39);
  31402. var vmlCore = __webpack_require__(351);
  31403. function parseInt10(val) {
  31404. return parseInt(val, 10);
  31405. }
  31406. /**
  31407. * @alias module:zrender/vml/Painter
  31408. */
  31409. function VMLPainter(root, storage) {
  31410. vmlCore.initVML();
  31411. this.root = root;
  31412. this.storage = storage;
  31413. var vmlViewport = document.createElement('div');
  31414. var vmlRoot = document.createElement('div');
  31415. vmlViewport.style.cssText = 'display:inline-block;overflow:hidden;position:relative;width:300px;height:150px;';
  31416. vmlRoot.style.cssText = 'position:absolute;left:0;top:0;';
  31417. root.appendChild(vmlViewport);
  31418. this._vmlRoot = vmlRoot;
  31419. this._vmlViewport = vmlViewport;
  31420. this.resize();
  31421. // Modify storage
  31422. var oldDelFromMap = storage.delFromMap;
  31423. var oldAddToMap = storage.addToMap;
  31424. storage.delFromMap = function (elId) {
  31425. var el = storage.get(elId);
  31426. oldDelFromMap.call(storage, elId);
  31427. if (el) {
  31428. el.onRemove && el.onRemove(vmlRoot);
  31429. }
  31430. };
  31431. storage.addToMap = function (el) {
  31432. // Displayable already has a vml node
  31433. el.onAdd && el.onAdd(vmlRoot);
  31434. oldAddToMap.call(storage, el);
  31435. };
  31436. this._firstPaint = true;
  31437. }
  31438. VMLPainter.prototype = {
  31439. constructor: VMLPainter,
  31440. /**
  31441. * @return {HTMLDivElement}
  31442. */
  31443. getViewportRoot: function () {
  31444. return this._vmlViewport;
  31445. },
  31446. /**
  31447. * 刷新
  31448. */
  31449. refresh: function () {
  31450. var list = this.storage.getDisplayList(true, true);
  31451. this._paintList(list);
  31452. },
  31453. _paintList: function (list) {
  31454. var vmlRoot = this._vmlRoot;
  31455. for (var i = 0; i < list.length; i++) {
  31456. var el = list[i];
  31457. if (el.invisible || el.ignore) {
  31458. if (!el.__alreadyNotVisible) {
  31459. el.onRemove(vmlRoot);
  31460. }
  31461. // Set as already invisible
  31462. el.__alreadyNotVisible = true;
  31463. }
  31464. else {
  31465. if (el.__alreadyNotVisible) {
  31466. el.onAdd(vmlRoot);
  31467. }
  31468. el.__alreadyNotVisible = false;
  31469. if (el.__dirty) {
  31470. el.beforeBrush && el.beforeBrush();
  31471. (el.brushVML || el.brush).call(el, vmlRoot);
  31472. el.afterBrush && el.afterBrush();
  31473. }
  31474. }
  31475. el.__dirty = false;
  31476. }
  31477. if (this._firstPaint) {
  31478. // Detached from document at first time
  31479. // to avoid page refreshing too many times
  31480. // FIXME 如果每次都先 removeChild 可能会导致一些填充和描边的效果改变
  31481. this._vmlViewport.appendChild(vmlRoot);
  31482. this._firstPaint = false;
  31483. }
  31484. },
  31485. resize: function () {
  31486. var width = this._getWidth();
  31487. var height = this._getHeight();
  31488. if (this._width != width && this._height != height) {
  31489. this._width = width;
  31490. this._height = height;
  31491. var vmlViewportStyle = this._vmlViewport.style;
  31492. vmlViewportStyle.width = width + 'px';
  31493. vmlViewportStyle.height = height + 'px';
  31494. }
  31495. },
  31496. dispose: function () {
  31497. this.root.innerHTML = '';
  31498. this._vmlRoot =
  31499. this._vmlViewport =
  31500. this.storage = null;
  31501. },
  31502. getWidth: function () {
  31503. return this._width;
  31504. },
  31505. getHeight: function () {
  31506. return this._height;
  31507. },
  31508. _getWidth: function () {
  31509. var root = this.root;
  31510. var stl = root.currentStyle;
  31511. return ((root.clientWidth || parseInt10(stl.width))
  31512. - parseInt10(stl.paddingLeft)
  31513. - parseInt10(stl.paddingRight)) | 0;
  31514. },
  31515. _getHeight: function () {
  31516. var root = this.root;
  31517. var stl = root.currentStyle;
  31518. return ((root.clientHeight || parseInt10(stl.height))
  31519. - parseInt10(stl.paddingTop)
  31520. - parseInt10(stl.paddingBottom)) | 0;
  31521. }
  31522. };
  31523. // Not supported methods
  31524. function createMethodNotSupport(method) {
  31525. return function () {
  31526. zrLog('In IE8.0 VML mode painter not support method "' + method + '"');
  31527. };
  31528. }
  31529. var notSupportedMethods = [
  31530. 'getLayer', 'insertLayer', 'eachLayer', 'eachBuildinLayer', 'eachOtherLayer', 'getLayers',
  31531. 'modLayer', 'delLayer', 'clearLayer', 'toDataURL', 'pathToImage'
  31532. ];
  31533. for (var i = 0; i < notSupportedMethods.length; i++) {
  31534. var name = notSupportedMethods[i];
  31535. VMLPainter.prototype[name] = createMethodNotSupport(name);
  31536. }
  31537. module.exports = VMLPainter;
  31538. /***/ }
  31539. /******/ ])
  31540. });
  31541. ;