echarts.simple.js 946 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory();
  4. else if(typeof define === 'function' && define.amd)
  5. define([], factory);
  6. else if(typeof exports === 'object')
  7. exports["echarts"] = factory();
  8. else
  9. root["echarts"] = factory();
  10. })(this, function() {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/ // The require function
  15. /******/ function __webpack_require__(moduleId) {
  16. /******/ // Check if module is in cache
  17. /******/ if(installedModules[moduleId])
  18. /******/ return installedModules[moduleId].exports;
  19. /******/ // Create a new module (and put it into the cache)
  20. /******/ var module = installedModules[moduleId] = {
  21. /******/ exports: {},
  22. /******/ id: moduleId,
  23. /******/ loaded: false
  24. /******/ };
  25. /******/ // Execute the module function
  26. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  27. /******/ // Flag the module as loaded
  28. /******/ module.loaded = true;
  29. /******/ // Return the exports of the module
  30. /******/ return module.exports;
  31. /******/ }
  32. /******/ // expose the modules object (__webpack_modules__)
  33. /******/ __webpack_require__.m = modules;
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/ // __webpack_public_path__
  37. /******/ __webpack_require__.p = "";
  38. /******/ // Load entry module and return exports
  39. /******/ return __webpack_require__(0);
  40. /******/ })
  41. /************************************************************************/
  42. /******/ ([
  43. /* 0 */
  44. /***/ function(module, exports, __webpack_require__) {
  45. /**
  46. * Export echarts as CommonJS module
  47. */
  48. module.exports = __webpack_require__(1);
  49. __webpack_require__(100);
  50. __webpack_require__(134);
  51. __webpack_require__(141);
  52. __webpack_require__(113);
  53. /***/ },
  54. /* 1 */
  55. /***/ function(module, exports, __webpack_require__) {
  56. // Enable DEV mode when using source code without build. which has no __DEV__ variable
  57. // In build process 'typeof __DEV__' will be replace with 'boolean'
  58. // So this code will be removed or disabled anyway after built.
  59. if (false) {
  60. // In browser
  61. if (typeof window !== 'undefined') {
  62. window.__DEV__ = true;
  63. }
  64. // In node
  65. else if (typeof global !== 'undefined') {
  66. global.__DEV__ = true;
  67. }
  68. }
  69. /*!
  70. * ECharts, a javascript interactive chart library.
  71. *
  72. * Copyright (c) 2015, Baidu Inc.
  73. * All rights reserved.
  74. *
  75. * LICENSE
  76. * https://github.com/ecomfe/echarts/blob/master/LICENSE.txt
  77. */
  78. /**
  79. * @module echarts
  80. */
  81. var env = __webpack_require__(2);
  82. var GlobalModel = __webpack_require__(3);
  83. var ExtensionAPI = __webpack_require__(25);
  84. var CoordinateSystemManager = __webpack_require__(26);
  85. var OptionManager = __webpack_require__(27);
  86. var ComponentModel = __webpack_require__(19);
  87. var SeriesModel = __webpack_require__(28);
  88. var ComponentView = __webpack_require__(29);
  89. var ChartView = __webpack_require__(42);
  90. var graphic = __webpack_require__(43);
  91. var modelUtil = __webpack_require__(5);
  92. var throttle = __webpack_require__(81);
  93. var zrender = __webpack_require__(82);
  94. var zrUtil = __webpack_require__(4);
  95. var colorTool = __webpack_require__(39);
  96. var Eventful = __webpack_require__(33);
  97. var timsort = __webpack_require__(86);
  98. var each = zrUtil.each;
  99. var parseClassType = ComponentModel.parseClassType;
  100. var PRIORITY_PROCESSOR_FILTER = 1000;
  101. var PRIORITY_PROCESSOR_STATISTIC = 5000;
  102. var PRIORITY_VISUAL_LAYOUT = 1000;
  103. var PRIORITY_VISUAL_GLOBAL = 2000;
  104. var PRIORITY_VISUAL_CHART = 3000;
  105. var PRIORITY_VISUAL_COMPONENT = 4000;
  106. // FIXME
  107. // necessary?
  108. var PRIORITY_VISUAL_BRUSH = 5000;
  109. // Main process have three entries: `setOption`, `dispatchAction` and `resize`,
  110. // where they must not be invoked nestedly, except the only case: invoke
  111. // dispatchAction with updateMethod "none" in main process.
  112. // This flag is used to carry out this rule.
  113. // All events will be triggered out side main process (i.e. when !this[IN_MAIN_PROCESS]).
  114. var IN_MAIN_PROCESS = '__flagInMainProcess';
  115. var HAS_GRADIENT_OR_PATTERN_BG = '__hasGradientOrPatternBg';
  116. var OPTION_UPDATED = '__optionUpdated';
  117. var ACTION_REG = /^[a-zA-Z0-9_]+$/;
  118. function createRegisterEventWithLowercaseName(method) {
  119. return function (eventName, handler, context) {
  120. // Event name is all lowercase
  121. eventName = eventName && eventName.toLowerCase();
  122. Eventful.prototype[method].call(this, eventName, handler, context);
  123. };
  124. }
  125. /**
  126. * @module echarts~MessageCenter
  127. */
  128. function MessageCenter() {
  129. Eventful.call(this);
  130. }
  131. MessageCenter.prototype.on = createRegisterEventWithLowercaseName('on');
  132. MessageCenter.prototype.off = createRegisterEventWithLowercaseName('off');
  133. MessageCenter.prototype.one = createRegisterEventWithLowercaseName('one');
  134. zrUtil.mixin(MessageCenter, Eventful);
  135. /**
  136. * @module echarts~ECharts
  137. */
  138. function ECharts (dom, theme, opts) {
  139. opts = opts || {};
  140. // Get theme by name
  141. if (typeof theme === 'string') {
  142. theme = themeStorage[theme];
  143. }
  144. /**
  145. * @type {string}
  146. */
  147. this.id;
  148. /**
  149. * Group id
  150. * @type {string}
  151. */
  152. this.group;
  153. /**
  154. * @type {HTMLDomElement}
  155. * @private
  156. */
  157. this._dom = dom;
  158. /**
  159. * @type {module:zrender/ZRender}
  160. * @private
  161. */
  162. var zr = this._zr = zrender.init(dom, {
  163. renderer: opts.renderer || 'canvas',
  164. devicePixelRatio: opts.devicePixelRatio,
  165. width: opts.width,
  166. height: opts.height
  167. });
  168. /**
  169. * Expect 60 pfs.
  170. * @type {Function}
  171. * @private
  172. */
  173. this._throttledZrFlush = throttle.throttle(zrUtil.bind(zr.flush, zr), 17);
  174. /**
  175. * @type {Object}
  176. * @private
  177. */
  178. this._theme = zrUtil.clone(theme);
  179. /**
  180. * @type {Array.<module:echarts/view/Chart>}
  181. * @private
  182. */
  183. this._chartsViews = [];
  184. /**
  185. * @type {Object.<string, module:echarts/view/Chart>}
  186. * @private
  187. */
  188. this._chartsMap = {};
  189. /**
  190. * @type {Array.<module:echarts/view/Component>}
  191. * @private
  192. */
  193. this._componentsViews = [];
  194. /**
  195. * @type {Object.<string, module:echarts/view/Component>}
  196. * @private
  197. */
  198. this._componentsMap = {};
  199. /**
  200. * @type {module:echarts/ExtensionAPI}
  201. * @private
  202. */
  203. this._api = new ExtensionAPI(this);
  204. /**
  205. * @type {module:echarts/CoordinateSystem}
  206. * @private
  207. */
  208. this._coordSysMgr = new CoordinateSystemManager();
  209. Eventful.call(this);
  210. /**
  211. * @type {module:echarts~MessageCenter}
  212. * @private
  213. */
  214. this._messageCenter = new MessageCenter();
  215. // Init mouse events
  216. this._initEvents();
  217. // In case some people write `window.onresize = chart.resize`
  218. this.resize = zrUtil.bind(this.resize, this);
  219. // Can't dispatch action during rendering procedure
  220. this._pendingActions = [];
  221. // Sort on demand
  222. function prioritySortFunc(a, b) {
  223. return a.prio - b.prio;
  224. }
  225. timsort(visualFuncs, prioritySortFunc);
  226. timsort(dataProcessorFuncs, prioritySortFunc);
  227. zr.animation.on('frame', this._onframe, this);
  228. }
  229. var echartsProto = ECharts.prototype;
  230. echartsProto._onframe = function () {
  231. // Lazy update
  232. if (this[OPTION_UPDATED]) {
  233. var silent = this[OPTION_UPDATED].silent;
  234. this[IN_MAIN_PROCESS] = true;
  235. updateMethods.prepareAndUpdate.call(this);
  236. this[IN_MAIN_PROCESS] = false;
  237. this[OPTION_UPDATED] = false;
  238. flushPendingActions.call(this, silent);
  239. triggerUpdatedEvent.call(this, silent);
  240. }
  241. };
  242. /**
  243. * @return {HTMLDomElement}
  244. */
  245. echartsProto.getDom = function () {
  246. return this._dom;
  247. };
  248. /**
  249. * @return {module:zrender~ZRender}
  250. */
  251. echartsProto.getZr = function () {
  252. return this._zr;
  253. };
  254. /**
  255. * Usage:
  256. * chart.setOption(option, notMerge, lazyUpdate);
  257. * chart.setOption(option, {
  258. * notMerge: ...,
  259. * lazyUpdate: ...,
  260. * silent: ...
  261. * });
  262. *
  263. * @param {Object} option
  264. * @param {Object|boolean} [opts] opts or notMerge.
  265. * @param {boolean} [opts.notMerge=false]
  266. * @param {boolean} [opts.lazyUpdate=false] Useful when setOption frequently.
  267. */
  268. echartsProto.setOption = function (option, notMerge, lazyUpdate) {
  269. if (true) {
  270. zrUtil.assert(!this[IN_MAIN_PROCESS], '`setOption` should not be called during main process.');
  271. }
  272. var silent;
  273. if (zrUtil.isObject(notMerge)) {
  274. lazyUpdate = notMerge.lazyUpdate;
  275. silent = notMerge.silent;
  276. notMerge = notMerge.notMerge;
  277. }
  278. this[IN_MAIN_PROCESS] = true;
  279. if (!this._model || notMerge) {
  280. var optionManager = new OptionManager(this._api);
  281. var theme = this._theme;
  282. var ecModel = this._model = new GlobalModel(null, null, theme, optionManager);
  283. ecModel.init(null, null, theme, optionManager);
  284. }
  285. // FIXME
  286. // ugly
  287. this.__lastOnlyGraphic = !!(option && option.graphic);
  288. zrUtil.each(option, function (o, mainType) {
  289. mainType !== 'graphic' && (this.__lastOnlyGraphic = false);
  290. }, this);
  291. this._model.setOption(option, optionPreprocessorFuncs);
  292. if (lazyUpdate) {
  293. this[OPTION_UPDATED] = {silent: silent};
  294. this[IN_MAIN_PROCESS] = false;
  295. }
  296. else {
  297. updateMethods.prepareAndUpdate.call(this);
  298. // Ensure zr refresh sychronously, and then pixel in canvas can be
  299. // fetched after `setOption`.
  300. this._zr.flush();
  301. this[OPTION_UPDATED] = false;
  302. this[IN_MAIN_PROCESS] = false;
  303. flushPendingActions.call(this, silent);
  304. triggerUpdatedEvent.call(this, silent);
  305. }
  306. };
  307. /**
  308. * @DEPRECATED
  309. */
  310. echartsProto.setTheme = function () {
  311. console.log('ECharts#setTheme() is DEPRECATED in ECharts 3.0');
  312. };
  313. /**
  314. * @return {module:echarts/model/Global}
  315. */
  316. echartsProto.getModel = function () {
  317. return this._model;
  318. };
  319. /**
  320. * @return {Object}
  321. */
  322. echartsProto.getOption = function () {
  323. return this._model && this._model.getOption();
  324. };
  325. /**
  326. * @return {number}
  327. */
  328. echartsProto.getWidth = function () {
  329. return this._zr.getWidth();
  330. };
  331. /**
  332. * @return {number}
  333. */
  334. echartsProto.getHeight = function () {
  335. return this._zr.getHeight();
  336. };
  337. /**
  338. * Get canvas which has all thing rendered
  339. * @param {Object} opts
  340. * @param {string} [opts.backgroundColor]
  341. */
  342. echartsProto.getRenderedCanvas = function (opts) {
  343. if (!env.canvasSupported) {
  344. return;
  345. }
  346. opts = opts || {};
  347. opts.pixelRatio = opts.pixelRatio || 1;
  348. opts.backgroundColor = opts.backgroundColor
  349. || this._model.get('backgroundColor');
  350. var zr = this._zr;
  351. var list = zr.storage.getDisplayList();
  352. // Stop animations
  353. zrUtil.each(list, function (el) {
  354. el.stopAnimation(true);
  355. });
  356. return zr.painter.getRenderedCanvas(opts);
  357. };
  358. /**
  359. * @return {string}
  360. * @param {Object} opts
  361. * @param {string} [opts.type='png']
  362. * @param {string} [opts.pixelRatio=1]
  363. * @param {string} [opts.backgroundColor]
  364. * @param {string} [opts.excludeComponents]
  365. */
  366. echartsProto.getDataURL = function (opts) {
  367. opts = opts || {};
  368. var excludeComponents = opts.excludeComponents;
  369. var ecModel = this._model;
  370. var excludesComponentViews = [];
  371. var self = this;
  372. each(excludeComponents, function (componentType) {
  373. ecModel.eachComponent({
  374. mainType: componentType
  375. }, function (component) {
  376. var view = self._componentsMap[component.__viewId];
  377. if (!view.group.ignore) {
  378. excludesComponentViews.push(view);
  379. view.group.ignore = true;
  380. }
  381. });
  382. });
  383. var url = this.getRenderedCanvas(opts).toDataURL(
  384. 'image/' + (opts && opts.type || 'png')
  385. );
  386. each(excludesComponentViews, function (view) {
  387. view.group.ignore = false;
  388. });
  389. return url;
  390. };
  391. /**
  392. * @return {string}
  393. * @param {Object} opts
  394. * @param {string} [opts.type='png']
  395. * @param {string} [opts.pixelRatio=1]
  396. * @param {string} [opts.backgroundColor]
  397. */
  398. echartsProto.getConnectedDataURL = function (opts) {
  399. if (!env.canvasSupported) {
  400. return;
  401. }
  402. var groupId = this.group;
  403. var mathMin = Math.min;
  404. var mathMax = Math.max;
  405. var MAX_NUMBER = Infinity;
  406. if (connectedGroups[groupId]) {
  407. var left = MAX_NUMBER;
  408. var top = MAX_NUMBER;
  409. var right = -MAX_NUMBER;
  410. var bottom = -MAX_NUMBER;
  411. var canvasList = [];
  412. var dpr = (opts && opts.pixelRatio) || 1;
  413. zrUtil.each(instances, function (chart, id) {
  414. if (chart.group === groupId) {
  415. var canvas = chart.getRenderedCanvas(
  416. zrUtil.clone(opts)
  417. );
  418. var boundingRect = chart.getDom().getBoundingClientRect();
  419. left = mathMin(boundingRect.left, left);
  420. top = mathMin(boundingRect.top, top);
  421. right = mathMax(boundingRect.right, right);
  422. bottom = mathMax(boundingRect.bottom, bottom);
  423. canvasList.push({
  424. dom: canvas,
  425. left: boundingRect.left,
  426. top: boundingRect.top
  427. });
  428. }
  429. });
  430. left *= dpr;
  431. top *= dpr;
  432. right *= dpr;
  433. bottom *= dpr;
  434. var width = right - left;
  435. var height = bottom - top;
  436. var targetCanvas = zrUtil.createCanvas();
  437. targetCanvas.width = width;
  438. targetCanvas.height = height;
  439. var zr = zrender.init(targetCanvas);
  440. each(canvasList, function (item) {
  441. var img = new graphic.Image({
  442. style: {
  443. x: item.left * dpr - left,
  444. y: item.top * dpr - top,
  445. image: item.dom
  446. }
  447. });
  448. zr.add(img);
  449. });
  450. zr.refreshImmediately();
  451. return targetCanvas.toDataURL('image/' + (opts && opts.type || 'png'));
  452. }
  453. else {
  454. return this.getDataURL(opts);
  455. }
  456. };
  457. /**
  458. * Convert from logical coordinate system to pixel coordinate system.
  459. * See CoordinateSystem#convertToPixel.
  460. * @param {string|Object} finder
  461. * If string, e.g., 'geo', means {geoIndex: 0}.
  462. * If Object, could contain some of these properties below:
  463. * {
  464. * seriesIndex / seriesId / seriesName,
  465. * geoIndex / geoId, geoName,
  466. * bmapIndex / bmapId / bmapName,
  467. * xAxisIndex / xAxisId / xAxisName,
  468. * yAxisIndex / yAxisId / yAxisName,
  469. * gridIndex / gridId / gridName,
  470. * ... (can be extended)
  471. * }
  472. * @param {Array|number} value
  473. * @return {Array|number} result
  474. */
  475. echartsProto.convertToPixel = zrUtil.curry(doConvertPixel, 'convertToPixel');
  476. /**
  477. * Convert from pixel coordinate system to logical coordinate system.
  478. * See CoordinateSystem#convertFromPixel.
  479. * @param {string|Object} finder
  480. * If string, e.g., 'geo', means {geoIndex: 0}.
  481. * If Object, could contain some of these properties below:
  482. * {
  483. * seriesIndex / seriesId / seriesName,
  484. * geoIndex / geoId / geoName,
  485. * bmapIndex / bmapId / bmapName,
  486. * xAxisIndex / xAxisId / xAxisName,
  487. * yAxisIndex / yAxisId / yAxisName
  488. * gridIndex / gridId / gridName,
  489. * ... (can be extended)
  490. * }
  491. * @param {Array|number} value
  492. * @return {Array|number} result
  493. */
  494. echartsProto.convertFromPixel = zrUtil.curry(doConvertPixel, 'convertFromPixel');
  495. function doConvertPixel(methodName, finder, value) {
  496. var ecModel = this._model;
  497. var coordSysList = this._coordSysMgr.getCoordinateSystems();
  498. var result;
  499. finder = modelUtil.parseFinder(ecModel, finder);
  500. for (var i = 0; i < coordSysList.length; i++) {
  501. var coordSys = coordSysList[i];
  502. if (coordSys[methodName]
  503. && (result = coordSys[methodName](ecModel, finder, value)) != null
  504. ) {
  505. return result;
  506. }
  507. }
  508. if (true) {
  509. console.warn(
  510. 'No coordinate system that supports ' + methodName + ' found by the given finder.'
  511. );
  512. }
  513. }
  514. /**
  515. * Is the specified coordinate systems or components contain the given pixel point.
  516. * @param {string|Object} finder
  517. * If string, e.g., 'geo', means {geoIndex: 0}.
  518. * If Object, could contain some of these properties below:
  519. * {
  520. * seriesIndex / seriesId / seriesName,
  521. * geoIndex / geoId / geoName,
  522. * bmapIndex / bmapId / bmapName,
  523. * xAxisIndex / xAxisId / xAxisName,
  524. * yAxisIndex / yAxisId / yAxisName
  525. * gridIndex / gridId / gridName,
  526. * ... (can be extended)
  527. * }
  528. * @param {Array|number} value
  529. * @return {boolean} result
  530. */
  531. echartsProto.containPixel = function (finder, value) {
  532. var ecModel = this._model;
  533. var result;
  534. finder = modelUtil.parseFinder(ecModel, finder);
  535. zrUtil.each(finder, function (models, key) {
  536. key.indexOf('Models') >= 0 && zrUtil.each(models, function (model) {
  537. var coordSys = model.coordinateSystem;
  538. if (coordSys && coordSys.containPoint) {
  539. result |= !!coordSys.containPoint(value);
  540. }
  541. else if (key === 'seriesModels') {
  542. var view = this._chartsMap[model.__viewId];
  543. if (view && view.containPoint) {
  544. result |= view.containPoint(value, model);
  545. }
  546. else {
  547. if (true) {
  548. console.warn(key + ': ' + (view
  549. ? 'The found component do not support containPoint.'
  550. : 'No view mapping to the found component.'
  551. ));
  552. }
  553. }
  554. }
  555. else {
  556. if (true) {
  557. console.warn(key + ': containPoint is not supported');
  558. }
  559. }
  560. }, this);
  561. }, this);
  562. return !!result;
  563. };
  564. /**
  565. * Get visual from series or data.
  566. * @param {string|Object} finder
  567. * If string, e.g., 'series', means {seriesIndex: 0}.
  568. * If Object, could contain some of these properties below:
  569. * {
  570. * seriesIndex / seriesId / seriesName,
  571. * dataIndex / dataIndexInside
  572. * }
  573. * If dataIndex is not specified, series visual will be fetched,
  574. * but not data item visual.
  575. * If all of seriesIndex, seriesId, seriesName are not specified,
  576. * visual will be fetched from first series.
  577. * @param {string} visualType 'color', 'symbol', 'symbolSize'
  578. */
  579. echartsProto.getVisual = function (finder, visualType) {
  580. var ecModel = this._model;
  581. finder = modelUtil.parseFinder(ecModel, finder, {defaultMainType: 'series'});
  582. var seriesModel = finder.seriesModel;
  583. if (true) {
  584. if (!seriesModel) {
  585. console.warn('There is no specified seires model');
  586. }
  587. }
  588. var data = seriesModel.getData();
  589. var dataIndexInside = finder.hasOwnProperty('dataIndexInside')
  590. ? finder.dataIndexInside
  591. : finder.hasOwnProperty('dataIndex')
  592. ? data.indexOfRawIndex(finder.dataIndex)
  593. : null;
  594. return dataIndexInside != null
  595. ? data.getItemVisual(dataIndexInside, visualType)
  596. : data.getVisual(visualType);
  597. };
  598. var updateMethods = {
  599. /**
  600. * @param {Object} payload
  601. * @private
  602. */
  603. update: function (payload) {
  604. // console.time && console.time('update');
  605. var ecModel = this._model;
  606. var api = this._api;
  607. var coordSysMgr = this._coordSysMgr;
  608. var zr = this._zr;
  609. // update before setOption
  610. if (!ecModel) {
  611. return;
  612. }
  613. // Fixme First time update ?
  614. ecModel.restoreData();
  615. // TODO
  616. // Save total ecModel here for undo/redo (after restoring data and before processing data).
  617. // Undo (restoration of total ecModel) can be carried out in 'action' or outside API call.
  618. // Create new coordinate system each update
  619. // In LineView may save the old coordinate system and use it to get the orignal point
  620. coordSysMgr.create(this._model, this._api);
  621. processData.call(this, ecModel, api);
  622. stackSeriesData.call(this, ecModel);
  623. coordSysMgr.update(ecModel, api);
  624. doVisualEncoding.call(this, ecModel, payload);
  625. doRender.call(this, ecModel, payload);
  626. // Set background
  627. var backgroundColor = ecModel.get('backgroundColor') || 'transparent';
  628. var painter = zr.painter;
  629. // TODO all use clearColor ?
  630. if (painter.isSingleCanvas && painter.isSingleCanvas()) {
  631. zr.configLayer(0, {
  632. clearColor: backgroundColor
  633. });
  634. }
  635. else {
  636. // In IE8
  637. if (!env.canvasSupported) {
  638. var colorArr = colorTool.parse(backgroundColor);
  639. backgroundColor = colorTool.stringify(colorArr, 'rgb');
  640. if (colorArr[3] === 0) {
  641. backgroundColor = 'transparent';
  642. }
  643. }
  644. if (backgroundColor.colorStops || backgroundColor.image) {
  645. // Gradient background
  646. // FIXME Fixed layer?
  647. zr.configLayer(0, {
  648. clearColor: backgroundColor
  649. });
  650. this[HAS_GRADIENT_OR_PATTERN_BG] = true;
  651. this._dom.style.background = 'transparent';
  652. }
  653. else {
  654. if (this[HAS_GRADIENT_OR_PATTERN_BG]) {
  655. zr.configLayer(0, {
  656. clearColor: null
  657. });
  658. }
  659. this[HAS_GRADIENT_OR_PATTERN_BG] = false;
  660. this._dom.style.background = backgroundColor;
  661. }
  662. }
  663. // console.time && console.timeEnd('update');
  664. },
  665. /**
  666. * @param {Object} payload
  667. * @private
  668. */
  669. updateView: function (payload) {
  670. var ecModel = this._model;
  671. // update before setOption
  672. if (!ecModel) {
  673. return;
  674. }
  675. ecModel.eachSeries(function (seriesModel) {
  676. seriesModel.getData().clearAllVisual();
  677. });
  678. doVisualEncoding.call(this, ecModel, payload);
  679. invokeUpdateMethod.call(this, 'updateView', ecModel, payload);
  680. },
  681. /**
  682. * @param {Object} payload
  683. * @private
  684. */
  685. updateVisual: function (payload) {
  686. var ecModel = this._model;
  687. // update before setOption
  688. if (!ecModel) {
  689. return;
  690. }
  691. ecModel.eachSeries(function (seriesModel) {
  692. seriesModel.getData().clearAllVisual();
  693. });
  694. doVisualEncoding.call(this, ecModel, payload, true);
  695. invokeUpdateMethod.call(this, 'updateVisual', ecModel, payload);
  696. },
  697. /**
  698. * @param {Object} payload
  699. * @private
  700. */
  701. updateLayout: function (payload) {
  702. var ecModel = this._model;
  703. // update before setOption
  704. if (!ecModel) {
  705. return;
  706. }
  707. doLayout.call(this, ecModel, payload);
  708. invokeUpdateMethod.call(this, 'updateLayout', ecModel, payload);
  709. },
  710. /**
  711. * @param {Object} payload
  712. * @private
  713. */
  714. prepareAndUpdate: function (payload) {
  715. var ecModel = this._model;
  716. prepareView.call(this, 'component', ecModel);
  717. prepareView.call(this, 'chart', ecModel);
  718. // FIXME
  719. // ugly
  720. if (this.__lastOnlyGraphic) {
  721. each(this._componentsViews, function (componentView) {
  722. var componentModel = componentView.__model;
  723. if (componentModel && componentModel.mainType === 'graphic') {
  724. componentView.render(componentModel, ecModel, this._api, payload);
  725. updateZ(componentModel, componentView);
  726. }
  727. }, this);
  728. this.__lastOnlyGraphic = false;
  729. }
  730. else {
  731. updateMethods.update.call(this, payload);
  732. }
  733. }
  734. };
  735. /**
  736. * @private
  737. */
  738. function updateDirectly(ecIns, method, payload, mainType, subType) {
  739. var ecModel = ecIns._model;
  740. var query = {};
  741. query[mainType + 'Id'] = payload[mainType + 'Id'];
  742. query[mainType + 'Index'] = payload[mainType + 'Index'];
  743. query[mainType + 'Name'] = payload[mainType + 'Name'];
  744. var condition = {mainType: mainType, query: query};
  745. subType && (condition.subType = subType); // subType may be '' by parseClassType;
  746. // If dispatchAction before setOption, do nothing.
  747. ecModel && ecModel.eachComponent(condition, function (model, index) {
  748. var view = ecIns[
  749. mainType === 'series' ? '_chartsMap' : '_componentsMap'
  750. ][model.__viewId];
  751. if (view && view.__alive) {
  752. view[method](model, ecModel, ecIns._api, payload);
  753. }
  754. }, ecIns);
  755. }
  756. /**
  757. * Resize the chart
  758. * @param {Object} opts
  759. * @param {number} [opts.width] Can be 'auto' (the same as null/undefined)
  760. * @param {number} [opts.height] Can be 'auto' (the same as null/undefined)
  761. * @param {boolean} [opts.silent=false]
  762. */
  763. echartsProto.resize = function (opts) {
  764. if (true) {
  765. zrUtil.assert(!this[IN_MAIN_PROCESS], '`resize` should not be called during main process.');
  766. }
  767. this[IN_MAIN_PROCESS] = true;
  768. this._zr.resize(opts);
  769. var optionChanged = this._model && this._model.resetOption('media');
  770. var updateMethod = optionChanged ? 'prepareAndUpdate' : 'update';
  771. updateMethods[updateMethod].call(this);
  772. // Resize loading effect
  773. this._loadingFX && this._loadingFX.resize();
  774. this[IN_MAIN_PROCESS] = false;
  775. var silent = opts && opts.silent;
  776. flushPendingActions.call(this, silent);
  777. triggerUpdatedEvent.call(this, silent);
  778. };
  779. /**
  780. * Show loading effect
  781. * @param {string} [name='default']
  782. * @param {Object} [cfg]
  783. */
  784. echartsProto.showLoading = function (name, cfg) {
  785. if (zrUtil.isObject(name)) {
  786. cfg = name;
  787. name = '';
  788. }
  789. name = name || 'default';
  790. this.hideLoading();
  791. if (!loadingEffects[name]) {
  792. if (true) {
  793. console.warn('Loading effects ' + name + ' not exists.');
  794. }
  795. return;
  796. }
  797. var el = loadingEffects[name](this._api, cfg);
  798. var zr = this._zr;
  799. this._loadingFX = el;
  800. zr.add(el);
  801. };
  802. /**
  803. * Hide loading effect
  804. */
  805. echartsProto.hideLoading = function () {
  806. this._loadingFX && this._zr.remove(this._loadingFX);
  807. this._loadingFX = null;
  808. };
  809. /**
  810. * @param {Object} eventObj
  811. * @return {Object}
  812. */
  813. echartsProto.makeActionFromEvent = function (eventObj) {
  814. var payload = zrUtil.extend({}, eventObj);
  815. payload.type = eventActionMap[eventObj.type];
  816. return payload;
  817. };
  818. /**
  819. * @pubilc
  820. * @param {Object} payload
  821. * @param {string} [payload.type] Action type
  822. * @param {Object|boolean} [opt] If pass boolean, means opt.silent
  823. * @param {boolean} [opt.silent=false] Whether trigger events.
  824. * @param {boolean} [opt.flush=undefined]
  825. * true: Flush immediately, and then pixel in canvas can be fetched
  826. * immediately. Caution: it might affect performance.
  827. * false: Not not flush.
  828. * undefined: Auto decide whether perform flush.
  829. */
  830. echartsProto.dispatchAction = function (payload, opt) {
  831. if (!zrUtil.isObject(opt)) {
  832. opt = {silent: !!opt};
  833. }
  834. if (!actions[payload.type]) {
  835. return;
  836. }
  837. // if (__DEV__) {
  838. // zrUtil.assert(
  839. // !this[IN_MAIN_PROCESS],
  840. // '`dispatchAction` should not be called during main process.'
  841. // + 'unless updateMathod is "none".'
  842. // );
  843. // }
  844. // May dispatchAction in rendering procedure
  845. if (this[IN_MAIN_PROCESS]) {
  846. this._pendingActions.push(payload);
  847. return;
  848. }
  849. doDispatchAction.call(this, payload, opt.silent);
  850. if (opt.flush) {
  851. this._zr.flush(true);
  852. }
  853. else if (opt.flush !== false && env.browser.weChat) {
  854. // In WeChat embeded browser, `requestAnimationFrame` and `setInterval`
  855. // hang when sliding page (on touch event), which cause that zr does not
  856. // refresh util user interaction finished, which is not expected.
  857. // But `dispatchAction` may be called too frequently when pan on touch
  858. // screen, which impacts performance if do not throttle them.
  859. this._throttledZrFlush();
  860. }
  861. flushPendingActions.call(this, opt.silent);
  862. triggerUpdatedEvent.call(this, opt.silent);
  863. };
  864. function doDispatchAction(payload, silent) {
  865. var payloadType = payload.type;
  866. var actionWrap = actions[payloadType];
  867. var actionInfo = actionWrap.actionInfo;
  868. var cptType = (actionInfo.update || 'update').split(':');
  869. var updateMethod = cptType.pop();
  870. cptType = cptType[0] && parseClassType(cptType[0]);
  871. this[IN_MAIN_PROCESS] = true;
  872. var payloads = [payload];
  873. var batched = false;
  874. // Batch action
  875. if (payload.batch) {
  876. batched = true;
  877. payloads = zrUtil.map(payload.batch, function (item) {
  878. item = zrUtil.defaults(zrUtil.extend({}, item), payload);
  879. item.batch = null;
  880. return item;
  881. });
  882. }
  883. var eventObjBatch = [];
  884. var eventObj;
  885. var isHighDown = payloadType === 'highlight' || payloadType === 'downplay';
  886. for (var i = 0; i < payloads.length; i++) {
  887. var batchItem = payloads[i];
  888. // Action can specify the event by return it.
  889. eventObj = actionWrap.action(batchItem, this._model);
  890. // Emit event outside
  891. eventObj = eventObj || zrUtil.extend({}, batchItem);
  892. // Convert type to eventType
  893. eventObj.type = actionInfo.event || eventObj.type;
  894. eventObjBatch.push(eventObj);
  895. // light update does not perform data process, layout and visual.
  896. if (isHighDown) {
  897. // method, payload, mainType, subType
  898. updateDirectly(this, updateMethod, batchItem, 'series');
  899. }
  900. else if (cptType) {
  901. updateDirectly(this, updateMethod, batchItem, cptType.main, cptType.sub);
  902. }
  903. }
  904. if (updateMethod !== 'none' && !isHighDown && !cptType) {
  905. // Still dirty
  906. if (this[OPTION_UPDATED]) {
  907. // FIXME Pass payload ?
  908. updateMethods.prepareAndUpdate.call(this, payload);
  909. this[OPTION_UPDATED] = false;
  910. }
  911. else {
  912. updateMethods[updateMethod].call(this, payload);
  913. }
  914. }
  915. // Follow the rule of action batch
  916. if (batched) {
  917. eventObj = {
  918. type: actionInfo.event || payloadType,
  919. batch: eventObjBatch
  920. };
  921. }
  922. else {
  923. eventObj = eventObjBatch[0];
  924. }
  925. this[IN_MAIN_PROCESS] = false;
  926. !silent && this._messageCenter.trigger(eventObj.type, eventObj);
  927. }
  928. function flushPendingActions(silent) {
  929. var pendingActions = this._pendingActions;
  930. while (pendingActions.length) {
  931. var payload = pendingActions.shift();
  932. doDispatchAction.call(this, payload, silent);
  933. }
  934. }
  935. function triggerUpdatedEvent(silent) {
  936. !silent && this.trigger('updated');
  937. }
  938. /**
  939. * Register event
  940. * @method
  941. */
  942. echartsProto.on = createRegisterEventWithLowercaseName('on');
  943. echartsProto.off = createRegisterEventWithLowercaseName('off');
  944. echartsProto.one = createRegisterEventWithLowercaseName('one');
  945. /**
  946. * @param {string} methodName
  947. * @private
  948. */
  949. function invokeUpdateMethod(methodName, ecModel, payload) {
  950. var api = this._api;
  951. // Update all components
  952. each(this._componentsViews, function (component) {
  953. var componentModel = component.__model;
  954. component[methodName](componentModel, ecModel, api, payload);
  955. updateZ(componentModel, component);
  956. }, this);
  957. // Upate all charts
  958. ecModel.eachSeries(function (seriesModel, idx) {
  959. var chart = this._chartsMap[seriesModel.__viewId];
  960. chart[methodName](seriesModel, ecModel, api, payload);
  961. updateZ(seriesModel, chart);
  962. updateProgressiveAndBlend(seriesModel, chart);
  963. }, this);
  964. // If use hover layer
  965. updateHoverLayerStatus(this._zr, ecModel);
  966. }
  967. /**
  968. * Prepare view instances of charts and components
  969. * @param {module:echarts/model/Global} ecModel
  970. * @private
  971. */
  972. function prepareView(type, ecModel) {
  973. var isComponent = type === 'component';
  974. var viewList = isComponent ? this._componentsViews : this._chartsViews;
  975. var viewMap = isComponent ? this._componentsMap : this._chartsMap;
  976. var zr = this._zr;
  977. for (var i = 0; i < viewList.length; i++) {
  978. viewList[i].__alive = false;
  979. }
  980. ecModel[isComponent ? 'eachComponent' : 'eachSeries'](function (componentType, model) {
  981. if (isComponent) {
  982. if (componentType === 'series') {
  983. return;
  984. }
  985. }
  986. else {
  987. model = componentType;
  988. }
  989. // Consider: id same and type changed.
  990. var viewId = model.id + '_' + model.type;
  991. var view = viewMap[viewId];
  992. if (!view) {
  993. var classType = parseClassType(model.type);
  994. var Clazz = isComponent
  995. ? ComponentView.getClass(classType.main, classType.sub)
  996. : ChartView.getClass(classType.sub);
  997. if (Clazz) {
  998. view = new Clazz();
  999. view.init(ecModel, this._api);
  1000. viewMap[viewId] = view;
  1001. viewList.push(view);
  1002. zr.add(view.group);
  1003. }
  1004. else {
  1005. // Error
  1006. return;
  1007. }
  1008. }
  1009. model.__viewId = viewId;
  1010. view.__alive = true;
  1011. view.__id = viewId;
  1012. view.__model = model;
  1013. }, this);
  1014. for (var i = 0; i < viewList.length;) {
  1015. var view = viewList[i];
  1016. if (!view.__alive) {
  1017. zr.remove(view.group);
  1018. view.dispose(ecModel, this._api);
  1019. viewList.splice(i, 1);
  1020. delete viewMap[view.__id];
  1021. }
  1022. else {
  1023. i++;
  1024. }
  1025. }
  1026. }
  1027. /**
  1028. * Processor data in each series
  1029. *
  1030. * @param {module:echarts/model/Global} ecModel
  1031. * @private
  1032. */
  1033. function processData(ecModel, api) {
  1034. each(dataProcessorFuncs, function (process) {
  1035. process.func(ecModel, api);
  1036. });
  1037. }
  1038. /**
  1039. * @private
  1040. */
  1041. function stackSeriesData(ecModel) {
  1042. var stackedDataMap = {};
  1043. ecModel.eachSeries(function (series) {
  1044. var stack = series.get('stack');
  1045. var data = series.getData();
  1046. if (stack && data.type === 'list') {
  1047. var previousStack = stackedDataMap[stack];
  1048. if (previousStack) {
  1049. data.stackedOn = previousStack;
  1050. }
  1051. stackedDataMap[stack] = data;
  1052. }
  1053. });
  1054. }
  1055. /**
  1056. * Layout before each chart render there series, special visual encoding stage
  1057. *
  1058. * @param {module:echarts/model/Global} ecModel
  1059. * @private
  1060. */
  1061. function doLayout(ecModel, payload) {
  1062. var api = this._api;
  1063. each(visualFuncs, function (visual) {
  1064. if (visual.isLayout) {
  1065. visual.func(ecModel, api, payload);
  1066. }
  1067. });
  1068. }
  1069. /**
  1070. * Encode visual infomation from data after data processing
  1071. *
  1072. * @param {module:echarts/model/Global} ecModel
  1073. * @param {object} layout
  1074. * @param {boolean} [excludesLayout]
  1075. * @private
  1076. */
  1077. function doVisualEncoding(ecModel, payload, excludesLayout) {
  1078. var api = this._api;
  1079. ecModel.clearColorPalette();
  1080. ecModel.eachSeries(function (seriesModel) {
  1081. seriesModel.clearColorPalette();
  1082. });
  1083. each(visualFuncs, function (visual) {
  1084. (!excludesLayout || !visual.isLayout)
  1085. && visual.func(ecModel, api, payload);
  1086. });
  1087. }
  1088. /**
  1089. * Render each chart and component
  1090. * @private
  1091. */
  1092. function doRender(ecModel, payload) {
  1093. var api = this._api;
  1094. // Render all components
  1095. each(this._componentsViews, function (componentView) {
  1096. var componentModel = componentView.__model;
  1097. componentView.render(componentModel, ecModel, api, payload);
  1098. updateZ(componentModel, componentView);
  1099. }, this);
  1100. each(this._chartsViews, function (chart) {
  1101. chart.__alive = false;
  1102. }, this);
  1103. // Render all charts
  1104. ecModel.eachSeries(function (seriesModel, idx) {
  1105. var chartView = this._chartsMap[seriesModel.__viewId];
  1106. chartView.__alive = true;
  1107. chartView.render(seriesModel, ecModel, api, payload);
  1108. chartView.group.silent = !!seriesModel.get('silent');
  1109. updateZ(seriesModel, chartView);
  1110. updateProgressiveAndBlend(seriesModel, chartView);
  1111. }, this);
  1112. // If use hover layer
  1113. updateHoverLayerStatus(this._zr, ecModel);
  1114. // Remove groups of unrendered charts
  1115. each(this._chartsViews, function (chart) {
  1116. if (!chart.__alive) {
  1117. chart.remove(ecModel, api);
  1118. }
  1119. }, this);
  1120. }
  1121. var MOUSE_EVENT_NAMES = [
  1122. 'click', 'dblclick', 'mouseover', 'mouseout', 'mousemove',
  1123. 'mousedown', 'mouseup', 'globalout', 'contextmenu'
  1124. ];
  1125. /**
  1126. * @private
  1127. */
  1128. echartsProto._initEvents = function () {
  1129. each(MOUSE_EVENT_NAMES, function (eveName) {
  1130. this._zr.on(eveName, function (e) {
  1131. var ecModel = this.getModel();
  1132. var el = e.target;
  1133. var params;
  1134. // no e.target when 'globalout'.
  1135. if (eveName === 'globalout') {
  1136. params = {};
  1137. }
  1138. else if (el && el.dataIndex != null) {
  1139. var dataModel = el.dataModel || ecModel.getSeriesByIndex(el.seriesIndex);
  1140. params = dataModel && dataModel.getDataParams(el.dataIndex, el.dataType) || {};
  1141. }
  1142. // If element has custom eventData of components
  1143. else if (el && el.eventData) {
  1144. params = zrUtil.extend({}, el.eventData);
  1145. }
  1146. if (params) {
  1147. params.event = e;
  1148. params.type = eveName;
  1149. this.trigger(eveName, params);
  1150. }
  1151. }, this);
  1152. }, this);
  1153. each(eventActionMap, function (actionType, eventType) {
  1154. this._messageCenter.on(eventType, function (event) {
  1155. this.trigger(eventType, event);
  1156. }, this);
  1157. }, this);
  1158. };
  1159. /**
  1160. * @return {boolean}
  1161. */
  1162. echartsProto.isDisposed = function () {
  1163. return this._disposed;
  1164. };
  1165. /**
  1166. * Clear
  1167. */
  1168. echartsProto.clear = function () {
  1169. this.setOption({ series: [] }, true);
  1170. };
  1171. /**
  1172. * Dispose instance
  1173. */
  1174. echartsProto.dispose = function () {
  1175. if (this._disposed) {
  1176. if (true) {
  1177. console.warn('Instance ' + this.id + ' has been disposed');
  1178. }
  1179. return;
  1180. }
  1181. this._disposed = true;
  1182. var api = this._api;
  1183. var ecModel = this._model;
  1184. each(this._componentsViews, function (component) {
  1185. component.dispose(ecModel, api);
  1186. });
  1187. each(this._chartsViews, function (chart) {
  1188. chart.dispose(ecModel, api);
  1189. });
  1190. // Dispose after all views disposed
  1191. this._zr.dispose();
  1192. delete instances[this.id];
  1193. };
  1194. zrUtil.mixin(ECharts, Eventful);
  1195. function updateHoverLayerStatus(zr, ecModel) {
  1196. var storage = zr.storage;
  1197. var elCount = 0;
  1198. storage.traverse(function (el) {
  1199. if (!el.isGroup) {
  1200. elCount++;
  1201. }
  1202. });
  1203. if (elCount > ecModel.get('hoverLayerThreshold') && !env.node) {
  1204. storage.traverse(function (el) {
  1205. if (!el.isGroup) {
  1206. el.useHoverLayer = true;
  1207. }
  1208. });
  1209. }
  1210. }
  1211. /**
  1212. * Update chart progressive and blend.
  1213. * @param {module:echarts/model/Series|module:echarts/model/Component} model
  1214. * @param {module:echarts/view/Component|module:echarts/view/Chart} view
  1215. */
  1216. function updateProgressiveAndBlend(seriesModel, chartView) {
  1217. // Progressive configuration
  1218. var elCount = 0;
  1219. chartView.group.traverse(function (el) {
  1220. if (el.type !== 'group' && !el.ignore) {
  1221. elCount++;
  1222. }
  1223. });
  1224. var frameDrawNum = +seriesModel.get('progressive');
  1225. var needProgressive = elCount > seriesModel.get('progressiveThreshold') && frameDrawNum && !env.node;
  1226. if (needProgressive) {
  1227. chartView.group.traverse(function (el) {
  1228. // FIXME marker and other components
  1229. if (!el.isGroup) {
  1230. el.progressive = needProgressive ?
  1231. Math.floor(elCount++ / frameDrawNum) : -1;
  1232. if (needProgressive) {
  1233. el.stopAnimation(true);
  1234. }
  1235. }
  1236. });
  1237. }
  1238. // Blend configration
  1239. var blendMode = seriesModel.get('blendMode') || null;
  1240. if (true) {
  1241. if (!env.canvasSupported && blendMode && blendMode !== 'source-over') {
  1242. console.warn('Only canvas support blendMode');
  1243. }
  1244. }
  1245. chartView.group.traverse(function (el) {
  1246. // FIXME marker and other components
  1247. if (!el.isGroup) {
  1248. el.setStyle('blend', blendMode);
  1249. }
  1250. });
  1251. }
  1252. /**
  1253. * @param {module:echarts/model/Series|module:echarts/model/Component} model
  1254. * @param {module:echarts/view/Component|module:echarts/view/Chart} view
  1255. */
  1256. function updateZ(model, view) {
  1257. var z = model.get('z');
  1258. var zlevel = model.get('zlevel');
  1259. // Set z and zlevel
  1260. view.group.traverse(function (el) {
  1261. if (el.type !== 'group') {
  1262. z != null && (el.z = z);
  1263. zlevel != null && (el.zlevel = zlevel);
  1264. }
  1265. });
  1266. }
  1267. /**
  1268. * @type {Array.<Function>}
  1269. * @inner
  1270. */
  1271. var actions = [];
  1272. /**
  1273. * Map eventType to actionType
  1274. * @type {Object}
  1275. */
  1276. var eventActionMap = {};
  1277. /**
  1278. * Data processor functions of each stage
  1279. * @type {Array.<Object.<string, Function>>}
  1280. * @inner
  1281. */
  1282. var dataProcessorFuncs = [];
  1283. /**
  1284. * @type {Array.<Function>}
  1285. * @inner
  1286. */
  1287. var optionPreprocessorFuncs = [];
  1288. /**
  1289. * Visual encoding functions of each stage
  1290. * @type {Array.<Object.<string, Function>>}
  1291. * @inner
  1292. */
  1293. var visualFuncs = [];
  1294. /**
  1295. * Theme storage
  1296. * @type {Object.<key, Object>}
  1297. */
  1298. var themeStorage = {};
  1299. /**
  1300. * Loading effects
  1301. */
  1302. var loadingEffects = {};
  1303. var instances = {};
  1304. var connectedGroups = {};
  1305. var idBase = new Date() - 0;
  1306. var groupIdBase = new Date() - 0;
  1307. var DOM_ATTRIBUTE_KEY = '_echarts_instance_';
  1308. /**
  1309. * @alias module:echarts
  1310. */
  1311. var echarts = {
  1312. /**
  1313. * @type {number}
  1314. */
  1315. version: '3.4.0',
  1316. dependencies: {
  1317. zrender: '3.3.0'
  1318. }
  1319. };
  1320. function enableConnect(chart) {
  1321. var STATUS_PENDING = 0;
  1322. var STATUS_UPDATING = 1;
  1323. var STATUS_UPDATED = 2;
  1324. var STATUS_KEY = '__connectUpdateStatus';
  1325. function updateConnectedChartsStatus(charts, status) {
  1326. for (var i = 0; i < charts.length; i++) {
  1327. var otherChart = charts[i];
  1328. otherChart[STATUS_KEY] = status;
  1329. }
  1330. }
  1331. zrUtil.each(eventActionMap, function (actionType, eventType) {
  1332. chart._messageCenter.on(eventType, function (event) {
  1333. if (connectedGroups[chart.group] && chart[STATUS_KEY] !== STATUS_PENDING) {
  1334. var action = chart.makeActionFromEvent(event);
  1335. var otherCharts = [];
  1336. zrUtil.each(instances, function (otherChart) {
  1337. if (otherChart !== chart && otherChart.group === chart.group) {
  1338. otherCharts.push(otherChart);
  1339. }
  1340. });
  1341. updateConnectedChartsStatus(otherCharts, STATUS_PENDING);
  1342. each(otherCharts, function (otherChart) {
  1343. if (otherChart[STATUS_KEY] !== STATUS_UPDATING) {
  1344. otherChart.dispatchAction(action);
  1345. }
  1346. });
  1347. updateConnectedChartsStatus(otherCharts, STATUS_UPDATED);
  1348. }
  1349. });
  1350. });
  1351. }
  1352. /**
  1353. * @param {HTMLDomElement} dom
  1354. * @param {Object} [theme]
  1355. * @param {Object} opts
  1356. * @param {number} [opts.devicePixelRatio] Use window.devicePixelRatio by default
  1357. * @param {string} [opts.renderer] Currently only 'canvas' is supported.
  1358. * @param {number} [opts.width] Use clientWidth of the input `dom` by default.
  1359. * Can be 'auto' (the same as null/undefined)
  1360. * @param {number} [opts.height] Use clientHeight of the input `dom` by default.
  1361. * Can be 'auto' (the same as null/undefined)
  1362. */
  1363. echarts.init = function (dom, theme, opts) {
  1364. if (true) {
  1365. // Check version
  1366. if ((zrender.version.replace('.', '') - 0) < (echarts.dependencies.zrender.replace('.', '') - 0)) {
  1367. throw new Error(
  1368. 'ZRender ' + zrender.version
  1369. + ' is too old for ECharts ' + echarts.version
  1370. + '. Current version need ZRender '
  1371. + echarts.dependencies.zrender + '+'
  1372. );
  1373. }
  1374. if (!dom) {
  1375. throw new Error('Initialize failed: invalid dom.');
  1376. }
  1377. if (zrUtil.isDom(dom) && dom.nodeName.toUpperCase() !== 'CANVAS' && (!dom.clientWidth || !dom.clientHeight)) {
  1378. console.warn('Can\'t get dom width or height');
  1379. }
  1380. }
  1381. var chart = new ECharts(dom, theme, opts);
  1382. chart.id = 'ec_' + idBase++;
  1383. instances[chart.id] = chart;
  1384. dom.setAttribute &&
  1385. dom.setAttribute(DOM_ATTRIBUTE_KEY, chart.id);
  1386. enableConnect(chart);
  1387. return chart;
  1388. };
  1389. /**
  1390. * @return {string|Array.<module:echarts~ECharts>} groupId
  1391. */
  1392. echarts.connect = function (groupId) {
  1393. // Is array of charts
  1394. if (zrUtil.isArray(groupId)) {
  1395. var charts = groupId;
  1396. groupId = null;
  1397. // If any chart has group
  1398. zrUtil.each(charts, function (chart) {
  1399. if (chart.group != null) {
  1400. groupId = chart.group;
  1401. }
  1402. });
  1403. groupId = groupId || ('g_' + groupIdBase++);
  1404. zrUtil.each(charts, function (chart) {
  1405. chart.group = groupId;
  1406. });
  1407. }
  1408. connectedGroups[groupId] = true;
  1409. return groupId;
  1410. };
  1411. /**
  1412. * @return {string} groupId
  1413. */
  1414. echarts.disConnect = function (groupId) {
  1415. connectedGroups[groupId] = false;
  1416. };
  1417. /**
  1418. * Dispose a chart instance
  1419. * @param {module:echarts~ECharts|HTMLDomElement|string} chart
  1420. */
  1421. echarts.dispose = function (chart) {
  1422. if (zrUtil.isDom(chart)) {
  1423. chart = echarts.getInstanceByDom(chart);
  1424. }
  1425. else if (typeof chart === 'string') {
  1426. chart = instances[chart];
  1427. }
  1428. if ((chart instanceof ECharts) && !chart.isDisposed()) {
  1429. chart.dispose();
  1430. }
  1431. };
  1432. /**
  1433. * @param {HTMLDomElement} dom
  1434. * @return {echarts~ECharts}
  1435. */
  1436. echarts.getInstanceByDom = function (dom) {
  1437. var key = dom.getAttribute(DOM_ATTRIBUTE_KEY);
  1438. return instances[key];
  1439. };
  1440. /**
  1441. * @param {string} key
  1442. * @return {echarts~ECharts}
  1443. */
  1444. echarts.getInstanceById = function (key) {
  1445. return instances[key];
  1446. };
  1447. /**
  1448. * Register theme
  1449. */
  1450. echarts.registerTheme = function (name, theme) {
  1451. themeStorage[name] = theme;
  1452. };
  1453. /**
  1454. * Register option preprocessor
  1455. * @param {Function} preprocessorFunc
  1456. */
  1457. echarts.registerPreprocessor = function (preprocessorFunc) {
  1458. optionPreprocessorFuncs.push(preprocessorFunc);
  1459. };
  1460. /**
  1461. * @param {number} [priority=1000]
  1462. * @param {Function} processorFunc
  1463. */
  1464. echarts.registerProcessor = function (priority, processorFunc) {
  1465. if (typeof priority === 'function') {
  1466. processorFunc = priority;
  1467. priority = PRIORITY_PROCESSOR_FILTER;
  1468. }
  1469. if (true) {
  1470. if (isNaN(priority)) {
  1471. throw new Error('Unkown processor priority');
  1472. }
  1473. }
  1474. dataProcessorFuncs.push({
  1475. prio: priority,
  1476. func: processorFunc
  1477. });
  1478. };
  1479. /**
  1480. * Usage:
  1481. * registerAction('someAction', 'someEvent', function () { ... });
  1482. * registerAction('someAction', function () { ... });
  1483. * registerAction(
  1484. * {type: 'someAction', event: 'someEvent', update: 'updateView'},
  1485. * function () { ... }
  1486. * );
  1487. *
  1488. * @param {(string|Object)} actionInfo
  1489. * @param {string} actionInfo.type
  1490. * @param {string} [actionInfo.event]
  1491. * @param {string} [actionInfo.update]
  1492. * @param {string} [eventName]
  1493. * @param {Function} action
  1494. */
  1495. echarts.registerAction = function (actionInfo, eventName, action) {
  1496. if (typeof eventName === 'function') {
  1497. action = eventName;
  1498. eventName = '';
  1499. }
  1500. var actionType = zrUtil.isObject(actionInfo)
  1501. ? actionInfo.type
  1502. : ([actionInfo, actionInfo = {
  1503. event: eventName
  1504. }][0]);
  1505. // Event name is all lowercase
  1506. actionInfo.event = (actionInfo.event || actionType).toLowerCase();
  1507. eventName = actionInfo.event;
  1508. // Validate action type and event name.
  1509. zrUtil.assert(ACTION_REG.test(actionType) && ACTION_REG.test(eventName));
  1510. if (!actions[actionType]) {
  1511. actions[actionType] = {action: action, actionInfo: actionInfo};
  1512. }
  1513. eventActionMap[eventName] = actionType;
  1514. };
  1515. /**
  1516. * @param {string} type
  1517. * @param {*} CoordinateSystem
  1518. */
  1519. echarts.registerCoordinateSystem = function (type, CoordinateSystem) {
  1520. CoordinateSystemManager.register(type, CoordinateSystem);
  1521. };
  1522. /**
  1523. * Layout is a special stage of visual encoding
  1524. * Most visual encoding like color are common for different chart
  1525. * But each chart has it's own layout algorithm
  1526. *
  1527. * @param {number} [priority=1000]
  1528. * @param {Function} layoutFunc
  1529. */
  1530. echarts.registerLayout = function (priority, layoutFunc) {
  1531. if (typeof priority === 'function') {
  1532. layoutFunc = priority;
  1533. priority = PRIORITY_VISUAL_LAYOUT;
  1534. }
  1535. if (true) {
  1536. if (isNaN(priority)) {
  1537. throw new Error('Unkown layout priority');
  1538. }
  1539. }
  1540. visualFuncs.push({
  1541. prio: priority,
  1542. func: layoutFunc,
  1543. isLayout: true
  1544. });
  1545. };
  1546. /**
  1547. * @param {number} [priority=3000]
  1548. * @param {Function} visualFunc
  1549. */
  1550. echarts.registerVisual = function (priority, visualFunc) {
  1551. if (typeof priority === 'function') {
  1552. visualFunc = priority;
  1553. priority = PRIORITY_VISUAL_CHART;
  1554. }
  1555. if (true) {
  1556. if (isNaN(priority)) {
  1557. throw new Error('Unkown visual priority');
  1558. }
  1559. }
  1560. visualFuncs.push({
  1561. prio: priority,
  1562. func: visualFunc
  1563. });
  1564. };
  1565. /**
  1566. * @param {string} name
  1567. */
  1568. echarts.registerLoading = function (name, loadingFx) {
  1569. loadingEffects[name] = loadingFx;
  1570. };
  1571. /**
  1572. * @param {Object} opts
  1573. * @param {string} [superClass]
  1574. */
  1575. echarts.extendComponentModel = function (opts/*, superClass*/) {
  1576. // var Clazz = ComponentModel;
  1577. // if (superClass) {
  1578. // var classType = parseClassType(superClass);
  1579. // Clazz = ComponentModel.getClass(classType.main, classType.sub, true);
  1580. // }
  1581. return ComponentModel.extend(opts);
  1582. };
  1583. /**
  1584. * @param {Object} opts
  1585. * @param {string} [superClass]
  1586. */
  1587. echarts.extendComponentView = function (opts/*, superClass*/) {
  1588. // var Clazz = ComponentView;
  1589. // if (superClass) {
  1590. // var classType = parseClassType(superClass);
  1591. // Clazz = ComponentView.getClass(classType.main, classType.sub, true);
  1592. // }
  1593. return ComponentView.extend(opts);
  1594. };
  1595. /**
  1596. * @param {Object} opts
  1597. * @param {string} [superClass]
  1598. */
  1599. echarts.extendSeriesModel = function (opts/*, superClass*/) {
  1600. // var Clazz = SeriesModel;
  1601. // if (superClass) {
  1602. // superClass = 'series.' + superClass.replace('series.', '');
  1603. // var classType = parseClassType(superClass);
  1604. // Clazz = ComponentModel.getClass(classType.main, classType.sub, true);
  1605. // }
  1606. return SeriesModel.extend(opts);
  1607. };
  1608. /**
  1609. * @param {Object} opts
  1610. * @param {string} [superClass]
  1611. */
  1612. echarts.extendChartView = function (opts/*, superClass*/) {
  1613. // var Clazz = ChartView;
  1614. // if (superClass) {
  1615. // superClass = superClass.replace('series.', '');
  1616. // var classType = parseClassType(superClass);
  1617. // Clazz = ChartView.getClass(classType.main, true);
  1618. // }
  1619. return ChartView.extend(opts);
  1620. };
  1621. /**
  1622. * ZRender need a canvas context to do measureText.
  1623. * But in node environment canvas may be created by node-canvas.
  1624. * So we need to specify how to create a canvas instead of using document.createElement('canvas')
  1625. *
  1626. * Be careful of using it in the browser.
  1627. *
  1628. * @param {Function} creator
  1629. * @example
  1630. * var Canvas = require('canvas');
  1631. * var echarts = require('echarts');
  1632. * echarts.setCanvasCreator(function () {
  1633. * // Small size is enough.
  1634. * return new Canvas(32, 32);
  1635. * });
  1636. */
  1637. echarts.setCanvasCreator = function (creator) {
  1638. zrUtil.createCanvas = creator;
  1639. };
  1640. echarts.registerVisual(PRIORITY_VISUAL_GLOBAL, __webpack_require__(94));
  1641. echarts.registerPreprocessor(__webpack_require__(95));
  1642. echarts.registerLoading('default', __webpack_require__(97));
  1643. // Default action
  1644. echarts.registerAction({
  1645. type: 'highlight',
  1646. event: 'highlight',
  1647. update: 'highlight'
  1648. }, zrUtil.noop);
  1649. echarts.registerAction({
  1650. type: 'downplay',
  1651. event: 'downplay',
  1652. update: 'downplay'
  1653. }, zrUtil.noop);
  1654. // --------
  1655. // Exports
  1656. // --------
  1657. //
  1658. echarts.List = __webpack_require__(98);
  1659. echarts.Model = __webpack_require__(12);
  1660. echarts.graphic = __webpack_require__(43);
  1661. echarts.number = __webpack_require__(7);
  1662. echarts.format = __webpack_require__(6);
  1663. echarts.throttle = throttle.throttle;
  1664. echarts.matrix = __webpack_require__(11);
  1665. echarts.vector = __webpack_require__(10);
  1666. echarts.color = __webpack_require__(39);
  1667. echarts.util = {};
  1668. each([
  1669. 'map', 'each', 'filter', 'indexOf', 'inherits', 'reduce', 'filter',
  1670. 'bind', 'curry', 'isArray', 'isString', 'isObject', 'isFunction',
  1671. 'extend', 'defaults', 'clone'
  1672. ],
  1673. function (name) {
  1674. echarts.util[name] = zrUtil[name];
  1675. }
  1676. );
  1677. // PRIORITY
  1678. echarts.PRIORITY = {
  1679. PROCESSOR: {
  1680. FILTER: PRIORITY_PROCESSOR_FILTER,
  1681. STATISTIC: PRIORITY_PROCESSOR_STATISTIC
  1682. },
  1683. VISUAL: {
  1684. LAYOUT: PRIORITY_VISUAL_LAYOUT,
  1685. GLOBAL: PRIORITY_VISUAL_GLOBAL,
  1686. CHART: PRIORITY_VISUAL_CHART,
  1687. COMPONENT: PRIORITY_VISUAL_COMPONENT,
  1688. BRUSH: PRIORITY_VISUAL_BRUSH
  1689. }
  1690. };
  1691. module.exports = echarts;
  1692. /***/ },
  1693. /* 2 */
  1694. /***/ function(module, exports) {
  1695. /**
  1696. * echarts设备环境识别
  1697. *
  1698. * @desc echarts基于Canvas,纯Javascript图表库,提供直观,生动,可交互,可个性化定制的数据统计图表。
  1699. * @author firede[firede@firede.us]
  1700. * @desc thanks zepto.
  1701. */
  1702. var env = {};
  1703. if (typeof navigator === 'undefined') {
  1704. // In node
  1705. env = {
  1706. browser: {},
  1707. os: {},
  1708. node: true,
  1709. // Assume canvas is supported
  1710. canvasSupported: true
  1711. };
  1712. }
  1713. else {
  1714. env = detect(navigator.userAgent);
  1715. }
  1716. module.exports = env;
  1717. // Zepto.js
  1718. // (c) 2010-2013 Thomas Fuchs
  1719. // Zepto.js may be freely distributed under the MIT license.
  1720. function detect(ua) {
  1721. var os = {};
  1722. var browser = {};
  1723. // var webkit = ua.match(/Web[kK]it[\/]{0,1}([\d.]+)/);
  1724. // var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
  1725. // var ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
  1726. // var ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
  1727. // var iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/);
  1728. // var webos = ua.match(/(webOS|hpwOS)[\s\/]([\d.]+)/);
  1729. // var touchpad = webos && ua.match(/TouchPad/);
  1730. // var kindle = ua.match(/Kindle\/([\d.]+)/);
  1731. // var silk = ua.match(/Silk\/([\d._]+)/);
  1732. // var blackberry = ua.match(/(BlackBerry).*Version\/([\d.]+)/);
  1733. // var bb10 = ua.match(/(BB10).*Version\/([\d.]+)/);
  1734. // var rimtabletos = ua.match(/(RIM\sTablet\sOS)\s([\d.]+)/);
  1735. // var playbook = ua.match(/PlayBook/);
  1736. // var chrome = ua.match(/Chrome\/([\d.]+)/) || ua.match(/CriOS\/([\d.]+)/);
  1737. var firefox = ua.match(/Firefox\/([\d.]+)/);
  1738. // var safari = webkit && ua.match(/Mobile\//) && !chrome;
  1739. // var webview = ua.match(/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/) && !chrome;
  1740. var ie = ua.match(/MSIE\s([\d.]+)/)
  1741. // IE 11 Trident/7.0; rv:11.0
  1742. || ua.match(/Trident\/.+?rv:(([\d.]+))/);
  1743. var edge = ua.match(/Edge\/([\d.]+)/); // IE 12 and 12+
  1744. var weChat = (/micromessenger/i).test(ua);
  1745. // Todo: clean this up with a better OS/browser seperation:
  1746. // - discern (more) between multiple browsers on android
  1747. // - decide if kindle fire in silk mode is android or not
  1748. // - Firefox on Android doesn't specify the Android version
  1749. // - possibly devide in os, device and browser hashes
  1750. // if (browser.webkit = !!webkit) browser.version = webkit[1];
  1751. // if (android) os.android = true, os.version = android[2];
  1752. // if (iphone && !ipod) os.ios = os.iphone = true, os.version = iphone[2].replace(/_/g, '.');
  1753. // if (ipad) os.ios = os.ipad = true, os.version = ipad[2].replace(/_/g, '.');
  1754. // if (ipod) os.ios = os.ipod = true, os.version = ipod[3] ? ipod[3].replace(/_/g, '.') : null;
  1755. // if (webos) os.webos = true, os.version = webos[2];
  1756. // if (touchpad) os.touchpad = true;
  1757. // if (blackberry) os.blackberry = true, os.version = blackberry[2];
  1758. // if (bb10) os.bb10 = true, os.version = bb10[2];
  1759. // if (rimtabletos) os.rimtabletos = true, os.version = rimtabletos[2];
  1760. // if (playbook) browser.playbook = true;
  1761. // if (kindle) os.kindle = true, os.version = kindle[1];
  1762. // if (silk) browser.silk = true, browser.version = silk[1];
  1763. // if (!silk && os.android && ua.match(/Kindle Fire/)) browser.silk = true;
  1764. // if (chrome) browser.chrome = true, browser.version = chrome[1];
  1765. if (firefox) {
  1766. browser.firefox = true;
  1767. browser.version = firefox[1];
  1768. }
  1769. // if (safari && (ua.match(/Safari/) || !!os.ios)) browser.safari = true;
  1770. // if (webview) browser.webview = true;
  1771. if (ie) {
  1772. browser.ie = true;
  1773. browser.version = ie[1];
  1774. }
  1775. if (edge) {
  1776. browser.edge = true;
  1777. browser.version = edge[1];
  1778. }
  1779. // It is difficult to detect WeChat in Win Phone precisely, because ua can
  1780. // not be set on win phone. So we do not consider Win Phone.
  1781. if (weChat) {
  1782. browser.weChat = true;
  1783. }
  1784. // os.tablet = !!(ipad || playbook || (android && !ua.match(/Mobile/)) ||
  1785. // (firefox && ua.match(/Tablet/)) || (ie && !ua.match(/Phone/) && ua.match(/Touch/)));
  1786. // os.phone = !!(!os.tablet && !os.ipod && (android || iphone || webos ||
  1787. // (chrome && ua.match(/Android/)) || (chrome && ua.match(/CriOS\/([\d.]+)/)) ||
  1788. // (firefox && ua.match(/Mobile/)) || (ie && ua.match(/Touch/))));
  1789. return {
  1790. browser: browser,
  1791. os: os,
  1792. node: false,
  1793. // 原生canvas支持,改极端点了
  1794. // canvasSupported : !(browser.ie && parseFloat(browser.version) < 9)
  1795. canvasSupported : document.createElement('canvas').getContext ? true : false,
  1796. // @see <http://stackoverflow.com/questions/4817029/whats-the-best-way-to-detect-a-touch-screen-device-using-javascript>
  1797. // works on most browsers
  1798. // IE10/11 does not support touch event, and MS Edge supports them but not by
  1799. // default, so we dont check navigator.maxTouchPoints for them here.
  1800. touchEventsSupported: 'ontouchstart' in window && !browser.ie && !browser.edge,
  1801. // <http://caniuse.com/#search=pointer%20event>.
  1802. pointerEventsSupported: 'onpointerdown' in window
  1803. // Firefox supports pointer but not by default, only MS browsers are reliable on pointer
  1804. // events currently. So we dont use that on other browsers unless tested sufficiently.
  1805. // Although IE 10 supports pointer event, it use old style and is different from the
  1806. // standard. So we exclude that. (IE 10 is hardly used on touch device)
  1807. && (browser.edge || (browser.ie && browser.version >= 11))
  1808. };
  1809. }
  1810. /***/ },
  1811. /* 3 */
  1812. /***/ function(module, exports, __webpack_require__) {
  1813. /**
  1814. * ECharts global model
  1815. *
  1816. * @module {echarts/model/Global}
  1817. */
  1818. /**
  1819. * Caution: If the mechanism should be changed some day, these cases
  1820. * should be considered:
  1821. *
  1822. * (1) In `merge option` mode, if using the same option to call `setOption`
  1823. * many times, the result should be the same (try our best to ensure that).
  1824. * (2) In `merge option` mode, if a component has no id/name specified, it
  1825. * will be merged by index, and the result sequence of the components is
  1826. * consistent to the original sequence.
  1827. * (3) `reset` feature (in toolbox). Find detailed info in comments about
  1828. * `mergeOption` in module:echarts/model/OptionManager.
  1829. */
  1830. var zrUtil = __webpack_require__(4);
  1831. var modelUtil = __webpack_require__(5);
  1832. var Model = __webpack_require__(12);
  1833. var each = zrUtil.each;
  1834. var filter = zrUtil.filter;
  1835. var map = zrUtil.map;
  1836. var isArray = zrUtil.isArray;
  1837. var indexOf = zrUtil.indexOf;
  1838. var isObject = zrUtil.isObject;
  1839. var ComponentModel = __webpack_require__(19);
  1840. var globalDefault = __webpack_require__(23);
  1841. var OPTION_INNER_KEY = '\0_ec_inner';
  1842. /**
  1843. * @alias module:echarts/model/Global
  1844. *
  1845. * @param {Object} option
  1846. * @param {module:echarts/model/Model} parentModel
  1847. * @param {Object} theme
  1848. */
  1849. var GlobalModel = Model.extend({
  1850. constructor: GlobalModel,
  1851. init: function (option, parentModel, theme, optionManager) {
  1852. theme = theme || {};
  1853. this.option = null; // Mark as not initialized.
  1854. /**
  1855. * @type {module:echarts/model/Model}
  1856. * @private
  1857. */
  1858. this._theme = new Model(theme);
  1859. /**
  1860. * @type {module:echarts/model/OptionManager}
  1861. */
  1862. this._optionManager = optionManager;
  1863. },
  1864. setOption: function (option, optionPreprocessorFuncs) {
  1865. zrUtil.assert(
  1866. !(OPTION_INNER_KEY in option),
  1867. 'please use chart.getOption()'
  1868. );
  1869. this._optionManager.setOption(option, optionPreprocessorFuncs);
  1870. this.resetOption();
  1871. },
  1872. /**
  1873. * @param {string} type null/undefined: reset all.
  1874. * 'recreate': force recreate all.
  1875. * 'timeline': only reset timeline option
  1876. * 'media': only reset media query option
  1877. * @return {boolean} Whether option changed.
  1878. */
  1879. resetOption: function (type) {
  1880. var optionChanged = false;
  1881. var optionManager = this._optionManager;
  1882. if (!type || type === 'recreate') {
  1883. var baseOption = optionManager.mountOption(type === 'recreate');
  1884. if (!this.option || type === 'recreate') {
  1885. initBase.call(this, baseOption);
  1886. }
  1887. else {
  1888. this.restoreData();
  1889. this.mergeOption(baseOption);
  1890. }
  1891. optionChanged = true;
  1892. }
  1893. if (type === 'timeline' || type === 'media') {
  1894. this.restoreData();
  1895. }
  1896. if (!type || type === 'recreate' || type === 'timeline') {
  1897. var timelineOption = optionManager.getTimelineOption(this);
  1898. timelineOption && (this.mergeOption(timelineOption), optionChanged = true);
  1899. }
  1900. if (!type || type === 'recreate' || type === 'media') {
  1901. var mediaOptions = optionManager.getMediaOption(this, this._api);
  1902. if (mediaOptions.length) {
  1903. each(mediaOptions, function (mediaOption) {
  1904. this.mergeOption(mediaOption, optionChanged = true);
  1905. }, this);
  1906. }
  1907. }
  1908. return optionChanged;
  1909. },
  1910. /**
  1911. * @protected
  1912. */
  1913. mergeOption: function (newOption) {
  1914. var option = this.option;
  1915. var componentsMap = this._componentsMap;
  1916. var newCptTypes = [];
  1917. // 如果不存在对应的 component model 则直接 merge
  1918. each(newOption, function (componentOption, mainType) {
  1919. if (componentOption == null) {
  1920. return;
  1921. }
  1922. if (!ComponentModel.hasClass(mainType)) {
  1923. option[mainType] = option[mainType] == null
  1924. ? zrUtil.clone(componentOption)
  1925. : zrUtil.merge(option[mainType], componentOption, true);
  1926. }
  1927. else {
  1928. newCptTypes.push(mainType);
  1929. }
  1930. });
  1931. // FIXME OPTION 同步是否要改回原来的
  1932. ComponentModel.topologicalTravel(
  1933. newCptTypes, ComponentModel.getAllClassMainTypes(), visitComponent, this
  1934. );
  1935. this._seriesIndices = this._seriesIndices || [];
  1936. function visitComponent(mainType, dependencies) {
  1937. var newCptOptionList = modelUtil.normalizeToArray(newOption[mainType]);
  1938. var mapResult = modelUtil.mappingToExists(
  1939. componentsMap[mainType], newCptOptionList
  1940. );
  1941. modelUtil.makeIdAndName(mapResult);
  1942. // Set mainType and complete subType.
  1943. each(mapResult, function (item, index) {
  1944. var opt = item.option;
  1945. if (isObject(opt)) {
  1946. item.keyInfo.mainType = mainType;
  1947. item.keyInfo.subType = determineSubType(mainType, opt, item.exist);
  1948. }
  1949. });
  1950. var dependentModels = getComponentsByTypes(
  1951. componentsMap, dependencies
  1952. );
  1953. option[mainType] = [];
  1954. componentsMap[mainType] = [];
  1955. each(mapResult, function (resultItem, index) {
  1956. var componentModel = resultItem.exist;
  1957. var newCptOption = resultItem.option;
  1958. zrUtil.assert(
  1959. isObject(newCptOption) || componentModel,
  1960. 'Empty component definition'
  1961. );
  1962. // Consider where is no new option and should be merged using {},
  1963. // see removeEdgeAndAdd in topologicalTravel and
  1964. // ComponentModel.getAllClassMainTypes.
  1965. if (!newCptOption) {
  1966. componentModel.mergeOption({}, this);
  1967. componentModel.optionUpdated({}, false);
  1968. }
  1969. else {
  1970. var ComponentModelClass = ComponentModel.getClass(
  1971. mainType, resultItem.keyInfo.subType, true
  1972. );
  1973. if (componentModel && componentModel instanceof ComponentModelClass) {
  1974. componentModel.name = resultItem.keyInfo.name;
  1975. componentModel.mergeOption(newCptOption, this);
  1976. componentModel.optionUpdated(newCptOption, false);
  1977. }
  1978. else {
  1979. // PENDING Global as parent ?
  1980. var extraOpt = zrUtil.extend(
  1981. {
  1982. dependentModels: dependentModels,
  1983. componentIndex: index
  1984. },
  1985. resultItem.keyInfo
  1986. );
  1987. componentModel = new ComponentModelClass(
  1988. newCptOption, this, this, extraOpt
  1989. );
  1990. zrUtil.extend(componentModel, extraOpt);
  1991. componentModel.init(newCptOption, this, this, extraOpt);
  1992. // Call optionUpdated after init.
  1993. // newCptOption has been used as componentModel.option
  1994. // and may be merged with theme and default, so pass null
  1995. // to avoid confusion.
  1996. componentModel.optionUpdated(null, true);
  1997. }
  1998. }
  1999. componentsMap[mainType][index] = componentModel;
  2000. option[mainType][index] = componentModel.option;
  2001. }, this);
  2002. // Backup series for filtering.
  2003. if (mainType === 'series') {
  2004. this._seriesIndices = createSeriesIndices(componentsMap.series);
  2005. }
  2006. }
  2007. },
  2008. /**
  2009. * Get option for output (cloned option and inner info removed)
  2010. * @public
  2011. * @return {Object}
  2012. */
  2013. getOption: function () {
  2014. var option = zrUtil.clone(this.option);
  2015. each(option, function (opts, mainType) {
  2016. if (ComponentModel.hasClass(mainType)) {
  2017. var opts = modelUtil.normalizeToArray(opts);
  2018. for (var i = opts.length - 1; i >= 0; i--) {
  2019. // Remove options with inner id.
  2020. if (modelUtil.isIdInner(opts[i])) {
  2021. opts.splice(i, 1);
  2022. }
  2023. }
  2024. option[mainType] = opts;
  2025. }
  2026. });
  2027. delete option[OPTION_INNER_KEY];
  2028. return option;
  2029. },
  2030. /**
  2031. * @return {module:echarts/model/Model}
  2032. */
  2033. getTheme: function () {
  2034. return this._theme;
  2035. },
  2036. /**
  2037. * @param {string} mainType
  2038. * @param {number} [idx=0]
  2039. * @return {module:echarts/model/Component}
  2040. */
  2041. getComponent: function (mainType, idx) {
  2042. var list = this._componentsMap[mainType];
  2043. if (list) {
  2044. return list[idx || 0];
  2045. }
  2046. },
  2047. /**
  2048. * If none of index and id and name used, return all components with mainType.
  2049. * @param {Object} condition
  2050. * @param {string} condition.mainType
  2051. * @param {string} [condition.subType] If ignore, only query by mainType
  2052. * @param {number|Array.<number>} [condition.index] Either input index or id or name.
  2053. * @param {string|Array.<string>} [condition.id] Either input index or id or name.
  2054. * @param {string|Array.<string>} [condition.name] Either input index or id or name.
  2055. * @return {Array.<module:echarts/model/Component>}
  2056. */
  2057. queryComponents: function (condition) {
  2058. var mainType = condition.mainType;
  2059. if (!mainType) {
  2060. return [];
  2061. }
  2062. var index = condition.index;
  2063. var id = condition.id;
  2064. var name = condition.name;
  2065. var cpts = this._componentsMap[mainType];
  2066. if (!cpts || !cpts.length) {
  2067. return [];
  2068. }
  2069. var result;
  2070. if (index != null) {
  2071. if (!isArray(index)) {
  2072. index = [index];
  2073. }
  2074. result = filter(map(index, function (idx) {
  2075. return cpts[idx];
  2076. }), function (val) {
  2077. return !!val;
  2078. });
  2079. }
  2080. else if (id != null) {
  2081. var isIdArray = isArray(id);
  2082. result = filter(cpts, function (cpt) {
  2083. return (isIdArray && indexOf(id, cpt.id) >= 0)
  2084. || (!isIdArray && cpt.id === id);
  2085. });
  2086. }
  2087. else if (name != null) {
  2088. var isNameArray = isArray(name);
  2089. result = filter(cpts, function (cpt) {
  2090. return (isNameArray && indexOf(name, cpt.name) >= 0)
  2091. || (!isNameArray && cpt.name === name);
  2092. });
  2093. }
  2094. else {
  2095. // Return all components with mainType
  2096. result = cpts;
  2097. }
  2098. return filterBySubType(result, condition);
  2099. },
  2100. /**
  2101. * The interface is different from queryComponents,
  2102. * which is convenient for inner usage.
  2103. *
  2104. * @usage
  2105. * var result = findComponents(
  2106. * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}}
  2107. * );
  2108. * var result = findComponents(
  2109. * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}}
  2110. * );
  2111. * var result = findComponents(
  2112. * {mainType: 'series'},
  2113. * function (model, index) {...}
  2114. * );
  2115. * // result like [component0, componnet1, ...]
  2116. *
  2117. * @param {Object} condition
  2118. * @param {string} condition.mainType Mandatory.
  2119. * @param {string} [condition.subType] Optional.
  2120. * @param {Object} [condition.query] like {xxxIndex, xxxId, xxxName},
  2121. * where xxx is mainType.
  2122. * If query attribute is null/undefined or has no index/id/name,
  2123. * do not filtering by query conditions, which is convenient for
  2124. * no-payload situations or when target of action is global.
  2125. * @param {Function} [condition.filter] parameter: component, return boolean.
  2126. * @return {Array.<module:echarts/model/Component>}
  2127. */
  2128. findComponents: function (condition) {
  2129. var query = condition.query;
  2130. var mainType = condition.mainType;
  2131. var queryCond = getQueryCond(query);
  2132. var result = queryCond
  2133. ? this.queryComponents(queryCond)
  2134. : this._componentsMap[mainType];
  2135. return doFilter(filterBySubType(result, condition));
  2136. function getQueryCond(q) {
  2137. var indexAttr = mainType + 'Index';
  2138. var idAttr = mainType + 'Id';
  2139. var nameAttr = mainType + 'Name';
  2140. return q && (
  2141. q[indexAttr] != null
  2142. || q[idAttr] != null
  2143. || q[nameAttr] != null
  2144. )
  2145. ? {
  2146. mainType: mainType,
  2147. // subType will be filtered finally.
  2148. index: q[indexAttr],
  2149. id: q[idAttr],
  2150. name: q[nameAttr]
  2151. }
  2152. : null;
  2153. }
  2154. function doFilter(res) {
  2155. return condition.filter
  2156. ? filter(res, condition.filter)
  2157. : res;
  2158. }
  2159. },
  2160. /**
  2161. * @usage
  2162. * eachComponent('legend', function (legendModel, index) {
  2163. * ...
  2164. * });
  2165. * eachComponent(function (componentType, model, index) {
  2166. * // componentType does not include subType
  2167. * // (componentType is 'xxx' but not 'xxx.aa')
  2168. * });
  2169. * eachComponent(
  2170. * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}},
  2171. * function (model, index) {...}
  2172. * );
  2173. * eachComponent(
  2174. * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}},
  2175. * function (model, index) {...}
  2176. * );
  2177. *
  2178. * @param {string|Object=} mainType When mainType is object, the definition
  2179. * is the same as the method 'findComponents'.
  2180. * @param {Function} cb
  2181. * @param {*} context
  2182. */
  2183. eachComponent: function (mainType, cb, context) {
  2184. var componentsMap = this._componentsMap;
  2185. if (typeof mainType === 'function') {
  2186. context = cb;
  2187. cb = mainType;
  2188. each(componentsMap, function (components, componentType) {
  2189. each(components, function (component, index) {
  2190. cb.call(context, componentType, component, index);
  2191. });
  2192. });
  2193. }
  2194. else if (zrUtil.isString(mainType)) {
  2195. each(componentsMap[mainType], cb, context);
  2196. }
  2197. else if (isObject(mainType)) {
  2198. var queryResult = this.findComponents(mainType);
  2199. each(queryResult, cb, context);
  2200. }
  2201. },
  2202. /**
  2203. * @param {string} name
  2204. * @return {Array.<module:echarts/model/Series>}
  2205. */
  2206. getSeriesByName: function (name) {
  2207. var series = this._componentsMap.series;
  2208. return filter(series, function (oneSeries) {
  2209. return oneSeries.name === name;
  2210. });
  2211. },
  2212. /**
  2213. * @param {number} seriesIndex
  2214. * @return {module:echarts/model/Series}
  2215. */
  2216. getSeriesByIndex: function (seriesIndex) {
  2217. return this._componentsMap.series[seriesIndex];
  2218. },
  2219. /**
  2220. * @param {string} subType
  2221. * @return {Array.<module:echarts/model/Series>}
  2222. */
  2223. getSeriesByType: function (subType) {
  2224. var series = this._componentsMap.series;
  2225. return filter(series, function (oneSeries) {
  2226. return oneSeries.subType === subType;
  2227. });
  2228. },
  2229. /**
  2230. * @return {Array.<module:echarts/model/Series>}
  2231. */
  2232. getSeries: function () {
  2233. return this._componentsMap.series.slice();
  2234. },
  2235. /**
  2236. * After filtering, series may be different
  2237. * frome raw series.
  2238. *
  2239. * @param {Function} cb
  2240. * @param {*} context
  2241. */
  2242. eachSeries: function (cb, context) {
  2243. assertSeriesInitialized(this);
  2244. each(this._seriesIndices, function (rawSeriesIndex) {
  2245. var series = this._componentsMap.series[rawSeriesIndex];
  2246. cb.call(context, series, rawSeriesIndex);
  2247. }, this);
  2248. },
  2249. /**
  2250. * Iterate raw series before filtered.
  2251. *
  2252. * @param {Function} cb
  2253. * @param {*} context
  2254. */
  2255. eachRawSeries: function (cb, context) {
  2256. each(this._componentsMap.series, cb, context);
  2257. },
  2258. /**
  2259. * After filtering, series may be different.
  2260. * frome raw series.
  2261. *
  2262. * @parma {string} subType
  2263. * @param {Function} cb
  2264. * @param {*} context
  2265. */
  2266. eachSeriesByType: function (subType, cb, context) {
  2267. assertSeriesInitialized(this);
  2268. each(this._seriesIndices, function (rawSeriesIndex) {
  2269. var series = this._componentsMap.series[rawSeriesIndex];
  2270. if (series.subType === subType) {
  2271. cb.call(context, series, rawSeriesIndex);
  2272. }
  2273. }, this);
  2274. },
  2275. /**
  2276. * Iterate raw series before filtered of given type.
  2277. *
  2278. * @parma {string} subType
  2279. * @param {Function} cb
  2280. * @param {*} context
  2281. */
  2282. eachRawSeriesByType: function (subType, cb, context) {
  2283. return each(this.getSeriesByType(subType), cb, context);
  2284. },
  2285. /**
  2286. * @param {module:echarts/model/Series} seriesModel
  2287. */
  2288. isSeriesFiltered: function (seriesModel) {
  2289. assertSeriesInitialized(this);
  2290. return zrUtil.indexOf(this._seriesIndices, seriesModel.componentIndex) < 0;
  2291. },
  2292. /**
  2293. * @param {Function} cb
  2294. * @param {*} context
  2295. */
  2296. filterSeries: function (cb, context) {
  2297. assertSeriesInitialized(this);
  2298. var filteredSeries = filter(
  2299. this._componentsMap.series, cb, context
  2300. );
  2301. this._seriesIndices = createSeriesIndices(filteredSeries);
  2302. },
  2303. restoreData: function () {
  2304. var componentsMap = this._componentsMap;
  2305. this._seriesIndices = createSeriesIndices(componentsMap.series);
  2306. var componentTypes = [];
  2307. each(componentsMap, function (components, componentType) {
  2308. componentTypes.push(componentType);
  2309. });
  2310. ComponentModel.topologicalTravel(
  2311. componentTypes,
  2312. ComponentModel.getAllClassMainTypes(),
  2313. function (componentType, dependencies) {
  2314. each(componentsMap[componentType], function (component) {
  2315. component.restoreData();
  2316. });
  2317. }
  2318. );
  2319. }
  2320. });
  2321. /**
  2322. * @inner
  2323. */
  2324. function mergeTheme(option, theme) {
  2325. zrUtil.each(theme, function (themeItem, name) {
  2326. // 如果有 component model 则把具体的 merge 逻辑交给该 model 处理
  2327. if (!ComponentModel.hasClass(name)) {
  2328. if (typeof themeItem === 'object') {
  2329. option[name] = !option[name]
  2330. ? zrUtil.clone(themeItem)
  2331. : zrUtil.merge(option[name], themeItem, false);
  2332. }
  2333. else {
  2334. if (option[name] == null) {
  2335. option[name] = themeItem;
  2336. }
  2337. }
  2338. }
  2339. });
  2340. }
  2341. function initBase(baseOption) {
  2342. baseOption = baseOption;
  2343. // Using OPTION_INNER_KEY to mark that this option can not be used outside,
  2344. // i.e. `chart.setOption(chart.getModel().option);` is forbiden.
  2345. this.option = {};
  2346. this.option[OPTION_INNER_KEY] = 1;
  2347. /**
  2348. * @type {Object.<string, Array.<module:echarts/model/Model>>}
  2349. * @private
  2350. */
  2351. this._componentsMap = {};
  2352. /**
  2353. * Mapping between filtered series list and raw series list.
  2354. * key: filtered series indices, value: raw series indices.
  2355. * @type {Array.<nubmer>}
  2356. * @private
  2357. */
  2358. this._seriesIndices = null;
  2359. mergeTheme(baseOption, this._theme.option);
  2360. // TODO Needs clone when merging to the unexisted property
  2361. zrUtil.merge(baseOption, globalDefault, false);
  2362. this.mergeOption(baseOption);
  2363. }
  2364. /**
  2365. * @inner
  2366. * @param {Array.<string>|string} types model types
  2367. * @return {Object} key: {string} type, value: {Array.<Object>} models
  2368. */
  2369. function getComponentsByTypes(componentsMap, types) {
  2370. if (!zrUtil.isArray(types)) {
  2371. types = types ? [types] : [];
  2372. }
  2373. var ret = {};
  2374. each(types, function (type) {
  2375. ret[type] = (componentsMap[type] || []).slice();
  2376. });
  2377. return ret;
  2378. }
  2379. /**
  2380. * @inner
  2381. */
  2382. function determineSubType(mainType, newCptOption, existComponent) {
  2383. var subType = newCptOption.type
  2384. ? newCptOption.type
  2385. : existComponent
  2386. ? existComponent.subType
  2387. // Use determineSubType only when there is no existComponent.
  2388. : ComponentModel.determineSubType(mainType, newCptOption);
  2389. // tooltip, markline, markpoint may always has no subType
  2390. return subType;
  2391. }
  2392. /**
  2393. * @inner
  2394. */
  2395. function createSeriesIndices(seriesModels) {
  2396. return map(seriesModels, function (series) {
  2397. return series.componentIndex;
  2398. }) || [];
  2399. }
  2400. /**
  2401. * @inner
  2402. */
  2403. function filterBySubType(components, condition) {
  2404. // Using hasOwnProperty for restrict. Consider
  2405. // subType is undefined in user payload.
  2406. return condition.hasOwnProperty('subType')
  2407. ? filter(components, function (cpt) {
  2408. return cpt.subType === condition.subType;
  2409. })
  2410. : components;
  2411. }
  2412. /**
  2413. * @inner
  2414. */
  2415. function assertSeriesInitialized(ecModel) {
  2416. // Components that use _seriesIndices should depends on series component,
  2417. // which make sure that their initialization is after series.
  2418. if (true) {
  2419. if (!ecModel._seriesIndices) {
  2420. throw new Error('Series has not been initialized yet.');
  2421. }
  2422. }
  2423. }
  2424. zrUtil.mixin(GlobalModel, __webpack_require__(24));
  2425. module.exports = GlobalModel;
  2426. /***/ },
  2427. /* 4 */
  2428. /***/ function(module, exports) {
  2429. /**
  2430. * @module zrender/core/util
  2431. */
  2432. // 用于处理merge时无法遍历Date等对象的问题
  2433. var BUILTIN_OBJECT = {
  2434. '[object Function]': 1,
  2435. '[object RegExp]': 1,
  2436. '[object Date]': 1,
  2437. '[object Error]': 1,
  2438. '[object CanvasGradient]': 1,
  2439. '[object CanvasPattern]': 1,
  2440. // For node-canvas
  2441. '[object Image]': 1,
  2442. '[object Canvas]': 1
  2443. };
  2444. var TYPED_ARRAY = {
  2445. '[object Int8Array]': 1,
  2446. '[object Uint8Array]': 1,
  2447. '[object Uint8ClampedArray]': 1,
  2448. '[object Int16Array]': 1,
  2449. '[object Uint16Array]': 1,
  2450. '[object Int32Array]': 1,
  2451. '[object Uint32Array]': 1,
  2452. '[object Float32Array]': 1,
  2453. '[object Float64Array]': 1
  2454. };
  2455. var objToString = Object.prototype.toString;
  2456. var arrayProto = Array.prototype;
  2457. var nativeForEach = arrayProto.forEach;
  2458. var nativeFilter = arrayProto.filter;
  2459. var nativeSlice = arrayProto.slice;
  2460. var nativeMap = arrayProto.map;
  2461. var nativeReduce = arrayProto.reduce;
  2462. /**
  2463. * Those data types can be cloned:
  2464. * Plain object, Array, TypedArray, number, string, null, undefined.
  2465. * Those data types will be assgined using the orginal data:
  2466. * BUILTIN_OBJECT
  2467. * Instance of user defined class will be cloned to a plain object, without
  2468. * properties in prototype.
  2469. * Other data types is not supported (not sure what will happen).
  2470. *
  2471. * Caution: do not support clone Date, for performance consideration.
  2472. * (There might be a large number of date in `series.data`).
  2473. * So date should not be modified in and out of echarts.
  2474. *
  2475. * @param {*} source
  2476. * @return {*} new
  2477. */
  2478. function clone(source) {
  2479. if (source == null || typeof source != 'object') {
  2480. return source;
  2481. }
  2482. var result = source;
  2483. var typeStr = objToString.call(source);
  2484. if (typeStr === '[object Array]') {
  2485. result = [];
  2486. for (var i = 0, len = source.length; i < len; i++) {
  2487. result[i] = clone(source[i]);
  2488. }
  2489. }
  2490. else if (TYPED_ARRAY[typeStr]) {
  2491. result = source.constructor.from(source);
  2492. }
  2493. else if (!BUILTIN_OBJECT[typeStr] && !isDom(source)) {
  2494. result = {};
  2495. for (var key in source) {
  2496. if (source.hasOwnProperty(key)) {
  2497. result[key] = clone(source[key]);
  2498. }
  2499. }
  2500. }
  2501. return result;
  2502. }
  2503. /**
  2504. * @memberOf module:zrender/core/util
  2505. * @param {*} target
  2506. * @param {*} source
  2507. * @param {boolean} [overwrite=false]
  2508. */
  2509. function merge(target, source, overwrite) {
  2510. // We should escapse that source is string
  2511. // and enter for ... in ...
  2512. if (!isObject(source) || !isObject(target)) {
  2513. return overwrite ? clone(source) : target;
  2514. }
  2515. for (var key in source) {
  2516. if (source.hasOwnProperty(key)) {
  2517. var targetProp = target[key];
  2518. var sourceProp = source[key];
  2519. if (isObject(sourceProp)
  2520. && isObject(targetProp)
  2521. && !isArray(sourceProp)
  2522. && !isArray(targetProp)
  2523. && !isDom(sourceProp)
  2524. && !isDom(targetProp)
  2525. && !isBuildInObject(sourceProp)
  2526. && !isBuildInObject(targetProp)
  2527. ) {
  2528. // 如果需要递归覆盖,就递归调用merge
  2529. merge(targetProp, sourceProp, overwrite);
  2530. }
  2531. else if (overwrite || !(key in target)) {
  2532. // 否则只处理overwrite为true,或者在目标对象中没有此属性的情况
  2533. // NOTE,在 target[key] 不存在的时候也是直接覆盖
  2534. target[key] = clone(source[key], true);
  2535. }
  2536. }
  2537. }
  2538. return target;
  2539. }
  2540. /**
  2541. * @param {Array} targetAndSources The first item is target, and the rests are source.
  2542. * @param {boolean} [overwrite=false]
  2543. * @return {*} target
  2544. */
  2545. function mergeAll(targetAndSources, overwrite) {
  2546. var result = targetAndSources[0];
  2547. for (var i = 1, len = targetAndSources.length; i < len; i++) {
  2548. result = merge(result, targetAndSources[i], overwrite);
  2549. }
  2550. return result;
  2551. }
  2552. /**
  2553. * @param {*} target
  2554. * @param {*} source
  2555. * @memberOf module:zrender/core/util
  2556. */
  2557. function extend(target, source) {
  2558. for (var key in source) {
  2559. if (source.hasOwnProperty(key)) {
  2560. target[key] = source[key];
  2561. }
  2562. }
  2563. return target;
  2564. }
  2565. /**
  2566. * @param {*} target
  2567. * @param {*} source
  2568. * @param {boolen} [overlay=false]
  2569. * @memberOf module:zrender/core/util
  2570. */
  2571. function defaults(target, source, overlay) {
  2572. for (var key in source) {
  2573. if (source.hasOwnProperty(key)
  2574. && (overlay ? source[key] != null : target[key] == null)
  2575. ) {
  2576. target[key] = source[key];
  2577. }
  2578. }
  2579. return target;
  2580. }
  2581. function createCanvas() {
  2582. return document.createElement('canvas');
  2583. }
  2584. // FIXME
  2585. var _ctx;
  2586. function getContext() {
  2587. if (!_ctx) {
  2588. // Use util.createCanvas instead of createCanvas
  2589. // because createCanvas may be overwritten in different environment
  2590. _ctx = util.createCanvas().getContext('2d');
  2591. }
  2592. return _ctx;
  2593. }
  2594. /**
  2595. * 查询数组中元素的index
  2596. * @memberOf module:zrender/core/util
  2597. */
  2598. function indexOf(array, value) {
  2599. if (array) {
  2600. if (array.indexOf) {
  2601. return array.indexOf(value);
  2602. }
  2603. for (var i = 0, len = array.length; i < len; i++) {
  2604. if (array[i] === value) {
  2605. return i;
  2606. }
  2607. }
  2608. }
  2609. return -1;
  2610. }
  2611. /**
  2612. * 构造类继承关系
  2613. *
  2614. * @memberOf module:zrender/core/util
  2615. * @param {Function} clazz 源类
  2616. * @param {Function} baseClazz 基类
  2617. */
  2618. function inherits(clazz, baseClazz) {
  2619. var clazzPrototype = clazz.prototype;
  2620. function F() {}
  2621. F.prototype = baseClazz.prototype;
  2622. clazz.prototype = new F();
  2623. for (var prop in clazzPrototype) {
  2624. clazz.prototype[prop] = clazzPrototype[prop];
  2625. }
  2626. clazz.prototype.constructor = clazz;
  2627. clazz.superClass = baseClazz;
  2628. }
  2629. /**
  2630. * @memberOf module:zrender/core/util
  2631. * @param {Object|Function} target
  2632. * @param {Object|Function} sorce
  2633. * @param {boolean} overlay
  2634. */
  2635. function mixin(target, source, overlay) {
  2636. target = 'prototype' in target ? target.prototype : target;
  2637. source = 'prototype' in source ? source.prototype : source;
  2638. defaults(target, source, overlay);
  2639. }
  2640. /**
  2641. * @param {Array|TypedArray} data
  2642. */
  2643. function isArrayLike(data) {
  2644. if (! data) {
  2645. return;
  2646. }
  2647. if (typeof data == 'string') {
  2648. return false;
  2649. }
  2650. return typeof data.length == 'number';
  2651. }
  2652. /**
  2653. * 数组或对象遍历
  2654. * @memberOf module:zrender/core/util
  2655. * @param {Object|Array} obj
  2656. * @param {Function} cb
  2657. * @param {*} [context]
  2658. */
  2659. function each(obj, cb, context) {
  2660. if (!(obj && cb)) {
  2661. return;
  2662. }
  2663. if (obj.forEach && obj.forEach === nativeForEach) {
  2664. obj.forEach(cb, context);
  2665. }
  2666. else if (obj.length === +obj.length) {
  2667. for (var i = 0, len = obj.length; i < len; i++) {
  2668. cb.call(context, obj[i], i, obj);
  2669. }
  2670. }
  2671. else {
  2672. for (var key in obj) {
  2673. if (obj.hasOwnProperty(key)) {
  2674. cb.call(context, obj[key], key, obj);
  2675. }
  2676. }
  2677. }
  2678. }
  2679. /**
  2680. * 数组映射
  2681. * @memberOf module:zrender/core/util
  2682. * @param {Array} obj
  2683. * @param {Function} cb
  2684. * @param {*} [context]
  2685. * @return {Array}
  2686. */
  2687. function map(obj, cb, context) {
  2688. if (!(obj && cb)) {
  2689. return;
  2690. }
  2691. if (obj.map && obj.map === nativeMap) {
  2692. return obj.map(cb, context);
  2693. }
  2694. else {
  2695. var result = [];
  2696. for (var i = 0, len = obj.length; i < len; i++) {
  2697. result.push(cb.call(context, obj[i], i, obj));
  2698. }
  2699. return result;
  2700. }
  2701. }
  2702. /**
  2703. * @memberOf module:zrender/core/util
  2704. * @param {Array} obj
  2705. * @param {Function} cb
  2706. * @param {Object} [memo]
  2707. * @param {*} [context]
  2708. * @return {Array}
  2709. */
  2710. function reduce(obj, cb, memo, context) {
  2711. if (!(obj && cb)) {
  2712. return;
  2713. }
  2714. if (obj.reduce && obj.reduce === nativeReduce) {
  2715. return obj.reduce(cb, memo, context);
  2716. }
  2717. else {
  2718. for (var i = 0, len = obj.length; i < len; i++) {
  2719. memo = cb.call(context, memo, obj[i], i, obj);
  2720. }
  2721. return memo;
  2722. }
  2723. }
  2724. /**
  2725. * 数组过滤
  2726. * @memberOf module:zrender/core/util
  2727. * @param {Array} obj
  2728. * @param {Function} cb
  2729. * @param {*} [context]
  2730. * @return {Array}
  2731. */
  2732. function filter(obj, cb, context) {
  2733. if (!(obj && cb)) {
  2734. return;
  2735. }
  2736. if (obj.filter && obj.filter === nativeFilter) {
  2737. return obj.filter(cb, context);
  2738. }
  2739. else {
  2740. var result = [];
  2741. for (var i = 0, len = obj.length; i < len; i++) {
  2742. if (cb.call(context, obj[i], i, obj)) {
  2743. result.push(obj[i]);
  2744. }
  2745. }
  2746. return result;
  2747. }
  2748. }
  2749. /**
  2750. * 数组项查找
  2751. * @memberOf module:zrender/core/util
  2752. * @param {Array} obj
  2753. * @param {Function} cb
  2754. * @param {*} [context]
  2755. * @return {Array}
  2756. */
  2757. function find(obj, cb, context) {
  2758. if (!(obj && cb)) {
  2759. return;
  2760. }
  2761. for (var i = 0, len = obj.length; i < len; i++) {
  2762. if (cb.call(context, obj[i], i, obj)) {
  2763. return obj[i];
  2764. }
  2765. }
  2766. }
  2767. /**
  2768. * @memberOf module:zrender/core/util
  2769. * @param {Function} func
  2770. * @param {*} context
  2771. * @return {Function}
  2772. */
  2773. function bind(func, context) {
  2774. var args = nativeSlice.call(arguments, 2);
  2775. return function () {
  2776. return func.apply(context, args.concat(nativeSlice.call(arguments)));
  2777. };
  2778. }
  2779. /**
  2780. * @memberOf module:zrender/core/util
  2781. * @param {Function} func
  2782. * @return {Function}
  2783. */
  2784. function curry(func) {
  2785. var args = nativeSlice.call(arguments, 1);
  2786. return function () {
  2787. return func.apply(this, args.concat(nativeSlice.call(arguments)));
  2788. };
  2789. }
  2790. /**
  2791. * @memberOf module:zrender/core/util
  2792. * @param {*} value
  2793. * @return {boolean}
  2794. */
  2795. function isArray(value) {
  2796. return objToString.call(value) === '[object Array]';
  2797. }
  2798. /**
  2799. * @memberOf module:zrender/core/util
  2800. * @param {*} value
  2801. * @return {boolean}
  2802. */
  2803. function isFunction(value) {
  2804. return typeof value === 'function';
  2805. }
  2806. /**
  2807. * @memberOf module:zrender/core/util
  2808. * @param {*} value
  2809. * @return {boolean}
  2810. */
  2811. function isString(value) {
  2812. return objToString.call(value) === '[object String]';
  2813. }
  2814. /**
  2815. * @memberOf module:zrender/core/util
  2816. * @param {*} value
  2817. * @return {boolean}
  2818. */
  2819. function isObject(value) {
  2820. // Avoid a V8 JIT bug in Chrome 19-20.
  2821. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  2822. var type = typeof value;
  2823. return type === 'function' || (!!value && type == 'object');
  2824. }
  2825. /**
  2826. * @memberOf module:zrender/core/util
  2827. * @param {*} value
  2828. * @return {boolean}
  2829. */
  2830. function isBuildInObject(value) {
  2831. return !!BUILTIN_OBJECT[objToString.call(value)];
  2832. }
  2833. /**
  2834. * @memberOf module:zrender/core/util
  2835. * @param {*} value
  2836. * @return {boolean}
  2837. */
  2838. function isDom(value) {
  2839. return typeof value === 'object'
  2840. && typeof value.nodeType === 'number'
  2841. && typeof value.ownerDocument === 'object';
  2842. }
  2843. /**
  2844. * Whether is exactly NaN. Notice isNaN('a') returns true.
  2845. * @param {*} value
  2846. * @return {boolean}
  2847. */
  2848. function eqNaN(value) {
  2849. return value !== value;
  2850. }
  2851. /**
  2852. * If value1 is not null, then return value1, otherwise judget rest of values.
  2853. * @memberOf module:zrender/core/util
  2854. * @return {*} Final value
  2855. */
  2856. function retrieve(values) {
  2857. for (var i = 0, len = arguments.length; i < len; i++) {
  2858. if (arguments[i] != null) {
  2859. return arguments[i];
  2860. }
  2861. }
  2862. }
  2863. /**
  2864. * @memberOf module:zrender/core/util
  2865. * @param {Array} arr
  2866. * @param {number} startIndex
  2867. * @param {number} endIndex
  2868. * @return {Array}
  2869. */
  2870. function slice() {
  2871. return Function.call.apply(nativeSlice, arguments);
  2872. }
  2873. /**
  2874. * @memberOf module:zrender/core/util
  2875. * @param {boolean} condition
  2876. * @param {string} message
  2877. */
  2878. function assert(condition, message) {
  2879. if (!condition) {
  2880. throw new Error(message);
  2881. }
  2882. }
  2883. var util = {
  2884. inherits: inherits,
  2885. mixin: mixin,
  2886. clone: clone,
  2887. merge: merge,
  2888. mergeAll: mergeAll,
  2889. extend: extend,
  2890. defaults: defaults,
  2891. getContext: getContext,
  2892. createCanvas: createCanvas,
  2893. indexOf: indexOf,
  2894. slice: slice,
  2895. find: find,
  2896. isArrayLike: isArrayLike,
  2897. each: each,
  2898. map: map,
  2899. reduce: reduce,
  2900. filter: filter,
  2901. bind: bind,
  2902. curry: curry,
  2903. isArray: isArray,
  2904. isString: isString,
  2905. isObject: isObject,
  2906. isFunction: isFunction,
  2907. isBuildInObject: isBuildInObject,
  2908. isDom: isDom,
  2909. eqNaN: eqNaN,
  2910. retrieve: retrieve,
  2911. assert: assert,
  2912. noop: function () {}
  2913. };
  2914. module.exports = util;
  2915. /***/ },
  2916. /* 5 */
  2917. /***/ function(module, exports, __webpack_require__) {
  2918. var formatUtil = __webpack_require__(6);
  2919. var nubmerUtil = __webpack_require__(7);
  2920. var Model = __webpack_require__(12);
  2921. var zrUtil = __webpack_require__(4);
  2922. var each = zrUtil.each;
  2923. var isObject = zrUtil.isObject;
  2924. var modelUtil = {};
  2925. /**
  2926. * If value is not array, then translate it to array.
  2927. * @param {*} value
  2928. * @return {Array} [value] or value
  2929. */
  2930. modelUtil.normalizeToArray = function (value) {
  2931. return value instanceof Array
  2932. ? value
  2933. : value == null
  2934. ? []
  2935. : [value];
  2936. };
  2937. /**
  2938. * Sync default option between normal and emphasis like `position` and `show`
  2939. * In case some one will write code like
  2940. * label: {
  2941. * normal: {
  2942. * show: false,
  2943. * position: 'outside',
  2944. * textStyle: {
  2945. * fontSize: 18
  2946. * }
  2947. * },
  2948. * emphasis: {
  2949. * show: true
  2950. * }
  2951. * }
  2952. * @param {Object} opt
  2953. * @param {Array.<string>} subOpts
  2954. */
  2955. modelUtil.defaultEmphasis = function (opt, subOpts) {
  2956. if (opt) {
  2957. var emphasisOpt = opt.emphasis = opt.emphasis || {};
  2958. var normalOpt = opt.normal = opt.normal || {};
  2959. // Default emphasis option from normal
  2960. each(subOpts, function (subOptName) {
  2961. var val = zrUtil.retrieve(emphasisOpt[subOptName], normalOpt[subOptName]);
  2962. if (val != null) {
  2963. emphasisOpt[subOptName] = val;
  2964. }
  2965. });
  2966. }
  2967. };
  2968. modelUtil.LABEL_OPTIONS = ['position', 'offset', 'show', 'textStyle', 'distance', 'formatter'];
  2969. /**
  2970. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  2971. * This helper method retieves value from data.
  2972. * @param {string|number|Date|Array|Object} dataItem
  2973. * @return {number|string|Date|Array.<number|string|Date>}
  2974. */
  2975. modelUtil.getDataItemValue = function (dataItem) {
  2976. // Performance sensitive.
  2977. return dataItem && (dataItem.value == null ? dataItem : dataItem.value);
  2978. };
  2979. /**
  2980. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  2981. * This helper method determine if dataItem has extra option besides value
  2982. * @param {string|number|Date|Array|Object} dataItem
  2983. */
  2984. modelUtil.isDataItemOption = function (dataItem) {
  2985. return isObject(dataItem)
  2986. && !(dataItem instanceof Array);
  2987. // // markLine data can be array
  2988. // && !(dataItem[0] && isObject(dataItem[0]) && !(dataItem[0] instanceof Array));
  2989. };
  2990. /**
  2991. * This helper method convert value in data.
  2992. * @param {string|number|Date} value
  2993. * @param {Object|string} [dimInfo] If string (like 'x'), dimType defaults 'number'.
  2994. */
  2995. modelUtil.converDataValue = function (value, dimInfo) {
  2996. // Performance sensitive.
  2997. var dimType = dimInfo && dimInfo.type;
  2998. if (dimType === 'ordinal') {
  2999. return value;
  3000. }
  3001. if (dimType === 'time' && !isFinite(value) && value != null && value !== '-') {
  3002. value = +nubmerUtil.parseDate(value);
  3003. }
  3004. // dimType defaults 'number'.
  3005. // If dimType is not ordinal and value is null or undefined or NaN or '-',
  3006. // parse to NaN.
  3007. return (value == null || value === '')
  3008. ? NaN : +value; // If string (like '-'), using '+' parse to NaN
  3009. };
  3010. /**
  3011. * Create a model proxy to be used in tooltip for edge data, markLine data, markPoint data.
  3012. * @param {module:echarts/data/List} data
  3013. * @param {Object} opt
  3014. * @param {string} [opt.seriesIndex]
  3015. * @param {Object} [opt.name]
  3016. * @param {Object} [opt.mainType]
  3017. * @param {Object} [opt.subType]
  3018. */
  3019. modelUtil.createDataFormatModel = function (data, opt) {
  3020. var model = new Model();
  3021. zrUtil.mixin(model, modelUtil.dataFormatMixin);
  3022. model.seriesIndex = opt.seriesIndex;
  3023. model.name = opt.name || '';
  3024. model.mainType = opt.mainType;
  3025. model.subType = opt.subType;
  3026. model.getData = function () {
  3027. return data;
  3028. };
  3029. return model;
  3030. };
  3031. // PENDING A little ugly
  3032. modelUtil.dataFormatMixin = {
  3033. /**
  3034. * Get params for formatter
  3035. * @param {number} dataIndex
  3036. * @param {string} [dataType]
  3037. * @return {Object}
  3038. */
  3039. getDataParams: function (dataIndex, dataType) {
  3040. var data = this.getData(dataType);
  3041. var seriesIndex = this.seriesIndex;
  3042. var seriesName = this.name;
  3043. var rawValue = this.getRawValue(dataIndex, dataType);
  3044. var rawDataIndex = data.getRawIndex(dataIndex);
  3045. var name = data.getName(dataIndex, true);
  3046. var itemOpt = data.getRawDataItem(dataIndex);
  3047. return {
  3048. componentType: this.mainType,
  3049. componentSubType: this.subType,
  3050. seriesType: this.mainType === 'series' ? this.subType : null,
  3051. seriesIndex: seriesIndex,
  3052. seriesName: seriesName,
  3053. name: name,
  3054. dataIndex: rawDataIndex,
  3055. data: itemOpt,
  3056. dataType: dataType,
  3057. value: rawValue,
  3058. color: data.getItemVisual(dataIndex, 'color'),
  3059. // Param name list for mapping `a`, `b`, `c`, `d`, `e`
  3060. $vars: ['seriesName', 'name', 'value']
  3061. };
  3062. },
  3063. /**
  3064. * Format label
  3065. * @param {number} dataIndex
  3066. * @param {string} [status='normal'] 'normal' or 'emphasis'
  3067. * @param {string} [dataType]
  3068. * @param {number} [dimIndex]
  3069. * @return {string}
  3070. */
  3071. getFormattedLabel: function (dataIndex, status, dataType, dimIndex) {
  3072. status = status || 'normal';
  3073. var data = this.getData(dataType);
  3074. var itemModel = data.getItemModel(dataIndex);
  3075. var params = this.getDataParams(dataIndex, dataType);
  3076. if (dimIndex != null && (params.value instanceof Array)) {
  3077. params.value = params.value[dimIndex];
  3078. }
  3079. var formatter = itemModel.get(['label', status, 'formatter']);
  3080. if (typeof formatter === 'function') {
  3081. params.status = status;
  3082. return formatter(params);
  3083. }
  3084. else if (typeof formatter === 'string') {
  3085. return formatUtil.formatTpl(formatter, params);
  3086. }
  3087. },
  3088. /**
  3089. * Get raw value in option
  3090. * @param {number} idx
  3091. * @param {string} [dataType]
  3092. * @return {Object}
  3093. */
  3094. getRawValue: function (idx, dataType) {
  3095. var data = this.getData(dataType);
  3096. var dataItem = data.getRawDataItem(idx);
  3097. if (dataItem != null) {
  3098. return (isObject(dataItem) && !(dataItem instanceof Array))
  3099. ? dataItem.value : dataItem;
  3100. }
  3101. },
  3102. /**
  3103. * Should be implemented.
  3104. * @param {number} dataIndex
  3105. * @param {boolean} [multipleSeries=false]
  3106. * @param {number} [dataType]
  3107. * @return {string} tooltip string
  3108. */
  3109. formatTooltip: zrUtil.noop
  3110. };
  3111. /**
  3112. * Mapping to exists for merge.
  3113. *
  3114. * @public
  3115. * @param {Array.<Object>|Array.<module:echarts/model/Component>} exists
  3116. * @param {Object|Array.<Object>} newCptOptions
  3117. * @return {Array.<Object>} Result, like [{exist: ..., option: ...}, {}],
  3118. * index of which is the same as exists.
  3119. */
  3120. modelUtil.mappingToExists = function (exists, newCptOptions) {
  3121. // Mapping by the order by original option (but not order of
  3122. // new option) in merge mode. Because we should ensure
  3123. // some specified index (like xAxisIndex) is consistent with
  3124. // original option, which is easy to understand, espatially in
  3125. // media query. And in most case, merge option is used to
  3126. // update partial option but not be expected to change order.
  3127. newCptOptions = (newCptOptions || []).slice();
  3128. var result = zrUtil.map(exists || [], function (obj, index) {
  3129. return {exist: obj};
  3130. });
  3131. // Mapping by id or name if specified.
  3132. each(newCptOptions, function (cptOption, index) {
  3133. if (!isObject(cptOption)) {
  3134. return;
  3135. }
  3136. // id has highest priority.
  3137. for (var i = 0; i < result.length; i++) {
  3138. if (!result[i].option // Consider name: two map to one.
  3139. && cptOption.id != null
  3140. && result[i].exist.id === cptOption.id + ''
  3141. ) {
  3142. result[i].option = cptOption;
  3143. newCptOptions[index] = null;
  3144. return;
  3145. }
  3146. }
  3147. for (var i = 0; i < result.length; i++) {
  3148. var exist = result[i].exist;
  3149. if (!result[i].option // Consider name: two map to one.
  3150. // Can not match when both ids exist but different.
  3151. && (exist.id == null || cptOption.id == null)
  3152. && cptOption.name != null
  3153. && !modelUtil.isIdInner(cptOption)
  3154. && !modelUtil.isIdInner(exist)
  3155. && exist.name === cptOption.name + ''
  3156. ) {
  3157. result[i].option = cptOption;
  3158. newCptOptions[index] = null;
  3159. return;
  3160. }
  3161. }
  3162. });
  3163. // Otherwise mapping by index.
  3164. each(newCptOptions, function (cptOption, index) {
  3165. if (!isObject(cptOption)) {
  3166. return;
  3167. }
  3168. var i = 0;
  3169. for (; i < result.length; i++) {
  3170. var exist = result[i].exist;
  3171. if (!result[i].option
  3172. // Existing model that already has id should be able to
  3173. // mapped to (because after mapping performed model may
  3174. // be assigned with a id, whish should not affect next
  3175. // mapping), except those has inner id.
  3176. && !modelUtil.isIdInner(exist)
  3177. // Caution:
  3178. // Do not overwrite id. But name can be overwritten,
  3179. // because axis use name as 'show label text'.
  3180. // 'exist' always has id and name and we dont
  3181. // need to check it.
  3182. && cptOption.id == null
  3183. ) {
  3184. result[i].option = cptOption;
  3185. break;
  3186. }
  3187. }
  3188. if (i >= result.length) {
  3189. result.push({option: cptOption});
  3190. }
  3191. });
  3192. return result;
  3193. };
  3194. /**
  3195. * Make id and name for mapping result (result of mappingToExists)
  3196. * into `keyInfo` field.
  3197. *
  3198. * @public
  3199. * @param {Array.<Object>} Result, like [{exist: ..., option: ...}, {}],
  3200. * which order is the same as exists.
  3201. * @return {Array.<Object>} The input.
  3202. */
  3203. modelUtil.makeIdAndName = function (mapResult) {
  3204. // We use this id to hash component models and view instances
  3205. // in echarts. id can be specified by user, or auto generated.
  3206. // The id generation rule ensures new view instance are able
  3207. // to mapped to old instance when setOption are called in
  3208. // no-merge mode. So we generate model id by name and plus
  3209. // type in view id.
  3210. // name can be duplicated among components, which is convenient
  3211. // to specify multi components (like series) by one name.
  3212. // Ensure that each id is distinct.
  3213. var idMap = {};
  3214. each(mapResult, function (item, index) {
  3215. var existCpt = item.exist;
  3216. existCpt && (idMap[existCpt.id] = item);
  3217. });
  3218. each(mapResult, function (item, index) {
  3219. var opt = item.option;
  3220. zrUtil.assert(
  3221. !opt || opt.id == null || !idMap[opt.id] || idMap[opt.id] === item,
  3222. 'id duplicates: ' + (opt && opt.id)
  3223. );
  3224. opt && opt.id != null && (idMap[opt.id] = item);
  3225. !item.keyInfo && (item.keyInfo = {});
  3226. });
  3227. // Make name and id.
  3228. each(mapResult, function (item, index) {
  3229. var existCpt = item.exist;
  3230. var opt = item.option;
  3231. var keyInfo = item.keyInfo;
  3232. if (!isObject(opt)) {
  3233. return;
  3234. }
  3235. // name can be overwitten. Consider case: axis.name = '20km'.
  3236. // But id generated by name will not be changed, which affect
  3237. // only in that case: setOption with 'not merge mode' and view
  3238. // instance will be recreated, which can be accepted.
  3239. keyInfo.name = opt.name != null
  3240. ? opt.name + ''
  3241. : existCpt
  3242. ? existCpt.name
  3243. : '\0-';
  3244. if (existCpt) {
  3245. keyInfo.id = existCpt.id;
  3246. }
  3247. else if (opt.id != null) {
  3248. keyInfo.id = opt.id + '';
  3249. }
  3250. else {
  3251. // Consider this situatoin:
  3252. // optionA: [{name: 'a'}, {name: 'a'}, {..}]
  3253. // optionB [{..}, {name: 'a'}, {name: 'a'}]
  3254. // Series with the same name between optionA and optionB
  3255. // should be mapped.
  3256. var idNum = 0;
  3257. do {
  3258. keyInfo.id = '\0' + keyInfo.name + '\0' + idNum++;
  3259. }
  3260. while (idMap[keyInfo.id]);
  3261. }
  3262. idMap[keyInfo.id] = item;
  3263. });
  3264. };
  3265. /**
  3266. * @public
  3267. * @param {Object} cptOption
  3268. * @return {boolean}
  3269. */
  3270. modelUtil.isIdInner = function (cptOption) {
  3271. return isObject(cptOption)
  3272. && cptOption.id
  3273. && (cptOption.id + '').indexOf('\0_ec_\0') === 0;
  3274. };
  3275. /**
  3276. * A helper for removing duplicate items between batchA and batchB,
  3277. * and in themselves, and categorize by series.
  3278. *
  3279. * @param {Array.<Object>} batchA Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
  3280. * @param {Array.<Object>} batchB Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
  3281. * @return {Array.<Array.<Object>, Array.<Object>>} result: [resultBatchA, resultBatchB]
  3282. */
  3283. modelUtil.compressBatches = function (batchA, batchB) {
  3284. var mapA = {};
  3285. var mapB = {};
  3286. makeMap(batchA || [], mapA);
  3287. makeMap(batchB || [], mapB, mapA);
  3288. return [mapToArray(mapA), mapToArray(mapB)];
  3289. function makeMap(sourceBatch, map, otherMap) {
  3290. for (var i = 0, len = sourceBatch.length; i < len; i++) {
  3291. var seriesId = sourceBatch[i].seriesId;
  3292. var dataIndices = modelUtil.normalizeToArray(sourceBatch[i].dataIndex);
  3293. var otherDataIndices = otherMap && otherMap[seriesId];
  3294. for (var j = 0, lenj = dataIndices.length; j < lenj; j++) {
  3295. var dataIndex = dataIndices[j];
  3296. if (otherDataIndices && otherDataIndices[dataIndex]) {
  3297. otherDataIndices[dataIndex] = null;
  3298. }
  3299. else {
  3300. (map[seriesId] || (map[seriesId] = {}))[dataIndex] = 1;
  3301. }
  3302. }
  3303. }
  3304. }
  3305. function mapToArray(map, isData) {
  3306. var result = [];
  3307. for (var i in map) {
  3308. if (map.hasOwnProperty(i) && map[i] != null) {
  3309. if (isData) {
  3310. result.push(+i);
  3311. }
  3312. else {
  3313. var dataIndices = mapToArray(map[i], true);
  3314. dataIndices.length && result.push({seriesId: i, dataIndex: dataIndices});
  3315. }
  3316. }
  3317. }
  3318. return result;
  3319. }
  3320. };
  3321. /**
  3322. * @param {module:echarts/data/List} data
  3323. * @param {Object} payload Contains dataIndex (means rawIndex) / dataIndexInside / name
  3324. * each of which can be Array or primary type.
  3325. * @return {number|Array.<number>} dataIndex If not found, return undefined/null.
  3326. */
  3327. modelUtil.queryDataIndex = function (data, payload) {
  3328. if (payload.dataIndexInside != null) {
  3329. return payload.dataIndexInside;
  3330. }
  3331. else if (payload.dataIndex != null) {
  3332. return zrUtil.isArray(payload.dataIndex)
  3333. ? zrUtil.map(payload.dataIndex, function (value) {
  3334. return data.indexOfRawIndex(value);
  3335. })
  3336. : data.indexOfRawIndex(payload.dataIndex);
  3337. }
  3338. else if (payload.name != null) {
  3339. return zrUtil.isArray(payload.name)
  3340. ? zrUtil.map(payload.name, function (value) {
  3341. return data.indexOfName(value);
  3342. })
  3343. : data.indexOfName(payload.name);
  3344. }
  3345. };
  3346. /**
  3347. * @param {module:echarts/model/Global} ecModel
  3348. * @param {string|Object} finder
  3349. * If string, e.g., 'geo', means {geoIndex: 0}.
  3350. * If Object, could contain some of these properties below:
  3351. * {
  3352. * seriesIndex, seriesId, seriesName,
  3353. * geoIndex, geoId, goeName,
  3354. * bmapIndex, bmapId, bmapName,
  3355. * xAxisIndex, xAxisId, xAxisName,
  3356. * yAxisIndex, yAxisId, yAxisName,
  3357. * gridIndex, gridId, gridName,
  3358. * ... (can be extended)
  3359. * }
  3360. * Each properties can be number|string|Array.<number>|Array.<string>
  3361. * For example, a finder could be
  3362. * {
  3363. * seriesIndex: 3,
  3364. * geoId: ['aa', 'cc'],
  3365. * gridName: ['xx', 'rr']
  3366. * }
  3367. * @param {Object} [opt]
  3368. * @param {string} [opt.defaultMainType]
  3369. * @return {Object} result like:
  3370. * {
  3371. * seriesModels: [seriesModel1, seriesModel2],
  3372. * seriesModel: seriesModel1, // The first model
  3373. * geoModels: [geoModel1, geoModel2],
  3374. * geoModel: geoModel1, // The first model
  3375. * ...
  3376. * }
  3377. */
  3378. modelUtil.parseFinder = function (ecModel, finder, opt) {
  3379. if (zrUtil.isString(finder)) {
  3380. var obj = {};
  3381. obj[finder + 'Index'] = 0;
  3382. finder = obj;
  3383. }
  3384. var defaultMainType = opt && opt.defaultMainType;
  3385. if (defaultMainType
  3386. && !has(finder, defaultMainType + 'Index')
  3387. && !has(finder, defaultMainType + 'Id')
  3388. && !has(finder, defaultMainType + 'Name')
  3389. ) {
  3390. finder[defaultMainType + 'Index'] = 0;
  3391. }
  3392. var result = {};
  3393. each(finder, function (value, key) {
  3394. var value = finder[key];
  3395. // Exclude 'dataIndex' and other illgal keys.
  3396. if (key === 'dataIndex' || key === 'dataIndexInside') {
  3397. result[key] = value;
  3398. return;
  3399. }
  3400. var parsedKey = key.match(/^(\w+)(Index|Id|Name)$/) || [];
  3401. var mainType = parsedKey[1];
  3402. var queryType = parsedKey[2];
  3403. if (!mainType || !queryType) {
  3404. return;
  3405. }
  3406. var queryParam = {mainType: mainType};
  3407. queryParam[queryType.toLowerCase()] = value;
  3408. var models = ecModel.queryComponents(queryParam);
  3409. result[mainType + 'Models'] = models;
  3410. result[mainType + 'Model'] = models[0];
  3411. });
  3412. return result;
  3413. };
  3414. function has(obj, prop) {
  3415. return obj && obj.hasOwnProperty(prop);
  3416. }
  3417. module.exports = modelUtil;
  3418. /***/ },
  3419. /* 6 */
  3420. /***/ function(module, exports, __webpack_require__) {
  3421. var zrUtil = __webpack_require__(4);
  3422. var numberUtil = __webpack_require__(7);
  3423. var textContain = __webpack_require__(8);
  3424. var formatUtil = {};
  3425. /**
  3426. * 每三位默认加,格式化
  3427. * @type {string|number} x
  3428. */
  3429. formatUtil.addCommas = function (x) {
  3430. if (isNaN(x)) {
  3431. return '-';
  3432. }
  3433. x = (x + '').split('.');
  3434. return x[0].replace(/(\d{1,3})(?=(?:\d{3})+(?!\d))/g,'$1,')
  3435. + (x.length > 1 ? ('.' + x[1]) : '');
  3436. };
  3437. /**
  3438. * @param {string} str
  3439. * @param {boolean} [upperCaseFirst=false]
  3440. * @return {string} str
  3441. */
  3442. formatUtil.toCamelCase = function (str, upperCaseFirst) {
  3443. str = (str || '').toLowerCase().replace(/-(.)/g, function(match, group1) {
  3444. return group1.toUpperCase();
  3445. });
  3446. if (upperCaseFirst && str) {
  3447. str = str.charAt(0).toUpperCase() + str.slice(1);
  3448. }
  3449. return str;
  3450. };
  3451. /**
  3452. * Normalize css liked array configuration
  3453. * e.g.
  3454. * 3 => [3, 3, 3, 3]
  3455. * [4, 2] => [4, 2, 4, 2]
  3456. * [4, 3, 2] => [4, 3, 2, 3]
  3457. * @param {number|Array.<number>} val
  3458. */
  3459. formatUtil.normalizeCssArray = function (val) {
  3460. var len = val.length;
  3461. if (typeof (val) === 'number') {
  3462. return [val, val, val, val];
  3463. }
  3464. else if (len === 2) {
  3465. // vertical | horizontal
  3466. return [val[0], val[1], val[0], val[1]];
  3467. }
  3468. else if (len === 3) {
  3469. // top | horizontal | bottom
  3470. return [val[0], val[1], val[2], val[1]];
  3471. }
  3472. return val;
  3473. };
  3474. var encodeHTML = formatUtil.encodeHTML = function (source) {
  3475. return String(source)
  3476. .replace(/&/g, '&amp;')
  3477. .replace(/</g, '&lt;')
  3478. .replace(/>/g, '&gt;')
  3479. .replace(/"/g, '&quot;')
  3480. .replace(/'/g, '&#39;');
  3481. };
  3482. var TPL_VAR_ALIAS = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
  3483. var wrapVar = function (varName, seriesIdx) {
  3484. return '{' + varName + (seriesIdx == null ? '' : seriesIdx) + '}';
  3485. };
  3486. /**
  3487. * Template formatter
  3488. * @param {string} tpl
  3489. * @param {Array.<Object>|Object} paramsList
  3490. * @param {boolean} [encode=false]
  3491. * @return {string}
  3492. */
  3493. formatUtil.formatTpl = function (tpl, paramsList, encode) {
  3494. if (!zrUtil.isArray(paramsList)) {
  3495. paramsList = [paramsList];
  3496. }
  3497. var seriesLen = paramsList.length;
  3498. if (!seriesLen) {
  3499. return '';
  3500. }
  3501. var $vars = paramsList[0].$vars || [];
  3502. for (var i = 0; i < $vars.length; i++) {
  3503. var alias = TPL_VAR_ALIAS[i];
  3504. var val = wrapVar(alias, 0);
  3505. tpl = tpl.replace(wrapVar(alias), encode ? encodeHTML(val) : val);
  3506. }
  3507. for (var seriesIdx = 0; seriesIdx < seriesLen; seriesIdx++) {
  3508. for (var k = 0; k < $vars.length; k++) {
  3509. var val = paramsList[seriesIdx][$vars[k]];
  3510. tpl = tpl.replace(
  3511. wrapVar(TPL_VAR_ALIAS[k], seriesIdx),
  3512. encode ? encodeHTML(val) : val
  3513. );
  3514. }
  3515. }
  3516. return tpl;
  3517. };
  3518. /**
  3519. * @param {string} str
  3520. * @return {string}
  3521. * @inner
  3522. */
  3523. var s2d = function (str) {
  3524. return str < 10 ? ('0' + str) : str;
  3525. };
  3526. /**
  3527. * ISO Date format
  3528. * @param {string} tpl
  3529. * @param {number} value
  3530. * @inner
  3531. */
  3532. formatUtil.formatTime = function (tpl, value) {
  3533. if (tpl === 'week'
  3534. || tpl === 'month'
  3535. || tpl === 'quarter'
  3536. || tpl === 'half-year'
  3537. || tpl === 'year'
  3538. ) {
  3539. tpl = 'MM-dd\nyyyy';
  3540. }
  3541. var date = numberUtil.parseDate(value);
  3542. var y = date.getFullYear();
  3543. var M = date.getMonth() + 1;
  3544. var d = date.getDate();
  3545. var h = date.getHours();
  3546. var m = date.getMinutes();
  3547. var s = date.getSeconds();
  3548. tpl = tpl.replace('MM', s2d(M))
  3549. .toLowerCase()
  3550. .replace('yyyy', y)
  3551. .replace('yy', y % 100)
  3552. .replace('dd', s2d(d))
  3553. .replace('d', d)
  3554. .replace('hh', s2d(h))
  3555. .replace('h', h)
  3556. .replace('mm', s2d(m))
  3557. .replace('m', m)
  3558. .replace('ss', s2d(s))
  3559. .replace('s', s);
  3560. return tpl;
  3561. };
  3562. /**
  3563. * Capital first
  3564. * @param {string} str
  3565. * @return {string}
  3566. */
  3567. formatUtil.capitalFirst = function (str) {
  3568. return str ? str.charAt(0).toUpperCase() + str.substr(1) : str;
  3569. };
  3570. formatUtil.truncateText = textContain.truncateText;
  3571. module.exports = formatUtil;
  3572. /***/ },
  3573. /* 7 */
  3574. /***/ function(module, exports) {
  3575. /**
  3576. * 数值处理模块
  3577. * @module echarts/util/number
  3578. */
  3579. var number = {};
  3580. var RADIAN_EPSILON = 1e-4;
  3581. function _trim(str) {
  3582. return str.replace(/^\s+/, '').replace(/\s+$/, '');
  3583. }
  3584. /**
  3585. * Linear mapping a value from domain to range
  3586. * @memberOf module:echarts/util/number
  3587. * @param {(number|Array.<number>)} val
  3588. * @param {Array.<number>} domain Domain extent domain[0] can be bigger than domain[1]
  3589. * @param {Array.<number>} range Range extent range[0] can be bigger than range[1]
  3590. * @param {boolean} clamp
  3591. * @return {(number|Array.<number>}
  3592. */
  3593. number.linearMap = function (val, domain, range, clamp) {
  3594. var subDomain = domain[1] - domain[0];
  3595. var subRange = range[1] - range[0];
  3596. if (subDomain === 0) {
  3597. return subRange === 0
  3598. ? range[0]
  3599. : (range[0] + range[1]) / 2;
  3600. }
  3601. // Avoid accuracy problem in edge, such as
  3602. // 146.39 - 62.83 === 83.55999999999999.
  3603. // See echarts/test/ut/spec/util/number.js#linearMap#accuracyError
  3604. // It is a little verbose for efficiency considering this method
  3605. // is a hotspot.
  3606. if (clamp) {
  3607. if (subDomain > 0) {
  3608. if (val <= domain[0]) {
  3609. return range[0];
  3610. }
  3611. else if (val >= domain[1]) {
  3612. return range[1];
  3613. }
  3614. }
  3615. else {
  3616. if (val >= domain[0]) {
  3617. return range[0];
  3618. }
  3619. else if (val <= domain[1]) {
  3620. return range[1];
  3621. }
  3622. }
  3623. }
  3624. else {
  3625. if (val === domain[0]) {
  3626. return range[0];
  3627. }
  3628. if (val === domain[1]) {
  3629. return range[1];
  3630. }
  3631. }
  3632. return (val - domain[0]) / subDomain * subRange + range[0];
  3633. };
  3634. /**
  3635. * Convert a percent string to absolute number.
  3636. * Returns NaN if percent is not a valid string or number
  3637. * @memberOf module:echarts/util/number
  3638. * @param {string|number} percent
  3639. * @param {number} all
  3640. * @return {number}
  3641. */
  3642. number.parsePercent = function(percent, all) {
  3643. switch (percent) {
  3644. case 'center':
  3645. case 'middle':
  3646. percent = '50%';
  3647. break;
  3648. case 'left':
  3649. case 'top':
  3650. percent = '0%';
  3651. break;
  3652. case 'right':
  3653. case 'bottom':
  3654. percent = '100%';
  3655. break;
  3656. }
  3657. if (typeof percent === 'string') {
  3658. if (_trim(percent).match(/%$/)) {
  3659. return parseFloat(percent) / 100 * all;
  3660. }
  3661. return parseFloat(percent);
  3662. }
  3663. return percent == null ? NaN : +percent;
  3664. };
  3665. /**
  3666. * Fix rounding error of float numbers
  3667. * @param {number} x
  3668. * @return {number}
  3669. */
  3670. number.round = function (x, precision) {
  3671. if (precision == null) {
  3672. precision = 10;
  3673. }
  3674. // Avoid range error
  3675. precision = Math.min(Math.max(0, precision), 20);
  3676. return +(+x).toFixed(precision);
  3677. };
  3678. number.asc = function (arr) {
  3679. arr.sort(function (a, b) {
  3680. return a - b;
  3681. });
  3682. return arr;
  3683. };
  3684. /**
  3685. * Get precision
  3686. * @param {number} val
  3687. */
  3688. number.getPrecision = function (val) {
  3689. val = +val;
  3690. if (isNaN(val)) {
  3691. return 0;
  3692. }
  3693. // It is much faster than methods converting number to string as follows
  3694. // var tmp = val.toString();
  3695. // return tmp.length - 1 - tmp.indexOf('.');
  3696. // especially when precision is low
  3697. var e = 1;
  3698. var count = 0;
  3699. while (Math.round(val * e) / e !== val) {
  3700. e *= 10;
  3701. count++;
  3702. }
  3703. return count;
  3704. };
  3705. number.getPrecisionSafe = function (val) {
  3706. var str = val.toString();
  3707. var dotIndex = str.indexOf('.');
  3708. if (dotIndex < 0) {
  3709. return 0;
  3710. }
  3711. return str.length - 1 - dotIndex;
  3712. };
  3713. /**
  3714. * Minimal dicernible data precisioin according to a single pixel.
  3715. * @param {Array.<number>} dataExtent
  3716. * @param {Array.<number>} pixelExtent
  3717. * @return {number} precision
  3718. */
  3719. number.getPixelPrecision = function (dataExtent, pixelExtent) {
  3720. var log = Math.log;
  3721. var LN10 = Math.LN10;
  3722. var dataQuantity = Math.floor(log(dataExtent[1] - dataExtent[0]) / LN10);
  3723. var sizeQuantity = Math.round(log(Math.abs(pixelExtent[1] - pixelExtent[0])) / LN10);
  3724. // toFixed() digits argument must be between 0 and 20.
  3725. var precision = Math.min(Math.max(-dataQuantity + sizeQuantity, 0), 20);
  3726. return !isFinite(precision) ? 20 : precision;
  3727. };
  3728. // Number.MAX_SAFE_INTEGER, ie do not support.
  3729. number.MAX_SAFE_INTEGER = 9007199254740991;
  3730. /**
  3731. * To 0 - 2 * PI, considering negative radian.
  3732. * @param {number} radian
  3733. * @return {number}
  3734. */
  3735. number.remRadian = function (radian) {
  3736. var pi2 = Math.PI * 2;
  3737. return (radian % pi2 + pi2) % pi2;
  3738. };
  3739. /**
  3740. * @param {type} radian
  3741. * @return {boolean}
  3742. */
  3743. number.isRadianAroundZero = function (val) {
  3744. return val > -RADIAN_EPSILON && val < RADIAN_EPSILON;
  3745. };
  3746. /**
  3747. * @param {string|Date|number} value
  3748. * @return {Date} date
  3749. */
  3750. number.parseDate = function (value) {
  3751. if (value instanceof Date) {
  3752. return value;
  3753. }
  3754. else if (typeof value === 'string') {
  3755. // Treat as ISO format. See issue #3623
  3756. var ret = new Date(value);
  3757. if (isNaN(+ret)) {
  3758. // FIXME new Date('1970-01-01') is UTC, new Date('1970/01/01') is local
  3759. ret = new Date(new Date(value.replace(/-/g, '/')) - new Date('1970/01/01'));
  3760. }
  3761. return ret;
  3762. }
  3763. return new Date(Math.round(value));
  3764. };
  3765. /**
  3766. * Quantity of a number. e.g. 0.1, 1, 10, 100
  3767. * @param {number} val
  3768. * @return {number}
  3769. */
  3770. number.quantity = function (val) {
  3771. return Math.pow(10, Math.floor(Math.log(val) / Math.LN10));
  3772. };
  3773. // "Nice Numbers for Graph Labels" of Graphic Gems
  3774. /**
  3775. * find a “nice” number approximately equal to x. Round the number if round = true, take ceiling if round = false
  3776. * The primary observation is that the “nicest” numbers in decimal are 1, 2, and 5, and all power-of-ten multiples of these numbers.
  3777. * @param {number} val
  3778. * @param {boolean} round
  3779. * @return {number}
  3780. */
  3781. number.nice = function (val, round) {
  3782. var exp10 = number.quantity(val);
  3783. var f = val / exp10; // between 1 and 10
  3784. var nf;
  3785. if (round) {
  3786. if (f < 1.5) { nf = 1; }
  3787. else if (f < 2.5) { nf = 2; }
  3788. else if (f < 4) { nf = 3; }
  3789. else if (f < 7) { nf = 5; }
  3790. else { nf = 10; }
  3791. }
  3792. else {
  3793. if (f < 1) { nf = 1; }
  3794. else if (f < 2) { nf = 2; }
  3795. else if (f < 3) { nf = 3; }
  3796. else if (f < 5) { nf = 5; }
  3797. else { nf = 10; }
  3798. }
  3799. return nf * exp10;
  3800. };
  3801. /**
  3802. * Order intervals asc, and split them when overlap.
  3803. * expect(numberUtil.reformIntervals([
  3804. * {interval: [18, 62], close: [1, 1]},
  3805. * {interval: [-Infinity, -70], close: [0, 0]},
  3806. * {interval: [-70, -26], close: [1, 1]},
  3807. * {interval: [-26, 18], close: [1, 1]},
  3808. * {interval: [62, 150], close: [1, 1]},
  3809. * {interval: [106, 150], close: [1, 1]},
  3810. * {interval: [150, Infinity], close: [0, 0]}
  3811. * ])).toEqual([
  3812. * {interval: [-Infinity, -70], close: [0, 0]},
  3813. * {interval: [-70, -26], close: [1, 1]},
  3814. * {interval: [-26, 18], close: [0, 1]},
  3815. * {interval: [18, 62], close: [0, 1]},
  3816. * {interval: [62, 150], close: [0, 1]},
  3817. * {interval: [150, Infinity], close: [0, 0]}
  3818. * ]);
  3819. * @param {Array.<Object>} list, where `close` mean open or close
  3820. * of the interval, and Infinity can be used.
  3821. * @return {Array.<Object>} The origin list, which has been reformed.
  3822. */
  3823. number.reformIntervals = function (list) {
  3824. list.sort(function (a, b) {
  3825. return littleThan(a, b, 0) ? -1 : 1;
  3826. });
  3827. var curr = -Infinity;
  3828. var currClose = 1;
  3829. for (var i = 0; i < list.length;) {
  3830. var interval = list[i].interval;
  3831. var close = list[i].close;
  3832. for (var lg = 0; lg < 2; lg++) {
  3833. if (interval[lg] <= curr) {
  3834. interval[lg] = curr;
  3835. close[lg] = !lg ? 1 - currClose : 1;
  3836. }
  3837. curr = interval[lg];
  3838. currClose = close[lg];
  3839. }
  3840. if (interval[0] === interval[1] && close[0] * close[1] !== 1) {
  3841. list.splice(i, 1);
  3842. }
  3843. else {
  3844. i++;
  3845. }
  3846. }
  3847. return list;
  3848. function littleThan(a, b, lg) {
  3849. return a.interval[lg] < b.interval[lg]
  3850. || (
  3851. a.interval[lg] === b.interval[lg]
  3852. && (
  3853. (a.close[lg] - b.close[lg] === (!lg ? 1 : -1))
  3854. || (!lg && littleThan(a, b, 1))
  3855. )
  3856. );
  3857. }
  3858. };
  3859. /**
  3860. * parseFloat NaNs numeric-cast false positives (null|true|false|"")
  3861. * ...but misinterprets leading-number strings, particularly hex literals ("0x...")
  3862. * subtraction forces infinities to NaN
  3863. * @param {*} v
  3864. * @return {boolean}
  3865. */
  3866. number.isNumeric = function (v) {
  3867. return v - parseFloat(v) >= 0;
  3868. };
  3869. module.exports = number;
  3870. /***/ },
  3871. /* 8 */
  3872. /***/ function(module, exports, __webpack_require__) {
  3873. var textWidthCache = {};
  3874. var textWidthCacheCounter = 0;
  3875. var TEXT_CACHE_MAX = 5000;
  3876. var util = __webpack_require__(4);
  3877. var BoundingRect = __webpack_require__(9);
  3878. var retrieve = util.retrieve;
  3879. function getTextWidth(text, textFont) {
  3880. var key = text + ':' + textFont;
  3881. if (textWidthCache[key]) {
  3882. return textWidthCache[key];
  3883. }
  3884. var textLines = (text + '').split('\n');
  3885. var width = 0;
  3886. for (var i = 0, l = textLines.length; i < l; i++) {
  3887. // measureText 可以被覆盖以兼容不支持 Canvas 的环境
  3888. width = Math.max(textContain.measureText(textLines[i], textFont).width, width);
  3889. }
  3890. if (textWidthCacheCounter > TEXT_CACHE_MAX) {
  3891. textWidthCacheCounter = 0;
  3892. textWidthCache = {};
  3893. }
  3894. textWidthCacheCounter++;
  3895. textWidthCache[key] = width;
  3896. return width;
  3897. }
  3898. function getTextRect(text, textFont, textAlign, textBaseline) {
  3899. var textLineLen = ((text || '') + '').split('\n').length;
  3900. var width = getTextWidth(text, textFont);
  3901. // FIXME 高度计算比较粗暴
  3902. var lineHeight = getTextWidth('国', textFont);
  3903. var height = textLineLen * lineHeight;
  3904. var rect = new BoundingRect(0, 0, width, height);
  3905. // Text has a special line height property
  3906. rect.lineHeight = lineHeight;
  3907. switch (textBaseline) {
  3908. case 'bottom':
  3909. case 'alphabetic':
  3910. rect.y -= lineHeight;
  3911. break;
  3912. case 'middle':
  3913. rect.y -= lineHeight / 2;
  3914. break;
  3915. // case 'hanging':
  3916. // case 'top':
  3917. }
  3918. // FIXME Right to left language
  3919. switch (textAlign) {
  3920. case 'end':
  3921. case 'right':
  3922. rect.x -= rect.width;
  3923. break;
  3924. case 'center':
  3925. rect.x -= rect.width / 2;
  3926. break;
  3927. // case 'start':
  3928. // case 'left':
  3929. }
  3930. return rect;
  3931. }
  3932. function adjustTextPositionOnRect(textPosition, rect, textRect, distance) {
  3933. var x = rect.x;
  3934. var y = rect.y;
  3935. var height = rect.height;
  3936. var width = rect.width;
  3937. var textHeight = textRect.height;
  3938. var halfHeight = height / 2 - textHeight / 2;
  3939. var textAlign = 'left';
  3940. switch (textPosition) {
  3941. case 'left':
  3942. x -= distance;
  3943. y += halfHeight;
  3944. textAlign = 'right';
  3945. break;
  3946. case 'right':
  3947. x += distance + width;
  3948. y += halfHeight;
  3949. textAlign = 'left';
  3950. break;
  3951. case 'top':
  3952. x += width / 2;
  3953. y -= distance + textHeight;
  3954. textAlign = 'center';
  3955. break;
  3956. case 'bottom':
  3957. x += width / 2;
  3958. y += height + distance;
  3959. textAlign = 'center';
  3960. break;
  3961. case 'inside':
  3962. x += width / 2;
  3963. y += halfHeight;
  3964. textAlign = 'center';
  3965. break;
  3966. case 'insideLeft':
  3967. x += distance;
  3968. y += halfHeight;
  3969. textAlign = 'left';
  3970. break;
  3971. case 'insideRight':
  3972. x += width - distance;
  3973. y += halfHeight;
  3974. textAlign = 'right';
  3975. break;
  3976. case 'insideTop':
  3977. x += width / 2;
  3978. y += distance;
  3979. textAlign = 'center';
  3980. break;
  3981. case 'insideBottom':
  3982. x += width / 2;
  3983. y += height - textHeight - distance;
  3984. textAlign = 'center';
  3985. break;
  3986. case 'insideTopLeft':
  3987. x += distance;
  3988. y += distance;
  3989. textAlign = 'left';
  3990. break;
  3991. case 'insideTopRight':
  3992. x += width - distance;
  3993. y += distance;
  3994. textAlign = 'right';
  3995. break;
  3996. case 'insideBottomLeft':
  3997. x += distance;
  3998. y += height - textHeight - distance;
  3999. break;
  4000. case 'insideBottomRight':
  4001. x += width - distance;
  4002. y += height - textHeight - distance;
  4003. textAlign = 'right';
  4004. break;
  4005. }
  4006. return {
  4007. x: x,
  4008. y: y,
  4009. textAlign: textAlign,
  4010. textBaseline: 'top'
  4011. };
  4012. }
  4013. /**
  4014. * Show ellipsis if overflow.
  4015. *
  4016. * @param {string} text
  4017. * @param {string} containerWidth
  4018. * @param {string} textFont
  4019. * @param {number} [ellipsis='...']
  4020. * @param {Object} [options]
  4021. * @param {number} [options.maxIterations=3]
  4022. * @param {number} [options.minChar=0] If truncate result are less
  4023. * then minChar, ellipsis will not show, which is
  4024. * better for user hint in some cases.
  4025. * @param {number} [options.placeholder=''] When all truncated, use the placeholder.
  4026. * @return {string}
  4027. */
  4028. function truncateText(text, containerWidth, textFont, ellipsis, options) {
  4029. if (!containerWidth) {
  4030. return '';
  4031. }
  4032. options = options || {};
  4033. ellipsis = retrieve(ellipsis, '...');
  4034. var maxIterations = retrieve(options.maxIterations, 2);
  4035. var minChar = retrieve(options.minChar, 0);
  4036. // FIXME
  4037. // Other languages?
  4038. var cnCharWidth = getTextWidth('国', textFont);
  4039. // FIXME
  4040. // Consider proportional font?
  4041. var ascCharWidth = getTextWidth('a', textFont);
  4042. var placeholder = retrieve(options.placeholder, '');
  4043. // Example 1: minChar: 3, text: 'asdfzxcv', truncate result: 'asdf', but not: 'a...'.
  4044. // Example 2: minChar: 3, text: '维度', truncate result: '维', but not: '...'.
  4045. var contentWidth = containerWidth = Math.max(0, containerWidth - 1); // Reserve some gap.
  4046. for (var i = 0; i < minChar && contentWidth >= ascCharWidth; i++) {
  4047. contentWidth -= ascCharWidth;
  4048. }
  4049. var ellipsisWidth = getTextWidth(ellipsis);
  4050. if (ellipsisWidth > contentWidth) {
  4051. ellipsis = '';
  4052. ellipsisWidth = 0;
  4053. }
  4054. contentWidth = containerWidth - ellipsisWidth;
  4055. var textLines = (text + '').split('\n');
  4056. for (var i = 0, len = textLines.length; i < len; i++) {
  4057. var textLine = textLines[i];
  4058. var lineWidth = getTextWidth(textLine, textFont);
  4059. if (lineWidth <= containerWidth) {
  4060. continue;
  4061. }
  4062. for (var j = 0;; j++) {
  4063. if (lineWidth <= contentWidth || j >= maxIterations) {
  4064. textLine += ellipsis;
  4065. break;
  4066. }
  4067. var subLength = j === 0
  4068. ? estimateLength(textLine, contentWidth, ascCharWidth, cnCharWidth)
  4069. : lineWidth > 0
  4070. ? Math.floor(textLine.length * contentWidth / lineWidth)
  4071. : 0;
  4072. textLine = textLine.substr(0, subLength);
  4073. lineWidth = getTextWidth(textLine, textFont);
  4074. }
  4075. if (textLine === '') {
  4076. textLine = placeholder;
  4077. }
  4078. textLines[i] = textLine;
  4079. }
  4080. return textLines.join('\n');
  4081. }
  4082. function estimateLength(text, contentWidth, ascCharWidth, cnCharWidth) {
  4083. var width = 0;
  4084. var i = 0;
  4085. for (var len = text.length; i < len && width < contentWidth; i++) {
  4086. var charCode = text.charCodeAt(i);
  4087. width += (0 <= charCode && charCode <= 127) ? ascCharWidth : cnCharWidth;
  4088. }
  4089. return i;
  4090. }
  4091. var textContain = {
  4092. getWidth: getTextWidth,
  4093. getBoundingRect: getTextRect,
  4094. adjustTextPositionOnRect: adjustTextPositionOnRect,
  4095. truncateText: truncateText,
  4096. measureText: function (text, textFont) {
  4097. var ctx = util.getContext();
  4098. ctx.font = textFont || '12px sans-serif';
  4099. return ctx.measureText(text);
  4100. }
  4101. };
  4102. module.exports = textContain;
  4103. /***/ },
  4104. /* 9 */
  4105. /***/ function(module, exports, __webpack_require__) {
  4106. 'use strict';
  4107. /**
  4108. * @module echarts/core/BoundingRect
  4109. */
  4110. var vec2 = __webpack_require__(10);
  4111. var matrix = __webpack_require__(11);
  4112. var v2ApplyTransform = vec2.applyTransform;
  4113. var mathMin = Math.min;
  4114. var mathMax = Math.max;
  4115. /**
  4116. * @alias module:echarts/core/BoundingRect
  4117. */
  4118. function BoundingRect(x, y, width, height) {
  4119. if (width < 0) {
  4120. x = x + width;
  4121. width = -width;
  4122. }
  4123. if (height < 0) {
  4124. y = y + height;
  4125. height = -height;
  4126. }
  4127. /**
  4128. * @type {number}
  4129. */
  4130. this.x = x;
  4131. /**
  4132. * @type {number}
  4133. */
  4134. this.y = y;
  4135. /**
  4136. * @type {number}
  4137. */
  4138. this.width = width;
  4139. /**
  4140. * @type {number}
  4141. */
  4142. this.height = height;
  4143. }
  4144. BoundingRect.prototype = {
  4145. constructor: BoundingRect,
  4146. /**
  4147. * @param {module:echarts/core/BoundingRect} other
  4148. */
  4149. union: function (other) {
  4150. var x = mathMin(other.x, this.x);
  4151. var y = mathMin(other.y, this.y);
  4152. this.width = mathMax(
  4153. other.x + other.width,
  4154. this.x + this.width
  4155. ) - x;
  4156. this.height = mathMax(
  4157. other.y + other.height,
  4158. this.y + this.height
  4159. ) - y;
  4160. this.x = x;
  4161. this.y = y;
  4162. },
  4163. /**
  4164. * @param {Array.<number>} m
  4165. * @methods
  4166. */
  4167. applyTransform: (function () {
  4168. var lt = [];
  4169. var rb = [];
  4170. var lb = [];
  4171. var rt = [];
  4172. return function (m) {
  4173. // In case usage like this
  4174. // el.getBoundingRect().applyTransform(el.transform)
  4175. // And element has no transform
  4176. if (!m) {
  4177. return;
  4178. }
  4179. lt[0] = lb[0] = this.x;
  4180. lt[1] = rt[1] = this.y;
  4181. rb[0] = rt[0] = this.x + this.width;
  4182. rb[1] = lb[1] = this.y + this.height;
  4183. v2ApplyTransform(lt, lt, m);
  4184. v2ApplyTransform(rb, rb, m);
  4185. v2ApplyTransform(lb, lb, m);
  4186. v2ApplyTransform(rt, rt, m);
  4187. this.x = mathMin(lt[0], rb[0], lb[0], rt[0]);
  4188. this.y = mathMin(lt[1], rb[1], lb[1], rt[1]);
  4189. var maxX = mathMax(lt[0], rb[0], lb[0], rt[0]);
  4190. var maxY = mathMax(lt[1], rb[1], lb[1], rt[1]);
  4191. this.width = maxX - this.x;
  4192. this.height = maxY - this.y;
  4193. };
  4194. })(),
  4195. /**
  4196. * Calculate matrix of transforming from self to target rect
  4197. * @param {module:zrender/core/BoundingRect} b
  4198. * @return {Array.<number>}
  4199. */
  4200. calculateTransform: function (b) {
  4201. var a = this;
  4202. var sx = b.width / a.width;
  4203. var sy = b.height / a.height;
  4204. var m = matrix.create();
  4205. // 矩阵右乘
  4206. matrix.translate(m, m, [-a.x, -a.y]);
  4207. matrix.scale(m, m, [sx, sy]);
  4208. matrix.translate(m, m, [b.x, b.y]);
  4209. return m;
  4210. },
  4211. /**
  4212. * @param {(module:echarts/core/BoundingRect|Object)} b
  4213. * @return {boolean}
  4214. */
  4215. intersect: function (b) {
  4216. if (!b) {
  4217. return false;
  4218. }
  4219. if (!(b instanceof BoundingRect)) {
  4220. // Normalize negative width/height.
  4221. b = BoundingRect.create(b);
  4222. }
  4223. var a = this;
  4224. var ax0 = a.x;
  4225. var ax1 = a.x + a.width;
  4226. var ay0 = a.y;
  4227. var ay1 = a.y + a.height;
  4228. var bx0 = b.x;
  4229. var bx1 = b.x + b.width;
  4230. var by0 = b.y;
  4231. var by1 = b.y + b.height;
  4232. return ! (ax1 < bx0 || bx1 < ax0 || ay1 < by0 || by1 < ay0);
  4233. },
  4234. contain: function (x, y) {
  4235. var rect = this;
  4236. return x >= rect.x
  4237. && x <= (rect.x + rect.width)
  4238. && y >= rect.y
  4239. && y <= (rect.y + rect.height);
  4240. },
  4241. /**
  4242. * @return {module:echarts/core/BoundingRect}
  4243. */
  4244. clone: function () {
  4245. return new BoundingRect(this.x, this.y, this.width, this.height);
  4246. },
  4247. /**
  4248. * Copy from another rect
  4249. */
  4250. copy: function (other) {
  4251. this.x = other.x;
  4252. this.y = other.y;
  4253. this.width = other.width;
  4254. this.height = other.height;
  4255. },
  4256. plain: function () {
  4257. return {
  4258. x: this.x,
  4259. y: this.y,
  4260. width: this.width,
  4261. height: this.height
  4262. };
  4263. }
  4264. };
  4265. /**
  4266. * @param {Object|module:zrender/core/BoundingRect} rect
  4267. * @param {number} rect.x
  4268. * @param {number} rect.y
  4269. * @param {number} rect.width
  4270. * @param {number} rect.height
  4271. * @return {module:zrender/core/BoundingRect}
  4272. */
  4273. BoundingRect.create = function (rect) {
  4274. return new BoundingRect(rect.x, rect.y, rect.width, rect.height);
  4275. };
  4276. module.exports = BoundingRect;
  4277. /***/ },
  4278. /* 10 */
  4279. /***/ function(module, exports) {
  4280. var ArrayCtor = typeof Float32Array === 'undefined'
  4281. ? Array
  4282. : Float32Array;
  4283. /**
  4284. * @typedef {Float32Array|Array.<number>} Vector2
  4285. */
  4286. /**
  4287. * 二维向量类
  4288. * @exports zrender/tool/vector
  4289. */
  4290. var vector = {
  4291. /**
  4292. * 创建一个向量
  4293. * @param {number} [x=0]
  4294. * @param {number} [y=0]
  4295. * @return {Vector2}
  4296. */
  4297. create: function (x, y) {
  4298. var out = new ArrayCtor(2);
  4299. if (x == null) {
  4300. x = 0;
  4301. }
  4302. if (y == null) {
  4303. y = 0;
  4304. }
  4305. out[0] = x;
  4306. out[1] = y;
  4307. return out;
  4308. },
  4309. /**
  4310. * 复制向量数据
  4311. * @param {Vector2} out
  4312. * @param {Vector2} v
  4313. * @return {Vector2}
  4314. */
  4315. copy: function (out, v) {
  4316. out[0] = v[0];
  4317. out[1] = v[1];
  4318. return out;
  4319. },
  4320. /**
  4321. * 克隆一个向量
  4322. * @param {Vector2} v
  4323. * @return {Vector2}
  4324. */
  4325. clone: function (v) {
  4326. var out = new ArrayCtor(2);
  4327. out[0] = v[0];
  4328. out[1] = v[1];
  4329. return out;
  4330. },
  4331. /**
  4332. * 设置向量的两个项
  4333. * @param {Vector2} out
  4334. * @param {number} a
  4335. * @param {number} b
  4336. * @return {Vector2} 结果
  4337. */
  4338. set: function (out, a, b) {
  4339. out[0] = a;
  4340. out[1] = b;
  4341. return out;
  4342. },
  4343. /**
  4344. * 向量相加
  4345. * @param {Vector2} out
  4346. * @param {Vector2} v1
  4347. * @param {Vector2} v2
  4348. */
  4349. add: function (out, v1, v2) {
  4350. out[0] = v1[0] + v2[0];
  4351. out[1] = v1[1] + v2[1];
  4352. return out;
  4353. },
  4354. /**
  4355. * 向量缩放后相加
  4356. * @param {Vector2} out
  4357. * @param {Vector2} v1
  4358. * @param {Vector2} v2
  4359. * @param {number} a
  4360. */
  4361. scaleAndAdd: function (out, v1, v2, a) {
  4362. out[0] = v1[0] + v2[0] * a;
  4363. out[1] = v1[1] + v2[1] * a;
  4364. return out;
  4365. },
  4366. /**
  4367. * 向量相减
  4368. * @param {Vector2} out
  4369. * @param {Vector2} v1
  4370. * @param {Vector2} v2
  4371. */
  4372. sub: function (out, v1, v2) {
  4373. out[0] = v1[0] - v2[0];
  4374. out[1] = v1[1] - v2[1];
  4375. return out;
  4376. },
  4377. /**
  4378. * 向量长度
  4379. * @param {Vector2} v
  4380. * @return {number}
  4381. */
  4382. len: function (v) {
  4383. return Math.sqrt(this.lenSquare(v));
  4384. },
  4385. /**
  4386. * 向量长度平方
  4387. * @param {Vector2} v
  4388. * @return {number}
  4389. */
  4390. lenSquare: function (v) {
  4391. return v[0] * v[0] + v[1] * v[1];
  4392. },
  4393. /**
  4394. * 向量乘法
  4395. * @param {Vector2} out
  4396. * @param {Vector2} v1
  4397. * @param {Vector2} v2
  4398. */
  4399. mul: function (out, v1, v2) {
  4400. out[0] = v1[0] * v2[0];
  4401. out[1] = v1[1] * v2[1];
  4402. return out;
  4403. },
  4404. /**
  4405. * 向量除法
  4406. * @param {Vector2} out
  4407. * @param {Vector2} v1
  4408. * @param {Vector2} v2
  4409. */
  4410. div: function (out, v1, v2) {
  4411. out[0] = v1[0] / v2[0];
  4412. out[1] = v1[1] / v2[1];
  4413. return out;
  4414. },
  4415. /**
  4416. * 向量点乘
  4417. * @param {Vector2} v1
  4418. * @param {Vector2} v2
  4419. * @return {number}
  4420. */
  4421. dot: function (v1, v2) {
  4422. return v1[0] * v2[0] + v1[1] * v2[1];
  4423. },
  4424. /**
  4425. * 向量缩放
  4426. * @param {Vector2} out
  4427. * @param {Vector2} v
  4428. * @param {number} s
  4429. */
  4430. scale: function (out, v, s) {
  4431. out[0] = v[0] * s;
  4432. out[1] = v[1] * s;
  4433. return out;
  4434. },
  4435. /**
  4436. * 向量归一化
  4437. * @param {Vector2} out
  4438. * @param {Vector2} v
  4439. */
  4440. normalize: function (out, v) {
  4441. var d = vector.len(v);
  4442. if (d === 0) {
  4443. out[0] = 0;
  4444. out[1] = 0;
  4445. }
  4446. else {
  4447. out[0] = v[0] / d;
  4448. out[1] = v[1] / d;
  4449. }
  4450. return out;
  4451. },
  4452. /**
  4453. * 计算向量间距离
  4454. * @param {Vector2} v1
  4455. * @param {Vector2} v2
  4456. * @return {number}
  4457. */
  4458. distance: function (v1, v2) {
  4459. return Math.sqrt(
  4460. (v1[0] - v2[0]) * (v1[0] - v2[0])
  4461. + (v1[1] - v2[1]) * (v1[1] - v2[1])
  4462. );
  4463. },
  4464. /**
  4465. * 向量距离平方
  4466. * @param {Vector2} v1
  4467. * @param {Vector2} v2
  4468. * @return {number}
  4469. */
  4470. distanceSquare: function (v1, v2) {
  4471. return (v1[0] - v2[0]) * (v1[0] - v2[0])
  4472. + (v1[1] - v2[1]) * (v1[1] - v2[1]);
  4473. },
  4474. /**
  4475. * 求负向量
  4476. * @param {Vector2} out
  4477. * @param {Vector2} v
  4478. */
  4479. negate: function (out, v) {
  4480. out[0] = -v[0];
  4481. out[1] = -v[1];
  4482. return out;
  4483. },
  4484. /**
  4485. * 插值两个点
  4486. * @param {Vector2} out
  4487. * @param {Vector2} v1
  4488. * @param {Vector2} v2
  4489. * @param {number} t
  4490. */
  4491. lerp: function (out, v1, v2, t) {
  4492. out[0] = v1[0] + t * (v2[0] - v1[0]);
  4493. out[1] = v1[1] + t * (v2[1] - v1[1]);
  4494. return out;
  4495. },
  4496. /**
  4497. * 矩阵左乘向量
  4498. * @param {Vector2} out
  4499. * @param {Vector2} v
  4500. * @param {Vector2} m
  4501. */
  4502. applyTransform: function (out, v, m) {
  4503. var x = v[0];
  4504. var y = v[1];
  4505. out[0] = m[0] * x + m[2] * y + m[4];
  4506. out[1] = m[1] * x + m[3] * y + m[5];
  4507. return out;
  4508. },
  4509. /**
  4510. * 求两个向量最小值
  4511. * @param {Vector2} out
  4512. * @param {Vector2} v1
  4513. * @param {Vector2} v2
  4514. */
  4515. min: function (out, v1, v2) {
  4516. out[0] = Math.min(v1[0], v2[0]);
  4517. out[1] = Math.min(v1[1], v2[1]);
  4518. return out;
  4519. },
  4520. /**
  4521. * 求两个向量最大值
  4522. * @param {Vector2} out
  4523. * @param {Vector2} v1
  4524. * @param {Vector2} v2
  4525. */
  4526. max: function (out, v1, v2) {
  4527. out[0] = Math.max(v1[0], v2[0]);
  4528. out[1] = Math.max(v1[1], v2[1]);
  4529. return out;
  4530. }
  4531. };
  4532. vector.length = vector.len;
  4533. vector.lengthSquare = vector.lenSquare;
  4534. vector.dist = vector.distance;
  4535. vector.distSquare = vector.distanceSquare;
  4536. module.exports = vector;
  4537. /***/ },
  4538. /* 11 */
  4539. /***/ function(module, exports) {
  4540. var ArrayCtor = typeof Float32Array === 'undefined'
  4541. ? Array
  4542. : Float32Array;
  4543. /**
  4544. * 3x2矩阵操作类
  4545. * @exports zrender/tool/matrix
  4546. */
  4547. var matrix = {
  4548. /**
  4549. * 创建一个单位矩阵
  4550. * @return {Float32Array|Array.<number>}
  4551. */
  4552. create : function() {
  4553. var out = new ArrayCtor(6);
  4554. matrix.identity(out);
  4555. return out;
  4556. },
  4557. /**
  4558. * 设置矩阵为单位矩阵
  4559. * @param {Float32Array|Array.<number>} out
  4560. */
  4561. identity : function(out) {
  4562. out[0] = 1;
  4563. out[1] = 0;
  4564. out[2] = 0;
  4565. out[3] = 1;
  4566. out[4] = 0;
  4567. out[5] = 0;
  4568. return out;
  4569. },
  4570. /**
  4571. * 复制矩阵
  4572. * @param {Float32Array|Array.<number>} out
  4573. * @param {Float32Array|Array.<number>} m
  4574. */
  4575. copy: function(out, m) {
  4576. out[0] = m[0];
  4577. out[1] = m[1];
  4578. out[2] = m[2];
  4579. out[3] = m[3];
  4580. out[4] = m[4];
  4581. out[5] = m[5];
  4582. return out;
  4583. },
  4584. /**
  4585. * 矩阵相乘
  4586. * @param {Float32Array|Array.<number>} out
  4587. * @param {Float32Array|Array.<number>} m1
  4588. * @param {Float32Array|Array.<number>} m2
  4589. */
  4590. mul : function (out, m1, m2) {
  4591. // Consider matrix.mul(m, m2, m);
  4592. // where out is the same as m2.
  4593. // So use temp variable to escape error.
  4594. var out0 = m1[0] * m2[0] + m1[2] * m2[1];
  4595. var out1 = m1[1] * m2[0] + m1[3] * m2[1];
  4596. var out2 = m1[0] * m2[2] + m1[2] * m2[3];
  4597. var out3 = m1[1] * m2[2] + m1[3] * m2[3];
  4598. var out4 = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  4599. var out5 = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  4600. out[0] = out0;
  4601. out[1] = out1;
  4602. out[2] = out2;
  4603. out[3] = out3;
  4604. out[4] = out4;
  4605. out[5] = out5;
  4606. return out;
  4607. },
  4608. /**
  4609. * 平移变换
  4610. * @param {Float32Array|Array.<number>} out
  4611. * @param {Float32Array|Array.<number>} a
  4612. * @param {Float32Array|Array.<number>} v
  4613. */
  4614. translate : function(out, a, v) {
  4615. out[0] = a[0];
  4616. out[1] = a[1];
  4617. out[2] = a[2];
  4618. out[3] = a[3];
  4619. out[4] = a[4] + v[0];
  4620. out[5] = a[5] + v[1];
  4621. return out;
  4622. },
  4623. /**
  4624. * 旋转变换
  4625. * @param {Float32Array|Array.<number>} out
  4626. * @param {Float32Array|Array.<number>} a
  4627. * @param {number} rad
  4628. */
  4629. rotate : function(out, a, rad) {
  4630. var aa = a[0];
  4631. var ac = a[2];
  4632. var atx = a[4];
  4633. var ab = a[1];
  4634. var ad = a[3];
  4635. var aty = a[5];
  4636. var st = Math.sin(rad);
  4637. var ct = Math.cos(rad);
  4638. out[0] = aa * ct + ab * st;
  4639. out[1] = -aa * st + ab * ct;
  4640. out[2] = ac * ct + ad * st;
  4641. out[3] = -ac * st + ct * ad;
  4642. out[4] = ct * atx + st * aty;
  4643. out[5] = ct * aty - st * atx;
  4644. return out;
  4645. },
  4646. /**
  4647. * 缩放变换
  4648. * @param {Float32Array|Array.<number>} out
  4649. * @param {Float32Array|Array.<number>} a
  4650. * @param {Float32Array|Array.<number>} v
  4651. */
  4652. scale : function(out, a, v) {
  4653. var vx = v[0];
  4654. var vy = v[1];
  4655. out[0] = a[0] * vx;
  4656. out[1] = a[1] * vy;
  4657. out[2] = a[2] * vx;
  4658. out[3] = a[3] * vy;
  4659. out[4] = a[4] * vx;
  4660. out[5] = a[5] * vy;
  4661. return out;
  4662. },
  4663. /**
  4664. * 求逆矩阵
  4665. * @param {Float32Array|Array.<number>} out
  4666. * @param {Float32Array|Array.<number>} a
  4667. */
  4668. invert : function(out, a) {
  4669. var aa = a[0];
  4670. var ac = a[2];
  4671. var atx = a[4];
  4672. var ab = a[1];
  4673. var ad = a[3];
  4674. var aty = a[5];
  4675. var det = aa * ad - ab * ac;
  4676. if (!det) {
  4677. return null;
  4678. }
  4679. det = 1.0 / det;
  4680. out[0] = ad * det;
  4681. out[1] = -ab * det;
  4682. out[2] = -ac * det;
  4683. out[3] = aa * det;
  4684. out[4] = (ac * aty - ad * atx) * det;
  4685. out[5] = (ab * atx - aa * aty) * det;
  4686. return out;
  4687. }
  4688. };
  4689. module.exports = matrix;
  4690. /***/ },
  4691. /* 12 */
  4692. /***/ function(module, exports, __webpack_require__) {
  4693. /**
  4694. * @module echarts/model/Model
  4695. */
  4696. var zrUtil = __webpack_require__(4);
  4697. var clazzUtil = __webpack_require__(13);
  4698. var env = __webpack_require__(2);
  4699. /**
  4700. * @alias module:echarts/model/Model
  4701. * @constructor
  4702. * @param {Object} option
  4703. * @param {module:echarts/model/Model} [parentModel]
  4704. * @param {module:echarts/model/Global} [ecModel]
  4705. */
  4706. function Model(option, parentModel, ecModel) {
  4707. /**
  4708. * @type {module:echarts/model/Model}
  4709. * @readOnly
  4710. */
  4711. this.parentModel = parentModel;
  4712. /**
  4713. * @type {module:echarts/model/Global}
  4714. * @readOnly
  4715. */
  4716. this.ecModel = ecModel;
  4717. /**
  4718. * @type {Object}
  4719. * @protected
  4720. */
  4721. this.option = option;
  4722. // Simple optimization
  4723. // if (this.init) {
  4724. // if (arguments.length <= 4) {
  4725. // this.init(option, parentModel, ecModel, extraOpt);
  4726. // }
  4727. // else {
  4728. // this.init.apply(this, arguments);
  4729. // }
  4730. // }
  4731. }
  4732. Model.prototype = {
  4733. constructor: Model,
  4734. /**
  4735. * Model 的初始化函数
  4736. * @param {Object} option
  4737. */
  4738. init: null,
  4739. /**
  4740. * 从新的 Option merge
  4741. */
  4742. mergeOption: function (option) {
  4743. zrUtil.merge(this.option, option, true);
  4744. },
  4745. /**
  4746. * @param {string|Array.<string>} path
  4747. * @param {boolean} [ignoreParent=false]
  4748. * @return {*}
  4749. */
  4750. get: function (path, ignoreParent) {
  4751. if (path == null) {
  4752. return this.option;
  4753. }
  4754. return doGet(
  4755. this.option,
  4756. this.parsePath(path),
  4757. !ignoreParent && getParent(this, path)
  4758. );
  4759. },
  4760. /**
  4761. * @param {string} key
  4762. * @param {boolean} [ignoreParent=false]
  4763. * @return {*}
  4764. */
  4765. getShallow: function (key, ignoreParent) {
  4766. var option = this.option;
  4767. var val = option == null ? option : option[key];
  4768. var parentModel = !ignoreParent && getParent(this, key);
  4769. if (val == null && parentModel) {
  4770. val = parentModel.getShallow(key);
  4771. }
  4772. return val;
  4773. },
  4774. /**
  4775. * @param {string|Array.<string>} path
  4776. * @param {module:echarts/model/Model} [parentModel]
  4777. * @return {module:echarts/model/Model}
  4778. */
  4779. getModel: function (path, parentModel) {
  4780. var obj = path == null
  4781. ? this.option
  4782. : doGet(this.option, path = this.parsePath(path));
  4783. var thisParentModel;
  4784. parentModel = parentModel || (
  4785. (thisParentModel = getParent(this, path))
  4786. && thisParentModel.getModel(path)
  4787. );
  4788. return new Model(obj, parentModel, this.ecModel);
  4789. },
  4790. /**
  4791. * If model has option
  4792. */
  4793. isEmpty: function () {
  4794. return this.option == null;
  4795. },
  4796. restoreData: function () {},
  4797. // Pending
  4798. clone: function () {
  4799. var Ctor = this.constructor;
  4800. return new Ctor(zrUtil.clone(this.option));
  4801. },
  4802. setReadOnly: function (properties) {
  4803. clazzUtil.setReadOnly(this, properties);
  4804. },
  4805. // If path is null/undefined, return null/undefined.
  4806. parsePath: function(path) {
  4807. if (typeof path === 'string') {
  4808. path = path.split('.');
  4809. }
  4810. return path;
  4811. },
  4812. /**
  4813. * @param {Function} getParentMethod
  4814. * param {Array.<string>|string} path
  4815. * return {module:echarts/model/Model}
  4816. */
  4817. customizeGetParent: function (getParentMethod) {
  4818. clazzUtil.set(this, 'getParent', getParentMethod);
  4819. },
  4820. isAnimationEnabled: function () {
  4821. if (!env.node) {
  4822. if (this.option.animation != null) {
  4823. return !!this.option.animation;
  4824. }
  4825. else if (this.parentModel) {
  4826. return this.parentModel.isAnimationEnabled();
  4827. }
  4828. }
  4829. }
  4830. };
  4831. function doGet(obj, pathArr, parentModel) {
  4832. for (var i = 0; i < pathArr.length; i++) {
  4833. // Ignore empty
  4834. if (!pathArr[i]) {
  4835. continue;
  4836. }
  4837. // obj could be number/string/... (like 0)
  4838. obj = (obj && typeof obj === 'object') ? obj[pathArr[i]] : null;
  4839. if (obj == null) {
  4840. break;
  4841. }
  4842. }
  4843. if (obj == null && parentModel) {
  4844. obj = parentModel.get(pathArr);
  4845. }
  4846. return obj;
  4847. }
  4848. function getParent(model, path) {
  4849. var getParentMethod = clazzUtil.get(model, 'getParent');
  4850. return getParentMethod ? getParentMethod.call(model, path) : model.parentModel;
  4851. }
  4852. // Enable Model.extend.
  4853. clazzUtil.enableClassExtend(Model);
  4854. var mixin = zrUtil.mixin;
  4855. mixin(Model, __webpack_require__(14));
  4856. mixin(Model, __webpack_require__(16));
  4857. mixin(Model, __webpack_require__(17));
  4858. mixin(Model, __webpack_require__(18));
  4859. module.exports = Model;
  4860. /***/ },
  4861. /* 13 */
  4862. /***/ function(module, exports, __webpack_require__) {
  4863. var zrUtil = __webpack_require__(4);
  4864. var clazz = {};
  4865. var TYPE_DELIMITER = '.';
  4866. var IS_CONTAINER = '___EC__COMPONENT__CONTAINER___';
  4867. var MEMBER_PRIFIX = '\0ec_\0';
  4868. /**
  4869. * Hide private class member.
  4870. * The same behavior as `host[name] = value;` (can be right-value)
  4871. * @public
  4872. */
  4873. clazz.set = function (host, name, value) {
  4874. return (host[MEMBER_PRIFIX + name] = value);
  4875. };
  4876. /**
  4877. * Hide private class member.
  4878. * The same behavior as `host[name];`
  4879. * @public
  4880. */
  4881. clazz.get = function (host, name) {
  4882. return host[MEMBER_PRIFIX + name];
  4883. };
  4884. /**
  4885. * For hidden private class member.
  4886. * The same behavior as `host.hasOwnProperty(name);`
  4887. * @public
  4888. */
  4889. clazz.hasOwn = function (host, name) {
  4890. return host.hasOwnProperty(MEMBER_PRIFIX + name);
  4891. };
  4892. /**
  4893. * @public
  4894. */
  4895. var parseClassType = clazz.parseClassType = function (componentType) {
  4896. var ret = {main: '', sub: ''};
  4897. if (componentType) {
  4898. componentType = componentType.split(TYPE_DELIMITER);
  4899. ret.main = componentType[0] || '';
  4900. ret.sub = componentType[1] || '';
  4901. }
  4902. return ret;
  4903. };
  4904. /**
  4905. * @public
  4906. */
  4907. function checkClassType(componentType) {
  4908. zrUtil.assert(
  4909. /^[a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)?$/.test(componentType),
  4910. 'componentType "' + componentType + '" illegal'
  4911. );
  4912. }
  4913. /**
  4914. * @public
  4915. */
  4916. clazz.enableClassExtend = function (RootClass, mandatoryMethods) {
  4917. RootClass.$constructor = RootClass;
  4918. RootClass.extend = function (proto) {
  4919. if (true) {
  4920. zrUtil.each(mandatoryMethods, function (method) {
  4921. if (!proto[method]) {
  4922. console.warn(
  4923. 'Method `' + method + '` should be implemented'
  4924. + (proto.type ? ' in ' + proto.type : '') + '.'
  4925. );
  4926. }
  4927. });
  4928. }
  4929. var superClass = this;
  4930. var ExtendedClass = function () {
  4931. if (!proto.$constructor) {
  4932. superClass.apply(this, arguments);
  4933. }
  4934. else {
  4935. proto.$constructor.apply(this, arguments);
  4936. }
  4937. };
  4938. zrUtil.extend(ExtendedClass.prototype, proto);
  4939. ExtendedClass.extend = this.extend;
  4940. ExtendedClass.superCall = superCall;
  4941. ExtendedClass.superApply = superApply;
  4942. zrUtil.inherits(ExtendedClass, this);
  4943. ExtendedClass.superClass = superClass;
  4944. return ExtendedClass;
  4945. };
  4946. };
  4947. // superCall should have class info, which can not be fetch from 'this'.
  4948. // Consider this case:
  4949. // class A has method f,
  4950. // class B inherits class A, overrides method f, f call superApply('f'),
  4951. // class C inherits class B, do not overrides method f,
  4952. // then when method of class C is called, dead loop occured.
  4953. function superCall(context, methodName) {
  4954. var args = zrUtil.slice(arguments, 2);
  4955. return this.superClass.prototype[methodName].apply(context, args);
  4956. }
  4957. function superApply(context, methodName, args) {
  4958. return this.superClass.prototype[methodName].apply(context, args);
  4959. }
  4960. /**
  4961. * @param {Object} entity
  4962. * @param {Object} options
  4963. * @param {boolean} [options.registerWhenExtend]
  4964. * @public
  4965. */
  4966. clazz.enableClassManagement = function (entity, options) {
  4967. options = options || {};
  4968. /**
  4969. * Component model classes
  4970. * key: componentType,
  4971. * value:
  4972. * componentClass, when componentType is 'xxx'
  4973. * or Object.<subKey, componentClass>, when componentType is 'xxx.yy'
  4974. * @type {Object}
  4975. */
  4976. var storage = {};
  4977. entity.registerClass = function (Clazz, componentType) {
  4978. if (componentType) {
  4979. checkClassType(componentType);
  4980. componentType = parseClassType(componentType);
  4981. if (!componentType.sub) {
  4982. if (true) {
  4983. if (storage[componentType.main]) {
  4984. console.warn(componentType.main + ' exists.');
  4985. }
  4986. }
  4987. storage[componentType.main] = Clazz;
  4988. }
  4989. else if (componentType.sub !== IS_CONTAINER) {
  4990. var container = makeContainer(componentType);
  4991. container[componentType.sub] = Clazz;
  4992. }
  4993. }
  4994. return Clazz;
  4995. };
  4996. entity.getClass = function (componentMainType, subType, throwWhenNotFound) {
  4997. var Clazz = storage[componentMainType];
  4998. if (Clazz && Clazz[IS_CONTAINER]) {
  4999. Clazz = subType ? Clazz[subType] : null;
  5000. }
  5001. if (throwWhenNotFound && !Clazz) {
  5002. throw new Error(
  5003. !subType
  5004. ? componentMainType + '.' + 'type should be specified.'
  5005. : 'Component ' + componentMainType + '.' + (subType || '') + ' not exists. Load it first.'
  5006. );
  5007. }
  5008. return Clazz;
  5009. };
  5010. entity.getClassesByMainType = function (componentType) {
  5011. componentType = parseClassType(componentType);
  5012. var result = [];
  5013. var obj = storage[componentType.main];
  5014. if (obj && obj[IS_CONTAINER]) {
  5015. zrUtil.each(obj, function (o, type) {
  5016. type !== IS_CONTAINER && result.push(o);
  5017. });
  5018. }
  5019. else {
  5020. result.push(obj);
  5021. }
  5022. return result;
  5023. };
  5024. entity.hasClass = function (componentType) {
  5025. // Just consider componentType.main.
  5026. componentType = parseClassType(componentType);
  5027. return !!storage[componentType.main];
  5028. };
  5029. /**
  5030. * @return {Array.<string>} Like ['aa', 'bb'], but can not be ['aa.xx']
  5031. */
  5032. entity.getAllClassMainTypes = function () {
  5033. var types = [];
  5034. zrUtil.each(storage, function (obj, type) {
  5035. types.push(type);
  5036. });
  5037. return types;
  5038. };
  5039. /**
  5040. * If a main type is container and has sub types
  5041. * @param {string} mainType
  5042. * @return {boolean}
  5043. */
  5044. entity.hasSubTypes = function (componentType) {
  5045. componentType = parseClassType(componentType);
  5046. var obj = storage[componentType.main];
  5047. return obj && obj[IS_CONTAINER];
  5048. };
  5049. entity.parseClassType = parseClassType;
  5050. function makeContainer(componentType) {
  5051. var container = storage[componentType.main];
  5052. if (!container || !container[IS_CONTAINER]) {
  5053. container = storage[componentType.main] = {};
  5054. container[IS_CONTAINER] = true;
  5055. }
  5056. return container;
  5057. }
  5058. if (options.registerWhenExtend) {
  5059. var originalExtend = entity.extend;
  5060. if (originalExtend) {
  5061. entity.extend = function (proto) {
  5062. var ExtendedClass = originalExtend.call(this, proto);
  5063. return entity.registerClass(ExtendedClass, proto.type);
  5064. };
  5065. }
  5066. }
  5067. return entity;
  5068. };
  5069. /**
  5070. * @param {string|Array.<string>} properties
  5071. */
  5072. clazz.setReadOnly = function (obj, properties) {
  5073. // FIXME It seems broken in IE8 simulation of IE11
  5074. // if (!zrUtil.isArray(properties)) {
  5075. // properties = properties != null ? [properties] : [];
  5076. // }
  5077. // zrUtil.each(properties, function (prop) {
  5078. // var value = obj[prop];
  5079. // Object.defineProperty
  5080. // && Object.defineProperty(obj, prop, {
  5081. // value: value, writable: false
  5082. // });
  5083. // zrUtil.isArray(obj[prop])
  5084. // && Object.freeze
  5085. // && Object.freeze(obj[prop]);
  5086. // });
  5087. };
  5088. module.exports = clazz;
  5089. /***/ },
  5090. /* 14 */
  5091. /***/ function(module, exports, __webpack_require__) {
  5092. var getLineStyle = __webpack_require__(15)(
  5093. [
  5094. ['lineWidth', 'width'],
  5095. ['stroke', 'color'],
  5096. ['opacity'],
  5097. ['shadowBlur'],
  5098. ['shadowOffsetX'],
  5099. ['shadowOffsetY'],
  5100. ['shadowColor']
  5101. ]
  5102. );
  5103. module.exports = {
  5104. getLineStyle: function (excludes) {
  5105. var style = getLineStyle.call(this, excludes);
  5106. var lineDash = this.getLineDash(style.lineWidth);
  5107. lineDash && (style.lineDash = lineDash);
  5108. return style;
  5109. },
  5110. getLineDash: function (lineWidth) {
  5111. if (lineWidth == null) {
  5112. lineWidth = 1;
  5113. }
  5114. var lineType = this.get('type');
  5115. var dotSize = Math.max(lineWidth, 2);
  5116. var dashSize = lineWidth * 4;
  5117. return (lineType === 'solid' || lineType == null) ? null
  5118. : (lineType === 'dashed' ? [dashSize, dashSize] : [dotSize, dotSize]);
  5119. }
  5120. };
  5121. /***/ },
  5122. /* 15 */
  5123. /***/ function(module, exports, __webpack_require__) {
  5124. // TODO Parse shadow style
  5125. // TODO Only shallow path support
  5126. var zrUtil = __webpack_require__(4);
  5127. module.exports = function (properties) {
  5128. // Normalize
  5129. for (var i = 0; i < properties.length; i++) {
  5130. if (!properties[i][1]) {
  5131. properties[i][1] = properties[i][0];
  5132. }
  5133. }
  5134. return function (excludes) {
  5135. var style = {};
  5136. for (var i = 0; i < properties.length; i++) {
  5137. var propName = properties[i][1];
  5138. if (excludes && zrUtil.indexOf(excludes, propName) >= 0) {
  5139. continue;
  5140. }
  5141. var val = this.getShallow(propName);
  5142. if (val != null) {
  5143. style[properties[i][0]] = val;
  5144. }
  5145. }
  5146. return style;
  5147. };
  5148. };
  5149. /***/ },
  5150. /* 16 */
  5151. /***/ function(module, exports, __webpack_require__) {
  5152. module.exports = {
  5153. getAreaStyle: __webpack_require__(15)(
  5154. [
  5155. ['fill', 'color'],
  5156. ['shadowBlur'],
  5157. ['shadowOffsetX'],
  5158. ['shadowOffsetY'],
  5159. ['opacity'],
  5160. ['shadowColor']
  5161. ]
  5162. )
  5163. };
  5164. /***/ },
  5165. /* 17 */
  5166. /***/ function(module, exports, __webpack_require__) {
  5167. var textContain = __webpack_require__(8);
  5168. function getShallow(model, path) {
  5169. return model && model.getShallow(path);
  5170. }
  5171. module.exports = {
  5172. /**
  5173. * Get color property or get color from option.textStyle.color
  5174. * @return {string}
  5175. */
  5176. getTextColor: function () {
  5177. var ecModel = this.ecModel;
  5178. return this.getShallow('color')
  5179. || (ecModel && ecModel.get('textStyle.color'));
  5180. },
  5181. /**
  5182. * Create font string from fontStyle, fontWeight, fontSize, fontFamily
  5183. * @return {string}
  5184. */
  5185. getFont: function () {
  5186. var ecModel = this.ecModel;
  5187. var gTextStyleModel = ecModel && ecModel.getModel('textStyle');
  5188. return [
  5189. // FIXME in node-canvas fontWeight is before fontStyle
  5190. this.getShallow('fontStyle') || getShallow(gTextStyleModel, 'fontStyle'),
  5191. this.getShallow('fontWeight') || getShallow(gTextStyleModel, 'fontWeight'),
  5192. (this.getShallow('fontSize') || getShallow(gTextStyleModel, 'fontSize') || 12) + 'px',
  5193. this.getShallow('fontFamily') || getShallow(gTextStyleModel, 'fontFamily') || 'sans-serif'
  5194. ].join(' ');
  5195. },
  5196. getTextRect: function (text) {
  5197. return textContain.getBoundingRect(
  5198. text,
  5199. this.getFont(),
  5200. this.getShallow('align'),
  5201. this.getShallow('baseline')
  5202. );
  5203. },
  5204. truncateText: function (text, containerWidth, ellipsis, options) {
  5205. return textContain.truncateText(
  5206. text, containerWidth, this.getFont(), ellipsis, options
  5207. );
  5208. }
  5209. };
  5210. /***/ },
  5211. /* 18 */
  5212. /***/ function(module, exports, __webpack_require__) {
  5213. var getItemStyle = __webpack_require__(15)(
  5214. [
  5215. ['fill', 'color'],
  5216. ['stroke', 'borderColor'],
  5217. ['lineWidth', 'borderWidth'],
  5218. ['opacity'],
  5219. ['shadowBlur'],
  5220. ['shadowOffsetX'],
  5221. ['shadowOffsetY'],
  5222. ['shadowColor'],
  5223. ['textPosition'],
  5224. ['textAlign']
  5225. ]
  5226. );
  5227. module.exports = {
  5228. getItemStyle: function (excludes) {
  5229. var style = getItemStyle.call(this, excludes);
  5230. var lineDash = this.getBorderLineDash();
  5231. lineDash && (style.lineDash = lineDash);
  5232. return style;
  5233. },
  5234. getBorderLineDash: function () {
  5235. var lineType = this.get('borderType');
  5236. return (lineType === 'solid' || lineType == null) ? null
  5237. : (lineType === 'dashed' ? [5, 5] : [1, 1]);
  5238. }
  5239. };
  5240. /***/ },
  5241. /* 19 */
  5242. /***/ function(module, exports, __webpack_require__) {
  5243. /**
  5244. * Component model
  5245. *
  5246. * @module echarts/model/Component
  5247. */
  5248. var Model = __webpack_require__(12);
  5249. var zrUtil = __webpack_require__(4);
  5250. var arrayPush = Array.prototype.push;
  5251. var componentUtil = __webpack_require__(20);
  5252. var clazzUtil = __webpack_require__(13);
  5253. var layout = __webpack_require__(21);
  5254. /**
  5255. * @alias module:echarts/model/Component
  5256. * @constructor
  5257. * @param {Object} option
  5258. * @param {module:echarts/model/Model} parentModel
  5259. * @param {module:echarts/model/Model} ecModel
  5260. */
  5261. var ComponentModel = Model.extend({
  5262. type: 'component',
  5263. /**
  5264. * @readOnly
  5265. * @type {string}
  5266. */
  5267. id: '',
  5268. /**
  5269. * @readOnly
  5270. */
  5271. name: '',
  5272. /**
  5273. * @readOnly
  5274. * @type {string}
  5275. */
  5276. mainType: '',
  5277. /**
  5278. * @readOnly
  5279. * @type {string}
  5280. */
  5281. subType: '',
  5282. /**
  5283. * @readOnly
  5284. * @type {number}
  5285. */
  5286. componentIndex: 0,
  5287. /**
  5288. * @type {Object}
  5289. * @protected
  5290. */
  5291. defaultOption: null,
  5292. /**
  5293. * @type {module:echarts/model/Global}
  5294. * @readOnly
  5295. */
  5296. ecModel: null,
  5297. /**
  5298. * key: componentType
  5299. * value: Component model list, can not be null.
  5300. * @type {Object.<string, Array.<module:echarts/model/Model>>}
  5301. * @readOnly
  5302. */
  5303. dependentModels: [],
  5304. /**
  5305. * @type {string}
  5306. * @readOnly
  5307. */
  5308. uid: null,
  5309. /**
  5310. * Support merge layout params.
  5311. * Only support 'box' now (left/right/top/bottom/width/height).
  5312. * @type {string|Object} Object can be {ignoreSize: true}
  5313. * @readOnly
  5314. */
  5315. layoutMode: null,
  5316. $constructor: function (option, parentModel, ecModel, extraOpt) {
  5317. Model.call(this, option, parentModel, ecModel, extraOpt);
  5318. this.uid = componentUtil.getUID('componentModel');
  5319. },
  5320. init: function (option, parentModel, ecModel, extraOpt) {
  5321. this.mergeDefaultAndTheme(option, ecModel);
  5322. },
  5323. mergeDefaultAndTheme: function (option, ecModel) {
  5324. var layoutMode = this.layoutMode;
  5325. var inputPositionParams = layoutMode
  5326. ? layout.getLayoutParams(option) : {};
  5327. var themeModel = ecModel.getTheme();
  5328. zrUtil.merge(option, themeModel.get(this.mainType));
  5329. zrUtil.merge(option, this.getDefaultOption());
  5330. if (layoutMode) {
  5331. layout.mergeLayoutParam(option, inputPositionParams, layoutMode);
  5332. }
  5333. },
  5334. mergeOption: function (option, extraOpt) {
  5335. zrUtil.merge(this.option, option, true);
  5336. var layoutMode = this.layoutMode;
  5337. if (layoutMode) {
  5338. layout.mergeLayoutParam(this.option, option, layoutMode);
  5339. }
  5340. },
  5341. // Hooker after init or mergeOption
  5342. optionUpdated: function (newCptOption, isInit) {},
  5343. getDefaultOption: function () {
  5344. if (!clazzUtil.hasOwn(this, '__defaultOption')) {
  5345. var optList = [];
  5346. var Class = this.constructor;
  5347. while (Class) {
  5348. var opt = Class.prototype.defaultOption;
  5349. opt && optList.push(opt);
  5350. Class = Class.superClass;
  5351. }
  5352. var defaultOption = {};
  5353. for (var i = optList.length - 1; i >= 0; i--) {
  5354. defaultOption = zrUtil.merge(defaultOption, optList[i], true);
  5355. }
  5356. clazzUtil.set(this, '__defaultOption', defaultOption);
  5357. }
  5358. return clazzUtil.get(this, '__defaultOption');
  5359. },
  5360. getReferringComponents: function (mainType) {
  5361. return this.ecModel.queryComponents({
  5362. mainType: mainType,
  5363. index: this.get(mainType + 'Index', true),
  5364. id: this.get(mainType + 'Id', true)
  5365. });
  5366. }
  5367. });
  5368. // Reset ComponentModel.extend, add preConstruct.
  5369. // clazzUtil.enableClassExtend(
  5370. // ComponentModel,
  5371. // function (option, parentModel, ecModel, extraOpt) {
  5372. // // Set dependentModels, componentIndex, name, id, mainType, subType.
  5373. // zrUtil.extend(this, extraOpt);
  5374. // this.uid = componentUtil.getUID('componentModel');
  5375. // // this.setReadOnly([
  5376. // // 'type', 'id', 'uid', 'name', 'mainType', 'subType',
  5377. // // 'dependentModels', 'componentIndex'
  5378. // // ]);
  5379. // }
  5380. // );
  5381. // Add capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  5382. clazzUtil.enableClassManagement(
  5383. ComponentModel, {registerWhenExtend: true}
  5384. );
  5385. componentUtil.enableSubTypeDefaulter(ComponentModel);
  5386. // Add capability of ComponentModel.topologicalTravel.
  5387. componentUtil.enableTopologicalTravel(ComponentModel, getDependencies);
  5388. function getDependencies(componentType) {
  5389. var deps = [];
  5390. zrUtil.each(ComponentModel.getClassesByMainType(componentType), function (Clazz) {
  5391. arrayPush.apply(deps, Clazz.prototype.dependencies || []);
  5392. });
  5393. // Ensure main type
  5394. return zrUtil.map(deps, function (type) {
  5395. return clazzUtil.parseClassType(type).main;
  5396. });
  5397. }
  5398. zrUtil.mixin(ComponentModel, __webpack_require__(22));
  5399. module.exports = ComponentModel;
  5400. /***/ },
  5401. /* 20 */
  5402. /***/ function(module, exports, __webpack_require__) {
  5403. var zrUtil = __webpack_require__(4);
  5404. var clazz = __webpack_require__(13);
  5405. var parseClassType = clazz.parseClassType;
  5406. var base = 0;
  5407. var componentUtil = {};
  5408. var DELIMITER = '_';
  5409. /**
  5410. * @public
  5411. * @param {string} type
  5412. * @return {string}
  5413. */
  5414. componentUtil.getUID = function (type) {
  5415. // Considering the case of crossing js context,
  5416. // use Math.random to make id as unique as possible.
  5417. return [(type || ''), base++, Math.random()].join(DELIMITER);
  5418. };
  5419. /**
  5420. * @inner
  5421. */
  5422. componentUtil.enableSubTypeDefaulter = function (entity) {
  5423. var subTypeDefaulters = {};
  5424. entity.registerSubTypeDefaulter = function (componentType, defaulter) {
  5425. componentType = parseClassType(componentType);
  5426. subTypeDefaulters[componentType.main] = defaulter;
  5427. };
  5428. entity.determineSubType = function (componentType, option) {
  5429. var type = option.type;
  5430. if (!type) {
  5431. var componentTypeMain = parseClassType(componentType).main;
  5432. if (entity.hasSubTypes(componentType) && subTypeDefaulters[componentTypeMain]) {
  5433. type = subTypeDefaulters[componentTypeMain](option);
  5434. }
  5435. }
  5436. return type;
  5437. };
  5438. return entity;
  5439. };
  5440. /**
  5441. * Topological travel on Activity Network (Activity On Vertices).
  5442. * Dependencies is defined in Model.prototype.dependencies, like ['xAxis', 'yAxis'].
  5443. *
  5444. * If 'xAxis' or 'yAxis' is absent in componentTypeList, just ignore it in topology.
  5445. *
  5446. * If there is circle dependencey, Error will be thrown.
  5447. *
  5448. */
  5449. componentUtil.enableTopologicalTravel = function (entity, dependencyGetter) {
  5450. /**
  5451. * @public
  5452. * @param {Array.<string>} targetNameList Target Component type list.
  5453. * Can be ['aa', 'bb', 'aa.xx']
  5454. * @param {Array.<string>} fullNameList By which we can build dependency graph.
  5455. * @param {Function} callback Params: componentType, dependencies.
  5456. * @param {Object} context Scope of callback.
  5457. */
  5458. entity.topologicalTravel = function (targetNameList, fullNameList, callback, context) {
  5459. if (!targetNameList.length) {
  5460. return;
  5461. }
  5462. var result = makeDepndencyGraph(fullNameList);
  5463. var graph = result.graph;
  5464. var stack = result.noEntryList;
  5465. var targetNameSet = {};
  5466. zrUtil.each(targetNameList, function (name) {
  5467. targetNameSet[name] = true;
  5468. });
  5469. while (stack.length) {
  5470. var currComponentType = stack.pop();
  5471. var currVertex = graph[currComponentType];
  5472. var isInTargetNameSet = !!targetNameSet[currComponentType];
  5473. if (isInTargetNameSet) {
  5474. callback.call(context, currComponentType, currVertex.originalDeps.slice());
  5475. delete targetNameSet[currComponentType];
  5476. }
  5477. zrUtil.each(
  5478. currVertex.successor,
  5479. isInTargetNameSet ? removeEdgeAndAdd : removeEdge
  5480. );
  5481. }
  5482. zrUtil.each(targetNameSet, function () {
  5483. throw new Error('Circle dependency may exists');
  5484. });
  5485. function removeEdge(succComponentType) {
  5486. graph[succComponentType].entryCount--;
  5487. if (graph[succComponentType].entryCount === 0) {
  5488. stack.push(succComponentType);
  5489. }
  5490. }
  5491. // Consider this case: legend depends on series, and we call
  5492. // chart.setOption({series: [...]}), where only series is in option.
  5493. // If we do not have 'removeEdgeAndAdd', legendModel.mergeOption will
  5494. // not be called, but only sereis.mergeOption is called. Thus legend
  5495. // have no chance to update its local record about series (like which
  5496. // name of series is available in legend).
  5497. function removeEdgeAndAdd(succComponentType) {
  5498. targetNameSet[succComponentType] = true;
  5499. removeEdge(succComponentType);
  5500. }
  5501. };
  5502. /**
  5503. * DepndencyGraph: {Object}
  5504. * key: conponentType,
  5505. * value: {
  5506. * successor: [conponentTypes...],
  5507. * originalDeps: [conponentTypes...],
  5508. * entryCount: {number}
  5509. * }
  5510. */
  5511. function makeDepndencyGraph(fullNameList) {
  5512. var graph = {};
  5513. var noEntryList = [];
  5514. zrUtil.each(fullNameList, function (name) {
  5515. var thisItem = createDependencyGraphItem(graph, name);
  5516. var originalDeps = thisItem.originalDeps = dependencyGetter(name);
  5517. var availableDeps = getAvailableDependencies(originalDeps, fullNameList);
  5518. thisItem.entryCount = availableDeps.length;
  5519. if (thisItem.entryCount === 0) {
  5520. noEntryList.push(name);
  5521. }
  5522. zrUtil.each(availableDeps, function (dependentName) {
  5523. if (zrUtil.indexOf(thisItem.predecessor, dependentName) < 0) {
  5524. thisItem.predecessor.push(dependentName);
  5525. }
  5526. var thatItem = createDependencyGraphItem(graph, dependentName);
  5527. if (zrUtil.indexOf(thatItem.successor, dependentName) < 0) {
  5528. thatItem.successor.push(name);
  5529. }
  5530. });
  5531. });
  5532. return {graph: graph, noEntryList: noEntryList};
  5533. }
  5534. function createDependencyGraphItem(graph, name) {
  5535. if (!graph[name]) {
  5536. graph[name] = {predecessor: [], successor: []};
  5537. }
  5538. return graph[name];
  5539. }
  5540. function getAvailableDependencies(originalDeps, fullNameList) {
  5541. var availableDeps = [];
  5542. zrUtil.each(originalDeps, function (dep) {
  5543. zrUtil.indexOf(fullNameList, dep) >= 0 && availableDeps.push(dep);
  5544. });
  5545. return availableDeps;
  5546. }
  5547. };
  5548. module.exports = componentUtil;
  5549. /***/ },
  5550. /* 21 */
  5551. /***/ function(module, exports, __webpack_require__) {
  5552. 'use strict';
  5553. // Layout helpers for each component positioning
  5554. var zrUtil = __webpack_require__(4);
  5555. var BoundingRect = __webpack_require__(9);
  5556. var numberUtil = __webpack_require__(7);
  5557. var formatUtil = __webpack_require__(6);
  5558. var parsePercent = numberUtil.parsePercent;
  5559. var each = zrUtil.each;
  5560. var layout = {};
  5561. var LOCATION_PARAMS = layout.LOCATION_PARAMS = [
  5562. 'left', 'right', 'top', 'bottom', 'width', 'height'
  5563. ];
  5564. function boxLayout(orient, group, gap, maxWidth, maxHeight) {
  5565. var x = 0;
  5566. var y = 0;
  5567. if (maxWidth == null) {
  5568. maxWidth = Infinity;
  5569. }
  5570. if (maxHeight == null) {
  5571. maxHeight = Infinity;
  5572. }
  5573. var currentLineMaxSize = 0;
  5574. group.eachChild(function (child, idx) {
  5575. var position = child.position;
  5576. var rect = child.getBoundingRect();
  5577. var nextChild = group.childAt(idx + 1);
  5578. var nextChildRect = nextChild && nextChild.getBoundingRect();
  5579. var nextX;
  5580. var nextY;
  5581. if (orient === 'horizontal') {
  5582. var moveX = rect.width + (nextChildRect ? (-nextChildRect.x + rect.x) : 0);
  5583. nextX = x + moveX;
  5584. // Wrap when width exceeds maxWidth or meet a `newline` group
  5585. if (nextX > maxWidth || child.newline) {
  5586. x = 0;
  5587. nextX = moveX;
  5588. y += currentLineMaxSize + gap;
  5589. currentLineMaxSize = rect.height;
  5590. }
  5591. else {
  5592. currentLineMaxSize = Math.max(currentLineMaxSize, rect.height);
  5593. }
  5594. }
  5595. else {
  5596. var moveY = rect.height + (nextChildRect ? (-nextChildRect.y + rect.y) : 0);
  5597. nextY = y + moveY;
  5598. // Wrap when width exceeds maxHeight or meet a `newline` group
  5599. if (nextY > maxHeight || child.newline) {
  5600. x += currentLineMaxSize + gap;
  5601. y = 0;
  5602. nextY = moveY;
  5603. currentLineMaxSize = rect.width;
  5604. }
  5605. else {
  5606. currentLineMaxSize = Math.max(currentLineMaxSize, rect.width);
  5607. }
  5608. }
  5609. if (child.newline) {
  5610. return;
  5611. }
  5612. position[0] = x;
  5613. position[1] = y;
  5614. orient === 'horizontal'
  5615. ? (x = nextX + gap)
  5616. : (y = nextY + gap);
  5617. });
  5618. }
  5619. /**
  5620. * VBox or HBox layouting
  5621. * @param {string} orient
  5622. * @param {module:zrender/container/Group} group
  5623. * @param {number} gap
  5624. * @param {number} [width=Infinity]
  5625. * @param {number} [height=Infinity]
  5626. */
  5627. layout.box = boxLayout;
  5628. /**
  5629. * VBox layouting
  5630. * @param {module:zrender/container/Group} group
  5631. * @param {number} gap
  5632. * @param {number} [width=Infinity]
  5633. * @param {number} [height=Infinity]
  5634. */
  5635. layout.vbox = zrUtil.curry(boxLayout, 'vertical');
  5636. /**
  5637. * HBox layouting
  5638. * @param {module:zrender/container/Group} group
  5639. * @param {number} gap
  5640. * @param {number} [width=Infinity]
  5641. * @param {number} [height=Infinity]
  5642. */
  5643. layout.hbox = zrUtil.curry(boxLayout, 'horizontal');
  5644. /**
  5645. * If x or x2 is not specified or 'center' 'left' 'right',
  5646. * the width would be as long as possible.
  5647. * If y or y2 is not specified or 'middle' 'top' 'bottom',
  5648. * the height would be as long as possible.
  5649. *
  5650. * @param {Object} positionInfo
  5651. * @param {number|string} [positionInfo.x]
  5652. * @param {number|string} [positionInfo.y]
  5653. * @param {number|string} [positionInfo.x2]
  5654. * @param {number|string} [positionInfo.y2]
  5655. * @param {Object} containerRect
  5656. * @param {string|number} margin
  5657. * @return {Object} {width, height}
  5658. */
  5659. layout.getAvailableSize = function (positionInfo, containerRect, margin) {
  5660. var containerWidth = containerRect.width;
  5661. var containerHeight = containerRect.height;
  5662. var x = parsePercent(positionInfo.x, containerWidth);
  5663. var y = parsePercent(positionInfo.y, containerHeight);
  5664. var x2 = parsePercent(positionInfo.x2, containerWidth);
  5665. var y2 = parsePercent(positionInfo.y2, containerHeight);
  5666. (isNaN(x) || isNaN(parseFloat(positionInfo.x))) && (x = 0);
  5667. (isNaN(x2) || isNaN(parseFloat(positionInfo.x2))) && (x2 = containerWidth);
  5668. (isNaN(y) || isNaN(parseFloat(positionInfo.y))) && (y = 0);
  5669. (isNaN(y2) || isNaN(parseFloat(positionInfo.y2))) && (y2 = containerHeight);
  5670. margin = formatUtil.normalizeCssArray(margin || 0);
  5671. return {
  5672. width: Math.max(x2 - x - margin[1] - margin[3], 0),
  5673. height: Math.max(y2 - y - margin[0] - margin[2], 0)
  5674. };
  5675. };
  5676. /**
  5677. * Parse position info.
  5678. *
  5679. * @param {Object} positionInfo
  5680. * @param {number|string} [positionInfo.left]
  5681. * @param {number|string} [positionInfo.top]
  5682. * @param {number|string} [positionInfo.right]
  5683. * @param {number|string} [positionInfo.bottom]
  5684. * @param {number|string} [positionInfo.width]
  5685. * @param {number|string} [positionInfo.height]
  5686. * @param {number|string} [positionInfo.aspect] Aspect is width / height
  5687. * @param {Object} containerRect
  5688. * @param {string|number} [margin]
  5689. *
  5690. * @return {module:zrender/core/BoundingRect}
  5691. */
  5692. layout.getLayoutRect = function (
  5693. positionInfo, containerRect, margin
  5694. ) {
  5695. margin = formatUtil.normalizeCssArray(margin || 0);
  5696. var containerWidth = containerRect.width;
  5697. var containerHeight = containerRect.height;
  5698. var left = parsePercent(positionInfo.left, containerWidth);
  5699. var top = parsePercent(positionInfo.top, containerHeight);
  5700. var right = parsePercent(positionInfo.right, containerWidth);
  5701. var bottom = parsePercent(positionInfo.bottom, containerHeight);
  5702. var width = parsePercent(positionInfo.width, containerWidth);
  5703. var height = parsePercent(positionInfo.height, containerHeight);
  5704. var verticalMargin = margin[2] + margin[0];
  5705. var horizontalMargin = margin[1] + margin[3];
  5706. var aspect = positionInfo.aspect;
  5707. // If width is not specified, calculate width from left and right
  5708. if (isNaN(width)) {
  5709. width = containerWidth - right - horizontalMargin - left;
  5710. }
  5711. if (isNaN(height)) {
  5712. height = containerHeight - bottom - verticalMargin - top;
  5713. }
  5714. // If width and height are not given
  5715. // 1. Graph should not exceeds the container
  5716. // 2. Aspect must be keeped
  5717. // 3. Graph should take the space as more as possible
  5718. if (isNaN(width) && isNaN(height)) {
  5719. if (aspect > containerWidth / containerHeight) {
  5720. width = containerWidth * 0.8;
  5721. }
  5722. else {
  5723. height = containerHeight * 0.8;
  5724. }
  5725. }
  5726. if (aspect != null) {
  5727. // Calculate width or height with given aspect
  5728. if (isNaN(width)) {
  5729. width = aspect * height;
  5730. }
  5731. if (isNaN(height)) {
  5732. height = width / aspect;
  5733. }
  5734. }
  5735. // If left is not specified, calculate left from right and width
  5736. if (isNaN(left)) {
  5737. left = containerWidth - right - width - horizontalMargin;
  5738. }
  5739. if (isNaN(top)) {
  5740. top = containerHeight - bottom - height - verticalMargin;
  5741. }
  5742. // Align left and top
  5743. switch (positionInfo.left || positionInfo.right) {
  5744. case 'center':
  5745. left = containerWidth / 2 - width / 2 - margin[3];
  5746. break;
  5747. case 'right':
  5748. left = containerWidth - width - horizontalMargin;
  5749. break;
  5750. }
  5751. switch (positionInfo.top || positionInfo.bottom) {
  5752. case 'middle':
  5753. case 'center':
  5754. top = containerHeight / 2 - height / 2 - margin[0];
  5755. break;
  5756. case 'bottom':
  5757. top = containerHeight - height - verticalMargin;
  5758. break;
  5759. }
  5760. // If something is wrong and left, top, width, height are calculated as NaN
  5761. left = left || 0;
  5762. top = top || 0;
  5763. if (isNaN(width)) {
  5764. // Width may be NaN if only one value is given except width
  5765. width = containerWidth - left - (right || 0);
  5766. }
  5767. if (isNaN(height)) {
  5768. // Height may be NaN if only one value is given except height
  5769. height = containerHeight - top - (bottom || 0);
  5770. }
  5771. var rect = new BoundingRect(left + margin[3], top + margin[0], width, height);
  5772. rect.margin = margin;
  5773. return rect;
  5774. };
  5775. /**
  5776. * Position a zr element in viewport
  5777. * Group position is specified by either
  5778. * {left, top}, {right, bottom}
  5779. * If all properties exists, right and bottom will be igonred.
  5780. *
  5781. * Logic:
  5782. * 1. Scale (against origin point in parent coord)
  5783. * 2. Rotate (against origin point in parent coord)
  5784. * 3. Traslate (with el.position by this method)
  5785. * So this method only fixes the last step 'Traslate', which does not affect
  5786. * scaling and rotating.
  5787. *
  5788. * If be called repeatly with the same input el, the same result will be gotten.
  5789. *
  5790. * @param {module:zrender/Element} el Should have `getBoundingRect` method.
  5791. * @param {Object} positionInfo
  5792. * @param {number|string} [positionInfo.left]
  5793. * @param {number|string} [positionInfo.top]
  5794. * @param {number|string} [positionInfo.right]
  5795. * @param {number|string} [positionInfo.bottom]
  5796. * @param {Object} containerRect
  5797. * @param {string|number} margin
  5798. * @param {Object} [opt]
  5799. * @param {Array.<number>} [opt.hv=[1,1]] Only horizontal or only vertical.
  5800. * @param {Array.<number>} [opt.boundingMode='all']
  5801. * Specify how to calculate boundingRect when locating.
  5802. * 'all': Position the boundingRect that is transformed and uioned
  5803. * both itself and its descendants.
  5804. * This mode simplies confine the elements in the bounding
  5805. * of their container (e.g., using 'right: 0').
  5806. * 'raw': Position the boundingRect that is not transformed and only itself.
  5807. * This mode is useful when you want a element can overflow its
  5808. * container. (Consider a rotated circle needs to be located in a corner.)
  5809. * In this mode positionInfo.width/height can only be number.
  5810. */
  5811. layout.positionElement = function (el, positionInfo, containerRect, margin, opt) {
  5812. var h = !opt || !opt.hv || opt.hv[0];
  5813. var v = !opt || !opt.hv || opt.hv[1];
  5814. var boundingMode = opt && opt.boundingMode || 'all';
  5815. if (!h && !v) {
  5816. return;
  5817. }
  5818. var rect;
  5819. if (boundingMode === 'raw') {
  5820. rect = el.type === 'group'
  5821. ? new BoundingRect(0, 0, +positionInfo.width || 0, +positionInfo.height || 0)
  5822. : el.getBoundingRect();
  5823. }
  5824. else {
  5825. rect = el.getBoundingRect();
  5826. if (el.needLocalTransform()) {
  5827. var transform = el.getLocalTransform();
  5828. // Notice: raw rect may be inner object of el,
  5829. // which should not be modified.
  5830. rect = rect.clone();
  5831. rect.applyTransform(transform);
  5832. }
  5833. }
  5834. positionInfo = layout.getLayoutRect(
  5835. zrUtil.defaults(
  5836. {width: rect.width, height: rect.height},
  5837. positionInfo
  5838. ),
  5839. containerRect,
  5840. margin
  5841. );
  5842. // Because 'tranlate' is the last step in transform
  5843. // (see zrender/core/Transformable#getLocalTransfrom),
  5844. // we can just only modify el.position to get final result.
  5845. var elPos = el.position;
  5846. var dx = h ? positionInfo.x - rect.x : 0;
  5847. var dy = v ? positionInfo.y - rect.y : 0;
  5848. el.attr('position', boundingMode === 'raw' ? [dx, dy] : [elPos[0] + dx, elPos[1] + dy]);
  5849. };
  5850. /**
  5851. * Consider Case:
  5852. * When defulat option has {left: 0, width: 100}, and we set {right: 0}
  5853. * through setOption or media query, using normal zrUtil.merge will cause
  5854. * {right: 0} does not take effect.
  5855. *
  5856. * @example
  5857. * ComponentModel.extend({
  5858. * init: function () {
  5859. * ...
  5860. * var inputPositionParams = layout.getLayoutParams(option);
  5861. * this.mergeOption(inputPositionParams);
  5862. * },
  5863. * mergeOption: function (newOption) {
  5864. * newOption && zrUtil.merge(thisOption, newOption, true);
  5865. * layout.mergeLayoutParam(thisOption, newOption);
  5866. * }
  5867. * });
  5868. *
  5869. * @param {Object} targetOption
  5870. * @param {Object} newOption
  5871. * @param {Object|string} [opt]
  5872. * @param {boolean} [opt.ignoreSize=false] Some component must has width and height.
  5873. */
  5874. layout.mergeLayoutParam = function (targetOption, newOption, opt) {
  5875. !zrUtil.isObject(opt) && (opt = {});
  5876. var hNames = ['width', 'left', 'right']; // Order by priority.
  5877. var vNames = ['height', 'top', 'bottom']; // Order by priority.
  5878. var hResult = merge(hNames);
  5879. var vResult = merge(vNames);
  5880. copy(hNames, targetOption, hResult);
  5881. copy(vNames, targetOption, vResult);
  5882. function merge(names) {
  5883. var newParams = {};
  5884. var newValueCount = 0;
  5885. var merged = {};
  5886. var mergedValueCount = 0;
  5887. var enoughParamNumber = opt.ignoreSize ? 1 : 2;
  5888. each(names, function (name) {
  5889. merged[name] = targetOption[name];
  5890. });
  5891. each(names, function (name) {
  5892. // Consider case: newOption.width is null, which is
  5893. // set by user for removing width setting.
  5894. hasProp(newOption, name) && (newParams[name] = merged[name] = newOption[name]);
  5895. hasValue(newParams, name) && newValueCount++;
  5896. hasValue(merged, name) && mergedValueCount++;
  5897. });
  5898. // Case: newOption: {width: ..., right: ...},
  5899. // or targetOption: {right: ...} and newOption: {width: ...},
  5900. // There is no conflict when merged only has params count
  5901. // little than enoughParamNumber.
  5902. if (mergedValueCount === enoughParamNumber || !newValueCount) {
  5903. return merged;
  5904. }
  5905. // Case: newOption: {width: ..., right: ...},
  5906. // Than we can make sure user only want those two, and ignore
  5907. // all origin params in targetOption.
  5908. else if (newValueCount >= enoughParamNumber) {
  5909. return newParams;
  5910. }
  5911. else {
  5912. // Chose another param from targetOption by priority.
  5913. // When 'ignoreSize', enoughParamNumber is 1 and those will not happen.
  5914. for (var i = 0; i < names.length; i++) {
  5915. var name = names[i];
  5916. if (!hasProp(newParams, name) && hasProp(targetOption, name)) {
  5917. newParams[name] = targetOption[name];
  5918. break;
  5919. }
  5920. }
  5921. return newParams;
  5922. }
  5923. }
  5924. function hasProp(obj, name) {
  5925. return obj.hasOwnProperty(name);
  5926. }
  5927. function hasValue(obj, name) {
  5928. return obj[name] != null && obj[name] !== 'auto';
  5929. }
  5930. function copy(names, target, source) {
  5931. each(names, function (name) {
  5932. target[name] = source[name];
  5933. });
  5934. }
  5935. };
  5936. /**
  5937. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  5938. * @param {Object} source
  5939. * @return {Object} Result contains those props.
  5940. */
  5941. layout.getLayoutParams = function (source) {
  5942. return layout.copyLayoutParams({}, source);
  5943. };
  5944. /**
  5945. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  5946. * @param {Object} source
  5947. * @return {Object} Result contains those props.
  5948. */
  5949. layout.copyLayoutParams = function (target, source) {
  5950. source && target && each(LOCATION_PARAMS, function (name) {
  5951. source.hasOwnProperty(name) && (target[name] = source[name]);
  5952. });
  5953. return target;
  5954. };
  5955. module.exports = layout;
  5956. /***/ },
  5957. /* 22 */
  5958. /***/ function(module, exports) {
  5959. module.exports = {
  5960. getBoxLayoutParams: function () {
  5961. return {
  5962. left: this.get('left'),
  5963. top: this.get('top'),
  5964. right: this.get('right'),
  5965. bottom: this.get('bottom'),
  5966. width: this.get('width'),
  5967. height: this.get('height')
  5968. };
  5969. }
  5970. };
  5971. /***/ },
  5972. /* 23 */
  5973. /***/ function(module, exports) {
  5974. var platform = '';
  5975. // Navigator not exists in node
  5976. if (typeof navigator !== 'undefined') {
  5977. platform = navigator.platform || '';
  5978. }
  5979. module.exports = {
  5980. // 全图默认背景
  5981. // backgroundColor: 'rgba(0,0,0,0)',
  5982. // https://dribbble.com/shots/1065960-Infographic-Pie-chart-visualization
  5983. // color: ['#5793f3', '#d14a61', '#fd9c35', '#675bba', '#fec42c', '#dd4444', '#d4df5a', '#cd4870'],
  5984. // 浅色
  5985. // color: ['#bcd3bb', '#e88f70', '#edc1a5', '#9dc5c8', '#e1e8c8', '#7b7c68', '#e5b5b5', '#f0b489', '#928ea8', '#bda29a'],
  5986. // color: ['#cc5664', '#9bd6ec', '#ea946e', '#8acaaa', '#f1ec64', '#ee8686', '#a48dc1', '#5da6bc', '#b9dcae'],
  5987. // 深色
  5988. color: ['#c23531','#2f4554', '#61a0a8', '#d48265', '#91c7ae','#749f83', '#ca8622', '#bda29a','#6e7074', '#546570', '#c4ccd3'],
  5989. // 默认需要 Grid 配置项
  5990. // grid: {},
  5991. // 主题,主题
  5992. textStyle: {
  5993. // color: '#000',
  5994. // decoration: 'none',
  5995. // PENDING
  5996. fontFamily: platform.match(/^Win/) ? 'Microsoft YaHei' : 'sans-serif',
  5997. // fontFamily: 'Arial, Verdana, sans-serif',
  5998. fontSize: 12,
  5999. fontStyle: 'normal',
  6000. fontWeight: 'normal'
  6001. },
  6002. // http://blogs.adobe.com/webplatform/2014/02/24/using-blend-modes-in-html-canvas/
  6003. // https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
  6004. // Default is source-over
  6005. blendMode: null,
  6006. animation: true,
  6007. animationDuration: 1000,
  6008. animationDurationUpdate: 300,
  6009. animationEasing: 'exponentialOut',
  6010. animationEasingUpdate: 'cubicOut',
  6011. animationThreshold: 2000,
  6012. // Configuration for progressive/incremental rendering
  6013. progressiveThreshold: 3000,
  6014. progressive: 400,
  6015. // Threshold of if use single hover layer to optimize.
  6016. // It is recommended that `hoverLayerThreshold` is equivalent to or less than
  6017. // `progressiveThreshold`, otherwise hover will cause restart of progressive,
  6018. // which is unexpected.
  6019. // see example <echarts/test/heatmap-large.html>.
  6020. hoverLayerThreshold: 3000
  6021. };
  6022. /***/ },
  6023. /* 24 */
  6024. /***/ function(module, exports, __webpack_require__) {
  6025. var classUtil = __webpack_require__(13);
  6026. var set = classUtil.set;
  6027. var get = classUtil.get;
  6028. module.exports = {
  6029. clearColorPalette: function () {
  6030. set(this, 'colorIdx', 0);
  6031. set(this, 'colorNameMap', {});
  6032. },
  6033. getColorFromPalette: function (name, scope) {
  6034. scope = scope || this;
  6035. var colorIdx = get(scope, 'colorIdx') || 0;
  6036. var colorNameMap = get(scope, 'colorNameMap') || set(scope, 'colorNameMap', {});
  6037. if (colorNameMap[name]) {
  6038. return colorNameMap[name];
  6039. }
  6040. var colorPalette = this.get('color', true) || [];
  6041. if (!colorPalette.length) {
  6042. return;
  6043. }
  6044. var color = colorPalette[colorIdx];
  6045. if (name) {
  6046. colorNameMap[name] = color;
  6047. }
  6048. set(scope, 'colorIdx', (colorIdx + 1) % colorPalette.length);
  6049. return color;
  6050. }
  6051. };
  6052. /***/ },
  6053. /* 25 */
  6054. /***/ function(module, exports, __webpack_require__) {
  6055. 'use strict';
  6056. var zrUtil = __webpack_require__(4);
  6057. var echartsAPIList = [
  6058. 'getDom', 'getZr', 'getWidth', 'getHeight', 'dispatchAction', 'isDisposed',
  6059. 'on', 'off', 'getDataURL', 'getConnectedDataURL', 'getModel', 'getOption'
  6060. ];
  6061. function ExtensionAPI(chartInstance) {
  6062. zrUtil.each(echartsAPIList, function (name) {
  6063. this[name] = zrUtil.bind(chartInstance[name], chartInstance);
  6064. }, this);
  6065. }
  6066. module.exports = ExtensionAPI;
  6067. /***/ },
  6068. /* 26 */
  6069. /***/ function(module, exports, __webpack_require__) {
  6070. 'use strict';
  6071. var zrUtil = __webpack_require__(4);
  6072. /**
  6073. * Interface of Coordinate System Class
  6074. *
  6075. * create:
  6076. * @param {module:echarts/model/Global} ecModel
  6077. * @param {module:echarts/ExtensionAPI} api
  6078. * @return {Object} coordinate system instance
  6079. *
  6080. * update:
  6081. * @param {module:echarts/model/Global} ecModel
  6082. * @param {module:echarts/ExtensionAPI} api
  6083. *
  6084. * convertToPixel:
  6085. * convertFromPixel:
  6086. * These two methods is also responsible for determine whether this
  6087. * coodinate system is applicable to the given `finder`.
  6088. * Each coordinate system will be tried, util one returns none
  6089. * null/undefined value.
  6090. * @param {module:echarts/model/Global} ecModel
  6091. * @param {Object} finder
  6092. * @param {Array|number} value
  6093. * @return {Array|number} convert result.
  6094. *
  6095. * containPoint:
  6096. * @param {Array.<number>} point In pixel coordinate system.
  6097. * @return {boolean}
  6098. */
  6099. var coordinateSystemCreators = {};
  6100. function CoordinateSystemManager() {
  6101. this._coordinateSystems = [];
  6102. }
  6103. CoordinateSystemManager.prototype = {
  6104. constructor: CoordinateSystemManager,
  6105. create: function (ecModel, api) {
  6106. var coordinateSystems = [];
  6107. zrUtil.each(coordinateSystemCreators, function (creater, type) {
  6108. var list = creater.create(ecModel, api);
  6109. coordinateSystems = coordinateSystems.concat(list || []);
  6110. });
  6111. this._coordinateSystems = coordinateSystems;
  6112. },
  6113. update: function (ecModel, api) {
  6114. zrUtil.each(this._coordinateSystems, function (coordSys) {
  6115. // FIXME MUST have
  6116. coordSys.update && coordSys.update(ecModel, api);
  6117. });
  6118. },
  6119. getCoordinateSystems: function () {
  6120. return this._coordinateSystems.slice();
  6121. }
  6122. };
  6123. CoordinateSystemManager.register = function (type, coordinateSystemCreator) {
  6124. coordinateSystemCreators[type] = coordinateSystemCreator;
  6125. };
  6126. CoordinateSystemManager.get = function (type) {
  6127. return coordinateSystemCreators[type];
  6128. };
  6129. module.exports = CoordinateSystemManager;
  6130. /***/ },
  6131. /* 27 */
  6132. /***/ function(module, exports, __webpack_require__) {
  6133. /**
  6134. * ECharts option manager
  6135. *
  6136. * @module {echarts/model/OptionManager}
  6137. */
  6138. var zrUtil = __webpack_require__(4);
  6139. var modelUtil = __webpack_require__(5);
  6140. var ComponentModel = __webpack_require__(19);
  6141. var each = zrUtil.each;
  6142. var clone = zrUtil.clone;
  6143. var map = zrUtil.map;
  6144. var merge = zrUtil.merge;
  6145. var QUERY_REG = /^(min|max)?(.+)$/;
  6146. /**
  6147. * TERM EXPLANATIONS:
  6148. *
  6149. * [option]:
  6150. *
  6151. * An object that contains definitions of components. For example:
  6152. * var option = {
  6153. * title: {...},
  6154. * legend: {...},
  6155. * visualMap: {...},
  6156. * series: [
  6157. * {data: [...]},
  6158. * {data: [...]},
  6159. * ...
  6160. * ]
  6161. * };
  6162. *
  6163. * [rawOption]:
  6164. *
  6165. * An object input to echarts.setOption. 'rawOption' may be an
  6166. * 'option', or may be an object contains multi-options. For example:
  6167. * var option = {
  6168. * baseOption: {
  6169. * title: {...},
  6170. * legend: {...},
  6171. * series: [
  6172. * {data: [...]},
  6173. * {data: [...]},
  6174. * ...
  6175. * ]
  6176. * },
  6177. * timeline: {...},
  6178. * options: [
  6179. * {title: {...}, series: {data: [...]}},
  6180. * {title: {...}, series: {data: [...]}},
  6181. * ...
  6182. * ],
  6183. * media: [
  6184. * {
  6185. * query: {maxWidth: 320},
  6186. * option: {series: {x: 20}, visualMap: {show: false}}
  6187. * },
  6188. * {
  6189. * query: {minWidth: 320, maxWidth: 720},
  6190. * option: {series: {x: 500}, visualMap: {show: true}}
  6191. * },
  6192. * {
  6193. * option: {series: {x: 1200}, visualMap: {show: true}}
  6194. * }
  6195. * ]
  6196. * };
  6197. *
  6198. * @alias module:echarts/model/OptionManager
  6199. * @param {module:echarts/ExtensionAPI} api
  6200. */
  6201. function OptionManager(api) {
  6202. /**
  6203. * @private
  6204. * @type {module:echarts/ExtensionAPI}
  6205. */
  6206. this._api = api;
  6207. /**
  6208. * @private
  6209. * @type {Array.<number>}
  6210. */
  6211. this._timelineOptions = [];
  6212. /**
  6213. * @private
  6214. * @type {Array.<Object>}
  6215. */
  6216. this._mediaList = [];
  6217. /**
  6218. * @private
  6219. * @type {Object}
  6220. */
  6221. this._mediaDefault;
  6222. /**
  6223. * -1, means default.
  6224. * empty means no media.
  6225. * @private
  6226. * @type {Array.<number>}
  6227. */
  6228. this._currentMediaIndices = [];
  6229. /**
  6230. * @private
  6231. * @type {Object}
  6232. */
  6233. this._optionBackup;
  6234. /**
  6235. * @private
  6236. * @type {Object}
  6237. */
  6238. this._newBaseOption;
  6239. }
  6240. // timeline.notMerge is not supported in ec3. Firstly there is rearly
  6241. // case that notMerge is needed. Secondly supporting 'notMerge' requires
  6242. // rawOption cloned and backuped when timeline changed, which does no
  6243. // good to performance. What's more, that both timeline and setOption
  6244. // method supply 'notMerge' brings complex and some problems.
  6245. // Consider this case:
  6246. // (step1) chart.setOption({timeline: {notMerge: false}, ...}, false);
  6247. // (step2) chart.setOption({timeline: {notMerge: true}, ...}, false);
  6248. OptionManager.prototype = {
  6249. constructor: OptionManager,
  6250. /**
  6251. * @public
  6252. * @param {Object} rawOption Raw option.
  6253. * @param {module:echarts/model/Global} ecModel
  6254. * @param {Array.<Function>} optionPreprocessorFuncs
  6255. * @return {Object} Init option
  6256. */
  6257. setOption: function (rawOption, optionPreprocessorFuncs) {
  6258. rawOption = clone(rawOption, true);
  6259. // FIXME
  6260. // 如果 timeline options 或者 media 中设置了某个属性,而baseOption中没有设置,则进行警告。
  6261. var oldOptionBackup = this._optionBackup;
  6262. var newParsedOption = parseRawOption.call(
  6263. this, rawOption, optionPreprocessorFuncs, !oldOptionBackup
  6264. );
  6265. this._newBaseOption = newParsedOption.baseOption;
  6266. // For setOption at second time (using merge mode);
  6267. if (oldOptionBackup) {
  6268. // Only baseOption can be merged.
  6269. mergeOption(oldOptionBackup.baseOption, newParsedOption.baseOption);
  6270. // For simplicity, timeline options and media options do not support merge,
  6271. // that is, if you `setOption` twice and both has timeline options, the latter
  6272. // timeline opitons will not be merged to the formers, but just substitude them.
  6273. if (newParsedOption.timelineOptions.length) {
  6274. oldOptionBackup.timelineOptions = newParsedOption.timelineOptions;
  6275. }
  6276. if (newParsedOption.mediaList.length) {
  6277. oldOptionBackup.mediaList = newParsedOption.mediaList;
  6278. }
  6279. if (newParsedOption.mediaDefault) {
  6280. oldOptionBackup.mediaDefault = newParsedOption.mediaDefault;
  6281. }
  6282. }
  6283. else {
  6284. this._optionBackup = newParsedOption;
  6285. }
  6286. },
  6287. /**
  6288. * @param {boolean} isRecreate
  6289. * @return {Object}
  6290. */
  6291. mountOption: function (isRecreate) {
  6292. var optionBackup = this._optionBackup;
  6293. // TODO
  6294. // 如果没有reset功能则不clone。
  6295. this._timelineOptions = map(optionBackup.timelineOptions, clone);
  6296. this._mediaList = map(optionBackup.mediaList, clone);
  6297. this._mediaDefault = clone(optionBackup.mediaDefault);
  6298. this._currentMediaIndices = [];
  6299. return clone(isRecreate
  6300. // this._optionBackup.baseOption, which is created at the first `setOption`
  6301. // called, and is merged into every new option by inner method `mergeOption`
  6302. // each time `setOption` called, can be only used in `isRecreate`, because
  6303. // its reliability is under suspicion. In other cases option merge is
  6304. // performed by `model.mergeOption`.
  6305. ? optionBackup.baseOption : this._newBaseOption
  6306. );
  6307. },
  6308. /**
  6309. * @param {module:echarts/model/Global} ecModel
  6310. * @return {Object}
  6311. */
  6312. getTimelineOption: function (ecModel) {
  6313. var option;
  6314. var timelineOptions = this._timelineOptions;
  6315. if (timelineOptions.length) {
  6316. // getTimelineOption can only be called after ecModel inited,
  6317. // so we can get currentIndex from timelineModel.
  6318. var timelineModel = ecModel.getComponent('timeline');
  6319. if (timelineModel) {
  6320. option = clone(
  6321. timelineOptions[timelineModel.getCurrentIndex()],
  6322. true
  6323. );
  6324. }
  6325. }
  6326. return option;
  6327. },
  6328. /**
  6329. * @param {module:echarts/model/Global} ecModel
  6330. * @return {Array.<Object>}
  6331. */
  6332. getMediaOption: function (ecModel) {
  6333. var ecWidth = this._api.getWidth();
  6334. var ecHeight = this._api.getHeight();
  6335. var mediaList = this._mediaList;
  6336. var mediaDefault = this._mediaDefault;
  6337. var indices = [];
  6338. var result = [];
  6339. // No media defined.
  6340. if (!mediaList.length && !mediaDefault) {
  6341. return result;
  6342. }
  6343. // Multi media may be applied, the latter defined media has higher priority.
  6344. for (var i = 0, len = mediaList.length; i < len; i++) {
  6345. if (applyMediaQuery(mediaList[i].query, ecWidth, ecHeight)) {
  6346. indices.push(i);
  6347. }
  6348. }
  6349. // FIXME
  6350. // 是否mediaDefault应该强制用户设置,否则可能修改不能回归。
  6351. if (!indices.length && mediaDefault) {
  6352. indices = [-1];
  6353. }
  6354. if (indices.length && !indicesEquals(indices, this._currentMediaIndices)) {
  6355. result = map(indices, function (index) {
  6356. return clone(
  6357. index === -1 ? mediaDefault.option : mediaList[index].option
  6358. );
  6359. });
  6360. }
  6361. // Otherwise return nothing.
  6362. this._currentMediaIndices = indices;
  6363. return result;
  6364. }
  6365. };
  6366. function parseRawOption(rawOption, optionPreprocessorFuncs, isNew) {
  6367. var timelineOptions = [];
  6368. var mediaList = [];
  6369. var mediaDefault;
  6370. var baseOption;
  6371. // Compatible with ec2.
  6372. var timelineOpt = rawOption.timeline;
  6373. if (rawOption.baseOption) {
  6374. baseOption = rawOption.baseOption;
  6375. }
  6376. // For timeline
  6377. if (timelineOpt || rawOption.options) {
  6378. baseOption = baseOption || {};
  6379. timelineOptions = (rawOption.options || []).slice();
  6380. }
  6381. // For media query
  6382. if (rawOption.media) {
  6383. baseOption = baseOption || {};
  6384. var media = rawOption.media;
  6385. each(media, function (singleMedia) {
  6386. if (singleMedia && singleMedia.option) {
  6387. if (singleMedia.query) {
  6388. mediaList.push(singleMedia);
  6389. }
  6390. else if (!mediaDefault) {
  6391. // Use the first media default.
  6392. mediaDefault = singleMedia;
  6393. }
  6394. }
  6395. });
  6396. }
  6397. // For normal option
  6398. if (!baseOption) {
  6399. baseOption = rawOption;
  6400. }
  6401. // Set timelineOpt to baseOption in ec3,
  6402. // which is convenient for merge option.
  6403. if (!baseOption.timeline) {
  6404. baseOption.timeline = timelineOpt;
  6405. }
  6406. // Preprocess.
  6407. each([baseOption].concat(timelineOptions)
  6408. .concat(zrUtil.map(mediaList, function (media) {
  6409. return media.option;
  6410. })),
  6411. function (option) {
  6412. each(optionPreprocessorFuncs, function (preProcess) {
  6413. preProcess(option, isNew);
  6414. });
  6415. }
  6416. );
  6417. return {
  6418. baseOption: baseOption,
  6419. timelineOptions: timelineOptions,
  6420. mediaDefault: mediaDefault,
  6421. mediaList: mediaList
  6422. };
  6423. }
  6424. /**
  6425. * @see <http://www.w3.org/TR/css3-mediaqueries/#media1>
  6426. * Support: width, height, aspectRatio
  6427. * Can use max or min as prefix.
  6428. */
  6429. function applyMediaQuery(query, ecWidth, ecHeight) {
  6430. var realMap = {
  6431. width: ecWidth,
  6432. height: ecHeight,
  6433. aspectratio: ecWidth / ecHeight // lowser case for convenientce.
  6434. };
  6435. var applicatable = true;
  6436. zrUtil.each(query, function (value, attr) {
  6437. var matched = attr.match(QUERY_REG);
  6438. if (!matched || !matched[1] || !matched[2]) {
  6439. return;
  6440. }
  6441. var operator = matched[1];
  6442. var realAttr = matched[2].toLowerCase();
  6443. if (!compare(realMap[realAttr], value, operator)) {
  6444. applicatable = false;
  6445. }
  6446. });
  6447. return applicatable;
  6448. }
  6449. function compare(real, expect, operator) {
  6450. if (operator === 'min') {
  6451. return real >= expect;
  6452. }
  6453. else if (operator === 'max') {
  6454. return real <= expect;
  6455. }
  6456. else { // Equals
  6457. return real === expect;
  6458. }
  6459. }
  6460. function indicesEquals(indices1, indices2) {
  6461. // indices is always order by asc and has only finite number.
  6462. return indices1.join(',') === indices2.join(',');
  6463. }
  6464. /**
  6465. * Consider case:
  6466. * `chart.setOption(opt1);`
  6467. * Then user do some interaction like dataZoom, dataView changing.
  6468. * `chart.setOption(opt2);`
  6469. * Then user press 'reset button' in toolbox.
  6470. *
  6471. * After doing that all of the interaction effects should be reset, the
  6472. * chart should be the same as the result of invoke
  6473. * `chart.setOption(opt1); chart.setOption(opt2);`.
  6474. *
  6475. * Although it is not able ensure that
  6476. * `chart.setOption(opt1); chart.setOption(opt2);` is equivalents to
  6477. * `chart.setOption(merge(opt1, opt2));` exactly,
  6478. * this might be the only simple way to implement that feature.
  6479. *
  6480. * MEMO: We've considered some other approaches:
  6481. * 1. Each model handle its self restoration but not uniform treatment.
  6482. * (Too complex in logic and error-prone)
  6483. * 2. Use a shadow ecModel. (Performace expensive)
  6484. */
  6485. function mergeOption(oldOption, newOption) {
  6486. newOption = newOption || {};
  6487. each(newOption, function (newCptOpt, mainType) {
  6488. if (newCptOpt == null) {
  6489. return;
  6490. }
  6491. var oldCptOpt = oldOption[mainType];
  6492. if (!ComponentModel.hasClass(mainType)) {
  6493. oldOption[mainType] = merge(oldCptOpt, newCptOpt, true);
  6494. }
  6495. else {
  6496. newCptOpt = modelUtil.normalizeToArray(newCptOpt);
  6497. oldCptOpt = modelUtil.normalizeToArray(oldCptOpt);
  6498. var mapResult = modelUtil.mappingToExists(oldCptOpt, newCptOpt);
  6499. oldOption[mainType] = map(mapResult, function (item) {
  6500. return (item.option && item.exist)
  6501. ? merge(item.exist, item.option, true)
  6502. : (item.exist || item.option);
  6503. });
  6504. }
  6505. });
  6506. }
  6507. module.exports = OptionManager;
  6508. /***/ },
  6509. /* 28 */
  6510. /***/ function(module, exports, __webpack_require__) {
  6511. 'use strict';
  6512. var zrUtil = __webpack_require__(4);
  6513. var formatUtil = __webpack_require__(6);
  6514. var classUtil = __webpack_require__(13);
  6515. var modelUtil = __webpack_require__(5);
  6516. var ComponentModel = __webpack_require__(19);
  6517. var colorPaletteMixin = __webpack_require__(24);
  6518. var env = __webpack_require__(2);
  6519. var layout = __webpack_require__(21);
  6520. var set = classUtil.set;
  6521. var get = classUtil.get;
  6522. var encodeHTML = formatUtil.encodeHTML;
  6523. var addCommas = formatUtil.addCommas;
  6524. var SeriesModel = ComponentModel.extend({
  6525. type: 'series.__base__',
  6526. /**
  6527. * @readOnly
  6528. */
  6529. seriesIndex: 0,
  6530. // coodinateSystem will be injected in the echarts/CoordinateSystem
  6531. coordinateSystem: null,
  6532. /**
  6533. * @type {Object}
  6534. * @protected
  6535. */
  6536. defaultOption: null,
  6537. /**
  6538. * Data provided for legend
  6539. * @type {Function}
  6540. */
  6541. // PENDING
  6542. legendDataProvider: null,
  6543. /**
  6544. * Access path of color for visual
  6545. */
  6546. visualColorAccessPath: 'itemStyle.normal.color',
  6547. /**
  6548. * Support merge layout params.
  6549. * Only support 'box' now (left/right/top/bottom/width/height).
  6550. * @type {string|Object} Object can be {ignoreSize: true}
  6551. * @readOnly
  6552. */
  6553. layoutMode: null,
  6554. init: function (option, parentModel, ecModel, extraOpt) {
  6555. /**
  6556. * @type {number}
  6557. * @readOnly
  6558. */
  6559. this.seriesIndex = this.componentIndex;
  6560. this.mergeDefaultAndTheme(option, ecModel);
  6561. /**
  6562. * @type {module:echarts/data/List|module:echarts/data/Tree|module:echarts/data/Graph}
  6563. * @private
  6564. */
  6565. set(this, 'dataBeforeProcessed', this.getInitialData(option, ecModel));
  6566. // If we reverse the order (make data firstly, and then make
  6567. // dataBeforeProcessed by cloneShallow), cloneShallow will
  6568. // cause data.graph.data !== data when using
  6569. // module:echarts/data/Graph or module:echarts/data/Tree.
  6570. // See module:echarts/data/helper/linkList
  6571. this.restoreData();
  6572. },
  6573. /**
  6574. * Util for merge default and theme to option
  6575. * @param {Object} option
  6576. * @param {module:echarts/model/Global} ecModel
  6577. */
  6578. mergeDefaultAndTheme: function (option, ecModel) {
  6579. var layoutMode = this.layoutMode;
  6580. var inputPositionParams = layoutMode
  6581. ? layout.getLayoutParams(option) : {};
  6582. zrUtil.merge(
  6583. option,
  6584. ecModel.getTheme().get(this.subType)
  6585. );
  6586. zrUtil.merge(option, this.getDefaultOption());
  6587. // Default label emphasis `position` and `show`
  6588. // FIXME Set label in mergeOption
  6589. modelUtil.defaultEmphasis(option.label, modelUtil.LABEL_OPTIONS);
  6590. this.fillDataTextStyle(option.data);
  6591. if (layoutMode) {
  6592. layout.mergeLayoutParam(option, inputPositionParams, layoutMode);
  6593. }
  6594. },
  6595. mergeOption: function (newSeriesOption, ecModel) {
  6596. newSeriesOption = zrUtil.merge(this.option, newSeriesOption, true);
  6597. this.fillDataTextStyle(newSeriesOption.data);
  6598. var layoutMode = this.layoutMode;
  6599. if (layoutMode) {
  6600. layout.mergeLayoutParam(this.option, newSeriesOption, layoutMode);
  6601. }
  6602. var data = this.getInitialData(newSeriesOption, ecModel);
  6603. // TODO Merge data?
  6604. if (data) {
  6605. set(this, 'data', data);
  6606. set(this, 'dataBeforeProcessed', data.cloneShallow());
  6607. }
  6608. },
  6609. fillDataTextStyle: function (data) {
  6610. // Default data label emphasis `position` and `show`
  6611. // FIXME Tree structure data ?
  6612. // FIXME Performance ?
  6613. if (data) {
  6614. for (var i = 0; i < data.length; i++) {
  6615. if (data[i] && data[i].label) {
  6616. modelUtil.defaultEmphasis(data[i].label, modelUtil.LABEL_OPTIONS);
  6617. }
  6618. }
  6619. }
  6620. },
  6621. /**
  6622. * Init a data structure from data related option in series
  6623. * Must be overwritten
  6624. */
  6625. getInitialData: function () {},
  6626. /**
  6627. * @param {string} [dataType]
  6628. * @return {module:echarts/data/List}
  6629. */
  6630. getData: function (dataType) {
  6631. var data = get(this, 'data');
  6632. return dataType == null ? data : data.getLinkedData(dataType);
  6633. },
  6634. /**
  6635. * @param {module:echarts/data/List} data
  6636. */
  6637. setData: function (data) {
  6638. set(this, 'data', data);
  6639. },
  6640. /**
  6641. * Get data before processed
  6642. * @return {module:echarts/data/List}
  6643. */
  6644. getRawData: function () {
  6645. return get(this, 'dataBeforeProcessed');
  6646. },
  6647. /**
  6648. * Coord dimension to data dimension.
  6649. *
  6650. * By default the result is the same as dimensions of series data.
  6651. * But in some series data dimensions are different from coord dimensions (i.e.
  6652. * candlestick and boxplot). Override this method to handle those cases.
  6653. *
  6654. * Coord dimension to data dimension can be one-to-many
  6655. *
  6656. * @param {string} coordDim
  6657. * @return {Array.<string>} dimensions on the axis.
  6658. */
  6659. coordDimToDataDim: function (coordDim) {
  6660. return [coordDim];
  6661. },
  6662. /**
  6663. * Convert data dimension to coord dimension.
  6664. *
  6665. * @param {string|number} dataDim
  6666. * @return {string}
  6667. */
  6668. dataDimToCoordDim: function (dataDim) {
  6669. return dataDim;
  6670. },
  6671. /**
  6672. * Get base axis if has coordinate system and has axis.
  6673. * By default use coordSys.getBaseAxis();
  6674. * Can be overrided for some chart.
  6675. * @return {type} description
  6676. */
  6677. getBaseAxis: function () {
  6678. var coordSys = this.coordinateSystem;
  6679. return coordSys && coordSys.getBaseAxis && coordSys.getBaseAxis();
  6680. },
  6681. // FIXME
  6682. /**
  6683. * Default tooltip formatter
  6684. *
  6685. * @param {number} dataIndex
  6686. * @param {boolean} [multipleSeries=false]
  6687. * @param {number} [dataType]
  6688. */
  6689. formatTooltip: function (dataIndex, multipleSeries, dataType) {
  6690. function formatArrayValue(value) {
  6691. var result = [];
  6692. zrUtil.each(value, function (val, idx) {
  6693. var dimInfo = data.getDimensionInfo(idx);
  6694. var dimType = dimInfo && dimInfo.type;
  6695. var valStr;
  6696. if (dimType === 'ordinal') {
  6697. valStr = val + '';
  6698. }
  6699. else if (dimType === 'time') {
  6700. valStr = multipleSeries ? '' : formatUtil.formatTime('yyyy/MM/dd hh:mm:ss', val);
  6701. }
  6702. else {
  6703. valStr = addCommas(val);
  6704. }
  6705. valStr && result.push(valStr);
  6706. });
  6707. return result.join(', ');
  6708. }
  6709. var data = get(this, 'data');
  6710. var value = this.getRawValue(dataIndex);
  6711. var formattedValue = encodeHTML(
  6712. zrUtil.isArray(value) ? formatArrayValue(value) : addCommas(value)
  6713. );
  6714. var name = data.getName(dataIndex);
  6715. var color = data.getItemVisual(dataIndex, 'color');
  6716. if (zrUtil.isObject(color) && color.colorStops) {
  6717. color = (color.colorStops[0] || {}).color;
  6718. }
  6719. color = color || 'transparent';
  6720. var colorEl = '<span style="display:inline-block;margin-right:5px;'
  6721. + 'border-radius:10px;width:9px;height:9px;background-color:' + encodeHTML(color) + '"></span>';
  6722. var seriesName = this.name;
  6723. // FIXME
  6724. if (seriesName === '\0-') {
  6725. // Not show '-'
  6726. seriesName = '';
  6727. }
  6728. return !multipleSeries
  6729. ? ((seriesName && encodeHTML(seriesName) + '<br />') + colorEl
  6730. + (name
  6731. ? encodeHTML(name) + ' : ' + formattedValue
  6732. : formattedValue
  6733. )
  6734. )
  6735. : (colorEl + encodeHTML(this.name) + ' : ' + formattedValue);
  6736. },
  6737. /**
  6738. * @return {boolean}
  6739. */
  6740. isAnimationEnabled: function () {
  6741. if (env.node) {
  6742. return false;
  6743. }
  6744. var animationEnabled = this.getShallow('animation');
  6745. if (animationEnabled) {
  6746. if (this.getData().count() > this.getShallow('animationThreshold')) {
  6747. animationEnabled = false;
  6748. }
  6749. }
  6750. return animationEnabled;
  6751. },
  6752. restoreData: function () {
  6753. set(this, 'data', get(this, 'dataBeforeProcessed').cloneShallow());
  6754. },
  6755. getColorFromPalette: function (name, scope) {
  6756. var ecModel = this.ecModel;
  6757. // PENDING
  6758. var color = colorPaletteMixin.getColorFromPalette.call(this, name, scope);
  6759. if (!color) {
  6760. color = ecModel.getColorFromPalette(name, scope);
  6761. }
  6762. return color;
  6763. },
  6764. /**
  6765. * Get data indices for show tooltip content. See tooltip.
  6766. * @abstract
  6767. * @param {Array.<string>|string} dim
  6768. * @param {Array.<number>} value
  6769. * @param {module:echarts/coord/single/SingleAxis} baseAxis
  6770. * @return {Array.<number>} data indices.
  6771. */
  6772. getAxisTooltipDataIndex: null,
  6773. /**
  6774. * See tooltip.
  6775. * @abstract
  6776. * @param {number} dataIndex
  6777. * @return {Array.<number>} Point of tooltip. null/undefined can be returned.
  6778. */
  6779. getTooltipPosition: null
  6780. });
  6781. zrUtil.mixin(SeriesModel, modelUtil.dataFormatMixin);
  6782. zrUtil.mixin(SeriesModel, colorPaletteMixin);
  6783. module.exports = SeriesModel;
  6784. /***/ },
  6785. /* 29 */
  6786. /***/ function(module, exports, __webpack_require__) {
  6787. var Group = __webpack_require__(30);
  6788. var componentUtil = __webpack_require__(20);
  6789. var clazzUtil = __webpack_require__(13);
  6790. var Component = function () {
  6791. /**
  6792. * @type {module:zrender/container/Group}
  6793. * @readOnly
  6794. */
  6795. this.group = new Group();
  6796. /**
  6797. * @type {string}
  6798. * @readOnly
  6799. */
  6800. this.uid = componentUtil.getUID('viewComponent');
  6801. };
  6802. Component.prototype = {
  6803. constructor: Component,
  6804. init: function (ecModel, api) {},
  6805. render: function (componentModel, ecModel, api, payload) {},
  6806. dispose: function () {}
  6807. };
  6808. var componentProto = Component.prototype;
  6809. componentProto.updateView
  6810. = componentProto.updateLayout
  6811. = componentProto.updateVisual
  6812. = function (seriesModel, ecModel, api, payload) {
  6813. // Do nothing;
  6814. };
  6815. // Enable Component.extend.
  6816. clazzUtil.enableClassExtend(Component);
  6817. // Enable capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  6818. clazzUtil.enableClassManagement(Component, {registerWhenExtend: true});
  6819. module.exports = Component;
  6820. /***/ },
  6821. /* 30 */
  6822. /***/ function(module, exports, __webpack_require__) {
  6823. /**
  6824. * Group是一个容器,可以插入子节点,Group的变换也会被应用到子节点上
  6825. * @module zrender/graphic/Group
  6826. * @example
  6827. * var Group = require('zrender/lib/container/Group');
  6828. * var Circle = require('zrender/lib/graphic/shape/Circle');
  6829. * var g = new Group();
  6830. * g.position[0] = 100;
  6831. * g.position[1] = 100;
  6832. * g.add(new Circle({
  6833. * style: {
  6834. * x: 100,
  6835. * y: 100,
  6836. * r: 20,
  6837. * }
  6838. * }));
  6839. * zr.add(g);
  6840. */
  6841. var zrUtil = __webpack_require__(4);
  6842. var Element = __webpack_require__(31);
  6843. var BoundingRect = __webpack_require__(9);
  6844. /**
  6845. * @alias module:zrender/graphic/Group
  6846. * @constructor
  6847. * @extends module:zrender/mixin/Transformable
  6848. * @extends module:zrender/mixin/Eventful
  6849. */
  6850. var Group = function (opts) {
  6851. opts = opts || {};
  6852. Element.call(this, opts);
  6853. for (var key in opts) {
  6854. if (opts.hasOwnProperty(key)) {
  6855. this[key] = opts[key];
  6856. }
  6857. }
  6858. this._children = [];
  6859. this.__storage = null;
  6860. this.__dirty = true;
  6861. };
  6862. Group.prototype = {
  6863. constructor: Group,
  6864. isGroup: true,
  6865. /**
  6866. * @type {string}
  6867. */
  6868. type: 'group',
  6869. /**
  6870. * 所有子孙元素是否响应鼠标事件
  6871. * @name module:/zrender/container/Group#silent
  6872. * @type {boolean}
  6873. * @default false
  6874. */
  6875. silent: false,
  6876. /**
  6877. * @return {Array.<module:zrender/Element>}
  6878. */
  6879. children: function () {
  6880. return this._children.slice();
  6881. },
  6882. /**
  6883. * 获取指定 index 的儿子节点
  6884. * @param {number} idx
  6885. * @return {module:zrender/Element}
  6886. */
  6887. childAt: function (idx) {
  6888. return this._children[idx];
  6889. },
  6890. /**
  6891. * 获取指定名字的儿子节点
  6892. * @param {string} name
  6893. * @return {module:zrender/Element}
  6894. */
  6895. childOfName: function (name) {
  6896. var children = this._children;
  6897. for (var i = 0; i < children.length; i++) {
  6898. if (children[i].name === name) {
  6899. return children[i];
  6900. }
  6901. }
  6902. },
  6903. /**
  6904. * @return {number}
  6905. */
  6906. childCount: function () {
  6907. return this._children.length;
  6908. },
  6909. /**
  6910. * 添加子节点到最后
  6911. * @param {module:zrender/Element} child
  6912. */
  6913. add: function (child) {
  6914. if (child && child !== this && child.parent !== this) {
  6915. this._children.push(child);
  6916. this._doAdd(child);
  6917. }
  6918. return this;
  6919. },
  6920. /**
  6921. * 添加子节点在 nextSibling 之前
  6922. * @param {module:zrender/Element} child
  6923. * @param {module:zrender/Element} nextSibling
  6924. */
  6925. addBefore: function (child, nextSibling) {
  6926. if (child && child !== this && child.parent !== this
  6927. && nextSibling && nextSibling.parent === this) {
  6928. var children = this._children;
  6929. var idx = children.indexOf(nextSibling);
  6930. if (idx >= 0) {
  6931. children.splice(idx, 0, child);
  6932. this._doAdd(child);
  6933. }
  6934. }
  6935. return this;
  6936. },
  6937. _doAdd: function (child) {
  6938. if (child.parent) {
  6939. child.parent.remove(child);
  6940. }
  6941. child.parent = this;
  6942. var storage = this.__storage;
  6943. var zr = this.__zr;
  6944. if (storage && storage !== child.__storage) {
  6945. storage.addToMap(child);
  6946. if (child instanceof Group) {
  6947. child.addChildrenToStorage(storage);
  6948. }
  6949. }
  6950. zr && zr.refresh();
  6951. },
  6952. /**
  6953. * 移除子节点
  6954. * @param {module:zrender/Element} child
  6955. */
  6956. remove: function (child) {
  6957. var zr = this.__zr;
  6958. var storage = this.__storage;
  6959. var children = this._children;
  6960. var idx = zrUtil.indexOf(children, child);
  6961. if (idx < 0) {
  6962. return this;
  6963. }
  6964. children.splice(idx, 1);
  6965. child.parent = null;
  6966. if (storage) {
  6967. storage.delFromMap(child.id);
  6968. if (child instanceof Group) {
  6969. child.delChildrenFromStorage(storage);
  6970. }
  6971. }
  6972. zr && zr.refresh();
  6973. return this;
  6974. },
  6975. /**
  6976. * 移除所有子节点
  6977. */
  6978. removeAll: function () {
  6979. var children = this._children;
  6980. var storage = this.__storage;
  6981. var child;
  6982. var i;
  6983. for (i = 0; i < children.length; i++) {
  6984. child = children[i];
  6985. if (storage) {
  6986. storage.delFromMap(child.id);
  6987. if (child instanceof Group) {
  6988. child.delChildrenFromStorage(storage);
  6989. }
  6990. }
  6991. child.parent = null;
  6992. }
  6993. children.length = 0;
  6994. return this;
  6995. },
  6996. /**
  6997. * 遍历所有子节点
  6998. * @param {Function} cb
  6999. * @param {} context
  7000. */
  7001. eachChild: function (cb, context) {
  7002. var children = this._children;
  7003. for (var i = 0; i < children.length; i++) {
  7004. var child = children[i];
  7005. cb.call(context, child, i);
  7006. }
  7007. return this;
  7008. },
  7009. /**
  7010. * 深度优先遍历所有子孙节点
  7011. * @param {Function} cb
  7012. * @param {} context
  7013. */
  7014. traverse: function (cb, context) {
  7015. for (var i = 0; i < this._children.length; i++) {
  7016. var child = this._children[i];
  7017. cb.call(context, child);
  7018. if (child.type === 'group') {
  7019. child.traverse(cb, context);
  7020. }
  7021. }
  7022. return this;
  7023. },
  7024. addChildrenToStorage: function (storage) {
  7025. for (var i = 0; i < this._children.length; i++) {
  7026. var child = this._children[i];
  7027. storage.addToMap(child);
  7028. if (child instanceof Group) {
  7029. child.addChildrenToStorage(storage);
  7030. }
  7031. }
  7032. },
  7033. delChildrenFromStorage: function (storage) {
  7034. for (var i = 0; i < this._children.length; i++) {
  7035. var child = this._children[i];
  7036. storage.delFromMap(child.id);
  7037. if (child instanceof Group) {
  7038. child.delChildrenFromStorage(storage);
  7039. }
  7040. }
  7041. },
  7042. dirty: function () {
  7043. this.__dirty = true;
  7044. this.__zr && this.__zr.refresh();
  7045. return this;
  7046. },
  7047. /**
  7048. * @return {module:zrender/core/BoundingRect}
  7049. */
  7050. getBoundingRect: function (includeChildren) {
  7051. // TODO Caching
  7052. var rect = null;
  7053. var tmpRect = new BoundingRect(0, 0, 0, 0);
  7054. var children = includeChildren || this._children;
  7055. var tmpMat = [];
  7056. for (var i = 0; i < children.length; i++) {
  7057. var child = children[i];
  7058. if (child.ignore || child.invisible) {
  7059. continue;
  7060. }
  7061. var childRect = child.getBoundingRect();
  7062. var transform = child.getLocalTransform(tmpMat);
  7063. // TODO
  7064. // The boundingRect cacluated by transforming original
  7065. // rect may be bigger than the actual bundingRect when rotation
  7066. // is used. (Consider a circle rotated aginst its center, where
  7067. // the actual boundingRect should be the same as that not be
  7068. // rotated.) But we can not find better approach to calculate
  7069. // actual boundingRect yet, considering performance.
  7070. if (transform) {
  7071. tmpRect.copy(childRect);
  7072. tmpRect.applyTransform(transform);
  7073. rect = rect || tmpRect.clone();
  7074. rect.union(tmpRect);
  7075. }
  7076. else {
  7077. rect = rect || childRect.clone();
  7078. rect.union(childRect);
  7079. }
  7080. }
  7081. return rect || tmpRect;
  7082. }
  7083. };
  7084. zrUtil.inherits(Group, Element);
  7085. module.exports = Group;
  7086. /***/ },
  7087. /* 31 */
  7088. /***/ function(module, exports, __webpack_require__) {
  7089. 'use strict';
  7090. /**
  7091. * @module zrender/Element
  7092. */
  7093. var guid = __webpack_require__(32);
  7094. var Eventful = __webpack_require__(33);
  7095. var Transformable = __webpack_require__(34);
  7096. var Animatable = __webpack_require__(35);
  7097. var zrUtil = __webpack_require__(4);
  7098. /**
  7099. * @alias module:zrender/Element
  7100. * @constructor
  7101. * @extends {module:zrender/mixin/Animatable}
  7102. * @extends {module:zrender/mixin/Transformable}
  7103. * @extends {module:zrender/mixin/Eventful}
  7104. */
  7105. var Element = function (opts) {
  7106. Transformable.call(this, opts);
  7107. Eventful.call(this, opts);
  7108. Animatable.call(this, opts);
  7109. /**
  7110. * 画布元素ID
  7111. * @type {string}
  7112. */
  7113. this.id = opts.id || guid();
  7114. };
  7115. Element.prototype = {
  7116. /**
  7117. * 元素类型
  7118. * Element type
  7119. * @type {string}
  7120. */
  7121. type: 'element',
  7122. /**
  7123. * 元素名字
  7124. * Element name
  7125. * @type {string}
  7126. */
  7127. name: '',
  7128. /**
  7129. * ZRender 实例对象,会在 element 添加到 zrender 实例中后自动赋值
  7130. * ZRender instance will be assigned when element is associated with zrender
  7131. * @name module:/zrender/Element#__zr
  7132. * @type {module:zrender/ZRender}
  7133. */
  7134. __zr: null,
  7135. /**
  7136. * 图形是否忽略,为true时忽略图形的绘制以及事件触发
  7137. * If ignore drawing and events of the element object
  7138. * @name module:/zrender/Element#ignore
  7139. * @type {boolean}
  7140. * @default false
  7141. */
  7142. ignore: false,
  7143. /**
  7144. * 用于裁剪的路径(shape),所有 Group 内的路径在绘制时都会被这个路径裁剪
  7145. * 该路径会继承被裁减对象的变换
  7146. * @type {module:zrender/graphic/Path}
  7147. * @see http://www.w3.org/TR/2dcontext/#clipping-region
  7148. * @readOnly
  7149. */
  7150. clipPath: null,
  7151. /**
  7152. * Drift element
  7153. * @param {number} dx dx on the global space
  7154. * @param {number} dy dy on the global space
  7155. */
  7156. drift: function (dx, dy) {
  7157. switch (this.draggable) {
  7158. case 'horizontal':
  7159. dy = 0;
  7160. break;
  7161. case 'vertical':
  7162. dx = 0;
  7163. break;
  7164. }
  7165. var m = this.transform;
  7166. if (!m) {
  7167. m = this.transform = [1, 0, 0, 1, 0, 0];
  7168. }
  7169. m[4] += dx;
  7170. m[5] += dy;
  7171. this.decomposeTransform();
  7172. this.dirty(false);
  7173. },
  7174. /**
  7175. * Hook before update
  7176. */
  7177. beforeUpdate: function () {},
  7178. /**
  7179. * Hook after update
  7180. */
  7181. afterUpdate: function () {},
  7182. /**
  7183. * Update each frame
  7184. */
  7185. update: function () {
  7186. this.updateTransform();
  7187. },
  7188. /**
  7189. * @param {Function} cb
  7190. * @param {} context
  7191. */
  7192. traverse: function (cb, context) {},
  7193. /**
  7194. * @protected
  7195. */
  7196. attrKV: function (key, value) {
  7197. if (key === 'position' || key === 'scale' || key === 'origin') {
  7198. // Copy the array
  7199. if (value) {
  7200. var target = this[key];
  7201. if (!target) {
  7202. target = this[key] = [];
  7203. }
  7204. target[0] = value[0];
  7205. target[1] = value[1];
  7206. }
  7207. }
  7208. else {
  7209. this[key] = value;
  7210. }
  7211. },
  7212. /**
  7213. * Hide the element
  7214. */
  7215. hide: function () {
  7216. this.ignore = true;
  7217. this.__zr && this.__zr.refresh();
  7218. },
  7219. /**
  7220. * Show the element
  7221. */
  7222. show: function () {
  7223. this.ignore = false;
  7224. this.__zr && this.__zr.refresh();
  7225. },
  7226. /**
  7227. * @param {string|Object} key
  7228. * @param {*} value
  7229. */
  7230. attr: function (key, value) {
  7231. if (typeof key === 'string') {
  7232. this.attrKV(key, value);
  7233. }
  7234. else if (zrUtil.isObject(key)) {
  7235. for (var name in key) {
  7236. if (key.hasOwnProperty(name)) {
  7237. this.attrKV(name, key[name]);
  7238. }
  7239. }
  7240. }
  7241. this.dirty(false);
  7242. return this;
  7243. },
  7244. /**
  7245. * @param {module:zrender/graphic/Path} clipPath
  7246. */
  7247. setClipPath: function (clipPath) {
  7248. var zr = this.__zr;
  7249. if (zr) {
  7250. clipPath.addSelfToZr(zr);
  7251. }
  7252. // Remove previous clip path
  7253. if (this.clipPath && this.clipPath !== clipPath) {
  7254. this.removeClipPath();
  7255. }
  7256. this.clipPath = clipPath;
  7257. clipPath.__zr = zr;
  7258. clipPath.__clipTarget = this;
  7259. this.dirty(false);
  7260. },
  7261. /**
  7262. */
  7263. removeClipPath: function () {
  7264. var clipPath = this.clipPath;
  7265. if (clipPath) {
  7266. if (clipPath.__zr) {
  7267. clipPath.removeSelfFromZr(clipPath.__zr);
  7268. }
  7269. clipPath.__zr = null;
  7270. clipPath.__clipTarget = null;
  7271. this.clipPath = null;
  7272. this.dirty(false);
  7273. }
  7274. },
  7275. /**
  7276. * Add self from zrender instance.
  7277. * Not recursively because it will be invoked when element added to storage.
  7278. * @param {module:zrender/ZRender} zr
  7279. */
  7280. addSelfToZr: function (zr) {
  7281. this.__zr = zr;
  7282. // 添加动画
  7283. var animators = this.animators;
  7284. if (animators) {
  7285. for (var i = 0; i < animators.length; i++) {
  7286. zr.animation.addAnimator(animators[i]);
  7287. }
  7288. }
  7289. if (this.clipPath) {
  7290. this.clipPath.addSelfToZr(zr);
  7291. }
  7292. },
  7293. /**
  7294. * Remove self from zrender instance.
  7295. * Not recursively because it will be invoked when element added to storage.
  7296. * @param {module:zrender/ZRender} zr
  7297. */
  7298. removeSelfFromZr: function (zr) {
  7299. this.__zr = null;
  7300. // 移除动画
  7301. var animators = this.animators;
  7302. if (animators) {
  7303. for (var i = 0; i < animators.length; i++) {
  7304. zr.animation.removeAnimator(animators[i]);
  7305. }
  7306. }
  7307. if (this.clipPath) {
  7308. this.clipPath.removeSelfFromZr(zr);
  7309. }
  7310. }
  7311. };
  7312. zrUtil.mixin(Element, Animatable);
  7313. zrUtil.mixin(Element, Transformable);
  7314. zrUtil.mixin(Element, Eventful);
  7315. module.exports = Element;
  7316. /***/ },
  7317. /* 32 */
  7318. /***/ function(module, exports) {
  7319. /**
  7320. * zrender: 生成唯一id
  7321. *
  7322. * @author errorrik (errorrik@gmail.com)
  7323. */
  7324. var idStart = 0x0907;
  7325. module.exports = function () {
  7326. return idStart++;
  7327. };
  7328. /***/ },
  7329. /* 33 */
  7330. /***/ function(module, exports) {
  7331. /**
  7332. * 事件扩展
  7333. * @module zrender/mixin/Eventful
  7334. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  7335. * pissang (https://www.github.com/pissang)
  7336. */
  7337. var arrySlice = Array.prototype.slice;
  7338. /**
  7339. * 事件分发器
  7340. * @alias module:zrender/mixin/Eventful
  7341. * @constructor
  7342. */
  7343. var Eventful = function () {
  7344. this._$handlers = {};
  7345. };
  7346. Eventful.prototype = {
  7347. constructor: Eventful,
  7348. /**
  7349. * 单次触发绑定,trigger后销毁
  7350. *
  7351. * @param {string} event 事件名
  7352. * @param {Function} handler 响应函数
  7353. * @param {Object} context
  7354. */
  7355. one: function (event, handler, context) {
  7356. var _h = this._$handlers;
  7357. if (!handler || !event) {
  7358. return this;
  7359. }
  7360. if (!_h[event]) {
  7361. _h[event] = [];
  7362. }
  7363. for (var i = 0; i < _h[event].length; i++) {
  7364. if (_h[event][i].h === handler) {
  7365. return this;
  7366. }
  7367. }
  7368. _h[event].push({
  7369. h: handler,
  7370. one: true,
  7371. ctx: context || this
  7372. });
  7373. return this;
  7374. },
  7375. /**
  7376. * 绑定事件
  7377. * @param {string} event 事件名
  7378. * @param {Function} handler 事件处理函数
  7379. * @param {Object} [context]
  7380. */
  7381. on: function (event, handler, context) {
  7382. var _h = this._$handlers;
  7383. if (!handler || !event) {
  7384. return this;
  7385. }
  7386. if (!_h[event]) {
  7387. _h[event] = [];
  7388. }
  7389. for (var i = 0; i < _h[event].length; i++) {
  7390. if (_h[event][i].h === handler) {
  7391. return this;
  7392. }
  7393. }
  7394. _h[event].push({
  7395. h: handler,
  7396. one: false,
  7397. ctx: context || this
  7398. });
  7399. return this;
  7400. },
  7401. /**
  7402. * 是否绑定了事件
  7403. * @param {string} event
  7404. * @return {boolean}
  7405. */
  7406. isSilent: function (event) {
  7407. var _h = this._$handlers;
  7408. return _h[event] && _h[event].length;
  7409. },
  7410. /**
  7411. * 解绑事件
  7412. * @param {string} event 事件名
  7413. * @param {Function} [handler] 事件处理函数
  7414. */
  7415. off: function (event, handler) {
  7416. var _h = this._$handlers;
  7417. if (!event) {
  7418. this._$handlers = {};
  7419. return this;
  7420. }
  7421. if (handler) {
  7422. if (_h[event]) {
  7423. var newList = [];
  7424. for (var i = 0, l = _h[event].length; i < l; i++) {
  7425. if (_h[event][i]['h'] != handler) {
  7426. newList.push(_h[event][i]);
  7427. }
  7428. }
  7429. _h[event] = newList;
  7430. }
  7431. if (_h[event] && _h[event].length === 0) {
  7432. delete _h[event];
  7433. }
  7434. }
  7435. else {
  7436. delete _h[event];
  7437. }
  7438. return this;
  7439. },
  7440. /**
  7441. * 事件分发
  7442. *
  7443. * @param {string} type 事件类型
  7444. */
  7445. trigger: function (type) {
  7446. if (this._$handlers[type]) {
  7447. var args = arguments;
  7448. var argLen = args.length;
  7449. if (argLen > 3) {
  7450. args = arrySlice.call(args, 1);
  7451. }
  7452. var _h = this._$handlers[type];
  7453. var len = _h.length;
  7454. for (var i = 0; i < len;) {
  7455. // Optimize advise from backbone
  7456. switch (argLen) {
  7457. case 1:
  7458. _h[i]['h'].call(_h[i]['ctx']);
  7459. break;
  7460. case 2:
  7461. _h[i]['h'].call(_h[i]['ctx'], args[1]);
  7462. break;
  7463. case 3:
  7464. _h[i]['h'].call(_h[i]['ctx'], args[1], args[2]);
  7465. break;
  7466. default:
  7467. // have more than 2 given arguments
  7468. _h[i]['h'].apply(_h[i]['ctx'], args);
  7469. break;
  7470. }
  7471. if (_h[i]['one']) {
  7472. _h.splice(i, 1);
  7473. len--;
  7474. }
  7475. else {
  7476. i++;
  7477. }
  7478. }
  7479. }
  7480. return this;
  7481. },
  7482. /**
  7483. * 带有context的事件分发, 最后一个参数是事件回调的context
  7484. * @param {string} type 事件类型
  7485. */
  7486. triggerWithContext: function (type) {
  7487. if (this._$handlers[type]) {
  7488. var args = arguments;
  7489. var argLen = args.length;
  7490. if (argLen > 4) {
  7491. args = arrySlice.call(args, 1, args.length - 1);
  7492. }
  7493. var ctx = args[args.length - 1];
  7494. var _h = this._$handlers[type];
  7495. var len = _h.length;
  7496. for (var i = 0; i < len;) {
  7497. // Optimize advise from backbone
  7498. switch (argLen) {
  7499. case 1:
  7500. _h[i]['h'].call(ctx);
  7501. break;
  7502. case 2:
  7503. _h[i]['h'].call(ctx, args[1]);
  7504. break;
  7505. case 3:
  7506. _h[i]['h'].call(ctx, args[1], args[2]);
  7507. break;
  7508. default:
  7509. // have more than 2 given arguments
  7510. _h[i]['h'].apply(ctx, args);
  7511. break;
  7512. }
  7513. if (_h[i]['one']) {
  7514. _h.splice(i, 1);
  7515. len--;
  7516. }
  7517. else {
  7518. i++;
  7519. }
  7520. }
  7521. }
  7522. return this;
  7523. }
  7524. };
  7525. // 对象可以通过 onxxxx 绑定事件
  7526. /**
  7527. * @event module:zrender/mixin/Eventful#onclick
  7528. * @type {Function}
  7529. * @default null
  7530. */
  7531. /**
  7532. * @event module:zrender/mixin/Eventful#onmouseover
  7533. * @type {Function}
  7534. * @default null
  7535. */
  7536. /**
  7537. * @event module:zrender/mixin/Eventful#onmouseout
  7538. * @type {Function}
  7539. * @default null
  7540. */
  7541. /**
  7542. * @event module:zrender/mixin/Eventful#onmousemove
  7543. * @type {Function}
  7544. * @default null
  7545. */
  7546. /**
  7547. * @event module:zrender/mixin/Eventful#onmousewheel
  7548. * @type {Function}
  7549. * @default null
  7550. */
  7551. /**
  7552. * @event module:zrender/mixin/Eventful#onmousedown
  7553. * @type {Function}
  7554. * @default null
  7555. */
  7556. /**
  7557. * @event module:zrender/mixin/Eventful#onmouseup
  7558. * @type {Function}
  7559. * @default null
  7560. */
  7561. /**
  7562. * @event module:zrender/mixin/Eventful#ondrag
  7563. * @type {Function}
  7564. * @default null
  7565. */
  7566. /**
  7567. * @event module:zrender/mixin/Eventful#ondragstart
  7568. * @type {Function}
  7569. * @default null
  7570. */
  7571. /**
  7572. * @event module:zrender/mixin/Eventful#ondragend
  7573. * @type {Function}
  7574. * @default null
  7575. */
  7576. /**
  7577. * @event module:zrender/mixin/Eventful#ondragenter
  7578. * @type {Function}
  7579. * @default null
  7580. */
  7581. /**
  7582. * @event module:zrender/mixin/Eventful#ondragleave
  7583. * @type {Function}
  7584. * @default null
  7585. */
  7586. /**
  7587. * @event module:zrender/mixin/Eventful#ondragover
  7588. * @type {Function}
  7589. * @default null
  7590. */
  7591. /**
  7592. * @event module:zrender/mixin/Eventful#ondrop
  7593. * @type {Function}
  7594. * @default null
  7595. */
  7596. module.exports = Eventful;
  7597. /***/ },
  7598. /* 34 */
  7599. /***/ function(module, exports, __webpack_require__) {
  7600. 'use strict';
  7601. /**
  7602. * 提供变换扩展
  7603. * @module zrender/mixin/Transformable
  7604. * @author pissang (https://www.github.com/pissang)
  7605. */
  7606. var matrix = __webpack_require__(11);
  7607. var vector = __webpack_require__(10);
  7608. var mIdentity = matrix.identity;
  7609. var EPSILON = 5e-5;
  7610. function isNotAroundZero(val) {
  7611. return val > EPSILON || val < -EPSILON;
  7612. }
  7613. /**
  7614. * @alias module:zrender/mixin/Transformable
  7615. * @constructor
  7616. */
  7617. var Transformable = function (opts) {
  7618. opts = opts || {};
  7619. // If there are no given position, rotation, scale
  7620. if (!opts.position) {
  7621. /**
  7622. * 平移
  7623. * @type {Array.<number>}
  7624. * @default [0, 0]
  7625. */
  7626. this.position = [0, 0];
  7627. }
  7628. if (opts.rotation == null) {
  7629. /**
  7630. * 旋转
  7631. * @type {Array.<number>}
  7632. * @default 0
  7633. */
  7634. this.rotation = 0;
  7635. }
  7636. if (!opts.scale) {
  7637. /**
  7638. * 缩放
  7639. * @type {Array.<number>}
  7640. * @default [1, 1]
  7641. */
  7642. this.scale = [1, 1];
  7643. }
  7644. /**
  7645. * 旋转和缩放的原点
  7646. * @type {Array.<number>}
  7647. * @default null
  7648. */
  7649. this.origin = this.origin || null;
  7650. };
  7651. var transformableProto = Transformable.prototype;
  7652. transformableProto.transform = null;
  7653. /**
  7654. * 判断是否需要有坐标变换
  7655. * 如果有坐标变换, 则从position, rotation, scale以及父节点的transform计算出自身的transform矩阵
  7656. */
  7657. transformableProto.needLocalTransform = function () {
  7658. return isNotAroundZero(this.rotation)
  7659. || isNotAroundZero(this.position[0])
  7660. || isNotAroundZero(this.position[1])
  7661. || isNotAroundZero(this.scale[0] - 1)
  7662. || isNotAroundZero(this.scale[1] - 1);
  7663. };
  7664. transformableProto.updateTransform = function () {
  7665. var parent = this.parent;
  7666. var parentHasTransform = parent && parent.transform;
  7667. var needLocalTransform = this.needLocalTransform();
  7668. var m = this.transform;
  7669. if (!(needLocalTransform || parentHasTransform)) {
  7670. m && mIdentity(m);
  7671. return;
  7672. }
  7673. m = m || matrix.create();
  7674. if (needLocalTransform) {
  7675. this.getLocalTransform(m);
  7676. }
  7677. else {
  7678. mIdentity(m);
  7679. }
  7680. // 应用父节点变换
  7681. if (parentHasTransform) {
  7682. if (needLocalTransform) {
  7683. matrix.mul(m, parent.transform, m);
  7684. }
  7685. else {
  7686. matrix.copy(m, parent.transform);
  7687. }
  7688. }
  7689. // 保存这个变换矩阵
  7690. this.transform = m;
  7691. this.invTransform = this.invTransform || matrix.create();
  7692. matrix.invert(this.invTransform, m);
  7693. };
  7694. transformableProto.getLocalTransform = function (m) {
  7695. m = m || [];
  7696. mIdentity(m);
  7697. var origin = this.origin;
  7698. var scale = this.scale;
  7699. var rotation = this.rotation;
  7700. var position = this.position;
  7701. if (origin) {
  7702. // Translate to origin
  7703. m[4] -= origin[0];
  7704. m[5] -= origin[1];
  7705. }
  7706. matrix.scale(m, m, scale);
  7707. if (rotation) {
  7708. matrix.rotate(m, m, rotation);
  7709. }
  7710. if (origin) {
  7711. // Translate back from origin
  7712. m[4] += origin[0];
  7713. m[5] += origin[1];
  7714. }
  7715. m[4] += position[0];
  7716. m[5] += position[1];
  7717. return m;
  7718. };
  7719. /**
  7720. * 将自己的transform应用到context上
  7721. * @param {Context2D} ctx
  7722. */
  7723. transformableProto.setTransform = function (ctx) {
  7724. var m = this.transform;
  7725. var dpr = ctx.dpr || 1;
  7726. if (m) {
  7727. ctx.setTransform(dpr * m[0], dpr * m[1], dpr * m[2], dpr * m[3], dpr * m[4], dpr * m[5]);
  7728. }
  7729. else {
  7730. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  7731. }
  7732. };
  7733. transformableProto.restoreTransform = function (ctx) {
  7734. var m = this.transform;
  7735. var dpr = ctx.dpr || 1;
  7736. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  7737. }
  7738. var tmpTransform = [];
  7739. /**
  7740. * 分解`transform`矩阵到`position`, `rotation`, `scale`
  7741. */
  7742. transformableProto.decomposeTransform = function () {
  7743. if (!this.transform) {
  7744. return;
  7745. }
  7746. var parent = this.parent;
  7747. var m = this.transform;
  7748. if (parent && parent.transform) {
  7749. // Get local transform and decompose them to position, scale, rotation
  7750. matrix.mul(tmpTransform, parent.invTransform, m);
  7751. m = tmpTransform;
  7752. }
  7753. var sx = m[0] * m[0] + m[1] * m[1];
  7754. var sy = m[2] * m[2] + m[3] * m[3];
  7755. var position = this.position;
  7756. var scale = this.scale;
  7757. if (isNotAroundZero(sx - 1)) {
  7758. sx = Math.sqrt(sx);
  7759. }
  7760. if (isNotAroundZero(sy - 1)) {
  7761. sy = Math.sqrt(sy);
  7762. }
  7763. if (m[0] < 0) {
  7764. sx = -sx;
  7765. }
  7766. if (m[3] < 0) {
  7767. sy = -sy;
  7768. }
  7769. position[0] = m[4];
  7770. position[1] = m[5];
  7771. scale[0] = sx;
  7772. scale[1] = sy;
  7773. this.rotation = Math.atan2(-m[1] / sy, m[0] / sx);
  7774. };
  7775. /**
  7776. * Get global scale
  7777. * @return {Array.<number>}
  7778. */
  7779. transformableProto.getGlobalScale = function () {
  7780. var m = this.transform;
  7781. if (!m) {
  7782. return [1, 1];
  7783. }
  7784. var sx = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
  7785. var sy = Math.sqrt(m[2] * m[2] + m[3] * m[3]);
  7786. if (m[0] < 0) {
  7787. sx = -sx;
  7788. }
  7789. if (m[3] < 0) {
  7790. sy = -sy;
  7791. }
  7792. return [sx, sy];
  7793. };
  7794. /**
  7795. * 变换坐标位置到 shape 的局部坐标空间
  7796. * @method
  7797. * @param {number} x
  7798. * @param {number} y
  7799. * @return {Array.<number>}
  7800. */
  7801. transformableProto.transformCoordToLocal = function (x, y) {
  7802. var v2 = [x, y];
  7803. var invTransform = this.invTransform;
  7804. if (invTransform) {
  7805. vector.applyTransform(v2, v2, invTransform);
  7806. }
  7807. return v2;
  7808. };
  7809. /**
  7810. * 变换局部坐标位置到全局坐标空间
  7811. * @method
  7812. * @param {number} x
  7813. * @param {number} y
  7814. * @return {Array.<number>}
  7815. */
  7816. transformableProto.transformCoordToGlobal = function (x, y) {
  7817. var v2 = [x, y];
  7818. var transform = this.transform;
  7819. if (transform) {
  7820. vector.applyTransform(v2, v2, transform);
  7821. }
  7822. return v2;
  7823. };
  7824. module.exports = Transformable;
  7825. /***/ },
  7826. /* 35 */
  7827. /***/ function(module, exports, __webpack_require__) {
  7828. 'use strict';
  7829. /**
  7830. * @module zrender/mixin/Animatable
  7831. */
  7832. var Animator = __webpack_require__(36);
  7833. var util = __webpack_require__(4);
  7834. var isString = util.isString;
  7835. var isFunction = util.isFunction;
  7836. var isObject = util.isObject;
  7837. var log = __webpack_require__(40);
  7838. /**
  7839. * @alias modue:zrender/mixin/Animatable
  7840. * @constructor
  7841. */
  7842. var Animatable = function () {
  7843. /**
  7844. * @type {Array.<module:zrender/animation/Animator>}
  7845. * @readOnly
  7846. */
  7847. this.animators = [];
  7848. };
  7849. Animatable.prototype = {
  7850. constructor: Animatable,
  7851. /**
  7852. * 动画
  7853. *
  7854. * @param {string} path 需要添加动画的属性获取路径,可以通过a.b.c来获取深层的属性
  7855. * @param {boolean} [loop] 动画是否循环
  7856. * @return {module:zrender/animation/Animator}
  7857. * @example:
  7858. * el.animate('style', false)
  7859. * .when(1000, {x: 10} )
  7860. * .done(function(){ // Animation done })
  7861. * .start()
  7862. */
  7863. animate: function (path, loop) {
  7864. var target;
  7865. var animatingShape = false;
  7866. var el = this;
  7867. var zr = this.__zr;
  7868. if (path) {
  7869. var pathSplitted = path.split('.');
  7870. var prop = el;
  7871. // If animating shape
  7872. animatingShape = pathSplitted[0] === 'shape';
  7873. for (var i = 0, l = pathSplitted.length; i < l; i++) {
  7874. if (!prop) {
  7875. continue;
  7876. }
  7877. prop = prop[pathSplitted[i]];
  7878. }
  7879. if (prop) {
  7880. target = prop;
  7881. }
  7882. }
  7883. else {
  7884. target = el;
  7885. }
  7886. if (!target) {
  7887. log(
  7888. 'Property "'
  7889. + path
  7890. + '" is not existed in element '
  7891. + el.id
  7892. );
  7893. return;
  7894. }
  7895. var animators = el.animators;
  7896. var animator = new Animator(target, loop);
  7897. animator.during(function (target) {
  7898. el.dirty(animatingShape);
  7899. })
  7900. .done(function () {
  7901. // FIXME Animator will not be removed if use `Animator#stop` to stop animation
  7902. animators.splice(util.indexOf(animators, animator), 1);
  7903. });
  7904. animators.push(animator);
  7905. // If animate after added to the zrender
  7906. if (zr) {
  7907. zr.animation.addAnimator(animator);
  7908. }
  7909. return animator;
  7910. },
  7911. /**
  7912. * 停止动画
  7913. * @param {boolean} forwardToLast If move to last frame before stop
  7914. */
  7915. stopAnimation: function (forwardToLast) {
  7916. var animators = this.animators;
  7917. var len = animators.length;
  7918. for (var i = 0; i < len; i++) {
  7919. animators[i].stop(forwardToLast);
  7920. }
  7921. animators.length = 0;
  7922. return this;
  7923. },
  7924. /**
  7925. * @param {Object} target
  7926. * @param {number} [time=500] Time in ms
  7927. * @param {string} [easing='linear']
  7928. * @param {number} [delay=0]
  7929. * @param {Function} [callback]
  7930. *
  7931. * @example
  7932. * // Animate position
  7933. * el.animateTo({
  7934. * position: [10, 10]
  7935. * }, function () { // done })
  7936. *
  7937. * // Animate shape, style and position in 100ms, delayed 100ms, with cubicOut easing
  7938. * el.animateTo({
  7939. * shape: {
  7940. * width: 500
  7941. * },
  7942. * style: {
  7943. * fill: 'red'
  7944. * }
  7945. * position: [10, 10]
  7946. * }, 100, 100, 'cubicOut', function () { // done })
  7947. */
  7948. // TODO Return animation key
  7949. animateTo: function (target, time, delay, easing, callback) {
  7950. // animateTo(target, time, easing, callback);
  7951. if (isString(delay)) {
  7952. callback = easing;
  7953. easing = delay;
  7954. delay = 0;
  7955. }
  7956. // animateTo(target, time, delay, callback);
  7957. else if (isFunction(easing)) {
  7958. callback = easing;
  7959. easing = 'linear';
  7960. delay = 0;
  7961. }
  7962. // animateTo(target, time, callback);
  7963. else if (isFunction(delay)) {
  7964. callback = delay;
  7965. delay = 0;
  7966. }
  7967. // animateTo(target, callback)
  7968. else if (isFunction(time)) {
  7969. callback = time;
  7970. time = 500;
  7971. }
  7972. // animateTo(target)
  7973. else if (!time) {
  7974. time = 500;
  7975. }
  7976. // Stop all previous animations
  7977. this.stopAnimation();
  7978. this._animateToShallow('', this, target, time, delay, easing, callback);
  7979. // Animators may be removed immediately after start
  7980. // if there is nothing to animate
  7981. var animators = this.animators.slice();
  7982. var count = animators.length;
  7983. function done() {
  7984. count--;
  7985. if (!count) {
  7986. callback && callback();
  7987. }
  7988. }
  7989. // No animators. This should be checked before animators[i].start(),
  7990. // because 'done' may be executed immediately if no need to animate.
  7991. if (!count) {
  7992. callback && callback();
  7993. }
  7994. // Start after all animators created
  7995. // Incase any animator is done immediately when all animation properties are not changed
  7996. for (var i = 0; i < animators.length; i++) {
  7997. animators[i]
  7998. .done(done)
  7999. .start(easing);
  8000. }
  8001. },
  8002. /**
  8003. * @private
  8004. * @param {string} path=''
  8005. * @param {Object} source=this
  8006. * @param {Object} target
  8007. * @param {number} [time=500]
  8008. * @param {number} [delay=0]
  8009. *
  8010. * @example
  8011. * // Animate position
  8012. * el._animateToShallow({
  8013. * position: [10, 10]
  8014. * })
  8015. *
  8016. * // Animate shape, style and position in 100ms, delayed 100ms
  8017. * el._animateToShallow({
  8018. * shape: {
  8019. * width: 500
  8020. * },
  8021. * style: {
  8022. * fill: 'red'
  8023. * }
  8024. * position: [10, 10]
  8025. * }, 100, 100)
  8026. */
  8027. _animateToShallow: function (path, source, target, time, delay) {
  8028. var objShallow = {};
  8029. var propertyCount = 0;
  8030. for (var name in target) {
  8031. if (!target.hasOwnProperty(name)) {
  8032. continue;
  8033. }
  8034. if (source[name] != null) {
  8035. if (isObject(target[name]) && !util.isArrayLike(target[name])) {
  8036. this._animateToShallow(
  8037. path ? path + '.' + name : name,
  8038. source[name],
  8039. target[name],
  8040. time,
  8041. delay
  8042. );
  8043. }
  8044. else {
  8045. objShallow[name] = target[name];
  8046. propertyCount++;
  8047. }
  8048. }
  8049. else if (target[name] != null) {
  8050. // Attr directly if not has property
  8051. // FIXME, if some property not needed for element ?
  8052. if (!path) {
  8053. this.attr(name, target[name]);
  8054. }
  8055. else { // Shape or style
  8056. var props = {};
  8057. props[path] = {};
  8058. props[path][name] = target[name];
  8059. this.attr(props);
  8060. }
  8061. }
  8062. }
  8063. if (propertyCount > 0) {
  8064. this.animate(path, false)
  8065. .when(time == null ? 500 : time, objShallow)
  8066. .delay(delay || 0);
  8067. }
  8068. return this;
  8069. }
  8070. };
  8071. module.exports = Animatable;
  8072. /***/ },
  8073. /* 36 */
  8074. /***/ function(module, exports, __webpack_require__) {
  8075. /**
  8076. * @module echarts/animation/Animator
  8077. */
  8078. var Clip = __webpack_require__(37);
  8079. var color = __webpack_require__(39);
  8080. var util = __webpack_require__(4);
  8081. var isArrayLike = util.isArrayLike;
  8082. var arraySlice = Array.prototype.slice;
  8083. function defaultGetter(target, key) {
  8084. return target[key];
  8085. }
  8086. function defaultSetter(target, key, value) {
  8087. target[key] = value;
  8088. }
  8089. /**
  8090. * @param {number} p0
  8091. * @param {number} p1
  8092. * @param {number} percent
  8093. * @return {number}
  8094. */
  8095. function interpolateNumber(p0, p1, percent) {
  8096. return (p1 - p0) * percent + p0;
  8097. }
  8098. /**
  8099. * @param {string} p0
  8100. * @param {string} p1
  8101. * @param {number} percent
  8102. * @return {string}
  8103. */
  8104. function interpolateString(p0, p1, percent) {
  8105. return percent > 0.5 ? p1 : p0;
  8106. }
  8107. /**
  8108. * @param {Array} p0
  8109. * @param {Array} p1
  8110. * @param {number} percent
  8111. * @param {Array} out
  8112. * @param {number} arrDim
  8113. */
  8114. function interpolateArray(p0, p1, percent, out, arrDim) {
  8115. var len = p0.length;
  8116. if (arrDim == 1) {
  8117. for (var i = 0; i < len; i++) {
  8118. out[i] = interpolateNumber(p0[i], p1[i], percent);
  8119. }
  8120. }
  8121. else {
  8122. var len2 = p0[0].length;
  8123. for (var i = 0; i < len; i++) {
  8124. for (var j = 0; j < len2; j++) {
  8125. out[i][j] = interpolateNumber(
  8126. p0[i][j], p1[i][j], percent
  8127. );
  8128. }
  8129. }
  8130. }
  8131. }
  8132. // arr0 is source array, arr1 is target array.
  8133. // Do some preprocess to avoid error happened when interpolating from arr0 to arr1
  8134. function fillArr(arr0, arr1, arrDim) {
  8135. var arr0Len = arr0.length;
  8136. var arr1Len = arr1.length;
  8137. if (arr0Len !== arr1Len) {
  8138. // FIXME Not work for TypedArray
  8139. var isPreviousLarger = arr0Len > arr1Len;
  8140. if (isPreviousLarger) {
  8141. // Cut the previous
  8142. arr0.length = arr1Len;
  8143. }
  8144. else {
  8145. // Fill the previous
  8146. for (var i = arr0Len; i < arr1Len; i++) {
  8147. arr0.push(
  8148. arrDim === 1 ? arr1[i] : arraySlice.call(arr1[i])
  8149. );
  8150. }
  8151. }
  8152. }
  8153. // Handling NaN value
  8154. var len2 = arr0[0] && arr0[0].length;
  8155. for (var i = 0; i < arr0.length; i++) {
  8156. if (arrDim === 1) {
  8157. if (isNaN(arr0[i])) {
  8158. arr0[i] = arr1[i];
  8159. }
  8160. }
  8161. else {
  8162. for (var j = 0; j < len2; j++) {
  8163. if (isNaN(arr0[i][j])) {
  8164. arr0[i][j] = arr1[i][j];
  8165. }
  8166. }
  8167. }
  8168. }
  8169. }
  8170. /**
  8171. * @param {Array} arr0
  8172. * @param {Array} arr1
  8173. * @param {number} arrDim
  8174. * @return {boolean}
  8175. */
  8176. function isArraySame(arr0, arr1, arrDim) {
  8177. if (arr0 === arr1) {
  8178. return true;
  8179. }
  8180. var len = arr0.length;
  8181. if (len !== arr1.length) {
  8182. return false;
  8183. }
  8184. if (arrDim === 1) {
  8185. for (var i = 0; i < len; i++) {
  8186. if (arr0[i] !== arr1[i]) {
  8187. return false;
  8188. }
  8189. }
  8190. }
  8191. else {
  8192. var len2 = arr0[0].length;
  8193. for (var i = 0; i < len; i++) {
  8194. for (var j = 0; j < len2; j++) {
  8195. if (arr0[i][j] !== arr1[i][j]) {
  8196. return false;
  8197. }
  8198. }
  8199. }
  8200. }
  8201. return true;
  8202. }
  8203. /**
  8204. * Catmull Rom interpolate array
  8205. * @param {Array} p0
  8206. * @param {Array} p1
  8207. * @param {Array} p2
  8208. * @param {Array} p3
  8209. * @param {number} t
  8210. * @param {number} t2
  8211. * @param {number} t3
  8212. * @param {Array} out
  8213. * @param {number} arrDim
  8214. */
  8215. function catmullRomInterpolateArray(
  8216. p0, p1, p2, p3, t, t2, t3, out, arrDim
  8217. ) {
  8218. var len = p0.length;
  8219. if (arrDim == 1) {
  8220. for (var i = 0; i < len; i++) {
  8221. out[i] = catmullRomInterpolate(
  8222. p0[i], p1[i], p2[i], p3[i], t, t2, t3
  8223. );
  8224. }
  8225. }
  8226. else {
  8227. var len2 = p0[0].length;
  8228. for (var i = 0; i < len; i++) {
  8229. for (var j = 0; j < len2; j++) {
  8230. out[i][j] = catmullRomInterpolate(
  8231. p0[i][j], p1[i][j], p2[i][j], p3[i][j],
  8232. t, t2, t3
  8233. );
  8234. }
  8235. }
  8236. }
  8237. }
  8238. /**
  8239. * Catmull Rom interpolate number
  8240. * @param {number} p0
  8241. * @param {number} p1
  8242. * @param {number} p2
  8243. * @param {number} p3
  8244. * @param {number} t
  8245. * @param {number} t2
  8246. * @param {number} t3
  8247. * @return {number}
  8248. */
  8249. function catmullRomInterpolate(p0, p1, p2, p3, t, t2, t3) {
  8250. var v0 = (p2 - p0) * 0.5;
  8251. var v1 = (p3 - p1) * 0.5;
  8252. return (2 * (p1 - p2) + v0 + v1) * t3
  8253. + (-3 * (p1 - p2) - 2 * v0 - v1) * t2
  8254. + v0 * t + p1;
  8255. }
  8256. function cloneValue(value) {
  8257. if (isArrayLike(value)) {
  8258. var len = value.length;
  8259. if (isArrayLike(value[0])) {
  8260. var ret = [];
  8261. for (var i = 0; i < len; i++) {
  8262. ret.push(arraySlice.call(value[i]));
  8263. }
  8264. return ret;
  8265. }
  8266. return arraySlice.call(value);
  8267. }
  8268. return value;
  8269. }
  8270. function rgba2String(rgba) {
  8271. rgba[0] = Math.floor(rgba[0]);
  8272. rgba[1] = Math.floor(rgba[1]);
  8273. rgba[2] = Math.floor(rgba[2]);
  8274. return 'rgba(' + rgba.join(',') + ')';
  8275. }
  8276. function createTrackClip (animator, easing, oneTrackDone, keyframes, propName) {
  8277. var getter = animator._getter;
  8278. var setter = animator._setter;
  8279. var useSpline = easing === 'spline';
  8280. var trackLen = keyframes.length;
  8281. if (!trackLen) {
  8282. return;
  8283. }
  8284. // Guess data type
  8285. var firstVal = keyframes[0].value;
  8286. var isValueArray = isArrayLike(firstVal);
  8287. var isValueColor = false;
  8288. var isValueString = false;
  8289. // For vertices morphing
  8290. var arrDim = (
  8291. isValueArray
  8292. && isArrayLike(firstVal[0])
  8293. )
  8294. ? 2 : 1;
  8295. var trackMaxTime;
  8296. // Sort keyframe as ascending
  8297. keyframes.sort(function(a, b) {
  8298. return a.time - b.time;
  8299. });
  8300. trackMaxTime = keyframes[trackLen - 1].time;
  8301. // Percents of each keyframe
  8302. var kfPercents = [];
  8303. // Value of each keyframe
  8304. var kfValues = [];
  8305. var prevValue = keyframes[0].value;
  8306. var isAllValueEqual = true;
  8307. for (var i = 0; i < trackLen; i++) {
  8308. kfPercents.push(keyframes[i].time / trackMaxTime);
  8309. // Assume value is a color when it is a string
  8310. var value = keyframes[i].value;
  8311. // Check if value is equal, deep check if value is array
  8312. if (!((isValueArray && isArraySame(value, prevValue, arrDim))
  8313. || (!isValueArray && value === prevValue))) {
  8314. isAllValueEqual = false;
  8315. }
  8316. prevValue = value;
  8317. // Try converting a string to a color array
  8318. if (typeof value == 'string') {
  8319. var colorArray = color.parse(value);
  8320. if (colorArray) {
  8321. value = colorArray;
  8322. isValueColor = true;
  8323. }
  8324. else {
  8325. isValueString = true;
  8326. }
  8327. }
  8328. kfValues.push(value);
  8329. }
  8330. if (isAllValueEqual) {
  8331. return;
  8332. }
  8333. var lastValue = kfValues[trackLen - 1];
  8334. // Polyfill array and NaN value
  8335. for (var i = 0; i < trackLen - 1; i++) {
  8336. if (isValueArray) {
  8337. fillArr(kfValues[i], lastValue, arrDim);
  8338. }
  8339. else {
  8340. if (isNaN(kfValues[i]) && !isNaN(lastValue) && !isValueString && !isValueColor) {
  8341. kfValues[i] = lastValue;
  8342. }
  8343. }
  8344. }
  8345. isValueArray && fillArr(getter(animator._target, propName), lastValue, arrDim);
  8346. // Cache the key of last frame to speed up when
  8347. // animation playback is sequency
  8348. var lastFrame = 0;
  8349. var lastFramePercent = 0;
  8350. var start;
  8351. var w;
  8352. var p0;
  8353. var p1;
  8354. var p2;
  8355. var p3;
  8356. if (isValueColor) {
  8357. var rgba = [0, 0, 0, 0];
  8358. }
  8359. var onframe = function (target, percent) {
  8360. // Find the range keyframes
  8361. // kf1-----kf2---------current--------kf3
  8362. // find kf2 and kf3 and do interpolation
  8363. var frame;
  8364. // In the easing function like elasticOut, percent may less than 0
  8365. if (percent < 0) {
  8366. frame = 0;
  8367. }
  8368. else if (percent < lastFramePercent) {
  8369. // Start from next key
  8370. // PENDING start from lastFrame ?
  8371. start = Math.min(lastFrame + 1, trackLen - 1);
  8372. for (frame = start; frame >= 0; frame--) {
  8373. if (kfPercents[frame] <= percent) {
  8374. break;
  8375. }
  8376. }
  8377. // PENDING really need to do this ?
  8378. frame = Math.min(frame, trackLen - 2);
  8379. }
  8380. else {
  8381. for (frame = lastFrame; frame < trackLen; frame++) {
  8382. if (kfPercents[frame] > percent) {
  8383. break;
  8384. }
  8385. }
  8386. frame = Math.min(frame - 1, trackLen - 2);
  8387. }
  8388. lastFrame = frame;
  8389. lastFramePercent = percent;
  8390. var range = (kfPercents[frame + 1] - kfPercents[frame]);
  8391. if (range === 0) {
  8392. return;
  8393. }
  8394. else {
  8395. w = (percent - kfPercents[frame]) / range;
  8396. }
  8397. if (useSpline) {
  8398. p1 = kfValues[frame];
  8399. p0 = kfValues[frame === 0 ? frame : frame - 1];
  8400. p2 = kfValues[frame > trackLen - 2 ? trackLen - 1 : frame + 1];
  8401. p3 = kfValues[frame > trackLen - 3 ? trackLen - 1 : frame + 2];
  8402. if (isValueArray) {
  8403. catmullRomInterpolateArray(
  8404. p0, p1, p2, p3, w, w * w, w * w * w,
  8405. getter(target, propName),
  8406. arrDim
  8407. );
  8408. }
  8409. else {
  8410. var value;
  8411. if (isValueColor) {
  8412. value = catmullRomInterpolateArray(
  8413. p0, p1, p2, p3, w, w * w, w * w * w,
  8414. rgba, 1
  8415. );
  8416. value = rgba2String(rgba);
  8417. }
  8418. else if (isValueString) {
  8419. // String is step(0.5)
  8420. return interpolateString(p1, p2, w);
  8421. }
  8422. else {
  8423. value = catmullRomInterpolate(
  8424. p0, p1, p2, p3, w, w * w, w * w * w
  8425. );
  8426. }
  8427. setter(
  8428. target,
  8429. propName,
  8430. value
  8431. );
  8432. }
  8433. }
  8434. else {
  8435. if (isValueArray) {
  8436. interpolateArray(
  8437. kfValues[frame], kfValues[frame + 1], w,
  8438. getter(target, propName),
  8439. arrDim
  8440. );
  8441. }
  8442. else {
  8443. var value;
  8444. if (isValueColor) {
  8445. interpolateArray(
  8446. kfValues[frame], kfValues[frame + 1], w,
  8447. rgba, 1
  8448. );
  8449. value = rgba2String(rgba);
  8450. }
  8451. else if (isValueString) {
  8452. // String is step(0.5)
  8453. return interpolateString(kfValues[frame], kfValues[frame + 1], w);
  8454. }
  8455. else {
  8456. value = interpolateNumber(kfValues[frame], kfValues[frame + 1], w);
  8457. }
  8458. setter(
  8459. target,
  8460. propName,
  8461. value
  8462. );
  8463. }
  8464. }
  8465. };
  8466. var clip = new Clip({
  8467. target: animator._target,
  8468. life: trackMaxTime,
  8469. loop: animator._loop,
  8470. delay: animator._delay,
  8471. onframe: onframe,
  8472. ondestroy: oneTrackDone
  8473. });
  8474. if (easing && easing !== 'spline') {
  8475. clip.easing = easing;
  8476. }
  8477. return clip;
  8478. }
  8479. /**
  8480. * @alias module:zrender/animation/Animator
  8481. * @constructor
  8482. * @param {Object} target
  8483. * @param {boolean} loop
  8484. * @param {Function} getter
  8485. * @param {Function} setter
  8486. */
  8487. var Animator = function(target, loop, getter, setter) {
  8488. this._tracks = {};
  8489. this._target = target;
  8490. this._loop = loop || false;
  8491. this._getter = getter || defaultGetter;
  8492. this._setter = setter || defaultSetter;
  8493. this._clipCount = 0;
  8494. this._delay = 0;
  8495. this._doneList = [];
  8496. this._onframeList = [];
  8497. this._clipList = [];
  8498. };
  8499. Animator.prototype = {
  8500. /**
  8501. * 设置动画关键帧
  8502. * @param {number} time 关键帧时间,单位是ms
  8503. * @param {Object} props 关键帧的属性值,key-value表示
  8504. * @return {module:zrender/animation/Animator}
  8505. */
  8506. when: function(time /* ms */, props) {
  8507. var tracks = this._tracks;
  8508. for (var propName in props) {
  8509. if (!props.hasOwnProperty(propName)) {
  8510. continue;
  8511. }
  8512. if (!tracks[propName]) {
  8513. tracks[propName] = [];
  8514. // Invalid value
  8515. var value = this._getter(this._target, propName);
  8516. if (value == null) {
  8517. // zrLog('Invalid property ' + propName);
  8518. continue;
  8519. }
  8520. // If time is 0
  8521. // Then props is given initialize value
  8522. // Else
  8523. // Initialize value from current prop value
  8524. if (time !== 0) {
  8525. tracks[propName].push({
  8526. time: 0,
  8527. value: cloneValue(value)
  8528. });
  8529. }
  8530. }
  8531. tracks[propName].push({
  8532. time: time,
  8533. value: props[propName]
  8534. });
  8535. }
  8536. return this;
  8537. },
  8538. /**
  8539. * 添加动画每一帧的回调函数
  8540. * @param {Function} callback
  8541. * @return {module:zrender/animation/Animator}
  8542. */
  8543. during: function (callback) {
  8544. this._onframeList.push(callback);
  8545. return this;
  8546. },
  8547. _doneCallback: function () {
  8548. // Clear all tracks
  8549. this._tracks = {};
  8550. // Clear all clips
  8551. this._clipList.length = 0;
  8552. var doneList = this._doneList;
  8553. var len = doneList.length;
  8554. for (var i = 0; i < len; i++) {
  8555. doneList[i].call(this);
  8556. }
  8557. },
  8558. /**
  8559. * 开始执行动画
  8560. * @param {string|Function} easing
  8561. * 动画缓动函数,详见{@link module:zrender/animation/easing}
  8562. * @return {module:zrender/animation/Animator}
  8563. */
  8564. start: function (easing) {
  8565. var self = this;
  8566. var clipCount = 0;
  8567. var oneTrackDone = function() {
  8568. clipCount--;
  8569. if (!clipCount) {
  8570. self._doneCallback();
  8571. }
  8572. };
  8573. var lastClip;
  8574. for (var propName in this._tracks) {
  8575. if (!this._tracks.hasOwnProperty(propName)) {
  8576. continue;
  8577. }
  8578. var clip = createTrackClip(
  8579. this, easing, oneTrackDone,
  8580. this._tracks[propName], propName
  8581. );
  8582. if (clip) {
  8583. this._clipList.push(clip);
  8584. clipCount++;
  8585. // If start after added to animation
  8586. if (this.animation) {
  8587. this.animation.addClip(clip);
  8588. }
  8589. lastClip = clip;
  8590. }
  8591. }
  8592. // Add during callback on the last clip
  8593. if (lastClip) {
  8594. var oldOnFrame = lastClip.onframe;
  8595. lastClip.onframe = function (target, percent) {
  8596. oldOnFrame(target, percent);
  8597. for (var i = 0; i < self._onframeList.length; i++) {
  8598. self._onframeList[i](target, percent);
  8599. }
  8600. };
  8601. }
  8602. if (!clipCount) {
  8603. this._doneCallback();
  8604. }
  8605. return this;
  8606. },
  8607. /**
  8608. * 停止动画
  8609. * @param {boolean} forwardToLast If move to last frame before stop
  8610. */
  8611. stop: function (forwardToLast) {
  8612. var clipList = this._clipList;
  8613. var animation = this.animation;
  8614. for (var i = 0; i < clipList.length; i++) {
  8615. var clip = clipList[i];
  8616. if (forwardToLast) {
  8617. // Move to last frame before stop
  8618. clip.onframe(this._target, 1);
  8619. }
  8620. animation && animation.removeClip(clip);
  8621. }
  8622. clipList.length = 0;
  8623. },
  8624. /**
  8625. * 设置动画延迟开始的时间
  8626. * @param {number} time 单位ms
  8627. * @return {module:zrender/animation/Animator}
  8628. */
  8629. delay: function (time) {
  8630. this._delay = time;
  8631. return this;
  8632. },
  8633. /**
  8634. * 添加动画结束的回调
  8635. * @param {Function} cb
  8636. * @return {module:zrender/animation/Animator}
  8637. */
  8638. done: function(cb) {
  8639. if (cb) {
  8640. this._doneList.push(cb);
  8641. }
  8642. return this;
  8643. },
  8644. /**
  8645. * @return {Array.<module:zrender/animation/Clip>}
  8646. */
  8647. getClips: function () {
  8648. return this._clipList;
  8649. }
  8650. };
  8651. module.exports = Animator;
  8652. /***/ },
  8653. /* 37 */
  8654. /***/ function(module, exports, __webpack_require__) {
  8655. /**
  8656. * 动画主控制器
  8657. * @config target 动画对象,可以是数组,如果是数组的话会批量分发onframe等事件
  8658. * @config life(1000) 动画时长
  8659. * @config delay(0) 动画延迟时间
  8660. * @config loop(true)
  8661. * @config gap(0) 循环的间隔时间
  8662. * @config onframe
  8663. * @config easing(optional)
  8664. * @config ondestroy(optional)
  8665. * @config onrestart(optional)
  8666. *
  8667. * TODO pause
  8668. */
  8669. var easingFuncs = __webpack_require__(38);
  8670. function Clip(options) {
  8671. this._target = options.target;
  8672. // 生命周期
  8673. this._life = options.life || 1000;
  8674. // 延时
  8675. this._delay = options.delay || 0;
  8676. // 开始时间
  8677. // this._startTime = new Date().getTime() + this._delay;// 单位毫秒
  8678. this._initialized = false;
  8679. // 是否循环
  8680. this.loop = options.loop == null ? false : options.loop;
  8681. this.gap = options.gap || 0;
  8682. this.easing = options.easing || 'Linear';
  8683. this.onframe = options.onframe;
  8684. this.ondestroy = options.ondestroy;
  8685. this.onrestart = options.onrestart;
  8686. }
  8687. Clip.prototype = {
  8688. constructor: Clip,
  8689. step: function (globalTime) {
  8690. // Set startTime on first step, or _startTime may has milleseconds different between clips
  8691. // PENDING
  8692. if (!this._initialized) {
  8693. this._startTime = globalTime + this._delay;
  8694. this._initialized = true;
  8695. }
  8696. var percent = (globalTime - this._startTime) / this._life;
  8697. // 还没开始
  8698. if (percent < 0) {
  8699. return;
  8700. }
  8701. percent = Math.min(percent, 1);
  8702. var easing = this.easing;
  8703. var easingFunc = typeof easing == 'string' ? easingFuncs[easing] : easing;
  8704. var schedule = typeof easingFunc === 'function'
  8705. ? easingFunc(percent)
  8706. : percent;
  8707. this.fire('frame', schedule);
  8708. // 结束
  8709. if (percent == 1) {
  8710. if (this.loop) {
  8711. this.restart (globalTime);
  8712. // 重新开始周期
  8713. // 抛出而不是直接调用事件直到 stage.update 后再统一调用这些事件
  8714. return 'restart';
  8715. }
  8716. // 动画完成将这个控制器标识为待删除
  8717. // 在Animation.update中进行批量删除
  8718. this._needsRemove = true;
  8719. return 'destroy';
  8720. }
  8721. return null;
  8722. },
  8723. restart: function (globalTime) {
  8724. var remainder = (globalTime - this._startTime) % this._life;
  8725. this._startTime = globalTime - remainder + this.gap;
  8726. this._needsRemove = false;
  8727. },
  8728. fire: function(eventType, arg) {
  8729. eventType = 'on' + eventType;
  8730. if (this[eventType]) {
  8731. this[eventType](this._target, arg);
  8732. }
  8733. }
  8734. };
  8735. module.exports = Clip;
  8736. /***/ },
  8737. /* 38 */
  8738. /***/ function(module, exports) {
  8739. /**
  8740. * 缓动代码来自 https://github.com/sole/tween.js/blob/master/src/Tween.js
  8741. * @see http://sole.github.io/tween.js/examples/03_graphs.html
  8742. * @exports zrender/animation/easing
  8743. */
  8744. var easing = {
  8745. /**
  8746. * @param {number} k
  8747. * @return {number}
  8748. */
  8749. linear: function (k) {
  8750. return k;
  8751. },
  8752. /**
  8753. * @param {number} k
  8754. * @return {number}
  8755. */
  8756. quadraticIn: function (k) {
  8757. return k * k;
  8758. },
  8759. /**
  8760. * @param {number} k
  8761. * @return {number}
  8762. */
  8763. quadraticOut: function (k) {
  8764. return k * (2 - k);
  8765. },
  8766. /**
  8767. * @param {number} k
  8768. * @return {number}
  8769. */
  8770. quadraticInOut: function (k) {
  8771. if ((k *= 2) < 1) {
  8772. return 0.5 * k * k;
  8773. }
  8774. return -0.5 * (--k * (k - 2) - 1);
  8775. },
  8776. // 三次方的缓动(t^3)
  8777. /**
  8778. * @param {number} k
  8779. * @return {number}
  8780. */
  8781. cubicIn: function (k) {
  8782. return k * k * k;
  8783. },
  8784. /**
  8785. * @param {number} k
  8786. * @return {number}
  8787. */
  8788. cubicOut: function (k) {
  8789. return --k * k * k + 1;
  8790. },
  8791. /**
  8792. * @param {number} k
  8793. * @return {number}
  8794. */
  8795. cubicInOut: function (k) {
  8796. if ((k *= 2) < 1) {
  8797. return 0.5 * k * k * k;
  8798. }
  8799. return 0.5 * ((k -= 2) * k * k + 2);
  8800. },
  8801. // 四次方的缓动(t^4)
  8802. /**
  8803. * @param {number} k
  8804. * @return {number}
  8805. */
  8806. quarticIn: function (k) {
  8807. return k * k * k * k;
  8808. },
  8809. /**
  8810. * @param {number} k
  8811. * @return {number}
  8812. */
  8813. quarticOut: function (k) {
  8814. return 1 - (--k * k * k * k);
  8815. },
  8816. /**
  8817. * @param {number} k
  8818. * @return {number}
  8819. */
  8820. quarticInOut: function (k) {
  8821. if ((k *= 2) < 1) {
  8822. return 0.5 * k * k * k * k;
  8823. }
  8824. return -0.5 * ((k -= 2) * k * k * k - 2);
  8825. },
  8826. // 五次方的缓动(t^5)
  8827. /**
  8828. * @param {number} k
  8829. * @return {number}
  8830. */
  8831. quinticIn: function (k) {
  8832. return k * k * k * k * k;
  8833. },
  8834. /**
  8835. * @param {number} k
  8836. * @return {number}
  8837. */
  8838. quinticOut: function (k) {
  8839. return --k * k * k * k * k + 1;
  8840. },
  8841. /**
  8842. * @param {number} k
  8843. * @return {number}
  8844. */
  8845. quinticInOut: function (k) {
  8846. if ((k *= 2) < 1) {
  8847. return 0.5 * k * k * k * k * k;
  8848. }
  8849. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  8850. },
  8851. // 正弦曲线的缓动(sin(t))
  8852. /**
  8853. * @param {number} k
  8854. * @return {number}
  8855. */
  8856. sinusoidalIn: function (k) {
  8857. return 1 - Math.cos(k * Math.PI / 2);
  8858. },
  8859. /**
  8860. * @param {number} k
  8861. * @return {number}
  8862. */
  8863. sinusoidalOut: function (k) {
  8864. return Math.sin(k * Math.PI / 2);
  8865. },
  8866. /**
  8867. * @param {number} k
  8868. * @return {number}
  8869. */
  8870. sinusoidalInOut: function (k) {
  8871. return 0.5 * (1 - Math.cos(Math.PI * k));
  8872. },
  8873. // 指数曲线的缓动(2^t)
  8874. /**
  8875. * @param {number} k
  8876. * @return {number}
  8877. */
  8878. exponentialIn: function (k) {
  8879. return k === 0 ? 0 : Math.pow(1024, k - 1);
  8880. },
  8881. /**
  8882. * @param {number} k
  8883. * @return {number}
  8884. */
  8885. exponentialOut: function (k) {
  8886. return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
  8887. },
  8888. /**
  8889. * @param {number} k
  8890. * @return {number}
  8891. */
  8892. exponentialInOut: function (k) {
  8893. if (k === 0) {
  8894. return 0;
  8895. }
  8896. if (k === 1) {
  8897. return 1;
  8898. }
  8899. if ((k *= 2) < 1) {
  8900. return 0.5 * Math.pow(1024, k - 1);
  8901. }
  8902. return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
  8903. },
  8904. // 圆形曲线的缓动(sqrt(1-t^2))
  8905. /**
  8906. * @param {number} k
  8907. * @return {number}
  8908. */
  8909. circularIn: function (k) {
  8910. return 1 - Math.sqrt(1 - k * k);
  8911. },
  8912. /**
  8913. * @param {number} k
  8914. * @return {number}
  8915. */
  8916. circularOut: function (k) {
  8917. return Math.sqrt(1 - (--k * k));
  8918. },
  8919. /**
  8920. * @param {number} k
  8921. * @return {number}
  8922. */
  8923. circularInOut: function (k) {
  8924. if ((k *= 2) < 1) {
  8925. return -0.5 * (Math.sqrt(1 - k * k) - 1);
  8926. }
  8927. return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
  8928. },
  8929. // 创建类似于弹簧在停止前来回振荡的动画
  8930. /**
  8931. * @param {number} k
  8932. * @return {number}
  8933. */
  8934. elasticIn: function (k) {
  8935. var s;
  8936. var a = 0.1;
  8937. var p = 0.4;
  8938. if (k === 0) {
  8939. return 0;
  8940. }
  8941. if (k === 1) {
  8942. return 1;
  8943. }
  8944. if (!a || a < 1) {
  8945. a = 1; s = p / 4;
  8946. }
  8947. else {
  8948. s = p * Math.asin(1 / a) / (2 * Math.PI);
  8949. }
  8950. return -(a * Math.pow(2, 10 * (k -= 1)) *
  8951. Math.sin((k - s) * (2 * Math.PI) / p));
  8952. },
  8953. /**
  8954. * @param {number} k
  8955. * @return {number}
  8956. */
  8957. elasticOut: function (k) {
  8958. var s;
  8959. var a = 0.1;
  8960. var p = 0.4;
  8961. if (k === 0) {
  8962. return 0;
  8963. }
  8964. if (k === 1) {
  8965. return 1;
  8966. }
  8967. if (!a || a < 1) {
  8968. a = 1; s = p / 4;
  8969. }
  8970. else {
  8971. s = p * Math.asin(1 / a) / (2 * Math.PI);
  8972. }
  8973. return (a * Math.pow(2, -10 * k) *
  8974. Math.sin((k - s) * (2 * Math.PI) / p) + 1);
  8975. },
  8976. /**
  8977. * @param {number} k
  8978. * @return {number}
  8979. */
  8980. elasticInOut: function (k) {
  8981. var s;
  8982. var a = 0.1;
  8983. var p = 0.4;
  8984. if (k === 0) {
  8985. return 0;
  8986. }
  8987. if (k === 1) {
  8988. return 1;
  8989. }
  8990. if (!a || a < 1) {
  8991. a = 1; s = p / 4;
  8992. }
  8993. else {
  8994. s = p * Math.asin(1 / a) / (2 * Math.PI);
  8995. }
  8996. if ((k *= 2) < 1) {
  8997. return -0.5 * (a * Math.pow(2, 10 * (k -= 1))
  8998. * Math.sin((k - s) * (2 * Math.PI) / p));
  8999. }
  9000. return a * Math.pow(2, -10 * (k -= 1))
  9001. * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
  9002. },
  9003. // 在某一动画开始沿指示的路径进行动画处理前稍稍收回该动画的移动
  9004. /**
  9005. * @param {number} k
  9006. * @return {number}
  9007. */
  9008. backIn: function (k) {
  9009. var s = 1.70158;
  9010. return k * k * ((s + 1) * k - s);
  9011. },
  9012. /**
  9013. * @param {number} k
  9014. * @return {number}
  9015. */
  9016. backOut: function (k) {
  9017. var s = 1.70158;
  9018. return --k * k * ((s + 1) * k + s) + 1;
  9019. },
  9020. /**
  9021. * @param {number} k
  9022. * @return {number}
  9023. */
  9024. backInOut: function (k) {
  9025. var s = 1.70158 * 1.525;
  9026. if ((k *= 2) < 1) {
  9027. return 0.5 * (k * k * ((s + 1) * k - s));
  9028. }
  9029. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  9030. },
  9031. // 创建弹跳效果
  9032. /**
  9033. * @param {number} k
  9034. * @return {number}
  9035. */
  9036. bounceIn: function (k) {
  9037. return 1 - easing.bounceOut(1 - k);
  9038. },
  9039. /**
  9040. * @param {number} k
  9041. * @return {number}
  9042. */
  9043. bounceOut: function (k) {
  9044. if (k < (1 / 2.75)) {
  9045. return 7.5625 * k * k;
  9046. }
  9047. else if (k < (2 / 2.75)) {
  9048. return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;
  9049. }
  9050. else if (k < (2.5 / 2.75)) {
  9051. return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;
  9052. }
  9053. else {
  9054. return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;
  9055. }
  9056. },
  9057. /**
  9058. * @param {number} k
  9059. * @return {number}
  9060. */
  9061. bounceInOut: function (k) {
  9062. if (k < 0.5) {
  9063. return easing.bounceIn(k * 2) * 0.5;
  9064. }
  9065. return easing.bounceOut(k * 2 - 1) * 0.5 + 0.5;
  9066. }
  9067. };
  9068. module.exports = easing;
  9069. /***/ },
  9070. /* 39 */
  9071. /***/ function(module, exports) {
  9072. /**
  9073. * @module zrender/tool/color
  9074. */
  9075. var kCSSColorTable = {
  9076. 'transparent': [0,0,0,0], 'aliceblue': [240,248,255,1],
  9077. 'antiquewhite': [250,235,215,1], 'aqua': [0,255,255,1],
  9078. 'aquamarine': [127,255,212,1], 'azure': [240,255,255,1],
  9079. 'beige': [245,245,220,1], 'bisque': [255,228,196,1],
  9080. 'black': [0,0,0,1], 'blanchedalmond': [255,235,205,1],
  9081. 'blue': [0,0,255,1], 'blueviolet': [138,43,226,1],
  9082. 'brown': [165,42,42,1], 'burlywood': [222,184,135,1],
  9083. 'cadetblue': [95,158,160,1], 'chartreuse': [127,255,0,1],
  9084. 'chocolate': [210,105,30,1], 'coral': [255,127,80,1],
  9085. 'cornflowerblue': [100,149,237,1], 'cornsilk': [255,248,220,1],
  9086. 'crimson': [220,20,60,1], 'cyan': [0,255,255,1],
  9087. 'darkblue': [0,0,139,1], 'darkcyan': [0,139,139,1],
  9088. 'darkgoldenrod': [184,134,11,1], 'darkgray': [169,169,169,1],
  9089. 'darkgreen': [0,100,0,1], 'darkgrey': [169,169,169,1],
  9090. 'darkkhaki': [189,183,107,1], 'darkmagenta': [139,0,139,1],
  9091. 'darkolivegreen': [85,107,47,1], 'darkorange': [255,140,0,1],
  9092. 'darkorchid': [153,50,204,1], 'darkred': [139,0,0,1],
  9093. 'darksalmon': [233,150,122,1], 'darkseagreen': [143,188,143,1],
  9094. 'darkslateblue': [72,61,139,1], 'darkslategray': [47,79,79,1],
  9095. 'darkslategrey': [47,79,79,1], 'darkturquoise': [0,206,209,1],
  9096. 'darkviolet': [148,0,211,1], 'deeppink': [255,20,147,1],
  9097. 'deepskyblue': [0,191,255,1], 'dimgray': [105,105,105,1],
  9098. 'dimgrey': [105,105,105,1], 'dodgerblue': [30,144,255,1],
  9099. 'firebrick': [178,34,34,1], 'floralwhite': [255,250,240,1],
  9100. 'forestgreen': [34,139,34,1], 'fuchsia': [255,0,255,1],
  9101. 'gainsboro': [220,220,220,1], 'ghostwhite': [248,248,255,1],
  9102. 'gold': [255,215,0,1], 'goldenrod': [218,165,32,1],
  9103. 'gray': [128,128,128,1], 'green': [0,128,0,1],
  9104. 'greenyellow': [173,255,47,1], 'grey': [128,128,128,1],
  9105. 'honeydew': [240,255,240,1], 'hotpink': [255,105,180,1],
  9106. 'indianred': [205,92,92,1], 'indigo': [75,0,130,1],
  9107. 'ivory': [255,255,240,1], 'khaki': [240,230,140,1],
  9108. 'lavender': [230,230,250,1], 'lavenderblush': [255,240,245,1],
  9109. 'lawngreen': [124,252,0,1], 'lemonchiffon': [255,250,205,1],
  9110. 'lightblue': [173,216,230,1], 'lightcoral': [240,128,128,1],
  9111. 'lightcyan': [224,255,255,1], 'lightgoldenrodyellow': [250,250,210,1],
  9112. 'lightgray': [211,211,211,1], 'lightgreen': [144,238,144,1],
  9113. 'lightgrey': [211,211,211,1], 'lightpink': [255,182,193,1],
  9114. 'lightsalmon': [255,160,122,1], 'lightseagreen': [32,178,170,1],
  9115. 'lightskyblue': [135,206,250,1], 'lightslategray': [119,136,153,1],
  9116. 'lightslategrey': [119,136,153,1], 'lightsteelblue': [176,196,222,1],
  9117. 'lightyellow': [255,255,224,1], 'lime': [0,255,0,1],
  9118. 'limegreen': [50,205,50,1], 'linen': [250,240,230,1],
  9119. 'magenta': [255,0,255,1], 'maroon': [128,0,0,1],
  9120. 'mediumaquamarine': [102,205,170,1], 'mediumblue': [0,0,205,1],
  9121. 'mediumorchid': [186,85,211,1], 'mediumpurple': [147,112,219,1],
  9122. 'mediumseagreen': [60,179,113,1], 'mediumslateblue': [123,104,238,1],
  9123. 'mediumspringgreen': [0,250,154,1], 'mediumturquoise': [72,209,204,1],
  9124. 'mediumvioletred': [199,21,133,1], 'midnightblue': [25,25,112,1],
  9125. 'mintcream': [245,255,250,1], 'mistyrose': [255,228,225,1],
  9126. 'moccasin': [255,228,181,1], 'navajowhite': [255,222,173,1],
  9127. 'navy': [0,0,128,1], 'oldlace': [253,245,230,1],
  9128. 'olive': [128,128,0,1], 'olivedrab': [107,142,35,1],
  9129. 'orange': [255,165,0,1], 'orangered': [255,69,0,1],
  9130. 'orchid': [218,112,214,1], 'palegoldenrod': [238,232,170,1],
  9131. 'palegreen': [152,251,152,1], 'paleturquoise': [175,238,238,1],
  9132. 'palevioletred': [219,112,147,1], 'papayawhip': [255,239,213,1],
  9133. 'peachpuff': [255,218,185,1], 'peru': [205,133,63,1],
  9134. 'pink': [255,192,203,1], 'plum': [221,160,221,1],
  9135. 'powderblue': [176,224,230,1], 'purple': [128,0,128,1],
  9136. 'red': [255,0,0,1], 'rosybrown': [188,143,143,1],
  9137. 'royalblue': [65,105,225,1], 'saddlebrown': [139,69,19,1],
  9138. 'salmon': [250,128,114,1], 'sandybrown': [244,164,96,1],
  9139. 'seagreen': [46,139,87,1], 'seashell': [255,245,238,1],
  9140. 'sienna': [160,82,45,1], 'silver': [192,192,192,1],
  9141. 'skyblue': [135,206,235,1], 'slateblue': [106,90,205,1],
  9142. 'slategray': [112,128,144,1], 'slategrey': [112,128,144,1],
  9143. 'snow': [255,250,250,1], 'springgreen': [0,255,127,1],
  9144. 'steelblue': [70,130,180,1], 'tan': [210,180,140,1],
  9145. 'teal': [0,128,128,1], 'thistle': [216,191,216,1],
  9146. 'tomato': [255,99,71,1], 'turquoise': [64,224,208,1],
  9147. 'violet': [238,130,238,1], 'wheat': [245,222,179,1],
  9148. 'white': [255,255,255,1], 'whitesmoke': [245,245,245,1],
  9149. 'yellow': [255,255,0,1], 'yellowgreen': [154,205,50,1]
  9150. };
  9151. function clampCssByte(i) { // Clamp to integer 0 .. 255.
  9152. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  9153. return i < 0 ? 0 : i > 255 ? 255 : i;
  9154. }
  9155. function clampCssAngle(i) { // Clamp to integer 0 .. 360.
  9156. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  9157. return i < 0 ? 0 : i > 360 ? 360 : i;
  9158. }
  9159. function clampCssFloat(f) { // Clamp to float 0.0 .. 1.0.
  9160. return f < 0 ? 0 : f > 1 ? 1 : f;
  9161. }
  9162. function parseCssInt(str) { // int or percentage.
  9163. if (str.length && str.charAt(str.length - 1) === '%') {
  9164. return clampCssByte(parseFloat(str) / 100 * 255);
  9165. }
  9166. return clampCssByte(parseInt(str, 10));
  9167. }
  9168. function parseCssFloat(str) { // float or percentage.
  9169. if (str.length && str.charAt(str.length - 1) === '%') {
  9170. return clampCssFloat(parseFloat(str) / 100);
  9171. }
  9172. return clampCssFloat(parseFloat(str));
  9173. }
  9174. function cssHueToRgb(m1, m2, h) {
  9175. if (h < 0) {
  9176. h += 1;
  9177. }
  9178. else if (h > 1) {
  9179. h -= 1;
  9180. }
  9181. if (h * 6 < 1) {
  9182. return m1 + (m2 - m1) * h * 6;
  9183. }
  9184. if (h * 2 < 1) {
  9185. return m2;
  9186. }
  9187. if (h * 3 < 2) {
  9188. return m1 + (m2 - m1) * (2/3 - h) * 6;
  9189. }
  9190. return m1;
  9191. }
  9192. function lerp(a, b, p) {
  9193. return a + (b - a) * p;
  9194. }
  9195. /**
  9196. * @param {string} colorStr
  9197. * @return {Array.<number>}
  9198. * @memberOf module:zrender/util/color
  9199. */
  9200. function parse(colorStr) {
  9201. if (!colorStr) {
  9202. return;
  9203. }
  9204. // colorStr may be not string
  9205. colorStr = colorStr + '';
  9206. // Remove all whitespace, not compliant, but should just be more accepting.
  9207. var str = colorStr.replace(/ /g, '').toLowerCase();
  9208. // Color keywords (and transparent) lookup.
  9209. if (str in kCSSColorTable) {
  9210. return kCSSColorTable[str].slice(); // dup.
  9211. }
  9212. // #abc and #abc123 syntax.
  9213. if (str.charAt(0) === '#') {
  9214. if (str.length === 4) {
  9215. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  9216. if (!(iv >= 0 && iv <= 0xfff)) {
  9217. return; // Covers NaN.
  9218. }
  9219. return [
  9220. ((iv & 0xf00) >> 4) | ((iv & 0xf00) >> 8),
  9221. (iv & 0xf0) | ((iv & 0xf0) >> 4),
  9222. (iv & 0xf) | ((iv & 0xf) << 4),
  9223. 1
  9224. ];
  9225. }
  9226. else if (str.length === 7) {
  9227. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  9228. if (!(iv >= 0 && iv <= 0xffffff)) {
  9229. return; // Covers NaN.
  9230. }
  9231. return [
  9232. (iv & 0xff0000) >> 16,
  9233. (iv & 0xff00) >> 8,
  9234. iv & 0xff,
  9235. 1
  9236. ];
  9237. }
  9238. return;
  9239. }
  9240. var op = str.indexOf('('), ep = str.indexOf(')');
  9241. if (op !== -1 && ep + 1 === str.length) {
  9242. var fname = str.substr(0, op);
  9243. var params = str.substr(op + 1, ep - (op + 1)).split(',');
  9244. var alpha = 1; // To allow case fallthrough.
  9245. switch (fname) {
  9246. case 'rgba':
  9247. if (params.length !== 4) {
  9248. return;
  9249. }
  9250. alpha = parseCssFloat(params.pop()); // jshint ignore:line
  9251. // Fall through.
  9252. case 'rgb':
  9253. if (params.length !== 3) {
  9254. return;
  9255. }
  9256. return [
  9257. parseCssInt(params[0]),
  9258. parseCssInt(params[1]),
  9259. parseCssInt(params[2]),
  9260. alpha
  9261. ];
  9262. case 'hsla':
  9263. if (params.length !== 4) {
  9264. return;
  9265. }
  9266. params[3] = parseCssFloat(params[3]);
  9267. return hsla2rgba(params);
  9268. case 'hsl':
  9269. if (params.length !== 3) {
  9270. return;
  9271. }
  9272. return hsla2rgba(params);
  9273. default:
  9274. return;
  9275. }
  9276. }
  9277. return;
  9278. }
  9279. /**
  9280. * @param {Array.<number>} hsla
  9281. * @return {Array.<number>} rgba
  9282. */
  9283. function hsla2rgba(hsla) {
  9284. var h = (((parseFloat(hsla[0]) % 360) + 360) % 360) / 360; // 0 .. 1
  9285. // NOTE(deanm): According to the CSS spec s/l should only be
  9286. // percentages, but we don't bother and let float or percentage.
  9287. var s = parseCssFloat(hsla[1]);
  9288. var l = parseCssFloat(hsla[2]);
  9289. var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  9290. var m1 = l * 2 - m2;
  9291. var rgba = [
  9292. clampCssByte(cssHueToRgb(m1, m2, h + 1 / 3) * 255),
  9293. clampCssByte(cssHueToRgb(m1, m2, h) * 255),
  9294. clampCssByte(cssHueToRgb(m1, m2, h - 1 / 3) * 255)
  9295. ];
  9296. if (hsla.length === 4) {
  9297. rgba[3] = hsla[3];
  9298. }
  9299. return rgba;
  9300. }
  9301. /**
  9302. * @param {Array.<number>} rgba
  9303. * @return {Array.<number>} hsla
  9304. */
  9305. function rgba2hsla(rgba) {
  9306. if (!rgba) {
  9307. return;
  9308. }
  9309. // RGB from 0 to 255
  9310. var R = rgba[0] / 255;
  9311. var G = rgba[1] / 255;
  9312. var B = rgba[2] / 255;
  9313. var vMin = Math.min(R, G, B); // Min. value of RGB
  9314. var vMax = Math.max(R, G, B); // Max. value of RGB
  9315. var delta = vMax - vMin; // Delta RGB value
  9316. var L = (vMax + vMin) / 2;
  9317. var H;
  9318. var S;
  9319. // HSL results from 0 to 1
  9320. if (delta === 0) {
  9321. H = 0;
  9322. S = 0;
  9323. }
  9324. else {
  9325. if (L < 0.5) {
  9326. S = delta / (vMax + vMin);
  9327. }
  9328. else {
  9329. S = delta / (2 - vMax - vMin);
  9330. }
  9331. var deltaR = (((vMax - R) / 6) + (delta / 2)) / delta;
  9332. var deltaG = (((vMax - G) / 6) + (delta / 2)) / delta;
  9333. var deltaB = (((vMax - B) / 6) + (delta / 2)) / delta;
  9334. if (R === vMax) {
  9335. H = deltaB - deltaG;
  9336. }
  9337. else if (G === vMax) {
  9338. H = (1 / 3) + deltaR - deltaB;
  9339. }
  9340. else if (B === vMax) {
  9341. H = (2 / 3) + deltaG - deltaR;
  9342. }
  9343. if (H < 0) {
  9344. H += 1;
  9345. }
  9346. if (H > 1) {
  9347. H -= 1;
  9348. }
  9349. }
  9350. var hsla = [H * 360, S, L];
  9351. if (rgba[3] != null) {
  9352. hsla.push(rgba[3]);
  9353. }
  9354. return hsla;
  9355. }
  9356. /**
  9357. * @param {string} color
  9358. * @param {number} level
  9359. * @return {string}
  9360. * @memberOf module:zrender/util/color
  9361. */
  9362. function lift(color, level) {
  9363. var colorArr = parse(color);
  9364. if (colorArr) {
  9365. for (var i = 0; i < 3; i++) {
  9366. if (level < 0) {
  9367. colorArr[i] = colorArr[i] * (1 - level) | 0;
  9368. }
  9369. else {
  9370. colorArr[i] = ((255 - colorArr[i]) * level + colorArr[i]) | 0;
  9371. }
  9372. }
  9373. return stringify(colorArr, colorArr.length === 4 ? 'rgba' : 'rgb');
  9374. }
  9375. }
  9376. /**
  9377. * @param {string} color
  9378. * @return {string}
  9379. * @memberOf module:zrender/util/color
  9380. */
  9381. function toHex(color, level) {
  9382. var colorArr = parse(color);
  9383. if (colorArr) {
  9384. return ((1 << 24) + (colorArr[0] << 16) + (colorArr[1] << 8) + (+colorArr[2])).toString(16).slice(1);
  9385. }
  9386. }
  9387. /**
  9388. * Map value to color. Faster than mapToColor methods because color is represented by rgba array
  9389. * @param {number} normalizedValue A float between 0 and 1.
  9390. * @param {Array.<Array.<number>>} colors List of rgba color array
  9391. * @param {Array.<number>} [out] Mapped gba color array
  9392. * @return {Array.<number>}
  9393. */
  9394. function fastMapToColor(normalizedValue, colors, out) {
  9395. if (!(colors && colors.length)
  9396. || !(normalizedValue >= 0 && normalizedValue <= 1)
  9397. ) {
  9398. return;
  9399. }
  9400. out = out || [0, 0, 0, 0];
  9401. var value = normalizedValue * (colors.length - 1);
  9402. var leftIndex = Math.floor(value);
  9403. var rightIndex = Math.ceil(value);
  9404. var leftColor = colors[leftIndex];
  9405. var rightColor = colors[rightIndex];
  9406. var dv = value - leftIndex;
  9407. out[0] = clampCssByte(lerp(leftColor[0], rightColor[0], dv));
  9408. out[1] = clampCssByte(lerp(leftColor[1], rightColor[1], dv));
  9409. out[2] = clampCssByte(lerp(leftColor[2], rightColor[2], dv));
  9410. out[3] = clampCssByte(lerp(leftColor[3], rightColor[3], dv));
  9411. return out;
  9412. }
  9413. /**
  9414. * @param {number} normalizedValue A float between 0 and 1.
  9415. * @param {Array.<string>} colors Color list.
  9416. * @param {boolean=} fullOutput Default false.
  9417. * @return {(string|Object)} Result color. If fullOutput,
  9418. * return {color: ..., leftIndex: ..., rightIndex: ..., value: ...},
  9419. * @memberOf module:zrender/util/color
  9420. */
  9421. function mapToColor(normalizedValue, colors, fullOutput) {
  9422. if (!(colors && colors.length)
  9423. || !(normalizedValue >= 0 && normalizedValue <= 1)
  9424. ) {
  9425. return;
  9426. }
  9427. var value = normalizedValue * (colors.length - 1);
  9428. var leftIndex = Math.floor(value);
  9429. var rightIndex = Math.ceil(value);
  9430. var leftColor = parse(colors[leftIndex]);
  9431. var rightColor = parse(colors[rightIndex]);
  9432. var dv = value - leftIndex;
  9433. var color = stringify(
  9434. [
  9435. clampCssByte(lerp(leftColor[0], rightColor[0], dv)),
  9436. clampCssByte(lerp(leftColor[1], rightColor[1], dv)),
  9437. clampCssByte(lerp(leftColor[2], rightColor[2], dv)),
  9438. clampCssFloat(lerp(leftColor[3], rightColor[3], dv))
  9439. ],
  9440. 'rgba'
  9441. );
  9442. return fullOutput
  9443. ? {
  9444. color: color,
  9445. leftIndex: leftIndex,
  9446. rightIndex: rightIndex,
  9447. value: value
  9448. }
  9449. : color;
  9450. }
  9451. /**
  9452. * @param {string} color
  9453. * @param {number=} h 0 ~ 360, ignore when null.
  9454. * @param {number=} s 0 ~ 1, ignore when null.
  9455. * @param {number=} l 0 ~ 1, ignore when null.
  9456. * @return {string} Color string in rgba format.
  9457. * @memberOf module:zrender/util/color
  9458. */
  9459. function modifyHSL(color, h, s, l) {
  9460. color = parse(color);
  9461. if (color) {
  9462. color = rgba2hsla(color);
  9463. h != null && (color[0] = clampCssAngle(h));
  9464. s != null && (color[1] = parseCssFloat(s));
  9465. l != null && (color[2] = parseCssFloat(l));
  9466. return stringify(hsla2rgba(color), 'rgba');
  9467. }
  9468. }
  9469. /**
  9470. * @param {string} color
  9471. * @param {number=} alpha 0 ~ 1
  9472. * @return {string} Color string in rgba format.
  9473. * @memberOf module:zrender/util/color
  9474. */
  9475. function modifyAlpha(color, alpha) {
  9476. color = parse(color);
  9477. if (color && alpha != null) {
  9478. color[3] = clampCssFloat(alpha);
  9479. return stringify(color, 'rgba');
  9480. }
  9481. }
  9482. /**
  9483. * @param {Array.<string>} colors Color list.
  9484. * @param {string} type 'rgba', 'hsva', ...
  9485. * @return {string} Result color.
  9486. */
  9487. function stringify(arrColor, type) {
  9488. var colorStr = arrColor[0] + ',' + arrColor[1] + ',' + arrColor[2];
  9489. if (type === 'rgba' || type === 'hsva' || type === 'hsla') {
  9490. colorStr += ',' + arrColor[3];
  9491. }
  9492. return type + '(' + colorStr + ')';
  9493. }
  9494. module.exports = {
  9495. parse: parse,
  9496. lift: lift,
  9497. toHex: toHex,
  9498. fastMapToColor: fastMapToColor,
  9499. mapToColor: mapToColor,
  9500. modifyHSL: modifyHSL,
  9501. modifyAlpha: modifyAlpha,
  9502. stringify: stringify
  9503. };
  9504. /***/ },
  9505. /* 40 */
  9506. /***/ function(module, exports, __webpack_require__) {
  9507. var config = __webpack_require__(41);
  9508. /**
  9509. * @exports zrender/tool/log
  9510. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  9511. */
  9512. module.exports = function() {
  9513. if (config.debugMode === 0) {
  9514. return;
  9515. }
  9516. else if (config.debugMode == 1) {
  9517. for (var k in arguments) {
  9518. throw new Error(arguments[k]);
  9519. }
  9520. }
  9521. else if (config.debugMode > 1) {
  9522. for (var k in arguments) {
  9523. console.log(arguments[k]);
  9524. }
  9525. }
  9526. };
  9527. /* for debug
  9528. return function(mes) {
  9529. document.getElementById('wrong-message').innerHTML =
  9530. mes + ' ' + (new Date() - 0)
  9531. + '<br/>'
  9532. + document.getElementById('wrong-message').innerHTML;
  9533. };
  9534. */
  9535. /***/ },
  9536. /* 41 */
  9537. /***/ function(module, exports) {
  9538. var dpr = 1;
  9539. // If in browser environment
  9540. if (typeof window !== 'undefined') {
  9541. dpr = Math.max(window.devicePixelRatio || 1, 1);
  9542. }
  9543. /**
  9544. * config默认配置项
  9545. * @exports zrender/config
  9546. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  9547. */
  9548. var config = {
  9549. /**
  9550. * debug日志选项:catchBrushException为true下有效
  9551. * 0 : 不生成debug数据,发布用
  9552. * 1 : 异常抛出,调试用
  9553. * 2 : 控制台输出,调试用
  9554. */
  9555. debugMode: 0,
  9556. // retina 屏幕优化
  9557. devicePixelRatio: dpr
  9558. };
  9559. module.exports = config;
  9560. /***/ },
  9561. /* 42 */
  9562. /***/ function(module, exports, __webpack_require__) {
  9563. var Group = __webpack_require__(30);
  9564. var componentUtil = __webpack_require__(20);
  9565. var clazzUtil = __webpack_require__(13);
  9566. var modelUtil = __webpack_require__(5);
  9567. var zrUtil = __webpack_require__(4);
  9568. function Chart() {
  9569. /**
  9570. * @type {module:zrender/container/Group}
  9571. * @readOnly
  9572. */
  9573. this.group = new Group();
  9574. /**
  9575. * @type {string}
  9576. * @readOnly
  9577. */
  9578. this.uid = componentUtil.getUID('viewChart');
  9579. }
  9580. Chart.prototype = {
  9581. type: 'chart',
  9582. /**
  9583. * Init the chart
  9584. * @param {module:echarts/model/Global} ecModel
  9585. * @param {module:echarts/ExtensionAPI} api
  9586. */
  9587. init: function (ecModel, api) {},
  9588. /**
  9589. * Render the chart
  9590. * @param {module:echarts/model/Series} seriesModel
  9591. * @param {module:echarts/model/Global} ecModel
  9592. * @param {module:echarts/ExtensionAPI} api
  9593. * @param {Object} payload
  9594. */
  9595. render: function (seriesModel, ecModel, api, payload) {},
  9596. /**
  9597. * Highlight series or specified data item
  9598. * @param {module:echarts/model/Series} seriesModel
  9599. * @param {module:echarts/model/Global} ecModel
  9600. * @param {module:echarts/ExtensionAPI} api
  9601. * @param {Object} payload
  9602. */
  9603. highlight: function (seriesModel, ecModel, api, payload) {
  9604. toggleHighlight(seriesModel.getData(), payload, 'emphasis');
  9605. },
  9606. /**
  9607. * Downplay series or specified data item
  9608. * @param {module:echarts/model/Series} seriesModel
  9609. * @param {module:echarts/model/Global} ecModel
  9610. * @param {module:echarts/ExtensionAPI} api
  9611. * @param {Object} payload
  9612. */
  9613. downplay: function (seriesModel, ecModel, api, payload) {
  9614. toggleHighlight(seriesModel.getData(), payload, 'normal');
  9615. },
  9616. /**
  9617. * Remove self
  9618. * @param {module:echarts/model/Global} ecModel
  9619. * @param {module:echarts/ExtensionAPI} api
  9620. */
  9621. remove: function (ecModel, api) {
  9622. this.group.removeAll();
  9623. },
  9624. /**
  9625. * Dispose self
  9626. * @param {module:echarts/model/Global} ecModel
  9627. * @param {module:echarts/ExtensionAPI} api
  9628. */
  9629. dispose: function () {}
  9630. /**
  9631. * The view contains the given point.
  9632. * @interface
  9633. * @param {Array.<number>} point
  9634. * @return {boolean}
  9635. */
  9636. // containPoint: function () {}
  9637. };
  9638. var chartProto = Chart.prototype;
  9639. chartProto.updateView
  9640. = chartProto.updateLayout
  9641. = chartProto.updateVisual
  9642. = function (seriesModel, ecModel, api, payload) {
  9643. this.render(seriesModel, ecModel, api, payload);
  9644. };
  9645. /**
  9646. * Set state of single element
  9647. * @param {module:zrender/Element} el
  9648. * @param {string} state
  9649. */
  9650. function elSetState(el, state) {
  9651. if (el) {
  9652. el.trigger(state);
  9653. if (el.type === 'group') {
  9654. for (var i = 0; i < el.childCount(); i++) {
  9655. elSetState(el.childAt(i), state);
  9656. }
  9657. }
  9658. }
  9659. }
  9660. /**
  9661. * @param {module:echarts/data/List} data
  9662. * @param {Object} payload
  9663. * @param {string} state 'normal'|'emphasis'
  9664. * @inner
  9665. */
  9666. function toggleHighlight(data, payload, state) {
  9667. var dataIndex = modelUtil.queryDataIndex(data, payload);
  9668. if (dataIndex != null) {
  9669. zrUtil.each(modelUtil.normalizeToArray(dataIndex), function (dataIdx) {
  9670. elSetState(data.getItemGraphicEl(dataIdx), state);
  9671. });
  9672. }
  9673. else {
  9674. data.eachItemGraphicEl(function (el) {
  9675. elSetState(el, state);
  9676. });
  9677. }
  9678. }
  9679. // Enable Chart.extend.
  9680. clazzUtil.enableClassExtend(Chart, ['dispose']);
  9681. // Add capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  9682. clazzUtil.enableClassManagement(Chart, {registerWhenExtend: true});
  9683. module.exports = Chart;
  9684. /***/ },
  9685. /* 43 */
  9686. /***/ function(module, exports, __webpack_require__) {
  9687. 'use strict';
  9688. var zrUtil = __webpack_require__(4);
  9689. var pathTool = __webpack_require__(44);
  9690. var round = Math.round;
  9691. var Path = __webpack_require__(45);
  9692. var colorTool = __webpack_require__(39);
  9693. var matrix = __webpack_require__(11);
  9694. var vector = __webpack_require__(10);
  9695. var graphic = {};
  9696. graphic.Group = __webpack_require__(30);
  9697. graphic.Image = __webpack_require__(61);
  9698. graphic.Text = __webpack_require__(63);
  9699. graphic.Circle = __webpack_require__(64);
  9700. graphic.Sector = __webpack_require__(65);
  9701. graphic.Ring = __webpack_require__(66);
  9702. graphic.Polygon = __webpack_require__(67);
  9703. graphic.Polyline = __webpack_require__(71);
  9704. graphic.Rect = __webpack_require__(72);
  9705. graphic.Line = __webpack_require__(74);
  9706. graphic.BezierCurve = __webpack_require__(75);
  9707. graphic.Arc = __webpack_require__(76);
  9708. graphic.CompoundPath = __webpack_require__(77);
  9709. graphic.LinearGradient = __webpack_require__(78);
  9710. graphic.RadialGradient = __webpack_require__(80);
  9711. graphic.BoundingRect = __webpack_require__(9);
  9712. /**
  9713. * Extend shape with parameters
  9714. */
  9715. graphic.extendShape = function (opts) {
  9716. return Path.extend(opts);
  9717. };
  9718. /**
  9719. * Extend path
  9720. */
  9721. graphic.extendPath = function (pathData, opts) {
  9722. return pathTool.extendFromString(pathData, opts);
  9723. };
  9724. /**
  9725. * Create a path element from path data string
  9726. * @param {string} pathData
  9727. * @param {Object} opts
  9728. * @param {module:zrender/core/BoundingRect} rect
  9729. * @param {string} [layout=cover] 'center' or 'cover'
  9730. */
  9731. graphic.makePath = function (pathData, opts, rect, layout) {
  9732. var path = pathTool.createFromString(pathData, opts);
  9733. var boundingRect = path.getBoundingRect();
  9734. if (rect) {
  9735. var aspect = boundingRect.width / boundingRect.height;
  9736. if (layout === 'center') {
  9737. // Set rect to center, keep width / height ratio.
  9738. var width = rect.height * aspect;
  9739. var height;
  9740. if (width <= rect.width) {
  9741. height = rect.height;
  9742. }
  9743. else {
  9744. width = rect.width;
  9745. height = width / aspect;
  9746. }
  9747. var cx = rect.x + rect.width / 2;
  9748. var cy = rect.y + rect.height / 2;
  9749. rect.x = cx - width / 2;
  9750. rect.y = cy - height / 2;
  9751. rect.width = width;
  9752. rect.height = height;
  9753. }
  9754. graphic.resizePath(path, rect);
  9755. }
  9756. return path;
  9757. };
  9758. graphic.mergePath = pathTool.mergePath,
  9759. /**
  9760. * Resize a path to fit the rect
  9761. * @param {module:zrender/graphic/Path} path
  9762. * @param {Object} rect
  9763. */
  9764. graphic.resizePath = function (path, rect) {
  9765. if (!path.applyTransform) {
  9766. return;
  9767. }
  9768. var pathRect = path.getBoundingRect();
  9769. var m = pathRect.calculateTransform(rect);
  9770. path.applyTransform(m);
  9771. };
  9772. /**
  9773. * Sub pixel optimize line for canvas
  9774. *
  9775. * @param {Object} param
  9776. * @param {Object} [param.shape]
  9777. * @param {number} [param.shape.x1]
  9778. * @param {number} [param.shape.y1]
  9779. * @param {number} [param.shape.x2]
  9780. * @param {number} [param.shape.y2]
  9781. * @param {Object} [param.style]
  9782. * @param {number} [param.style.lineWidth]
  9783. * @return {Object} Modified param
  9784. */
  9785. graphic.subPixelOptimizeLine = function (param) {
  9786. var subPixelOptimize = graphic.subPixelOptimize;
  9787. var shape = param.shape;
  9788. var lineWidth = param.style.lineWidth;
  9789. if (round(shape.x1 * 2) === round(shape.x2 * 2)) {
  9790. shape.x1 = shape.x2 = subPixelOptimize(shape.x1, lineWidth, true);
  9791. }
  9792. if (round(shape.y1 * 2) === round(shape.y2 * 2)) {
  9793. shape.y1 = shape.y2 = subPixelOptimize(shape.y1, lineWidth, true);
  9794. }
  9795. return param;
  9796. };
  9797. /**
  9798. * Sub pixel optimize rect for canvas
  9799. *
  9800. * @param {Object} param
  9801. * @param {Object} [param.shape]
  9802. * @param {number} [param.shape.x]
  9803. * @param {number} [param.shape.y]
  9804. * @param {number} [param.shape.width]
  9805. * @param {number} [param.shape.height]
  9806. * @param {Object} [param.style]
  9807. * @param {number} [param.style.lineWidth]
  9808. * @return {Object} Modified param
  9809. */
  9810. graphic.subPixelOptimizeRect = function (param) {
  9811. var subPixelOptimize = graphic.subPixelOptimize;
  9812. var shape = param.shape;
  9813. var lineWidth = param.style.lineWidth;
  9814. var originX = shape.x;
  9815. var originY = shape.y;
  9816. var originWidth = shape.width;
  9817. var originHeight = shape.height;
  9818. shape.x = subPixelOptimize(shape.x, lineWidth, true);
  9819. shape.y = subPixelOptimize(shape.y, lineWidth, true);
  9820. shape.width = Math.max(
  9821. subPixelOptimize(originX + originWidth, lineWidth, false) - shape.x,
  9822. originWidth === 0 ? 0 : 1
  9823. );
  9824. shape.height = Math.max(
  9825. subPixelOptimize(originY + originHeight, lineWidth, false) - shape.y,
  9826. originHeight === 0 ? 0 : 1
  9827. );
  9828. return param;
  9829. };
  9830. /**
  9831. * Sub pixel optimize for canvas
  9832. *
  9833. * @param {number} position Coordinate, such as x, y
  9834. * @param {number} lineWidth Should be nonnegative integer.
  9835. * @param {boolean=} positiveOrNegative Default false (negative).
  9836. * @return {number} Optimized position.
  9837. */
  9838. graphic.subPixelOptimize = function (position, lineWidth, positiveOrNegative) {
  9839. // Assure that (position + lineWidth / 2) is near integer edge,
  9840. // otherwise line will be fuzzy in canvas.
  9841. var doubledPosition = round(position * 2);
  9842. return (doubledPosition + round(lineWidth)) % 2 === 0
  9843. ? doubledPosition / 2
  9844. : (doubledPosition + (positiveOrNegative ? 1 : -1)) / 2;
  9845. };
  9846. function hasFillOrStroke(fillOrStroke) {
  9847. return fillOrStroke != null && fillOrStroke != 'none';
  9848. }
  9849. function liftColor(color) {
  9850. return typeof color === 'string' ? colorTool.lift(color, -0.1) : color;
  9851. }
  9852. /**
  9853. * @private
  9854. */
  9855. function cacheElementStl(el) {
  9856. if (el.__hoverStlDirty) {
  9857. var stroke = el.style.stroke;
  9858. var fill = el.style.fill;
  9859. // Create hoverStyle on mouseover
  9860. var hoverStyle = el.__hoverStl;
  9861. hoverStyle.fill = hoverStyle.fill
  9862. || (hasFillOrStroke(fill) ? liftColor(fill) : null);
  9863. hoverStyle.stroke = hoverStyle.stroke
  9864. || (hasFillOrStroke(stroke) ? liftColor(stroke) : null);
  9865. var normalStyle = {};
  9866. for (var name in hoverStyle) {
  9867. if (hoverStyle.hasOwnProperty(name)) {
  9868. normalStyle[name] = el.style[name];
  9869. }
  9870. }
  9871. el.__normalStl = normalStyle;
  9872. el.__hoverStlDirty = false;
  9873. }
  9874. }
  9875. /**
  9876. * @private
  9877. */
  9878. function doSingleEnterHover(el) {
  9879. if (el.__isHover) {
  9880. return;
  9881. }
  9882. cacheElementStl(el);
  9883. if (el.useHoverLayer) {
  9884. el.__zr && el.__zr.addHover(el, el.__hoverStl);
  9885. }
  9886. else {
  9887. el.setStyle(el.__hoverStl);
  9888. el.z2 += 1;
  9889. }
  9890. el.__isHover = true;
  9891. }
  9892. /**
  9893. * @inner
  9894. */
  9895. function doSingleLeaveHover(el) {
  9896. if (!el.__isHover) {
  9897. return;
  9898. }
  9899. var normalStl = el.__normalStl;
  9900. if (el.useHoverLayer) {
  9901. el.__zr && el.__zr.removeHover(el);
  9902. }
  9903. else {
  9904. normalStl && el.setStyle(normalStl);
  9905. el.z2 -= 1;
  9906. }
  9907. el.__isHover = false;
  9908. }
  9909. /**
  9910. * @inner
  9911. */
  9912. function doEnterHover(el) {
  9913. el.type === 'group'
  9914. ? el.traverse(function (child) {
  9915. if (child.type !== 'group') {
  9916. doSingleEnterHover(child);
  9917. }
  9918. })
  9919. : doSingleEnterHover(el);
  9920. }
  9921. function doLeaveHover(el) {
  9922. el.type === 'group'
  9923. ? el.traverse(function (child) {
  9924. if (child.type !== 'group') {
  9925. doSingleLeaveHover(child);
  9926. }
  9927. })
  9928. : doSingleLeaveHover(el);
  9929. }
  9930. /**
  9931. * @inner
  9932. */
  9933. function setElementHoverStl(el, hoverStl) {
  9934. // If element has sepcified hoverStyle, then use it instead of given hoverStyle
  9935. // Often used when item group has a label element and it's hoverStyle is different
  9936. el.__hoverStl = el.hoverStyle || hoverStl || {};
  9937. el.__hoverStlDirty = true;
  9938. if (el.__isHover) {
  9939. cacheElementStl(el);
  9940. }
  9941. }
  9942. /**
  9943. * @inner
  9944. */
  9945. function onElementMouseOver(e) {
  9946. if (this.__hoverSilentOnTouch && e.zrByTouch) {
  9947. return;
  9948. }
  9949. // Only if element is not in emphasis status
  9950. !this.__isEmphasis && doEnterHover(this);
  9951. }
  9952. /**
  9953. * @inner
  9954. */
  9955. function onElementMouseOut(e) {
  9956. if (this.__hoverSilentOnTouch && e.zrByTouch) {
  9957. return;
  9958. }
  9959. // Only if element is not in emphasis status
  9960. !this.__isEmphasis && doLeaveHover(this);
  9961. }
  9962. /**
  9963. * @inner
  9964. */
  9965. function enterEmphasis() {
  9966. this.__isEmphasis = true;
  9967. doEnterHover(this);
  9968. }
  9969. /**
  9970. * @inner
  9971. */
  9972. function leaveEmphasis() {
  9973. this.__isEmphasis = false;
  9974. doLeaveHover(this);
  9975. }
  9976. /**
  9977. * Set hover style of element
  9978. * @param {module:zrender/Element} el
  9979. * @param {Object} [hoverStyle]
  9980. * @param {Object} [opt]
  9981. * @param {boolean} [opt.hoverSilentOnTouch=false]
  9982. * In touch device, mouseover event will be trigger on touchstart event
  9983. * (see module:zrender/dom/HandlerProxy). By this mechanism, we can
  9984. * conviniently use hoverStyle when tap on touch screen without additional
  9985. * code for compatibility.
  9986. * But if the chart/component has select feature, which usually also use
  9987. * hoverStyle, there might be conflict between 'select-highlight' and
  9988. * 'hover-highlight' especially when roam is enabled (see geo for example).
  9989. * In this case, hoverSilentOnTouch should be used to disable hover-highlight
  9990. * on touch device.
  9991. */
  9992. graphic.setHoverStyle = function (el, hoverStyle, opt) {
  9993. el.__hoverSilentOnTouch = opt && opt.hoverSilentOnTouch;
  9994. el.type === 'group'
  9995. ? el.traverse(function (child) {
  9996. if (child.type !== 'group') {
  9997. setElementHoverStl(child, hoverStyle);
  9998. }
  9999. })
  10000. : setElementHoverStl(el, hoverStyle);
  10001. // Duplicated function will be auto-ignored, see Eventful.js.
  10002. el.on('mouseover', onElementMouseOver)
  10003. .on('mouseout', onElementMouseOut);
  10004. // Emphasis, normal can be triggered manually
  10005. el.on('emphasis', enterEmphasis)
  10006. .on('normal', leaveEmphasis);
  10007. };
  10008. /**
  10009. * Set text option in the style
  10010. * @param {Object} textStyle
  10011. * @param {module:echarts/model/Model} labelModel
  10012. * @param {string} color
  10013. */
  10014. graphic.setText = function (textStyle, labelModel, color) {
  10015. var labelPosition = labelModel.getShallow('position') || 'inside';
  10016. var labelOffset = labelModel.getShallow('offset');
  10017. var labelColor = labelPosition.indexOf('inside') >= 0 ? 'white' : color;
  10018. var textStyleModel = labelModel.getModel('textStyle');
  10019. zrUtil.extend(textStyle, {
  10020. textDistance: labelModel.getShallow('distance') || 5,
  10021. textFont: textStyleModel.getFont(),
  10022. textPosition: labelPosition,
  10023. textOffset: labelOffset,
  10024. textFill: textStyleModel.getTextColor() || labelColor
  10025. });
  10026. };
  10027. function animateOrSetProps(isUpdate, el, props, animatableModel, dataIndex, cb) {
  10028. if (typeof dataIndex === 'function') {
  10029. cb = dataIndex;
  10030. dataIndex = null;
  10031. }
  10032. // Do not check 'animation' property directly here. Consider this case:
  10033. // animation model is an `itemModel`, whose does not have `isAnimationEnabled`
  10034. // but its parent model (`seriesModel`) does.
  10035. var animationEnabled = animatableModel && animatableModel.isAnimationEnabled();
  10036. if (animationEnabled) {
  10037. var postfix = isUpdate ? 'Update' : '';
  10038. var duration = animatableModel.getShallow('animationDuration' + postfix);
  10039. var animationEasing = animatableModel.getShallow('animationEasing' + postfix);
  10040. var animationDelay = animatableModel.getShallow('animationDelay' + postfix);
  10041. if (typeof animationDelay === 'function') {
  10042. animationDelay = animationDelay(
  10043. dataIndex,
  10044. animatableModel.getAnimationDelayParams
  10045. ? animatableModel.getAnimationDelayParams(el, dataIndex)
  10046. : null
  10047. );
  10048. }
  10049. if (typeof duration === 'function') {
  10050. duration = duration(dataIndex);
  10051. }
  10052. duration > 0
  10053. ? el.animateTo(props, duration, animationDelay || 0, animationEasing, cb)
  10054. : (el.attr(props), cb && cb());
  10055. }
  10056. else {
  10057. el.attr(props);
  10058. cb && cb();
  10059. }
  10060. }
  10061. /**
  10062. * Update graphic element properties with or without animation according to the configuration in series
  10063. * @param {module:zrender/Element} el
  10064. * @param {Object} props
  10065. * @param {module:echarts/model/Model} [animatableModel]
  10066. * @param {number} [dataIndex]
  10067. * @param {Function} [cb]
  10068. * @example
  10069. * graphic.updateProps(el, {
  10070. * position: [100, 100]
  10071. * }, seriesModel, dataIndex, function () { console.log('Animation done!'); });
  10072. * // Or
  10073. * graphic.updateProps(el, {
  10074. * position: [100, 100]
  10075. * }, seriesModel, function () { console.log('Animation done!'); });
  10076. */
  10077. graphic.updateProps = function (el, props, animatableModel, dataIndex, cb) {
  10078. animateOrSetProps(true, el, props, animatableModel, dataIndex, cb);
  10079. };
  10080. /**
  10081. * Init graphic element properties with or without animation according to the configuration in series
  10082. * @param {module:zrender/Element} el
  10083. * @param {Object} props
  10084. * @param {module:echarts/model/Model} [animatableModel]
  10085. * @param {number} [dataIndex]
  10086. * @param {Function} cb
  10087. */
  10088. graphic.initProps = function (el, props, animatableModel, dataIndex, cb) {
  10089. animateOrSetProps(false, el, props, animatableModel, dataIndex, cb);
  10090. };
  10091. /**
  10092. * Get transform matrix of target (param target),
  10093. * in coordinate of its ancestor (param ancestor)
  10094. *
  10095. * @param {module:zrender/mixin/Transformable} target
  10096. * @param {module:zrender/mixin/Transformable} [ancestor]
  10097. */
  10098. graphic.getTransform = function (target, ancestor) {
  10099. var mat = matrix.identity([]);
  10100. while (target && target !== ancestor) {
  10101. matrix.mul(mat, target.getLocalTransform(), mat);
  10102. target = target.parent;
  10103. }
  10104. return mat;
  10105. };
  10106. /**
  10107. * Apply transform to an vertex.
  10108. * @param {Array.<number>} vertex [x, y]
  10109. * @param {Array.<number>} transform Transform matrix: like [1, 0, 0, 1, 0, 0]
  10110. * @param {boolean=} invert Whether use invert matrix.
  10111. * @return {Array.<number>} [x, y]
  10112. */
  10113. graphic.applyTransform = function (vertex, transform, invert) {
  10114. if (invert) {
  10115. transform = matrix.invert([], transform);
  10116. }
  10117. return vector.applyTransform([], vertex, transform);
  10118. };
  10119. /**
  10120. * @param {string} direction 'left' 'right' 'top' 'bottom'
  10121. * @param {Array.<number>} transform Transform matrix: like [1, 0, 0, 1, 0, 0]
  10122. * @param {boolean=} invert Whether use invert matrix.
  10123. * @return {string} Transformed direction. 'left' 'right' 'top' 'bottom'
  10124. */
  10125. graphic.transformDirection = function (direction, transform, invert) {
  10126. // Pick a base, ensure that transform result will not be (0, 0).
  10127. var hBase = (transform[4] === 0 || transform[5] === 0 || transform[0] === 0)
  10128. ? 1 : Math.abs(2 * transform[4] / transform[0]);
  10129. var vBase = (transform[4] === 0 || transform[5] === 0 || transform[2] === 0)
  10130. ? 1 : Math.abs(2 * transform[4] / transform[2]);
  10131. var vertex = [
  10132. direction === 'left' ? -hBase : direction === 'right' ? hBase : 0,
  10133. direction === 'top' ? -vBase : direction === 'bottom' ? vBase : 0
  10134. ];
  10135. vertex = graphic.applyTransform(vertex, transform, invert);
  10136. return Math.abs(vertex[0]) > Math.abs(vertex[1])
  10137. ? (vertex[0] > 0 ? 'right' : 'left')
  10138. : (vertex[1] > 0 ? 'bottom' : 'top');
  10139. };
  10140. /**
  10141. * Apply group transition animation from g1 to g2
  10142. */
  10143. graphic.groupTransition = function (g1, g2, animatableModel, cb) {
  10144. if (!g1 || !g2) {
  10145. return;
  10146. }
  10147. function getElMap(g) {
  10148. var elMap = {};
  10149. g.traverse(function (el) {
  10150. if (!el.isGroup && el.anid) {
  10151. elMap[el.anid] = el;
  10152. }
  10153. });
  10154. return elMap;
  10155. }
  10156. function getAnimatableProps(el) {
  10157. var obj = {
  10158. position: vector.clone(el.position),
  10159. rotation: el.rotation
  10160. };
  10161. if (el.shape) {
  10162. obj.shape = zrUtil.extend({}, el.shape);
  10163. }
  10164. return obj;
  10165. }
  10166. var elMap1 = getElMap(g1);
  10167. g2.traverse(function (el) {
  10168. if (!el.isGroup && el.anid) {
  10169. var oldEl = elMap1[el.anid];
  10170. if (oldEl) {
  10171. var newProp = getAnimatableProps(el);
  10172. el.attr(getAnimatableProps(oldEl));
  10173. graphic.updateProps(el, newProp, animatableModel, el.dataIndex);
  10174. }
  10175. // else {
  10176. // if (el.previousProps) {
  10177. // graphic.updateProps
  10178. // }
  10179. // }
  10180. }
  10181. });
  10182. };
  10183. module.exports = graphic;
  10184. /***/ },
  10185. /* 44 */
  10186. /***/ function(module, exports, __webpack_require__) {
  10187. var Path = __webpack_require__(45);
  10188. var PathProxy = __webpack_require__(49);
  10189. var transformPath = __webpack_require__(60);
  10190. var matrix = __webpack_require__(11);
  10191. // command chars
  10192. var cc = [
  10193. 'm', 'M', 'l', 'L', 'v', 'V', 'h', 'H', 'z', 'Z',
  10194. 'c', 'C', 'q', 'Q', 't', 'T', 's', 'S', 'a', 'A'
  10195. ];
  10196. var mathSqrt = Math.sqrt;
  10197. var mathSin = Math.sin;
  10198. var mathCos = Math.cos;
  10199. var PI = Math.PI;
  10200. var vMag = function(v) {
  10201. return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
  10202. };
  10203. var vRatio = function(u, v) {
  10204. return (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v));
  10205. };
  10206. var vAngle = function(u, v) {
  10207. return (u[0] * v[1] < u[1] * v[0] ? -1 : 1)
  10208. * Math.acos(vRatio(u, v));
  10209. };
  10210. function processArc(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg, cmd, path) {
  10211. var psi = psiDeg * (PI / 180.0);
  10212. var xp = mathCos(psi) * (x1 - x2) / 2.0
  10213. + mathSin(psi) * (y1 - y2) / 2.0;
  10214. var yp = -1 * mathSin(psi) * (x1 - x2) / 2.0
  10215. + mathCos(psi) * (y1 - y2) / 2.0;
  10216. var lambda = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry);
  10217. if (lambda > 1) {
  10218. rx *= mathSqrt(lambda);
  10219. ry *= mathSqrt(lambda);
  10220. }
  10221. var f = (fa === fs ? -1 : 1)
  10222. * mathSqrt((((rx * rx) * (ry * ry))
  10223. - ((rx * rx) * (yp * yp))
  10224. - ((ry * ry) * (xp * xp))) / ((rx * rx) * (yp * yp)
  10225. + (ry * ry) * (xp * xp))
  10226. ) || 0;
  10227. var cxp = f * rx * yp / ry;
  10228. var cyp = f * -ry * xp / rx;
  10229. var cx = (x1 + x2) / 2.0
  10230. + mathCos(psi) * cxp
  10231. - mathSin(psi) * cyp;
  10232. var cy = (y1 + y2) / 2.0
  10233. + mathSin(psi) * cxp
  10234. + mathCos(psi) * cyp;
  10235. var theta = vAngle([ 1, 0 ], [ (xp - cxp) / rx, (yp - cyp) / ry ]);
  10236. var u = [ (xp - cxp) / rx, (yp - cyp) / ry ];
  10237. var v = [ (-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry ];
  10238. var dTheta = vAngle(u, v);
  10239. if (vRatio(u, v) <= -1) {
  10240. dTheta = PI;
  10241. }
  10242. if (vRatio(u, v) >= 1) {
  10243. dTheta = 0;
  10244. }
  10245. if (fs === 0 && dTheta > 0) {
  10246. dTheta = dTheta - 2 * PI;
  10247. }
  10248. if (fs === 1 && dTheta < 0) {
  10249. dTheta = dTheta + 2 * PI;
  10250. }
  10251. path.addData(cmd, cx, cy, rx, ry, theta, dTheta, psi, fs);
  10252. }
  10253. function createPathProxyFromString(data) {
  10254. if (!data) {
  10255. return [];
  10256. }
  10257. // command string
  10258. var cs = data.replace(/-/g, ' -')
  10259. .replace(/ /g, ' ')
  10260. .replace(/ /g, ',')
  10261. .replace(/,,/g, ',');
  10262. var n;
  10263. // create pipes so that we can split the data
  10264. for (n = 0; n < cc.length; n++) {
  10265. cs = cs.replace(new RegExp(cc[n], 'g'), '|' + cc[n]);
  10266. }
  10267. // create array
  10268. var arr = cs.split('|');
  10269. // init context point
  10270. var cpx = 0;
  10271. var cpy = 0;
  10272. var path = new PathProxy();
  10273. var CMD = PathProxy.CMD;
  10274. var prevCmd;
  10275. for (n = 1; n < arr.length; n++) {
  10276. var str = arr[n];
  10277. var c = str.charAt(0);
  10278. var off = 0;
  10279. var p = str.slice(1).replace(/e,-/g, 'e-').split(',');
  10280. var cmd;
  10281. if (p.length > 0 && p[0] === '') {
  10282. p.shift();
  10283. }
  10284. for (var i = 0; i < p.length; i++) {
  10285. p[i] = parseFloat(p[i]);
  10286. }
  10287. while (off < p.length && !isNaN(p[off])) {
  10288. if (isNaN(p[0])) {
  10289. break;
  10290. }
  10291. var ctlPtx;
  10292. var ctlPty;
  10293. var rx;
  10294. var ry;
  10295. var psi;
  10296. var fa;
  10297. var fs;
  10298. var x1 = cpx;
  10299. var y1 = cpy;
  10300. // convert l, H, h, V, and v to L
  10301. switch (c) {
  10302. case 'l':
  10303. cpx += p[off++];
  10304. cpy += p[off++];
  10305. cmd = CMD.L;
  10306. path.addData(cmd, cpx, cpy);
  10307. break;
  10308. case 'L':
  10309. cpx = p[off++];
  10310. cpy = p[off++];
  10311. cmd = CMD.L;
  10312. path.addData(cmd, cpx, cpy);
  10313. break;
  10314. case 'm':
  10315. cpx += p[off++];
  10316. cpy += p[off++];
  10317. cmd = CMD.M;
  10318. path.addData(cmd, cpx, cpy);
  10319. c = 'l';
  10320. break;
  10321. case 'M':
  10322. cpx = p[off++];
  10323. cpy = p[off++];
  10324. cmd = CMD.M;
  10325. path.addData(cmd, cpx, cpy);
  10326. c = 'L';
  10327. break;
  10328. case 'h':
  10329. cpx += p[off++];
  10330. cmd = CMD.L;
  10331. path.addData(cmd, cpx, cpy);
  10332. break;
  10333. case 'H':
  10334. cpx = p[off++];
  10335. cmd = CMD.L;
  10336. path.addData(cmd, cpx, cpy);
  10337. break;
  10338. case 'v':
  10339. cpy += p[off++];
  10340. cmd = CMD.L;
  10341. path.addData(cmd, cpx, cpy);
  10342. break;
  10343. case 'V':
  10344. cpy = p[off++];
  10345. cmd = CMD.L;
  10346. path.addData(cmd, cpx, cpy);
  10347. break;
  10348. case 'C':
  10349. cmd = CMD.C;
  10350. path.addData(
  10351. cmd, p[off++], p[off++], p[off++], p[off++], p[off++], p[off++]
  10352. );
  10353. cpx = p[off - 2];
  10354. cpy = p[off - 1];
  10355. break;
  10356. case 'c':
  10357. cmd = CMD.C;
  10358. path.addData(
  10359. cmd,
  10360. p[off++] + cpx, p[off++] + cpy,
  10361. p[off++] + cpx, p[off++] + cpy,
  10362. p[off++] + cpx, p[off++] + cpy
  10363. );
  10364. cpx += p[off - 2];
  10365. cpy += p[off - 1];
  10366. break;
  10367. case 'S':
  10368. ctlPtx = cpx;
  10369. ctlPty = cpy;
  10370. var len = path.len();
  10371. var pathData = path.data;
  10372. if (prevCmd === CMD.C) {
  10373. ctlPtx += cpx - pathData[len - 4];
  10374. ctlPty += cpy - pathData[len - 3];
  10375. }
  10376. cmd = CMD.C;
  10377. x1 = p[off++];
  10378. y1 = p[off++];
  10379. cpx = p[off++];
  10380. cpy = p[off++];
  10381. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  10382. break;
  10383. case 's':
  10384. ctlPtx = cpx;
  10385. ctlPty = cpy;
  10386. var len = path.len();
  10387. var pathData = path.data;
  10388. if (prevCmd === CMD.C) {
  10389. ctlPtx += cpx - pathData[len - 4];
  10390. ctlPty += cpy - pathData[len - 3];
  10391. }
  10392. cmd = CMD.C;
  10393. x1 = cpx + p[off++];
  10394. y1 = cpy + p[off++];
  10395. cpx += p[off++];
  10396. cpy += p[off++];
  10397. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  10398. break;
  10399. case 'Q':
  10400. x1 = p[off++];
  10401. y1 = p[off++];
  10402. cpx = p[off++];
  10403. cpy = p[off++];
  10404. cmd = CMD.Q;
  10405. path.addData(cmd, x1, y1, cpx, cpy);
  10406. break;
  10407. case 'q':
  10408. x1 = p[off++] + cpx;
  10409. y1 = p[off++] + cpy;
  10410. cpx += p[off++];
  10411. cpy += p[off++];
  10412. cmd = CMD.Q;
  10413. path.addData(cmd, x1, y1, cpx, cpy);
  10414. break;
  10415. case 'T':
  10416. ctlPtx = cpx;
  10417. ctlPty = cpy;
  10418. var len = path.len();
  10419. var pathData = path.data;
  10420. if (prevCmd === CMD.Q) {
  10421. ctlPtx += cpx - pathData[len - 4];
  10422. ctlPty += cpy - pathData[len - 3];
  10423. }
  10424. cpx = p[off++];
  10425. cpy = p[off++];
  10426. cmd = CMD.Q;
  10427. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  10428. break;
  10429. case 't':
  10430. ctlPtx = cpx;
  10431. ctlPty = cpy;
  10432. var len = path.len();
  10433. var pathData = path.data;
  10434. if (prevCmd === CMD.Q) {
  10435. ctlPtx += cpx - pathData[len - 4];
  10436. ctlPty += cpy - pathData[len - 3];
  10437. }
  10438. cpx += p[off++];
  10439. cpy += p[off++];
  10440. cmd = CMD.Q;
  10441. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  10442. break;
  10443. case 'A':
  10444. rx = p[off++];
  10445. ry = p[off++];
  10446. psi = p[off++];
  10447. fa = p[off++];
  10448. fs = p[off++];
  10449. x1 = cpx, y1 = cpy;
  10450. cpx = p[off++];
  10451. cpy = p[off++];
  10452. cmd = CMD.A;
  10453. processArc(
  10454. x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path
  10455. );
  10456. break;
  10457. case 'a':
  10458. rx = p[off++];
  10459. ry = p[off++];
  10460. psi = p[off++];
  10461. fa = p[off++];
  10462. fs = p[off++];
  10463. x1 = cpx, y1 = cpy;
  10464. cpx += p[off++];
  10465. cpy += p[off++];
  10466. cmd = CMD.A;
  10467. processArc(
  10468. x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path
  10469. );
  10470. break;
  10471. }
  10472. }
  10473. if (c === 'z' || c === 'Z') {
  10474. cmd = CMD.Z;
  10475. path.addData(cmd);
  10476. }
  10477. prevCmd = cmd;
  10478. }
  10479. path.toStatic();
  10480. return path;
  10481. }
  10482. // TODO Optimize double memory cost problem
  10483. function createPathOptions(str, opts) {
  10484. var pathProxy = createPathProxyFromString(str);
  10485. var transform;
  10486. opts = opts || {};
  10487. opts.buildPath = function (path) {
  10488. path.setData(pathProxy.data);
  10489. transform && transformPath(path, transform);
  10490. // Svg and vml renderer don't have context
  10491. var ctx = path.getContext();
  10492. if (ctx) {
  10493. path.rebuildPath(ctx);
  10494. }
  10495. };
  10496. opts.applyTransform = function (m) {
  10497. if (!transform) {
  10498. transform = matrix.create();
  10499. }
  10500. matrix.mul(transform, m, transform);
  10501. this.dirty(true);
  10502. };
  10503. return opts;
  10504. }
  10505. module.exports = {
  10506. /**
  10507. * Create a Path object from path string data
  10508. * http://www.w3.org/TR/SVG/paths.html#PathData
  10509. * @param {Object} opts Other options
  10510. */
  10511. createFromString: function (str, opts) {
  10512. return new Path(createPathOptions(str, opts));
  10513. },
  10514. /**
  10515. * Create a Path class from path string data
  10516. * @param {string} str
  10517. * @param {Object} opts Other options
  10518. */
  10519. extendFromString: function (str, opts) {
  10520. return Path.extend(createPathOptions(str, opts));
  10521. },
  10522. /**
  10523. * Merge multiple paths
  10524. */
  10525. // TODO Apply transform
  10526. // TODO stroke dash
  10527. // TODO Optimize double memory cost problem
  10528. mergePath: function (pathEls, opts) {
  10529. var pathList = [];
  10530. var len = pathEls.length;
  10531. for (var i = 0; i < len; i++) {
  10532. var pathEl = pathEls[i];
  10533. if (pathEl.__dirty) {
  10534. pathEl.buildPath(pathEl.path, pathEl.shape, true);
  10535. }
  10536. pathList.push(pathEl.path);
  10537. }
  10538. var pathBundle = new Path(opts);
  10539. pathBundle.buildPath = function (path) {
  10540. path.appendPath(pathList);
  10541. // Svg and vml renderer don't have context
  10542. var ctx = path.getContext();
  10543. if (ctx) {
  10544. path.rebuildPath(ctx);
  10545. }
  10546. };
  10547. return pathBundle;
  10548. }
  10549. };
  10550. /***/ },
  10551. /* 45 */
  10552. /***/ function(module, exports, __webpack_require__) {
  10553. /**
  10554. * Path element
  10555. * @module zrender/graphic/Path
  10556. */
  10557. var Displayable = __webpack_require__(46);
  10558. var zrUtil = __webpack_require__(4);
  10559. var PathProxy = __webpack_require__(49);
  10560. var pathContain = __webpack_require__(52);
  10561. var Pattern = __webpack_require__(59);
  10562. var getCanvasPattern = Pattern.prototype.getCanvasPattern;
  10563. var abs = Math.abs;
  10564. /**
  10565. * @alias module:zrender/graphic/Path
  10566. * @extends module:zrender/graphic/Displayable
  10567. * @constructor
  10568. * @param {Object} opts
  10569. */
  10570. function Path(opts) {
  10571. Displayable.call(this, opts);
  10572. /**
  10573. * @type {module:zrender/core/PathProxy}
  10574. * @readOnly
  10575. */
  10576. this.path = new PathProxy();
  10577. }
  10578. Path.prototype = {
  10579. constructor: Path,
  10580. type: 'path',
  10581. __dirtyPath: true,
  10582. strokeContainThreshold: 5,
  10583. brush: function (ctx, prevEl) {
  10584. var style = this.style;
  10585. var path = this.path;
  10586. var hasStroke = style.hasStroke();
  10587. var hasFill = style.hasFill();
  10588. var fill = style.fill;
  10589. var stroke = style.stroke;
  10590. var hasFillGradient = hasFill && !!(fill.colorStops);
  10591. var hasStrokeGradient = hasStroke && !!(stroke.colorStops);
  10592. var hasFillPattern = hasFill && !!(fill.image);
  10593. var hasStrokePattern = hasStroke && !!(stroke.image);
  10594. style.bind(ctx, this, prevEl);
  10595. this.setTransform(ctx);
  10596. if (this.__dirty) {
  10597. var rect = this.getBoundingRect();
  10598. // Update gradient because bounding rect may changed
  10599. if (hasFillGradient) {
  10600. this._fillGradient = style.getGradient(ctx, fill, rect);
  10601. }
  10602. if (hasStrokeGradient) {
  10603. this._strokeGradient = style.getGradient(ctx, stroke, rect);
  10604. }
  10605. }
  10606. // Use the gradient or pattern
  10607. if (hasFillGradient) {
  10608. // PENDING If may have affect the state
  10609. ctx.fillStyle = this._fillGradient;
  10610. }
  10611. else if (hasFillPattern) {
  10612. ctx.fillStyle = getCanvasPattern.call(fill, ctx);
  10613. }
  10614. if (hasStrokeGradient) {
  10615. ctx.strokeStyle = this._strokeGradient;
  10616. }
  10617. else if (hasStrokePattern) {
  10618. ctx.strokeStyle = getCanvasPattern.call(stroke, ctx);
  10619. }
  10620. var lineDash = style.lineDash;
  10621. var lineDashOffset = style.lineDashOffset;
  10622. var ctxLineDash = !!ctx.setLineDash;
  10623. // Update path sx, sy
  10624. var scale = this.getGlobalScale();
  10625. path.setScale(scale[0], scale[1]);
  10626. // Proxy context
  10627. // Rebuild path in following 2 cases
  10628. // 1. Path is dirty
  10629. // 2. Path needs javascript implemented lineDash stroking.
  10630. // In this case, lineDash information will not be saved in PathProxy
  10631. if (this.__dirtyPath || (
  10632. lineDash && !ctxLineDash && hasStroke
  10633. )) {
  10634. path = this.path.beginPath(ctx);
  10635. // Setting line dash before build path
  10636. if (lineDash && !ctxLineDash) {
  10637. path.setLineDash(lineDash);
  10638. path.setLineDashOffset(lineDashOffset);
  10639. }
  10640. this.buildPath(path, this.shape, false);
  10641. // Clear path dirty flag
  10642. this.__dirtyPath = false;
  10643. }
  10644. else {
  10645. // Replay path building
  10646. ctx.beginPath();
  10647. this.path.rebuildPath(ctx);
  10648. }
  10649. hasFill && path.fill(ctx);
  10650. if (lineDash && ctxLineDash) {
  10651. ctx.setLineDash(lineDash);
  10652. ctx.lineDashOffset = lineDashOffset;
  10653. }
  10654. hasStroke && path.stroke(ctx);
  10655. if (lineDash && ctxLineDash) {
  10656. // PENDING
  10657. // Remove lineDash
  10658. ctx.setLineDash([]);
  10659. }
  10660. this.restoreTransform(ctx);
  10661. // Draw rect text
  10662. if (style.text != null) {
  10663. // var rect = this.getBoundingRect();
  10664. this.drawRectText(ctx, this.getBoundingRect());
  10665. }
  10666. },
  10667. // When bundling path, some shape may decide if use moveTo to begin a new subpath or closePath
  10668. // Like in circle
  10669. buildPath: function (ctx, shapeCfg, inBundle) {},
  10670. getBoundingRect: function () {
  10671. var rect = this._rect;
  10672. var style = this.style;
  10673. var needsUpdateRect = !rect;
  10674. if (needsUpdateRect) {
  10675. var path = this.path;
  10676. if (this.__dirtyPath) {
  10677. path.beginPath();
  10678. this.buildPath(path, this.shape, false);
  10679. }
  10680. rect = path.getBoundingRect();
  10681. }
  10682. this._rect = rect;
  10683. if (style.hasStroke()) {
  10684. // Needs update rect with stroke lineWidth when
  10685. // 1. Element changes scale or lineWidth
  10686. // 2. Shape is changed
  10687. var rectWithStroke = this._rectWithStroke || (this._rectWithStroke = rect.clone());
  10688. if (this.__dirty || needsUpdateRect) {
  10689. rectWithStroke.copy(rect);
  10690. // FIXME Must after updateTransform
  10691. var w = style.lineWidth;
  10692. // PENDING, Min line width is needed when line is horizontal or vertical
  10693. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  10694. // Only add extra hover lineWidth when there are no fill
  10695. if (!style.hasFill()) {
  10696. w = Math.max(w, this.strokeContainThreshold || 4);
  10697. }
  10698. // Consider line width
  10699. // Line scale can't be 0;
  10700. if (lineScale > 1e-10) {
  10701. rectWithStroke.width += w / lineScale;
  10702. rectWithStroke.height += w / lineScale;
  10703. rectWithStroke.x -= w / lineScale / 2;
  10704. rectWithStroke.y -= w / lineScale / 2;
  10705. }
  10706. }
  10707. // Return rect with stroke
  10708. return rectWithStroke;
  10709. }
  10710. return rect;
  10711. },
  10712. contain: function (x, y) {
  10713. var localPos = this.transformCoordToLocal(x, y);
  10714. var rect = this.getBoundingRect();
  10715. var style = this.style;
  10716. x = localPos[0];
  10717. y = localPos[1];
  10718. if (rect.contain(x, y)) {
  10719. var pathData = this.path.data;
  10720. if (style.hasStroke()) {
  10721. var lineWidth = style.lineWidth;
  10722. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  10723. // Line scale can't be 0;
  10724. if (lineScale > 1e-10) {
  10725. // Only add extra hover lineWidth when there are no fill
  10726. if (!style.hasFill()) {
  10727. lineWidth = Math.max(lineWidth, this.strokeContainThreshold);
  10728. }
  10729. if (pathContain.containStroke(
  10730. pathData, lineWidth / lineScale, x, y
  10731. )) {
  10732. return true;
  10733. }
  10734. }
  10735. }
  10736. if (style.hasFill()) {
  10737. return pathContain.contain(pathData, x, y);
  10738. }
  10739. }
  10740. return false;
  10741. },
  10742. /**
  10743. * @param {boolean} dirtyPath
  10744. */
  10745. dirty: function (dirtyPath) {
  10746. if (dirtyPath == null) {
  10747. dirtyPath = true;
  10748. }
  10749. // Only mark dirty, not mark clean
  10750. if (dirtyPath) {
  10751. this.__dirtyPath = dirtyPath;
  10752. this._rect = null;
  10753. }
  10754. this.__dirty = true;
  10755. this.__zr && this.__zr.refresh();
  10756. // Used as a clipping path
  10757. if (this.__clipTarget) {
  10758. this.__clipTarget.dirty();
  10759. }
  10760. },
  10761. /**
  10762. * Alias for animate('shape')
  10763. * @param {boolean} loop
  10764. */
  10765. animateShape: function (loop) {
  10766. return this.animate('shape', loop);
  10767. },
  10768. // Overwrite attrKV
  10769. attrKV: function (key, value) {
  10770. // FIXME
  10771. if (key === 'shape') {
  10772. this.setShape(value);
  10773. this.__dirtyPath = true;
  10774. this._rect = null;
  10775. }
  10776. else {
  10777. Displayable.prototype.attrKV.call(this, key, value);
  10778. }
  10779. },
  10780. /**
  10781. * @param {Object|string} key
  10782. * @param {*} value
  10783. */
  10784. setShape: function (key, value) {
  10785. var shape = this.shape;
  10786. // Path from string may not have shape
  10787. if (shape) {
  10788. if (zrUtil.isObject(key)) {
  10789. for (var name in key) {
  10790. if (key.hasOwnProperty(name)) {
  10791. shape[name] = key[name];
  10792. }
  10793. }
  10794. }
  10795. else {
  10796. shape[key] = value;
  10797. }
  10798. this.dirty(true);
  10799. }
  10800. return this;
  10801. },
  10802. getLineScale: function () {
  10803. var m = this.transform;
  10804. // Get the line scale.
  10805. // Determinant of `m` means how much the area is enlarged by the
  10806. // transformation. So its square root can be used as a scale factor
  10807. // for width.
  10808. return m && abs(m[0] - 1) > 1e-10 && abs(m[3] - 1) > 1e-10
  10809. ? Math.sqrt(abs(m[0] * m[3] - m[2] * m[1]))
  10810. : 1;
  10811. }
  10812. };
  10813. /**
  10814. * 扩展一个 Path element, 比如星形,圆等。
  10815. * Extend a path element
  10816. * @param {Object} props
  10817. * @param {string} props.type Path type
  10818. * @param {Function} props.init Initialize
  10819. * @param {Function} props.buildPath Overwrite buildPath method
  10820. * @param {Object} [props.style] Extended default style config
  10821. * @param {Object} [props.shape] Extended default shape config
  10822. */
  10823. Path.extend = function (defaults) {
  10824. var Sub = function (opts) {
  10825. Path.call(this, opts);
  10826. if (defaults.style) {
  10827. // Extend default style
  10828. this.style.extendFrom(defaults.style, false);
  10829. }
  10830. // Extend default shape
  10831. var defaultShape = defaults.shape;
  10832. if (defaultShape) {
  10833. this.shape = this.shape || {};
  10834. var thisShape = this.shape;
  10835. for (var name in defaultShape) {
  10836. if (
  10837. ! thisShape.hasOwnProperty(name)
  10838. && defaultShape.hasOwnProperty(name)
  10839. ) {
  10840. thisShape[name] = defaultShape[name];
  10841. }
  10842. }
  10843. }
  10844. defaults.init && defaults.init.call(this, opts);
  10845. };
  10846. zrUtil.inherits(Sub, Path);
  10847. // FIXME 不能 extend position, rotation 等引用对象
  10848. for (var name in defaults) {
  10849. // Extending prototype values and methods
  10850. if (name !== 'style' && name !== 'shape') {
  10851. Sub.prototype[name] = defaults[name];
  10852. }
  10853. }
  10854. return Sub;
  10855. };
  10856. zrUtil.inherits(Path, Displayable);
  10857. module.exports = Path;
  10858. /***/ },
  10859. /* 46 */
  10860. /***/ function(module, exports, __webpack_require__) {
  10861. /**
  10862. * 可绘制的图形基类
  10863. * Base class of all displayable graphic objects
  10864. * @module zrender/graphic/Displayable
  10865. */
  10866. var zrUtil = __webpack_require__(4);
  10867. var Style = __webpack_require__(47);
  10868. var Element = __webpack_require__(31);
  10869. var RectText = __webpack_require__(48);
  10870. // var Stateful = require('./mixin/Stateful');
  10871. /**
  10872. * @alias module:zrender/graphic/Displayable
  10873. * @extends module:zrender/Element
  10874. * @extends module:zrender/graphic/mixin/RectText
  10875. */
  10876. function Displayable(opts) {
  10877. opts = opts || {};
  10878. Element.call(this, opts);
  10879. // Extend properties
  10880. for (var name in opts) {
  10881. if (
  10882. opts.hasOwnProperty(name) &&
  10883. name !== 'style'
  10884. ) {
  10885. this[name] = opts[name];
  10886. }
  10887. }
  10888. /**
  10889. * @type {module:zrender/graphic/Style}
  10890. */
  10891. this.style = new Style(opts.style);
  10892. this._rect = null;
  10893. // Shapes for cascade clipping.
  10894. this.__clipPaths = [];
  10895. // FIXME Stateful must be mixined after style is setted
  10896. // Stateful.call(this, opts);
  10897. }
  10898. Displayable.prototype = {
  10899. constructor: Displayable,
  10900. type: 'displayable',
  10901. /**
  10902. * Displayable 是否为脏,Painter 中会根据该标记判断是否需要是否需要重新绘制
  10903. * Dirty flag. From which painter will determine if this displayable object needs brush
  10904. * @name module:zrender/graphic/Displayable#__dirty
  10905. * @type {boolean}
  10906. */
  10907. __dirty: true,
  10908. /**
  10909. * 图形是否可见,为true时不绘制图形,但是仍能触发鼠标事件
  10910. * If ignore drawing of the displayable object. Mouse event will still be triggered
  10911. * @name module:/zrender/graphic/Displayable#invisible
  10912. * @type {boolean}
  10913. * @default false
  10914. */
  10915. invisible: false,
  10916. /**
  10917. * @name module:/zrender/graphic/Displayable#z
  10918. * @type {number}
  10919. * @default 0
  10920. */
  10921. z: 0,
  10922. /**
  10923. * @name module:/zrender/graphic/Displayable#z
  10924. * @type {number}
  10925. * @default 0
  10926. */
  10927. z2: 0,
  10928. /**
  10929. * z层level,决定绘画在哪层canvas中
  10930. * @name module:/zrender/graphic/Displayable#zlevel
  10931. * @type {number}
  10932. * @default 0
  10933. */
  10934. zlevel: 0,
  10935. /**
  10936. * 是否可拖拽
  10937. * @name module:/zrender/graphic/Displayable#draggable
  10938. * @type {boolean}
  10939. * @default false
  10940. */
  10941. draggable: false,
  10942. /**
  10943. * 是否正在拖拽
  10944. * @name module:/zrender/graphic/Displayable#draggable
  10945. * @type {boolean}
  10946. * @default false
  10947. */
  10948. dragging: false,
  10949. /**
  10950. * 是否相应鼠标事件
  10951. * @name module:/zrender/graphic/Displayable#silent
  10952. * @type {boolean}
  10953. * @default false
  10954. */
  10955. silent: false,
  10956. /**
  10957. * If enable culling
  10958. * @type {boolean}
  10959. * @default false
  10960. */
  10961. culling: false,
  10962. /**
  10963. * Mouse cursor when hovered
  10964. * @name module:/zrender/graphic/Displayable#cursor
  10965. * @type {string}
  10966. */
  10967. cursor: 'pointer',
  10968. /**
  10969. * If hover area is bounding rect
  10970. * @name module:/zrender/graphic/Displayable#rectHover
  10971. * @type {string}
  10972. */
  10973. rectHover: false,
  10974. /**
  10975. * Render the element progressively when the value >= 0,
  10976. * usefull for large data.
  10977. * @type {number}
  10978. */
  10979. progressive: -1,
  10980. beforeBrush: function (ctx) {},
  10981. afterBrush: function (ctx) {},
  10982. /**
  10983. * 图形绘制方法
  10984. * @param {Canvas2DRenderingContext} ctx
  10985. */
  10986. // Interface
  10987. brush: function (ctx, prevEl) {},
  10988. /**
  10989. * 获取最小包围盒
  10990. * @return {module:zrender/core/BoundingRect}
  10991. */
  10992. // Interface
  10993. getBoundingRect: function () {},
  10994. /**
  10995. * 判断坐标 x, y 是否在图形上
  10996. * If displayable element contain coord x, y
  10997. * @param {number} x
  10998. * @param {number} y
  10999. * @return {boolean}
  11000. */
  11001. contain: function (x, y) {
  11002. return this.rectContain(x, y);
  11003. },
  11004. /**
  11005. * @param {Function} cb
  11006. * @param {} context
  11007. */
  11008. traverse: function (cb, context) {
  11009. cb.call(context, this);
  11010. },
  11011. /**
  11012. * 判断坐标 x, y 是否在图形的包围盒上
  11013. * If bounding rect of element contain coord x, y
  11014. * @param {number} x
  11015. * @param {number} y
  11016. * @return {boolean}
  11017. */
  11018. rectContain: function (x, y) {
  11019. var coord = this.transformCoordToLocal(x, y);
  11020. var rect = this.getBoundingRect();
  11021. return rect.contain(coord[0], coord[1]);
  11022. },
  11023. /**
  11024. * 标记图形元素为脏,并且在下一帧重绘
  11025. * Mark displayable element dirty and refresh next frame
  11026. */
  11027. dirty: function () {
  11028. this.__dirty = true;
  11029. this._rect = null;
  11030. this.__zr && this.__zr.refresh();
  11031. },
  11032. /**
  11033. * 图形是否会触发事件
  11034. * If displayable object binded any event
  11035. * @return {boolean}
  11036. */
  11037. // TODO, 通过 bind 绑定的事件
  11038. // isSilent: function () {
  11039. // return !(
  11040. // this.hoverable || this.draggable
  11041. // || this.onmousemove || this.onmouseover || this.onmouseout
  11042. // || this.onmousedown || this.onmouseup || this.onclick
  11043. // || this.ondragenter || this.ondragover || this.ondragleave
  11044. // || this.ondrop
  11045. // );
  11046. // },
  11047. /**
  11048. * Alias for animate('style')
  11049. * @param {boolean} loop
  11050. */
  11051. animateStyle: function (loop) {
  11052. return this.animate('style', loop);
  11053. },
  11054. attrKV: function (key, value) {
  11055. if (key !== 'style') {
  11056. Element.prototype.attrKV.call(this, key, value);
  11057. }
  11058. else {
  11059. this.style.set(value);
  11060. }
  11061. },
  11062. /**
  11063. * @param {Object|string} key
  11064. * @param {*} value
  11065. */
  11066. setStyle: function (key, value) {
  11067. this.style.set(key, value);
  11068. this.dirty(false);
  11069. return this;
  11070. },
  11071. /**
  11072. * Use given style object
  11073. * @param {Object} obj
  11074. */
  11075. useStyle: function (obj) {
  11076. this.style = new Style(obj);
  11077. this.dirty(false);
  11078. return this;
  11079. }
  11080. };
  11081. zrUtil.inherits(Displayable, Element);
  11082. zrUtil.mixin(Displayable, RectText);
  11083. // zrUtil.mixin(Displayable, Stateful);
  11084. module.exports = Displayable;
  11085. /***/ },
  11086. /* 47 */
  11087. /***/ function(module, exports) {
  11088. /**
  11089. * @module zrender/graphic/Style
  11090. */
  11091. var STYLE_COMMON_PROPS = [
  11092. ['shadowBlur', 0], ['shadowOffsetX', 0], ['shadowOffsetY', 0], ['shadowColor', '#000'],
  11093. ['lineCap', 'butt'], ['lineJoin', 'miter'], ['miterLimit', 10]
  11094. ];
  11095. // var SHADOW_PROPS = STYLE_COMMON_PROPS.slice(0, 4);
  11096. // var LINE_PROPS = STYLE_COMMON_PROPS.slice(4);
  11097. var Style = function (opts) {
  11098. this.extendFrom(opts);
  11099. };
  11100. function createLinearGradient(ctx, obj, rect) {
  11101. // var size =
  11102. var x = obj.x;
  11103. var x2 = obj.x2;
  11104. var y = obj.y;
  11105. var y2 = obj.y2;
  11106. if (!obj.global) {
  11107. x = x * rect.width + rect.x;
  11108. x2 = x2 * rect.width + rect.x;
  11109. y = y * rect.height + rect.y;
  11110. y2 = y2 * rect.height + rect.y;
  11111. }
  11112. var canvasGradient = ctx.createLinearGradient(x, y, x2, y2);
  11113. return canvasGradient;
  11114. }
  11115. function createRadialGradient(ctx, obj, rect) {
  11116. var width = rect.width;
  11117. var height = rect.height;
  11118. var min = Math.min(width, height);
  11119. var x = obj.x;
  11120. var y = obj.y;
  11121. var r = obj.r;
  11122. if (!obj.global) {
  11123. x = x * width + rect.x;
  11124. y = y * height + rect.y;
  11125. r = r * min;
  11126. }
  11127. var canvasGradient = ctx.createRadialGradient(x, y, 0, x, y, r);
  11128. return canvasGradient;
  11129. }
  11130. Style.prototype = {
  11131. constructor: Style,
  11132. /**
  11133. * @type {string}
  11134. */
  11135. fill: '#000000',
  11136. /**
  11137. * @type {string}
  11138. */
  11139. stroke: null,
  11140. /**
  11141. * @type {number}
  11142. */
  11143. opacity: 1,
  11144. /**
  11145. * @type {Array.<number>}
  11146. */
  11147. lineDash: null,
  11148. /**
  11149. * @type {number}
  11150. */
  11151. lineDashOffset: 0,
  11152. /**
  11153. * @type {number}
  11154. */
  11155. shadowBlur: 0,
  11156. /**
  11157. * @type {number}
  11158. */
  11159. shadowOffsetX: 0,
  11160. /**
  11161. * @type {number}
  11162. */
  11163. shadowOffsetY: 0,
  11164. /**
  11165. * @type {number}
  11166. */
  11167. lineWidth: 1,
  11168. /**
  11169. * If stroke ignore scale
  11170. * @type {Boolean}
  11171. */
  11172. strokeNoScale: false,
  11173. // Bounding rect text configuration
  11174. // Not affected by element transform
  11175. /**
  11176. * @type {string}
  11177. */
  11178. text: null,
  11179. /**
  11180. * @type {string}
  11181. */
  11182. textFill: '#000',
  11183. /**
  11184. * @type {string}
  11185. */
  11186. textStroke: null,
  11187. /**
  11188. * 'inside', 'left', 'right', 'top', 'bottom'
  11189. * [x, y]
  11190. * @type {string|Array.<number>}
  11191. * @default 'inside'
  11192. */
  11193. textPosition: 'inside',
  11194. /**
  11195. * [x, y]
  11196. * @type {Array.<number>}
  11197. */
  11198. textOffset: null,
  11199. /**
  11200. * @type {string}
  11201. */
  11202. textBaseline: null,
  11203. /**
  11204. * @type {string}
  11205. */
  11206. textAlign: null,
  11207. /**
  11208. * @type {string}
  11209. */
  11210. textVerticalAlign: null,
  11211. /**
  11212. * Only useful in Path and Image element
  11213. * @type {number}
  11214. */
  11215. textDistance: 5,
  11216. /**
  11217. * Only useful in Path and Image element
  11218. * @type {number}
  11219. */
  11220. textShadowBlur: 0,
  11221. /**
  11222. * Only useful in Path and Image element
  11223. * @type {number}
  11224. */
  11225. textShadowOffsetX: 0,
  11226. /**
  11227. * Only useful in Path and Image element
  11228. * @type {number}
  11229. */
  11230. textShadowOffsetY: 0,
  11231. /**
  11232. * If transform text
  11233. * Only useful in Path and Image element
  11234. * @type {boolean}
  11235. */
  11236. textTransform: false,
  11237. /**
  11238. * Text rotate around position of Path or Image
  11239. * Only useful in Path and Image element and textTransform is false.
  11240. */
  11241. textRotation: 0,
  11242. /**
  11243. * @type {string}
  11244. * https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
  11245. */
  11246. blend: null,
  11247. /**
  11248. * @param {CanvasRenderingContext2D} ctx
  11249. */
  11250. bind: function (ctx, el, prevEl) {
  11251. var style = this;
  11252. var prevStyle = prevEl && prevEl.style;
  11253. var firstDraw = !prevStyle;
  11254. for (var i = 0; i < STYLE_COMMON_PROPS.length; i++) {
  11255. var prop = STYLE_COMMON_PROPS[i];
  11256. var styleName = prop[0];
  11257. if (firstDraw || style[styleName] !== prevStyle[styleName]) {
  11258. // FIXME Invalid property value will cause style leak from previous element.
  11259. ctx[styleName] = style[styleName] || prop[1];
  11260. }
  11261. }
  11262. if ((firstDraw || style.fill !== prevStyle.fill)) {
  11263. ctx.fillStyle = style.fill;
  11264. }
  11265. if ((firstDraw || style.stroke !== prevStyle.stroke)) {
  11266. ctx.strokeStyle = style.stroke;
  11267. }
  11268. if ((firstDraw || style.opacity !== prevStyle.opacity)) {
  11269. ctx.globalAlpha = style.opacity == null ? 1 : style.opacity;
  11270. }
  11271. if ((firstDraw || style.blend !== prevStyle.blend)) {
  11272. ctx.globalCompositeOperation = style.blend || 'source-over';
  11273. }
  11274. if (this.hasStroke()) {
  11275. var lineWidth = style.lineWidth;
  11276. ctx.lineWidth = lineWidth / (
  11277. (this.strokeNoScale && el && el.getLineScale) ? el.getLineScale() : 1
  11278. );
  11279. }
  11280. },
  11281. hasFill: function () {
  11282. var fill = this.fill;
  11283. return fill != null && fill !== 'none';
  11284. },
  11285. hasStroke: function () {
  11286. var stroke = this.stroke;
  11287. return stroke != null && stroke !== 'none' && this.lineWidth > 0;
  11288. },
  11289. /**
  11290. * Extend from other style
  11291. * @param {zrender/graphic/Style} otherStyle
  11292. * @param {boolean} overwrite
  11293. */
  11294. extendFrom: function (otherStyle, overwrite) {
  11295. if (otherStyle) {
  11296. var target = this;
  11297. for (var name in otherStyle) {
  11298. if (otherStyle.hasOwnProperty(name)
  11299. && (overwrite || ! target.hasOwnProperty(name))
  11300. ) {
  11301. target[name] = otherStyle[name];
  11302. }
  11303. }
  11304. }
  11305. },
  11306. /**
  11307. * Batch setting style with a given object
  11308. * @param {Object|string} obj
  11309. * @param {*} [obj]
  11310. */
  11311. set: function (obj, value) {
  11312. if (typeof obj === 'string') {
  11313. this[obj] = value;
  11314. }
  11315. else {
  11316. this.extendFrom(obj, true);
  11317. }
  11318. },
  11319. /**
  11320. * Clone
  11321. * @return {zrender/graphic/Style} [description]
  11322. */
  11323. clone: function () {
  11324. var newStyle = new this.constructor();
  11325. newStyle.extendFrom(this, true);
  11326. return newStyle;
  11327. },
  11328. getGradient: function (ctx, obj, rect) {
  11329. var method = obj.type === 'radial' ? createRadialGradient : createLinearGradient;
  11330. var canvasGradient = method(ctx, obj, rect);
  11331. var colorStops = obj.colorStops;
  11332. for (var i = 0; i < colorStops.length; i++) {
  11333. canvasGradient.addColorStop(
  11334. colorStops[i].offset, colorStops[i].color
  11335. );
  11336. }
  11337. return canvasGradient;
  11338. }
  11339. };
  11340. var styleProto = Style.prototype;
  11341. for (var i = 0; i < STYLE_COMMON_PROPS.length; i++) {
  11342. var prop = STYLE_COMMON_PROPS[i];
  11343. if (!(prop[0] in styleProto)) {
  11344. styleProto[prop[0]] = prop[1];
  11345. }
  11346. }
  11347. // Provide for others
  11348. Style.getGradient = styleProto.getGradient;
  11349. module.exports = Style;
  11350. /***/ },
  11351. /* 48 */
  11352. /***/ function(module, exports, __webpack_require__) {
  11353. /**
  11354. * Mixin for drawing text in a element bounding rect
  11355. * @module zrender/mixin/RectText
  11356. */
  11357. var textContain = __webpack_require__(8);
  11358. var BoundingRect = __webpack_require__(9);
  11359. var tmpRect = new BoundingRect();
  11360. var RectText = function () {};
  11361. function parsePercent(value, maxValue) {
  11362. if (typeof value === 'string') {
  11363. if (value.lastIndexOf('%') >= 0) {
  11364. return parseFloat(value) / 100 * maxValue;
  11365. }
  11366. return parseFloat(value);
  11367. }
  11368. return value;
  11369. }
  11370. RectText.prototype = {
  11371. constructor: RectText,
  11372. /**
  11373. * Draw text in a rect with specified position.
  11374. * @param {CanvasRenderingContext} ctx
  11375. * @param {Object} rect Displayable rect
  11376. * @return {Object} textRect Alternative precalculated text bounding rect
  11377. */
  11378. drawRectText: function (ctx, rect, textRect) {
  11379. var style = this.style;
  11380. var text = style.text;
  11381. // Convert to string
  11382. text != null && (text += '');
  11383. if (!text) {
  11384. return;
  11385. }
  11386. // FIXME
  11387. ctx.save();
  11388. var x;
  11389. var y;
  11390. var textPosition = style.textPosition;
  11391. var textOffset = style.textOffset;
  11392. var distance = style.textDistance;
  11393. var align = style.textAlign;
  11394. var font = style.textFont || style.font;
  11395. var baseline = style.textBaseline;
  11396. var verticalAlign = style.textVerticalAlign;
  11397. textRect = textRect || textContain.getBoundingRect(text, font, align, baseline);
  11398. // Transform rect to view space
  11399. var transform = this.transform;
  11400. if (!style.textTransform) {
  11401. if (transform) {
  11402. tmpRect.copy(rect);
  11403. tmpRect.applyTransform(transform);
  11404. rect = tmpRect;
  11405. }
  11406. }
  11407. else {
  11408. this.setTransform(ctx);
  11409. }
  11410. // Text position represented by coord
  11411. if (textPosition instanceof Array) {
  11412. // Percent
  11413. x = rect.x + parsePercent(textPosition[0], rect.width);
  11414. y = rect.y + parsePercent(textPosition[1], rect.height);
  11415. align = align || 'left';
  11416. baseline = baseline || 'top';
  11417. if (verticalAlign) {
  11418. switch (verticalAlign) {
  11419. case 'middle':
  11420. y -= textRect.height / 2 - textRect.lineHeight / 2;
  11421. break;
  11422. case 'bottom':
  11423. y -= textRect.height - textRect.lineHeight / 2;
  11424. break;
  11425. default:
  11426. y += textRect.lineHeight / 2;
  11427. }
  11428. // Force bseline to be middle
  11429. baseline = 'middle';
  11430. }
  11431. }
  11432. else {
  11433. var res = textContain.adjustTextPositionOnRect(
  11434. textPosition, rect, textRect, distance
  11435. );
  11436. x = res.x;
  11437. y = res.y;
  11438. // Default align and baseline when has textPosition
  11439. align = align || res.textAlign;
  11440. baseline = baseline || res.textBaseline;
  11441. }
  11442. if (textOffset) {
  11443. x += textOffset[0];
  11444. y += textOffset[1];
  11445. }
  11446. // Use canvas default left textAlign. Giving invalid value will cause state not change
  11447. ctx.textAlign = align || 'left';
  11448. // Use canvas default alphabetic baseline
  11449. ctx.textBaseline = baseline || 'alphabetic';
  11450. var textFill = style.textFill;
  11451. var textStroke = style.textStroke;
  11452. textFill && (ctx.fillStyle = textFill);
  11453. textStroke && (ctx.strokeStyle = textStroke);
  11454. // TODO Invalid font
  11455. ctx.font = font || '12px sans-serif';
  11456. // Text shadow
  11457. // Always set shadowBlur and shadowOffset to avoid leak from displayable
  11458. ctx.shadowBlur = style.textShadowBlur;
  11459. ctx.shadowColor = style.textShadowColor || 'transparent';
  11460. ctx.shadowOffsetX = style.textShadowOffsetX;
  11461. ctx.shadowOffsetY = style.textShadowOffsetY;
  11462. var textLines = text.split('\n');
  11463. if (style.textRotation) {
  11464. transform && ctx.translate(transform[4], transform[5]);
  11465. ctx.rotate(style.textRotation);
  11466. transform && ctx.translate(-transform[4], -transform[5]);
  11467. }
  11468. for (var i = 0; i < textLines.length; i++) {
  11469. textFill && ctx.fillText(textLines[i], x, y);
  11470. textStroke && ctx.strokeText(textLines[i], x, y);
  11471. y += textRect.lineHeight;
  11472. }
  11473. ctx.restore();
  11474. }
  11475. };
  11476. module.exports = RectText;
  11477. /***/ },
  11478. /* 49 */
  11479. /***/ function(module, exports, __webpack_require__) {
  11480. 'use strict';
  11481. /**
  11482. * Path 代理,可以在`buildPath`中用于替代`ctx`, 会保存每个path操作的命令到pathCommands属性中
  11483. * 可以用于 isInsidePath 判断以及获取boundingRect
  11484. *
  11485. * @module zrender/core/PathProxy
  11486. * @author Yi Shen (http://www.github.com/pissang)
  11487. */
  11488. // TODO getTotalLength, getPointAtLength
  11489. var curve = __webpack_require__(50);
  11490. var vec2 = __webpack_require__(10);
  11491. var bbox = __webpack_require__(51);
  11492. var BoundingRect = __webpack_require__(9);
  11493. var dpr = __webpack_require__(41).devicePixelRatio;
  11494. var CMD = {
  11495. M: 1,
  11496. L: 2,
  11497. C: 3,
  11498. Q: 4,
  11499. A: 5,
  11500. Z: 6,
  11501. // Rect
  11502. R: 7
  11503. };
  11504. var min = [];
  11505. var max = [];
  11506. var min2 = [];
  11507. var max2 = [];
  11508. var mathMin = Math.min;
  11509. var mathMax = Math.max;
  11510. var mathCos = Math.cos;
  11511. var mathSin = Math.sin;
  11512. var mathSqrt = Math.sqrt;
  11513. var mathAbs = Math.abs;
  11514. var hasTypedArray = typeof Float32Array != 'undefined';
  11515. /**
  11516. * @alias module:zrender/core/PathProxy
  11517. * @constructor
  11518. */
  11519. var PathProxy = function () {
  11520. /**
  11521. * Path data. Stored as flat array
  11522. * @type {Array.<Object>}
  11523. */
  11524. this.data = [];
  11525. this._len = 0;
  11526. this._ctx = null;
  11527. this._xi = 0;
  11528. this._yi = 0;
  11529. this._x0 = 0;
  11530. this._y0 = 0;
  11531. // Unit x, Unit y. Provide for avoiding drawing that too short line segment
  11532. this._ux = 0;
  11533. this._uy = 0;
  11534. };
  11535. /**
  11536. * 快速计算Path包围盒(并不是最小包围盒)
  11537. * @return {Object}
  11538. */
  11539. PathProxy.prototype = {
  11540. constructor: PathProxy,
  11541. _lineDash: null,
  11542. _dashOffset: 0,
  11543. _dashIdx: 0,
  11544. _dashSum: 0,
  11545. /**
  11546. * @readOnly
  11547. */
  11548. setScale: function (sx, sy) {
  11549. this._ux = mathAbs(1 / dpr / sx) || 0;
  11550. this._uy = mathAbs(1 / dpr / sy) || 0;
  11551. },
  11552. getContext: function () {
  11553. return this._ctx;
  11554. },
  11555. /**
  11556. * @param {CanvasRenderingContext2D} ctx
  11557. * @return {module:zrender/core/PathProxy}
  11558. */
  11559. beginPath: function (ctx) {
  11560. this._ctx = ctx;
  11561. ctx && ctx.beginPath();
  11562. ctx && (this.dpr = ctx.dpr);
  11563. // Reset
  11564. this._len = 0;
  11565. if (this._lineDash) {
  11566. this._lineDash = null;
  11567. this._dashOffset = 0;
  11568. }
  11569. return this;
  11570. },
  11571. /**
  11572. * @param {number} x
  11573. * @param {number} y
  11574. * @return {module:zrender/core/PathProxy}
  11575. */
  11576. moveTo: function (x, y) {
  11577. this.addData(CMD.M, x, y);
  11578. this._ctx && this._ctx.moveTo(x, y);
  11579. // x0, y0, xi, yi 是记录在 _dashedXXXXTo 方法中使用
  11580. // xi, yi 记录当前点, x0, y0 在 closePath 的时候回到起始点。
  11581. // 有可能在 beginPath 之后直接调用 lineTo,这时候 x0, y0 需要
  11582. // 在 lineTo 方法中记录,这里先不考虑这种情况,dashed line 也只在 IE10- 中不支持
  11583. this._x0 = x;
  11584. this._y0 = y;
  11585. this._xi = x;
  11586. this._yi = y;
  11587. return this;
  11588. },
  11589. /**
  11590. * @param {number} x
  11591. * @param {number} y
  11592. * @return {module:zrender/core/PathProxy}
  11593. */
  11594. lineTo: function (x, y) {
  11595. var exceedUnit = mathAbs(x - this._xi) > this._ux
  11596. || mathAbs(y - this._yi) > this._uy
  11597. // Force draw the first segment
  11598. || this._len < 5;
  11599. this.addData(CMD.L, x, y);
  11600. if (this._ctx && exceedUnit) {
  11601. this._needsDash() ? this._dashedLineTo(x, y)
  11602. : this._ctx.lineTo(x, y);
  11603. }
  11604. if (exceedUnit) {
  11605. this._xi = x;
  11606. this._yi = y;
  11607. }
  11608. return this;
  11609. },
  11610. /**
  11611. * @param {number} x1
  11612. * @param {number} y1
  11613. * @param {number} x2
  11614. * @param {number} y2
  11615. * @param {number} x3
  11616. * @param {number} y3
  11617. * @return {module:zrender/core/PathProxy}
  11618. */
  11619. bezierCurveTo: function (x1, y1, x2, y2, x3, y3) {
  11620. this.addData(CMD.C, x1, y1, x2, y2, x3, y3);
  11621. if (this._ctx) {
  11622. this._needsDash() ? this._dashedBezierTo(x1, y1, x2, y2, x3, y3)
  11623. : this._ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  11624. }
  11625. this._xi = x3;
  11626. this._yi = y3;
  11627. return this;
  11628. },
  11629. /**
  11630. * @param {number} x1
  11631. * @param {number} y1
  11632. * @param {number} x2
  11633. * @param {number} y2
  11634. * @return {module:zrender/core/PathProxy}
  11635. */
  11636. quadraticCurveTo: function (x1, y1, x2, y2) {
  11637. this.addData(CMD.Q, x1, y1, x2, y2);
  11638. if (this._ctx) {
  11639. this._needsDash() ? this._dashedQuadraticTo(x1, y1, x2, y2)
  11640. : this._ctx.quadraticCurveTo(x1, y1, x2, y2);
  11641. }
  11642. this._xi = x2;
  11643. this._yi = y2;
  11644. return this;
  11645. },
  11646. /**
  11647. * @param {number} cx
  11648. * @param {number} cy
  11649. * @param {number} r
  11650. * @param {number} startAngle
  11651. * @param {number} endAngle
  11652. * @param {boolean} anticlockwise
  11653. * @return {module:zrender/core/PathProxy}
  11654. */
  11655. arc: function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  11656. this.addData(
  11657. CMD.A, cx, cy, r, r, startAngle, endAngle - startAngle, 0, anticlockwise ? 0 : 1
  11658. );
  11659. this._ctx && this._ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  11660. this._xi = mathCos(endAngle) * r + cx;
  11661. this._yi = mathSin(endAngle) * r + cx;
  11662. return this;
  11663. },
  11664. // TODO
  11665. arcTo: function (x1, y1, x2, y2, radius) {
  11666. if (this._ctx) {
  11667. this._ctx.arcTo(x1, y1, x2, y2, radius);
  11668. }
  11669. return this;
  11670. },
  11671. // TODO
  11672. rect: function (x, y, w, h) {
  11673. this._ctx && this._ctx.rect(x, y, w, h);
  11674. this.addData(CMD.R, x, y, w, h);
  11675. return this;
  11676. },
  11677. /**
  11678. * @return {module:zrender/core/PathProxy}
  11679. */
  11680. closePath: function () {
  11681. this.addData(CMD.Z);
  11682. var ctx = this._ctx;
  11683. var x0 = this._x0;
  11684. var y0 = this._y0;
  11685. if (ctx) {
  11686. this._needsDash() && this._dashedLineTo(x0, y0);
  11687. ctx.closePath();
  11688. }
  11689. this._xi = x0;
  11690. this._yi = y0;
  11691. return this;
  11692. },
  11693. /**
  11694. * Context 从外部传入,因为有可能是 rebuildPath 完之后再 fill。
  11695. * stroke 同样
  11696. * @param {CanvasRenderingContext2D} ctx
  11697. * @return {module:zrender/core/PathProxy}
  11698. */
  11699. fill: function (ctx) {
  11700. ctx && ctx.fill();
  11701. this.toStatic();
  11702. },
  11703. /**
  11704. * @param {CanvasRenderingContext2D} ctx
  11705. * @return {module:zrender/core/PathProxy}
  11706. */
  11707. stroke: function (ctx) {
  11708. ctx && ctx.stroke();
  11709. this.toStatic();
  11710. },
  11711. /**
  11712. * 必须在其它绘制命令前调用
  11713. * Must be invoked before all other path drawing methods
  11714. * @return {module:zrender/core/PathProxy}
  11715. */
  11716. setLineDash: function (lineDash) {
  11717. if (lineDash instanceof Array) {
  11718. this._lineDash = lineDash;
  11719. this._dashIdx = 0;
  11720. var lineDashSum = 0;
  11721. for (var i = 0; i < lineDash.length; i++) {
  11722. lineDashSum += lineDash[i];
  11723. }
  11724. this._dashSum = lineDashSum;
  11725. }
  11726. return this;
  11727. },
  11728. /**
  11729. * 必须在其它绘制命令前调用
  11730. * Must be invoked before all other path drawing methods
  11731. * @return {module:zrender/core/PathProxy}
  11732. */
  11733. setLineDashOffset: function (offset) {
  11734. this._dashOffset = offset;
  11735. return this;
  11736. },
  11737. /**
  11738. *
  11739. * @return {boolean}
  11740. */
  11741. len: function () {
  11742. return this._len;
  11743. },
  11744. /**
  11745. * 直接设置 Path 数据
  11746. */
  11747. setData: function (data) {
  11748. var len = data.length;
  11749. if (! (this.data && this.data.length == len) && hasTypedArray) {
  11750. this.data = new Float32Array(len);
  11751. }
  11752. for (var i = 0; i < len; i++) {
  11753. this.data[i] = data[i];
  11754. }
  11755. this._len = len;
  11756. },
  11757. /**
  11758. * 添加子路径
  11759. * @param {module:zrender/core/PathProxy|Array.<module:zrender/core/PathProxy>} path
  11760. */
  11761. appendPath: function (path) {
  11762. if (!(path instanceof Array)) {
  11763. path = [path];
  11764. }
  11765. var len = path.length;
  11766. var appendSize = 0;
  11767. var offset = this._len;
  11768. for (var i = 0; i < len; i++) {
  11769. appendSize += path[i].len();
  11770. }
  11771. if (hasTypedArray && (this.data instanceof Float32Array)) {
  11772. this.data = new Float32Array(offset + appendSize);
  11773. }
  11774. for (var i = 0; i < len; i++) {
  11775. var appendPathData = path[i].data;
  11776. for (var k = 0; k < appendPathData.length; k++) {
  11777. this.data[offset++] = appendPathData[k];
  11778. }
  11779. }
  11780. this._len = offset;
  11781. },
  11782. /**
  11783. * 填充 Path 数据。
  11784. * 尽量复用而不申明新的数组。大部分图形重绘的指令数据长度都是不变的。
  11785. */
  11786. addData: function (cmd) {
  11787. var data = this.data;
  11788. if (this._len + arguments.length > data.length) {
  11789. // 因为之前的数组已经转换成静态的 Float32Array
  11790. // 所以不够用时需要扩展一个新的动态数组
  11791. this._expandData();
  11792. data = this.data;
  11793. }
  11794. for (var i = 0; i < arguments.length; i++) {
  11795. data[this._len++] = arguments[i];
  11796. }
  11797. this._prevCmd = cmd;
  11798. },
  11799. _expandData: function () {
  11800. // Only if data is Float32Array
  11801. if (!(this.data instanceof Array)) {
  11802. var newData = [];
  11803. for (var i = 0; i < this._len; i++) {
  11804. newData[i] = this.data[i];
  11805. }
  11806. this.data = newData;
  11807. }
  11808. },
  11809. /**
  11810. * If needs js implemented dashed line
  11811. * @return {boolean}
  11812. * @private
  11813. */
  11814. _needsDash: function () {
  11815. return this._lineDash;
  11816. },
  11817. _dashedLineTo: function (x1, y1) {
  11818. var dashSum = this._dashSum;
  11819. var offset = this._dashOffset;
  11820. var lineDash = this._lineDash;
  11821. var ctx = this._ctx;
  11822. var x0 = this._xi;
  11823. var y0 = this._yi;
  11824. var dx = x1 - x0;
  11825. var dy = y1 - y0;
  11826. var dist = mathSqrt(dx * dx + dy * dy);
  11827. var x = x0;
  11828. var y = y0;
  11829. var dash;
  11830. var nDash = lineDash.length;
  11831. var idx;
  11832. dx /= dist;
  11833. dy /= dist;
  11834. if (offset < 0) {
  11835. // Convert to positive offset
  11836. offset = dashSum + offset;
  11837. }
  11838. offset %= dashSum;
  11839. x -= offset * dx;
  11840. y -= offset * dy;
  11841. while ((dx > 0 && x <= x1) || (dx < 0 && x >= x1)
  11842. || (dx == 0 && ((dy > 0 && y <= y1) || (dy < 0 && y >= y1)))) {
  11843. idx = this._dashIdx;
  11844. dash = lineDash[idx];
  11845. x += dx * dash;
  11846. y += dy * dash;
  11847. this._dashIdx = (idx + 1) % nDash;
  11848. // Skip positive offset
  11849. if ((dx > 0 && x < x0) || (dx < 0 && x > x0) || (dy > 0 && y < y0) || (dy < 0 && y > y0)) {
  11850. continue;
  11851. }
  11852. ctx[idx % 2 ? 'moveTo' : 'lineTo'](
  11853. dx >= 0 ? mathMin(x, x1) : mathMax(x, x1),
  11854. dy >= 0 ? mathMin(y, y1) : mathMax(y, y1)
  11855. );
  11856. }
  11857. // Offset for next lineTo
  11858. dx = x - x1;
  11859. dy = y - y1;
  11860. this._dashOffset = -mathSqrt(dx * dx + dy * dy);
  11861. },
  11862. // Not accurate dashed line to
  11863. _dashedBezierTo: function (x1, y1, x2, y2, x3, y3) {
  11864. var dashSum = this._dashSum;
  11865. var offset = this._dashOffset;
  11866. var lineDash = this._lineDash;
  11867. var ctx = this._ctx;
  11868. var x0 = this._xi;
  11869. var y0 = this._yi;
  11870. var t;
  11871. var dx;
  11872. var dy;
  11873. var cubicAt = curve.cubicAt;
  11874. var bezierLen = 0;
  11875. var idx = this._dashIdx;
  11876. var nDash = lineDash.length;
  11877. var x;
  11878. var y;
  11879. var tmpLen = 0;
  11880. if (offset < 0) {
  11881. // Convert to positive offset
  11882. offset = dashSum + offset;
  11883. }
  11884. offset %= dashSum;
  11885. // Bezier approx length
  11886. for (t = 0; t < 1; t += 0.1) {
  11887. dx = cubicAt(x0, x1, x2, x3, t + 0.1)
  11888. - cubicAt(x0, x1, x2, x3, t);
  11889. dy = cubicAt(y0, y1, y2, y3, t + 0.1)
  11890. - cubicAt(y0, y1, y2, y3, t);
  11891. bezierLen += mathSqrt(dx * dx + dy * dy);
  11892. }
  11893. // Find idx after add offset
  11894. for (; idx < nDash; idx++) {
  11895. tmpLen += lineDash[idx];
  11896. if (tmpLen > offset) {
  11897. break;
  11898. }
  11899. }
  11900. t = (tmpLen - offset) / bezierLen;
  11901. while (t <= 1) {
  11902. x = cubicAt(x0, x1, x2, x3, t);
  11903. y = cubicAt(y0, y1, y2, y3, t);
  11904. // Use line to approximate dashed bezier
  11905. // Bad result if dash is long
  11906. idx % 2 ? ctx.moveTo(x, y)
  11907. : ctx.lineTo(x, y);
  11908. t += lineDash[idx] / bezierLen;
  11909. idx = (idx + 1) % nDash;
  11910. }
  11911. // Finish the last segment and calculate the new offset
  11912. (idx % 2 !== 0) && ctx.lineTo(x3, y3);
  11913. dx = x3 - x;
  11914. dy = y3 - y;
  11915. this._dashOffset = -mathSqrt(dx * dx + dy * dy);
  11916. },
  11917. _dashedQuadraticTo: function (x1, y1, x2, y2) {
  11918. // Convert quadratic to cubic using degree elevation
  11919. var x3 = x2;
  11920. var y3 = y2;
  11921. x2 = (x2 + 2 * x1) / 3;
  11922. y2 = (y2 + 2 * y1) / 3;
  11923. x1 = (this._xi + 2 * x1) / 3;
  11924. y1 = (this._yi + 2 * y1) / 3;
  11925. this._dashedBezierTo(x1, y1, x2, y2, x3, y3);
  11926. },
  11927. /**
  11928. * 转成静态的 Float32Array 减少堆内存占用
  11929. * Convert dynamic array to static Float32Array
  11930. */
  11931. toStatic: function () {
  11932. var data = this.data;
  11933. if (data instanceof Array) {
  11934. data.length = this._len;
  11935. if (hasTypedArray) {
  11936. this.data = new Float32Array(data);
  11937. }
  11938. }
  11939. },
  11940. /**
  11941. * @return {module:zrender/core/BoundingRect}
  11942. */
  11943. getBoundingRect: function () {
  11944. min[0] = min[1] = min2[0] = min2[1] = Number.MAX_VALUE;
  11945. max[0] = max[1] = max2[0] = max2[1] = -Number.MAX_VALUE;
  11946. var data = this.data;
  11947. var xi = 0;
  11948. var yi = 0;
  11949. var x0 = 0;
  11950. var y0 = 0;
  11951. for (var i = 0; i < data.length;) {
  11952. var cmd = data[i++];
  11953. if (i == 1) {
  11954. // 如果第一个命令是 L, C, Q
  11955. // 则 previous point 同绘制命令的第一个 point
  11956. //
  11957. // 第一个命令为 Arc 的情况下会在后面特殊处理
  11958. xi = data[i];
  11959. yi = data[i + 1];
  11960. x0 = xi;
  11961. y0 = yi;
  11962. }
  11963. switch (cmd) {
  11964. case CMD.M:
  11965. // moveTo 命令重新创建一个新的 subpath, 并且更新新的起点
  11966. // 在 closePath 的时候使用
  11967. x0 = data[i++];
  11968. y0 = data[i++];
  11969. xi = x0;
  11970. yi = y0;
  11971. min2[0] = x0;
  11972. min2[1] = y0;
  11973. max2[0] = x0;
  11974. max2[1] = y0;
  11975. break;
  11976. case CMD.L:
  11977. bbox.fromLine(xi, yi, data[i], data[i + 1], min2, max2);
  11978. xi = data[i++];
  11979. yi = data[i++];
  11980. break;
  11981. case CMD.C:
  11982. bbox.fromCubic(
  11983. xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],
  11984. min2, max2
  11985. );
  11986. xi = data[i++];
  11987. yi = data[i++];
  11988. break;
  11989. case CMD.Q:
  11990. bbox.fromQuadratic(
  11991. xi, yi, data[i++], data[i++], data[i], data[i + 1],
  11992. min2, max2
  11993. );
  11994. xi = data[i++];
  11995. yi = data[i++];
  11996. break;
  11997. case CMD.A:
  11998. // TODO Arc 判断的开销比较大
  11999. var cx = data[i++];
  12000. var cy = data[i++];
  12001. var rx = data[i++];
  12002. var ry = data[i++];
  12003. var startAngle = data[i++];
  12004. var endAngle = data[i++] + startAngle;
  12005. // TODO Arc 旋转
  12006. var psi = data[i++];
  12007. var anticlockwise = 1 - data[i++];
  12008. if (i == 1) {
  12009. // 直接使用 arc 命令
  12010. // 第一个命令起点还未定义
  12011. x0 = mathCos(startAngle) * rx + cx;
  12012. y0 = mathSin(startAngle) * ry + cy;
  12013. }
  12014. bbox.fromArc(
  12015. cx, cy, rx, ry, startAngle, endAngle,
  12016. anticlockwise, min2, max2
  12017. );
  12018. xi = mathCos(endAngle) * rx + cx;
  12019. yi = mathSin(endAngle) * ry + cy;
  12020. break;
  12021. case CMD.R:
  12022. x0 = xi = data[i++];
  12023. y0 = yi = data[i++];
  12024. var width = data[i++];
  12025. var height = data[i++];
  12026. // Use fromLine
  12027. bbox.fromLine(x0, y0, x0 + width, y0 + height, min2, max2);
  12028. break;
  12029. case CMD.Z:
  12030. xi = x0;
  12031. yi = y0;
  12032. break;
  12033. }
  12034. // Union
  12035. vec2.min(min, min, min2);
  12036. vec2.max(max, max, max2);
  12037. }
  12038. // No data
  12039. if (i === 0) {
  12040. min[0] = min[1] = max[0] = max[1] = 0;
  12041. }
  12042. return new BoundingRect(
  12043. min[0], min[1], max[0] - min[0], max[1] - min[1]
  12044. );
  12045. },
  12046. /**
  12047. * Rebuild path from current data
  12048. * Rebuild path will not consider javascript implemented line dash.
  12049. * @param {CanvasRenderingContext} ctx
  12050. */
  12051. rebuildPath: function (ctx) {
  12052. var d = this.data;
  12053. var x0, y0;
  12054. var xi, yi;
  12055. var x, y;
  12056. var ux = this._ux;
  12057. var uy = this._uy;
  12058. var len = this._len;
  12059. for (var i = 0; i < len;) {
  12060. var cmd = d[i++];
  12061. if (i == 1) {
  12062. // 如果第一个命令是 L, C, Q
  12063. // 则 previous point 同绘制命令的第一个 point
  12064. //
  12065. // 第一个命令为 Arc 的情况下会在后面特殊处理
  12066. xi = d[i];
  12067. yi = d[i + 1];
  12068. x0 = xi;
  12069. y0 = yi;
  12070. }
  12071. switch (cmd) {
  12072. case CMD.M:
  12073. x0 = xi = d[i++];
  12074. y0 = yi = d[i++];
  12075. ctx.moveTo(xi, yi);
  12076. break;
  12077. case CMD.L:
  12078. x = d[i++];
  12079. y = d[i++];
  12080. // Not draw too small seg between
  12081. if (mathAbs(x - xi) > ux || mathAbs(y - yi) > uy || i === len - 1) {
  12082. ctx.lineTo(x, y);
  12083. xi = x;
  12084. yi = y;
  12085. }
  12086. break;
  12087. case CMD.C:
  12088. ctx.bezierCurveTo(
  12089. d[i++], d[i++], d[i++], d[i++], d[i++], d[i++]
  12090. );
  12091. xi = d[i - 2];
  12092. yi = d[i - 1];
  12093. break;
  12094. case CMD.Q:
  12095. ctx.quadraticCurveTo(d[i++], d[i++], d[i++], d[i++]);
  12096. xi = d[i - 2];
  12097. yi = d[i - 1];
  12098. break;
  12099. case CMD.A:
  12100. var cx = d[i++];
  12101. var cy = d[i++];
  12102. var rx = d[i++];
  12103. var ry = d[i++];
  12104. var theta = d[i++];
  12105. var dTheta = d[i++];
  12106. var psi = d[i++];
  12107. var fs = d[i++];
  12108. var r = (rx > ry) ? rx : ry;
  12109. var scaleX = (rx > ry) ? 1 : rx / ry;
  12110. var scaleY = (rx > ry) ? ry / rx : 1;
  12111. var isEllipse = Math.abs(rx - ry) > 1e-3;
  12112. var endAngle = theta + dTheta;
  12113. if (isEllipse) {
  12114. ctx.translate(cx, cy);
  12115. ctx.rotate(psi);
  12116. ctx.scale(scaleX, scaleY);
  12117. ctx.arc(0, 0, r, theta, endAngle, 1 - fs);
  12118. ctx.scale(1 / scaleX, 1 / scaleY);
  12119. ctx.rotate(-psi);
  12120. ctx.translate(-cx, -cy);
  12121. }
  12122. else {
  12123. ctx.arc(cx, cy, r, theta, endAngle, 1 - fs);
  12124. }
  12125. if (i == 1) {
  12126. // 直接使用 arc 命令
  12127. // 第一个命令起点还未定义
  12128. x0 = mathCos(theta) * rx + cx;
  12129. y0 = mathSin(theta) * ry + cy;
  12130. }
  12131. xi = mathCos(endAngle) * rx + cx;
  12132. yi = mathSin(endAngle) * ry + cy;
  12133. break;
  12134. case CMD.R:
  12135. x0 = xi = d[i];
  12136. y0 = yi = d[i + 1];
  12137. ctx.rect(d[i++], d[i++], d[i++], d[i++]);
  12138. break;
  12139. case CMD.Z:
  12140. ctx.closePath();
  12141. xi = x0;
  12142. yi = y0;
  12143. }
  12144. }
  12145. }
  12146. };
  12147. PathProxy.CMD = CMD;
  12148. module.exports = PathProxy;
  12149. /***/ },
  12150. /* 50 */
  12151. /***/ function(module, exports, __webpack_require__) {
  12152. 'use strict';
  12153. /**
  12154. * 曲线辅助模块
  12155. * @module zrender/core/curve
  12156. * @author pissang(https://www.github.com/pissang)
  12157. */
  12158. var vec2 = __webpack_require__(10);
  12159. var v2Create = vec2.create;
  12160. var v2DistSquare = vec2.distSquare;
  12161. var mathPow = Math.pow;
  12162. var mathSqrt = Math.sqrt;
  12163. var EPSILON = 1e-8;
  12164. var EPSILON_NUMERIC = 1e-4;
  12165. var THREE_SQRT = mathSqrt(3);
  12166. var ONE_THIRD = 1 / 3;
  12167. // 临时变量
  12168. var _v0 = v2Create();
  12169. var _v1 = v2Create();
  12170. var _v2 = v2Create();
  12171. // var _v3 = vec2.create();
  12172. function isAroundZero(val) {
  12173. return val > -EPSILON && val < EPSILON;
  12174. }
  12175. function isNotAroundZero(val) {
  12176. return val > EPSILON || val < -EPSILON;
  12177. }
  12178. /**
  12179. * 计算三次贝塞尔值
  12180. * @memberOf module:zrender/core/curve
  12181. * @param {number} p0
  12182. * @param {number} p1
  12183. * @param {number} p2
  12184. * @param {number} p3
  12185. * @param {number} t
  12186. * @return {number}
  12187. */
  12188. function cubicAt(p0, p1, p2, p3, t) {
  12189. var onet = 1 - t;
  12190. return onet * onet * (onet * p0 + 3 * t * p1)
  12191. + t * t * (t * p3 + 3 * onet * p2);
  12192. }
  12193. /**
  12194. * 计算三次贝塞尔导数值
  12195. * @memberOf module:zrender/core/curve
  12196. * @param {number} p0
  12197. * @param {number} p1
  12198. * @param {number} p2
  12199. * @param {number} p3
  12200. * @param {number} t
  12201. * @return {number}
  12202. */
  12203. function cubicDerivativeAt(p0, p1, p2, p3, t) {
  12204. var onet = 1 - t;
  12205. return 3 * (
  12206. ((p1 - p0) * onet + 2 * (p2 - p1) * t) * onet
  12207. + (p3 - p2) * t * t
  12208. );
  12209. }
  12210. /**
  12211. * 计算三次贝塞尔方程根,使用盛金公式
  12212. * @memberOf module:zrender/core/curve
  12213. * @param {number} p0
  12214. * @param {number} p1
  12215. * @param {number} p2
  12216. * @param {number} p3
  12217. * @param {number} val
  12218. * @param {Array.<number>} roots
  12219. * @return {number} 有效根数目
  12220. */
  12221. function cubicRootAt(p0, p1, p2, p3, val, roots) {
  12222. // Evaluate roots of cubic functions
  12223. var a = p3 + 3 * (p1 - p2) - p0;
  12224. var b = 3 * (p2 - p1 * 2 + p0);
  12225. var c = 3 * (p1 - p0);
  12226. var d = p0 - val;
  12227. var A = b * b - 3 * a * c;
  12228. var B = b * c - 9 * a * d;
  12229. var C = c * c - 3 * b * d;
  12230. var n = 0;
  12231. if (isAroundZero(A) && isAroundZero(B)) {
  12232. if (isAroundZero(b)) {
  12233. roots[0] = 0;
  12234. }
  12235. else {
  12236. var t1 = -c / b; //t1, t2, t3, b is not zero
  12237. if (t1 >= 0 && t1 <= 1) {
  12238. roots[n++] = t1;
  12239. }
  12240. }
  12241. }
  12242. else {
  12243. var disc = B * B - 4 * A * C;
  12244. if (isAroundZero(disc)) {
  12245. var K = B / A;
  12246. var t1 = -b / a + K; // t1, a is not zero
  12247. var t2 = -K / 2; // t2, t3
  12248. if (t1 >= 0 && t1 <= 1) {
  12249. roots[n++] = t1;
  12250. }
  12251. if (t2 >= 0 && t2 <= 1) {
  12252. roots[n++] = t2;
  12253. }
  12254. }
  12255. else if (disc > 0) {
  12256. var discSqrt = mathSqrt(disc);
  12257. var Y1 = A * b + 1.5 * a * (-B + discSqrt);
  12258. var Y2 = A * b + 1.5 * a * (-B - discSqrt);
  12259. if (Y1 < 0) {
  12260. Y1 = -mathPow(-Y1, ONE_THIRD);
  12261. }
  12262. else {
  12263. Y1 = mathPow(Y1, ONE_THIRD);
  12264. }
  12265. if (Y2 < 0) {
  12266. Y2 = -mathPow(-Y2, ONE_THIRD);
  12267. }
  12268. else {
  12269. Y2 = mathPow(Y2, ONE_THIRD);
  12270. }
  12271. var t1 = (-b - (Y1 + Y2)) / (3 * a);
  12272. if (t1 >= 0 && t1 <= 1) {
  12273. roots[n++] = t1;
  12274. }
  12275. }
  12276. else {
  12277. var T = (2 * A * b - 3 * a * B) / (2 * mathSqrt(A * A * A));
  12278. var theta = Math.acos(T) / 3;
  12279. var ASqrt = mathSqrt(A);
  12280. var tmp = Math.cos(theta);
  12281. var t1 = (-b - 2 * ASqrt * tmp) / (3 * a);
  12282. var t2 = (-b + ASqrt * (tmp + THREE_SQRT * Math.sin(theta))) / (3 * a);
  12283. var t3 = (-b + ASqrt * (tmp - THREE_SQRT * Math.sin(theta))) / (3 * a);
  12284. if (t1 >= 0 && t1 <= 1) {
  12285. roots[n++] = t1;
  12286. }
  12287. if (t2 >= 0 && t2 <= 1) {
  12288. roots[n++] = t2;
  12289. }
  12290. if (t3 >= 0 && t3 <= 1) {
  12291. roots[n++] = t3;
  12292. }
  12293. }
  12294. }
  12295. return n;
  12296. }
  12297. /**
  12298. * 计算三次贝塞尔方程极限值的位置
  12299. * @memberOf module:zrender/core/curve
  12300. * @param {number} p0
  12301. * @param {number} p1
  12302. * @param {number} p2
  12303. * @param {number} p3
  12304. * @param {Array.<number>} extrema
  12305. * @return {number} 有效数目
  12306. */
  12307. function cubicExtrema(p0, p1, p2, p3, extrema) {
  12308. var b = 6 * p2 - 12 * p1 + 6 * p0;
  12309. var a = 9 * p1 + 3 * p3 - 3 * p0 - 9 * p2;
  12310. var c = 3 * p1 - 3 * p0;
  12311. var n = 0;
  12312. if (isAroundZero(a)) {
  12313. if (isNotAroundZero(b)) {
  12314. var t1 = -c / b;
  12315. if (t1 >= 0 && t1 <=1) {
  12316. extrema[n++] = t1;
  12317. }
  12318. }
  12319. }
  12320. else {
  12321. var disc = b * b - 4 * a * c;
  12322. if (isAroundZero(disc)) {
  12323. extrema[0] = -b / (2 * a);
  12324. }
  12325. else if (disc > 0) {
  12326. var discSqrt = mathSqrt(disc);
  12327. var t1 = (-b + discSqrt) / (2 * a);
  12328. var t2 = (-b - discSqrt) / (2 * a);
  12329. if (t1 >= 0 && t1 <= 1) {
  12330. extrema[n++] = t1;
  12331. }
  12332. if (t2 >= 0 && t2 <= 1) {
  12333. extrema[n++] = t2;
  12334. }
  12335. }
  12336. }
  12337. return n;
  12338. }
  12339. /**
  12340. * 细分三次贝塞尔曲线
  12341. * @memberOf module:zrender/core/curve
  12342. * @param {number} p0
  12343. * @param {number} p1
  12344. * @param {number} p2
  12345. * @param {number} p3
  12346. * @param {number} t
  12347. * @param {Array.<number>} out
  12348. */
  12349. function cubicSubdivide(p0, p1, p2, p3, t, out) {
  12350. var p01 = (p1 - p0) * t + p0;
  12351. var p12 = (p2 - p1) * t + p1;
  12352. var p23 = (p3 - p2) * t + p2;
  12353. var p012 = (p12 - p01) * t + p01;
  12354. var p123 = (p23 - p12) * t + p12;
  12355. var p0123 = (p123 - p012) * t + p012;
  12356. // Seg0
  12357. out[0] = p0;
  12358. out[1] = p01;
  12359. out[2] = p012;
  12360. out[3] = p0123;
  12361. // Seg1
  12362. out[4] = p0123;
  12363. out[5] = p123;
  12364. out[6] = p23;
  12365. out[7] = p3;
  12366. }
  12367. /**
  12368. * 投射点到三次贝塞尔曲线上,返回投射距离。
  12369. * 投射点有可能会有一个或者多个,这里只返回其中距离最短的一个。
  12370. * @param {number} x0
  12371. * @param {number} y0
  12372. * @param {number} x1
  12373. * @param {number} y1
  12374. * @param {number} x2
  12375. * @param {number} y2
  12376. * @param {number} x3
  12377. * @param {number} y3
  12378. * @param {number} x
  12379. * @param {number} y
  12380. * @param {Array.<number>} [out] 投射点
  12381. * @return {number}
  12382. */
  12383. function cubicProjectPoint(
  12384. x0, y0, x1, y1, x2, y2, x3, y3,
  12385. x, y, out
  12386. ) {
  12387. // http://pomax.github.io/bezierinfo/#projections
  12388. var t;
  12389. var interval = 0.005;
  12390. var d = Infinity;
  12391. var prev;
  12392. var next;
  12393. var d1;
  12394. var d2;
  12395. _v0[0] = x;
  12396. _v0[1] = y;
  12397. // 先粗略估计一下可能的最小距离的 t 值
  12398. // PENDING
  12399. for (var _t = 0; _t < 1; _t += 0.05) {
  12400. _v1[0] = cubicAt(x0, x1, x2, x3, _t);
  12401. _v1[1] = cubicAt(y0, y1, y2, y3, _t);
  12402. d1 = v2DistSquare(_v0, _v1);
  12403. if (d1 < d) {
  12404. t = _t;
  12405. d = d1;
  12406. }
  12407. }
  12408. d = Infinity;
  12409. // At most 32 iteration
  12410. for (var i = 0; i < 32; i++) {
  12411. if (interval < EPSILON_NUMERIC) {
  12412. break;
  12413. }
  12414. prev = t - interval;
  12415. next = t + interval;
  12416. // t - interval
  12417. _v1[0] = cubicAt(x0, x1, x2, x3, prev);
  12418. _v1[1] = cubicAt(y0, y1, y2, y3, prev);
  12419. d1 = v2DistSquare(_v1, _v0);
  12420. if (prev >= 0 && d1 < d) {
  12421. t = prev;
  12422. d = d1;
  12423. }
  12424. else {
  12425. // t + interval
  12426. _v2[0] = cubicAt(x0, x1, x2, x3, next);
  12427. _v2[1] = cubicAt(y0, y1, y2, y3, next);
  12428. d2 = v2DistSquare(_v2, _v0);
  12429. if (next <= 1 && d2 < d) {
  12430. t = next;
  12431. d = d2;
  12432. }
  12433. else {
  12434. interval *= 0.5;
  12435. }
  12436. }
  12437. }
  12438. // t
  12439. if (out) {
  12440. out[0] = cubicAt(x0, x1, x2, x3, t);
  12441. out[1] = cubicAt(y0, y1, y2, y3, t);
  12442. }
  12443. // console.log(interval, i);
  12444. return mathSqrt(d);
  12445. }
  12446. /**
  12447. * 计算二次方贝塞尔值
  12448. * @param {number} p0
  12449. * @param {number} p1
  12450. * @param {number} p2
  12451. * @param {number} t
  12452. * @return {number}
  12453. */
  12454. function quadraticAt(p0, p1, p2, t) {
  12455. var onet = 1 - t;
  12456. return onet * (onet * p0 + 2 * t * p1) + t * t * p2;
  12457. }
  12458. /**
  12459. * 计算二次方贝塞尔导数值
  12460. * @param {number} p0
  12461. * @param {number} p1
  12462. * @param {number} p2
  12463. * @param {number} t
  12464. * @return {number}
  12465. */
  12466. function quadraticDerivativeAt(p0, p1, p2, t) {
  12467. return 2 * ((1 - t) * (p1 - p0) + t * (p2 - p1));
  12468. }
  12469. /**
  12470. * 计算二次方贝塞尔方程根
  12471. * @param {number} p0
  12472. * @param {number} p1
  12473. * @param {number} p2
  12474. * @param {number} t
  12475. * @param {Array.<number>} roots
  12476. * @return {number} 有效根数目
  12477. */
  12478. function quadraticRootAt(p0, p1, p2, val, roots) {
  12479. var a = p0 - 2 * p1 + p2;
  12480. var b = 2 * (p1 - p0);
  12481. var c = p0 - val;
  12482. var n = 0;
  12483. if (isAroundZero(a)) {
  12484. if (isNotAroundZero(b)) {
  12485. var t1 = -c / b;
  12486. if (t1 >= 0 && t1 <= 1) {
  12487. roots[n++] = t1;
  12488. }
  12489. }
  12490. }
  12491. else {
  12492. var disc = b * b - 4 * a * c;
  12493. if (isAroundZero(disc)) {
  12494. var t1 = -b / (2 * a);
  12495. if (t1 >= 0 && t1 <= 1) {
  12496. roots[n++] = t1;
  12497. }
  12498. }
  12499. else if (disc > 0) {
  12500. var discSqrt = mathSqrt(disc);
  12501. var t1 = (-b + discSqrt) / (2 * a);
  12502. var t2 = (-b - discSqrt) / (2 * a);
  12503. if (t1 >= 0 && t1 <= 1) {
  12504. roots[n++] = t1;
  12505. }
  12506. if (t2 >= 0 && t2 <= 1) {
  12507. roots[n++] = t2;
  12508. }
  12509. }
  12510. }
  12511. return n;
  12512. }
  12513. /**
  12514. * 计算二次贝塞尔方程极限值
  12515. * @memberOf module:zrender/core/curve
  12516. * @param {number} p0
  12517. * @param {number} p1
  12518. * @param {number} p2
  12519. * @return {number}
  12520. */
  12521. function quadraticExtremum(p0, p1, p2) {
  12522. var divider = p0 + p2 - 2 * p1;
  12523. if (divider === 0) {
  12524. // p1 is center of p0 and p2
  12525. return 0.5;
  12526. }
  12527. else {
  12528. return (p0 - p1) / divider;
  12529. }
  12530. }
  12531. /**
  12532. * 细分二次贝塞尔曲线
  12533. * @memberOf module:zrender/core/curve
  12534. * @param {number} p0
  12535. * @param {number} p1
  12536. * @param {number} p2
  12537. * @param {number} t
  12538. * @param {Array.<number>} out
  12539. */
  12540. function quadraticSubdivide(p0, p1, p2, t, out) {
  12541. var p01 = (p1 - p0) * t + p0;
  12542. var p12 = (p2 - p1) * t + p1;
  12543. var p012 = (p12 - p01) * t + p01;
  12544. // Seg0
  12545. out[0] = p0;
  12546. out[1] = p01;
  12547. out[2] = p012;
  12548. // Seg1
  12549. out[3] = p012;
  12550. out[4] = p12;
  12551. out[5] = p2;
  12552. }
  12553. /**
  12554. * 投射点到二次贝塞尔曲线上,返回投射距离。
  12555. * 投射点有可能会有一个或者多个,这里只返回其中距离最短的一个。
  12556. * @param {number} x0
  12557. * @param {number} y0
  12558. * @param {number} x1
  12559. * @param {number} y1
  12560. * @param {number} x2
  12561. * @param {number} y2
  12562. * @param {number} x
  12563. * @param {number} y
  12564. * @param {Array.<number>} out 投射点
  12565. * @return {number}
  12566. */
  12567. function quadraticProjectPoint(
  12568. x0, y0, x1, y1, x2, y2,
  12569. x, y, out
  12570. ) {
  12571. // http://pomax.github.io/bezierinfo/#projections
  12572. var t;
  12573. var interval = 0.005;
  12574. var d = Infinity;
  12575. _v0[0] = x;
  12576. _v0[1] = y;
  12577. // 先粗略估计一下可能的最小距离的 t 值
  12578. // PENDING
  12579. for (var _t = 0; _t < 1; _t += 0.05) {
  12580. _v1[0] = quadraticAt(x0, x1, x2, _t);
  12581. _v1[1] = quadraticAt(y0, y1, y2, _t);
  12582. var d1 = v2DistSquare(_v0, _v1);
  12583. if (d1 < d) {
  12584. t = _t;
  12585. d = d1;
  12586. }
  12587. }
  12588. d = Infinity;
  12589. // At most 32 iteration
  12590. for (var i = 0; i < 32; i++) {
  12591. if (interval < EPSILON_NUMERIC) {
  12592. break;
  12593. }
  12594. var prev = t - interval;
  12595. var next = t + interval;
  12596. // t - interval
  12597. _v1[0] = quadraticAt(x0, x1, x2, prev);
  12598. _v1[1] = quadraticAt(y0, y1, y2, prev);
  12599. var d1 = v2DistSquare(_v1, _v0);
  12600. if (prev >= 0 && d1 < d) {
  12601. t = prev;
  12602. d = d1;
  12603. }
  12604. else {
  12605. // t + interval
  12606. _v2[0] = quadraticAt(x0, x1, x2, next);
  12607. _v2[1] = quadraticAt(y0, y1, y2, next);
  12608. var d2 = v2DistSquare(_v2, _v0);
  12609. if (next <= 1 && d2 < d) {
  12610. t = next;
  12611. d = d2;
  12612. }
  12613. else {
  12614. interval *= 0.5;
  12615. }
  12616. }
  12617. }
  12618. // t
  12619. if (out) {
  12620. out[0] = quadraticAt(x0, x1, x2, t);
  12621. out[1] = quadraticAt(y0, y1, y2, t);
  12622. }
  12623. // console.log(interval, i);
  12624. return mathSqrt(d);
  12625. }
  12626. module.exports = {
  12627. cubicAt: cubicAt,
  12628. cubicDerivativeAt: cubicDerivativeAt,
  12629. cubicRootAt: cubicRootAt,
  12630. cubicExtrema: cubicExtrema,
  12631. cubicSubdivide: cubicSubdivide,
  12632. cubicProjectPoint: cubicProjectPoint,
  12633. quadraticAt: quadraticAt,
  12634. quadraticDerivativeAt: quadraticDerivativeAt,
  12635. quadraticRootAt: quadraticRootAt,
  12636. quadraticExtremum: quadraticExtremum,
  12637. quadraticSubdivide: quadraticSubdivide,
  12638. quadraticProjectPoint: quadraticProjectPoint
  12639. };
  12640. /***/ },
  12641. /* 51 */
  12642. /***/ function(module, exports, __webpack_require__) {
  12643. /**
  12644. * @author Yi Shen(https://github.com/pissang)
  12645. */
  12646. var vec2 = __webpack_require__(10);
  12647. var curve = __webpack_require__(50);
  12648. var bbox = {};
  12649. var mathMin = Math.min;
  12650. var mathMax = Math.max;
  12651. var mathSin = Math.sin;
  12652. var mathCos = Math.cos;
  12653. var start = vec2.create();
  12654. var end = vec2.create();
  12655. var extremity = vec2.create();
  12656. var PI2 = Math.PI * 2;
  12657. /**
  12658. * 从顶点数组中计算出最小包围盒,写入`min`和`max`中
  12659. * @module zrender/core/bbox
  12660. * @param {Array<Object>} points 顶点数组
  12661. * @param {number} min
  12662. * @param {number} max
  12663. */
  12664. bbox.fromPoints = function(points, min, max) {
  12665. if (points.length === 0) {
  12666. return;
  12667. }
  12668. var p = points[0];
  12669. var left = p[0];
  12670. var right = p[0];
  12671. var top = p[1];
  12672. var bottom = p[1];
  12673. var i;
  12674. for (i = 1; i < points.length; i++) {
  12675. p = points[i];
  12676. left = mathMin(left, p[0]);
  12677. right = mathMax(right, p[0]);
  12678. top = mathMin(top, p[1]);
  12679. bottom = mathMax(bottom, p[1]);
  12680. }
  12681. min[0] = left;
  12682. min[1] = top;
  12683. max[0] = right;
  12684. max[1] = bottom;
  12685. };
  12686. /**
  12687. * @memberOf module:zrender/core/bbox
  12688. * @param {number} x0
  12689. * @param {number} y0
  12690. * @param {number} x1
  12691. * @param {number} y1
  12692. * @param {Array.<number>} min
  12693. * @param {Array.<number>} max
  12694. */
  12695. bbox.fromLine = function (x0, y0, x1, y1, min, max) {
  12696. min[0] = mathMin(x0, x1);
  12697. min[1] = mathMin(y0, y1);
  12698. max[0] = mathMax(x0, x1);
  12699. max[1] = mathMax(y0, y1);
  12700. };
  12701. var xDim = [];
  12702. var yDim = [];
  12703. /**
  12704. * 从三阶贝塞尔曲线(p0, p1, p2, p3)中计算出最小包围盒,写入`min`和`max`中
  12705. * @memberOf module:zrender/core/bbox
  12706. * @param {number} x0
  12707. * @param {number} y0
  12708. * @param {number} x1
  12709. * @param {number} y1
  12710. * @param {number} x2
  12711. * @param {number} y2
  12712. * @param {number} x3
  12713. * @param {number} y3
  12714. * @param {Array.<number>} min
  12715. * @param {Array.<number>} max
  12716. */
  12717. bbox.fromCubic = function(
  12718. x0, y0, x1, y1, x2, y2, x3, y3, min, max
  12719. ) {
  12720. var cubicExtrema = curve.cubicExtrema;
  12721. var cubicAt = curve.cubicAt;
  12722. var i;
  12723. var n = cubicExtrema(x0, x1, x2, x3, xDim);
  12724. min[0] = Infinity;
  12725. min[1] = Infinity;
  12726. max[0] = -Infinity;
  12727. max[1] = -Infinity;
  12728. for (i = 0; i < n; i++) {
  12729. var x = cubicAt(x0, x1, x2, x3, xDim[i]);
  12730. min[0] = mathMin(x, min[0]);
  12731. max[0] = mathMax(x, max[0]);
  12732. }
  12733. n = cubicExtrema(y0, y1, y2, y3, yDim);
  12734. for (i = 0; i < n; i++) {
  12735. var y = cubicAt(y0, y1, y2, y3, yDim[i]);
  12736. min[1] = mathMin(y, min[1]);
  12737. max[1] = mathMax(y, max[1]);
  12738. }
  12739. min[0] = mathMin(x0, min[0]);
  12740. max[0] = mathMax(x0, max[0]);
  12741. min[0] = mathMin(x3, min[0]);
  12742. max[0] = mathMax(x3, max[0]);
  12743. min[1] = mathMin(y0, min[1]);
  12744. max[1] = mathMax(y0, max[1]);
  12745. min[1] = mathMin(y3, min[1]);
  12746. max[1] = mathMax(y3, max[1]);
  12747. };
  12748. /**
  12749. * 从二阶贝塞尔曲线(p0, p1, p2)中计算出最小包围盒,写入`min`和`max`中
  12750. * @memberOf module:zrender/core/bbox
  12751. * @param {number} x0
  12752. * @param {number} y0
  12753. * @param {number} x1
  12754. * @param {number} y1
  12755. * @param {number} x2
  12756. * @param {number} y2
  12757. * @param {Array.<number>} min
  12758. * @param {Array.<number>} max
  12759. */
  12760. bbox.fromQuadratic = function(x0, y0, x1, y1, x2, y2, min, max) {
  12761. var quadraticExtremum = curve.quadraticExtremum;
  12762. var quadraticAt = curve.quadraticAt;
  12763. // Find extremities, where derivative in x dim or y dim is zero
  12764. var tx =
  12765. mathMax(
  12766. mathMin(quadraticExtremum(x0, x1, x2), 1), 0
  12767. );
  12768. var ty =
  12769. mathMax(
  12770. mathMin(quadraticExtremum(y0, y1, y2), 1), 0
  12771. );
  12772. var x = quadraticAt(x0, x1, x2, tx);
  12773. var y = quadraticAt(y0, y1, y2, ty);
  12774. min[0] = mathMin(x0, x2, x);
  12775. min[1] = mathMin(y0, y2, y);
  12776. max[0] = mathMax(x0, x2, x);
  12777. max[1] = mathMax(y0, y2, y);
  12778. };
  12779. /**
  12780. * 从圆弧中计算出最小包围盒,写入`min`和`max`中
  12781. * @method
  12782. * @memberOf module:zrender/core/bbox
  12783. * @param {number} x
  12784. * @param {number} y
  12785. * @param {number} rx
  12786. * @param {number} ry
  12787. * @param {number} startAngle
  12788. * @param {number} endAngle
  12789. * @param {number} anticlockwise
  12790. * @param {Array.<number>} min
  12791. * @param {Array.<number>} max
  12792. */
  12793. bbox.fromArc = function (
  12794. x, y, rx, ry, startAngle, endAngle, anticlockwise, min, max
  12795. ) {
  12796. var vec2Min = vec2.min;
  12797. var vec2Max = vec2.max;
  12798. var diff = Math.abs(startAngle - endAngle);
  12799. if (diff % PI2 < 1e-4 && diff > 1e-4) {
  12800. // Is a circle
  12801. min[0] = x - rx;
  12802. min[1] = y - ry;
  12803. max[0] = x + rx;
  12804. max[1] = y + ry;
  12805. return;
  12806. }
  12807. start[0] = mathCos(startAngle) * rx + x;
  12808. start[1] = mathSin(startAngle) * ry + y;
  12809. end[0] = mathCos(endAngle) * rx + x;
  12810. end[1] = mathSin(endAngle) * ry + y;
  12811. vec2Min(min, start, end);
  12812. vec2Max(max, start, end);
  12813. // Thresh to [0, Math.PI * 2]
  12814. startAngle = startAngle % (PI2);
  12815. if (startAngle < 0) {
  12816. startAngle = startAngle + PI2;
  12817. }
  12818. endAngle = endAngle % (PI2);
  12819. if (endAngle < 0) {
  12820. endAngle = endAngle + PI2;
  12821. }
  12822. if (startAngle > endAngle && !anticlockwise) {
  12823. endAngle += PI2;
  12824. }
  12825. else if (startAngle < endAngle && anticlockwise) {
  12826. startAngle += PI2;
  12827. }
  12828. if (anticlockwise) {
  12829. var tmp = endAngle;
  12830. endAngle = startAngle;
  12831. startAngle = tmp;
  12832. }
  12833. // var number = 0;
  12834. // var step = (anticlockwise ? -Math.PI : Math.PI) / 2;
  12835. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  12836. if (angle > startAngle) {
  12837. extremity[0] = mathCos(angle) * rx + x;
  12838. extremity[1] = mathSin(angle) * ry + y;
  12839. vec2Min(min, extremity, min);
  12840. vec2Max(max, extremity, max);
  12841. }
  12842. }
  12843. };
  12844. module.exports = bbox;
  12845. /***/ },
  12846. /* 52 */
  12847. /***/ function(module, exports, __webpack_require__) {
  12848. 'use strict';
  12849. var CMD = __webpack_require__(49).CMD;
  12850. var line = __webpack_require__(53);
  12851. var cubic = __webpack_require__(54);
  12852. var quadratic = __webpack_require__(55);
  12853. var arc = __webpack_require__(56);
  12854. var normalizeRadian = __webpack_require__(57).normalizeRadian;
  12855. var curve = __webpack_require__(50);
  12856. var windingLine = __webpack_require__(58);
  12857. var containStroke = line.containStroke;
  12858. var PI2 = Math.PI * 2;
  12859. var EPSILON = 1e-4;
  12860. function isAroundEqual(a, b) {
  12861. return Math.abs(a - b) < EPSILON;
  12862. }
  12863. // 临时数组
  12864. var roots = [-1, -1, -1];
  12865. var extrema = [-1, -1];
  12866. function swapExtrema() {
  12867. var tmp = extrema[0];
  12868. extrema[0] = extrema[1];
  12869. extrema[1] = tmp;
  12870. }
  12871. function windingCubic(x0, y0, x1, y1, x2, y2, x3, y3, x, y) {
  12872. // Quick reject
  12873. if (
  12874. (y > y0 && y > y1 && y > y2 && y > y3)
  12875. || (y < y0 && y < y1 && y < y2 && y < y3)
  12876. ) {
  12877. return 0;
  12878. }
  12879. var nRoots = curve.cubicRootAt(y0, y1, y2, y3, y, roots);
  12880. if (nRoots === 0) {
  12881. return 0;
  12882. }
  12883. else {
  12884. var w = 0;
  12885. var nExtrema = -1;
  12886. var y0_, y1_;
  12887. for (var i = 0; i < nRoots; i++) {
  12888. var t = roots[i];
  12889. // Avoid winding error when intersection point is the connect point of two line of polygon
  12890. var unit = (t === 0 || t === 1) ? 0.5 : 1;
  12891. var x_ = curve.cubicAt(x0, x1, x2, x3, t);
  12892. if (x_ < x) { // Quick reject
  12893. continue;
  12894. }
  12895. if (nExtrema < 0) {
  12896. nExtrema = curve.cubicExtrema(y0, y1, y2, y3, extrema);
  12897. if (extrema[1] < extrema[0] && nExtrema > 1) {
  12898. swapExtrema();
  12899. }
  12900. y0_ = curve.cubicAt(y0, y1, y2, y3, extrema[0]);
  12901. if (nExtrema > 1) {
  12902. y1_ = curve.cubicAt(y0, y1, y2, y3, extrema[1]);
  12903. }
  12904. }
  12905. if (nExtrema == 2) {
  12906. // 分成三段单调函数
  12907. if (t < extrema[0]) {
  12908. w += y0_ < y0 ? unit : -unit;
  12909. }
  12910. else if (t < extrema[1]) {
  12911. w += y1_ < y0_ ? unit : -unit;
  12912. }
  12913. else {
  12914. w += y3 < y1_ ? unit : -unit;
  12915. }
  12916. }
  12917. else {
  12918. // 分成两段单调函数
  12919. if (t < extrema[0]) {
  12920. w += y0_ < y0 ? unit : -unit;
  12921. }
  12922. else {
  12923. w += y3 < y0_ ? unit : -unit;
  12924. }
  12925. }
  12926. }
  12927. return w;
  12928. }
  12929. }
  12930. function windingQuadratic(x0, y0, x1, y1, x2, y2, x, y) {
  12931. // Quick reject
  12932. if (
  12933. (y > y0 && y > y1 && y > y2)
  12934. || (y < y0 && y < y1 && y < y2)
  12935. ) {
  12936. return 0;
  12937. }
  12938. var nRoots = curve.quadraticRootAt(y0, y1, y2, y, roots);
  12939. if (nRoots === 0) {
  12940. return 0;
  12941. }
  12942. else {
  12943. var t = curve.quadraticExtremum(y0, y1, y2);
  12944. if (t >= 0 && t <= 1) {
  12945. var w = 0;
  12946. var y_ = curve.quadraticAt(y0, y1, y2, t);
  12947. for (var i = 0; i < nRoots; i++) {
  12948. // Remove one endpoint.
  12949. var unit = (roots[i] === 0 || roots[i] === 1) ? 0.5 : 1;
  12950. var x_ = curve.quadraticAt(x0, x1, x2, roots[i]);
  12951. if (x_ < x) { // Quick reject
  12952. continue;
  12953. }
  12954. if (roots[i] < t) {
  12955. w += y_ < y0 ? unit : -unit;
  12956. }
  12957. else {
  12958. w += y2 < y_ ? unit : -unit;
  12959. }
  12960. }
  12961. return w;
  12962. }
  12963. else {
  12964. // Remove one endpoint.
  12965. var unit = (roots[0] === 0 || roots[0] === 1) ? 0.5 : 1;
  12966. var x_ = curve.quadraticAt(x0, x1, x2, roots[0]);
  12967. if (x_ < x) { // Quick reject
  12968. return 0;
  12969. }
  12970. return y2 < y0 ? unit : -unit;
  12971. }
  12972. }
  12973. }
  12974. // TODO
  12975. // Arc 旋转
  12976. function windingArc(
  12977. cx, cy, r, startAngle, endAngle, anticlockwise, x, y
  12978. ) {
  12979. y -= cy;
  12980. if (y > r || y < -r) {
  12981. return 0;
  12982. }
  12983. var tmp = Math.sqrt(r * r - y * y);
  12984. roots[0] = -tmp;
  12985. roots[1] = tmp;
  12986. var diff = Math.abs(startAngle - endAngle);
  12987. if (diff < 1e-4) {
  12988. return 0;
  12989. }
  12990. if (diff % PI2 < 1e-4) {
  12991. // Is a circle
  12992. startAngle = 0;
  12993. endAngle = PI2;
  12994. var dir = anticlockwise ? 1 : -1;
  12995. if (x >= roots[0] + cx && x <= roots[1] + cx) {
  12996. return dir;
  12997. } else {
  12998. return 0;
  12999. }
  13000. }
  13001. if (anticlockwise) {
  13002. var tmp = startAngle;
  13003. startAngle = normalizeRadian(endAngle);
  13004. endAngle = normalizeRadian(tmp);
  13005. }
  13006. else {
  13007. startAngle = normalizeRadian(startAngle);
  13008. endAngle = normalizeRadian(endAngle);
  13009. }
  13010. if (startAngle > endAngle) {
  13011. endAngle += PI2;
  13012. }
  13013. var w = 0;
  13014. for (var i = 0; i < 2; i++) {
  13015. var x_ = roots[i];
  13016. if (x_ + cx > x) {
  13017. var angle = Math.atan2(y, x_);
  13018. var dir = anticlockwise ? 1 : -1;
  13019. if (angle < 0) {
  13020. angle = PI2 + angle;
  13021. }
  13022. if (
  13023. (angle >= startAngle && angle <= endAngle)
  13024. || (angle + PI2 >= startAngle && angle + PI2 <= endAngle)
  13025. ) {
  13026. if (angle > Math.PI / 2 && angle < Math.PI * 1.5) {
  13027. dir = -dir;
  13028. }
  13029. w += dir;
  13030. }
  13031. }
  13032. }
  13033. return w;
  13034. }
  13035. function containPath(data, lineWidth, isStroke, x, y) {
  13036. var w = 0;
  13037. var xi = 0;
  13038. var yi = 0;
  13039. var x0 = 0;
  13040. var y0 = 0;
  13041. for (var i = 0; i < data.length;) {
  13042. var cmd = data[i++];
  13043. // Begin a new subpath
  13044. if (cmd === CMD.M && i > 1) {
  13045. // Close previous subpath
  13046. if (!isStroke) {
  13047. w += windingLine(xi, yi, x0, y0, x, y);
  13048. }
  13049. // 如果被任何一个 subpath 包含
  13050. // if (w !== 0) {
  13051. // return true;
  13052. // }
  13053. }
  13054. if (i == 1) {
  13055. // 如果第一个命令是 L, C, Q
  13056. // 则 previous point 同绘制命令的第一个 point
  13057. //
  13058. // 第一个命令为 Arc 的情况下会在后面特殊处理
  13059. xi = data[i];
  13060. yi = data[i + 1];
  13061. x0 = xi;
  13062. y0 = yi;
  13063. }
  13064. switch (cmd) {
  13065. case CMD.M:
  13066. // moveTo 命令重新创建一个新的 subpath, 并且更新新的起点
  13067. // 在 closePath 的时候使用
  13068. x0 = data[i++];
  13069. y0 = data[i++];
  13070. xi = x0;
  13071. yi = y0;
  13072. break;
  13073. case CMD.L:
  13074. if (isStroke) {
  13075. if (containStroke(xi, yi, data[i], data[i + 1], lineWidth, x, y)) {
  13076. return true;
  13077. }
  13078. }
  13079. else {
  13080. // NOTE 在第一个命令为 L, C, Q 的时候会计算出 NaN
  13081. w += windingLine(xi, yi, data[i], data[i + 1], x, y) || 0;
  13082. }
  13083. xi = data[i++];
  13084. yi = data[i++];
  13085. break;
  13086. case CMD.C:
  13087. if (isStroke) {
  13088. if (cubic.containStroke(xi, yi,
  13089. data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],
  13090. lineWidth, x, y
  13091. )) {
  13092. return true;
  13093. }
  13094. }
  13095. else {
  13096. w += windingCubic(
  13097. xi, yi,
  13098. data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],
  13099. x, y
  13100. ) || 0;
  13101. }
  13102. xi = data[i++];
  13103. yi = data[i++];
  13104. break;
  13105. case CMD.Q:
  13106. if (isStroke) {
  13107. if (quadratic.containStroke(xi, yi,
  13108. data[i++], data[i++], data[i], data[i + 1],
  13109. lineWidth, x, y
  13110. )) {
  13111. return true;
  13112. }
  13113. }
  13114. else {
  13115. w += windingQuadratic(
  13116. xi, yi,
  13117. data[i++], data[i++], data[i], data[i + 1],
  13118. x, y
  13119. ) || 0;
  13120. }
  13121. xi = data[i++];
  13122. yi = data[i++];
  13123. break;
  13124. case CMD.A:
  13125. // TODO Arc 判断的开销比较大
  13126. var cx = data[i++];
  13127. var cy = data[i++];
  13128. var rx = data[i++];
  13129. var ry = data[i++];
  13130. var theta = data[i++];
  13131. var dTheta = data[i++];
  13132. // TODO Arc 旋转
  13133. var psi = data[i++];
  13134. var anticlockwise = 1 - data[i++];
  13135. var x1 = Math.cos(theta) * rx + cx;
  13136. var y1 = Math.sin(theta) * ry + cy;
  13137. // 不是直接使用 arc 命令
  13138. if (i > 1) {
  13139. w += windingLine(xi, yi, x1, y1, x, y);
  13140. }
  13141. else {
  13142. // 第一个命令起点还未定义
  13143. x0 = x1;
  13144. y0 = y1;
  13145. }
  13146. // zr 使用scale来模拟椭圆, 这里也对x做一定的缩放
  13147. var _x = (x - cx) * ry / rx + cx;
  13148. if (isStroke) {
  13149. if (arc.containStroke(
  13150. cx, cy, ry, theta, theta + dTheta, anticlockwise,
  13151. lineWidth, _x, y
  13152. )) {
  13153. return true;
  13154. }
  13155. }
  13156. else {
  13157. w += windingArc(
  13158. cx, cy, ry, theta, theta + dTheta, anticlockwise,
  13159. _x, y
  13160. );
  13161. }
  13162. xi = Math.cos(theta + dTheta) * rx + cx;
  13163. yi = Math.sin(theta + dTheta) * ry + cy;
  13164. break;
  13165. case CMD.R:
  13166. x0 = xi = data[i++];
  13167. y0 = yi = data[i++];
  13168. var width = data[i++];
  13169. var height = data[i++];
  13170. var x1 = x0 + width;
  13171. var y1 = y0 + height;
  13172. if (isStroke) {
  13173. if (containStroke(x0, y0, x1, y0, lineWidth, x, y)
  13174. || containStroke(x1, y0, x1, y1, lineWidth, x, y)
  13175. || containStroke(x1, y1, x0, y1, lineWidth, x, y)
  13176. || containStroke(x0, y1, x0, y0, lineWidth, x, y)
  13177. ) {
  13178. return true;
  13179. }
  13180. }
  13181. else {
  13182. // FIXME Clockwise ?
  13183. w += windingLine(x1, y0, x1, y1, x, y);
  13184. w += windingLine(x0, y1, x0, y0, x, y);
  13185. }
  13186. break;
  13187. case CMD.Z:
  13188. if (isStroke) {
  13189. if (containStroke(
  13190. xi, yi, x0, y0, lineWidth, x, y
  13191. )) {
  13192. return true;
  13193. }
  13194. }
  13195. else {
  13196. // Close a subpath
  13197. w += windingLine(xi, yi, x0, y0, x, y);
  13198. // 如果被任何一个 subpath 包含
  13199. // FIXME subpaths may overlap
  13200. // if (w !== 0) {
  13201. // return true;
  13202. // }
  13203. }
  13204. xi = x0;
  13205. yi = y0;
  13206. break;
  13207. }
  13208. }
  13209. if (!isStroke && !isAroundEqual(yi, y0)) {
  13210. w += windingLine(xi, yi, x0, y0, x, y) || 0;
  13211. }
  13212. return w !== 0;
  13213. }
  13214. module.exports = {
  13215. contain: function (pathData, x, y) {
  13216. return containPath(pathData, 0, false, x, y);
  13217. },
  13218. containStroke: function (pathData, lineWidth, x, y) {
  13219. return containPath(pathData, lineWidth, true, x, y);
  13220. }
  13221. };
  13222. /***/ },
  13223. /* 53 */
  13224. /***/ function(module, exports) {
  13225. module.exports = {
  13226. /**
  13227. * 线段包含判断
  13228. * @param {number} x0
  13229. * @param {number} y0
  13230. * @param {number} x1
  13231. * @param {number} y1
  13232. * @param {number} lineWidth
  13233. * @param {number} x
  13234. * @param {number} y
  13235. * @return {boolean}
  13236. */
  13237. containStroke: function (x0, y0, x1, y1, lineWidth, x, y) {
  13238. if (lineWidth === 0) {
  13239. return false;
  13240. }
  13241. var _l = lineWidth;
  13242. var _a = 0;
  13243. var _b = x0;
  13244. // Quick reject
  13245. if (
  13246. (y > y0 + _l && y > y1 + _l)
  13247. || (y < y0 - _l && y < y1 - _l)
  13248. || (x > x0 + _l && x > x1 + _l)
  13249. || (x < x0 - _l && x < x1 - _l)
  13250. ) {
  13251. return false;
  13252. }
  13253. if (x0 !== x1) {
  13254. _a = (y0 - y1) / (x0 - x1);
  13255. _b = (x0 * y1 - x1 * y0) / (x0 - x1) ;
  13256. }
  13257. else {
  13258. return Math.abs(x - x0) <= _l / 2;
  13259. }
  13260. var tmp = _a * x - y + _b;
  13261. var _s = tmp * tmp / (_a * _a + 1);
  13262. return _s <= _l / 2 * _l / 2;
  13263. }
  13264. };
  13265. /***/ },
  13266. /* 54 */
  13267. /***/ function(module, exports, __webpack_require__) {
  13268. var curve = __webpack_require__(50);
  13269. module.exports = {
  13270. /**
  13271. * 三次贝塞尔曲线描边包含判断
  13272. * @param {number} x0
  13273. * @param {number} y0
  13274. * @param {number} x1
  13275. * @param {number} y1
  13276. * @param {number} x2
  13277. * @param {number} y2
  13278. * @param {number} x3
  13279. * @param {number} y3
  13280. * @param {number} lineWidth
  13281. * @param {number} x
  13282. * @param {number} y
  13283. * @return {boolean}
  13284. */
  13285. containStroke: function(x0, y0, x1, y1, x2, y2, x3, y3, lineWidth, x, y) {
  13286. if (lineWidth === 0) {
  13287. return false;
  13288. }
  13289. var _l = lineWidth;
  13290. // Quick reject
  13291. if (
  13292. (y > y0 + _l && y > y1 + _l && y > y2 + _l && y > y3 + _l)
  13293. || (y < y0 - _l && y < y1 - _l && y < y2 - _l && y < y3 - _l)
  13294. || (x > x0 + _l && x > x1 + _l && x > x2 + _l && x > x3 + _l)
  13295. || (x < x0 - _l && x < x1 - _l && x < x2 - _l && x < x3 - _l)
  13296. ) {
  13297. return false;
  13298. }
  13299. var d = curve.cubicProjectPoint(
  13300. x0, y0, x1, y1, x2, y2, x3, y3,
  13301. x, y, null
  13302. );
  13303. return d <= _l / 2;
  13304. }
  13305. };
  13306. /***/ },
  13307. /* 55 */
  13308. /***/ function(module, exports, __webpack_require__) {
  13309. var curve = __webpack_require__(50);
  13310. module.exports = {
  13311. /**
  13312. * 二次贝塞尔曲线描边包含判断
  13313. * @param {number} x0
  13314. * @param {number} y0
  13315. * @param {number} x1
  13316. * @param {number} y1
  13317. * @param {number} x2
  13318. * @param {number} y2
  13319. * @param {number} lineWidth
  13320. * @param {number} x
  13321. * @param {number} y
  13322. * @return {boolean}
  13323. */
  13324. containStroke: function (x0, y0, x1, y1, x2, y2, lineWidth, x, y) {
  13325. if (lineWidth === 0) {
  13326. return false;
  13327. }
  13328. var _l = lineWidth;
  13329. // Quick reject
  13330. if (
  13331. (y > y0 + _l && y > y1 + _l && y > y2 + _l)
  13332. || (y < y0 - _l && y < y1 - _l && y < y2 - _l)
  13333. || (x > x0 + _l && x > x1 + _l && x > x2 + _l)
  13334. || (x < x0 - _l && x < x1 - _l && x < x2 - _l)
  13335. ) {
  13336. return false;
  13337. }
  13338. var d = curve.quadraticProjectPoint(
  13339. x0, y0, x1, y1, x2, y2,
  13340. x, y, null
  13341. );
  13342. return d <= _l / 2;
  13343. }
  13344. };
  13345. /***/ },
  13346. /* 56 */
  13347. /***/ function(module, exports, __webpack_require__) {
  13348. var normalizeRadian = __webpack_require__(57).normalizeRadian;
  13349. var PI2 = Math.PI * 2;
  13350. module.exports = {
  13351. /**
  13352. * 圆弧描边包含判断
  13353. * @param {number} cx
  13354. * @param {number} cy
  13355. * @param {number} r
  13356. * @param {number} startAngle
  13357. * @param {number} endAngle
  13358. * @param {boolean} anticlockwise
  13359. * @param {number} lineWidth
  13360. * @param {number} x
  13361. * @param {number} y
  13362. * @return {Boolean}
  13363. */
  13364. containStroke: function (
  13365. cx, cy, r, startAngle, endAngle, anticlockwise,
  13366. lineWidth, x, y
  13367. ) {
  13368. if (lineWidth === 0) {
  13369. return false;
  13370. }
  13371. var _l = lineWidth;
  13372. x -= cx;
  13373. y -= cy;
  13374. var d = Math.sqrt(x * x + y * y);
  13375. if ((d - _l > r) || (d + _l < r)) {
  13376. return false;
  13377. }
  13378. if (Math.abs(startAngle - endAngle) % PI2 < 1e-4) {
  13379. // Is a circle
  13380. return true;
  13381. }
  13382. if (anticlockwise) {
  13383. var tmp = startAngle;
  13384. startAngle = normalizeRadian(endAngle);
  13385. endAngle = normalizeRadian(tmp);
  13386. } else {
  13387. startAngle = normalizeRadian(startAngle);
  13388. endAngle = normalizeRadian(endAngle);
  13389. }
  13390. if (startAngle > endAngle) {
  13391. endAngle += PI2;
  13392. }
  13393. var angle = Math.atan2(y, x);
  13394. if (angle < 0) {
  13395. angle += PI2;
  13396. }
  13397. return (angle >= startAngle && angle <= endAngle)
  13398. || (angle + PI2 >= startAngle && angle + PI2 <= endAngle);
  13399. }
  13400. };
  13401. /***/ },
  13402. /* 57 */
  13403. /***/ function(module, exports) {
  13404. var PI2 = Math.PI * 2;
  13405. module.exports = {
  13406. normalizeRadian: function(angle) {
  13407. angle %= PI2;
  13408. if (angle < 0) {
  13409. angle += PI2;
  13410. }
  13411. return angle;
  13412. }
  13413. };
  13414. /***/ },
  13415. /* 58 */
  13416. /***/ function(module, exports) {
  13417. module.exports = function windingLine(x0, y0, x1, y1, x, y) {
  13418. if ((y > y0 && y > y1) || (y < y0 && y < y1)) {
  13419. return 0;
  13420. }
  13421. // Ignore horizontal line
  13422. if (y1 === y0) {
  13423. return 0;
  13424. }
  13425. var dir = y1 < y0 ? 1 : -1;
  13426. var t = (y - y0) / (y1 - y0);
  13427. // Avoid winding error when intersection point is the connect point of two line of polygon
  13428. if (t === 1 || t === 0) {
  13429. dir = y1 < y0 ? 0.5 : -0.5;
  13430. }
  13431. var x_ = t * (x1 - x0) + x0;
  13432. return x_ > x ? dir : 0;
  13433. };
  13434. /***/ },
  13435. /* 59 */
  13436. /***/ function(module, exports) {
  13437. var Pattern = function (image, repeat) {
  13438. this.image = image;
  13439. this.repeat = repeat;
  13440. // Can be cloned
  13441. this.type = 'pattern';
  13442. };
  13443. Pattern.prototype.getCanvasPattern = function (ctx) {
  13444. return this._canvasPattern
  13445. || (this._canvasPattern = ctx.createPattern(this.image, this.repeat));
  13446. };
  13447. module.exports = Pattern;
  13448. /***/ },
  13449. /* 60 */
  13450. /***/ function(module, exports, __webpack_require__) {
  13451. var CMD = __webpack_require__(49).CMD;
  13452. var vec2 = __webpack_require__(10);
  13453. var v2ApplyTransform = vec2.applyTransform;
  13454. var points = [[], [], []];
  13455. var mathSqrt = Math.sqrt;
  13456. var mathAtan2 = Math.atan2;
  13457. function transformPath(path, m) {
  13458. var data = path.data;
  13459. var cmd;
  13460. var nPoint;
  13461. var i;
  13462. var j;
  13463. var k;
  13464. var p;
  13465. var M = CMD.M;
  13466. var C = CMD.C;
  13467. var L = CMD.L;
  13468. var R = CMD.R;
  13469. var A = CMD.A;
  13470. var Q = CMD.Q;
  13471. for (i = 0, j = 0; i < data.length;) {
  13472. cmd = data[i++];
  13473. j = i;
  13474. nPoint = 0;
  13475. switch (cmd) {
  13476. case M:
  13477. nPoint = 1;
  13478. break;
  13479. case L:
  13480. nPoint = 1;
  13481. break;
  13482. case C:
  13483. nPoint = 3;
  13484. break;
  13485. case Q:
  13486. nPoint = 2;
  13487. break;
  13488. case A:
  13489. var x = m[4];
  13490. var y = m[5];
  13491. var sx = mathSqrt(m[0] * m[0] + m[1] * m[1]);
  13492. var sy = mathSqrt(m[2] * m[2] + m[3] * m[3]);
  13493. var angle = mathAtan2(-m[1] / sy, m[0] / sx);
  13494. // cx
  13495. data[i++] += x;
  13496. // cy
  13497. data[i++] += y;
  13498. // Scale rx and ry
  13499. // FIXME Assume psi is 0 here
  13500. data[i++] *= sx;
  13501. data[i++] *= sy;
  13502. // Start angle
  13503. data[i++] += angle;
  13504. // end angle
  13505. data[i++] += angle;
  13506. // FIXME psi
  13507. i += 2;
  13508. j = i;
  13509. break;
  13510. case R:
  13511. // x0, y0
  13512. p[0] = data[i++];
  13513. p[1] = data[i++];
  13514. v2ApplyTransform(p, p, m);
  13515. data[j++] = p[0];
  13516. data[j++] = p[1];
  13517. // x1, y1
  13518. p[0] += data[i++];
  13519. p[1] += data[i++];
  13520. v2ApplyTransform(p, p, m);
  13521. data[j++] = p[0];
  13522. data[j++] = p[1];
  13523. }
  13524. for (k = 0; k < nPoint; k++) {
  13525. var p = points[k];
  13526. p[0] = data[i++];
  13527. p[1] = data[i++];
  13528. v2ApplyTransform(p, p, m);
  13529. // Write back
  13530. data[j++] = p[0];
  13531. data[j++] = p[1];
  13532. }
  13533. }
  13534. }
  13535. module.exports = transformPath;
  13536. /***/ },
  13537. /* 61 */
  13538. /***/ function(module, exports, __webpack_require__) {
  13539. /**
  13540. * Image element
  13541. * @module zrender/graphic/Image
  13542. */
  13543. var Displayable = __webpack_require__(46);
  13544. var BoundingRect = __webpack_require__(9);
  13545. var zrUtil = __webpack_require__(4);
  13546. var LRU = __webpack_require__(62);
  13547. var globalImageCache = new LRU(50);
  13548. /**
  13549. * @alias zrender/graphic/Image
  13550. * @extends module:zrender/graphic/Displayable
  13551. * @constructor
  13552. * @param {Object} opts
  13553. */
  13554. function ZImage(opts) {
  13555. Displayable.call(this, opts);
  13556. }
  13557. ZImage.prototype = {
  13558. constructor: ZImage,
  13559. type: 'image',
  13560. brush: function (ctx, prevEl) {
  13561. var style = this.style;
  13562. var src = style.image;
  13563. var image;
  13564. // Must bind each time
  13565. style.bind(ctx, this, prevEl);
  13566. // style.image is a url string
  13567. if (typeof src === 'string') {
  13568. image = this._image;
  13569. }
  13570. // style.image is an HTMLImageElement or HTMLCanvasElement or Canvas
  13571. else {
  13572. image = src;
  13573. }
  13574. // FIXME Case create many images with src
  13575. if (!image && src) {
  13576. // Try get from global image cache
  13577. var cachedImgObj = globalImageCache.get(src);
  13578. if (!cachedImgObj) {
  13579. // Create a new image
  13580. image = new Image();
  13581. image.onload = function () {
  13582. image.onload = null;
  13583. for (var i = 0; i < cachedImgObj.pending.length; i++) {
  13584. cachedImgObj.pending[i].dirty();
  13585. }
  13586. };
  13587. cachedImgObj = {
  13588. image: image,
  13589. pending: [this]
  13590. };
  13591. image.src = src;
  13592. globalImageCache.put(src, cachedImgObj);
  13593. this._image = image;
  13594. return;
  13595. }
  13596. else {
  13597. image = cachedImgObj.image;
  13598. this._image = image;
  13599. // Image is not complete finish, add to pending list
  13600. if (!image.width || !image.height) {
  13601. cachedImgObj.pending.push(this);
  13602. return;
  13603. }
  13604. }
  13605. }
  13606. if (image) {
  13607. // 图片已经加载完成
  13608. // if (image.nodeName.toUpperCase() == 'IMG') {
  13609. // if (!image.complete) {
  13610. // return;
  13611. // }
  13612. // }
  13613. // Else is canvas
  13614. var width = style.width || image.width;
  13615. var height = style.height || image.height;
  13616. var x = style.x || 0;
  13617. var y = style.y || 0;
  13618. // 图片加载失败
  13619. if (!image.width || !image.height) {
  13620. return;
  13621. }
  13622. // 设置transform
  13623. this.setTransform(ctx);
  13624. if (style.sWidth && style.sHeight) {
  13625. var sx = style.sx || 0;
  13626. var sy = style.sy || 0;
  13627. ctx.drawImage(
  13628. image,
  13629. sx, sy, style.sWidth, style.sHeight,
  13630. x, y, width, height
  13631. );
  13632. }
  13633. else if (style.sx && style.sy) {
  13634. var sx = style.sx;
  13635. var sy = style.sy;
  13636. var sWidth = width - sx;
  13637. var sHeight = height - sy;
  13638. ctx.drawImage(
  13639. image,
  13640. sx, sy, sWidth, sHeight,
  13641. x, y, width, height
  13642. );
  13643. }
  13644. else {
  13645. ctx.drawImage(image, x, y, width, height);
  13646. }
  13647. // 如果没设置宽和高的话自动根据图片宽高设置
  13648. if (style.width == null) {
  13649. style.width = width;
  13650. }
  13651. if (style.height == null) {
  13652. style.height = height;
  13653. }
  13654. this.restoreTransform(ctx);
  13655. // Draw rect text
  13656. if (style.text != null) {
  13657. this.drawRectText(ctx, this.getBoundingRect());
  13658. }
  13659. }
  13660. },
  13661. getBoundingRect: function () {
  13662. var style = this.style;
  13663. if (! this._rect) {
  13664. this._rect = new BoundingRect(
  13665. style.x || 0, style.y || 0, style.width || 0, style.height || 0
  13666. );
  13667. }
  13668. return this._rect;
  13669. }
  13670. };
  13671. zrUtil.inherits(ZImage, Displayable);
  13672. module.exports = ZImage;
  13673. /***/ },
  13674. /* 62 */
  13675. /***/ function(module, exports) {
  13676. // Simple LRU cache use doubly linked list
  13677. // @module zrender/core/LRU
  13678. /**
  13679. * Simple double linked list. Compared with array, it has O(1) remove operation.
  13680. * @constructor
  13681. */
  13682. var LinkedList = function() {
  13683. /**
  13684. * @type {module:zrender/core/LRU~Entry}
  13685. */
  13686. this.head = null;
  13687. /**
  13688. * @type {module:zrender/core/LRU~Entry}
  13689. */
  13690. this.tail = null;
  13691. this._len = 0;
  13692. };
  13693. var linkedListProto = LinkedList.prototype;
  13694. /**
  13695. * Insert a new value at the tail
  13696. * @param {} val
  13697. * @return {module:zrender/core/LRU~Entry}
  13698. */
  13699. linkedListProto.insert = function(val) {
  13700. var entry = new Entry(val);
  13701. this.insertEntry(entry);
  13702. return entry;
  13703. };
  13704. /**
  13705. * Insert an entry at the tail
  13706. * @param {module:zrender/core/LRU~Entry} entry
  13707. */
  13708. linkedListProto.insertEntry = function(entry) {
  13709. if (!this.head) {
  13710. this.head = this.tail = entry;
  13711. }
  13712. else {
  13713. this.tail.next = entry;
  13714. entry.prev = this.tail;
  13715. this.tail = entry;
  13716. }
  13717. this._len++;
  13718. };
  13719. /**
  13720. * Remove entry.
  13721. * @param {module:zrender/core/LRU~Entry} entry
  13722. */
  13723. linkedListProto.remove = function(entry) {
  13724. var prev = entry.prev;
  13725. var next = entry.next;
  13726. if (prev) {
  13727. prev.next = next;
  13728. }
  13729. else {
  13730. // Is head
  13731. this.head = next;
  13732. }
  13733. if (next) {
  13734. next.prev = prev;
  13735. }
  13736. else {
  13737. // Is tail
  13738. this.tail = prev;
  13739. }
  13740. entry.next = entry.prev = null;
  13741. this._len--;
  13742. };
  13743. /**
  13744. * @return {number}
  13745. */
  13746. linkedListProto.len = function() {
  13747. return this._len;
  13748. };
  13749. /**
  13750. * @constructor
  13751. * @param {} val
  13752. */
  13753. var Entry = function(val) {
  13754. /**
  13755. * @type {}
  13756. */
  13757. this.value = val;
  13758. /**
  13759. * @type {module:zrender/core/LRU~Entry}
  13760. */
  13761. this.next;
  13762. /**
  13763. * @type {module:zrender/core/LRU~Entry}
  13764. */
  13765. this.prev;
  13766. };
  13767. /**
  13768. * LRU Cache
  13769. * @constructor
  13770. * @alias module:zrender/core/LRU
  13771. */
  13772. var LRU = function(maxSize) {
  13773. this._list = new LinkedList();
  13774. this._map = {};
  13775. this._maxSize = maxSize || 10;
  13776. };
  13777. var LRUProto = LRU.prototype;
  13778. /**
  13779. * @param {string} key
  13780. * @param {} value
  13781. */
  13782. LRUProto.put = function(key, value) {
  13783. var list = this._list;
  13784. var map = this._map;
  13785. if (map[key] == null) {
  13786. var len = list.len();
  13787. if (len >= this._maxSize && len > 0) {
  13788. // Remove the least recently used
  13789. var leastUsedEntry = list.head;
  13790. list.remove(leastUsedEntry);
  13791. delete map[leastUsedEntry.key];
  13792. }
  13793. var entry = list.insert(value);
  13794. entry.key = key;
  13795. map[key] = entry;
  13796. }
  13797. };
  13798. /**
  13799. * @param {string} key
  13800. * @return {}
  13801. */
  13802. LRUProto.get = function(key) {
  13803. var entry = this._map[key];
  13804. var list = this._list;
  13805. if (entry != null) {
  13806. // Put the latest used entry in the tail
  13807. if (entry !== list.tail) {
  13808. list.remove(entry);
  13809. list.insertEntry(entry);
  13810. }
  13811. return entry.value;
  13812. }
  13813. };
  13814. /**
  13815. * Clear the cache
  13816. */
  13817. LRUProto.clear = function() {
  13818. this._list.clear();
  13819. this._map = {};
  13820. };
  13821. module.exports = LRU;
  13822. /***/ },
  13823. /* 63 */
  13824. /***/ function(module, exports, __webpack_require__) {
  13825. /**
  13826. * Text element
  13827. * @module zrender/graphic/Text
  13828. *
  13829. * TODO Wrapping
  13830. *
  13831. * Text not support gradient
  13832. */
  13833. var Displayable = __webpack_require__(46);
  13834. var zrUtil = __webpack_require__(4);
  13835. var textContain = __webpack_require__(8);
  13836. /**
  13837. * @alias zrender/graphic/Text
  13838. * @extends module:zrender/graphic/Displayable
  13839. * @constructor
  13840. * @param {Object} opts
  13841. */
  13842. var Text = function (opts) {
  13843. Displayable.call(this, opts);
  13844. };
  13845. Text.prototype = {
  13846. constructor: Text,
  13847. type: 'text',
  13848. brush: function (ctx, prevEl) {
  13849. var style = this.style;
  13850. var x = style.x || 0;
  13851. var y = style.y || 0;
  13852. // Convert to string
  13853. var text = style.text;
  13854. // Convert to string
  13855. text != null && (text += '');
  13856. // Always bind style
  13857. style.bind(ctx, this, prevEl);
  13858. if (text) {
  13859. this.setTransform(ctx);
  13860. var textBaseline;
  13861. var textAlign = style.textAlign;
  13862. var font = style.textFont || style.font;
  13863. if (style.textVerticalAlign) {
  13864. var rect = textContain.getBoundingRect(
  13865. text, font, style.textAlign, 'top'
  13866. );
  13867. // Ignore textBaseline
  13868. textBaseline = 'middle';
  13869. switch (style.textVerticalAlign) {
  13870. case 'middle':
  13871. y -= rect.height / 2 - rect.lineHeight / 2;
  13872. break;
  13873. case 'bottom':
  13874. y -= rect.height - rect.lineHeight / 2;
  13875. break;
  13876. default:
  13877. y += rect.lineHeight / 2;
  13878. }
  13879. }
  13880. else {
  13881. textBaseline = style.textBaseline;
  13882. }
  13883. // TODO Invalid font
  13884. ctx.font = font || '12px sans-serif';
  13885. ctx.textAlign = textAlign || 'left';
  13886. // Use canvas default left textAlign. Giving invalid value will cause state not change
  13887. if (ctx.textAlign !== textAlign) {
  13888. ctx.textAlign = 'left';
  13889. }
  13890. ctx.textBaseline = textBaseline || 'alphabetic';
  13891. // Use canvas default alphabetic baseline
  13892. if (ctx.textBaseline !== textBaseline) {
  13893. ctx.textBaseline = 'alphabetic';
  13894. }
  13895. var lineHeight = textContain.measureText('国', ctx.font).width;
  13896. var textLines = text.split('\n');
  13897. for (var i = 0; i < textLines.length; i++) {
  13898. style.hasFill() && ctx.fillText(textLines[i], x, y);
  13899. style.hasStroke() && ctx.strokeText(textLines[i], x, y);
  13900. y += lineHeight;
  13901. }
  13902. this.restoreTransform(ctx);
  13903. }
  13904. },
  13905. getBoundingRect: function () {
  13906. if (!this._rect) {
  13907. var style = this.style;
  13908. var textVerticalAlign = style.textVerticalAlign;
  13909. var rect = textContain.getBoundingRect(
  13910. style.text + '', style.textFont || style.font, style.textAlign,
  13911. textVerticalAlign ? 'top' : style.textBaseline
  13912. );
  13913. switch (textVerticalAlign) {
  13914. case 'middle':
  13915. rect.y -= rect.height / 2;
  13916. break;
  13917. case 'bottom':
  13918. rect.y -= rect.height;
  13919. break;
  13920. }
  13921. rect.x += style.x || 0;
  13922. rect.y += style.y || 0;
  13923. this._rect = rect;
  13924. }
  13925. return this._rect;
  13926. }
  13927. };
  13928. zrUtil.inherits(Text, Displayable);
  13929. module.exports = Text;
  13930. /***/ },
  13931. /* 64 */
  13932. /***/ function(module, exports, __webpack_require__) {
  13933. 'use strict';
  13934. /**
  13935. * 圆形
  13936. * @module zrender/shape/Circle
  13937. */
  13938. module.exports = __webpack_require__(45).extend({
  13939. type: 'circle',
  13940. shape: {
  13941. cx: 0,
  13942. cy: 0,
  13943. r: 0
  13944. },
  13945. buildPath : function (ctx, shape, inBundle) {
  13946. // Better stroking in ShapeBundle
  13947. // Always do it may have performence issue ( fill may be 2x more cost)
  13948. if (inBundle) {
  13949. ctx.moveTo(shape.cx + shape.r, shape.cy);
  13950. }
  13951. // Better stroking in ShapeBundle
  13952. // ctx.moveTo(shape.cx + shape.r, shape.cy);
  13953. ctx.arc(shape.cx, shape.cy, shape.r, 0, Math.PI * 2, true);
  13954. }
  13955. });
  13956. /***/ },
  13957. /* 65 */
  13958. /***/ function(module, exports, __webpack_require__) {
  13959. /**
  13960. * 扇形
  13961. * @module zrender/graphic/shape/Sector
  13962. */
  13963. var env = __webpack_require__(2);
  13964. var Path = __webpack_require__(45);
  13965. var shadowTemp = [
  13966. ['shadowBlur', 0],
  13967. ['shadowColor', '#000'],
  13968. ['shadowOffsetX', 0],
  13969. ['shadowOffsetY', 0]
  13970. ];
  13971. module.exports = Path.extend({
  13972. type: 'sector',
  13973. shape: {
  13974. cx: 0,
  13975. cy: 0,
  13976. r0: 0,
  13977. r: 0,
  13978. startAngle: 0,
  13979. endAngle: Math.PI * 2,
  13980. clockwise: true
  13981. },
  13982. brush: (env.browser.ie && env.browser.version >= 11) // version: '11.0'
  13983. // Fix weird bug in some version of IE11 (like 11.0.9600.17801),
  13984. // where exception "unexpected call to method or property access"
  13985. // might be thrown when calling ctx.fill after a path whose area size
  13986. // is zero is drawn and ctx.clip() is called and shadowBlur is set.
  13987. // (e.g.,
  13988. // ctx.moveTo(10, 10);
  13989. // ctx.lineTo(20, 10);
  13990. // ctx.closePath();
  13991. // ctx.clip();
  13992. // ctx.shadowBlur = 10;
  13993. // ...
  13994. // ctx.fill();
  13995. // )
  13996. ? function () {
  13997. var clipPaths = this.__clipPaths;
  13998. var style = this.style;
  13999. var modified;
  14000. if (clipPaths) {
  14001. for (var i = 0; i < clipPaths.length; i++) {
  14002. var shape = clipPaths[i] && clipPaths[i].shape;
  14003. if (shape && shape.startAngle === shape.endAngle) {
  14004. for (var j = 0; j < shadowTemp.length; j++) {
  14005. shadowTemp[j][2] = style[shadowTemp[j][0]];
  14006. style[shadowTemp[j][0]] = shadowTemp[j][1];
  14007. }
  14008. modified = true;
  14009. break;
  14010. }
  14011. }
  14012. }
  14013. Path.prototype.brush.apply(this, arguments);
  14014. if (modified) {
  14015. for (var j = 0; j < shadowTemp.length; j++) {
  14016. style[shadowTemp[j][0]] = shadowTemp[j][2];
  14017. }
  14018. }
  14019. }
  14020. : Path.prototype.brush,
  14021. buildPath: function (ctx, shape) {
  14022. var x = shape.cx;
  14023. var y = shape.cy;
  14024. var r0 = Math.max(shape.r0 || 0, 0);
  14025. var r = Math.max(shape.r, 0);
  14026. var startAngle = shape.startAngle;
  14027. var endAngle = shape.endAngle;
  14028. var clockwise = shape.clockwise;
  14029. var unitX = Math.cos(startAngle);
  14030. var unitY = Math.sin(startAngle);
  14031. ctx.moveTo(unitX * r0 + x, unitY * r0 + y);
  14032. ctx.lineTo(unitX * r + x, unitY * r + y);
  14033. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  14034. ctx.lineTo(
  14035. Math.cos(endAngle) * r0 + x,
  14036. Math.sin(endAngle) * r0 + y
  14037. );
  14038. if (r0 !== 0) {
  14039. ctx.arc(x, y, r0, endAngle, startAngle, clockwise);
  14040. }
  14041. ctx.closePath();
  14042. }
  14043. });
  14044. /***/ },
  14045. /* 66 */
  14046. /***/ function(module, exports, __webpack_require__) {
  14047. /**
  14048. * 圆环
  14049. * @module zrender/graphic/shape/Ring
  14050. */
  14051. module.exports = __webpack_require__(45).extend({
  14052. type: 'ring',
  14053. shape: {
  14054. cx: 0,
  14055. cy: 0,
  14056. r: 0,
  14057. r0: 0
  14058. },
  14059. buildPath: function (ctx, shape) {
  14060. var x = shape.cx;
  14061. var y = shape.cy;
  14062. var PI2 = Math.PI * 2;
  14063. ctx.moveTo(x + shape.r, y);
  14064. ctx.arc(x, y, shape.r, 0, PI2, false);
  14065. ctx.moveTo(x + shape.r0, y);
  14066. ctx.arc(x, y, shape.r0, 0, PI2, true);
  14067. }
  14068. });
  14069. /***/ },
  14070. /* 67 */
  14071. /***/ function(module, exports, __webpack_require__) {
  14072. /**
  14073. * 多边形
  14074. * @module zrender/shape/Polygon
  14075. */
  14076. var polyHelper = __webpack_require__(68);
  14077. module.exports = __webpack_require__(45).extend({
  14078. type: 'polygon',
  14079. shape: {
  14080. points: null,
  14081. smooth: false,
  14082. smoothConstraint: null
  14083. },
  14084. buildPath: function (ctx, shape) {
  14085. polyHelper.buildPath(ctx, shape, true);
  14086. }
  14087. });
  14088. /***/ },
  14089. /* 68 */
  14090. /***/ function(module, exports, __webpack_require__) {
  14091. var smoothSpline = __webpack_require__(69);
  14092. var smoothBezier = __webpack_require__(70);
  14093. module.exports = {
  14094. buildPath: function (ctx, shape, closePath) {
  14095. var points = shape.points;
  14096. var smooth = shape.smooth;
  14097. if (points && points.length >= 2) {
  14098. if (smooth && smooth !== 'spline') {
  14099. var controlPoints = smoothBezier(
  14100. points, smooth, closePath, shape.smoothConstraint
  14101. );
  14102. ctx.moveTo(points[0][0], points[0][1]);
  14103. var len = points.length;
  14104. for (var i = 0; i < (closePath ? len : len - 1); i++) {
  14105. var cp1 = controlPoints[i * 2];
  14106. var cp2 = controlPoints[i * 2 + 1];
  14107. var p = points[(i + 1) % len];
  14108. ctx.bezierCurveTo(
  14109. cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]
  14110. );
  14111. }
  14112. }
  14113. else {
  14114. if (smooth === 'spline') {
  14115. points = smoothSpline(points, closePath);
  14116. }
  14117. ctx.moveTo(points[0][0], points[0][1]);
  14118. for (var i = 1, l = points.length; i < l; i++) {
  14119. ctx.lineTo(points[i][0], points[i][1]);
  14120. }
  14121. }
  14122. closePath && ctx.closePath();
  14123. }
  14124. }
  14125. };
  14126. /***/ },
  14127. /* 69 */
  14128. /***/ function(module, exports, __webpack_require__) {
  14129. /**
  14130. * Catmull-Rom spline 插值折线
  14131. * @module zrender/shape/util/smoothSpline
  14132. * @author pissang (https://www.github.com/pissang)
  14133. * Kener (@Kener-林峰, kener.linfeng@gmail.com)
  14134. * errorrik (errorrik@gmail.com)
  14135. */
  14136. var vec2 = __webpack_require__(10);
  14137. /**
  14138. * @inner
  14139. */
  14140. function interpolate(p0, p1, p2, p3, t, t2, t3) {
  14141. var v0 = (p2 - p0) * 0.5;
  14142. var v1 = (p3 - p1) * 0.5;
  14143. return (2 * (p1 - p2) + v0 + v1) * t3
  14144. + (-3 * (p1 - p2) - 2 * v0 - v1) * t2
  14145. + v0 * t + p1;
  14146. }
  14147. /**
  14148. * @alias module:zrender/shape/util/smoothSpline
  14149. * @param {Array} points 线段顶点数组
  14150. * @param {boolean} isLoop
  14151. * @return {Array}
  14152. */
  14153. module.exports = function (points, isLoop) {
  14154. var len = points.length;
  14155. var ret = [];
  14156. var distance = 0;
  14157. for (var i = 1; i < len; i++) {
  14158. distance += vec2.distance(points[i - 1], points[i]);
  14159. }
  14160. var segs = distance / 2;
  14161. segs = segs < len ? len : segs;
  14162. for (var i = 0; i < segs; i++) {
  14163. var pos = i / (segs - 1) * (isLoop ? len : len - 1);
  14164. var idx = Math.floor(pos);
  14165. var w = pos - idx;
  14166. var p0;
  14167. var p1 = points[idx % len];
  14168. var p2;
  14169. var p3;
  14170. if (!isLoop) {
  14171. p0 = points[idx === 0 ? idx : idx - 1];
  14172. p2 = points[idx > len - 2 ? len - 1 : idx + 1];
  14173. p3 = points[idx > len - 3 ? len - 1 : idx + 2];
  14174. }
  14175. else {
  14176. p0 = points[(idx - 1 + len) % len];
  14177. p2 = points[(idx + 1) % len];
  14178. p3 = points[(idx + 2) % len];
  14179. }
  14180. var w2 = w * w;
  14181. var w3 = w * w2;
  14182. ret.push([
  14183. interpolate(p0[0], p1[0], p2[0], p3[0], w, w2, w3),
  14184. interpolate(p0[1], p1[1], p2[1], p3[1], w, w2, w3)
  14185. ]);
  14186. }
  14187. return ret;
  14188. };
  14189. /***/ },
  14190. /* 70 */
  14191. /***/ function(module, exports, __webpack_require__) {
  14192. /**
  14193. * 贝塞尔平滑曲线
  14194. * @module zrender/shape/util/smoothBezier
  14195. * @author pissang (https://www.github.com/pissang)
  14196. * Kener (@Kener-林峰, kener.linfeng@gmail.com)
  14197. * errorrik (errorrik@gmail.com)
  14198. */
  14199. var vec2 = __webpack_require__(10);
  14200. var v2Min = vec2.min;
  14201. var v2Max = vec2.max;
  14202. var v2Scale = vec2.scale;
  14203. var v2Distance = vec2.distance;
  14204. var v2Add = vec2.add;
  14205. /**
  14206. * 贝塞尔平滑曲线
  14207. * @alias module:zrender/shape/util/smoothBezier
  14208. * @param {Array} points 线段顶点数组
  14209. * @param {number} smooth 平滑等级, 0-1
  14210. * @param {boolean} isLoop
  14211. * @param {Array} constraint 将计算出来的控制点约束在一个包围盒内
  14212. * 比如 [[0, 0], [100, 100]], 这个包围盒会与
  14213. * 整个折线的包围盒做一个并集用来约束控制点。
  14214. * @param {Array} 计算出来的控制点数组
  14215. */
  14216. module.exports = function (points, smooth, isLoop, constraint) {
  14217. var cps = [];
  14218. var v = [];
  14219. var v1 = [];
  14220. var v2 = [];
  14221. var prevPoint;
  14222. var nextPoint;
  14223. var min, max;
  14224. if (constraint) {
  14225. min = [Infinity, Infinity];
  14226. max = [-Infinity, -Infinity];
  14227. for (var i = 0, len = points.length; i < len; i++) {
  14228. v2Min(min, min, points[i]);
  14229. v2Max(max, max, points[i]);
  14230. }
  14231. // 与指定的包围盒做并集
  14232. v2Min(min, min, constraint[0]);
  14233. v2Max(max, max, constraint[1]);
  14234. }
  14235. for (var i = 0, len = points.length; i < len; i++) {
  14236. var point = points[i];
  14237. if (isLoop) {
  14238. prevPoint = points[i ? i - 1 : len - 1];
  14239. nextPoint = points[(i + 1) % len];
  14240. }
  14241. else {
  14242. if (i === 0 || i === len - 1) {
  14243. cps.push(vec2.clone(points[i]));
  14244. continue;
  14245. }
  14246. else {
  14247. prevPoint = points[i - 1];
  14248. nextPoint = points[i + 1];
  14249. }
  14250. }
  14251. vec2.sub(v, nextPoint, prevPoint);
  14252. // use degree to scale the handle length
  14253. v2Scale(v, v, smooth);
  14254. var d0 = v2Distance(point, prevPoint);
  14255. var d1 = v2Distance(point, nextPoint);
  14256. var sum = d0 + d1;
  14257. if (sum !== 0) {
  14258. d0 /= sum;
  14259. d1 /= sum;
  14260. }
  14261. v2Scale(v1, v, -d0);
  14262. v2Scale(v2, v, d1);
  14263. var cp0 = v2Add([], point, v1);
  14264. var cp1 = v2Add([], point, v2);
  14265. if (constraint) {
  14266. v2Max(cp0, cp0, min);
  14267. v2Min(cp0, cp0, max);
  14268. v2Max(cp1, cp1, min);
  14269. v2Min(cp1, cp1, max);
  14270. }
  14271. cps.push(cp0);
  14272. cps.push(cp1);
  14273. }
  14274. if (isLoop) {
  14275. cps.push(cps.shift());
  14276. }
  14277. return cps;
  14278. };
  14279. /***/ },
  14280. /* 71 */
  14281. /***/ function(module, exports, __webpack_require__) {
  14282. /**
  14283. * @module zrender/graphic/shape/Polyline
  14284. */
  14285. var polyHelper = __webpack_require__(68);
  14286. module.exports = __webpack_require__(45).extend({
  14287. type: 'polyline',
  14288. shape: {
  14289. points: null,
  14290. smooth: false,
  14291. smoothConstraint: null
  14292. },
  14293. style: {
  14294. stroke: '#000',
  14295. fill: null
  14296. },
  14297. buildPath: function (ctx, shape) {
  14298. polyHelper.buildPath(ctx, shape, false);
  14299. }
  14300. });
  14301. /***/ },
  14302. /* 72 */
  14303. /***/ function(module, exports, __webpack_require__) {
  14304. /**
  14305. * 矩形
  14306. * @module zrender/graphic/shape/Rect
  14307. */
  14308. var roundRectHelper = __webpack_require__(73);
  14309. module.exports = __webpack_require__(45).extend({
  14310. type: 'rect',
  14311. shape: {
  14312. // 左上、右上、右下、左下角的半径依次为r1、r2、r3、r4
  14313. // r缩写为1 相当于 [1, 1, 1, 1]
  14314. // r缩写为[1] 相当于 [1, 1, 1, 1]
  14315. // r缩写为[1, 2] 相当于 [1, 2, 1, 2]
  14316. // r缩写为[1, 2, 3] 相当于 [1, 2, 3, 2]
  14317. r: 0,
  14318. x: 0,
  14319. y: 0,
  14320. width: 0,
  14321. height: 0
  14322. },
  14323. buildPath: function (ctx, shape) {
  14324. var x = shape.x;
  14325. var y = shape.y;
  14326. var width = shape.width;
  14327. var height = shape.height;
  14328. if (!shape.r) {
  14329. ctx.rect(x, y, width, height);
  14330. }
  14331. else {
  14332. roundRectHelper.buildPath(ctx, shape);
  14333. }
  14334. ctx.closePath();
  14335. return;
  14336. }
  14337. });
  14338. /***/ },
  14339. /* 73 */
  14340. /***/ function(module, exports) {
  14341. module.exports = {
  14342. buildPath: function (ctx, shape) {
  14343. var x = shape.x;
  14344. var y = shape.y;
  14345. var width = shape.width;
  14346. var height = shape.height;
  14347. var r = shape.r;
  14348. var r1;
  14349. var r2;
  14350. var r3;
  14351. var r4;
  14352. // Convert width and height to positive for better borderRadius
  14353. if (width < 0) {
  14354. x = x + width;
  14355. width = -width;
  14356. }
  14357. if (height < 0) {
  14358. y = y + height;
  14359. height = -height;
  14360. }
  14361. if (typeof r === 'number') {
  14362. r1 = r2 = r3 = r4 = r;
  14363. }
  14364. else if (r instanceof Array) {
  14365. if (r.length === 1) {
  14366. r1 = r2 = r3 = r4 = r[0];
  14367. }
  14368. else if (r.length === 2) {
  14369. r1 = r3 = r[0];
  14370. r2 = r4 = r[1];
  14371. }
  14372. else if (r.length === 3) {
  14373. r1 = r[0];
  14374. r2 = r4 = r[1];
  14375. r3 = r[2];
  14376. }
  14377. else {
  14378. r1 = r[0];
  14379. r2 = r[1];
  14380. r3 = r[2];
  14381. r4 = r[3];
  14382. }
  14383. }
  14384. else {
  14385. r1 = r2 = r3 = r4 = 0;
  14386. }
  14387. var total;
  14388. if (r1 + r2 > width) {
  14389. total = r1 + r2;
  14390. r1 *= width / total;
  14391. r2 *= width / total;
  14392. }
  14393. if (r3 + r4 > width) {
  14394. total = r3 + r4;
  14395. r3 *= width / total;
  14396. r4 *= width / total;
  14397. }
  14398. if (r2 + r3 > height) {
  14399. total = r2 + r3;
  14400. r2 *= height / total;
  14401. r3 *= height / total;
  14402. }
  14403. if (r1 + r4 > height) {
  14404. total = r1 + r4;
  14405. r1 *= height / total;
  14406. r4 *= height / total;
  14407. }
  14408. ctx.moveTo(x + r1, y);
  14409. ctx.lineTo(x + width - r2, y);
  14410. r2 !== 0 && ctx.quadraticCurveTo(
  14411. x + width, y, x + width, y + r2
  14412. );
  14413. ctx.lineTo(x + width, y + height - r3);
  14414. r3 !== 0 && ctx.quadraticCurveTo(
  14415. x + width, y + height, x + width - r3, y + height
  14416. );
  14417. ctx.lineTo(x + r4, y + height);
  14418. r4 !== 0 && ctx.quadraticCurveTo(
  14419. x, y + height, x, y + height - r4
  14420. );
  14421. ctx.lineTo(x, y + r1);
  14422. r1 !== 0 && ctx.quadraticCurveTo(x, y, x + r1, y);
  14423. }
  14424. };
  14425. /***/ },
  14426. /* 74 */
  14427. /***/ function(module, exports, __webpack_require__) {
  14428. /**
  14429. * 直线
  14430. * @module zrender/graphic/shape/Line
  14431. */
  14432. module.exports = __webpack_require__(45).extend({
  14433. type: 'line',
  14434. shape: {
  14435. // Start point
  14436. x1: 0,
  14437. y1: 0,
  14438. // End point
  14439. x2: 0,
  14440. y2: 0,
  14441. percent: 1
  14442. },
  14443. style: {
  14444. stroke: '#000',
  14445. fill: null
  14446. },
  14447. buildPath: function (ctx, shape) {
  14448. var x1 = shape.x1;
  14449. var y1 = shape.y1;
  14450. var x2 = shape.x2;
  14451. var y2 = shape.y2;
  14452. var percent = shape.percent;
  14453. if (percent === 0) {
  14454. return;
  14455. }
  14456. ctx.moveTo(x1, y1);
  14457. if (percent < 1) {
  14458. x2 = x1 * (1 - percent) + x2 * percent;
  14459. y2 = y1 * (1 - percent) + y2 * percent;
  14460. }
  14461. ctx.lineTo(x2, y2);
  14462. },
  14463. /**
  14464. * Get point at percent
  14465. * @param {number} percent
  14466. * @return {Array.<number>}
  14467. */
  14468. pointAt: function (p) {
  14469. var shape = this.shape;
  14470. return [
  14471. shape.x1 * (1 - p) + shape.x2 * p,
  14472. shape.y1 * (1 - p) + shape.y2 * p
  14473. ];
  14474. }
  14475. });
  14476. /***/ },
  14477. /* 75 */
  14478. /***/ function(module, exports, __webpack_require__) {
  14479. 'use strict';
  14480. /**
  14481. * 贝塞尔曲线
  14482. * @module zrender/shape/BezierCurve
  14483. */
  14484. var curveTool = __webpack_require__(50);
  14485. var vec2 = __webpack_require__(10);
  14486. var quadraticSubdivide = curveTool.quadraticSubdivide;
  14487. var cubicSubdivide = curveTool.cubicSubdivide;
  14488. var quadraticAt = curveTool.quadraticAt;
  14489. var cubicAt = curveTool.cubicAt;
  14490. var quadraticDerivativeAt = curveTool.quadraticDerivativeAt;
  14491. var cubicDerivativeAt = curveTool.cubicDerivativeAt;
  14492. var out = [];
  14493. function someVectorAt(shape, t, isTangent) {
  14494. var cpx2 = shape.cpx2;
  14495. var cpy2 = shape.cpy2;
  14496. if (cpx2 === null || cpy2 === null) {
  14497. return [
  14498. (isTangent ? cubicDerivativeAt : cubicAt)(shape.x1, shape.cpx1, shape.cpx2, shape.x2, t),
  14499. (isTangent ? cubicDerivativeAt : cubicAt)(shape.y1, shape.cpy1, shape.cpy2, shape.y2, t)
  14500. ];
  14501. }
  14502. else {
  14503. return [
  14504. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.x1, shape.cpx1, shape.x2, t),
  14505. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.y1, shape.cpy1, shape.y2, t)
  14506. ];
  14507. }
  14508. }
  14509. module.exports = __webpack_require__(45).extend({
  14510. type: 'bezier-curve',
  14511. shape: {
  14512. x1: 0,
  14513. y1: 0,
  14514. x2: 0,
  14515. y2: 0,
  14516. cpx1: 0,
  14517. cpy1: 0,
  14518. // cpx2: 0,
  14519. // cpy2: 0
  14520. // Curve show percent, for animating
  14521. percent: 1
  14522. },
  14523. style: {
  14524. stroke: '#000',
  14525. fill: null
  14526. },
  14527. buildPath: function (ctx, shape) {
  14528. var x1 = shape.x1;
  14529. var y1 = shape.y1;
  14530. var x2 = shape.x2;
  14531. var y2 = shape.y2;
  14532. var cpx1 = shape.cpx1;
  14533. var cpy1 = shape.cpy1;
  14534. var cpx2 = shape.cpx2;
  14535. var cpy2 = shape.cpy2;
  14536. var percent = shape.percent;
  14537. if (percent === 0) {
  14538. return;
  14539. }
  14540. ctx.moveTo(x1, y1);
  14541. if (cpx2 == null || cpy2 == null) {
  14542. if (percent < 1) {
  14543. quadraticSubdivide(
  14544. x1, cpx1, x2, percent, out
  14545. );
  14546. cpx1 = out[1];
  14547. x2 = out[2];
  14548. quadraticSubdivide(
  14549. y1, cpy1, y2, percent, out
  14550. );
  14551. cpy1 = out[1];
  14552. y2 = out[2];
  14553. }
  14554. ctx.quadraticCurveTo(
  14555. cpx1, cpy1,
  14556. x2, y2
  14557. );
  14558. }
  14559. else {
  14560. if (percent < 1) {
  14561. cubicSubdivide(
  14562. x1, cpx1, cpx2, x2, percent, out
  14563. );
  14564. cpx1 = out[1];
  14565. cpx2 = out[2];
  14566. x2 = out[3];
  14567. cubicSubdivide(
  14568. y1, cpy1, cpy2, y2, percent, out
  14569. );
  14570. cpy1 = out[1];
  14571. cpy2 = out[2];
  14572. y2 = out[3];
  14573. }
  14574. ctx.bezierCurveTo(
  14575. cpx1, cpy1,
  14576. cpx2, cpy2,
  14577. x2, y2
  14578. );
  14579. }
  14580. },
  14581. /**
  14582. * Get point at percent
  14583. * @param {number} t
  14584. * @return {Array.<number>}
  14585. */
  14586. pointAt: function (t) {
  14587. return someVectorAt(this.shape, t, false);
  14588. },
  14589. /**
  14590. * Get tangent at percent
  14591. * @param {number} t
  14592. * @return {Array.<number>}
  14593. */
  14594. tangentAt: function (t) {
  14595. var p = someVectorAt(this.shape, t, true);
  14596. return vec2.normalize(p, p);
  14597. }
  14598. });
  14599. /***/ },
  14600. /* 76 */
  14601. /***/ function(module, exports, __webpack_require__) {
  14602. /**
  14603. * 圆弧
  14604. * @module zrender/graphic/shape/Arc
  14605. */
  14606. module.exports = __webpack_require__(45).extend({
  14607. type: 'arc',
  14608. shape: {
  14609. cx: 0,
  14610. cy: 0,
  14611. r: 0,
  14612. startAngle: 0,
  14613. endAngle: Math.PI * 2,
  14614. clockwise: true
  14615. },
  14616. style: {
  14617. stroke: '#000',
  14618. fill: null
  14619. },
  14620. buildPath: function (ctx, shape) {
  14621. var x = shape.cx;
  14622. var y = shape.cy;
  14623. var r = Math.max(shape.r, 0);
  14624. var startAngle = shape.startAngle;
  14625. var endAngle = shape.endAngle;
  14626. var clockwise = shape.clockwise;
  14627. var unitX = Math.cos(startAngle);
  14628. var unitY = Math.sin(startAngle);
  14629. ctx.moveTo(unitX * r + x, unitY * r + y);
  14630. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  14631. }
  14632. });
  14633. /***/ },
  14634. /* 77 */
  14635. /***/ function(module, exports, __webpack_require__) {
  14636. // CompoundPath to improve performance
  14637. var Path = __webpack_require__(45);
  14638. module.exports = Path.extend({
  14639. type: 'compound',
  14640. shape: {
  14641. paths: null
  14642. },
  14643. _updatePathDirty: function () {
  14644. var dirtyPath = this.__dirtyPath;
  14645. var paths = this.shape.paths;
  14646. for (var i = 0; i < paths.length; i++) {
  14647. // Mark as dirty if any subpath is dirty
  14648. dirtyPath = dirtyPath || paths[i].__dirtyPath;
  14649. }
  14650. this.__dirtyPath = dirtyPath;
  14651. this.__dirty = this.__dirty || dirtyPath;
  14652. },
  14653. beforeBrush: function () {
  14654. this._updatePathDirty();
  14655. var paths = this.shape.paths || [];
  14656. var scale = this.getGlobalScale();
  14657. // Update path scale
  14658. for (var i = 0; i < paths.length; i++) {
  14659. paths[i].path.setScale(scale[0], scale[1]);
  14660. }
  14661. },
  14662. buildPath: function (ctx, shape) {
  14663. var paths = shape.paths || [];
  14664. for (var i = 0; i < paths.length; i++) {
  14665. paths[i].buildPath(ctx, paths[i].shape, true);
  14666. }
  14667. },
  14668. afterBrush: function () {
  14669. var paths = this.shape.paths;
  14670. for (var i = 0; i < paths.length; i++) {
  14671. paths[i].__dirtyPath = false;
  14672. }
  14673. },
  14674. getBoundingRect: function () {
  14675. this._updatePathDirty();
  14676. return Path.prototype.getBoundingRect.call(this);
  14677. }
  14678. });
  14679. /***/ },
  14680. /* 78 */
  14681. /***/ function(module, exports, __webpack_require__) {
  14682. 'use strict';
  14683. var zrUtil = __webpack_require__(4);
  14684. var Gradient = __webpack_require__(79);
  14685. /**
  14686. * x, y, x2, y2 are all percent from 0 to 1
  14687. * @param {number} [x=0]
  14688. * @param {number} [y=0]
  14689. * @param {number} [x2=1]
  14690. * @param {number} [y2=0]
  14691. * @param {Array.<Object>} colorStops
  14692. * @param {boolean} [globalCoord=false]
  14693. */
  14694. var LinearGradient = function (x, y, x2, y2, colorStops, globalCoord) {
  14695. this.x = x == null ? 0 : x;
  14696. this.y = y == null ? 0 : y;
  14697. this.x2 = x2 == null ? 1 : x2;
  14698. this.y2 = y2 == null ? 0 : y2;
  14699. // Can be cloned
  14700. this.type = 'linear';
  14701. // If use global coord
  14702. this.global = globalCoord || false;
  14703. Gradient.call(this, colorStops);
  14704. };
  14705. LinearGradient.prototype = {
  14706. constructor: LinearGradient
  14707. };
  14708. zrUtil.inherits(LinearGradient, Gradient);
  14709. module.exports = LinearGradient;
  14710. /***/ },
  14711. /* 79 */
  14712. /***/ function(module, exports) {
  14713. /**
  14714. * @param {Array.<Object>} colorStops
  14715. */
  14716. var Gradient = function (colorStops) {
  14717. this.colorStops = colorStops || [];
  14718. };
  14719. Gradient.prototype = {
  14720. constructor: Gradient,
  14721. addColorStop: function (offset, color) {
  14722. this.colorStops.push({
  14723. offset: offset,
  14724. color: color
  14725. });
  14726. }
  14727. };
  14728. module.exports = Gradient;
  14729. /***/ },
  14730. /* 80 */
  14731. /***/ function(module, exports, __webpack_require__) {
  14732. 'use strict';
  14733. var zrUtil = __webpack_require__(4);
  14734. var Gradient = __webpack_require__(79);
  14735. /**
  14736. * x, y, r are all percent from 0 to 1
  14737. * @param {number} [x=0.5]
  14738. * @param {number} [y=0.5]
  14739. * @param {number} [r=0.5]
  14740. * @param {Array.<Object>} [colorStops]
  14741. * @param {boolean} [globalCoord=false]
  14742. */
  14743. var RadialGradient = function (x, y, r, colorStops, globalCoord) {
  14744. this.x = x == null ? 0.5 : x;
  14745. this.y = y == null ? 0.5 : y;
  14746. this.r = r == null ? 0.5 : r;
  14747. // Can be cloned
  14748. this.type = 'radial';
  14749. // If use global coord
  14750. this.global = globalCoord || false;
  14751. Gradient.call(this, colorStops);
  14752. };
  14753. RadialGradient.prototype = {
  14754. constructor: RadialGradient
  14755. };
  14756. zrUtil.inherits(RadialGradient, Gradient);
  14757. module.exports = RadialGradient;
  14758. /***/ },
  14759. /* 81 */
  14760. /***/ function(module, exports) {
  14761. var lib = {};
  14762. var ORIGIN_METHOD = '\0__throttleOriginMethod';
  14763. var RATE = '\0__throttleRate';
  14764. var THROTTLE_TYPE = '\0__throttleType';
  14765. /**
  14766. * @public
  14767. * @param {(Function)} fn
  14768. * @param {number} [delay=0] Unit: ms.
  14769. * @param {boolean} [debounce=false]
  14770. * true: If call interval less than `delay`, only the last call works.
  14771. * false: If call interval less than `delay, call works on fixed rate.
  14772. * @return {(Function)} throttled fn.
  14773. */
  14774. lib.throttle = function (fn, delay, debounce) {
  14775. var currCall;
  14776. var lastCall = 0;
  14777. var lastExec = 0;
  14778. var timer = null;
  14779. var diff;
  14780. var scope;
  14781. var args;
  14782. delay = delay || 0;
  14783. function exec() {
  14784. lastExec = (new Date()).getTime();
  14785. timer = null;
  14786. fn.apply(scope, args || []);
  14787. }
  14788. var cb = function () {
  14789. currCall = (new Date()).getTime();
  14790. scope = this;
  14791. args = arguments;
  14792. diff = currCall - (debounce ? lastCall : lastExec) - delay;
  14793. clearTimeout(timer);
  14794. if (debounce) {
  14795. timer = setTimeout(exec, delay);
  14796. }
  14797. else {
  14798. if (diff >= 0) {
  14799. exec();
  14800. }
  14801. else {
  14802. timer = setTimeout(exec, -diff);
  14803. }
  14804. }
  14805. lastCall = currCall;
  14806. };
  14807. /**
  14808. * Clear throttle.
  14809. * @public
  14810. */
  14811. cb.clear = function () {
  14812. if (timer) {
  14813. clearTimeout(timer);
  14814. timer = null;
  14815. }
  14816. };
  14817. return cb;
  14818. };
  14819. /**
  14820. * Create throttle method or update throttle rate.
  14821. *
  14822. * @example
  14823. * ComponentView.prototype.render = function () {
  14824. * ...
  14825. * throttle.createOrUpdate(
  14826. * this,
  14827. * '_dispatchAction',
  14828. * this.model.get('throttle'),
  14829. * 'fixRate'
  14830. * );
  14831. * };
  14832. * ComponentView.prototype.remove = function () {
  14833. * throttle.clear(this, '_dispatchAction');
  14834. * };
  14835. * ComponentView.prototype.dispose = function () {
  14836. * throttle.clear(this, '_dispatchAction');
  14837. * };
  14838. *
  14839. * @public
  14840. * @param {Object} obj
  14841. * @param {string} fnAttr
  14842. * @param {number} [rate]
  14843. * @param {string} [throttleType='fixRate'] 'fixRate' or 'debounce'
  14844. * @return {Function} throttled function.
  14845. */
  14846. lib.createOrUpdate = function (obj, fnAttr, rate, throttleType) {
  14847. var fn = obj[fnAttr];
  14848. if (!fn) {
  14849. return;
  14850. }
  14851. var originFn = fn[ORIGIN_METHOD] || fn;
  14852. var lastThrottleType = fn[THROTTLE_TYPE];
  14853. var lastRate = fn[RATE];
  14854. if (lastRate !== rate || lastThrottleType !== throttleType) {
  14855. if (rate == null || !throttleType) {
  14856. return (obj[fnAttr] = originFn);
  14857. }
  14858. fn = obj[fnAttr] = lib.throttle(
  14859. originFn, rate, throttleType === 'debounce'
  14860. );
  14861. fn[ORIGIN_METHOD] = originFn;
  14862. fn[THROTTLE_TYPE] = throttleType;
  14863. fn[RATE] = rate;
  14864. }
  14865. return fn;
  14866. };
  14867. /**
  14868. * Clear throttle. Example see throttle.createOrUpdate.
  14869. *
  14870. * @public
  14871. * @param {Object} obj
  14872. * @param {string} fnAttr
  14873. */
  14874. lib.clear = function (obj, fnAttr) {
  14875. var fn = obj[fnAttr];
  14876. if (fn && fn[ORIGIN_METHOD]) {
  14877. obj[fnAttr] = fn[ORIGIN_METHOD];
  14878. }
  14879. };
  14880. module.exports = lib;
  14881. /***/ },
  14882. /* 82 */
  14883. /***/ function(module, exports, __webpack_require__) {
  14884. /*!
  14885. * ZRender, a high performance 2d drawing library.
  14886. *
  14887. * Copyright (c) 2013, Baidu Inc.
  14888. * All rights reserved.
  14889. *
  14890. * LICENSE
  14891. * https://github.com/ecomfe/zrender/blob/master/LICENSE.txt
  14892. */
  14893. // Global defines
  14894. var guid = __webpack_require__(32);
  14895. var env = __webpack_require__(2);
  14896. var zrUtil = __webpack_require__(4);
  14897. var Handler = __webpack_require__(83);
  14898. var Storage = __webpack_require__(85);
  14899. var Animation = __webpack_require__(87);
  14900. var HandlerProxy = __webpack_require__(90);
  14901. var useVML = !env.canvasSupported;
  14902. var painterCtors = {
  14903. canvas: __webpack_require__(92)
  14904. };
  14905. var instances = {}; // ZRender实例map索引
  14906. var zrender = {};
  14907. /**
  14908. * @type {string}
  14909. */
  14910. zrender.version = '3.3.0';
  14911. /**
  14912. * Initializing a zrender instance
  14913. * @param {HTMLElement} dom
  14914. * @param {Object} opts
  14915. * @param {string} [opts.renderer='canvas'] 'canvas' or 'svg'
  14916. * @param {number} [opts.devicePixelRatio]
  14917. * @param {number|string} [opts.width] Can be 'auto' (the same as null/undefined)
  14918. * @param {number|string} [opts.height] Can be 'auto' (the same as null/undefined)
  14919. * @return {module:zrender/ZRender}
  14920. */
  14921. zrender.init = function(dom, opts) {
  14922. var zr = new ZRender(guid(), dom, opts);
  14923. instances[zr.id] = zr;
  14924. return zr;
  14925. };
  14926. /**
  14927. * Dispose zrender instance
  14928. * @param {module:zrender/ZRender} zr
  14929. */
  14930. zrender.dispose = function (zr) {
  14931. if (zr) {
  14932. zr.dispose();
  14933. }
  14934. else {
  14935. for (var key in instances) {
  14936. if (instances.hasOwnProperty(key)) {
  14937. instances[key].dispose();
  14938. }
  14939. }
  14940. instances = {};
  14941. }
  14942. return zrender;
  14943. };
  14944. /**
  14945. * Get zrender instance by id
  14946. * @param {string} id zrender instance id
  14947. * @return {module:zrender/ZRender}
  14948. */
  14949. zrender.getInstance = function (id) {
  14950. return instances[id];
  14951. };
  14952. zrender.registerPainter = function (name, Ctor) {
  14953. painterCtors[name] = Ctor;
  14954. };
  14955. function delInstance(id) {
  14956. delete instances[id];
  14957. }
  14958. /**
  14959. * @module zrender/ZRender
  14960. */
  14961. /**
  14962. * @constructor
  14963. * @alias module:zrender/ZRender
  14964. * @param {string} id
  14965. * @param {HTMLDomElement} dom
  14966. * @param {Object} opts
  14967. * @param {string} [opts.renderer='canvas'] 'canvas' or 'svg'
  14968. * @param {number} [opts.devicePixelRatio]
  14969. * @param {number} [opts.width] Can be 'auto' (the same as null/undefined)
  14970. * @param {number} [opts.height] Can be 'auto' (the same as null/undefined)
  14971. */
  14972. var ZRender = function(id, dom, opts) {
  14973. opts = opts || {};
  14974. /**
  14975. * @type {HTMLDomElement}
  14976. */
  14977. this.dom = dom;
  14978. /**
  14979. * @type {string}
  14980. */
  14981. this.id = id;
  14982. var self = this;
  14983. var storage = new Storage();
  14984. var rendererType = opts.renderer;
  14985. if (useVML) {
  14986. if (!painterCtors.vml) {
  14987. throw new Error('You need to require \'zrender/vml/vml\' to support IE8');
  14988. }
  14989. rendererType = 'vml';
  14990. }
  14991. else if (!rendererType || !painterCtors[rendererType]) {
  14992. rendererType = 'canvas';
  14993. }
  14994. var painter = new painterCtors[rendererType](dom, storage, opts);
  14995. this.storage = storage;
  14996. this.painter = painter;
  14997. var handerProxy = !env.node ? new HandlerProxy(painter.getViewportRoot()) : null;
  14998. this.handler = new Handler(storage, painter, handerProxy, painter.root);
  14999. /**
  15000. * @type {module:zrender/animation/Animation}
  15001. */
  15002. this.animation = new Animation({
  15003. stage: {
  15004. update: zrUtil.bind(this.flush, this)
  15005. }
  15006. });
  15007. this.animation.start();
  15008. /**
  15009. * @type {boolean}
  15010. * @private
  15011. */
  15012. this._needsRefresh;
  15013. // 修改 storage.delFromMap, 每次删除元素之前删除动画
  15014. // FIXME 有点ugly
  15015. var oldDelFromMap = storage.delFromMap;
  15016. var oldAddToMap = storage.addToMap;
  15017. storage.delFromMap = function (elId) {
  15018. var el = storage.get(elId);
  15019. oldDelFromMap.call(storage, elId);
  15020. el && el.removeSelfFromZr(self);
  15021. };
  15022. storage.addToMap = function (el) {
  15023. oldAddToMap.call(storage, el);
  15024. el.addSelfToZr(self);
  15025. };
  15026. };
  15027. ZRender.prototype = {
  15028. constructor: ZRender,
  15029. /**
  15030. * 获取实例唯一标识
  15031. * @return {string}
  15032. */
  15033. getId: function () {
  15034. return this.id;
  15035. },
  15036. /**
  15037. * 添加元素
  15038. * @param {module:zrender/Element} el
  15039. */
  15040. add: function (el) {
  15041. this.storage.addRoot(el);
  15042. this._needsRefresh = true;
  15043. },
  15044. /**
  15045. * 删除元素
  15046. * @param {module:zrender/Element} el
  15047. */
  15048. remove: function (el) {
  15049. this.storage.delRoot(el);
  15050. this._needsRefresh = true;
  15051. },
  15052. /**
  15053. * Change configuration of layer
  15054. * @param {string} zLevel
  15055. * @param {Object} config
  15056. * @param {string} [config.clearColor=0] Clear color
  15057. * @param {string} [config.motionBlur=false] If enable motion blur
  15058. * @param {number} [config.lastFrameAlpha=0.7] Motion blur factor. Larger value cause longer trailer
  15059. */
  15060. configLayer: function (zLevel, config) {
  15061. this.painter.configLayer(zLevel, config);
  15062. this._needsRefresh = true;
  15063. },
  15064. /**
  15065. * Repaint the canvas immediately
  15066. */
  15067. refreshImmediately: function () {
  15068. // Clear needsRefresh ahead to avoid something wrong happens in refresh
  15069. // Or it will cause zrender refreshes again and again.
  15070. this._needsRefresh = false;
  15071. this.painter.refresh();
  15072. /**
  15073. * Avoid trigger zr.refresh in Element#beforeUpdate hook
  15074. */
  15075. this._needsRefresh = false;
  15076. },
  15077. /**
  15078. * Mark and repaint the canvas in the next frame of browser
  15079. */
  15080. refresh: function() {
  15081. this._needsRefresh = true;
  15082. },
  15083. /**
  15084. * Perform all refresh
  15085. */
  15086. flush: function () {
  15087. if (this._needsRefresh) {
  15088. this.refreshImmediately();
  15089. }
  15090. if (this._needsRefreshHover) {
  15091. this.refreshHoverImmediately();
  15092. }
  15093. },
  15094. /**
  15095. * Add element to hover layer
  15096. * @param {module:zrender/Element} el
  15097. * @param {Object} style
  15098. */
  15099. addHover: function (el, style) {
  15100. if (this.painter.addHover) {
  15101. this.painter.addHover(el, style);
  15102. this.refreshHover();
  15103. }
  15104. },
  15105. /**
  15106. * Add element from hover layer
  15107. * @param {module:zrender/Element} el
  15108. */
  15109. removeHover: function (el) {
  15110. if (this.painter.removeHover) {
  15111. this.painter.removeHover(el);
  15112. this.refreshHover();
  15113. }
  15114. },
  15115. /**
  15116. * Clear all hover elements in hover layer
  15117. * @param {module:zrender/Element} el
  15118. */
  15119. clearHover: function () {
  15120. if (this.painter.clearHover) {
  15121. this.painter.clearHover();
  15122. this.refreshHover();
  15123. }
  15124. },
  15125. /**
  15126. * Refresh hover in next frame
  15127. */
  15128. refreshHover: function () {
  15129. this._needsRefreshHover = true;
  15130. },
  15131. /**
  15132. * Refresh hover immediately
  15133. */
  15134. refreshHoverImmediately: function () {
  15135. this._needsRefreshHover = false;
  15136. this.painter.refreshHover && this.painter.refreshHover();
  15137. },
  15138. /**
  15139. * Resize the canvas.
  15140. * Should be invoked when container size is changed
  15141. * @param {Object} [opts]
  15142. * @param {number|string} [opts.width] Can be 'auto' (the same as null/undefined)
  15143. * @param {number|string} [opts.height] Can be 'auto' (the same as null/undefined)
  15144. */
  15145. resize: function(opts) {
  15146. opts = opts || {};
  15147. this.painter.resize(opts.width, opts.height);
  15148. this.handler.resize();
  15149. },
  15150. /**
  15151. * Stop and clear all animation immediately
  15152. */
  15153. clearAnimation: function () {
  15154. this.animation.clear();
  15155. },
  15156. /**
  15157. * Get container width
  15158. */
  15159. getWidth: function() {
  15160. return this.painter.getWidth();
  15161. },
  15162. /**
  15163. * Get container height
  15164. */
  15165. getHeight: function() {
  15166. return this.painter.getHeight();
  15167. },
  15168. /**
  15169. * Export the canvas as Base64 URL
  15170. * @param {string} type
  15171. * @param {string} [backgroundColor='#fff']
  15172. * @return {string} Base64 URL
  15173. */
  15174. // toDataURL: function(type, backgroundColor) {
  15175. // return this.painter.getRenderedCanvas({
  15176. // backgroundColor: backgroundColor
  15177. // }).toDataURL(type);
  15178. // },
  15179. /**
  15180. * Converting a path to image.
  15181. * It has much better performance of drawing image rather than drawing a vector path.
  15182. * @param {module:zrender/graphic/Path} e
  15183. * @param {number} width
  15184. * @param {number} height
  15185. */
  15186. pathToImage: function(e, width, height) {
  15187. var id = guid();
  15188. return this.painter.pathToImage(id, e, width, height);
  15189. },
  15190. /**
  15191. * Set default cursor
  15192. * @param {string} [cursorStyle='default'] 例如 crosshair
  15193. */
  15194. setCursorStyle: function (cursorStyle) {
  15195. this.handler.setCursorStyle(cursorStyle);
  15196. },
  15197. /**
  15198. * Bind event
  15199. *
  15200. * @param {string} eventName Event name
  15201. * @param {Function} eventHandler Handler function
  15202. * @param {Object} [context] Context object
  15203. */
  15204. on: function(eventName, eventHandler, context) {
  15205. this.handler.on(eventName, eventHandler, context);
  15206. },
  15207. /**
  15208. * Unbind event
  15209. * @param {string} eventName Event name
  15210. * @param {Function} [eventHandler] Handler function
  15211. */
  15212. off: function(eventName, eventHandler) {
  15213. this.handler.off(eventName, eventHandler);
  15214. },
  15215. /**
  15216. * Trigger event manually
  15217. *
  15218. * @param {string} eventName Event name
  15219. * @param {event=} event Event object
  15220. */
  15221. trigger: function (eventName, event) {
  15222. this.handler.trigger(eventName, event);
  15223. },
  15224. /**
  15225. * Clear all objects and the canvas.
  15226. */
  15227. clear: function () {
  15228. this.storage.delRoot();
  15229. this.painter.clear();
  15230. },
  15231. /**
  15232. * Dispose self.
  15233. */
  15234. dispose: function () {
  15235. this.animation.stop();
  15236. this.clear();
  15237. this.storage.dispose();
  15238. this.painter.dispose();
  15239. this.handler.dispose();
  15240. this.animation =
  15241. this.storage =
  15242. this.painter =
  15243. this.handler = null;
  15244. delInstance(this.id);
  15245. }
  15246. };
  15247. module.exports = zrender;
  15248. /***/ },
  15249. /* 83 */
  15250. /***/ function(module, exports, __webpack_require__) {
  15251. 'use strict';
  15252. /**
  15253. * Handler
  15254. * @module zrender/Handler
  15255. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  15256. * errorrik (errorrik@gmail.com)
  15257. * pissang (shenyi.914@gmail.com)
  15258. */
  15259. var util = __webpack_require__(4);
  15260. var Draggable = __webpack_require__(84);
  15261. var Eventful = __webpack_require__(33);
  15262. function makeEventPacket(eveType, target, event) {
  15263. return {
  15264. type: eveType,
  15265. event: event,
  15266. target: target,
  15267. cancelBubble: false,
  15268. offsetX: event.zrX,
  15269. offsetY: event.zrY,
  15270. gestureEvent: event.gestureEvent,
  15271. pinchX: event.pinchX,
  15272. pinchY: event.pinchY,
  15273. pinchScale: event.pinchScale,
  15274. wheelDelta: event.zrDelta,
  15275. zrByTouch: event.zrByTouch
  15276. };
  15277. }
  15278. function EmptyProxy () {}
  15279. EmptyProxy.prototype.dispose = function () {};
  15280. var handlerNames = [
  15281. 'click', 'dblclick', 'mousewheel', 'mouseout',
  15282. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  15283. ];
  15284. /**
  15285. * @alias module:zrender/Handler
  15286. * @constructor
  15287. * @extends module:zrender/mixin/Eventful
  15288. * @param {module:zrender/Storage} storage Storage instance.
  15289. * @param {module:zrender/Painter} painter Painter instance.
  15290. * @param {module:zrender/dom/HandlerProxy} proxy HandlerProxy instance.
  15291. * @param {HTMLElement} painterRoot painter.root (not painter.getViewportRoot()).
  15292. */
  15293. var Handler = function(storage, painter, proxy, painterRoot) {
  15294. Eventful.call(this);
  15295. this.storage = storage;
  15296. this.painter = painter;
  15297. this.painterRoot = painterRoot;
  15298. proxy = proxy || new EmptyProxy();
  15299. /**
  15300. * Proxy of event. can be Dom, WebGLSurface, etc.
  15301. */
  15302. this.proxy = proxy;
  15303. // Attach handler
  15304. proxy.handler = this;
  15305. /**
  15306. * @private
  15307. * @type {boolean}
  15308. */
  15309. this._hovered;
  15310. /**
  15311. * @private
  15312. * @type {Date}
  15313. */
  15314. this._lastTouchMoment;
  15315. /**
  15316. * @private
  15317. * @type {number}
  15318. */
  15319. this._lastX;
  15320. /**
  15321. * @private
  15322. * @type {number}
  15323. */
  15324. this._lastY;
  15325. Draggable.call(this);
  15326. util.each(handlerNames, function (name) {
  15327. proxy.on && proxy.on(name, this[name], this);
  15328. }, this);
  15329. };
  15330. Handler.prototype = {
  15331. constructor: Handler,
  15332. mousemove: function (event) {
  15333. var x = event.zrX;
  15334. var y = event.zrY;
  15335. var hovered = this.findHover(x, y, null);
  15336. var lastHovered = this._hovered;
  15337. var proxy = this.proxy;
  15338. this._hovered = hovered;
  15339. proxy.setCursor && proxy.setCursor(hovered ? hovered.cursor : 'default');
  15340. // Mouse out on previous hovered element
  15341. if (lastHovered && hovered !== lastHovered && lastHovered.__zr) {
  15342. this.dispatchToElement(lastHovered, 'mouseout', event);
  15343. }
  15344. // Mouse moving on one element
  15345. this.dispatchToElement(hovered, 'mousemove', event);
  15346. // Mouse over on a new element
  15347. if (hovered && hovered !== lastHovered) {
  15348. this.dispatchToElement(hovered, 'mouseover', event);
  15349. }
  15350. },
  15351. mouseout: function (event) {
  15352. this.dispatchToElement(this._hovered, 'mouseout', event);
  15353. // There might be some doms created by upper layer application
  15354. // at the same level of painter.getViewportRoot() (e.g., tooltip
  15355. // dom created by echarts), where 'globalout' event should not
  15356. // be triggered when mouse enters these doms. (But 'mouseout'
  15357. // should be triggered at the original hovered element as usual).
  15358. var element = event.toElement || event.relatedTarget;
  15359. var innerDom;
  15360. do {
  15361. element = element && element.parentNode;
  15362. }
  15363. while (element && element.nodeType != 9 && !(
  15364. innerDom = element === this.painterRoot
  15365. ));
  15366. !innerDom && this.trigger('globalout', {event: event});
  15367. },
  15368. /**
  15369. * Resize
  15370. */
  15371. resize: function (event) {
  15372. this._hovered = null;
  15373. },
  15374. /**
  15375. * Dispatch event
  15376. * @param {string} eventName
  15377. * @param {event=} eventArgs
  15378. */
  15379. dispatch: function (eventName, eventArgs) {
  15380. var handler = this[eventName];
  15381. handler && handler.call(this, eventArgs);
  15382. },
  15383. /**
  15384. * Dispose
  15385. */
  15386. dispose: function () {
  15387. this.proxy.dispose();
  15388. this.storage =
  15389. this.proxy =
  15390. this.painter = null;
  15391. },
  15392. /**
  15393. * 设置默认的cursor style
  15394. * @param {string} [cursorStyle='default'] 例如 crosshair
  15395. */
  15396. setCursorStyle: function (cursorStyle) {
  15397. var proxy = this.proxy;
  15398. proxy.setCursor && proxy.setCursor(cursorStyle);
  15399. },
  15400. /**
  15401. * 事件分发代理
  15402. *
  15403. * @private
  15404. * @param {Object} targetEl 目标图形元素
  15405. * @param {string} eventName 事件名称
  15406. * @param {Object} event 事件对象
  15407. */
  15408. dispatchToElement: function (targetEl, eventName, event) {
  15409. var eventHandler = 'on' + eventName;
  15410. var eventPacket = makeEventPacket(eventName, targetEl, event);
  15411. var el = targetEl;
  15412. while (el) {
  15413. el[eventHandler]
  15414. && (eventPacket.cancelBubble = el[eventHandler].call(el, eventPacket));
  15415. el.trigger(eventName, eventPacket);
  15416. el = el.parent;
  15417. if (eventPacket.cancelBubble) {
  15418. break;
  15419. }
  15420. }
  15421. if (!eventPacket.cancelBubble) {
  15422. // 冒泡到顶级 zrender 对象
  15423. this.trigger(eventName, eventPacket);
  15424. // 分发事件到用户自定义层
  15425. // 用户有可能在全局 click 事件中 dispose,所以需要判断下 painter 是否存在
  15426. this.painter && this.painter.eachOtherLayer(function (layer) {
  15427. if (typeof(layer[eventHandler]) == 'function') {
  15428. layer[eventHandler].call(layer, eventPacket);
  15429. }
  15430. if (layer.trigger) {
  15431. layer.trigger(eventName, eventPacket);
  15432. }
  15433. });
  15434. }
  15435. },
  15436. /**
  15437. * @private
  15438. * @param {number} x
  15439. * @param {number} y
  15440. * @param {module:zrender/graphic/Displayable} exclude
  15441. * @method
  15442. */
  15443. findHover: function(x, y, exclude) {
  15444. var list = this.storage.getDisplayList();
  15445. for (var i = list.length - 1; i >= 0 ; i--) {
  15446. if (!list[i].silent
  15447. && list[i] !== exclude
  15448. // getDisplayList may include ignored item in VML mode
  15449. && !list[i].ignore
  15450. && isHover(list[i], x, y)) {
  15451. return list[i];
  15452. }
  15453. }
  15454. }
  15455. };
  15456. // Common handlers
  15457. util.each(['click', 'mousedown', 'mouseup', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  15458. Handler.prototype[name] = function (event) {
  15459. // Find hover again to avoid click event is dispatched manually. Or click is triggered without mouseover
  15460. var hovered = this.findHover(event.zrX, event.zrY, null);
  15461. if (name === 'mousedown') {
  15462. this._downel = hovered;
  15463. // In case click triggered before mouseup
  15464. this._upel = hovered;
  15465. }
  15466. else if (name === 'mosueup') {
  15467. this._upel = hovered;
  15468. }
  15469. else if (name === 'click') {
  15470. if (this._downel !== this._upel) {
  15471. return;
  15472. }
  15473. }
  15474. this.dispatchToElement(hovered, name, event);
  15475. };
  15476. });
  15477. function isHover(displayable, x, y) {
  15478. if (displayable[displayable.rectHover ? 'rectContain' : 'contain'](x, y)) {
  15479. var el = displayable;
  15480. while (el) {
  15481. // If ancestor is silent or clipped by ancestor
  15482. if (el.silent || (el.clipPath && !el.clipPath.contain(x, y))) {
  15483. return false;
  15484. }
  15485. el = el.parent;
  15486. }
  15487. return true;
  15488. }
  15489. return false;
  15490. }
  15491. util.mixin(Handler, Eventful);
  15492. util.mixin(Handler, Draggable);
  15493. module.exports = Handler;
  15494. /***/ },
  15495. /* 84 */
  15496. /***/ function(module, exports) {
  15497. // TODO Draggable for group
  15498. // FIXME Draggable on element which has parent rotation or scale
  15499. function Draggable() {
  15500. this.on('mousedown', this._dragStart, this);
  15501. this.on('mousemove', this._drag, this);
  15502. this.on('mouseup', this._dragEnd, this);
  15503. this.on('globalout', this._dragEnd, this);
  15504. // this._dropTarget = null;
  15505. // this._draggingTarget = null;
  15506. // this._x = 0;
  15507. // this._y = 0;
  15508. }
  15509. Draggable.prototype = {
  15510. constructor: Draggable,
  15511. _dragStart: function (e) {
  15512. var draggingTarget = e.target;
  15513. if (draggingTarget && draggingTarget.draggable) {
  15514. this._draggingTarget = draggingTarget;
  15515. draggingTarget.dragging = true;
  15516. this._x = e.offsetX;
  15517. this._y = e.offsetY;
  15518. this.dispatchToElement(draggingTarget, 'dragstart', e.event);
  15519. }
  15520. },
  15521. _drag: function (e) {
  15522. var draggingTarget = this._draggingTarget;
  15523. if (draggingTarget) {
  15524. var x = e.offsetX;
  15525. var y = e.offsetY;
  15526. var dx = x - this._x;
  15527. var dy = y - this._y;
  15528. this._x = x;
  15529. this._y = y;
  15530. draggingTarget.drift(dx, dy, e);
  15531. this.dispatchToElement(draggingTarget, 'drag', e.event);
  15532. var dropTarget = this.findHover(x, y, draggingTarget);
  15533. var lastDropTarget = this._dropTarget;
  15534. this._dropTarget = dropTarget;
  15535. if (draggingTarget !== dropTarget) {
  15536. if (lastDropTarget && dropTarget !== lastDropTarget) {
  15537. this.dispatchToElement(lastDropTarget, 'dragleave', e.event);
  15538. }
  15539. if (dropTarget && dropTarget !== lastDropTarget) {
  15540. this.dispatchToElement(dropTarget, 'dragenter', e.event);
  15541. }
  15542. }
  15543. }
  15544. },
  15545. _dragEnd: function (e) {
  15546. var draggingTarget = this._draggingTarget;
  15547. if (draggingTarget) {
  15548. draggingTarget.dragging = false;
  15549. }
  15550. this.dispatchToElement(draggingTarget, 'dragend', e.event);
  15551. if (this._dropTarget) {
  15552. this.dispatchToElement(this._dropTarget, 'drop', e.event);
  15553. }
  15554. this._draggingTarget = null;
  15555. this._dropTarget = null;
  15556. }
  15557. };
  15558. module.exports = Draggable;
  15559. /***/ },
  15560. /* 85 */
  15561. /***/ function(module, exports, __webpack_require__) {
  15562. 'use strict';
  15563. /**
  15564. * Storage内容仓库模块
  15565. * @module zrender/Storage
  15566. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  15567. * @author errorrik (errorrik@gmail.com)
  15568. * @author pissang (https://github.com/pissang/)
  15569. */
  15570. var util = __webpack_require__(4);
  15571. var env = __webpack_require__(2);
  15572. var Group = __webpack_require__(30);
  15573. // Use timsort because in most case elements are partially sorted
  15574. // https://jsfiddle.net/pissang/jr4x7mdm/8/
  15575. var timsort = __webpack_require__(86);
  15576. function shapeCompareFunc(a, b) {
  15577. if (a.zlevel === b.zlevel) {
  15578. if (a.z === b.z) {
  15579. // if (a.z2 === b.z2) {
  15580. // // FIXME Slow has renderidx compare
  15581. // // http://stackoverflow.com/questions/20883421/sorting-in-javascript-should-every-compare-function-have-a-return-0-statement
  15582. // // https://github.com/v8/v8/blob/47cce544a31ed5577ffe2963f67acb4144ee0232/src/js/array.js#L1012
  15583. // return a.__renderidx - b.__renderidx;
  15584. // }
  15585. return a.z2 - b.z2;
  15586. }
  15587. return a.z - b.z;
  15588. }
  15589. return a.zlevel - b.zlevel;
  15590. }
  15591. /**
  15592. * 内容仓库 (M)
  15593. * @alias module:zrender/Storage
  15594. * @constructor
  15595. */
  15596. var Storage = function () {
  15597. // 所有常规形状,id索引的map
  15598. this._elements = {};
  15599. this._roots = [];
  15600. this._displayList = [];
  15601. this._displayListLen = 0;
  15602. };
  15603. Storage.prototype = {
  15604. constructor: Storage,
  15605. /**
  15606. * @param {Function} cb
  15607. *
  15608. */
  15609. traverse: function (cb, context) {
  15610. for (var i = 0; i < this._roots.length; i++) {
  15611. this._roots[i].traverse(cb, context);
  15612. }
  15613. },
  15614. /**
  15615. * 返回所有图形的绘制队列
  15616. * @param {boolean} [update=false] 是否在返回前更新该数组
  15617. * @param {boolean} [includeIgnore=false] 是否包含 ignore 的数组, 在 update 为 true 的时候有效
  15618. *
  15619. * 详见{@link module:zrender/graphic/Displayable.prototype.updateDisplayList}
  15620. * @return {Array.<module:zrender/graphic/Displayable>}
  15621. */
  15622. getDisplayList: function (update, includeIgnore) {
  15623. includeIgnore = includeIgnore || false;
  15624. if (update) {
  15625. this.updateDisplayList(includeIgnore);
  15626. }
  15627. return this._displayList;
  15628. },
  15629. /**
  15630. * 更新图形的绘制队列。
  15631. * 每次绘制前都会调用,该方法会先深度优先遍历整个树,更新所有Group和Shape的变换并且把所有可见的Shape保存到数组中,
  15632. * 最后根据绘制的优先级(zlevel > z > 插入顺序)排序得到绘制队列
  15633. * @param {boolean} [includeIgnore=false] 是否包含 ignore 的数组
  15634. */
  15635. updateDisplayList: function (includeIgnore) {
  15636. this._displayListLen = 0;
  15637. var roots = this._roots;
  15638. var displayList = this._displayList;
  15639. for (var i = 0, len = roots.length; i < len; i++) {
  15640. this._updateAndAddDisplayable(roots[i], null, includeIgnore);
  15641. }
  15642. displayList.length = this._displayListLen;
  15643. // for (var i = 0, len = displayList.length; i < len; i++) {
  15644. // displayList[i].__renderidx = i;
  15645. // }
  15646. // displayList.sort(shapeCompareFunc);
  15647. env.canvasSupported && timsort(displayList, shapeCompareFunc);
  15648. },
  15649. _updateAndAddDisplayable: function (el, clipPaths, includeIgnore) {
  15650. if (el.ignore && !includeIgnore) {
  15651. return;
  15652. }
  15653. el.beforeUpdate();
  15654. if (el.__dirty) {
  15655. el.update();
  15656. }
  15657. el.afterUpdate();
  15658. var userSetClipPath = el.clipPath;
  15659. if (userSetClipPath) {
  15660. // FIXME 效率影响
  15661. if (clipPaths) {
  15662. clipPaths = clipPaths.slice();
  15663. }
  15664. else {
  15665. clipPaths = [];
  15666. }
  15667. var currentClipPath = userSetClipPath;
  15668. var parentClipPath = el;
  15669. // Recursively add clip path
  15670. while (currentClipPath) {
  15671. // clipPath 的变换是基于使用这个 clipPath 的元素
  15672. currentClipPath.parent = parentClipPath;
  15673. currentClipPath.updateTransform();
  15674. clipPaths.push(currentClipPath);
  15675. parentClipPath = currentClipPath;
  15676. currentClipPath = currentClipPath.clipPath;
  15677. }
  15678. }
  15679. if (el.isGroup) {
  15680. var children = el._children;
  15681. for (var i = 0; i < children.length; i++) {
  15682. var child = children[i];
  15683. // Force to mark as dirty if group is dirty
  15684. // FIXME __dirtyPath ?
  15685. if (el.__dirty) {
  15686. child.__dirty = true;
  15687. }
  15688. this._updateAndAddDisplayable(child, clipPaths, includeIgnore);
  15689. }
  15690. // Mark group clean here
  15691. el.__dirty = false;
  15692. }
  15693. else {
  15694. el.__clipPaths = clipPaths;
  15695. this._displayList[this._displayListLen++] = el;
  15696. }
  15697. },
  15698. /**
  15699. * 添加图形(Shape)或者组(Group)到根节点
  15700. * @param {module:zrender/Element} el
  15701. */
  15702. addRoot: function (el) {
  15703. // Element has been added
  15704. if (this._elements[el.id]) {
  15705. return;
  15706. }
  15707. if (el instanceof Group) {
  15708. el.addChildrenToStorage(this);
  15709. }
  15710. this.addToMap(el);
  15711. this._roots.push(el);
  15712. },
  15713. /**
  15714. * 删除指定的图形(Shape)或者组(Group)
  15715. * @param {string|Array.<string>} [elId] 如果为空清空整个Storage
  15716. */
  15717. delRoot: function (elId) {
  15718. if (elId == null) {
  15719. // 不指定elId清空
  15720. for (var i = 0; i < this._roots.length; i++) {
  15721. var root = this._roots[i];
  15722. if (root instanceof Group) {
  15723. root.delChildrenFromStorage(this);
  15724. }
  15725. }
  15726. this._elements = {};
  15727. this._roots = [];
  15728. this._displayList = [];
  15729. this._displayListLen = 0;
  15730. return;
  15731. }
  15732. if (elId instanceof Array) {
  15733. for (var i = 0, l = elId.length; i < l; i++) {
  15734. this.delRoot(elId[i]);
  15735. }
  15736. return;
  15737. }
  15738. var el;
  15739. if (typeof(elId) == 'string') {
  15740. el = this._elements[elId];
  15741. }
  15742. else {
  15743. el = elId;
  15744. }
  15745. var idx = util.indexOf(this._roots, el);
  15746. if (idx >= 0) {
  15747. this.delFromMap(el.id);
  15748. this._roots.splice(idx, 1);
  15749. if (el instanceof Group) {
  15750. el.delChildrenFromStorage(this);
  15751. }
  15752. }
  15753. },
  15754. addToMap: function (el) {
  15755. if (el instanceof Group) {
  15756. el.__storage = this;
  15757. }
  15758. el.dirty(false);
  15759. this._elements[el.id] = el;
  15760. return this;
  15761. },
  15762. get: function (elId) {
  15763. return this._elements[elId];
  15764. },
  15765. delFromMap: function (elId) {
  15766. var elements = this._elements;
  15767. var el = elements[elId];
  15768. if (el) {
  15769. delete elements[elId];
  15770. if (el instanceof Group) {
  15771. el.__storage = null;
  15772. }
  15773. }
  15774. return this;
  15775. },
  15776. /**
  15777. * 清空并且释放Storage
  15778. */
  15779. dispose: function () {
  15780. this._elements =
  15781. this._renderList =
  15782. this._roots = null;
  15783. },
  15784. displayableSortFunc: shapeCompareFunc
  15785. };
  15786. module.exports = Storage;
  15787. /***/ },
  15788. /* 86 */
  15789. /***/ function(module, exports) {
  15790. // https://github.com/mziccard/node-timsort
  15791. var DEFAULT_MIN_MERGE = 32;
  15792. var DEFAULT_MIN_GALLOPING = 7;
  15793. var DEFAULT_TMP_STORAGE_LENGTH = 256;
  15794. function minRunLength(n) {
  15795. var r = 0;
  15796. while (n >= DEFAULT_MIN_MERGE) {
  15797. r |= n & 1;
  15798. n >>= 1;
  15799. }
  15800. return n + r;
  15801. }
  15802. function makeAscendingRun(array, lo, hi, compare) {
  15803. var runHi = lo + 1;
  15804. if (runHi === hi) {
  15805. return 1;
  15806. }
  15807. if (compare(array[runHi++], array[lo]) < 0) {
  15808. while (runHi < hi && compare(array[runHi], array[runHi - 1]) < 0) {
  15809. runHi++;
  15810. }
  15811. reverseRun(array, lo, runHi);
  15812. }
  15813. else {
  15814. while (runHi < hi && compare(array[runHi], array[runHi - 1]) >= 0) {
  15815. runHi++;
  15816. }
  15817. }
  15818. return runHi - lo;
  15819. }
  15820. function reverseRun(array, lo, hi) {
  15821. hi--;
  15822. while (lo < hi) {
  15823. var t = array[lo];
  15824. array[lo++] = array[hi];
  15825. array[hi--] = t;
  15826. }
  15827. }
  15828. function binaryInsertionSort(array, lo, hi, start, compare) {
  15829. if (start === lo) {
  15830. start++;
  15831. }
  15832. for (; start < hi; start++) {
  15833. var pivot = array[start];
  15834. var left = lo;
  15835. var right = start;
  15836. var mid;
  15837. while (left < right) {
  15838. mid = left + right >>> 1;
  15839. if (compare(pivot, array[mid]) < 0) {
  15840. right = mid;
  15841. }
  15842. else {
  15843. left = mid + 1;
  15844. }
  15845. }
  15846. var n = start - left;
  15847. switch (n) {
  15848. case 3:
  15849. array[left + 3] = array[left + 2];
  15850. case 2:
  15851. array[left + 2] = array[left + 1];
  15852. case 1:
  15853. array[left + 1] = array[left];
  15854. break;
  15855. default:
  15856. while (n > 0) {
  15857. array[left + n] = array[left + n - 1];
  15858. n--;
  15859. }
  15860. }
  15861. array[left] = pivot;
  15862. }
  15863. }
  15864. function gallopLeft(value, array, start, length, hint, compare) {
  15865. var lastOffset = 0;
  15866. var maxOffset = 0;
  15867. var offset = 1;
  15868. if (compare(value, array[start + hint]) > 0) {
  15869. maxOffset = length - hint;
  15870. while (offset < maxOffset && compare(value, array[start + hint + offset]) > 0) {
  15871. lastOffset = offset;
  15872. offset = (offset << 1) + 1;
  15873. if (offset <= 0) {
  15874. offset = maxOffset;
  15875. }
  15876. }
  15877. if (offset > maxOffset) {
  15878. offset = maxOffset;
  15879. }
  15880. lastOffset += hint;
  15881. offset += hint;
  15882. }
  15883. else {
  15884. maxOffset = hint + 1;
  15885. while (offset < maxOffset && compare(value, array[start + hint - offset]) <= 0) {
  15886. lastOffset = offset;
  15887. offset = (offset << 1) + 1;
  15888. if (offset <= 0) {
  15889. offset = maxOffset;
  15890. }
  15891. }
  15892. if (offset > maxOffset) {
  15893. offset = maxOffset;
  15894. }
  15895. var tmp = lastOffset;
  15896. lastOffset = hint - offset;
  15897. offset = hint - tmp;
  15898. }
  15899. lastOffset++;
  15900. while (lastOffset < offset) {
  15901. var m = lastOffset + (offset - lastOffset >>> 1);
  15902. if (compare(value, array[start + m]) > 0) {
  15903. lastOffset = m + 1;
  15904. }
  15905. else {
  15906. offset = m;
  15907. }
  15908. }
  15909. return offset;
  15910. }
  15911. function gallopRight(value, array, start, length, hint, compare) {
  15912. var lastOffset = 0;
  15913. var maxOffset = 0;
  15914. var offset = 1;
  15915. if (compare(value, array[start + hint]) < 0) {
  15916. maxOffset = hint + 1;
  15917. while (offset < maxOffset && compare(value, array[start + hint - offset]) < 0) {
  15918. lastOffset = offset;
  15919. offset = (offset << 1) + 1;
  15920. if (offset <= 0) {
  15921. offset = maxOffset;
  15922. }
  15923. }
  15924. if (offset > maxOffset) {
  15925. offset = maxOffset;
  15926. }
  15927. var tmp = lastOffset;
  15928. lastOffset = hint - offset;
  15929. offset = hint - tmp;
  15930. }
  15931. else {
  15932. maxOffset = length - hint;
  15933. while (offset < maxOffset && compare(value, array[start + hint + offset]) >= 0) {
  15934. lastOffset = offset;
  15935. offset = (offset << 1) + 1;
  15936. if (offset <= 0) {
  15937. offset = maxOffset;
  15938. }
  15939. }
  15940. if (offset > maxOffset) {
  15941. offset = maxOffset;
  15942. }
  15943. lastOffset += hint;
  15944. offset += hint;
  15945. }
  15946. lastOffset++;
  15947. while (lastOffset < offset) {
  15948. var m = lastOffset + (offset - lastOffset >>> 1);
  15949. if (compare(value, array[start + m]) < 0) {
  15950. offset = m;
  15951. }
  15952. else {
  15953. lastOffset = m + 1;
  15954. }
  15955. }
  15956. return offset;
  15957. }
  15958. function TimSort(array, compare) {
  15959. var minGallop = DEFAULT_MIN_GALLOPING;
  15960. var length = 0;
  15961. var tmpStorageLength = DEFAULT_TMP_STORAGE_LENGTH;
  15962. var stackLength = 0;
  15963. var runStart;
  15964. var runLength;
  15965. var stackSize = 0;
  15966. length = array.length;
  15967. if (length < 2 * DEFAULT_TMP_STORAGE_LENGTH) {
  15968. tmpStorageLength = length >>> 1;
  15969. }
  15970. var tmp = [];
  15971. stackLength = length < 120 ? 5 : length < 1542 ? 10 : length < 119151 ? 19 : 40;
  15972. runStart = [];
  15973. runLength = [];
  15974. function pushRun(_runStart, _runLength) {
  15975. runStart[stackSize] = _runStart;
  15976. runLength[stackSize] = _runLength;
  15977. stackSize += 1;
  15978. }
  15979. function mergeRuns() {
  15980. while (stackSize > 1) {
  15981. var n = stackSize - 2;
  15982. if (n >= 1 && runLength[n - 1] <= runLength[n] + runLength[n + 1] || n >= 2 && runLength[n - 2] <= runLength[n] + runLength[n - 1]) {
  15983. if (runLength[n - 1] < runLength[n + 1]) {
  15984. n--;
  15985. }
  15986. }
  15987. else if (runLength[n] > runLength[n + 1]) {
  15988. break;
  15989. }
  15990. mergeAt(n);
  15991. }
  15992. }
  15993. function forceMergeRuns() {
  15994. while (stackSize > 1) {
  15995. var n = stackSize - 2;
  15996. if (n > 0 && runLength[n - 1] < runLength[n + 1]) {
  15997. n--;
  15998. }
  15999. mergeAt(n);
  16000. }
  16001. }
  16002. function mergeAt(i) {
  16003. var start1 = runStart[i];
  16004. var length1 = runLength[i];
  16005. var start2 = runStart[i + 1];
  16006. var length2 = runLength[i + 1];
  16007. runLength[i] = length1 + length2;
  16008. if (i === stackSize - 3) {
  16009. runStart[i + 1] = runStart[i + 2];
  16010. runLength[i + 1] = runLength[i + 2];
  16011. }
  16012. stackSize--;
  16013. var k = gallopRight(array[start2], array, start1, length1, 0, compare);
  16014. start1 += k;
  16015. length1 -= k;
  16016. if (length1 === 0) {
  16017. return;
  16018. }
  16019. length2 = gallopLeft(array[start1 + length1 - 1], array, start2, length2, length2 - 1, compare);
  16020. if (length2 === 0) {
  16021. return;
  16022. }
  16023. if (length1 <= length2) {
  16024. mergeLow(start1, length1, start2, length2);
  16025. }
  16026. else {
  16027. mergeHigh(start1, length1, start2, length2);
  16028. }
  16029. }
  16030. function mergeLow(start1, length1, start2, length2) {
  16031. var i = 0;
  16032. for (i = 0; i < length1; i++) {
  16033. tmp[i] = array[start1 + i];
  16034. }
  16035. var cursor1 = 0;
  16036. var cursor2 = start2;
  16037. var dest = start1;
  16038. array[dest++] = array[cursor2++];
  16039. if (--length2 === 0) {
  16040. for (i = 0; i < length1; i++) {
  16041. array[dest + i] = tmp[cursor1 + i];
  16042. }
  16043. return;
  16044. }
  16045. if (length1 === 1) {
  16046. for (i = 0; i < length2; i++) {
  16047. array[dest + i] = array[cursor2 + i];
  16048. }
  16049. array[dest + length2] = tmp[cursor1];
  16050. return;
  16051. }
  16052. var _minGallop = minGallop;
  16053. var count1, count2, exit;
  16054. while (1) {
  16055. count1 = 0;
  16056. count2 = 0;
  16057. exit = false;
  16058. do {
  16059. if (compare(array[cursor2], tmp[cursor1]) < 0) {
  16060. array[dest++] = array[cursor2++];
  16061. count2++;
  16062. count1 = 0;
  16063. if (--length2 === 0) {
  16064. exit = true;
  16065. break;
  16066. }
  16067. }
  16068. else {
  16069. array[dest++] = tmp[cursor1++];
  16070. count1++;
  16071. count2 = 0;
  16072. if (--length1 === 1) {
  16073. exit = true;
  16074. break;
  16075. }
  16076. }
  16077. } while ((count1 | count2) < _minGallop);
  16078. if (exit) {
  16079. break;
  16080. }
  16081. do {
  16082. count1 = gallopRight(array[cursor2], tmp, cursor1, length1, 0, compare);
  16083. if (count1 !== 0) {
  16084. for (i = 0; i < count1; i++) {
  16085. array[dest + i] = tmp[cursor1 + i];
  16086. }
  16087. dest += count1;
  16088. cursor1 += count1;
  16089. length1 -= count1;
  16090. if (length1 <= 1) {
  16091. exit = true;
  16092. break;
  16093. }
  16094. }
  16095. array[dest++] = array[cursor2++];
  16096. if (--length2 === 0) {
  16097. exit = true;
  16098. break;
  16099. }
  16100. count2 = gallopLeft(tmp[cursor1], array, cursor2, length2, 0, compare);
  16101. if (count2 !== 0) {
  16102. for (i = 0; i < count2; i++) {
  16103. array[dest + i] = array[cursor2 + i];
  16104. }
  16105. dest += count2;
  16106. cursor2 += count2;
  16107. length2 -= count2;
  16108. if (length2 === 0) {
  16109. exit = true;
  16110. break;
  16111. }
  16112. }
  16113. array[dest++] = tmp[cursor1++];
  16114. if (--length1 === 1) {
  16115. exit = true;
  16116. break;
  16117. }
  16118. _minGallop--;
  16119. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  16120. if (exit) {
  16121. break;
  16122. }
  16123. if (_minGallop < 0) {
  16124. _minGallop = 0;
  16125. }
  16126. _minGallop += 2;
  16127. }
  16128. minGallop = _minGallop;
  16129. minGallop < 1 && (minGallop = 1);
  16130. if (length1 === 1) {
  16131. for (i = 0; i < length2; i++) {
  16132. array[dest + i] = array[cursor2 + i];
  16133. }
  16134. array[dest + length2] = tmp[cursor1];
  16135. }
  16136. else if (length1 === 0) {
  16137. throw new Error();
  16138. // throw new Error('mergeLow preconditions were not respected');
  16139. }
  16140. else {
  16141. for (i = 0; i < length1; i++) {
  16142. array[dest + i] = tmp[cursor1 + i];
  16143. }
  16144. }
  16145. }
  16146. function mergeHigh (start1, length1, start2, length2) {
  16147. var i = 0;
  16148. for (i = 0; i < length2; i++) {
  16149. tmp[i] = array[start2 + i];
  16150. }
  16151. var cursor1 = start1 + length1 - 1;
  16152. var cursor2 = length2 - 1;
  16153. var dest = start2 + length2 - 1;
  16154. var customCursor = 0;
  16155. var customDest = 0;
  16156. array[dest--] = array[cursor1--];
  16157. if (--length1 === 0) {
  16158. customCursor = dest - (length2 - 1);
  16159. for (i = 0; i < length2; i++) {
  16160. array[customCursor + i] = tmp[i];
  16161. }
  16162. return;
  16163. }
  16164. if (length2 === 1) {
  16165. dest -= length1;
  16166. cursor1 -= length1;
  16167. customDest = dest + 1;
  16168. customCursor = cursor1 + 1;
  16169. for (i = length1 - 1; i >= 0; i--) {
  16170. array[customDest + i] = array[customCursor + i];
  16171. }
  16172. array[dest] = tmp[cursor2];
  16173. return;
  16174. }
  16175. var _minGallop = minGallop;
  16176. while (true) {
  16177. var count1 = 0;
  16178. var count2 = 0;
  16179. var exit = false;
  16180. do {
  16181. if (compare(tmp[cursor2], array[cursor1]) < 0) {
  16182. array[dest--] = array[cursor1--];
  16183. count1++;
  16184. count2 = 0;
  16185. if (--length1 === 0) {
  16186. exit = true;
  16187. break;
  16188. }
  16189. }
  16190. else {
  16191. array[dest--] = tmp[cursor2--];
  16192. count2++;
  16193. count1 = 0;
  16194. if (--length2 === 1) {
  16195. exit = true;
  16196. break;
  16197. }
  16198. }
  16199. } while ((count1 | count2) < _minGallop);
  16200. if (exit) {
  16201. break;
  16202. }
  16203. do {
  16204. count1 = length1 - gallopRight(tmp[cursor2], array, start1, length1, length1 - 1, compare);
  16205. if (count1 !== 0) {
  16206. dest -= count1;
  16207. cursor1 -= count1;
  16208. length1 -= count1;
  16209. customDest = dest + 1;
  16210. customCursor = cursor1 + 1;
  16211. for (i = count1 - 1; i >= 0; i--) {
  16212. array[customDest + i] = array[customCursor + i];
  16213. }
  16214. if (length1 === 0) {
  16215. exit = true;
  16216. break;
  16217. }
  16218. }
  16219. array[dest--] = tmp[cursor2--];
  16220. if (--length2 === 1) {
  16221. exit = true;
  16222. break;
  16223. }
  16224. count2 = length2 - gallopLeft(array[cursor1], tmp, 0, length2, length2 - 1, compare);
  16225. if (count2 !== 0) {
  16226. dest -= count2;
  16227. cursor2 -= count2;
  16228. length2 -= count2;
  16229. customDest = dest + 1;
  16230. customCursor = cursor2 + 1;
  16231. for (i = 0; i < count2; i++) {
  16232. array[customDest + i] = tmp[customCursor + i];
  16233. }
  16234. if (length2 <= 1) {
  16235. exit = true;
  16236. break;
  16237. }
  16238. }
  16239. array[dest--] = array[cursor1--];
  16240. if (--length1 === 0) {
  16241. exit = true;
  16242. break;
  16243. }
  16244. _minGallop--;
  16245. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  16246. if (exit) {
  16247. break;
  16248. }
  16249. if (_minGallop < 0) {
  16250. _minGallop = 0;
  16251. }
  16252. _minGallop += 2;
  16253. }
  16254. minGallop = _minGallop;
  16255. if (minGallop < 1) {
  16256. minGallop = 1;
  16257. }
  16258. if (length2 === 1) {
  16259. dest -= length1;
  16260. cursor1 -= length1;
  16261. customDest = dest + 1;
  16262. customCursor = cursor1 + 1;
  16263. for (i = length1 - 1; i >= 0; i--) {
  16264. array[customDest + i] = array[customCursor + i];
  16265. }
  16266. array[dest] = tmp[cursor2];
  16267. }
  16268. else if (length2 === 0) {
  16269. throw new Error();
  16270. // throw new Error('mergeHigh preconditions were not respected');
  16271. }
  16272. else {
  16273. customCursor = dest - (length2 - 1);
  16274. for (i = 0; i < length2; i++) {
  16275. array[customCursor + i] = tmp[i];
  16276. }
  16277. }
  16278. }
  16279. this.mergeRuns = mergeRuns;
  16280. this.forceMergeRuns = forceMergeRuns;
  16281. this.pushRun = pushRun;
  16282. }
  16283. function sort(array, compare, lo, hi) {
  16284. if (!lo) {
  16285. lo = 0;
  16286. }
  16287. if (!hi) {
  16288. hi = array.length;
  16289. }
  16290. var remaining = hi - lo;
  16291. if (remaining < 2) {
  16292. return;
  16293. }
  16294. var runLength = 0;
  16295. if (remaining < DEFAULT_MIN_MERGE) {
  16296. runLength = makeAscendingRun(array, lo, hi, compare);
  16297. binaryInsertionSort(array, lo, hi, lo + runLength, compare);
  16298. return;
  16299. }
  16300. var ts = new TimSort(array, compare);
  16301. var minRun = minRunLength(remaining);
  16302. do {
  16303. runLength = makeAscendingRun(array, lo, hi, compare);
  16304. if (runLength < minRun) {
  16305. var force = remaining;
  16306. if (force > minRun) {
  16307. force = minRun;
  16308. }
  16309. binaryInsertionSort(array, lo, lo + force, lo + runLength, compare);
  16310. runLength = force;
  16311. }
  16312. ts.pushRun(lo, runLength);
  16313. ts.mergeRuns();
  16314. remaining -= runLength;
  16315. lo += runLength;
  16316. } while (remaining !== 0);
  16317. ts.forceMergeRuns();
  16318. }
  16319. module.exports = sort;
  16320. /***/ },
  16321. /* 87 */
  16322. /***/ function(module, exports, __webpack_require__) {
  16323. 'use strict';
  16324. /**
  16325. * 动画主类, 调度和管理所有动画控制器
  16326. *
  16327. * @module zrender/animation/Animation
  16328. * @author pissang(https://github.com/pissang)
  16329. */
  16330. // TODO Additive animation
  16331. // http://iosoteric.com/additive-animations-animatewithduration-in-ios-8/
  16332. // https://developer.apple.com/videos/wwdc2014/#236
  16333. var util = __webpack_require__(4);
  16334. var Dispatcher = __webpack_require__(88).Dispatcher;
  16335. var requestAnimationFrame = __webpack_require__(89);
  16336. var Animator = __webpack_require__(36);
  16337. /**
  16338. * @typedef {Object} IZRenderStage
  16339. * @property {Function} update
  16340. */
  16341. /**
  16342. * @alias module:zrender/animation/Animation
  16343. * @constructor
  16344. * @param {Object} [options]
  16345. * @param {Function} [options.onframe]
  16346. * @param {IZRenderStage} [options.stage]
  16347. * @example
  16348. * var animation = new Animation();
  16349. * var obj = {
  16350. * x: 100,
  16351. * y: 100
  16352. * };
  16353. * animation.animate(node.position)
  16354. * .when(1000, {
  16355. * x: 500,
  16356. * y: 500
  16357. * })
  16358. * .when(2000, {
  16359. * x: 100,
  16360. * y: 100
  16361. * })
  16362. * .start('spline');
  16363. */
  16364. var Animation = function (options) {
  16365. options = options || {};
  16366. this.stage = options.stage || {};
  16367. this.onframe = options.onframe || function() {};
  16368. // private properties
  16369. this._clips = [];
  16370. this._running = false;
  16371. this._time;
  16372. this._pausedTime;
  16373. this._pauseStart;
  16374. this._paused = false;
  16375. Dispatcher.call(this);
  16376. };
  16377. Animation.prototype = {
  16378. constructor: Animation,
  16379. /**
  16380. * 添加 clip
  16381. * @param {module:zrender/animation/Clip} clip
  16382. */
  16383. addClip: function (clip) {
  16384. this._clips.push(clip);
  16385. },
  16386. /**
  16387. * 添加 animator
  16388. * @param {module:zrender/animation/Animator} animator
  16389. */
  16390. addAnimator: function (animator) {
  16391. animator.animation = this;
  16392. var clips = animator.getClips();
  16393. for (var i = 0; i < clips.length; i++) {
  16394. this.addClip(clips[i]);
  16395. }
  16396. },
  16397. /**
  16398. * 删除动画片段
  16399. * @param {module:zrender/animation/Clip} clip
  16400. */
  16401. removeClip: function(clip) {
  16402. var idx = util.indexOf(this._clips, clip);
  16403. if (idx >= 0) {
  16404. this._clips.splice(idx, 1);
  16405. }
  16406. },
  16407. /**
  16408. * 删除动画片段
  16409. * @param {module:zrender/animation/Animator} animator
  16410. */
  16411. removeAnimator: function (animator) {
  16412. var clips = animator.getClips();
  16413. for (var i = 0; i < clips.length; i++) {
  16414. this.removeClip(clips[i]);
  16415. }
  16416. animator.animation = null;
  16417. },
  16418. _update: function() {
  16419. var time = new Date().getTime() - this._pausedTime;
  16420. var delta = time - this._time;
  16421. var clips = this._clips;
  16422. var len = clips.length;
  16423. var deferredEvents = [];
  16424. var deferredClips = [];
  16425. for (var i = 0; i < len; i++) {
  16426. var clip = clips[i];
  16427. var e = clip.step(time);
  16428. // Throw out the events need to be called after
  16429. // stage.update, like destroy
  16430. if (e) {
  16431. deferredEvents.push(e);
  16432. deferredClips.push(clip);
  16433. }
  16434. }
  16435. // Remove the finished clip
  16436. for (var i = 0; i < len;) {
  16437. if (clips[i]._needsRemove) {
  16438. clips[i] = clips[len - 1];
  16439. clips.pop();
  16440. len--;
  16441. }
  16442. else {
  16443. i++;
  16444. }
  16445. }
  16446. len = deferredEvents.length;
  16447. for (var i = 0; i < len; i++) {
  16448. deferredClips[i].fire(deferredEvents[i]);
  16449. }
  16450. this._time = time;
  16451. this.onframe(delta);
  16452. this.trigger('frame', delta);
  16453. if (this.stage.update) {
  16454. this.stage.update();
  16455. }
  16456. },
  16457. _startLoop: function () {
  16458. var self = this;
  16459. this._running = true;
  16460. function step() {
  16461. if (self._running) {
  16462. requestAnimationFrame(step);
  16463. !self._paused && self._update();
  16464. }
  16465. }
  16466. requestAnimationFrame(step);
  16467. },
  16468. /**
  16469. * 开始运行动画
  16470. */
  16471. start: function () {
  16472. this._time = new Date().getTime();
  16473. this._pausedTime = 0;
  16474. this._startLoop();
  16475. },
  16476. /**
  16477. * 停止运行动画
  16478. */
  16479. stop: function () {
  16480. this._running = false;
  16481. },
  16482. /**
  16483. * Pause
  16484. */
  16485. pause: function () {
  16486. if (!this._paused) {
  16487. this._pauseStart = new Date().getTime();
  16488. this._paused = true;
  16489. }
  16490. },
  16491. /**
  16492. * Resume
  16493. */
  16494. resume: function () {
  16495. if (this._paused) {
  16496. this._pausedTime += (new Date().getTime()) - this._pauseStart;
  16497. this._paused = false;
  16498. }
  16499. },
  16500. /**
  16501. * 清除所有动画片段
  16502. */
  16503. clear: function () {
  16504. this._clips = [];
  16505. },
  16506. /**
  16507. * 对一个目标创建一个animator对象,可以指定目标中的属性使用动画
  16508. * @param {Object} target
  16509. * @param {Object} options
  16510. * @param {boolean} [options.loop=false] 是否循环播放动画
  16511. * @param {Function} [options.getter=null]
  16512. * 如果指定getter函数,会通过getter函数取属性值
  16513. * @param {Function} [options.setter=null]
  16514. * 如果指定setter函数,会通过setter函数设置属性值
  16515. * @return {module:zrender/animation/Animation~Animator}
  16516. */
  16517. // TODO Gap
  16518. animate: function (target, options) {
  16519. options = options || {};
  16520. var animator = new Animator(
  16521. target,
  16522. options.loop,
  16523. options.getter,
  16524. options.setter
  16525. );
  16526. this.addAnimator(animator);
  16527. return animator;
  16528. }
  16529. };
  16530. util.mixin(Animation, Dispatcher);
  16531. module.exports = Animation;
  16532. /***/ },
  16533. /* 88 */
  16534. /***/ function(module, exports, __webpack_require__) {
  16535. 'use strict';
  16536. /**
  16537. * 事件辅助类
  16538. * @module zrender/core/event
  16539. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  16540. */
  16541. var Eventful = __webpack_require__(33);
  16542. var env = __webpack_require__(2);
  16543. var isDomLevel2 = (typeof window !== 'undefined') && !!window.addEventListener;
  16544. function getBoundingClientRect(el) {
  16545. // BlackBerry 5, iOS 3 (original iPhone) don't have getBoundingRect
  16546. return el.getBoundingClientRect ? el.getBoundingClientRect() : {left: 0, top: 0};
  16547. }
  16548. // `calculate` is optional, default false
  16549. function clientToLocal(el, e, out, calculate) {
  16550. out = out || {};
  16551. // According to the W3C Working Draft, offsetX and offsetY should be relative
  16552. // to the padding edge of the target element. The only browser using this convention
  16553. // is IE. Webkit uses the border edge, Opera uses the content edge, and FireFox does
  16554. // not support the properties.
  16555. // (see http://www.jacklmoore.com/notes/mouse-position/)
  16556. // In zr painter.dom, padding edge equals to border edge.
  16557. // FIXME
  16558. // When mousemove event triggered on ec tooltip, target is not zr painter.dom, and
  16559. // offsetX/Y is relative to e.target, where the calculation of zrX/Y via offsetX/Y
  16560. // is too complex. So css-transfrom dont support in this case temporarily.
  16561. if (calculate || !env.canvasSupported) {
  16562. defaultGetZrXY(el, e, out);
  16563. }
  16564. // Caution: In FireFox, layerX/layerY Mouse position relative to the closest positioned
  16565. // ancestor element, so we should make sure el is positioned (e.g., not position:static).
  16566. // BTW1, Webkit don't return the same results as FF in non-simple cases (like add
  16567. // zoom-factor, overflow / opacity layers, transforms ...)
  16568. // BTW2, (ev.offsetY || ev.pageY - $(ev.target).offset().top) is not correct in preserve-3d.
  16569. // <https://bugs.jquery.com/ticket/8523#comment:14>
  16570. // BTW3, In ff, offsetX/offsetY is always 0.
  16571. else if (env.browser.firefox && e.layerX != null && e.layerX !== e.offsetX) {
  16572. out.zrX = e.layerX;
  16573. out.zrY = e.layerY;
  16574. }
  16575. // For IE6+, chrome, safari, opera. (When will ff support offsetX?)
  16576. else if (e.offsetX != null) {
  16577. out.zrX = e.offsetX;
  16578. out.zrY = e.offsetY;
  16579. }
  16580. // For some other device, e.g., IOS safari.
  16581. else {
  16582. defaultGetZrXY(el, e, out);
  16583. }
  16584. return out;
  16585. }
  16586. function defaultGetZrXY(el, e, out) {
  16587. // This well-known method below does not support css transform.
  16588. var box = getBoundingClientRect(el);
  16589. out.zrX = e.clientX - box.left;
  16590. out.zrY = e.clientY - box.top;
  16591. }
  16592. /**
  16593. * 如果存在第三方嵌入的一些dom触发的事件,或touch事件,需要转换一下事件坐标.
  16594. * `calculate` is optional, default false.
  16595. */
  16596. function normalizeEvent(el, e, calculate) {
  16597. e = e || window.event;
  16598. if (e.zrX != null) {
  16599. return e;
  16600. }
  16601. var eventType = e.type;
  16602. var isTouch = eventType && eventType.indexOf('touch') >= 0;
  16603. if (!isTouch) {
  16604. clientToLocal(el, e, e, calculate);
  16605. e.zrDelta = (e.wheelDelta) ? e.wheelDelta / 120 : -(e.detail || 0) / 3;
  16606. }
  16607. else {
  16608. var touch = eventType != 'touchend'
  16609. ? e.targetTouches[0]
  16610. : e.changedTouches[0];
  16611. touch && clientToLocal(el, touch, e, calculate);
  16612. }
  16613. return e;
  16614. }
  16615. function addEventListener(el, name, handler) {
  16616. if (isDomLevel2) {
  16617. el.addEventListener(name, handler);
  16618. }
  16619. else {
  16620. el.attachEvent('on' + name, handler);
  16621. }
  16622. }
  16623. function removeEventListener(el, name, handler) {
  16624. if (isDomLevel2) {
  16625. el.removeEventListener(name, handler);
  16626. }
  16627. else {
  16628. el.detachEvent('on' + name, handler);
  16629. }
  16630. }
  16631. /**
  16632. * preventDefault and stopPropagation.
  16633. * Notice: do not do that in zrender. Upper application
  16634. * do that if necessary.
  16635. *
  16636. * @memberOf module:zrender/core/event
  16637. * @method
  16638. * @param {Event} e : event对象
  16639. */
  16640. var stop = isDomLevel2
  16641. ? function (e) {
  16642. e.preventDefault();
  16643. e.stopPropagation();
  16644. e.cancelBubble = true;
  16645. }
  16646. : function (e) {
  16647. e.returnValue = false;
  16648. e.cancelBubble = true;
  16649. };
  16650. module.exports = {
  16651. clientToLocal: clientToLocal,
  16652. normalizeEvent: normalizeEvent,
  16653. addEventListener: addEventListener,
  16654. removeEventListener: removeEventListener,
  16655. stop: stop,
  16656. // 做向上兼容
  16657. Dispatcher: Eventful
  16658. };
  16659. /***/ },
  16660. /* 89 */
  16661. /***/ function(module, exports) {
  16662. module.exports = (typeof window !== 'undefined' &&
  16663. (window.requestAnimationFrame
  16664. || window.msRequestAnimationFrame
  16665. || window.mozRequestAnimationFrame
  16666. || window.webkitRequestAnimationFrame))
  16667. || function (func) {
  16668. setTimeout(func, 16);
  16669. };
  16670. /***/ },
  16671. /* 90 */
  16672. /***/ function(module, exports, __webpack_require__) {
  16673. var eventTool = __webpack_require__(88);
  16674. var zrUtil = __webpack_require__(4);
  16675. var Eventful = __webpack_require__(33);
  16676. var env = __webpack_require__(2);
  16677. var GestureMgr = __webpack_require__(91);
  16678. var addEventListener = eventTool.addEventListener;
  16679. var removeEventListener = eventTool.removeEventListener;
  16680. var normalizeEvent = eventTool.normalizeEvent;
  16681. var TOUCH_CLICK_DELAY = 300;
  16682. var mouseHandlerNames = [
  16683. 'click', 'dblclick', 'mousewheel', 'mouseout',
  16684. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  16685. ];
  16686. var touchHandlerNames = [
  16687. 'touchstart', 'touchend', 'touchmove'
  16688. ];
  16689. var pointerEventNames = {
  16690. pointerdown: 1, pointerup: 1, pointermove: 1, pointerout: 1
  16691. };
  16692. var pointerHandlerNames = zrUtil.map(mouseHandlerNames, function (name) {
  16693. var nm = name.replace('mouse', 'pointer');
  16694. return pointerEventNames[nm] ? nm : name;
  16695. });
  16696. function eventNameFix(name) {
  16697. return (name === 'mousewheel' && env.browser.firefox) ? 'DOMMouseScroll' : name;
  16698. }
  16699. function processGesture(proxy, event, stage) {
  16700. var gestureMgr = proxy._gestureMgr;
  16701. stage === 'start' && gestureMgr.clear();
  16702. var gestureInfo = gestureMgr.recognize(
  16703. event,
  16704. proxy.handler.findHover(event.zrX, event.zrY, null),
  16705. proxy.dom
  16706. );
  16707. stage === 'end' && gestureMgr.clear();
  16708. // Do not do any preventDefault here. Upper application do that if necessary.
  16709. if (gestureInfo) {
  16710. var type = gestureInfo.type;
  16711. event.gestureEvent = type;
  16712. proxy.handler.dispatchToElement(gestureInfo.target, type, gestureInfo.event);
  16713. }
  16714. }
  16715. // function onMSGestureChange(proxy, event) {
  16716. // if (event.translationX || event.translationY) {
  16717. // // mousemove is carried by MSGesture to reduce the sensitivity.
  16718. // proxy.handler.dispatchToElement(event.target, 'mousemove', event);
  16719. // }
  16720. // if (event.scale !== 1) {
  16721. // event.pinchX = event.offsetX;
  16722. // event.pinchY = event.offsetY;
  16723. // event.pinchScale = event.scale;
  16724. // proxy.handler.dispatchToElement(event.target, 'pinch', event);
  16725. // }
  16726. // }
  16727. /**
  16728. * Prevent mouse event from being dispatched after Touch Events action
  16729. * @see <https://github.com/deltakosh/handjs/blob/master/src/hand.base.js>
  16730. * 1. Mobile browsers dispatch mouse events 300ms after touchend.
  16731. * 2. Chrome for Android dispatch mousedown for long-touch about 650ms
  16732. * Result: Blocking Mouse Events for 700ms.
  16733. */
  16734. function setTouchTimer(instance) {
  16735. instance._touching = true;
  16736. clearTimeout(instance._touchTimer);
  16737. instance._touchTimer = setTimeout(function () {
  16738. instance._touching = false;
  16739. }, 700);
  16740. }
  16741. var domHandlers = {
  16742. /**
  16743. * Mouse move handler
  16744. * @inner
  16745. * @param {Event} event
  16746. */
  16747. mousemove: function (event) {
  16748. event = normalizeEvent(this.dom, event);
  16749. this.trigger('mousemove', event);
  16750. },
  16751. /**
  16752. * Mouse out handler
  16753. * @inner
  16754. * @param {Event} event
  16755. */
  16756. mouseout: function (event) {
  16757. event = normalizeEvent(this.dom, event);
  16758. var element = event.toElement || event.relatedTarget;
  16759. if (element != this.dom) {
  16760. while (element && element.nodeType != 9) {
  16761. // 忽略包含在root中的dom引起的mouseOut
  16762. if (element === this.dom) {
  16763. return;
  16764. }
  16765. element = element.parentNode;
  16766. }
  16767. }
  16768. this.trigger('mouseout', event);
  16769. },
  16770. /**
  16771. * Touch开始响应函数
  16772. * @inner
  16773. * @param {Event} event
  16774. */
  16775. touchstart: function (event) {
  16776. // Default mouse behaviour should not be disabled here.
  16777. // For example, page may needs to be slided.
  16778. event = normalizeEvent(this.dom, event);
  16779. // Mark touch, which is useful in distinguish touch and
  16780. // mouse event in upper applicatoin.
  16781. event.zrByTouch = true;
  16782. this._lastTouchMoment = new Date();
  16783. processGesture(this, event, 'start');
  16784. // In touch device, trigger `mousemove`(`mouseover`) should
  16785. // be triggered, and must before `mousedown` triggered.
  16786. domHandlers.mousemove.call(this, event);
  16787. domHandlers.mousedown.call(this, event);
  16788. setTouchTimer(this);
  16789. },
  16790. /**
  16791. * Touch移动响应函数
  16792. * @inner
  16793. * @param {Event} event
  16794. */
  16795. touchmove: function (event) {
  16796. event = normalizeEvent(this.dom, event);
  16797. // Mark touch, which is useful in distinguish touch and
  16798. // mouse event in upper applicatoin.
  16799. event.zrByTouch = true;
  16800. processGesture(this, event, 'change');
  16801. // Mouse move should always be triggered no matter whether
  16802. // there is gestrue event, because mouse move and pinch may
  16803. // be used at the same time.
  16804. domHandlers.mousemove.call(this, event);
  16805. setTouchTimer(this);
  16806. },
  16807. /**
  16808. * Touch结束响应函数
  16809. * @inner
  16810. * @param {Event} event
  16811. */
  16812. touchend: function (event) {
  16813. event = normalizeEvent(this.dom, event);
  16814. // Mark touch, which is useful in distinguish touch and
  16815. // mouse event in upper applicatoin.
  16816. event.zrByTouch = true;
  16817. processGesture(this, event, 'end');
  16818. domHandlers.mouseup.call(this, event);
  16819. // Do not trigger `mouseout` here, in spite of `mousemove`(`mouseover`) is
  16820. // triggered in `touchstart`. This seems to be illogical, but by this mechanism,
  16821. // we can conveniently implement "hover style" in both PC and touch device just
  16822. // by listening to `mouseover` to add "hover style" and listening to `mouseout`
  16823. // to remove "hover style" on an element, without any additional code for
  16824. // compatibility. (`mouseout` will not be triggered in `touchend`, so "hover
  16825. // style" will remain for user view)
  16826. // click event should always be triggered no matter whether
  16827. // there is gestrue event. System click can not be prevented.
  16828. if (+new Date() - this._lastTouchMoment < TOUCH_CLICK_DELAY) {
  16829. domHandlers.click.call(this, event);
  16830. }
  16831. setTouchTimer(this);
  16832. },
  16833. pointerdown: function (event) {
  16834. domHandlers.mousedown.call(this, event);
  16835. // if (useMSGuesture(this, event)) {
  16836. // this._msGesture.addPointer(event.pointerId);
  16837. // }
  16838. },
  16839. pointermove: function (event) {
  16840. // FIXME
  16841. // pointermove is so sensitive that it always triggered when
  16842. // tap(click) on touch screen, which affect some judgement in
  16843. // upper application. So, we dont support mousemove on MS touch
  16844. // device yet.
  16845. if (!isPointerFromTouch(event)) {
  16846. domHandlers.mousemove.call(this, event);
  16847. }
  16848. },
  16849. pointerup: function (event) {
  16850. domHandlers.mouseup.call(this, event);
  16851. },
  16852. pointerout: function (event) {
  16853. // pointerout will be triggered when tap on touch screen
  16854. // (IE11+/Edge on MS Surface) after click event triggered,
  16855. // which is inconsistent with the mousout behavior we defined
  16856. // in touchend. So we unify them.
  16857. // (check domHandlers.touchend for detailed explanation)
  16858. if (!isPointerFromTouch(event)) {
  16859. domHandlers.mouseout.call(this, event);
  16860. }
  16861. }
  16862. };
  16863. function isPointerFromTouch(event) {
  16864. var pointerType = event.pointerType;
  16865. return pointerType === 'pen' || pointerType === 'touch';
  16866. }
  16867. // function useMSGuesture(handlerProxy, event) {
  16868. // return isPointerFromTouch(event) && !!handlerProxy._msGesture;
  16869. // }
  16870. // Common handlers
  16871. zrUtil.each(['click', 'mousedown', 'mouseup', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  16872. domHandlers[name] = function (event) {
  16873. event = normalizeEvent(this.dom, event);
  16874. this.trigger(name, event);
  16875. };
  16876. });
  16877. /**
  16878. * 为控制类实例初始化dom 事件处理函数
  16879. *
  16880. * @inner
  16881. * @param {module:zrender/Handler} instance 控制类实例
  16882. */
  16883. function initDomHandler(instance) {
  16884. zrUtil.each(touchHandlerNames, function (name) {
  16885. instance._handlers[name] = zrUtil.bind(domHandlers[name], instance);
  16886. });
  16887. zrUtil.each(pointerHandlerNames, function (name) {
  16888. instance._handlers[name] = zrUtil.bind(domHandlers[name], instance);
  16889. });
  16890. zrUtil.each(mouseHandlerNames, function (name) {
  16891. instance._handlers[name] = makeMouseHandler(domHandlers[name], instance);
  16892. });
  16893. function makeMouseHandler(fn, instance) {
  16894. return function () {
  16895. if (instance._touching) {
  16896. return;
  16897. }
  16898. return fn.apply(instance, arguments);
  16899. };
  16900. }
  16901. }
  16902. function HandlerDomProxy(dom) {
  16903. Eventful.call(this);
  16904. this.dom = dom;
  16905. /**
  16906. * @private
  16907. * @type {boolean}
  16908. */
  16909. this._touching = false;
  16910. /**
  16911. * @private
  16912. * @type {number}
  16913. */
  16914. this._touchTimer;
  16915. /**
  16916. * @private
  16917. * @type {module:zrender/core/GestureMgr}
  16918. */
  16919. this._gestureMgr = new GestureMgr();
  16920. this._handlers = {};
  16921. initDomHandler(this);
  16922. if (env.pointerEventsSupported) { // Only IE11+/Edge
  16923. // 1. On devices that both enable touch and mouse (e.g., MS Surface and lenovo X240),
  16924. // IE11+/Edge do not trigger touch event, but trigger pointer event and mouse event
  16925. // at the same time.
  16926. // 2. On MS Surface, it probablely only trigger mousedown but no mouseup when tap on
  16927. // screen, which do not occurs in pointer event.
  16928. // So we use pointer event to both detect touch gesture and mouse behavior.
  16929. mountHandlers(pointerHandlerNames, this);
  16930. // FIXME
  16931. // Note: MS Gesture require CSS touch-action set. But touch-action is not reliable,
  16932. // which does not prevent defuault behavior occasionally (which may cause view port
  16933. // zoomed in but use can not zoom it back). And event.preventDefault() does not work.
  16934. // So we have to not to use MSGesture and not to support touchmove and pinch on MS
  16935. // touch screen. And we only support click behavior on MS touch screen now.
  16936. // MS Gesture Event is only supported on IE11+/Edge and on Windows 8+.
  16937. // We dont support touch on IE on win7.
  16938. // See <https://msdn.microsoft.com/en-us/library/dn433243(v=vs.85).aspx>
  16939. // if (typeof MSGesture === 'function') {
  16940. // (this._msGesture = new MSGesture()).target = dom; // jshint ignore:line
  16941. // dom.addEventListener('MSGestureChange', onMSGestureChange);
  16942. // }
  16943. }
  16944. else {
  16945. if (env.touchEventsSupported) {
  16946. mountHandlers(touchHandlerNames, this);
  16947. // Handler of 'mouseout' event is needed in touch mode, which will be mounted below.
  16948. // addEventListener(root, 'mouseout', this._mouseoutHandler);
  16949. }
  16950. // 1. Considering some devices that both enable touch and mouse event (like on MS Surface
  16951. // and lenovo X240, @see #2350), we make mouse event be always listened, otherwise
  16952. // mouse event can not be handle in those devices.
  16953. // 2. On MS Surface, Chrome will trigger both touch event and mouse event. How to prevent
  16954. // mouseevent after touch event triggered, see `setTouchTimer`.
  16955. mountHandlers(mouseHandlerNames, this);
  16956. }
  16957. function mountHandlers(handlerNames, instance) {
  16958. zrUtil.each(handlerNames, function (name) {
  16959. addEventListener(dom, eventNameFix(name), instance._handlers[name]);
  16960. }, instance);
  16961. }
  16962. }
  16963. var handlerDomProxyProto = HandlerDomProxy.prototype;
  16964. handlerDomProxyProto.dispose = function () {
  16965. var handlerNames = mouseHandlerNames.concat(touchHandlerNames);
  16966. for (var i = 0; i < handlerNames.length; i++) {
  16967. var name = handlerNames[i];
  16968. removeEventListener(this.dom, eventNameFix(name), this._handlers[name]);
  16969. }
  16970. };
  16971. handlerDomProxyProto.setCursor = function (cursorStyle) {
  16972. this.dom.style.cursor = cursorStyle || 'default';
  16973. };
  16974. zrUtil.mixin(HandlerDomProxy, Eventful);
  16975. module.exports = HandlerDomProxy;
  16976. /***/ },
  16977. /* 91 */
  16978. /***/ function(module, exports, __webpack_require__) {
  16979. 'use strict';
  16980. /**
  16981. * Only implements needed gestures for mobile.
  16982. */
  16983. var eventUtil = __webpack_require__(88);
  16984. var GestureMgr = function () {
  16985. /**
  16986. * @private
  16987. * @type {Array.<Object>}
  16988. */
  16989. this._track = [];
  16990. };
  16991. GestureMgr.prototype = {
  16992. constructor: GestureMgr,
  16993. recognize: function (event, target, root) {
  16994. this._doTrack(event, target, root);
  16995. return this._recognize(event);
  16996. },
  16997. clear: function () {
  16998. this._track.length = 0;
  16999. return this;
  17000. },
  17001. _doTrack: function (event, target, root) {
  17002. var touches = event.touches;
  17003. if (!touches) {
  17004. return;
  17005. }
  17006. var trackItem = {
  17007. points: [],
  17008. touches: [],
  17009. target: target,
  17010. event: event
  17011. };
  17012. for (var i = 0, len = touches.length; i < len; i++) {
  17013. var touch = touches[i];
  17014. var pos = eventUtil.clientToLocal(root, touch, {});
  17015. trackItem.points.push([pos.zrX, pos.zrY]);
  17016. trackItem.touches.push(touch);
  17017. }
  17018. this._track.push(trackItem);
  17019. },
  17020. _recognize: function (event) {
  17021. for (var eventName in recognizers) {
  17022. if (recognizers.hasOwnProperty(eventName)) {
  17023. var gestureInfo = recognizers[eventName](this._track, event);
  17024. if (gestureInfo) {
  17025. return gestureInfo;
  17026. }
  17027. }
  17028. }
  17029. }
  17030. };
  17031. function dist(pointPair) {
  17032. var dx = pointPair[1][0] - pointPair[0][0];
  17033. var dy = pointPair[1][1] - pointPair[0][1];
  17034. return Math.sqrt(dx * dx + dy * dy);
  17035. }
  17036. function center(pointPair) {
  17037. return [
  17038. (pointPair[0][0] + pointPair[1][0]) / 2,
  17039. (pointPair[0][1] + pointPair[1][1]) / 2
  17040. ];
  17041. }
  17042. var recognizers = {
  17043. pinch: function (track, event) {
  17044. var trackLen = track.length;
  17045. if (!trackLen) {
  17046. return;
  17047. }
  17048. var pinchEnd = (track[trackLen - 1] || {}).points;
  17049. var pinchPre = (track[trackLen - 2] || {}).points || pinchEnd;
  17050. if (pinchPre
  17051. && pinchPre.length > 1
  17052. && pinchEnd
  17053. && pinchEnd.length > 1
  17054. ) {
  17055. var pinchScale = dist(pinchEnd) / dist(pinchPre);
  17056. !isFinite(pinchScale) && (pinchScale = 1);
  17057. event.pinchScale = pinchScale;
  17058. var pinchCenter = center(pinchEnd);
  17059. event.pinchX = pinchCenter[0];
  17060. event.pinchY = pinchCenter[1];
  17061. return {
  17062. type: 'pinch',
  17063. target: track[0].target,
  17064. event: event
  17065. };
  17066. }
  17067. }
  17068. // Only pinch currently.
  17069. };
  17070. module.exports = GestureMgr;
  17071. /***/ },
  17072. /* 92 */
  17073. /***/ function(module, exports, __webpack_require__) {
  17074. 'use strict';
  17075. /**
  17076. * Default canvas painter
  17077. * @module zrender/Painter
  17078. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  17079. * errorrik (errorrik@gmail.com)
  17080. * pissang (https://www.github.com/pissang)
  17081. */
  17082. var config = __webpack_require__(41);
  17083. var util = __webpack_require__(4);
  17084. var log = __webpack_require__(40);
  17085. var BoundingRect = __webpack_require__(9);
  17086. var timsort = __webpack_require__(86);
  17087. var Layer = __webpack_require__(93);
  17088. var requestAnimationFrame = __webpack_require__(89);
  17089. // PENDIGN
  17090. // Layer exceeds MAX_PROGRESSIVE_LAYER_NUMBER may have some problem when flush directly second time.
  17091. //
  17092. // Maximum progressive layer. When exceeding this number. All elements will be drawed in the last layer.
  17093. var MAX_PROGRESSIVE_LAYER_NUMBER = 5;
  17094. function parseInt10(val) {
  17095. return parseInt(val, 10);
  17096. }
  17097. function isLayerValid(layer) {
  17098. if (!layer) {
  17099. return false;
  17100. }
  17101. if (layer.isBuildin) {
  17102. return true;
  17103. }
  17104. if (typeof(layer.resize) !== 'function'
  17105. || typeof(layer.refresh) !== 'function'
  17106. ) {
  17107. return false;
  17108. }
  17109. return true;
  17110. }
  17111. function preProcessLayer(layer) {
  17112. layer.__unusedCount++;
  17113. }
  17114. function postProcessLayer(layer) {
  17115. if (layer.__unusedCount == 1) {
  17116. layer.clear();
  17117. }
  17118. }
  17119. var tmpRect = new BoundingRect(0, 0, 0, 0);
  17120. var viewRect = new BoundingRect(0, 0, 0, 0);
  17121. function isDisplayableCulled(el, width, height) {
  17122. tmpRect.copy(el.getBoundingRect());
  17123. if (el.transform) {
  17124. tmpRect.applyTransform(el.transform);
  17125. }
  17126. viewRect.width = width;
  17127. viewRect.height = height;
  17128. return !tmpRect.intersect(viewRect);
  17129. }
  17130. function isClipPathChanged(clipPaths, prevClipPaths) {
  17131. if (clipPaths == prevClipPaths) { // Can both be null or undefined
  17132. return false;
  17133. }
  17134. if (!clipPaths || !prevClipPaths || (clipPaths.length !== prevClipPaths.length)) {
  17135. return true;
  17136. }
  17137. for (var i = 0; i < clipPaths.length; i++) {
  17138. if (clipPaths[i] !== prevClipPaths[i]) {
  17139. return true;
  17140. }
  17141. }
  17142. }
  17143. function doClip(clipPaths, ctx) {
  17144. for (var i = 0; i < clipPaths.length; i++) {
  17145. var clipPath = clipPaths[i];
  17146. var path = clipPath.path;
  17147. clipPath.setTransform(ctx);
  17148. path.beginPath(ctx);
  17149. clipPath.buildPath(path, clipPath.shape);
  17150. ctx.clip();
  17151. // Transform back
  17152. clipPath.restoreTransform(ctx);
  17153. }
  17154. }
  17155. function createRoot(width, height) {
  17156. var domRoot = document.createElement('div');
  17157. // domRoot.onselectstart = returnFalse; // 避免页面选中的尴尬
  17158. domRoot.style.cssText = [
  17159. 'position:relative',
  17160. 'overflow:hidden',
  17161. 'width:' + width + 'px',
  17162. 'height:' + height + 'px',
  17163. 'padding:0',
  17164. 'margin:0',
  17165. 'border-width:0'
  17166. ].join(';') + ';';
  17167. return domRoot;
  17168. }
  17169. /**
  17170. * @alias module:zrender/Painter
  17171. * @constructor
  17172. * @param {HTMLElement} root 绘图容器
  17173. * @param {module:zrender/Storage} storage
  17174. * @param {Ojbect} opts
  17175. */
  17176. var Painter = function (root, storage, opts) {
  17177. // In node environment using node-canvas
  17178. var singleCanvas = !root.nodeName // In node ?
  17179. || root.nodeName.toUpperCase() === 'CANVAS';
  17180. this._opts = opts = util.extend({}, opts || {});
  17181. /**
  17182. * @type {number}
  17183. */
  17184. this.dpr = opts.devicePixelRatio || config.devicePixelRatio;
  17185. /**
  17186. * @type {boolean}
  17187. * @private
  17188. */
  17189. this._singleCanvas = singleCanvas;
  17190. /**
  17191. * 绘图容器
  17192. * @type {HTMLElement}
  17193. */
  17194. this.root = root;
  17195. var rootStyle = root.style;
  17196. if (rootStyle) {
  17197. rootStyle['-webkit-tap-highlight-color'] = 'transparent';
  17198. rootStyle['-webkit-user-select'] =
  17199. rootStyle['user-select'] =
  17200. rootStyle['-webkit-touch-callout'] = 'none';
  17201. root.innerHTML = '';
  17202. }
  17203. /**
  17204. * @type {module:zrender/Storage}
  17205. */
  17206. this.storage = storage;
  17207. /**
  17208. * @type {Array.<number>}
  17209. * @private
  17210. */
  17211. var zlevelList = this._zlevelList = [];
  17212. /**
  17213. * @type {Object.<string, module:zrender/Layer>}
  17214. * @private
  17215. */
  17216. var layers = this._layers = {};
  17217. /**
  17218. * @type {Object.<string, Object>}
  17219. * @type {private}
  17220. */
  17221. this._layerConfig = {};
  17222. if (!singleCanvas) {
  17223. this._width = this._getSize(0);
  17224. this._height = this._getSize(1);
  17225. var domRoot = this._domRoot = createRoot(
  17226. this._width, this._height
  17227. );
  17228. root.appendChild(domRoot);
  17229. }
  17230. else {
  17231. // Use canvas width and height directly
  17232. var width = root.width;
  17233. var height = root.height;
  17234. this._width = width;
  17235. this._height = height;
  17236. // Create layer if only one given canvas
  17237. // Device pixel ratio is fixed to 1 because given canvas has its specified width and height
  17238. var mainLayer = new Layer(root, this, 1);
  17239. mainLayer.initContext();
  17240. // FIXME Use canvas width and height
  17241. // mainLayer.resize(width, height);
  17242. layers[0] = mainLayer;
  17243. zlevelList.push(0);
  17244. this._domRoot = root;
  17245. }
  17246. this.pathToImage = this._createPathToImage();
  17247. // Layers for progressive rendering
  17248. this._progressiveLayers = [];
  17249. /**
  17250. * @type {module:zrender/Layer}
  17251. * @private
  17252. */
  17253. this._hoverlayer;
  17254. this._hoverElements = [];
  17255. };
  17256. Painter.prototype = {
  17257. constructor: Painter,
  17258. /**
  17259. * If painter use a single canvas
  17260. * @return {boolean}
  17261. */
  17262. isSingleCanvas: function () {
  17263. return this._singleCanvas;
  17264. },
  17265. /**
  17266. * @return {HTMLDivElement}
  17267. */
  17268. getViewportRoot: function () {
  17269. return this._domRoot;
  17270. },
  17271. /**
  17272. * 刷新
  17273. * @param {boolean} [paintAll=false] 强制绘制所有displayable
  17274. */
  17275. refresh: function (paintAll) {
  17276. var list = this.storage.getDisplayList(true);
  17277. var zlevelList = this._zlevelList;
  17278. this._paintList(list, paintAll);
  17279. // Paint custum layers
  17280. for (var i = 0; i < zlevelList.length; i++) {
  17281. var z = zlevelList[i];
  17282. var layer = this._layers[z];
  17283. if (!layer.isBuildin && layer.refresh) {
  17284. layer.refresh();
  17285. }
  17286. }
  17287. this.refreshHover();
  17288. if (this._progressiveLayers.length) {
  17289. this._startProgessive();
  17290. }
  17291. return this;
  17292. },
  17293. addHover: function (el, hoverStyle) {
  17294. if (el.__hoverMir) {
  17295. return;
  17296. }
  17297. var elMirror = new el.constructor({
  17298. style: el.style,
  17299. shape: el.shape
  17300. });
  17301. elMirror.__from = el;
  17302. el.__hoverMir = elMirror;
  17303. elMirror.setStyle(hoverStyle);
  17304. this._hoverElements.push(elMirror);
  17305. },
  17306. removeHover: function (el) {
  17307. var elMirror = el.__hoverMir;
  17308. var hoverElements = this._hoverElements;
  17309. var idx = util.indexOf(hoverElements, elMirror);
  17310. if (idx >= 0) {
  17311. hoverElements.splice(idx, 1);
  17312. }
  17313. el.__hoverMir = null;
  17314. },
  17315. clearHover: function (el) {
  17316. var hoverElements = this._hoverElements;
  17317. for (var i = 0; i < hoverElements.length; i++) {
  17318. var from = hoverElements[i].__from;
  17319. if (from) {
  17320. from.__hoverMir = null;
  17321. }
  17322. }
  17323. hoverElements.length = 0;
  17324. },
  17325. refreshHover: function () {
  17326. var hoverElements = this._hoverElements;
  17327. var len = hoverElements.length;
  17328. var hoverLayer = this._hoverlayer;
  17329. hoverLayer && hoverLayer.clear();
  17330. if (!len) {
  17331. return;
  17332. }
  17333. timsort(hoverElements, this.storage.displayableSortFunc);
  17334. // Use a extream large zlevel
  17335. // FIXME?
  17336. if (!hoverLayer) {
  17337. hoverLayer = this._hoverlayer = this.getLayer(1e5);
  17338. }
  17339. var scope = {};
  17340. hoverLayer.ctx.save();
  17341. for (var i = 0; i < len;) {
  17342. var el = hoverElements[i];
  17343. var originalEl = el.__from;
  17344. // Original el is removed
  17345. // PENDING
  17346. if (!(originalEl && originalEl.__zr)) {
  17347. hoverElements.splice(i, 1);
  17348. originalEl.__hoverMir = null;
  17349. len--;
  17350. continue;
  17351. }
  17352. i++;
  17353. // Use transform
  17354. // FIXME style and shape ?
  17355. if (!originalEl.invisible) {
  17356. el.transform = originalEl.transform;
  17357. el.invTransform = originalEl.invTransform;
  17358. el.__clipPaths = originalEl.__clipPaths;
  17359. // el.
  17360. this._doPaintEl(el, hoverLayer, true, scope);
  17361. }
  17362. }
  17363. hoverLayer.ctx.restore();
  17364. },
  17365. _startProgessive: function () {
  17366. var self = this;
  17367. if (!self._furtherProgressive) {
  17368. return;
  17369. }
  17370. // Use a token to stop progress steps triggered by
  17371. // previous zr.refresh calling.
  17372. var token = self._progressiveToken = +new Date();
  17373. self._progress++;
  17374. requestAnimationFrame(step);
  17375. function step() {
  17376. // In case refreshed or disposed
  17377. if (token === self._progressiveToken && self.storage) {
  17378. self._doPaintList(self.storage.getDisplayList());
  17379. if (self._furtherProgressive) {
  17380. self._progress++;
  17381. requestAnimationFrame(step);
  17382. }
  17383. else {
  17384. self._progressiveToken = -1;
  17385. }
  17386. }
  17387. }
  17388. },
  17389. _clearProgressive: function () {
  17390. this._progressiveToken = -1;
  17391. this._progress = 0;
  17392. util.each(this._progressiveLayers, function (layer) {
  17393. layer.__dirty && layer.clear();
  17394. });
  17395. },
  17396. _paintList: function (list, paintAll) {
  17397. if (paintAll == null) {
  17398. paintAll = false;
  17399. }
  17400. this._updateLayerStatus(list);
  17401. this._clearProgressive();
  17402. this.eachBuildinLayer(preProcessLayer);
  17403. this._doPaintList(list, paintAll);
  17404. this.eachBuildinLayer(postProcessLayer);
  17405. },
  17406. _doPaintList: function (list, paintAll) {
  17407. var currentLayer;
  17408. var currentZLevel;
  17409. var ctx;
  17410. // var invTransform = [];
  17411. var scope;
  17412. var progressiveLayerIdx = 0;
  17413. var currentProgressiveLayer;
  17414. var width = this._width;
  17415. var height = this._height;
  17416. var layerProgress;
  17417. var frame = this._progress;
  17418. function flushProgressiveLayer(layer) {
  17419. var dpr = ctx.dpr || 1;
  17420. ctx.save();
  17421. ctx.globalAlpha = 1;
  17422. ctx.shadowBlur = 0;
  17423. // Avoid layer don't clear in next progressive frame
  17424. currentLayer.__dirty = true;
  17425. ctx.setTransform(1, 0, 0, 1, 0, 0);
  17426. ctx.drawImage(layer.dom, 0, 0, width * dpr, height * dpr);
  17427. ctx.restore();
  17428. }
  17429. for (var i = 0, l = list.length; i < l; i++) {
  17430. var el = list[i];
  17431. var elZLevel = this._singleCanvas ? 0 : el.zlevel;
  17432. var elFrame = el.__frame;
  17433. // Flush at current context
  17434. // PENDING
  17435. if (elFrame < 0 && currentProgressiveLayer) {
  17436. flushProgressiveLayer(currentProgressiveLayer);
  17437. currentProgressiveLayer = null;
  17438. }
  17439. // Change draw layer
  17440. if (currentZLevel !== elZLevel) {
  17441. if (ctx) {
  17442. ctx.restore();
  17443. }
  17444. // Reset scope
  17445. scope = {};
  17446. // Only 0 zlevel if only has one canvas
  17447. currentZLevel = elZLevel;
  17448. currentLayer = this.getLayer(currentZLevel);
  17449. if (!currentLayer.isBuildin) {
  17450. log(
  17451. 'ZLevel ' + currentZLevel
  17452. + ' has been used by unkown layer ' + currentLayer.id
  17453. );
  17454. }
  17455. ctx = currentLayer.ctx;
  17456. ctx.save();
  17457. // Reset the count
  17458. currentLayer.__unusedCount = 0;
  17459. if (currentLayer.__dirty || paintAll) {
  17460. currentLayer.clear();
  17461. }
  17462. }
  17463. if (!(currentLayer.__dirty || paintAll)) {
  17464. continue;
  17465. }
  17466. if (elFrame >= 0) {
  17467. // Progressive layer changed
  17468. if (!currentProgressiveLayer) {
  17469. currentProgressiveLayer = this._progressiveLayers[
  17470. Math.min(progressiveLayerIdx++, MAX_PROGRESSIVE_LAYER_NUMBER - 1)
  17471. ];
  17472. currentProgressiveLayer.ctx.save();
  17473. currentProgressiveLayer.renderScope = {};
  17474. if (currentProgressiveLayer
  17475. && (currentProgressiveLayer.__progress > currentProgressiveLayer.__maxProgress)
  17476. ) {
  17477. // flushProgressiveLayer(currentProgressiveLayer);
  17478. // Quick jump all progressive elements
  17479. // All progressive element are not dirty, jump over and flush directly
  17480. i = currentProgressiveLayer.__nextIdxNotProg - 1;
  17481. // currentProgressiveLayer = null;
  17482. continue;
  17483. }
  17484. layerProgress = currentProgressiveLayer.__progress;
  17485. if (!currentProgressiveLayer.__dirty) {
  17486. // Keep rendering
  17487. frame = layerProgress;
  17488. }
  17489. currentProgressiveLayer.__progress = frame + 1;
  17490. }
  17491. if (elFrame === frame) {
  17492. this._doPaintEl(el, currentProgressiveLayer, true, currentProgressiveLayer.renderScope);
  17493. }
  17494. }
  17495. else {
  17496. this._doPaintEl(el, currentLayer, paintAll, scope);
  17497. }
  17498. el.__dirty = false;
  17499. }
  17500. if (currentProgressiveLayer) {
  17501. flushProgressiveLayer(currentProgressiveLayer);
  17502. }
  17503. // Restore the lastLayer ctx
  17504. ctx && ctx.restore();
  17505. // If still has clipping state
  17506. // if (scope.prevElClipPaths) {
  17507. // ctx.restore();
  17508. // }
  17509. this._furtherProgressive = false;
  17510. util.each(this._progressiveLayers, function (layer) {
  17511. if (layer.__maxProgress >= layer.__progress) {
  17512. this._furtherProgressive = true;
  17513. }
  17514. }, this);
  17515. },
  17516. _doPaintEl: function (el, currentLayer, forcePaint, scope) {
  17517. var ctx = currentLayer.ctx;
  17518. var m = el.transform;
  17519. if (
  17520. (currentLayer.__dirty || forcePaint)
  17521. // Ignore invisible element
  17522. && !el.invisible
  17523. // Ignore transparent element
  17524. && el.style.opacity !== 0
  17525. // Ignore scale 0 element, in some environment like node-canvas
  17526. // Draw a scale 0 element can cause all following draw wrong
  17527. // And setTransform with scale 0 will cause set back transform failed.
  17528. && !(m && !m[0] && !m[3])
  17529. // Ignore culled element
  17530. && !(el.culling && isDisplayableCulled(el, this._width, this._height))
  17531. ) {
  17532. var clipPaths = el.__clipPaths;
  17533. // Optimize when clipping on group with several elements
  17534. if (scope.prevClipLayer !== currentLayer
  17535. || isClipPathChanged(clipPaths, scope.prevElClipPaths)
  17536. ) {
  17537. // If has previous clipping state, restore from it
  17538. if (scope.prevElClipPaths) {
  17539. scope.prevClipLayer.ctx.restore();
  17540. scope.prevClipLayer = scope.prevElClipPaths = null;
  17541. // Reset prevEl since context has been restored
  17542. scope.prevEl = null;
  17543. }
  17544. // New clipping state
  17545. if (clipPaths) {
  17546. ctx.save();
  17547. doClip(clipPaths, ctx);
  17548. scope.prevClipLayer = currentLayer;
  17549. scope.prevElClipPaths = clipPaths;
  17550. }
  17551. }
  17552. el.beforeBrush && el.beforeBrush(ctx);
  17553. el.brush(ctx, scope.prevEl || null);
  17554. scope.prevEl = el;
  17555. el.afterBrush && el.afterBrush(ctx);
  17556. }
  17557. },
  17558. /**
  17559. * 获取 zlevel 所在层,如果不存在则会创建一个新的层
  17560. * @param {number} zlevel
  17561. * @return {module:zrender/Layer}
  17562. */
  17563. getLayer: function (zlevel) {
  17564. if (this._singleCanvas) {
  17565. return this._layers[0];
  17566. }
  17567. var layer = this._layers[zlevel];
  17568. if (!layer) {
  17569. // Create a new layer
  17570. layer = new Layer('zr_' + zlevel, this, this.dpr);
  17571. layer.isBuildin = true;
  17572. if (this._layerConfig[zlevel]) {
  17573. util.merge(layer, this._layerConfig[zlevel], true);
  17574. }
  17575. this.insertLayer(zlevel, layer);
  17576. // Context is created after dom inserted to document
  17577. // Or excanvas will get 0px clientWidth and clientHeight
  17578. layer.initContext();
  17579. }
  17580. return layer;
  17581. },
  17582. insertLayer: function (zlevel, layer) {
  17583. var layersMap = this._layers;
  17584. var zlevelList = this._zlevelList;
  17585. var len = zlevelList.length;
  17586. var prevLayer = null;
  17587. var i = -1;
  17588. var domRoot = this._domRoot;
  17589. if (layersMap[zlevel]) {
  17590. log('ZLevel ' + zlevel + ' has been used already');
  17591. return;
  17592. }
  17593. // Check if is a valid layer
  17594. if (!isLayerValid(layer)) {
  17595. log('Layer of zlevel ' + zlevel + ' is not valid');
  17596. return;
  17597. }
  17598. if (len > 0 && zlevel > zlevelList[0]) {
  17599. for (i = 0; i < len - 1; i++) {
  17600. if (
  17601. zlevelList[i] < zlevel
  17602. && zlevelList[i + 1] > zlevel
  17603. ) {
  17604. break;
  17605. }
  17606. }
  17607. prevLayer = layersMap[zlevelList[i]];
  17608. }
  17609. zlevelList.splice(i + 1, 0, zlevel);
  17610. if (prevLayer) {
  17611. var prevDom = prevLayer.dom;
  17612. if (prevDom.nextSibling) {
  17613. domRoot.insertBefore(
  17614. layer.dom,
  17615. prevDom.nextSibling
  17616. );
  17617. }
  17618. else {
  17619. domRoot.appendChild(layer.dom);
  17620. }
  17621. }
  17622. else {
  17623. if (domRoot.firstChild) {
  17624. domRoot.insertBefore(layer.dom, domRoot.firstChild);
  17625. }
  17626. else {
  17627. domRoot.appendChild(layer.dom);
  17628. }
  17629. }
  17630. layersMap[zlevel] = layer;
  17631. },
  17632. // Iterate each layer
  17633. eachLayer: function (cb, context) {
  17634. var zlevelList = this._zlevelList;
  17635. var z;
  17636. var i;
  17637. for (i = 0; i < zlevelList.length; i++) {
  17638. z = zlevelList[i];
  17639. cb.call(context, this._layers[z], z);
  17640. }
  17641. },
  17642. // Iterate each buildin layer
  17643. eachBuildinLayer: function (cb, context) {
  17644. var zlevelList = this._zlevelList;
  17645. var layer;
  17646. var z;
  17647. var i;
  17648. for (i = 0; i < zlevelList.length; i++) {
  17649. z = zlevelList[i];
  17650. layer = this._layers[z];
  17651. if (layer.isBuildin) {
  17652. cb.call(context, layer, z);
  17653. }
  17654. }
  17655. },
  17656. // Iterate each other layer except buildin layer
  17657. eachOtherLayer: function (cb, context) {
  17658. var zlevelList = this._zlevelList;
  17659. var layer;
  17660. var z;
  17661. var i;
  17662. for (i = 0; i < zlevelList.length; i++) {
  17663. z = zlevelList[i];
  17664. layer = this._layers[z];
  17665. if (! layer.isBuildin) {
  17666. cb.call(context, layer, z);
  17667. }
  17668. }
  17669. },
  17670. /**
  17671. * 获取所有已创建的层
  17672. * @param {Array.<module:zrender/Layer>} [prevLayer]
  17673. */
  17674. getLayers: function () {
  17675. return this._layers;
  17676. },
  17677. _updateLayerStatus: function (list) {
  17678. var layers = this._layers;
  17679. var progressiveLayers = this._progressiveLayers;
  17680. var elCountsLastFrame = {};
  17681. var progressiveElCountsLastFrame = {};
  17682. this.eachBuildinLayer(function (layer, z) {
  17683. elCountsLastFrame[z] = layer.elCount;
  17684. layer.elCount = 0;
  17685. layer.__dirty = false;
  17686. });
  17687. util.each(progressiveLayers, function (layer, idx) {
  17688. progressiveElCountsLastFrame[idx] = layer.elCount;
  17689. layer.elCount = 0;
  17690. layer.__dirty = false;
  17691. });
  17692. var progressiveLayerCount = 0;
  17693. var currentProgressiveLayer;
  17694. var lastProgressiveKey;
  17695. var frameCount = 0;
  17696. for (var i = 0, l = list.length; i < l; i++) {
  17697. var el = list[i];
  17698. var zlevel = this._singleCanvas ? 0 : el.zlevel;
  17699. var layer = layers[zlevel];
  17700. var elProgress = el.progressive;
  17701. if (layer) {
  17702. layer.elCount++;
  17703. layer.__dirty = layer.__dirty || el.__dirty;
  17704. }
  17705. /////// Update progressive
  17706. if (elProgress >= 0) {
  17707. // Fix wrong progressive sequence problem.
  17708. if (lastProgressiveKey !== elProgress) {
  17709. lastProgressiveKey = elProgress;
  17710. frameCount++;
  17711. }
  17712. var elFrame = el.__frame = frameCount - 1;
  17713. if (!currentProgressiveLayer) {
  17714. var idx = Math.min(progressiveLayerCount, MAX_PROGRESSIVE_LAYER_NUMBER - 1);
  17715. currentProgressiveLayer = progressiveLayers[idx];
  17716. if (!currentProgressiveLayer) {
  17717. currentProgressiveLayer = progressiveLayers[idx] = new Layer(
  17718. 'progressive', this, this.dpr
  17719. );
  17720. currentProgressiveLayer.initContext();
  17721. }
  17722. currentProgressiveLayer.__maxProgress = 0;
  17723. }
  17724. currentProgressiveLayer.__dirty = currentProgressiveLayer.__dirty || el.__dirty;
  17725. currentProgressiveLayer.elCount++;
  17726. currentProgressiveLayer.__maxProgress = Math.max(
  17727. currentProgressiveLayer.__maxProgress, elFrame
  17728. );
  17729. if (currentProgressiveLayer.__maxProgress >= currentProgressiveLayer.__progress) {
  17730. // Should keep rendering this layer because progressive rendering is not finished yet
  17731. layer.__dirty = true;
  17732. }
  17733. }
  17734. else {
  17735. el.__frame = -1;
  17736. if (currentProgressiveLayer) {
  17737. currentProgressiveLayer.__nextIdxNotProg = i;
  17738. progressiveLayerCount++;
  17739. currentProgressiveLayer = null;
  17740. }
  17741. }
  17742. }
  17743. if (currentProgressiveLayer) {
  17744. progressiveLayerCount++;
  17745. currentProgressiveLayer.__nextIdxNotProg = i;
  17746. }
  17747. // 层中的元素数量有发生变化
  17748. this.eachBuildinLayer(function (layer, z) {
  17749. if (elCountsLastFrame[z] !== layer.elCount) {
  17750. layer.__dirty = true;
  17751. }
  17752. });
  17753. progressiveLayers.length = Math.min(progressiveLayerCount, MAX_PROGRESSIVE_LAYER_NUMBER);
  17754. util.each(progressiveLayers, function (layer, idx) {
  17755. if (progressiveElCountsLastFrame[idx] !== layer.elCount) {
  17756. el.__dirty = true;
  17757. }
  17758. if (layer.__dirty) {
  17759. layer.__progress = 0;
  17760. }
  17761. });
  17762. },
  17763. /**
  17764. * 清除hover层外所有内容
  17765. */
  17766. clear: function () {
  17767. this.eachBuildinLayer(this._clearLayer);
  17768. return this;
  17769. },
  17770. _clearLayer: function (layer) {
  17771. layer.clear();
  17772. },
  17773. /**
  17774. * 修改指定zlevel的绘制参数
  17775. *
  17776. * @param {string} zlevel
  17777. * @param {Object} config 配置对象
  17778. * @param {string} [config.clearColor=0] 每次清空画布的颜色
  17779. * @param {string} [config.motionBlur=false] 是否开启动态模糊
  17780. * @param {number} [config.lastFrameAlpha=0.7]
  17781. * 在开启动态模糊的时候使用,与上一帧混合的alpha值,值越大尾迹越明显
  17782. */
  17783. configLayer: function (zlevel, config) {
  17784. if (config) {
  17785. var layerConfig = this._layerConfig;
  17786. if (!layerConfig[zlevel]) {
  17787. layerConfig[zlevel] = config;
  17788. }
  17789. else {
  17790. util.merge(layerConfig[zlevel], config, true);
  17791. }
  17792. var layer = this._layers[zlevel];
  17793. if (layer) {
  17794. util.merge(layer, layerConfig[zlevel], true);
  17795. }
  17796. }
  17797. },
  17798. /**
  17799. * 删除指定层
  17800. * @param {number} zlevel 层所在的zlevel
  17801. */
  17802. delLayer: function (zlevel) {
  17803. var layers = this._layers;
  17804. var zlevelList = this._zlevelList;
  17805. var layer = layers[zlevel];
  17806. if (!layer) {
  17807. return;
  17808. }
  17809. layer.dom.parentNode.removeChild(layer.dom);
  17810. delete layers[zlevel];
  17811. zlevelList.splice(util.indexOf(zlevelList, zlevel), 1);
  17812. },
  17813. /**
  17814. * 区域大小变化后重绘
  17815. */
  17816. resize: function (width, height) {
  17817. var domRoot = this._domRoot;
  17818. // FIXME Why ?
  17819. domRoot.style.display = 'none';
  17820. // Save input w/h
  17821. var opts = this._opts;
  17822. width != null && (opts.width = width);
  17823. height != null && (opts.height = height);
  17824. width = this._getSize(0);
  17825. height = this._getSize(1);
  17826. domRoot.style.display = '';
  17827. // 优化没有实际改变的resize
  17828. if (this._width != width || height != this._height) {
  17829. domRoot.style.width = width + 'px';
  17830. domRoot.style.height = height + 'px';
  17831. for (var id in this._layers) {
  17832. if (this._layers.hasOwnProperty(id)) {
  17833. this._layers[id].resize(width, height);
  17834. }
  17835. }
  17836. util.each(this._progressiveLayers, function (layer) {
  17837. layer.resize(width, height);
  17838. });
  17839. this.refresh(true);
  17840. }
  17841. this._width = width;
  17842. this._height = height;
  17843. return this;
  17844. },
  17845. /**
  17846. * 清除单独的一个层
  17847. * @param {number} zlevel
  17848. */
  17849. clearLayer: function (zlevel) {
  17850. var layer = this._layers[zlevel];
  17851. if (layer) {
  17852. layer.clear();
  17853. }
  17854. },
  17855. /**
  17856. * 释放
  17857. */
  17858. dispose: function () {
  17859. this.root.innerHTML = '';
  17860. this.root =
  17861. this.storage =
  17862. this._domRoot =
  17863. this._layers = null;
  17864. },
  17865. /**
  17866. * Get canvas which has all thing rendered
  17867. * @param {Object} opts
  17868. * @param {string} [opts.backgroundColor]
  17869. */
  17870. getRenderedCanvas: function (opts) {
  17871. opts = opts || {};
  17872. if (this._singleCanvas) {
  17873. return this._layers[0].dom;
  17874. }
  17875. var imageLayer = new Layer('image', this, opts.pixelRatio || this.dpr);
  17876. imageLayer.initContext();
  17877. imageLayer.clearColor = opts.backgroundColor;
  17878. imageLayer.clear();
  17879. var displayList = this.storage.getDisplayList(true);
  17880. var scope = {};
  17881. for (var i = 0; i < displayList.length; i++) {
  17882. var el = displayList[i];
  17883. this._doPaintEl(el, imageLayer, true, scope);
  17884. }
  17885. return imageLayer.dom;
  17886. },
  17887. /**
  17888. * 获取绘图区域宽度
  17889. */
  17890. getWidth: function () {
  17891. return this._width;
  17892. },
  17893. /**
  17894. * 获取绘图区域高度
  17895. */
  17896. getHeight: function () {
  17897. return this._height;
  17898. },
  17899. _getSize: function (whIdx) {
  17900. var opts = this._opts;
  17901. var wh = ['width', 'height'][whIdx];
  17902. var cwh = ['clientWidth', 'clientHeight'][whIdx];
  17903. var plt = ['paddingLeft', 'paddingTop'][whIdx];
  17904. var prb = ['paddingRight', 'paddingBottom'][whIdx];
  17905. if (opts[wh] != null && opts[wh] !== 'auto') {
  17906. return parseFloat(opts[wh]);
  17907. }
  17908. var root = this.root;
  17909. var stl = document.defaultView.getComputedStyle(root);
  17910. return (
  17911. (root[cwh] || parseInt10(stl[wh]) || parseInt10(root.style[wh]))
  17912. - (parseInt10(stl[plt]) || 0)
  17913. - (parseInt10(stl[prb]) || 0)
  17914. ) | 0;
  17915. },
  17916. _pathToImage: function (id, path, width, height, dpr) {
  17917. var canvas = document.createElement('canvas');
  17918. var ctx = canvas.getContext('2d');
  17919. canvas.width = width * dpr;
  17920. canvas.height = height * dpr;
  17921. ctx.clearRect(0, 0, width * dpr, height * dpr);
  17922. var pathTransform = {
  17923. position: path.position,
  17924. rotation: path.rotation,
  17925. scale: path.scale
  17926. };
  17927. path.position = [0, 0, 0];
  17928. path.rotation = 0;
  17929. path.scale = [1, 1];
  17930. if (path) {
  17931. path.brush(ctx);
  17932. }
  17933. var ImageShape = __webpack_require__(61);
  17934. var imgShape = new ImageShape({
  17935. id: id,
  17936. style: {
  17937. x: 0,
  17938. y: 0,
  17939. image: canvas
  17940. }
  17941. });
  17942. if (pathTransform.position != null) {
  17943. imgShape.position = path.position = pathTransform.position;
  17944. }
  17945. if (pathTransform.rotation != null) {
  17946. imgShape.rotation = path.rotation = pathTransform.rotation;
  17947. }
  17948. if (pathTransform.scale != null) {
  17949. imgShape.scale = path.scale = pathTransform.scale;
  17950. }
  17951. return imgShape;
  17952. },
  17953. _createPathToImage: function () {
  17954. var me = this;
  17955. return function (id, e, width, height) {
  17956. return me._pathToImage(
  17957. id, e, width, height, me.dpr
  17958. );
  17959. };
  17960. }
  17961. };
  17962. module.exports = Painter;
  17963. /***/ },
  17964. /* 93 */
  17965. /***/ function(module, exports, __webpack_require__) {
  17966. /**
  17967. * @module zrender/Layer
  17968. * @author pissang(https://www.github.com/pissang)
  17969. */
  17970. var util = __webpack_require__(4);
  17971. var config = __webpack_require__(41);
  17972. var Style = __webpack_require__(47);
  17973. var Pattern = __webpack_require__(59);
  17974. function returnFalse() {
  17975. return false;
  17976. }
  17977. /**
  17978. * 创建dom
  17979. *
  17980. * @inner
  17981. * @param {string} id dom id 待用
  17982. * @param {string} type dom type,such as canvas, div etc.
  17983. * @param {Painter} painter painter instance
  17984. * @param {number} number
  17985. */
  17986. function createDom(id, type, painter, dpr) {
  17987. var newDom = document.createElement(type);
  17988. var width = painter.getWidth();
  17989. var height = painter.getHeight();
  17990. var newDomStyle = newDom.style;
  17991. // 没append呢,请原谅我这样写,清晰~
  17992. newDomStyle.position = 'absolute';
  17993. newDomStyle.left = 0;
  17994. newDomStyle.top = 0;
  17995. newDomStyle.width = width + 'px';
  17996. newDomStyle.height = height + 'px';
  17997. newDom.width = width * dpr;
  17998. newDom.height = height * dpr;
  17999. // id不作为索引用,避免可能造成的重名,定义为私有属性
  18000. newDom.setAttribute('data-zr-dom-id', id);
  18001. return newDom;
  18002. }
  18003. /**
  18004. * @alias module:zrender/Layer
  18005. * @constructor
  18006. * @extends module:zrender/mixin/Transformable
  18007. * @param {string} id
  18008. * @param {module:zrender/Painter} painter
  18009. * @param {number} [dpr]
  18010. */
  18011. var Layer = function(id, painter, dpr) {
  18012. var dom;
  18013. dpr = dpr || config.devicePixelRatio;
  18014. if (typeof id === 'string') {
  18015. dom = createDom(id, 'canvas', painter, dpr);
  18016. }
  18017. // Not using isDom because in node it will return false
  18018. else if (util.isObject(id)) {
  18019. dom = id;
  18020. id = dom.id;
  18021. }
  18022. this.id = id;
  18023. this.dom = dom;
  18024. var domStyle = dom.style;
  18025. if (domStyle) { // Not in node
  18026. dom.onselectstart = returnFalse; // 避免页面选中的尴尬
  18027. domStyle['-webkit-user-select'] = 'none';
  18028. domStyle['user-select'] = 'none';
  18029. domStyle['-webkit-touch-callout'] = 'none';
  18030. domStyle['-webkit-tap-highlight-color'] = 'rgba(0,0,0,0)';
  18031. domStyle['padding'] = 0;
  18032. domStyle['margin'] = 0;
  18033. domStyle['border-width'] = 0;
  18034. }
  18035. this.domBack = null;
  18036. this.ctxBack = null;
  18037. this.painter = painter;
  18038. this.config = null;
  18039. // Configs
  18040. /**
  18041. * 每次清空画布的颜色
  18042. * @type {string}
  18043. * @default 0
  18044. */
  18045. this.clearColor = 0;
  18046. /**
  18047. * 是否开启动态模糊
  18048. * @type {boolean}
  18049. * @default false
  18050. */
  18051. this.motionBlur = false;
  18052. /**
  18053. * 在开启动态模糊的时候使用,与上一帧混合的alpha值,值越大尾迹越明显
  18054. * @type {number}
  18055. * @default 0.7
  18056. */
  18057. this.lastFrameAlpha = 0.7;
  18058. /**
  18059. * Layer dpr
  18060. * @type {number}
  18061. */
  18062. this.dpr = dpr;
  18063. };
  18064. Layer.prototype = {
  18065. constructor: Layer,
  18066. elCount: 0,
  18067. __dirty: true,
  18068. initContext: function () {
  18069. this.ctx = this.dom.getContext('2d');
  18070. this.ctx.dpr = this.dpr;
  18071. },
  18072. createBackBuffer: function () {
  18073. var dpr = this.dpr;
  18074. this.domBack = createDom('back-' + this.id, 'canvas', this.painter, dpr);
  18075. this.ctxBack = this.domBack.getContext('2d');
  18076. if (dpr != 1) {
  18077. this.ctxBack.scale(dpr, dpr);
  18078. }
  18079. },
  18080. /**
  18081. * @param {number} width
  18082. * @param {number} height
  18083. */
  18084. resize: function (width, height) {
  18085. var dpr = this.dpr;
  18086. var dom = this.dom;
  18087. var domStyle = dom.style;
  18088. var domBack = this.domBack;
  18089. domStyle.width = width + 'px';
  18090. domStyle.height = height + 'px';
  18091. dom.width = width * dpr;
  18092. dom.height = height * dpr;
  18093. if (domBack) {
  18094. domBack.width = width * dpr;
  18095. domBack.height = height * dpr;
  18096. if (dpr != 1) {
  18097. this.ctxBack.scale(dpr, dpr);
  18098. }
  18099. }
  18100. },
  18101. /**
  18102. * 清空该层画布
  18103. * @param {boolean} clearAll Clear all with out motion blur
  18104. */
  18105. clear: function (clearAll) {
  18106. var dom = this.dom;
  18107. var ctx = this.ctx;
  18108. var width = dom.width;
  18109. var height = dom.height;
  18110. var clearColor = this.clearColor;
  18111. var haveMotionBLur = this.motionBlur && !clearAll;
  18112. var lastFrameAlpha = this.lastFrameAlpha;
  18113. var dpr = this.dpr;
  18114. if (haveMotionBLur) {
  18115. if (!this.domBack) {
  18116. this.createBackBuffer();
  18117. }
  18118. this.ctxBack.globalCompositeOperation = 'copy';
  18119. this.ctxBack.drawImage(
  18120. dom, 0, 0,
  18121. width / dpr,
  18122. height / dpr
  18123. );
  18124. }
  18125. ctx.clearRect(0, 0, width, height);
  18126. if (clearColor) {
  18127. var clearColorGradientOrPattern;
  18128. // Gradient
  18129. if (clearColor.colorStops) {
  18130. // Cache canvas gradient
  18131. clearColorGradientOrPattern = clearColor.__canvasGradient || Style.getGradient(ctx, clearColor, {
  18132. x: 0,
  18133. y: 0,
  18134. width: width,
  18135. height: height
  18136. });
  18137. clearColor.__canvasGradient = clearColorGradientOrPattern;
  18138. }
  18139. // Pattern
  18140. else if (clearColor.image) {
  18141. clearColorGradientOrPattern = Pattern.prototype.getCanvasPattern.call(clearColor, ctx);
  18142. }
  18143. ctx.save();
  18144. ctx.fillStyle = clearColorGradientOrPattern || clearColor;
  18145. ctx.fillRect(0, 0, width, height);
  18146. ctx.restore();
  18147. }
  18148. if (haveMotionBLur) {
  18149. var domBack = this.domBack;
  18150. ctx.save();
  18151. ctx.globalAlpha = lastFrameAlpha;
  18152. ctx.drawImage(domBack, 0, 0, width, height);
  18153. ctx.restore();
  18154. }
  18155. }
  18156. };
  18157. module.exports = Layer;
  18158. /***/ },
  18159. /* 94 */
  18160. /***/ function(module, exports, __webpack_require__) {
  18161. var Gradient = __webpack_require__(79);
  18162. module.exports = function (ecModel) {
  18163. function encodeColor(seriesModel) {
  18164. var colorAccessPath = (seriesModel.visualColorAccessPath || 'itemStyle.normal.color').split('.');
  18165. var data = seriesModel.getData();
  18166. var color = seriesModel.get(colorAccessPath) // Set in itemStyle
  18167. || seriesModel.getColorFromPalette(seriesModel.get('name')); // Default color
  18168. // FIXME Set color function or use the platte color
  18169. data.setVisual('color', color);
  18170. // Only visible series has each data be visual encoded
  18171. if (!ecModel.isSeriesFiltered(seriesModel)) {
  18172. if (typeof color === 'function' && !(color instanceof Gradient)) {
  18173. data.each(function (idx) {
  18174. data.setItemVisual(
  18175. idx, 'color', color(seriesModel.getDataParams(idx))
  18176. );
  18177. });
  18178. }
  18179. // itemStyle in each data item
  18180. data.each(function (idx) {
  18181. var itemModel = data.getItemModel(idx);
  18182. var color = itemModel.get(colorAccessPath, true);
  18183. if (color != null) {
  18184. data.setItemVisual(idx, 'color', color);
  18185. }
  18186. });
  18187. }
  18188. }
  18189. ecModel.eachRawSeries(encodeColor);
  18190. };
  18191. /***/ },
  18192. /* 95 */
  18193. /***/ function(module, exports, __webpack_require__) {
  18194. // Compatitable with 2.0
  18195. var zrUtil = __webpack_require__(4);
  18196. var compatStyle = __webpack_require__(96);
  18197. function get(opt, path) {
  18198. path = path.split(',');
  18199. var obj = opt;
  18200. for (var i = 0; i < path.length; i++) {
  18201. obj = obj && obj[path[i]];
  18202. if (obj == null) {
  18203. break;
  18204. }
  18205. }
  18206. return obj;
  18207. }
  18208. function set(opt, path, val, overwrite) {
  18209. path = path.split(',');
  18210. var obj = opt;
  18211. var key;
  18212. for (var i = 0; i < path.length - 1; i++) {
  18213. key = path[i];
  18214. if (obj[key] == null) {
  18215. obj[key] = {};
  18216. }
  18217. obj = obj[key];
  18218. }
  18219. if (overwrite || obj[path[i]] == null) {
  18220. obj[path[i]] = val;
  18221. }
  18222. }
  18223. function compatLayoutProperties(option) {
  18224. each(LAYOUT_PROPERTIES, function (prop) {
  18225. if (prop[0] in option && !(prop[1] in option)) {
  18226. option[prop[1]] = option[prop[0]];
  18227. }
  18228. });
  18229. }
  18230. var LAYOUT_PROPERTIES = [
  18231. ['x', 'left'], ['y', 'top'], ['x2', 'right'], ['y2', 'bottom']
  18232. ];
  18233. var COMPATITABLE_COMPONENTS = [
  18234. 'grid', 'geo', 'parallel', 'legend', 'toolbox', 'title', 'visualMap', 'dataZoom', 'timeline'
  18235. ];
  18236. var COMPATITABLE_SERIES = [
  18237. 'bar', 'boxplot', 'candlestick', 'chord', 'effectScatter',
  18238. 'funnel', 'gauge', 'lines', 'graph', 'heatmap', 'line', 'map', 'parallel',
  18239. 'pie', 'radar', 'sankey', 'scatter', 'treemap'
  18240. ];
  18241. var each = zrUtil.each;
  18242. module.exports = function (option) {
  18243. each(option.series, function (seriesOpt) {
  18244. if (!zrUtil.isObject(seriesOpt)) {
  18245. return;
  18246. }
  18247. var seriesType = seriesOpt.type;
  18248. compatStyle(seriesOpt);
  18249. if (seriesType === 'pie' || seriesType === 'gauge') {
  18250. if (seriesOpt.clockWise != null) {
  18251. seriesOpt.clockwise = seriesOpt.clockWise;
  18252. }
  18253. }
  18254. if (seriesType === 'gauge') {
  18255. var pointerColor = get(seriesOpt, 'pointer.color');
  18256. pointerColor != null
  18257. && set(seriesOpt, 'itemStyle.normal.color', pointerColor);
  18258. }
  18259. for (var i = 0; i < COMPATITABLE_SERIES.length; i++) {
  18260. if (COMPATITABLE_SERIES[i] === seriesOpt.type) {
  18261. compatLayoutProperties(seriesOpt);
  18262. break;
  18263. }
  18264. }
  18265. });
  18266. // dataRange has changed to visualMap
  18267. if (option.dataRange) {
  18268. option.visualMap = option.dataRange;
  18269. }
  18270. each(COMPATITABLE_COMPONENTS, function (componentName) {
  18271. var options = option[componentName];
  18272. if (options) {
  18273. if (!zrUtil.isArray(options)) {
  18274. options = [options];
  18275. }
  18276. each(options, function (option) {
  18277. compatLayoutProperties(option);
  18278. });
  18279. }
  18280. });
  18281. };
  18282. /***/ },
  18283. /* 96 */
  18284. /***/ function(module, exports, __webpack_require__) {
  18285. var zrUtil = __webpack_require__(4);
  18286. var POSSIBLE_STYLES = [
  18287. 'areaStyle', 'lineStyle', 'nodeStyle', 'linkStyle',
  18288. 'chordStyle', 'label', 'labelLine'
  18289. ];
  18290. function compatItemStyle(opt) {
  18291. var itemStyleOpt = opt && opt.itemStyle;
  18292. if (itemStyleOpt) {
  18293. zrUtil.each(POSSIBLE_STYLES, function (styleName) {
  18294. var normalItemStyleOpt = itemStyleOpt.normal;
  18295. var emphasisItemStyleOpt = itemStyleOpt.emphasis;
  18296. if (normalItemStyleOpt && normalItemStyleOpt[styleName]) {
  18297. opt[styleName] = opt[styleName] || {};
  18298. if (!opt[styleName].normal) {
  18299. opt[styleName].normal = normalItemStyleOpt[styleName];
  18300. }
  18301. else {
  18302. zrUtil.merge(opt[styleName].normal, normalItemStyleOpt[styleName]);
  18303. }
  18304. normalItemStyleOpt[styleName] = null;
  18305. }
  18306. if (emphasisItemStyleOpt && emphasisItemStyleOpt[styleName]) {
  18307. opt[styleName] = opt[styleName] || {};
  18308. if (!opt[styleName].emphasis) {
  18309. opt[styleName].emphasis = emphasisItemStyleOpt[styleName];
  18310. }
  18311. else {
  18312. zrUtil.merge(opt[styleName].emphasis, emphasisItemStyleOpt[styleName]);
  18313. }
  18314. emphasisItemStyleOpt[styleName] = null;
  18315. }
  18316. });
  18317. }
  18318. }
  18319. module.exports = function (seriesOpt) {
  18320. if (!seriesOpt) {
  18321. return;
  18322. }
  18323. compatItemStyle(seriesOpt);
  18324. compatItemStyle(seriesOpt.markPoint);
  18325. compatItemStyle(seriesOpt.markLine);
  18326. var data = seriesOpt.data;
  18327. if (data) {
  18328. for (var i = 0; i < data.length; i++) {
  18329. compatItemStyle(data[i]);
  18330. }
  18331. // mark point data
  18332. var markPoint = seriesOpt.markPoint;
  18333. if (markPoint && markPoint.data) {
  18334. var mpData = markPoint.data;
  18335. for (var i = 0; i < mpData.length; i++) {
  18336. compatItemStyle(mpData[i]);
  18337. }
  18338. }
  18339. // mark line data
  18340. var markLine = seriesOpt.markLine;
  18341. if (markLine && markLine.data) {
  18342. var mlData = markLine.data;
  18343. for (var i = 0; i < mlData.length; i++) {
  18344. if (zrUtil.isArray(mlData[i])) {
  18345. compatItemStyle(mlData[i][0]);
  18346. compatItemStyle(mlData[i][1]);
  18347. }
  18348. else {
  18349. compatItemStyle(mlData[i]);
  18350. }
  18351. }
  18352. }
  18353. }
  18354. };
  18355. /***/ },
  18356. /* 97 */
  18357. /***/ function(module, exports, __webpack_require__) {
  18358. var graphic = __webpack_require__(43);
  18359. var zrUtil = __webpack_require__(4);
  18360. var PI = Math.PI;
  18361. /**
  18362. * @param {module:echarts/ExtensionAPI} api
  18363. * @param {Object} [opts]
  18364. * @param {string} [opts.text]
  18365. * @param {string} [opts.color]
  18366. * @param {string} [opts.textColor]
  18367. * @return {module:zrender/Element}
  18368. */
  18369. module.exports = function (api, opts) {
  18370. opts = opts || {};
  18371. zrUtil.defaults(opts, {
  18372. text: 'loading',
  18373. color: '#c23531',
  18374. textColor: '#000',
  18375. maskColor: 'rgba(255, 255, 255, 0.8)',
  18376. zlevel: 0
  18377. });
  18378. var mask = new graphic.Rect({
  18379. style: {
  18380. fill: opts.maskColor
  18381. },
  18382. zlevel: opts.zlevel,
  18383. z: 10000
  18384. });
  18385. var arc = new graphic.Arc({
  18386. shape: {
  18387. startAngle: -PI / 2,
  18388. endAngle: -PI / 2 + 0.1,
  18389. r: 10
  18390. },
  18391. style: {
  18392. stroke: opts.color,
  18393. lineCap: 'round',
  18394. lineWidth: 5
  18395. },
  18396. zlevel: opts.zlevel,
  18397. z: 10001
  18398. });
  18399. var labelRect = new graphic.Rect({
  18400. style: {
  18401. fill: 'none',
  18402. text: opts.text,
  18403. textPosition: 'right',
  18404. textDistance: 10,
  18405. textFill: opts.textColor
  18406. },
  18407. zlevel: opts.zlevel,
  18408. z: 10001
  18409. });
  18410. arc.animateShape(true)
  18411. .when(1000, {
  18412. endAngle: PI * 3 / 2
  18413. })
  18414. .start('circularInOut');
  18415. arc.animateShape(true)
  18416. .when(1000, {
  18417. startAngle: PI * 3 / 2
  18418. })
  18419. .delay(300)
  18420. .start('circularInOut');
  18421. var group = new graphic.Group();
  18422. group.add(arc);
  18423. group.add(labelRect);
  18424. group.add(mask);
  18425. // Inject resize
  18426. group.resize = function () {
  18427. var cx = api.getWidth() / 2;
  18428. var cy = api.getHeight() / 2;
  18429. arc.setShape({
  18430. cx: cx,
  18431. cy: cy
  18432. });
  18433. var r = arc.shape.r;
  18434. labelRect.setShape({
  18435. x: cx - r,
  18436. y: cy - r,
  18437. width: r * 2,
  18438. height: r * 2
  18439. });
  18440. mask.setShape({
  18441. x: 0,
  18442. y: 0,
  18443. width: api.getWidth(),
  18444. height: api.getHeight()
  18445. });
  18446. };
  18447. group.resize();
  18448. return group;
  18449. };
  18450. /***/ },
  18451. /* 98 */
  18452. /***/ function(module, exports, __webpack_require__) {
  18453. /* WEBPACK VAR INJECTION */(function(global) {/**
  18454. * List for data storage
  18455. * @module echarts/data/List
  18456. */
  18457. var UNDEFINED = 'undefined';
  18458. var globalObj = typeof window === 'undefined' ? global : window;
  18459. var Float64Array = typeof globalObj.Float64Array === UNDEFINED
  18460. ? Array : globalObj.Float64Array;
  18461. var Int32Array = typeof globalObj.Int32Array === UNDEFINED
  18462. ? Array : globalObj.Int32Array;
  18463. var dataCtors = {
  18464. 'float': Float64Array,
  18465. 'int': Int32Array,
  18466. // Ordinal data type can be string or int
  18467. 'ordinal': Array,
  18468. 'number': Array,
  18469. 'time': Array
  18470. };
  18471. var Model = __webpack_require__(12);
  18472. var DataDiffer = __webpack_require__(99);
  18473. var zrUtil = __webpack_require__(4);
  18474. var modelUtil = __webpack_require__(5);
  18475. var isObject = zrUtil.isObject;
  18476. var TRANSFERABLE_PROPERTIES = [
  18477. 'stackedOn', 'hasItemOption', '_nameList', '_idList', '_rawData'
  18478. ];
  18479. var transferProperties = function (a, b) {
  18480. zrUtil.each(TRANSFERABLE_PROPERTIES.concat(b.__wrappedMethods || []), function (propName) {
  18481. if (b.hasOwnProperty(propName)) {
  18482. a[propName] = b[propName];
  18483. }
  18484. });
  18485. a.__wrappedMethods = b.__wrappedMethods;
  18486. };
  18487. /**
  18488. * @constructor
  18489. * @alias module:echarts/data/List
  18490. *
  18491. * @param {Array.<string>} dimensions
  18492. * Dimensions should be concrete names like x, y, z, lng, lat, angle, radius
  18493. * @param {module:echarts/model/Model} hostModel
  18494. */
  18495. var List = function (dimensions, hostModel) {
  18496. dimensions = dimensions || ['x', 'y'];
  18497. var dimensionInfos = {};
  18498. var dimensionNames = [];
  18499. for (var i = 0; i < dimensions.length; i++) {
  18500. var dimensionName;
  18501. var dimensionInfo = {};
  18502. if (typeof dimensions[i] === 'string') {
  18503. dimensionName = dimensions[i];
  18504. dimensionInfo = {
  18505. name: dimensionName,
  18506. stackable: false,
  18507. // Type can be 'float', 'int', 'number'
  18508. // Default is number, Precision of float may not enough
  18509. type: 'number'
  18510. };
  18511. }
  18512. else {
  18513. dimensionInfo = dimensions[i];
  18514. dimensionName = dimensionInfo.name;
  18515. dimensionInfo.type = dimensionInfo.type || 'number';
  18516. }
  18517. dimensionNames.push(dimensionName);
  18518. dimensionInfos[dimensionName] = dimensionInfo;
  18519. }
  18520. /**
  18521. * @readOnly
  18522. * @type {Array.<string>}
  18523. */
  18524. this.dimensions = dimensionNames;
  18525. /**
  18526. * Infomation of each data dimension, like data type.
  18527. * @type {Object}
  18528. */
  18529. this._dimensionInfos = dimensionInfos;
  18530. /**
  18531. * @type {module:echarts/model/Model}
  18532. */
  18533. this.hostModel = hostModel;
  18534. /**
  18535. * @type {module:echarts/model/Model}
  18536. */
  18537. this.dataType;
  18538. /**
  18539. * Indices stores the indices of data subset after filtered.
  18540. * This data subset will be used in chart.
  18541. * @type {Array.<number>}
  18542. * @readOnly
  18543. */
  18544. this.indices = [];
  18545. /**
  18546. * Data storage
  18547. * @type {Object.<key, TypedArray|Array>}
  18548. * @private
  18549. */
  18550. this._storage = {};
  18551. /**
  18552. * @type {Array.<string>}
  18553. */
  18554. this._nameList = [];
  18555. /**
  18556. * @type {Array.<string>}
  18557. */
  18558. this._idList = [];
  18559. /**
  18560. * Models of data option is stored sparse for optimizing memory cost
  18561. * @type {Array.<module:echarts/model/Model>}
  18562. * @private
  18563. */
  18564. this._optionModels = [];
  18565. /**
  18566. * @param {module:echarts/data/List}
  18567. */
  18568. this.stackedOn = null;
  18569. /**
  18570. * Global visual properties after visual coding
  18571. * @type {Object}
  18572. * @private
  18573. */
  18574. this._visual = {};
  18575. /**
  18576. * Globel layout properties.
  18577. * @type {Object}
  18578. * @private
  18579. */
  18580. this._layout = {};
  18581. /**
  18582. * Item visual properties after visual coding
  18583. * @type {Array.<Object>}
  18584. * @private
  18585. */
  18586. this._itemVisuals = [];
  18587. /**
  18588. * Item layout properties after layout
  18589. * @type {Array.<Object>}
  18590. * @private
  18591. */
  18592. this._itemLayouts = [];
  18593. /**
  18594. * Graphic elemnents
  18595. * @type {Array.<module:zrender/Element>}
  18596. * @private
  18597. */
  18598. this._graphicEls = [];
  18599. /**
  18600. * @type {Array.<Array|Object>}
  18601. * @private
  18602. */
  18603. this._rawData;
  18604. /**
  18605. * @type {Object}
  18606. * @private
  18607. */
  18608. this._extent;
  18609. };
  18610. var listProto = List.prototype;
  18611. listProto.type = 'list';
  18612. /**
  18613. * If each data item has it's own option
  18614. * @type {boolean}
  18615. */
  18616. listProto.hasItemOption = true;
  18617. /**
  18618. * Get dimension name
  18619. * @param {string|number} dim
  18620. * Dimension can be concrete names like x, y, z, lng, lat, angle, radius
  18621. * Or a ordinal number. For example getDimensionInfo(0) will return 'x' or 'lng' or 'radius'
  18622. * @return {string} Concrete dim name.
  18623. */
  18624. listProto.getDimension = function (dim) {
  18625. if (!isNaN(dim)) {
  18626. dim = this.dimensions[dim] || dim;
  18627. }
  18628. return dim;
  18629. };
  18630. /**
  18631. * Get type and stackable info of particular dimension
  18632. * @param {string|number} dim
  18633. * Dimension can be concrete names like x, y, z, lng, lat, angle, radius
  18634. * Or a ordinal number. For example getDimensionInfo(0) will return 'x' or 'lng' or 'radius'
  18635. */
  18636. listProto.getDimensionInfo = function (dim) {
  18637. return zrUtil.clone(this._dimensionInfos[this.getDimension(dim)]);
  18638. };
  18639. /**
  18640. * Initialize from data
  18641. * @param {Array.<Object|number|Array>} data
  18642. * @param {Array.<string>} [nameList]
  18643. * @param {Function} [dimValueGetter] (dataItem, dimName, dataIndex, dimIndex) => number
  18644. */
  18645. listProto.initData = function (data, nameList, dimValueGetter) {
  18646. data = data || [];
  18647. if (true) {
  18648. if (!zrUtil.isArray(data)) {
  18649. throw new Error('Invalid data.');
  18650. }
  18651. }
  18652. this._rawData = data;
  18653. // Clear
  18654. var storage = this._storage = {};
  18655. var indices = this.indices = [];
  18656. var dimensions = this.dimensions;
  18657. var size = data.length;
  18658. var dimensionInfoMap = this._dimensionInfos;
  18659. var idList = [];
  18660. var nameRepeatCount = {};
  18661. nameList = nameList || [];
  18662. // Init storage
  18663. for (var i = 0; i < dimensions.length; i++) {
  18664. var dimInfo = dimensionInfoMap[dimensions[i]];
  18665. var DataCtor = dataCtors[dimInfo.type];
  18666. storage[dimensions[i]] = new DataCtor(size);
  18667. }
  18668. var self = this;
  18669. if (!dimValueGetter) {
  18670. self.hasItemOption = false;
  18671. }
  18672. // Default dim value getter
  18673. dimValueGetter = dimValueGetter || function (dataItem, dimName, dataIndex, dimIndex) {
  18674. var value = modelUtil.getDataItemValue(dataItem);
  18675. // If any dataItem is like { value: 10 }
  18676. if (modelUtil.isDataItemOption(dataItem)) {
  18677. self.hasItemOption = true;
  18678. }
  18679. return modelUtil.converDataValue(
  18680. (value instanceof Array)
  18681. ? value[dimIndex]
  18682. // If value is a single number or something else not array.
  18683. : value,
  18684. dimensionInfoMap[dimName]
  18685. );
  18686. };
  18687. for (var idx = 0; idx < data.length; idx++) {
  18688. var dataItem = data[idx];
  18689. // Each data item is value
  18690. // [1, 2]
  18691. // 2
  18692. // Bar chart, line chart which uses category axis
  18693. // only gives the 'y' value. 'x' value is the indices of cateogry
  18694. // Use a tempValue to normalize the value to be a (x, y) value
  18695. // Store the data by dimensions
  18696. for (var k = 0; k < dimensions.length; k++) {
  18697. var dim = dimensions[k];
  18698. var dimStorage = storage[dim];
  18699. // PENDING NULL is empty or zero
  18700. dimStorage[idx] = dimValueGetter(dataItem, dim, idx, k);
  18701. }
  18702. indices.push(idx);
  18703. }
  18704. // Use the name in option and create id
  18705. for (var i = 0; i < data.length; i++) {
  18706. if (!nameList[i]) {
  18707. if (data[i] && data[i].name != null) {
  18708. nameList[i] = data[i].name;
  18709. }
  18710. }
  18711. var name = nameList[i] || '';
  18712. // Try using the id in option
  18713. var id = data[i] && data[i].id;
  18714. if (!id && name) {
  18715. // Use name as id and add counter to avoid same name
  18716. nameRepeatCount[name] = nameRepeatCount[name] || 0;
  18717. id = name;
  18718. if (nameRepeatCount[name] > 0) {
  18719. id += '__ec__' + nameRepeatCount[name];
  18720. }
  18721. nameRepeatCount[name]++;
  18722. }
  18723. id && (idList[i] = id);
  18724. }
  18725. this._nameList = nameList;
  18726. this._idList = idList;
  18727. };
  18728. /**
  18729. * @return {number}
  18730. */
  18731. listProto.count = function () {
  18732. return this.indices.length;
  18733. };
  18734. /**
  18735. * Get value. Return NaN if idx is out of range.
  18736. * @param {string} dim Dim must be concrete name.
  18737. * @param {number} idx
  18738. * @param {boolean} stack
  18739. * @return {number}
  18740. */
  18741. listProto.get = function (dim, idx, stack) {
  18742. var storage = this._storage;
  18743. var dataIndex = this.indices[idx];
  18744. // If value not exists
  18745. if (dataIndex == null) {
  18746. return NaN;
  18747. }
  18748. var value = storage[dim] && storage[dim][dataIndex];
  18749. // FIXME ordinal data type is not stackable
  18750. if (stack) {
  18751. var dimensionInfo = this._dimensionInfos[dim];
  18752. if (dimensionInfo && dimensionInfo.stackable) {
  18753. var stackedOn = this.stackedOn;
  18754. while (stackedOn) {
  18755. // Get no stacked data of stacked on
  18756. var stackedValue = stackedOn.get(dim, idx);
  18757. // Considering positive stack, negative stack and empty data
  18758. if ((value >= 0 && stackedValue > 0) // Positive stack
  18759. || (value <= 0 && stackedValue < 0) // Negative stack
  18760. ) {
  18761. value += stackedValue;
  18762. }
  18763. stackedOn = stackedOn.stackedOn;
  18764. }
  18765. }
  18766. }
  18767. return value;
  18768. };
  18769. /**
  18770. * Get value for multi dimensions.
  18771. * @param {Array.<string>} [dimensions] If ignored, using all dimensions.
  18772. * @param {number} idx
  18773. * @param {boolean} stack
  18774. * @return {number}
  18775. */
  18776. listProto.getValues = function (dimensions, idx, stack) {
  18777. var values = [];
  18778. if (!zrUtil.isArray(dimensions)) {
  18779. stack = idx;
  18780. idx = dimensions;
  18781. dimensions = this.dimensions;
  18782. }
  18783. for (var i = 0, len = dimensions.length; i < len; i++) {
  18784. values.push(this.get(dimensions[i], idx, stack));
  18785. }
  18786. return values;
  18787. };
  18788. /**
  18789. * If value is NaN. Inlcuding '-'
  18790. * @param {string} dim
  18791. * @param {number} idx
  18792. * @return {number}
  18793. */
  18794. listProto.hasValue = function (idx) {
  18795. var dimensions = this.dimensions;
  18796. var dimensionInfos = this._dimensionInfos;
  18797. for (var i = 0, len = dimensions.length; i < len; i++) {
  18798. if (
  18799. // Ordinal type can be string or number
  18800. dimensionInfos[dimensions[i]].type !== 'ordinal'
  18801. && isNaN(this.get(dimensions[i], idx))
  18802. ) {
  18803. return false;
  18804. }
  18805. }
  18806. return true;
  18807. };
  18808. /**
  18809. * Get extent of data in one dimension
  18810. * @param {string} dim
  18811. * @param {boolean} stack
  18812. * @param {Function} filter
  18813. */
  18814. listProto.getDataExtent = function (dim, stack, filter) {
  18815. dim = this.getDimension(dim);
  18816. var dimData = this._storage[dim];
  18817. var dimInfo = this.getDimensionInfo(dim);
  18818. stack = (dimInfo && dimInfo.stackable) && stack;
  18819. var dimExtent = (this._extent || (this._extent = {}))[dim + (!!stack)];
  18820. var value;
  18821. if (dimExtent) {
  18822. return dimExtent;
  18823. }
  18824. // var dimInfo = this._dimensionInfos[dim];
  18825. if (dimData) {
  18826. var min = Infinity;
  18827. var max = -Infinity;
  18828. // var isOrdinal = dimInfo.type === 'ordinal';
  18829. for (var i = 0, len = this.count(); i < len; i++) {
  18830. value = this.get(dim, i, stack);
  18831. // FIXME
  18832. // if (isOrdinal && typeof value === 'string') {
  18833. // value = zrUtil.indexOf(dimData, value);
  18834. // }
  18835. if (!filter || filter(value, dim, i)) {
  18836. value < min && (min = value);
  18837. value > max && (max = value);
  18838. }
  18839. }
  18840. return (this._extent[dim + !!stack] = [min, max]);
  18841. }
  18842. else {
  18843. return [Infinity, -Infinity];
  18844. }
  18845. };
  18846. /**
  18847. * Get sum of data in one dimension
  18848. * @param {string} dim
  18849. * @param {boolean} stack
  18850. */
  18851. listProto.getSum = function (dim, stack) {
  18852. var dimData = this._storage[dim];
  18853. var sum = 0;
  18854. if (dimData) {
  18855. for (var i = 0, len = this.count(); i < len; i++) {
  18856. var value = this.get(dim, i, stack);
  18857. if (!isNaN(value)) {
  18858. sum += value;
  18859. }
  18860. }
  18861. }
  18862. return sum;
  18863. };
  18864. /**
  18865. * Retreive the index with given value
  18866. * @param {number} idx
  18867. * @param {number} value
  18868. * @return {number}
  18869. */
  18870. // FIXME Precision of float value
  18871. listProto.indexOf = function (dim, value) {
  18872. var storage = this._storage;
  18873. var dimData = storage[dim];
  18874. var indices = this.indices;
  18875. if (dimData) {
  18876. for (var i = 0, len = indices.length; i < len; i++) {
  18877. var rawIndex = indices[i];
  18878. if (dimData[rawIndex] === value) {
  18879. return i;
  18880. }
  18881. }
  18882. }
  18883. return -1;
  18884. };
  18885. /**
  18886. * Retreive the index with given name
  18887. * @param {number} idx
  18888. * @param {number} name
  18889. * @return {number}
  18890. */
  18891. listProto.indexOfName = function (name) {
  18892. var indices = this.indices;
  18893. var nameList = this._nameList;
  18894. for (var i = 0, len = indices.length; i < len; i++) {
  18895. var rawIndex = indices[i];
  18896. if (nameList[rawIndex] === name) {
  18897. return i;
  18898. }
  18899. }
  18900. return -1;
  18901. };
  18902. /**
  18903. * Retreive the index with given raw data index
  18904. * @param {number} idx
  18905. * @param {number} name
  18906. * @return {number}
  18907. */
  18908. listProto.indexOfRawIndex = function (rawIndex) {
  18909. // Indices are ascending
  18910. var indices = this.indices;
  18911. // If rawIndex === dataIndex
  18912. var rawDataIndex = indices[rawIndex];
  18913. if (rawDataIndex != null && rawDataIndex === rawIndex) {
  18914. return rawIndex;
  18915. }
  18916. var left = 0;
  18917. var right = indices.length - 1;
  18918. while (left <= right) {
  18919. var mid = (left + right) / 2 | 0;
  18920. if (indices[mid] < rawIndex) {
  18921. left = mid + 1;
  18922. }
  18923. else if (indices[mid] > rawIndex) {
  18924. right = mid - 1;
  18925. }
  18926. else {
  18927. return mid;
  18928. }
  18929. }
  18930. return -1;
  18931. };
  18932. /**
  18933. * Retreive the index of nearest value
  18934. * @param {string} dim
  18935. * @param {number} value
  18936. * @param {boolean} stack If given value is after stacked
  18937. * @param {number} [maxDistance=Infinity]
  18938. * @return {number}
  18939. */
  18940. listProto.indexOfNearest = function (dim, value, stack, maxDistance) {
  18941. var storage = this._storage;
  18942. var dimData = storage[dim];
  18943. if (maxDistance == null) {
  18944. maxDistance = Infinity;
  18945. }
  18946. var nearestIdx = -1;
  18947. if (dimData) {
  18948. var minDist = Number.MAX_VALUE;
  18949. for (var i = 0, len = this.count(); i < len; i++) {
  18950. var diff = value - this.get(dim, i, stack);
  18951. var dist = Math.abs(diff);
  18952. if (
  18953. diff <= maxDistance
  18954. && (dist < minDist
  18955. // For the case of two data are same on xAxis, which has sequence data.
  18956. // Show the nearest index
  18957. // https://github.com/ecomfe/echarts/issues/2869
  18958. || (dist === minDist && diff > 0)
  18959. )
  18960. ) {
  18961. minDist = dist;
  18962. nearestIdx = i;
  18963. }
  18964. }
  18965. }
  18966. return nearestIdx;
  18967. };
  18968. /**
  18969. * Get raw data index
  18970. * @param {number} idx
  18971. * @return {number}
  18972. */
  18973. listProto.getRawIndex = function (idx) {
  18974. var rawIdx = this.indices[idx];
  18975. return rawIdx == null ? -1 : rawIdx;
  18976. };
  18977. /**
  18978. * Get raw data item
  18979. * @param {number} idx
  18980. * @return {number}
  18981. */
  18982. listProto.getRawDataItem = function (idx) {
  18983. return this._rawData[this.getRawIndex(idx)];
  18984. };
  18985. /**
  18986. * @param {number} idx
  18987. * @param {boolean} [notDefaultIdx=false]
  18988. * @return {string}
  18989. */
  18990. listProto.getName = function (idx) {
  18991. return this._nameList[this.indices[idx]] || '';
  18992. };
  18993. /**
  18994. * @param {number} idx
  18995. * @param {boolean} [notDefaultIdx=false]
  18996. * @return {string}
  18997. */
  18998. listProto.getId = function (idx) {
  18999. return this._idList[this.indices[idx]] || (this.getRawIndex(idx) + '');
  19000. };
  19001. function normalizeDimensions(dimensions) {
  19002. if (!zrUtil.isArray(dimensions)) {
  19003. dimensions = [dimensions];
  19004. }
  19005. return dimensions;
  19006. }
  19007. /**
  19008. * Data iteration
  19009. * @param {string|Array.<string>}
  19010. * @param {Function} cb
  19011. * @param {boolean} [stack=false]
  19012. * @param {*} [context=this]
  19013. *
  19014. * @example
  19015. * list.each('x', function (x, idx) {});
  19016. * list.each(['x', 'y'], function (x, y, idx) {});
  19017. * list.each(function (idx) {})
  19018. */
  19019. listProto.each = function (dims, cb, stack, context) {
  19020. if (typeof dims === 'function') {
  19021. context = stack;
  19022. stack = cb;
  19023. cb = dims;
  19024. dims = [];
  19025. }
  19026. dims = zrUtil.map(normalizeDimensions(dims), this.getDimension, this);
  19027. var value = [];
  19028. var dimSize = dims.length;
  19029. var indices = this.indices;
  19030. context = context || this;
  19031. for (var i = 0; i < indices.length; i++) {
  19032. // Simple optimization
  19033. switch (dimSize) {
  19034. case 0:
  19035. cb.call(context, i);
  19036. break;
  19037. case 1:
  19038. cb.call(context, this.get(dims[0], i, stack), i);
  19039. break;
  19040. case 2:
  19041. cb.call(context, this.get(dims[0], i, stack), this.get(dims[1], i, stack), i);
  19042. break;
  19043. default:
  19044. for (var k = 0; k < dimSize; k++) {
  19045. value[k] = this.get(dims[k], i, stack);
  19046. }
  19047. // Index
  19048. value[k] = i;
  19049. cb.apply(context, value);
  19050. }
  19051. }
  19052. };
  19053. /**
  19054. * Data filter
  19055. * @param {string|Array.<string>}
  19056. * @param {Function} cb
  19057. * @param {boolean} [stack=false]
  19058. * @param {*} [context=this]
  19059. */
  19060. listProto.filterSelf = function (dimensions, cb, stack, context) {
  19061. if (typeof dimensions === 'function') {
  19062. context = stack;
  19063. stack = cb;
  19064. cb = dimensions;
  19065. dimensions = [];
  19066. }
  19067. dimensions = zrUtil.map(
  19068. normalizeDimensions(dimensions), this.getDimension, this
  19069. );
  19070. var newIndices = [];
  19071. var value = [];
  19072. var dimSize = dimensions.length;
  19073. var indices = this.indices;
  19074. context = context || this;
  19075. for (var i = 0; i < indices.length; i++) {
  19076. var keep;
  19077. // Simple optimization
  19078. if (dimSize === 1) {
  19079. keep = cb.call(
  19080. context, this.get(dimensions[0], i, stack), i
  19081. );
  19082. }
  19083. else {
  19084. for (var k = 0; k < dimSize; k++) {
  19085. value[k] = this.get(dimensions[k], i, stack);
  19086. }
  19087. value[k] = i;
  19088. keep = cb.apply(context, value);
  19089. }
  19090. if (keep) {
  19091. newIndices.push(indices[i]);
  19092. }
  19093. }
  19094. this.indices = newIndices;
  19095. // Reset data extent
  19096. this._extent = {};
  19097. return this;
  19098. };
  19099. /**
  19100. * Data mapping to a plain array
  19101. * @param {string|Array.<string>} [dimensions]
  19102. * @param {Function} cb
  19103. * @param {boolean} [stack=false]
  19104. * @param {*} [context=this]
  19105. * @return {Array}
  19106. */
  19107. listProto.mapArray = function (dimensions, cb, stack, context) {
  19108. if (typeof dimensions === 'function') {
  19109. context = stack;
  19110. stack = cb;
  19111. cb = dimensions;
  19112. dimensions = [];
  19113. }
  19114. var result = [];
  19115. this.each(dimensions, function () {
  19116. result.push(cb && cb.apply(this, arguments));
  19117. }, stack, context);
  19118. return result;
  19119. };
  19120. function cloneListForMapAndSample(original, excludeDimensions) {
  19121. var allDimensions = original.dimensions;
  19122. var list = new List(
  19123. zrUtil.map(allDimensions, original.getDimensionInfo, original),
  19124. original.hostModel
  19125. );
  19126. // FIXME If needs stackedOn, value may already been stacked
  19127. transferProperties(list, original);
  19128. var storage = list._storage = {};
  19129. var originalStorage = original._storage;
  19130. // Init storage
  19131. for (var i = 0; i < allDimensions.length; i++) {
  19132. var dim = allDimensions[i];
  19133. var dimStore = originalStorage[dim];
  19134. if (zrUtil.indexOf(excludeDimensions, dim) >= 0) {
  19135. storage[dim] = new dimStore.constructor(
  19136. originalStorage[dim].length
  19137. );
  19138. }
  19139. else {
  19140. // Direct reference for other dimensions
  19141. storage[dim] = originalStorage[dim];
  19142. }
  19143. }
  19144. return list;
  19145. }
  19146. /**
  19147. * Data mapping to a new List with given dimensions
  19148. * @param {string|Array.<string>} dimensions
  19149. * @param {Function} cb
  19150. * @param {boolean} [stack=false]
  19151. * @param {*} [context=this]
  19152. * @return {Array}
  19153. */
  19154. listProto.map = function (dimensions, cb, stack, context) {
  19155. dimensions = zrUtil.map(
  19156. normalizeDimensions(dimensions), this.getDimension, this
  19157. );
  19158. var list = cloneListForMapAndSample(this, dimensions);
  19159. // Following properties are all immutable.
  19160. // So we can reference to the same value
  19161. var indices = list.indices = this.indices;
  19162. var storage = list._storage;
  19163. var tmpRetValue = [];
  19164. this.each(dimensions, function () {
  19165. var idx = arguments[arguments.length - 1];
  19166. var retValue = cb && cb.apply(this, arguments);
  19167. if (retValue != null) {
  19168. // a number
  19169. if (typeof retValue === 'number') {
  19170. tmpRetValue[0] = retValue;
  19171. retValue = tmpRetValue;
  19172. }
  19173. for (var i = 0; i < retValue.length; i++) {
  19174. var dim = dimensions[i];
  19175. var dimStore = storage[dim];
  19176. var rawIdx = indices[idx];
  19177. if (dimStore) {
  19178. dimStore[rawIdx] = retValue[i];
  19179. }
  19180. }
  19181. }
  19182. }, stack, context);
  19183. return list;
  19184. };
  19185. /**
  19186. * Large data down sampling on given dimension
  19187. * @param {string} dimension
  19188. * @param {number} rate
  19189. * @param {Function} sampleValue
  19190. * @param {Function} sampleIndex Sample index for name and id
  19191. */
  19192. listProto.downSample = function (dimension, rate, sampleValue, sampleIndex) {
  19193. var list = cloneListForMapAndSample(this, [dimension]);
  19194. var storage = this._storage;
  19195. var targetStorage = list._storage;
  19196. var originalIndices = this.indices;
  19197. var indices = list.indices = [];
  19198. var frameValues = [];
  19199. var frameIndices = [];
  19200. var frameSize = Math.floor(1 / rate);
  19201. var dimStore = targetStorage[dimension];
  19202. var len = this.count();
  19203. // Copy data from original data
  19204. for (var i = 0; i < storage[dimension].length; i++) {
  19205. targetStorage[dimension][i] = storage[dimension][i];
  19206. }
  19207. for (var i = 0; i < len; i += frameSize) {
  19208. // Last frame
  19209. if (frameSize > len - i) {
  19210. frameSize = len - i;
  19211. frameValues.length = frameSize;
  19212. }
  19213. for (var k = 0; k < frameSize; k++) {
  19214. var idx = originalIndices[i + k];
  19215. frameValues[k] = dimStore[idx];
  19216. frameIndices[k] = idx;
  19217. }
  19218. var value = sampleValue(frameValues);
  19219. var idx = frameIndices[sampleIndex(frameValues, value) || 0];
  19220. // Only write value on the filtered data
  19221. dimStore[idx] = value;
  19222. indices.push(idx);
  19223. }
  19224. return list;
  19225. };
  19226. /**
  19227. * Get model of one data item.
  19228. *
  19229. * @param {number} idx
  19230. */
  19231. // FIXME Model proxy ?
  19232. listProto.getItemModel = function (idx) {
  19233. var hostModel = this.hostModel;
  19234. idx = this.indices[idx];
  19235. return new Model(this._rawData[idx], hostModel, hostModel && hostModel.ecModel);
  19236. };
  19237. /**
  19238. * Create a data differ
  19239. * @param {module:echarts/data/List} otherList
  19240. * @return {module:echarts/data/DataDiffer}
  19241. */
  19242. listProto.diff = function (otherList) {
  19243. var idList = this._idList;
  19244. var otherIdList = otherList && otherList._idList;
  19245. var val;
  19246. // Use prefix to avoid index to be the same as otherIdList[idx],
  19247. // which will cause weird udpate animation.
  19248. var prefix = 'e\0\0';
  19249. return new DataDiffer(
  19250. otherList ? otherList.indices : [],
  19251. this.indices,
  19252. function (idx) {
  19253. return (val = otherIdList[idx]) != null ? val : prefix + idx;
  19254. },
  19255. function (idx) {
  19256. return (val = idList[idx]) != null ? val : prefix + idx;
  19257. }
  19258. );
  19259. };
  19260. /**
  19261. * Get visual property.
  19262. * @param {string} key
  19263. */
  19264. listProto.getVisual = function (key) {
  19265. var visual = this._visual;
  19266. return visual && visual[key];
  19267. };
  19268. /**
  19269. * Set visual property
  19270. * @param {string|Object} key
  19271. * @param {*} [value]
  19272. *
  19273. * @example
  19274. * setVisual('color', color);
  19275. * setVisual({
  19276. * 'color': color
  19277. * });
  19278. */
  19279. listProto.setVisual = function (key, val) {
  19280. if (isObject(key)) {
  19281. for (var name in key) {
  19282. if (key.hasOwnProperty(name)) {
  19283. this.setVisual(name, key[name]);
  19284. }
  19285. }
  19286. return;
  19287. }
  19288. this._visual = this._visual || {};
  19289. this._visual[key] = val;
  19290. };
  19291. /**
  19292. * Set layout property.
  19293. * @param {string} key
  19294. * @param {*} [val]
  19295. */
  19296. listProto.setLayout = function (key, val) {
  19297. if (isObject(key)) {
  19298. for (var name in key) {
  19299. if (key.hasOwnProperty(name)) {
  19300. this.setLayout(name, key[name]);
  19301. }
  19302. }
  19303. return;
  19304. }
  19305. this._layout[key] = val;
  19306. };
  19307. /**
  19308. * Get layout property.
  19309. * @param {string} key.
  19310. * @return {*}
  19311. */
  19312. listProto.getLayout = function (key) {
  19313. return this._layout[key];
  19314. };
  19315. /**
  19316. * Get layout of single data item
  19317. * @param {number} idx
  19318. */
  19319. listProto.getItemLayout = function (idx) {
  19320. return this._itemLayouts[idx];
  19321. };
  19322. /**
  19323. * Set layout of single data item
  19324. * @param {number} idx
  19325. * @param {Object} layout
  19326. * @param {boolean=} [merge=false]
  19327. */
  19328. listProto.setItemLayout = function (idx, layout, merge) {
  19329. this._itemLayouts[idx] = merge
  19330. ? zrUtil.extend(this._itemLayouts[idx] || {}, layout)
  19331. : layout;
  19332. };
  19333. /**
  19334. * Clear all layout of single data item
  19335. */
  19336. listProto.clearItemLayouts = function () {
  19337. this._itemLayouts.length = 0;
  19338. };
  19339. /**
  19340. * Get visual property of single data item
  19341. * @param {number} idx
  19342. * @param {string} key
  19343. * @param {boolean} ignoreParent
  19344. */
  19345. listProto.getItemVisual = function (idx, key, ignoreParent) {
  19346. var itemVisual = this._itemVisuals[idx];
  19347. var val = itemVisual && itemVisual[key];
  19348. if (val == null && !ignoreParent) {
  19349. // Use global visual property
  19350. return this.getVisual(key);
  19351. }
  19352. return val;
  19353. };
  19354. /**
  19355. * Set visual property of single data item
  19356. *
  19357. * @param {number} idx
  19358. * @param {string|Object} key
  19359. * @param {*} [value]
  19360. *
  19361. * @example
  19362. * setItemVisual(0, 'color', color);
  19363. * setItemVisual(0, {
  19364. * 'color': color
  19365. * });
  19366. */
  19367. listProto.setItemVisual = function (idx, key, value) {
  19368. var itemVisual = this._itemVisuals[idx] || {};
  19369. this._itemVisuals[idx] = itemVisual;
  19370. if (isObject(key)) {
  19371. for (var name in key) {
  19372. if (key.hasOwnProperty(name)) {
  19373. itemVisual[name] = key[name];
  19374. }
  19375. }
  19376. return;
  19377. }
  19378. itemVisual[key] = value;
  19379. };
  19380. /**
  19381. * Clear itemVisuals and list visual.
  19382. */
  19383. listProto.clearAllVisual = function () {
  19384. this._visual = {};
  19385. this._itemVisuals = [];
  19386. };
  19387. var setItemDataAndSeriesIndex = function (child) {
  19388. child.seriesIndex = this.seriesIndex;
  19389. child.dataIndex = this.dataIndex;
  19390. child.dataType = this.dataType;
  19391. };
  19392. /**
  19393. * Set graphic element relative to data. It can be set as null
  19394. * @param {number} idx
  19395. * @param {module:zrender/Element} [el]
  19396. */
  19397. listProto.setItemGraphicEl = function (idx, el) {
  19398. var hostModel = this.hostModel;
  19399. if (el) {
  19400. // Add data index and series index for indexing the data by element
  19401. // Useful in tooltip
  19402. el.dataIndex = idx;
  19403. el.dataType = this.dataType;
  19404. el.seriesIndex = hostModel && hostModel.seriesIndex;
  19405. if (el.type === 'group') {
  19406. el.traverse(setItemDataAndSeriesIndex, el);
  19407. }
  19408. }
  19409. this._graphicEls[idx] = el;
  19410. };
  19411. /**
  19412. * @param {number} idx
  19413. * @return {module:zrender/Element}
  19414. */
  19415. listProto.getItemGraphicEl = function (idx) {
  19416. return this._graphicEls[idx];
  19417. };
  19418. /**
  19419. * @param {Function} cb
  19420. * @param {*} context
  19421. */
  19422. listProto.eachItemGraphicEl = function (cb, context) {
  19423. zrUtil.each(this._graphicEls, function (el, idx) {
  19424. if (el) {
  19425. cb && cb.call(context, el, idx);
  19426. }
  19427. });
  19428. };
  19429. /**
  19430. * Shallow clone a new list except visual and layout properties, and graph elements.
  19431. * New list only change the indices.
  19432. */
  19433. listProto.cloneShallow = function () {
  19434. var dimensionInfoList = zrUtil.map(this.dimensions, this.getDimensionInfo, this);
  19435. var list = new List(dimensionInfoList, this.hostModel);
  19436. // FIXME
  19437. list._storage = this._storage;
  19438. transferProperties(list, this);
  19439. // Clone will not change the data extent and indices
  19440. list.indices = this.indices.slice();
  19441. if (this._extent) {
  19442. list._extent = zrUtil.extend({}, this._extent);
  19443. }
  19444. return list;
  19445. };
  19446. /**
  19447. * Wrap some method to add more feature
  19448. * @param {string} methodName
  19449. * @param {Function} injectFunction
  19450. */
  19451. listProto.wrapMethod = function (methodName, injectFunction) {
  19452. var originalMethod = this[methodName];
  19453. if (typeof originalMethod !== 'function') {
  19454. return;
  19455. }
  19456. this.__wrappedMethods = this.__wrappedMethods || [];
  19457. this.__wrappedMethods.push(methodName);
  19458. this[methodName] = function () {
  19459. var res = originalMethod.apply(this, arguments);
  19460. return injectFunction.apply(this, [res].concat(zrUtil.slice(arguments)));
  19461. };
  19462. };
  19463. // Methods that create a new list based on this list should be listed here.
  19464. // Notice that those method should `RETURN` the new list.
  19465. listProto.TRANSFERABLE_METHODS = ['cloneShallow', 'downSample', 'map'];
  19466. // Methods that change indices of this list should be listed here.
  19467. listProto.CHANGABLE_METHODS = ['filterSelf'];
  19468. module.exports = List;
  19469. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  19470. /***/ },
  19471. /* 99 */
  19472. /***/ function(module, exports) {
  19473. 'use strict';
  19474. function defaultKeyGetter(item) {
  19475. return item;
  19476. }
  19477. function DataDiffer(oldArr, newArr, oldKeyGetter, newKeyGetter) {
  19478. this._old = oldArr;
  19479. this._new = newArr;
  19480. this._oldKeyGetter = oldKeyGetter || defaultKeyGetter;
  19481. this._newKeyGetter = newKeyGetter || defaultKeyGetter;
  19482. }
  19483. DataDiffer.prototype = {
  19484. constructor: DataDiffer,
  19485. /**
  19486. * Callback function when add a data
  19487. */
  19488. add: function (func) {
  19489. this._add = func;
  19490. return this;
  19491. },
  19492. /**
  19493. * Callback function when update a data
  19494. */
  19495. update: function (func) {
  19496. this._update = func;
  19497. return this;
  19498. },
  19499. /**
  19500. * Callback function when remove a data
  19501. */
  19502. remove: function (func) {
  19503. this._remove = func;
  19504. return this;
  19505. },
  19506. execute: function () {
  19507. var oldArr = this._old;
  19508. var newArr = this._new;
  19509. var oldKeyGetter = this._oldKeyGetter;
  19510. var newKeyGetter = this._newKeyGetter;
  19511. var oldDataIndexMap = {};
  19512. var newDataIndexMap = {};
  19513. var oldDataKeyArr = [];
  19514. var newDataKeyArr = [];
  19515. var i;
  19516. initIndexMap(oldArr, oldDataIndexMap, oldDataKeyArr, oldKeyGetter);
  19517. initIndexMap(newArr, newDataIndexMap, newDataKeyArr, newKeyGetter);
  19518. // Travel by inverted order to make sure order consistency
  19519. // when duplicate keys exists (consider newDataIndex.pop() below).
  19520. // For performance consideration, these code below do not look neat.
  19521. for (i = 0; i < oldArr.length; i++) {
  19522. var key = oldDataKeyArr[i];
  19523. var idx = newDataIndexMap[key];
  19524. // idx can never be empty array here. see 'set null' logic below.
  19525. if (idx != null) {
  19526. // Consider there is duplicate key (for example, use dataItem.name as key).
  19527. // We should make sure every item in newArr and oldArr can be visited.
  19528. var len = idx.length;
  19529. if (len) {
  19530. len === 1 && (newDataIndexMap[key] = null);
  19531. idx = idx.unshift();
  19532. }
  19533. else {
  19534. newDataIndexMap[key] = null;
  19535. }
  19536. this._update && this._update(idx, i);
  19537. }
  19538. else {
  19539. this._remove && this._remove(i);
  19540. }
  19541. }
  19542. for (var i = 0; i < newDataKeyArr.length; i++) {
  19543. var key = newDataKeyArr[i];
  19544. if (newDataIndexMap.hasOwnProperty(key)) {
  19545. var idx = newDataIndexMap[key];
  19546. if (idx == null) {
  19547. continue;
  19548. }
  19549. // idx can never be empty array here. see 'set null' logic above.
  19550. if (!idx.length) {
  19551. this._add && this._add(idx);
  19552. }
  19553. else {
  19554. for (var j = 0, len = idx.length; j < len; j++) {
  19555. this._add && this._add(idx[j]);
  19556. }
  19557. }
  19558. }
  19559. }
  19560. }
  19561. };
  19562. function initIndexMap(arr, map, keyArr, keyGetter) {
  19563. for (var i = 0; i < arr.length; i++) {
  19564. var key = keyGetter(arr[i], i);
  19565. var existence = map[key];
  19566. if (existence == null) {
  19567. keyArr.push(key);
  19568. map[key] = i;
  19569. }
  19570. else {
  19571. if (!existence.length) {
  19572. map[key] = existence = [existence];
  19573. }
  19574. existence.push(i);
  19575. }
  19576. }
  19577. }
  19578. module.exports = DataDiffer;
  19579. /***/ },
  19580. /* 100 */
  19581. /***/ function(module, exports, __webpack_require__) {
  19582. var zrUtil = __webpack_require__(4);
  19583. var echarts = __webpack_require__(1);
  19584. var PRIORITY = echarts.PRIORITY;
  19585. __webpack_require__(101);
  19586. __webpack_require__(104);
  19587. echarts.registerVisual(zrUtil.curry(
  19588. __webpack_require__(110), 'line', 'circle', 'line'
  19589. ));
  19590. echarts.registerLayout(zrUtil.curry(
  19591. __webpack_require__(111), 'line'
  19592. ));
  19593. // Down sample after filter
  19594. echarts.registerProcessor(PRIORITY.PROCESSOR.STATISTIC, zrUtil.curry(
  19595. __webpack_require__(112), 'line'
  19596. ));
  19597. // In case developer forget to include grid component
  19598. __webpack_require__(113);
  19599. /***/ },
  19600. /* 101 */
  19601. /***/ function(module, exports, __webpack_require__) {
  19602. 'use strict';
  19603. var createListFromArray = __webpack_require__(102);
  19604. var SeriesModel = __webpack_require__(28);
  19605. module.exports = SeriesModel.extend({
  19606. type: 'series.line',
  19607. dependencies: ['grid', 'polar'],
  19608. getInitialData: function (option, ecModel) {
  19609. if (true) {
  19610. var coordSys = option.coordinateSystem;
  19611. if (coordSys !== 'polar' && coordSys !== 'cartesian2d') {
  19612. throw new Error('Line not support coordinateSystem besides cartesian and polar');
  19613. }
  19614. }
  19615. return createListFromArray(option.data, this, ecModel);
  19616. },
  19617. defaultOption: {
  19618. zlevel: 0, // 一级层叠
  19619. z: 2, // 二级层叠
  19620. coordinateSystem: 'cartesian2d',
  19621. legendHoverLink: true,
  19622. hoverAnimation: true,
  19623. // stack: null
  19624. // xAxisIndex: 0,
  19625. // yAxisIndex: 0,
  19626. // polarIndex: 0,
  19627. // If clip the overflow value
  19628. clipOverflow: true,
  19629. label: {
  19630. normal: {
  19631. position: 'top'
  19632. }
  19633. },
  19634. // itemStyle: {
  19635. // normal: {},
  19636. // emphasis: {}
  19637. // },
  19638. lineStyle: {
  19639. normal: {
  19640. width: 2,
  19641. type: 'solid'
  19642. }
  19643. },
  19644. // areaStyle: {},
  19645. // false, 'start', 'end', 'middle'
  19646. step: false,
  19647. // Disabled if step is true
  19648. smooth: false,
  19649. smoothMonotone: null,
  19650. // 拐点图形类型
  19651. symbol: 'emptyCircle',
  19652. // 拐点图形大小
  19653. symbolSize: 4,
  19654. // 拐点图形旋转控制
  19655. symbolRotate: null,
  19656. // 是否显示 symbol, 只有在 tooltip hover 的时候显示
  19657. showSymbol: true,
  19658. // 标志图形默认只有主轴显示(随主轴标签间隔隐藏策略)
  19659. showAllSymbol: false,
  19660. // 是否连接断点
  19661. connectNulls: false,
  19662. // 数据过滤,'average', 'max', 'min', 'sum'
  19663. sampling: 'none',
  19664. animationEasing: 'linear',
  19665. // Disable progressive
  19666. progressive: 0,
  19667. hoverLayerThreshold: Infinity
  19668. }
  19669. });
  19670. /***/ },
  19671. /* 102 */
  19672. /***/ function(module, exports, __webpack_require__) {
  19673. 'use strict';
  19674. var List = __webpack_require__(98);
  19675. var completeDimensions = __webpack_require__(103);
  19676. var zrUtil = __webpack_require__(4);
  19677. var modelUtil = __webpack_require__(5);
  19678. var CoordinateSystem = __webpack_require__(26);
  19679. var getDataItemValue = modelUtil.getDataItemValue;
  19680. var converDataValue = modelUtil.converDataValue;
  19681. function firstDataNotNull(data) {
  19682. var i = 0;
  19683. while (i < data.length && data[i] == null) {
  19684. i++;
  19685. }
  19686. return data[i];
  19687. }
  19688. function ifNeedCompleteOrdinalData(data) {
  19689. var sampleItem = firstDataNotNull(data);
  19690. return sampleItem != null
  19691. && !zrUtil.isArray(getDataItemValue(sampleItem));
  19692. }
  19693. /**
  19694. * Helper function to create a list from option data
  19695. */
  19696. function createListFromArray(data, seriesModel, ecModel) {
  19697. // If data is undefined
  19698. data = data || [];
  19699. if (true) {
  19700. if (!zrUtil.isArray(data)) {
  19701. throw new Error('Invalid data.');
  19702. }
  19703. }
  19704. var coordSysName = seriesModel.get('coordinateSystem');
  19705. var creator = creators[coordSysName];
  19706. var registeredCoordSys = CoordinateSystem.get(coordSysName);
  19707. // FIXME
  19708. var axesInfo = creator && creator(data, seriesModel, ecModel);
  19709. var dimensions = axesInfo && axesInfo.dimensions;
  19710. if (!dimensions) {
  19711. // Get dimensions from registered coordinate system
  19712. dimensions = (registeredCoordSys && registeredCoordSys.dimensions) || ['x', 'y'];
  19713. dimensions = completeDimensions(dimensions, data, dimensions.concat(['value']));
  19714. }
  19715. var categoryIndex = axesInfo ? axesInfo.categoryIndex : -1;
  19716. var list = new List(dimensions, seriesModel);
  19717. var nameList = createNameList(axesInfo, data);
  19718. var categories = {};
  19719. var dimValueGetter = (categoryIndex >= 0 && ifNeedCompleteOrdinalData(data))
  19720. ? function (itemOpt, dimName, dataIndex, dimIndex) {
  19721. // If any dataItem is like { value: 10 }
  19722. if (modelUtil.isDataItemOption(itemOpt)) {
  19723. list.hasItemOption = true;
  19724. }
  19725. // Use dataIndex as ordinal value in categoryAxis
  19726. return dimIndex === categoryIndex
  19727. ? dataIndex
  19728. : converDataValue(getDataItemValue(itemOpt), dimensions[dimIndex]);
  19729. }
  19730. : function (itemOpt, dimName, dataIndex, dimIndex) {
  19731. var value = getDataItemValue(itemOpt);
  19732. var val = converDataValue(value && value[dimIndex], dimensions[dimIndex]);
  19733. // If any dataItem is like { value: 10 }
  19734. if (modelUtil.isDataItemOption(itemOpt)) {
  19735. list.hasItemOption = true;
  19736. }
  19737. var categoryAxesModels = axesInfo && axesInfo.categoryAxesModels;
  19738. if (categoryAxesModels && categoryAxesModels[dimName]) {
  19739. // If given value is a category string
  19740. if (typeof val === 'string') {
  19741. // Lazy get categories
  19742. categories[dimName] = categories[dimName]
  19743. || categoryAxesModels[dimName].getCategories();
  19744. val = zrUtil.indexOf(categories[dimName], val);
  19745. if (val < 0 && !isNaN(val)) {
  19746. // In case some one write '1', '2' istead of 1, 2
  19747. val = +val;
  19748. }
  19749. }
  19750. }
  19751. return val;
  19752. };
  19753. list.hasItemOption = false;
  19754. list.initData(data, nameList, dimValueGetter);
  19755. return list;
  19756. }
  19757. function isStackable(axisType) {
  19758. return axisType !== 'category' && axisType !== 'time';
  19759. }
  19760. function getDimTypeByAxis(axisType) {
  19761. return axisType === 'category'
  19762. ? 'ordinal'
  19763. : axisType === 'time'
  19764. ? 'time'
  19765. : 'float';
  19766. }
  19767. /**
  19768. * Creaters for each coord system.
  19769. */
  19770. var creators = {
  19771. cartesian2d: function (data, seriesModel, ecModel) {
  19772. var axesModels = zrUtil.map(['xAxis', 'yAxis'], function (name) {
  19773. return ecModel.queryComponents({
  19774. mainType: name,
  19775. index: seriesModel.get(name + 'Index'),
  19776. id: seriesModel.get(name + 'Id')
  19777. })[0];
  19778. });
  19779. var xAxisModel = axesModels[0];
  19780. var yAxisModel = axesModels[1];
  19781. if (true) {
  19782. if (!xAxisModel) {
  19783. throw new Error('xAxis "' + zrUtil.retrieve(
  19784. seriesModel.get('xAxisIndex'),
  19785. seriesModel.get('xAxisId'),
  19786. 0
  19787. ) + '" not found');
  19788. }
  19789. if (!yAxisModel) {
  19790. throw new Error('yAxis "' + zrUtil.retrieve(
  19791. seriesModel.get('xAxisIndex'),
  19792. seriesModel.get('yAxisId'),
  19793. 0
  19794. ) + '" not found');
  19795. }
  19796. }
  19797. var xAxisType = xAxisModel.get('type');
  19798. var yAxisType = yAxisModel.get('type');
  19799. var dimensions = [
  19800. {
  19801. name: 'x',
  19802. type: getDimTypeByAxis(xAxisType),
  19803. stackable: isStackable(xAxisType)
  19804. },
  19805. {
  19806. name: 'y',
  19807. // If two category axes
  19808. type: getDimTypeByAxis(yAxisType),
  19809. stackable: isStackable(yAxisType)
  19810. }
  19811. ];
  19812. var isXAxisCateogry = xAxisType === 'category';
  19813. var isYAxisCategory = yAxisType === 'category';
  19814. completeDimensions(dimensions, data, ['x', 'y', 'z']);
  19815. var categoryAxesModels = {};
  19816. if (isXAxisCateogry) {
  19817. categoryAxesModels.x = xAxisModel;
  19818. }
  19819. if (isYAxisCategory) {
  19820. categoryAxesModels.y = yAxisModel;
  19821. }
  19822. return {
  19823. dimensions: dimensions,
  19824. categoryIndex: isXAxisCateogry ? 0 : (isYAxisCategory ? 1 : -1),
  19825. categoryAxesModels: categoryAxesModels
  19826. };
  19827. },
  19828. singleAxis: function (data, seriesModel, ecModel) {
  19829. var singleAxisModel = ecModel.queryComponents({
  19830. mainType: 'singleAxis',
  19831. index: seriesModel.get('singleAxisIndex'),
  19832. id: seriesModel.get('singleAxisId')
  19833. })[0];
  19834. if (true) {
  19835. if (!singleAxisModel) {
  19836. throw new Error('singleAxis should be specified.');
  19837. }
  19838. }
  19839. var singleAxisType = singleAxisModel.get('type');
  19840. var isCategory = singleAxisType === 'category';
  19841. var dimensions = [{
  19842. name: 'single',
  19843. type: getDimTypeByAxis(singleAxisType),
  19844. stackable: isStackable(singleAxisType)
  19845. }];
  19846. completeDimensions(dimensions, data);
  19847. var categoryAxesModels = {};
  19848. if (isCategory) {
  19849. categoryAxesModels.single = singleAxisModel;
  19850. }
  19851. return {
  19852. dimensions: dimensions,
  19853. categoryIndex: isCategory ? 0 : -1,
  19854. categoryAxesModels: categoryAxesModels
  19855. };
  19856. },
  19857. polar: function (data, seriesModel, ecModel) {
  19858. var polarModel = ecModel.queryComponents({
  19859. mainType: 'polar',
  19860. index: seriesModel.get('polarIndex'),
  19861. id: seriesModel.get('polarId')
  19862. })[0];
  19863. var angleAxisModel = polarModel.findAxisModel('angleAxis');
  19864. var radiusAxisModel = polarModel.findAxisModel('radiusAxis');
  19865. if (true) {
  19866. if (!angleAxisModel) {
  19867. throw new Error('angleAxis option not found');
  19868. }
  19869. if (!radiusAxisModel) {
  19870. throw new Error('radiusAxis option not found');
  19871. }
  19872. }
  19873. var radiusAxisType = radiusAxisModel.get('type');
  19874. var angleAxisType = angleAxisModel.get('type');
  19875. var dimensions = [
  19876. {
  19877. name: 'radius',
  19878. type: getDimTypeByAxis(radiusAxisType),
  19879. stackable: isStackable(radiusAxisType)
  19880. },
  19881. {
  19882. name: 'angle',
  19883. type: getDimTypeByAxis(angleAxisType),
  19884. stackable: isStackable(angleAxisType)
  19885. }
  19886. ];
  19887. var isAngleAxisCateogry = angleAxisType === 'category';
  19888. var isRadiusAxisCateogry = radiusAxisType === 'category';
  19889. completeDimensions(dimensions, data, ['radius', 'angle', 'value']);
  19890. var categoryAxesModels = {};
  19891. if (isRadiusAxisCateogry) {
  19892. categoryAxesModels.radius = radiusAxisModel;
  19893. }
  19894. if (isAngleAxisCateogry) {
  19895. categoryAxesModels.angle = angleAxisModel;
  19896. }
  19897. return {
  19898. dimensions: dimensions,
  19899. categoryIndex: isAngleAxisCateogry ? 1 : (isRadiusAxisCateogry ? 0 : -1),
  19900. categoryAxesModels: categoryAxesModels
  19901. };
  19902. },
  19903. geo: function (data, seriesModel, ecModel) {
  19904. // TODO Region
  19905. // 多个散点图系列在同一个地区的时候
  19906. return {
  19907. dimensions: completeDimensions([
  19908. {name: 'lng'},
  19909. {name: 'lat'}
  19910. ], data, ['lng', 'lat', 'value'])
  19911. };
  19912. }
  19913. };
  19914. function createNameList(result, data) {
  19915. var nameList = [];
  19916. var categoryDim = result && result.dimensions[result.categoryIndex];
  19917. var categoryAxisModel;
  19918. if (categoryDim) {
  19919. categoryAxisModel = result.categoryAxesModels[categoryDim.name];
  19920. }
  19921. if (categoryAxisModel) {
  19922. // FIXME Two category axis
  19923. var categories = categoryAxisModel.getCategories();
  19924. if (categories) {
  19925. var dataLen = data.length;
  19926. // Ordered data is given explicitly like
  19927. // [[3, 0.2], [1, 0.3], [2, 0.15]]
  19928. // or given scatter data,
  19929. // pick the category
  19930. if (zrUtil.isArray(data[0]) && data[0].length > 1) {
  19931. nameList = [];
  19932. for (var i = 0; i < dataLen; i++) {
  19933. nameList[i] = categories[data[i][result.categoryIndex || 0]];
  19934. }
  19935. }
  19936. else {
  19937. nameList = categories.slice(0);
  19938. }
  19939. }
  19940. }
  19941. return nameList;
  19942. }
  19943. module.exports = createListFromArray;
  19944. /***/ },
  19945. /* 103 */
  19946. /***/ function(module, exports, __webpack_require__) {
  19947. /**
  19948. * Complete dimensions by data (guess dimension).
  19949. */
  19950. var zrUtil = __webpack_require__(4);
  19951. /**
  19952. * Complete the dimensions array guessed from the data structure.
  19953. * @param {Array.<string>} dimensions Necessary dimensions, like ['x', 'y']
  19954. * @param {Array} data Data list. [[1, 2, 3], [2, 3, 4]]
  19955. * @param {Array.<string>} [defaultNames] Default names to fill not necessary dimensions, like ['value']
  19956. * @param {string} [extraPrefix] Prefix of name when filling the left dimensions.
  19957. * @return {Array.<string>}
  19958. */
  19959. function completeDimensions(dimensions, data, defaultNames, extraPrefix) {
  19960. if (!data) {
  19961. return dimensions;
  19962. }
  19963. var value0 = retrieveValue(data[0]);
  19964. var dimSize = zrUtil.isArray(value0) && value0.length || 1;
  19965. defaultNames = defaultNames || [];
  19966. extraPrefix = extraPrefix || 'extra';
  19967. for (var i = 0; i < dimSize; i++) {
  19968. if (!dimensions[i]) {
  19969. var name = defaultNames[i] || (extraPrefix + (i - defaultNames.length));
  19970. dimensions[i] = guessOrdinal(data, i)
  19971. ? {type: 'ordinal', name: name}
  19972. : name;
  19973. }
  19974. }
  19975. return dimensions;
  19976. }
  19977. // The rule should not be complex, otherwise user might not
  19978. // be able to known where the data is wrong.
  19979. var guessOrdinal = completeDimensions.guessOrdinal = function (data, dimIndex) {
  19980. for (var i = 0, len = data.length; i < len; i++) {
  19981. var value = retrieveValue(data[i]);
  19982. if (!zrUtil.isArray(value)) {
  19983. return false;
  19984. }
  19985. var value = value[dimIndex];
  19986. if (value != null && isFinite(value)) {
  19987. return false;
  19988. }
  19989. else if (zrUtil.isString(value) && value !== '-') {
  19990. return true;
  19991. }
  19992. }
  19993. return false;
  19994. };
  19995. function retrieveValue(o) {
  19996. return zrUtil.isArray(o) ? o : zrUtil.isObject(o) ? o.value: o;
  19997. }
  19998. module.exports = completeDimensions;
  19999. /***/ },
  20000. /* 104 */
  20001. /***/ function(module, exports, __webpack_require__) {
  20002. 'use strict';
  20003. // FIXME step not support polar
  20004. var zrUtil = __webpack_require__(4);
  20005. var SymbolDraw = __webpack_require__(105);
  20006. var Symbol = __webpack_require__(106);
  20007. var lineAnimationDiff = __webpack_require__(108);
  20008. var graphic = __webpack_require__(43);
  20009. var modelUtil = __webpack_require__(5);
  20010. var polyHelper = __webpack_require__(109);
  20011. var ChartView = __webpack_require__(42);
  20012. function isPointsSame(points1, points2) {
  20013. if (points1.length !== points2.length) {
  20014. return;
  20015. }
  20016. for (var i = 0; i < points1.length; i++) {
  20017. var p1 = points1[i];
  20018. var p2 = points2[i];
  20019. if (p1[0] !== p2[0] || p1[1] !== p2[1]) {
  20020. return;
  20021. }
  20022. }
  20023. return true;
  20024. }
  20025. function getSmooth(smooth) {
  20026. return typeof (smooth) === 'number' ? smooth : (smooth ? 0.3 : 0);
  20027. }
  20028. function getAxisExtentWithGap(axis) {
  20029. var extent = axis.getGlobalExtent();
  20030. if (axis.onBand) {
  20031. // Remove extra 1px to avoid line miter in clipped edge
  20032. var halfBandWidth = axis.getBandWidth() / 2 - 1;
  20033. var dir = extent[1] > extent[0] ? 1 : -1;
  20034. extent[0] += dir * halfBandWidth;
  20035. extent[1] -= dir * halfBandWidth;
  20036. }
  20037. return extent;
  20038. }
  20039. function sign(val) {
  20040. return val >= 0 ? 1 : -1;
  20041. }
  20042. /**
  20043. * @param {module:echarts/coord/cartesian/Cartesian2D|module:echarts/coord/polar/Polar} coordSys
  20044. * @param {module:echarts/data/List} data
  20045. * @param {Array.<Array.<number>>} points
  20046. * @private
  20047. */
  20048. function getStackedOnPoints(coordSys, data) {
  20049. var baseAxis = coordSys.getBaseAxis();
  20050. var valueAxis = coordSys.getOtherAxis(baseAxis);
  20051. var valueStart = baseAxis.onZero
  20052. ? 0 : valueAxis.scale.getExtent()[0];
  20053. var valueDim = valueAxis.dim;
  20054. var baseDataOffset = valueDim === 'x' || valueDim === 'radius' ? 1 : 0;
  20055. return data.mapArray([valueDim], function (val, idx) {
  20056. var stackedOnSameSign;
  20057. var stackedOn = data.stackedOn;
  20058. // Find first stacked value with same sign
  20059. while (stackedOn &&
  20060. sign(stackedOn.get(valueDim, idx)) === sign(val)
  20061. ) {
  20062. stackedOnSameSign = stackedOn;
  20063. break;
  20064. }
  20065. var stackedData = [];
  20066. stackedData[baseDataOffset] = data.get(baseAxis.dim, idx);
  20067. stackedData[1 - baseDataOffset] = stackedOnSameSign
  20068. ? stackedOnSameSign.get(valueDim, idx, true) : valueStart;
  20069. return coordSys.dataToPoint(stackedData);
  20070. }, true);
  20071. }
  20072. function createGridClipShape(cartesian, hasAnimation, seriesModel) {
  20073. var xExtent = getAxisExtentWithGap(cartesian.getAxis('x'));
  20074. var yExtent = getAxisExtentWithGap(cartesian.getAxis('y'));
  20075. var isHorizontal = cartesian.getBaseAxis().isHorizontal();
  20076. var x = Math.min(xExtent[0], xExtent[1]);
  20077. var y = Math.min(yExtent[0], yExtent[1]);
  20078. var width = Math.max(xExtent[0], xExtent[1]) - x;
  20079. var height = Math.max(yExtent[0], yExtent[1]) - y;
  20080. var lineWidth = seriesModel.get('lineStyle.normal.width') || 2;
  20081. // Expand clip shape to avoid clipping when line value exceeds axis
  20082. var expandSize = seriesModel.get('clipOverflow') ? lineWidth / 2 : Math.max(width, height);
  20083. if (isHorizontal) {
  20084. y -= expandSize;
  20085. height += expandSize * 2;
  20086. }
  20087. else {
  20088. x -= expandSize;
  20089. width += expandSize * 2;
  20090. }
  20091. var clipPath = new graphic.Rect({
  20092. shape: {
  20093. x: x,
  20094. y: y,
  20095. width: width,
  20096. height: height
  20097. }
  20098. });
  20099. if (hasAnimation) {
  20100. clipPath.shape[isHorizontal ? 'width' : 'height'] = 0;
  20101. graphic.initProps(clipPath, {
  20102. shape: {
  20103. width: width,
  20104. height: height
  20105. }
  20106. }, seriesModel);
  20107. }
  20108. return clipPath;
  20109. }
  20110. function createPolarClipShape(polar, hasAnimation, seriesModel) {
  20111. var angleAxis = polar.getAngleAxis();
  20112. var radiusAxis = polar.getRadiusAxis();
  20113. var radiusExtent = radiusAxis.getExtent();
  20114. var angleExtent = angleAxis.getExtent();
  20115. var RADIAN = Math.PI / 180;
  20116. var clipPath = new graphic.Sector({
  20117. shape: {
  20118. cx: polar.cx,
  20119. cy: polar.cy,
  20120. r0: radiusExtent[0],
  20121. r: radiusExtent[1],
  20122. startAngle: -angleExtent[0] * RADIAN,
  20123. endAngle: -angleExtent[1] * RADIAN,
  20124. clockwise: angleAxis.inverse
  20125. }
  20126. });
  20127. if (hasAnimation) {
  20128. clipPath.shape.endAngle = -angleExtent[0] * RADIAN;
  20129. graphic.initProps(clipPath, {
  20130. shape: {
  20131. endAngle: -angleExtent[1] * RADIAN
  20132. }
  20133. }, seriesModel);
  20134. }
  20135. return clipPath;
  20136. }
  20137. function createClipShape(coordSys, hasAnimation, seriesModel) {
  20138. return coordSys.type === 'polar'
  20139. ? createPolarClipShape(coordSys, hasAnimation, seriesModel)
  20140. : createGridClipShape(coordSys, hasAnimation, seriesModel);
  20141. }
  20142. function turnPointsIntoStep(points, coordSys, stepTurnAt) {
  20143. var baseAxis = coordSys.getBaseAxis();
  20144. var baseIndex = baseAxis.dim === 'x' || baseAxis.dim === 'radius' ? 0 : 1;
  20145. var stepPoints = [];
  20146. for (var i = 0; i < points.length - 1; i++) {
  20147. var nextPt = points[i + 1];
  20148. var pt = points[i];
  20149. stepPoints.push(pt);
  20150. var stepPt = [];
  20151. switch (stepTurnAt) {
  20152. case 'end':
  20153. stepPt[baseIndex] = nextPt[baseIndex];
  20154. stepPt[1 - baseIndex] = pt[1 - baseIndex];
  20155. // default is start
  20156. stepPoints.push(stepPt);
  20157. break;
  20158. case 'middle':
  20159. // default is start
  20160. var middle = (pt[baseIndex] + nextPt[baseIndex]) / 2;
  20161. var stepPt2 = [];
  20162. stepPt[baseIndex] = stepPt2[baseIndex] = middle;
  20163. stepPt[1 - baseIndex] = pt[1 - baseIndex];
  20164. stepPt2[1 - baseIndex] = nextPt[1 - baseIndex];
  20165. stepPoints.push(stepPt);
  20166. stepPoints.push(stepPt2);
  20167. break;
  20168. default:
  20169. stepPt[baseIndex] = pt[baseIndex];
  20170. stepPt[1 - baseIndex] = nextPt[1 - baseIndex];
  20171. // default is start
  20172. stepPoints.push(stepPt);
  20173. }
  20174. }
  20175. // Last points
  20176. points[i] && stepPoints.push(points[i]);
  20177. return stepPoints;
  20178. }
  20179. function getVisualGradient(data, coordSys) {
  20180. var visualMetaList = data.getVisual('visualMeta');
  20181. if (!visualMetaList || !visualMetaList.length || !data.count()) {
  20182. // When data.count() is 0, gradient range can not be calculated.
  20183. return;
  20184. }
  20185. var visualMeta;
  20186. for (var i = visualMetaList.length - 1; i >= 0; i--) {
  20187. // Can only be x or y
  20188. if (visualMetaList[i].dimension < 2) {
  20189. visualMeta = visualMetaList[i];
  20190. break;
  20191. }
  20192. }
  20193. if (!visualMeta || coordSys.type !== 'cartesian2d') {
  20194. if (true) {
  20195. console.warn('Visual map on line style only support x or y dimension.');
  20196. }
  20197. return;
  20198. }
  20199. // If the area to be rendered is bigger than area defined by LinearGradient,
  20200. // the canvas spec prescribes that the color of the first stop and the last
  20201. // stop should be used. But if two stops are added at offset 0, in effect
  20202. // browsers use the color of the second stop to render area outside
  20203. // LinearGradient. So we can only infinitesimally extend area defined in
  20204. // LinearGradient to render `outerColors`.
  20205. var dimension = visualMeta.dimension;
  20206. var dimName = data.dimensions[dimension];
  20207. var axis = coordSys.getAxis(dimName);
  20208. // dataToCoor mapping may not be linear, but must be monotonic.
  20209. var colorStops = zrUtil.map(visualMeta.stops, function (stop) {
  20210. return {
  20211. coord: axis.toGlobalCoord(axis.dataToCoord(stop.value)),
  20212. color: stop.color
  20213. };
  20214. });
  20215. var stopLen = colorStops.length;
  20216. var outerColors = visualMeta.outerColors.slice();
  20217. if (stopLen && colorStops[0].coord > colorStops[stopLen - 1].coord) {
  20218. colorStops.reverse();
  20219. outerColors.reverse();
  20220. }
  20221. var tinyExtent = 10; // Arbitrary value: 10px
  20222. var minCoord = colorStops[0].coord - tinyExtent;
  20223. var maxCoord = colorStops[stopLen - 1].coord + tinyExtent;
  20224. var coordSpan = maxCoord - minCoord;
  20225. if (coordSpan < 1e-3) {
  20226. return 'transparent';
  20227. }
  20228. zrUtil.each(colorStops, function (stop) {
  20229. stop.offset = (stop.coord - minCoord) / coordSpan;
  20230. });
  20231. colorStops.push({
  20232. offset: stopLen ? colorStops[stopLen - 1].offset : 0.5,
  20233. color: outerColors[1] || 'transparent'
  20234. });
  20235. colorStops.unshift({ // notice colorStops.length have been changed.
  20236. offset: stopLen ? colorStops[0].offset : 0.5,
  20237. color: outerColors[0] || 'transparent'
  20238. });
  20239. // zrUtil.each(colorStops, function (colorStop) {
  20240. // // Make sure each offset has rounded px to avoid not sharp edge
  20241. // colorStop.offset = (Math.round(colorStop.offset * (end - start) + start) - start) / (end - start);
  20242. // });
  20243. var gradient = new graphic.LinearGradient(0, 0, 0, 0, colorStops, true);
  20244. gradient[dimName] = minCoord;
  20245. gradient[dimName + '2'] = maxCoord;
  20246. return gradient;
  20247. }
  20248. module.exports = ChartView.extend({
  20249. type: 'line',
  20250. init: function () {
  20251. var lineGroup = new graphic.Group();
  20252. var symbolDraw = new SymbolDraw();
  20253. this.group.add(symbolDraw.group);
  20254. this._symbolDraw = symbolDraw;
  20255. this._lineGroup = lineGroup;
  20256. },
  20257. render: function (seriesModel, ecModel, api) {
  20258. var coordSys = seriesModel.coordinateSystem;
  20259. var group = this.group;
  20260. var data = seriesModel.getData();
  20261. var lineStyleModel = seriesModel.getModel('lineStyle.normal');
  20262. var areaStyleModel = seriesModel.getModel('areaStyle.normal');
  20263. var points = data.mapArray(data.getItemLayout, true);
  20264. var isCoordSysPolar = coordSys.type === 'polar';
  20265. var prevCoordSys = this._coordSys;
  20266. var symbolDraw = this._symbolDraw;
  20267. var polyline = this._polyline;
  20268. var polygon = this._polygon;
  20269. var lineGroup = this._lineGroup;
  20270. var hasAnimation = seriesModel.get('animation');
  20271. var isAreaChart = !areaStyleModel.isEmpty();
  20272. var stackedOnPoints = getStackedOnPoints(coordSys, data);
  20273. var showSymbol = seriesModel.get('showSymbol');
  20274. var isSymbolIgnore = showSymbol && !isCoordSysPolar && !seriesModel.get('showAllSymbol')
  20275. && this._getSymbolIgnoreFunc(data, coordSys);
  20276. // Remove temporary symbols
  20277. var oldData = this._data;
  20278. oldData && oldData.eachItemGraphicEl(function (el, idx) {
  20279. if (el.__temp) {
  20280. group.remove(el);
  20281. oldData.setItemGraphicEl(idx, null);
  20282. }
  20283. });
  20284. // Remove previous created symbols if showSymbol changed to false
  20285. if (!showSymbol) {
  20286. symbolDraw.remove();
  20287. }
  20288. group.add(lineGroup);
  20289. // FIXME step not support polar
  20290. var step = !isCoordSysPolar && seriesModel.get('step');
  20291. // Initialization animation or coordinate system changed
  20292. if (
  20293. !(polyline && prevCoordSys.type === coordSys.type && step === this._step)
  20294. ) {
  20295. showSymbol && symbolDraw.updateData(data, isSymbolIgnore);
  20296. if (step) {
  20297. // TODO If stacked series is not step
  20298. points = turnPointsIntoStep(points, coordSys, step);
  20299. stackedOnPoints = turnPointsIntoStep(stackedOnPoints, coordSys, step);
  20300. }
  20301. polyline = this._newPolyline(points, coordSys, hasAnimation);
  20302. if (isAreaChart) {
  20303. polygon = this._newPolygon(
  20304. points, stackedOnPoints,
  20305. coordSys, hasAnimation
  20306. );
  20307. }
  20308. lineGroup.setClipPath(createClipShape(coordSys, true, seriesModel));
  20309. }
  20310. else {
  20311. if (isAreaChart && !polygon) {
  20312. // If areaStyle is added
  20313. polygon = this._newPolygon(
  20314. points, stackedOnPoints,
  20315. coordSys, hasAnimation
  20316. );
  20317. }
  20318. else if (polygon && !isAreaChart) {
  20319. // If areaStyle is removed
  20320. lineGroup.remove(polygon);
  20321. polygon = this._polygon = null;
  20322. }
  20323. // Update clipPath
  20324. lineGroup.setClipPath(createClipShape(coordSys, false, seriesModel));
  20325. // Always update, or it is wrong in the case turning on legend
  20326. // because points are not changed
  20327. showSymbol && symbolDraw.updateData(data, isSymbolIgnore);
  20328. // Stop symbol animation and sync with line points
  20329. // FIXME performance?
  20330. data.eachItemGraphicEl(function (el) {
  20331. el.stopAnimation(true);
  20332. });
  20333. // In the case data zoom triggerred refreshing frequently
  20334. // Data may not change if line has a category axis. So it should animate nothing
  20335. if (!isPointsSame(this._stackedOnPoints, stackedOnPoints)
  20336. || !isPointsSame(this._points, points)
  20337. ) {
  20338. if (hasAnimation) {
  20339. this._updateAnimation(
  20340. data, stackedOnPoints, coordSys, api, step
  20341. );
  20342. }
  20343. else {
  20344. // Not do it in update with animation
  20345. if (step) {
  20346. // TODO If stacked series is not step
  20347. points = turnPointsIntoStep(points, coordSys, step);
  20348. stackedOnPoints = turnPointsIntoStep(stackedOnPoints, coordSys, step);
  20349. }
  20350. polyline.setShape({
  20351. points: points
  20352. });
  20353. polygon && polygon.setShape({
  20354. points: points,
  20355. stackedOnPoints: stackedOnPoints
  20356. });
  20357. }
  20358. }
  20359. }
  20360. var visualColor = getVisualGradient(data, coordSys) || data.getVisual('color');
  20361. polyline.useStyle(zrUtil.defaults(
  20362. // Use color in lineStyle first
  20363. lineStyleModel.getLineStyle(),
  20364. {
  20365. fill: 'none',
  20366. stroke: visualColor,
  20367. lineJoin: 'bevel'
  20368. }
  20369. ));
  20370. var smooth = seriesModel.get('smooth');
  20371. smooth = getSmooth(seriesModel.get('smooth'));
  20372. polyline.setShape({
  20373. smooth: smooth,
  20374. smoothMonotone: seriesModel.get('smoothMonotone'),
  20375. connectNulls: seriesModel.get('connectNulls')
  20376. });
  20377. if (polygon) {
  20378. var stackedOn = data.stackedOn;
  20379. var stackedOnSmooth = 0;
  20380. polygon.useStyle(zrUtil.defaults(
  20381. areaStyleModel.getAreaStyle(),
  20382. {
  20383. fill: visualColor,
  20384. opacity: 0.7,
  20385. lineJoin: 'bevel'
  20386. }
  20387. ));
  20388. if (stackedOn) {
  20389. var stackedOnSeries = stackedOn.hostModel;
  20390. stackedOnSmooth = getSmooth(stackedOnSeries.get('smooth'));
  20391. }
  20392. polygon.setShape({
  20393. smooth: smooth,
  20394. stackedOnSmooth: stackedOnSmooth,
  20395. smoothMonotone: seriesModel.get('smoothMonotone'),
  20396. connectNulls: seriesModel.get('connectNulls')
  20397. });
  20398. }
  20399. this._data = data;
  20400. // Save the coordinate system for transition animation when data changed
  20401. this._coordSys = coordSys;
  20402. this._stackedOnPoints = stackedOnPoints;
  20403. this._points = points;
  20404. this._step = step;
  20405. },
  20406. dispose: function () {},
  20407. highlight: function (seriesModel, ecModel, api, payload) {
  20408. var data = seriesModel.getData();
  20409. var dataIndex = modelUtil.queryDataIndex(data, payload);
  20410. if (!(dataIndex instanceof Array) && dataIndex != null && dataIndex >= 0) {
  20411. var symbol = data.getItemGraphicEl(dataIndex);
  20412. if (!symbol) {
  20413. // Create a temporary symbol if it is not exists
  20414. var pt = data.getItemLayout(dataIndex);
  20415. if (!pt) {
  20416. // Null data
  20417. return;
  20418. }
  20419. symbol = new Symbol(data, dataIndex);
  20420. symbol.position = pt;
  20421. symbol.setZ(
  20422. seriesModel.get('zlevel'),
  20423. seriesModel.get('z')
  20424. );
  20425. symbol.ignore = isNaN(pt[0]) || isNaN(pt[1]);
  20426. symbol.__temp = true;
  20427. data.setItemGraphicEl(dataIndex, symbol);
  20428. // Stop scale animation
  20429. symbol.stopSymbolAnimation(true);
  20430. this.group.add(symbol);
  20431. }
  20432. symbol.highlight();
  20433. }
  20434. else {
  20435. // Highlight whole series
  20436. ChartView.prototype.highlight.call(
  20437. this, seriesModel, ecModel, api, payload
  20438. );
  20439. }
  20440. },
  20441. downplay: function (seriesModel, ecModel, api, payload) {
  20442. var data = seriesModel.getData();
  20443. var dataIndex = modelUtil.queryDataIndex(data, payload);
  20444. if (dataIndex != null && dataIndex >= 0) {
  20445. var symbol = data.getItemGraphicEl(dataIndex);
  20446. if (symbol) {
  20447. if (symbol.__temp) {
  20448. data.setItemGraphicEl(dataIndex, null);
  20449. this.group.remove(symbol);
  20450. }
  20451. else {
  20452. symbol.downplay();
  20453. }
  20454. }
  20455. }
  20456. else {
  20457. // Downplay whole series
  20458. ChartView.prototype.downplay.call(
  20459. this, seriesModel, ecModel, api, payload
  20460. );
  20461. }
  20462. },
  20463. /**
  20464. * @param {module:zrender/container/Group} group
  20465. * @param {Array.<Array.<number>>} points
  20466. * @private
  20467. */
  20468. _newPolyline: function (points) {
  20469. var polyline = this._polyline;
  20470. // Remove previous created polyline
  20471. if (polyline) {
  20472. this._lineGroup.remove(polyline);
  20473. }
  20474. polyline = new polyHelper.Polyline({
  20475. shape: {
  20476. points: points
  20477. },
  20478. silent: true,
  20479. z2: 10
  20480. });
  20481. this._lineGroup.add(polyline);
  20482. this._polyline = polyline;
  20483. return polyline;
  20484. },
  20485. /**
  20486. * @param {module:zrender/container/Group} group
  20487. * @param {Array.<Array.<number>>} stackedOnPoints
  20488. * @param {Array.<Array.<number>>} points
  20489. * @private
  20490. */
  20491. _newPolygon: function (points, stackedOnPoints) {
  20492. var polygon = this._polygon;
  20493. // Remove previous created polygon
  20494. if (polygon) {
  20495. this._lineGroup.remove(polygon);
  20496. }
  20497. polygon = new polyHelper.Polygon({
  20498. shape: {
  20499. points: points,
  20500. stackedOnPoints: stackedOnPoints
  20501. },
  20502. silent: true
  20503. });
  20504. this._lineGroup.add(polygon);
  20505. this._polygon = polygon;
  20506. return polygon;
  20507. },
  20508. /**
  20509. * @private
  20510. */
  20511. _getSymbolIgnoreFunc: function (data, coordSys) {
  20512. var categoryAxis = coordSys.getAxesByScale('ordinal')[0];
  20513. // `getLabelInterval` is provided by echarts/component/axis
  20514. if (categoryAxis && categoryAxis.isLabelIgnored) {
  20515. return zrUtil.bind(categoryAxis.isLabelIgnored, categoryAxis);
  20516. }
  20517. },
  20518. /**
  20519. * @private
  20520. */
  20521. // FIXME Two value axis
  20522. _updateAnimation: function (data, stackedOnPoints, coordSys, api, step) {
  20523. var polyline = this._polyline;
  20524. var polygon = this._polygon;
  20525. var seriesModel = data.hostModel;
  20526. var diff = lineAnimationDiff(
  20527. this._data, data,
  20528. this._stackedOnPoints, stackedOnPoints,
  20529. this._coordSys, coordSys
  20530. );
  20531. var current = diff.current;
  20532. var stackedOnCurrent = diff.stackedOnCurrent;
  20533. var next = diff.next;
  20534. var stackedOnNext = diff.stackedOnNext;
  20535. if (step) {
  20536. // TODO If stacked series is not step
  20537. current = turnPointsIntoStep(diff.current, coordSys, step);
  20538. stackedOnCurrent = turnPointsIntoStep(diff.stackedOnCurrent, coordSys, step);
  20539. next = turnPointsIntoStep(diff.next, coordSys, step);
  20540. stackedOnNext = turnPointsIntoStep(diff.stackedOnNext, coordSys, step);
  20541. }
  20542. // `diff.current` is subset of `current` (which should be ensured by
  20543. // turnPointsIntoStep), so points in `__points` can be updated when
  20544. // points in `current` are update during animation.
  20545. polyline.shape.__points = diff.current;
  20546. polyline.shape.points = current;
  20547. graphic.updateProps(polyline, {
  20548. shape: {
  20549. points: next
  20550. }
  20551. }, seriesModel);
  20552. if (polygon) {
  20553. polygon.setShape({
  20554. points: current,
  20555. stackedOnPoints: stackedOnCurrent
  20556. });
  20557. graphic.updateProps(polygon, {
  20558. shape: {
  20559. points: next,
  20560. stackedOnPoints: stackedOnNext
  20561. }
  20562. }, seriesModel);
  20563. }
  20564. var updatedDataInfo = [];
  20565. var diffStatus = diff.status;
  20566. for (var i = 0; i < diffStatus.length; i++) {
  20567. var cmd = diffStatus[i].cmd;
  20568. if (cmd === '=') {
  20569. var el = data.getItemGraphicEl(diffStatus[i].idx1);
  20570. if (el) {
  20571. updatedDataInfo.push({
  20572. el: el,
  20573. ptIdx: i // Index of points
  20574. });
  20575. }
  20576. }
  20577. }
  20578. if (polyline.animators && polyline.animators.length) {
  20579. polyline.animators[0].during(function () {
  20580. for (var i = 0; i < updatedDataInfo.length; i++) {
  20581. var el = updatedDataInfo[i].el;
  20582. el.attr('position', polyline.shape.__points[updatedDataInfo[i].ptIdx]);
  20583. }
  20584. });
  20585. }
  20586. },
  20587. remove: function (ecModel) {
  20588. var group = this.group;
  20589. var oldData = this._data;
  20590. this._lineGroup.removeAll();
  20591. this._symbolDraw.remove(true);
  20592. // Remove temporary created elements when highlighting
  20593. oldData && oldData.eachItemGraphicEl(function (el, idx) {
  20594. if (el.__temp) {
  20595. group.remove(el);
  20596. oldData.setItemGraphicEl(idx, null);
  20597. }
  20598. });
  20599. this._polyline =
  20600. this._polygon =
  20601. this._coordSys =
  20602. this._points =
  20603. this._stackedOnPoints =
  20604. this._data = null;
  20605. }
  20606. });
  20607. /***/ },
  20608. /* 105 */
  20609. /***/ function(module, exports, __webpack_require__) {
  20610. /**
  20611. * @module echarts/chart/helper/SymbolDraw
  20612. */
  20613. var graphic = __webpack_require__(43);
  20614. var Symbol = __webpack_require__(106);
  20615. /**
  20616. * @constructor
  20617. * @alias module:echarts/chart/helper/SymbolDraw
  20618. * @param {module:zrender/graphic/Group} [symbolCtor]
  20619. */
  20620. function SymbolDraw(symbolCtor) {
  20621. this.group = new graphic.Group();
  20622. this._symbolCtor = symbolCtor || Symbol;
  20623. }
  20624. var symbolDrawProto = SymbolDraw.prototype;
  20625. function symbolNeedsDraw(data, idx, isIgnore) {
  20626. var point = data.getItemLayout(idx);
  20627. // Is an object
  20628. // if (point && point.hasOwnProperty('point')) {
  20629. // point = point.point;
  20630. // }
  20631. return point && !isNaN(point[0]) && !isNaN(point[1]) && !(isIgnore && isIgnore(idx))
  20632. && data.getItemVisual(idx, 'symbol') !== 'none';
  20633. }
  20634. /**
  20635. * Update symbols draw by new data
  20636. * @param {module:echarts/data/List} data
  20637. * @param {Array.<boolean>} [isIgnore]
  20638. */
  20639. symbolDrawProto.updateData = function (data, isIgnore) {
  20640. var group = this.group;
  20641. var seriesModel = data.hostModel;
  20642. var oldData = this._data;
  20643. var SymbolCtor = this._symbolCtor;
  20644. var seriesScope = {
  20645. itemStyle: seriesModel.getModel('itemStyle.normal').getItemStyle(['color']),
  20646. hoverItemStyle: seriesModel.getModel('itemStyle.emphasis').getItemStyle(),
  20647. symbolRotate: seriesModel.get('symbolRotate'),
  20648. symbolOffset: seriesModel.get('symbolOffset'),
  20649. hoverAnimation: seriesModel.get('hoverAnimation'),
  20650. labelModel: seriesModel.getModel('label.normal'),
  20651. hoverLabelModel: seriesModel.getModel('label.emphasis')
  20652. };
  20653. data.diff(oldData)
  20654. .add(function (newIdx) {
  20655. var point = data.getItemLayout(newIdx);
  20656. if (symbolNeedsDraw(data, newIdx, isIgnore)) {
  20657. var symbolEl = new SymbolCtor(data, newIdx, seriesScope);
  20658. symbolEl.attr('position', point);
  20659. data.setItemGraphicEl(newIdx, symbolEl);
  20660. group.add(symbolEl);
  20661. }
  20662. })
  20663. .update(function (newIdx, oldIdx) {
  20664. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  20665. var point = data.getItemLayout(newIdx);
  20666. if (!symbolNeedsDraw(data, newIdx, isIgnore)) {
  20667. group.remove(symbolEl);
  20668. return;
  20669. }
  20670. if (!symbolEl) {
  20671. symbolEl = new SymbolCtor(data, newIdx);
  20672. symbolEl.attr('position', point);
  20673. }
  20674. else {
  20675. symbolEl.updateData(data, newIdx, seriesScope);
  20676. graphic.updateProps(symbolEl, {
  20677. position: point
  20678. }, seriesModel);
  20679. }
  20680. // Add back
  20681. group.add(symbolEl);
  20682. data.setItemGraphicEl(newIdx, symbolEl);
  20683. })
  20684. .remove(function (oldIdx) {
  20685. var el = oldData.getItemGraphicEl(oldIdx);
  20686. el && el.fadeOut(function () {
  20687. group.remove(el);
  20688. });
  20689. })
  20690. .execute();
  20691. this._data = data;
  20692. };
  20693. symbolDrawProto.updateLayout = function () {
  20694. var data = this._data;
  20695. if (data) {
  20696. // Not use animation
  20697. data.eachItemGraphicEl(function (el, idx) {
  20698. var point = data.getItemLayout(idx);
  20699. el.attr('position', point);
  20700. });
  20701. }
  20702. };
  20703. symbolDrawProto.remove = function (enableAnimation) {
  20704. var group = this.group;
  20705. var data = this._data;
  20706. if (data) {
  20707. if (enableAnimation) {
  20708. data.eachItemGraphicEl(function (el) {
  20709. el.fadeOut(function () {
  20710. group.remove(el);
  20711. });
  20712. });
  20713. }
  20714. else {
  20715. group.removeAll();
  20716. }
  20717. }
  20718. };
  20719. module.exports = SymbolDraw;
  20720. /***/ },
  20721. /* 106 */
  20722. /***/ function(module, exports, __webpack_require__) {
  20723. /**
  20724. * @module echarts/chart/helper/Symbol
  20725. */
  20726. var zrUtil = __webpack_require__(4);
  20727. var symbolUtil = __webpack_require__(107);
  20728. var graphic = __webpack_require__(43);
  20729. var numberUtil = __webpack_require__(7);
  20730. function getSymbolSize(data, idx) {
  20731. var symbolSize = data.getItemVisual(idx, 'symbolSize');
  20732. return symbolSize instanceof Array
  20733. ? symbolSize.slice()
  20734. : [+symbolSize, +symbolSize];
  20735. }
  20736. function getScale(symbolSize) {
  20737. return [symbolSize[0] / 2, symbolSize[1] / 2];
  20738. }
  20739. /**
  20740. * @constructor
  20741. * @alias {module:echarts/chart/helper/Symbol}
  20742. * @param {module:echarts/data/List} data
  20743. * @param {number} idx
  20744. * @extends {module:zrender/graphic/Group}
  20745. */
  20746. function Symbol(data, idx, seriesScope) {
  20747. graphic.Group.call(this);
  20748. this.updateData(data, idx, seriesScope);
  20749. }
  20750. var symbolProto = Symbol.prototype;
  20751. function driftSymbol(dx, dy) {
  20752. this.parent.drift(dx, dy);
  20753. }
  20754. symbolProto._createSymbol = function (symbolType, data, idx, symbolSize) {
  20755. // Remove paths created before
  20756. this.removeAll();
  20757. var seriesModel = data.hostModel;
  20758. var color = data.getItemVisual(idx, 'color');
  20759. // var symbolPath = symbolUtil.createSymbol(
  20760. // symbolType, -0.5, -0.5, 1, 1, color
  20761. // );
  20762. // If width/height are set too small (e.g., set to 1) on ios10
  20763. // and macOS Sierra, a circle stroke become a rect, no matter what
  20764. // the scale is set. So we set width/height as 2. See #4150.
  20765. var symbolPath = symbolUtil.createSymbol(
  20766. symbolType, -1, -1, 2, 2, color
  20767. );
  20768. symbolPath.attr({
  20769. z2: 100,
  20770. culling: true,
  20771. scale: [0, 0]
  20772. });
  20773. // Rewrite drift method
  20774. symbolPath.drift = driftSymbol;
  20775. graphic.initProps(symbolPath, {
  20776. scale: getScale(symbolSize)
  20777. }, seriesModel, idx);
  20778. this._symbolType = symbolType;
  20779. this.add(symbolPath);
  20780. };
  20781. /**
  20782. * Stop animation
  20783. * @param {boolean} toLastFrame
  20784. */
  20785. symbolProto.stopSymbolAnimation = function (toLastFrame) {
  20786. this.childAt(0).stopAnimation(toLastFrame);
  20787. };
  20788. /**
  20789. * Get symbol path element
  20790. */
  20791. symbolProto.getSymbolPath = function () {
  20792. return this.childAt(0);
  20793. };
  20794. /**
  20795. * Get scale(aka, current symbol size).
  20796. * Including the change caused by animation
  20797. */
  20798. symbolProto.getScale = function () {
  20799. return this.childAt(0).scale;
  20800. };
  20801. /**
  20802. * Highlight symbol
  20803. */
  20804. symbolProto.highlight = function () {
  20805. this.childAt(0).trigger('emphasis');
  20806. };
  20807. /**
  20808. * Downplay symbol
  20809. */
  20810. symbolProto.downplay = function () {
  20811. this.childAt(0).trigger('normal');
  20812. };
  20813. /**
  20814. * @param {number} zlevel
  20815. * @param {number} z
  20816. */
  20817. symbolProto.setZ = function (zlevel, z) {
  20818. var symbolPath = this.childAt(0);
  20819. symbolPath.zlevel = zlevel;
  20820. symbolPath.z = z;
  20821. };
  20822. symbolProto.setDraggable = function (draggable) {
  20823. var symbolPath = this.childAt(0);
  20824. symbolPath.draggable = draggable;
  20825. symbolPath.cursor = draggable ? 'move' : 'pointer';
  20826. };
  20827. /**
  20828. * Update symbol properties
  20829. * @param {module:echarts/data/List} data
  20830. * @param {number} idx
  20831. */
  20832. symbolProto.updateData = function (data, idx, seriesScope) {
  20833. this.silent = false;
  20834. var symbolType = data.getItemVisual(idx, 'symbol') || 'circle';
  20835. var seriesModel = data.hostModel;
  20836. var symbolSize = getSymbolSize(data, idx);
  20837. if (symbolType !== this._symbolType) {
  20838. this._createSymbol(symbolType, data, idx, symbolSize);
  20839. }
  20840. else {
  20841. var symbolPath = this.childAt(0);
  20842. graphic.updateProps(symbolPath, {
  20843. scale: getScale(symbolSize)
  20844. }, seriesModel, idx);
  20845. }
  20846. this._updateCommon(data, idx, symbolSize, seriesScope);
  20847. this._seriesModel = seriesModel;
  20848. };
  20849. // Update common properties
  20850. var normalStyleAccessPath = ['itemStyle', 'normal'];
  20851. var emphasisStyleAccessPath = ['itemStyle', 'emphasis'];
  20852. var normalLabelAccessPath = ['label', 'normal'];
  20853. var emphasisLabelAccessPath = ['label', 'emphasis'];
  20854. symbolProto._updateCommon = function (data, idx, symbolSize, seriesScope) {
  20855. var symbolPath = this.childAt(0);
  20856. var seriesModel = data.hostModel;
  20857. var color = data.getItemVisual(idx, 'color');
  20858. // Reset style
  20859. if (symbolPath.type !== 'image') {
  20860. symbolPath.useStyle({
  20861. strokeNoScale: true
  20862. });
  20863. }
  20864. seriesScope = seriesScope || null;
  20865. var itemStyle = seriesScope && seriesScope.itemStyle;
  20866. var hoverItemStyle = seriesScope && seriesScope.hoverItemStyle;
  20867. var symbolRotate = seriesScope && seriesScope.symbolRotate;
  20868. var symbolOffset = seriesScope && seriesScope.symbolOffset;
  20869. var labelModel = seriesScope && seriesScope.labelModel;
  20870. var hoverLabelModel = seriesScope && seriesScope.hoverLabelModel;
  20871. var hoverAnimation = seriesScope && seriesScope.hoverAnimation;
  20872. if (!seriesScope || data.hasItemOption) {
  20873. var itemModel = data.getItemModel(idx);
  20874. // Color must be excluded.
  20875. // Because symbol provide setColor individually to set fill and stroke
  20876. itemStyle = itemModel.getModel(normalStyleAccessPath).getItemStyle(['color']);
  20877. hoverItemStyle = itemModel.getModel(emphasisStyleAccessPath).getItemStyle();
  20878. symbolRotate = itemModel.getShallow('symbolRotate');
  20879. symbolOffset = itemModel.getShallow('symbolOffset');
  20880. labelModel = itemModel.getModel(normalLabelAccessPath);
  20881. hoverLabelModel = itemModel.getModel(emphasisLabelAccessPath);
  20882. hoverAnimation = itemModel.getShallow('hoverAnimation');
  20883. }
  20884. else {
  20885. hoverItemStyle = zrUtil.extend({}, hoverItemStyle);
  20886. }
  20887. var elStyle = symbolPath.style;
  20888. symbolPath.attr('rotation', (symbolRotate || 0) * Math.PI / 180 || 0);
  20889. if (symbolOffset) {
  20890. symbolPath.attr('position', [
  20891. numberUtil.parsePercent(symbolOffset[0], symbolSize[0]),
  20892. numberUtil.parsePercent(symbolOffset[1], symbolSize[1])
  20893. ]);
  20894. }
  20895. // PENDING setColor before setStyle!!!
  20896. symbolPath.setColor(color);
  20897. symbolPath.setStyle(itemStyle);
  20898. var opacity = data.getItemVisual(idx, 'opacity');
  20899. if (opacity != null) {
  20900. elStyle.opacity = opacity;
  20901. }
  20902. // Get last value dim
  20903. var dimensions = data.dimensions.slice();
  20904. var valueDim;
  20905. var dataType;
  20906. while (dimensions.length && (
  20907. valueDim = dimensions.pop(),
  20908. dataType = data.getDimensionInfo(valueDim).type,
  20909. dataType === 'ordinal' || dataType === 'time'
  20910. )) {} // jshint ignore:line
  20911. if (valueDim != null && labelModel.getShallow('show')) {
  20912. graphic.setText(elStyle, labelModel, color);
  20913. elStyle.text = zrUtil.retrieve(
  20914. seriesModel.getFormattedLabel(idx, 'normal'),
  20915. data.get(valueDim, idx)
  20916. );
  20917. }
  20918. else {
  20919. elStyle.text = '';
  20920. }
  20921. if (valueDim != null && hoverLabelModel.getShallow('show')) {
  20922. graphic.setText(hoverItemStyle, hoverLabelModel, color);
  20923. hoverItemStyle.text = zrUtil.retrieve(
  20924. seriesModel.getFormattedLabel(idx, 'emphasis'),
  20925. data.get(valueDim, idx)
  20926. );
  20927. }
  20928. else {
  20929. hoverItemStyle.text = '';
  20930. }
  20931. symbolPath.off('mouseover')
  20932. .off('mouseout')
  20933. .off('emphasis')
  20934. .off('normal');
  20935. symbolPath.hoverStyle = hoverItemStyle;
  20936. graphic.setHoverStyle(symbolPath);
  20937. var scale = getScale(symbolSize);
  20938. if (hoverAnimation && seriesModel.isAnimationEnabled()) {
  20939. var onEmphasis = function() {
  20940. var ratio = scale[1] / scale[0];
  20941. this.animateTo({
  20942. scale: [
  20943. Math.max(scale[0] * 1.1, scale[0] + 3),
  20944. Math.max(scale[1] * 1.1, scale[1] + 3 * ratio)
  20945. ]
  20946. }, 400, 'elasticOut');
  20947. };
  20948. var onNormal = function() {
  20949. this.animateTo({
  20950. scale: scale
  20951. }, 400, 'elasticOut');
  20952. };
  20953. symbolPath.on('mouseover', onEmphasis)
  20954. .on('mouseout', onNormal)
  20955. .on('emphasis', onEmphasis)
  20956. .on('normal', onNormal);
  20957. }
  20958. };
  20959. symbolProto.fadeOut = function (cb) {
  20960. var symbolPath = this.childAt(0);
  20961. // Avoid mistaken hover when fading out
  20962. this.silent = true;
  20963. // Not show text when animating
  20964. symbolPath.style.text = '';
  20965. graphic.updateProps(symbolPath, {
  20966. scale: [0, 0]
  20967. }, this._seriesModel, this.dataIndex, cb);
  20968. };
  20969. zrUtil.inherits(Symbol, graphic.Group);
  20970. module.exports = Symbol;
  20971. /***/ },
  20972. /* 107 */
  20973. /***/ function(module, exports, __webpack_require__) {
  20974. 'use strict';
  20975. // Symbol factory
  20976. var graphic = __webpack_require__(43);
  20977. var BoundingRect = __webpack_require__(9);
  20978. /**
  20979. * Triangle shape
  20980. * @inner
  20981. */
  20982. var Triangle = graphic.extendShape({
  20983. type: 'triangle',
  20984. shape: {
  20985. cx: 0,
  20986. cy: 0,
  20987. width: 0,
  20988. height: 0
  20989. },
  20990. buildPath: function (path, shape) {
  20991. var cx = shape.cx;
  20992. var cy = shape.cy;
  20993. var width = shape.width / 2;
  20994. var height = shape.height / 2;
  20995. path.moveTo(cx, cy - height);
  20996. path.lineTo(cx + width, cy + height);
  20997. path.lineTo(cx - width, cy + height);
  20998. path.closePath();
  20999. }
  21000. });
  21001. /**
  21002. * Diamond shape
  21003. * @inner
  21004. */
  21005. var Diamond = graphic.extendShape({
  21006. type: 'diamond',
  21007. shape: {
  21008. cx: 0,
  21009. cy: 0,
  21010. width: 0,
  21011. height: 0
  21012. },
  21013. buildPath: function (path, shape) {
  21014. var cx = shape.cx;
  21015. var cy = shape.cy;
  21016. var width = shape.width / 2;
  21017. var height = shape.height / 2;
  21018. path.moveTo(cx, cy - height);
  21019. path.lineTo(cx + width, cy);
  21020. path.lineTo(cx, cy + height);
  21021. path.lineTo(cx - width, cy);
  21022. path.closePath();
  21023. }
  21024. });
  21025. /**
  21026. * Pin shape
  21027. * @inner
  21028. */
  21029. var Pin = graphic.extendShape({
  21030. type: 'pin',
  21031. shape: {
  21032. // x, y on the cusp
  21033. x: 0,
  21034. y: 0,
  21035. width: 0,
  21036. height: 0
  21037. },
  21038. buildPath: function (path, shape) {
  21039. var x = shape.x;
  21040. var y = shape.y;
  21041. var w = shape.width / 5 * 3;
  21042. // Height must be larger than width
  21043. var h = Math.max(w, shape.height);
  21044. var r = w / 2;
  21045. // Dist on y with tangent point and circle center
  21046. var dy = r * r / (h - r);
  21047. var cy = y - h + r + dy;
  21048. var angle = Math.asin(dy / r);
  21049. // Dist on x with tangent point and circle center
  21050. var dx = Math.cos(angle) * r;
  21051. var tanX = Math.sin(angle);
  21052. var tanY = Math.cos(angle);
  21053. path.arc(
  21054. x, cy, r,
  21055. Math.PI - angle,
  21056. Math.PI * 2 + angle
  21057. );
  21058. var cpLen = r * 0.6;
  21059. var cpLen2 = r * 0.7;
  21060. path.bezierCurveTo(
  21061. x + dx - tanX * cpLen, cy + dy + tanY * cpLen,
  21062. x, y - cpLen2,
  21063. x, y
  21064. );
  21065. path.bezierCurveTo(
  21066. x, y - cpLen2,
  21067. x - dx + tanX * cpLen, cy + dy + tanY * cpLen,
  21068. x - dx, cy + dy
  21069. );
  21070. path.closePath();
  21071. }
  21072. });
  21073. /**
  21074. * Arrow shape
  21075. * @inner
  21076. */
  21077. var Arrow = graphic.extendShape({
  21078. type: 'arrow',
  21079. shape: {
  21080. x: 0,
  21081. y: 0,
  21082. width: 0,
  21083. height: 0
  21084. },
  21085. buildPath: function (ctx, shape) {
  21086. var height = shape.height;
  21087. var width = shape.width;
  21088. var x = shape.x;
  21089. var y = shape.y;
  21090. var dx = width / 3 * 2;
  21091. ctx.moveTo(x, y);
  21092. ctx.lineTo(x + dx, y + height);
  21093. ctx.lineTo(x, y + height / 4 * 3);
  21094. ctx.lineTo(x - dx, y + height);
  21095. ctx.lineTo(x, y);
  21096. ctx.closePath();
  21097. }
  21098. });
  21099. /**
  21100. * Map of path contructors
  21101. * @type {Object.<string, module:zrender/graphic/Path>}
  21102. */
  21103. var symbolCtors = {
  21104. line: graphic.Line,
  21105. rect: graphic.Rect,
  21106. roundRect: graphic.Rect,
  21107. square: graphic.Rect,
  21108. circle: graphic.Circle,
  21109. diamond: Diamond,
  21110. pin: Pin,
  21111. arrow: Arrow,
  21112. triangle: Triangle
  21113. };
  21114. var symbolShapeMakers = {
  21115. line: function (x, y, w, h, shape) {
  21116. // FIXME
  21117. shape.x1 = x;
  21118. shape.y1 = y + h / 2;
  21119. shape.x2 = x + w;
  21120. shape.y2 = y + h / 2;
  21121. },
  21122. rect: function (x, y, w, h, shape) {
  21123. shape.x = x;
  21124. shape.y = y;
  21125. shape.width = w;
  21126. shape.height = h;
  21127. },
  21128. roundRect: function (x, y, w, h, shape) {
  21129. shape.x = x;
  21130. shape.y = y;
  21131. shape.width = w;
  21132. shape.height = h;
  21133. shape.r = Math.min(w, h) / 4;
  21134. },
  21135. square: function (x, y, w, h, shape) {
  21136. var size = Math.min(w, h);
  21137. shape.x = x;
  21138. shape.y = y;
  21139. shape.width = size;
  21140. shape.height = size;
  21141. },
  21142. circle: function (x, y, w, h, shape) {
  21143. // Put circle in the center of square
  21144. shape.cx = x + w / 2;
  21145. shape.cy = y + h / 2;
  21146. shape.r = Math.min(w, h) / 2;
  21147. },
  21148. diamond: function (x, y, w, h, shape) {
  21149. shape.cx = x + w / 2;
  21150. shape.cy = y + h / 2;
  21151. shape.width = w;
  21152. shape.height = h;
  21153. },
  21154. pin: function (x, y, w, h, shape) {
  21155. shape.x = x + w / 2;
  21156. shape.y = y + h / 2;
  21157. shape.width = w;
  21158. shape.height = h;
  21159. },
  21160. arrow: function (x, y, w, h, shape) {
  21161. shape.x = x + w / 2;
  21162. shape.y = y + h / 2;
  21163. shape.width = w;
  21164. shape.height = h;
  21165. },
  21166. triangle: function (x, y, w, h, shape) {
  21167. shape.cx = x + w / 2;
  21168. shape.cy = y + h / 2;
  21169. shape.width = w;
  21170. shape.height = h;
  21171. }
  21172. };
  21173. var symbolBuildProxies = {};
  21174. for (var name in symbolCtors) {
  21175. if (symbolCtors.hasOwnProperty(name)) {
  21176. symbolBuildProxies[name] = new symbolCtors[name]();
  21177. }
  21178. }
  21179. var Symbol = graphic.extendShape({
  21180. type: 'symbol',
  21181. shape: {
  21182. symbolType: '',
  21183. x: 0,
  21184. y: 0,
  21185. width: 0,
  21186. height: 0
  21187. },
  21188. beforeBrush: function () {
  21189. var style = this.style;
  21190. var shape = this.shape;
  21191. // FIXME
  21192. if (shape.symbolType === 'pin' && style.textPosition === 'inside') {
  21193. style.textPosition = ['50%', '40%'];
  21194. style.textAlign = 'center';
  21195. style.textVerticalAlign = 'middle';
  21196. }
  21197. },
  21198. buildPath: function (ctx, shape, inBundle) {
  21199. var symbolType = shape.symbolType;
  21200. var proxySymbol = symbolBuildProxies[symbolType];
  21201. if (shape.symbolType !== 'none') {
  21202. if (!proxySymbol) {
  21203. // Default rect
  21204. symbolType = 'rect';
  21205. proxySymbol = symbolBuildProxies[symbolType];
  21206. }
  21207. symbolShapeMakers[symbolType](
  21208. shape.x, shape.y, shape.width, shape.height, proxySymbol.shape
  21209. );
  21210. proxySymbol.buildPath(ctx, proxySymbol.shape, inBundle);
  21211. }
  21212. }
  21213. });
  21214. // Provide setColor helper method to avoid determine if set the fill or stroke outside
  21215. var symbolPathSetColor = function (color) {
  21216. if (this.type !== 'image') {
  21217. var symbolStyle = this.style;
  21218. var symbolShape = this.shape;
  21219. if (symbolShape && symbolShape.symbolType === 'line') {
  21220. symbolStyle.stroke = color;
  21221. }
  21222. else if (this.__isEmptyBrush) {
  21223. symbolStyle.stroke = color;
  21224. symbolStyle.fill = '#fff';
  21225. }
  21226. else {
  21227. // FIXME 判断图形默认是填充还是描边,使用 onlyStroke ?
  21228. symbolStyle.fill && (symbolStyle.fill = color);
  21229. symbolStyle.stroke && (symbolStyle.stroke = color);
  21230. }
  21231. this.dirty(false);
  21232. }
  21233. };
  21234. var symbolUtil = {
  21235. /**
  21236. * Create a symbol element with given symbol configuration: shape, x, y, width, height, color
  21237. * @param {string} symbolType
  21238. * @param {number} x
  21239. * @param {number} y
  21240. * @param {number} w
  21241. * @param {number} h
  21242. * @param {string} color
  21243. */
  21244. createSymbol: function (symbolType, x, y, w, h, color) {
  21245. var isEmpty = symbolType.indexOf('empty') === 0;
  21246. if (isEmpty) {
  21247. symbolType = symbolType.substr(5, 1).toLowerCase() + symbolType.substr(6);
  21248. }
  21249. var symbolPath;
  21250. if (symbolType.indexOf('image://') === 0) {
  21251. symbolPath = new graphic.Image({
  21252. style: {
  21253. image: symbolType.slice(8),
  21254. x: x,
  21255. y: y,
  21256. width: w,
  21257. height: h
  21258. }
  21259. });
  21260. }
  21261. else if (symbolType.indexOf('path://') === 0) {
  21262. symbolPath = graphic.makePath(symbolType.slice(7), {}, new BoundingRect(x, y, w, h));
  21263. }
  21264. else {
  21265. symbolPath = new Symbol({
  21266. shape: {
  21267. symbolType: symbolType,
  21268. x: x,
  21269. y: y,
  21270. width: w,
  21271. height: h
  21272. }
  21273. });
  21274. }
  21275. symbolPath.__isEmptyBrush = isEmpty;
  21276. symbolPath.setColor = symbolPathSetColor;
  21277. symbolPath.setColor(color);
  21278. return symbolPath;
  21279. }
  21280. };
  21281. module.exports = symbolUtil;
  21282. /***/ },
  21283. /* 108 */
  21284. /***/ function(module, exports) {
  21285. // var arrayDiff = require('zrender/lib/core/arrayDiff');
  21286. // 'zrender/core/arrayDiff' has been used before, but it did
  21287. // not do well in performance when roam with fixed dataZoom window.
  21288. function sign(val) {
  21289. return val >= 0 ? 1 : -1;
  21290. }
  21291. function getStackedOnPoint(coordSys, data, idx) {
  21292. var baseAxis = coordSys.getBaseAxis();
  21293. var valueAxis = coordSys.getOtherAxis(baseAxis);
  21294. var valueStart = baseAxis.onZero
  21295. ? 0 : valueAxis.scale.getExtent()[0];
  21296. var valueDim = valueAxis.dim;
  21297. var baseDataOffset = valueDim === 'x' || valueDim === 'radius' ? 1 : 0;
  21298. var stackedOnSameSign;
  21299. var stackedOn = data.stackedOn;
  21300. var val = data.get(valueDim, idx);
  21301. // Find first stacked value with same sign
  21302. while (stackedOn &&
  21303. sign(stackedOn.get(valueDim, idx)) === sign(val)
  21304. ) {
  21305. stackedOnSameSign = stackedOn;
  21306. break;
  21307. }
  21308. var stackedData = [];
  21309. stackedData[baseDataOffset] = data.get(baseAxis.dim, idx);
  21310. stackedData[1 - baseDataOffset] = stackedOnSameSign
  21311. ? stackedOnSameSign.get(valueDim, idx, true) : valueStart;
  21312. return coordSys.dataToPoint(stackedData);
  21313. }
  21314. // function convertToIntId(newIdList, oldIdList) {
  21315. // // Generate int id instead of string id.
  21316. // // Compare string maybe slow in score function of arrDiff
  21317. // // Assume id in idList are all unique
  21318. // var idIndicesMap = {};
  21319. // var idx = 0;
  21320. // for (var i = 0; i < newIdList.length; i++) {
  21321. // idIndicesMap[newIdList[i]] = idx;
  21322. // newIdList[i] = idx++;
  21323. // }
  21324. // for (var i = 0; i < oldIdList.length; i++) {
  21325. // var oldId = oldIdList[i];
  21326. // // Same with newIdList
  21327. // if (idIndicesMap[oldId]) {
  21328. // oldIdList[i] = idIndicesMap[oldId];
  21329. // }
  21330. // else {
  21331. // oldIdList[i] = idx++;
  21332. // }
  21333. // }
  21334. // }
  21335. function diffData(oldData, newData) {
  21336. var diffResult = [];
  21337. newData.diff(oldData)
  21338. .add(function (idx) {
  21339. diffResult.push({cmd: '+', idx: idx});
  21340. })
  21341. .update(function (newIdx, oldIdx) {
  21342. diffResult.push({cmd: '=', idx: oldIdx, idx1: newIdx});
  21343. })
  21344. .remove(function (idx) {
  21345. diffResult.push({cmd: '-', idx: idx});
  21346. })
  21347. .execute();
  21348. return diffResult;
  21349. }
  21350. module.exports = function (
  21351. oldData, newData,
  21352. oldStackedOnPoints, newStackedOnPoints,
  21353. oldCoordSys, newCoordSys
  21354. ) {
  21355. var diff = diffData(oldData, newData);
  21356. // var newIdList = newData.mapArray(newData.getId);
  21357. // var oldIdList = oldData.mapArray(oldData.getId);
  21358. // convertToIntId(newIdList, oldIdList);
  21359. // // FIXME One data ?
  21360. // diff = arrayDiff(oldIdList, newIdList);
  21361. var currPoints = [];
  21362. var nextPoints = [];
  21363. // Points for stacking base line
  21364. var currStackedPoints = [];
  21365. var nextStackedPoints = [];
  21366. var status = [];
  21367. var sortedIndices = [];
  21368. var rawIndices = [];
  21369. var dims = newCoordSys.dimensions;
  21370. for (var i = 0; i < diff.length; i++) {
  21371. var diffItem = diff[i];
  21372. var pointAdded = true;
  21373. // FIXME, animation is not so perfect when dataZoom window moves fast
  21374. // Which is in case remvoing or add more than one data in the tail or head
  21375. switch (diffItem.cmd) {
  21376. case '=':
  21377. var currentPt = oldData.getItemLayout(diffItem.idx);
  21378. var nextPt = newData.getItemLayout(diffItem.idx1);
  21379. // If previous data is NaN, use next point directly
  21380. if (isNaN(currentPt[0]) || isNaN(currentPt[1])) {
  21381. currentPt = nextPt.slice();
  21382. }
  21383. currPoints.push(currentPt);
  21384. nextPoints.push(nextPt);
  21385. currStackedPoints.push(oldStackedOnPoints[diffItem.idx]);
  21386. nextStackedPoints.push(newStackedOnPoints[diffItem.idx1]);
  21387. rawIndices.push(newData.getRawIndex(diffItem.idx1));
  21388. break;
  21389. case '+':
  21390. var idx = diffItem.idx;
  21391. currPoints.push(
  21392. oldCoordSys.dataToPoint([
  21393. newData.get(dims[0], idx, true), newData.get(dims[1], idx, true)
  21394. ])
  21395. );
  21396. nextPoints.push(newData.getItemLayout(idx).slice());
  21397. currStackedPoints.push(
  21398. getStackedOnPoint(oldCoordSys, newData, idx)
  21399. );
  21400. nextStackedPoints.push(newStackedOnPoints[idx]);
  21401. rawIndices.push(newData.getRawIndex(idx));
  21402. break;
  21403. case '-':
  21404. var idx = diffItem.idx;
  21405. var rawIndex = oldData.getRawIndex(idx);
  21406. // Data is replaced. In the case of dynamic data queue
  21407. // FIXME FIXME FIXME
  21408. if (rawIndex !== idx) {
  21409. currPoints.push(oldData.getItemLayout(idx));
  21410. nextPoints.push(newCoordSys.dataToPoint([
  21411. oldData.get(dims[0], idx, true), oldData.get(dims[1], idx, true)
  21412. ]));
  21413. currStackedPoints.push(oldStackedOnPoints[idx]);
  21414. nextStackedPoints.push(
  21415. getStackedOnPoint(
  21416. newCoordSys, oldData, idx
  21417. )
  21418. );
  21419. rawIndices.push(rawIndex);
  21420. }
  21421. else {
  21422. pointAdded = false;
  21423. }
  21424. }
  21425. // Original indices
  21426. if (pointAdded) {
  21427. status.push(diffItem);
  21428. sortedIndices.push(sortedIndices.length);
  21429. }
  21430. }
  21431. // Diff result may be crossed if all items are changed
  21432. // Sort by data index
  21433. sortedIndices.sort(function (a, b) {
  21434. return rawIndices[a] - rawIndices[b];
  21435. });
  21436. var sortedCurrPoints = [];
  21437. var sortedNextPoints = [];
  21438. var sortedCurrStackedPoints = [];
  21439. var sortedNextStackedPoints = [];
  21440. var sortedStatus = [];
  21441. for (var i = 0; i < sortedIndices.length; i++) {
  21442. var idx = sortedIndices[i];
  21443. sortedCurrPoints[i] = currPoints[idx];
  21444. sortedNextPoints[i] = nextPoints[idx];
  21445. sortedCurrStackedPoints[i] = currStackedPoints[idx];
  21446. sortedNextStackedPoints[i] = nextStackedPoints[idx];
  21447. sortedStatus[i] = status[idx];
  21448. }
  21449. return {
  21450. current: sortedCurrPoints,
  21451. next: sortedNextPoints,
  21452. stackedOnCurrent: sortedCurrStackedPoints,
  21453. stackedOnNext: sortedNextStackedPoints,
  21454. status: sortedStatus
  21455. };
  21456. };
  21457. /***/ },
  21458. /* 109 */
  21459. /***/ function(module, exports, __webpack_require__) {
  21460. // Poly path support NaN point
  21461. var Path = __webpack_require__(45);
  21462. var vec2 = __webpack_require__(10);
  21463. var vec2Min = vec2.min;
  21464. var vec2Max = vec2.max;
  21465. var scaleAndAdd = vec2.scaleAndAdd;
  21466. var v2Copy = vec2.copy;
  21467. // Temporary variable
  21468. var v = [];
  21469. var cp0 = [];
  21470. var cp1 = [];
  21471. function isPointNull(p) {
  21472. return isNaN(p[0]) || isNaN(p[1]);
  21473. }
  21474. function drawSegment(
  21475. ctx, points, start, segLen, allLen,
  21476. dir, smoothMin, smoothMax, smooth, smoothMonotone, connectNulls
  21477. ) {
  21478. var prevIdx = 0;
  21479. var idx = start;
  21480. for (var k = 0; k < segLen; k++) {
  21481. var p = points[idx];
  21482. if (idx >= allLen || idx < 0) {
  21483. break;
  21484. }
  21485. if (isPointNull(p)) {
  21486. if (connectNulls) {
  21487. idx += dir;
  21488. continue;
  21489. }
  21490. break;
  21491. }
  21492. if (idx === start) {
  21493. ctx[dir > 0 ? 'moveTo' : 'lineTo'](p[0], p[1]);
  21494. v2Copy(cp0, p);
  21495. }
  21496. else {
  21497. if (smooth > 0) {
  21498. var nextIdx = idx + dir;
  21499. var nextP = points[nextIdx];
  21500. if (connectNulls) {
  21501. // Find next point not null
  21502. while (nextP && isPointNull(points[nextIdx])) {
  21503. nextIdx += dir;
  21504. nextP = points[nextIdx];
  21505. }
  21506. }
  21507. var ratioNextSeg = 0.5;
  21508. var prevP = points[prevIdx];
  21509. var nextP = points[nextIdx];
  21510. // Last point
  21511. if (!nextP || isPointNull(nextP)) {
  21512. v2Copy(cp1, p);
  21513. }
  21514. else {
  21515. // If next data is null in not connect case
  21516. if (isPointNull(nextP) && !connectNulls) {
  21517. nextP = p;
  21518. }
  21519. vec2.sub(v, nextP, prevP);
  21520. var lenPrevSeg;
  21521. var lenNextSeg;
  21522. if (smoothMonotone === 'x' || smoothMonotone === 'y') {
  21523. var dim = smoothMonotone === 'x' ? 0 : 1;
  21524. lenPrevSeg = Math.abs(p[dim] - prevP[dim]);
  21525. lenNextSeg = Math.abs(p[dim] - nextP[dim]);
  21526. }
  21527. else {
  21528. lenPrevSeg = vec2.dist(p, prevP);
  21529. lenNextSeg = vec2.dist(p, nextP);
  21530. }
  21531. // Use ratio of seg length
  21532. ratioNextSeg = lenNextSeg / (lenNextSeg + lenPrevSeg);
  21533. scaleAndAdd(cp1, p, v, -smooth * (1 - ratioNextSeg));
  21534. }
  21535. // Smooth constraint
  21536. vec2Min(cp0, cp0, smoothMax);
  21537. vec2Max(cp0, cp0, smoothMin);
  21538. vec2Min(cp1, cp1, smoothMax);
  21539. vec2Max(cp1, cp1, smoothMin);
  21540. ctx.bezierCurveTo(
  21541. cp0[0], cp0[1],
  21542. cp1[0], cp1[1],
  21543. p[0], p[1]
  21544. );
  21545. // cp0 of next segment
  21546. scaleAndAdd(cp0, p, v, smooth * ratioNextSeg);
  21547. }
  21548. else {
  21549. ctx.lineTo(p[0], p[1]);
  21550. }
  21551. }
  21552. prevIdx = idx;
  21553. idx += dir;
  21554. }
  21555. return k;
  21556. }
  21557. function getBoundingBox(points, smoothConstraint) {
  21558. var ptMin = [Infinity, Infinity];
  21559. var ptMax = [-Infinity, -Infinity];
  21560. if (smoothConstraint) {
  21561. for (var i = 0; i < points.length; i++) {
  21562. var pt = points[i];
  21563. if (pt[0] < ptMin[0]) { ptMin[0] = pt[0]; }
  21564. if (pt[1] < ptMin[1]) { ptMin[1] = pt[1]; }
  21565. if (pt[0] > ptMax[0]) { ptMax[0] = pt[0]; }
  21566. if (pt[1] > ptMax[1]) { ptMax[1] = pt[1]; }
  21567. }
  21568. }
  21569. return {
  21570. min: smoothConstraint ? ptMin : ptMax,
  21571. max: smoothConstraint ? ptMax : ptMin
  21572. };
  21573. }
  21574. module.exports = {
  21575. Polyline: Path.extend({
  21576. type: 'ec-polyline',
  21577. shape: {
  21578. points: [],
  21579. smooth: 0,
  21580. smoothConstraint: true,
  21581. smoothMonotone: null,
  21582. connectNulls: false
  21583. },
  21584. style: {
  21585. fill: null,
  21586. stroke: '#000'
  21587. },
  21588. buildPath: function (ctx, shape) {
  21589. var points = shape.points;
  21590. var i = 0;
  21591. var len = points.length;
  21592. var result = getBoundingBox(points, shape.smoothConstraint);
  21593. if (shape.connectNulls) {
  21594. // Must remove first and last null values avoid draw error in polygon
  21595. for (; len > 0; len--) {
  21596. if (!isPointNull(points[len - 1])) {
  21597. break;
  21598. }
  21599. }
  21600. for (; i < len; i++) {
  21601. if (!isPointNull(points[i])) {
  21602. break;
  21603. }
  21604. }
  21605. }
  21606. while (i < len) {
  21607. i += drawSegment(
  21608. ctx, points, i, len, len,
  21609. 1, result.min, result.max, shape.smooth,
  21610. shape.smoothMonotone, shape.connectNulls
  21611. ) + 1;
  21612. }
  21613. }
  21614. }),
  21615. Polygon: Path.extend({
  21616. type: 'ec-polygon',
  21617. shape: {
  21618. points: [],
  21619. // Offset between stacked base points and points
  21620. stackedOnPoints: [],
  21621. smooth: 0,
  21622. stackedOnSmooth: 0,
  21623. smoothConstraint: true,
  21624. smoothMonotone: null,
  21625. connectNulls: false
  21626. },
  21627. buildPath: function (ctx, shape) {
  21628. var points = shape.points;
  21629. var stackedOnPoints = shape.stackedOnPoints;
  21630. var i = 0;
  21631. var len = points.length;
  21632. var smoothMonotone = shape.smoothMonotone;
  21633. var bbox = getBoundingBox(points, shape.smoothConstraint);
  21634. var stackedOnBBox = getBoundingBox(stackedOnPoints, shape.smoothConstraint);
  21635. if (shape.connectNulls) {
  21636. // Must remove first and last null values avoid draw error in polygon
  21637. for (; len > 0; len--) {
  21638. if (!isPointNull(points[len - 1])) {
  21639. break;
  21640. }
  21641. }
  21642. for (; i < len; i++) {
  21643. if (!isPointNull(points[i])) {
  21644. break;
  21645. }
  21646. }
  21647. }
  21648. while (i < len) {
  21649. var k = drawSegment(
  21650. ctx, points, i, len, len,
  21651. 1, bbox.min, bbox.max, shape.smooth,
  21652. smoothMonotone, shape.connectNulls
  21653. );
  21654. drawSegment(
  21655. ctx, stackedOnPoints, i + k - 1, k, len,
  21656. -1, stackedOnBBox.min, stackedOnBBox.max, shape.stackedOnSmooth,
  21657. smoothMonotone, shape.connectNulls
  21658. );
  21659. i += k + 1;
  21660. ctx.closePath();
  21661. }
  21662. }
  21663. })
  21664. };
  21665. /***/ },
  21666. /* 110 */
  21667. /***/ function(module, exports) {
  21668. module.exports = function (seriesType, defaultSymbolType, legendSymbol, ecModel, api) {
  21669. // Encoding visual for all series include which is filtered for legend drawing
  21670. ecModel.eachRawSeriesByType(seriesType, function (seriesModel) {
  21671. var data = seriesModel.getData();
  21672. var symbolType = seriesModel.get('symbol') || defaultSymbolType;
  21673. var symbolSize = seriesModel.get('symbolSize');
  21674. data.setVisual({
  21675. legendSymbol: legendSymbol || symbolType,
  21676. symbol: symbolType,
  21677. symbolSize: symbolSize
  21678. });
  21679. // Only visible series has each data be visual encoded
  21680. if (!ecModel.isSeriesFiltered(seriesModel)) {
  21681. if (typeof symbolSize === 'function') {
  21682. data.each(function (idx) {
  21683. var rawValue = seriesModel.getRawValue(idx);
  21684. // FIXME
  21685. var params = seriesModel.getDataParams(idx);
  21686. data.setItemVisual(idx, 'symbolSize', symbolSize(rawValue, params));
  21687. });
  21688. }
  21689. data.each(function (idx) {
  21690. var itemModel = data.getItemModel(idx);
  21691. var itemSymbolType = itemModel.getShallow('symbol', true);
  21692. var itemSymbolSize = itemModel.getShallow('symbolSize', true);
  21693. // If has item symbol
  21694. if (itemSymbolType != null) {
  21695. data.setItemVisual(idx, 'symbol', itemSymbolType);
  21696. }
  21697. if (itemSymbolSize != null) {
  21698. // PENDING Transform symbolSize ?
  21699. data.setItemVisual(idx, 'symbolSize', itemSymbolSize);
  21700. }
  21701. });
  21702. }
  21703. });
  21704. };
  21705. /***/ },
  21706. /* 111 */
  21707. /***/ function(module, exports) {
  21708. module.exports = function (seriesType, ecModel) {
  21709. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  21710. var data = seriesModel.getData();
  21711. var coordSys = seriesModel.coordinateSystem;
  21712. if (coordSys) {
  21713. var dims = coordSys.dimensions;
  21714. if (coordSys.type === 'singleAxis') {
  21715. data.each(dims[0], function (x, idx) {
  21716. // Also {Array.<number>}, not undefined to avoid if...else... statement
  21717. data.setItemLayout(idx, isNaN(x) ? [NaN, NaN] : coordSys.dataToPoint(x));
  21718. });
  21719. }
  21720. else {
  21721. data.each(dims, function (x, y, idx) {
  21722. // Also {Array.<number>}, not undefined to avoid if...else... statement
  21723. data.setItemLayout(
  21724. idx, (isNaN(x) || isNaN(y)) ? [NaN, NaN] : coordSys.dataToPoint([x, y])
  21725. );
  21726. }, true);
  21727. }
  21728. }
  21729. });
  21730. };
  21731. /***/ },
  21732. /* 112 */
  21733. /***/ function(module, exports) {
  21734. var samplers = {
  21735. average: function (frame) {
  21736. var sum = 0;
  21737. var count = 0;
  21738. for (var i = 0; i < frame.length; i++) {
  21739. if (!isNaN(frame[i])) {
  21740. sum += frame[i];
  21741. count++;
  21742. }
  21743. }
  21744. // Return NaN if count is 0
  21745. return count === 0 ? NaN : sum / count;
  21746. },
  21747. sum: function (frame) {
  21748. var sum = 0;
  21749. for (var i = 0; i < frame.length; i++) {
  21750. // Ignore NaN
  21751. sum += frame[i] || 0;
  21752. }
  21753. return sum;
  21754. },
  21755. max: function (frame) {
  21756. var max = -Infinity;
  21757. for (var i = 0; i < frame.length; i++) {
  21758. frame[i] > max && (max = frame[i]);
  21759. }
  21760. return max;
  21761. },
  21762. min: function (frame) {
  21763. var min = Infinity;
  21764. for (var i = 0; i < frame.length; i++) {
  21765. frame[i] < min && (min = frame[i]);
  21766. }
  21767. return min;
  21768. },
  21769. // TODO
  21770. // Median
  21771. nearest: function (frame) {
  21772. return frame[0];
  21773. }
  21774. };
  21775. var indexSampler = function (frame, value) {
  21776. return Math.round(frame.length / 2);
  21777. };
  21778. module.exports = function (seriesType, ecModel, api) {
  21779. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  21780. var data = seriesModel.getData();
  21781. var sampling = seriesModel.get('sampling');
  21782. var coordSys = seriesModel.coordinateSystem;
  21783. // Only cartesian2d support down sampling
  21784. if (coordSys.type === 'cartesian2d' && sampling) {
  21785. var baseAxis = coordSys.getBaseAxis();
  21786. var valueAxis = coordSys.getOtherAxis(baseAxis);
  21787. var extent = baseAxis.getExtent();
  21788. // Coordinste system has been resized
  21789. var size = extent[1] - extent[0];
  21790. var rate = Math.round(data.count() / size);
  21791. if (rate > 1) {
  21792. var sampler;
  21793. if (typeof sampling === 'string') {
  21794. sampler = samplers[sampling];
  21795. }
  21796. else if (typeof sampling === 'function') {
  21797. sampler = sampling;
  21798. }
  21799. if (sampler) {
  21800. data = data.downSample(
  21801. valueAxis.dim, 1 / rate, sampler, indexSampler
  21802. );
  21803. seriesModel.setData(data);
  21804. }
  21805. }
  21806. }
  21807. }, this);
  21808. };
  21809. /***/ },
  21810. /* 113 */
  21811. /***/ function(module, exports, __webpack_require__) {
  21812. 'use strict';
  21813. var graphic = __webpack_require__(43);
  21814. var zrUtil = __webpack_require__(4);
  21815. var echarts = __webpack_require__(1);
  21816. __webpack_require__(114);
  21817. __webpack_require__(131);
  21818. // Grid view
  21819. echarts.extendComponentView({
  21820. type: 'grid',
  21821. render: function (gridModel, ecModel) {
  21822. this.group.removeAll();
  21823. if (gridModel.get('show')) {
  21824. this.group.add(new graphic.Rect({
  21825. shape: gridModel.coordinateSystem.getRect(),
  21826. style: zrUtil.defaults({
  21827. fill: gridModel.get('backgroundColor')
  21828. }, gridModel.getItemStyle()),
  21829. silent: true,
  21830. z2: -1
  21831. }));
  21832. }
  21833. }
  21834. });
  21835. echarts.registerPreprocessor(function (option) {
  21836. // Only create grid when need
  21837. if (option.xAxis && option.yAxis && !option.grid) {
  21838. option.grid = {};
  21839. }
  21840. });
  21841. /***/ },
  21842. /* 114 */
  21843. /***/ function(module, exports, __webpack_require__) {
  21844. /**
  21845. * Grid is a region which contains at most 4 cartesian systems
  21846. *
  21847. * TODO Default cartesian
  21848. */
  21849. var factory = exports;
  21850. var layout = __webpack_require__(21);
  21851. var axisHelper = __webpack_require__(115);
  21852. var zrUtil = __webpack_require__(4);
  21853. var Cartesian2D = __webpack_require__(121);
  21854. var Axis2D = __webpack_require__(123);
  21855. var each = zrUtil.each;
  21856. var ifAxisCrossZero = axisHelper.ifAxisCrossZero;
  21857. var niceScaleExtent = axisHelper.niceScaleExtent;
  21858. // 依赖 GridModel, AxisModel 做预处理
  21859. __webpack_require__(126);
  21860. /**
  21861. * Check if the axis is used in the specified grid
  21862. * @inner
  21863. */
  21864. function isAxisUsedInTheGrid(axisModel, gridModel, ecModel) {
  21865. return axisModel.getCoordSysModel() === gridModel;
  21866. }
  21867. function getLabelUnionRect(axis) {
  21868. var axisModel = axis.model;
  21869. var labels = axisModel.getFormattedLabels();
  21870. var textStyleModel = axisModel.getModel('axisLabel.textStyle');
  21871. var rect;
  21872. var step = 1;
  21873. var labelCount = labels.length;
  21874. if (labelCount > 40) {
  21875. // Simple optimization for large amount of labels
  21876. step = Math.ceil(labelCount / 40);
  21877. }
  21878. for (var i = 0; i < labelCount; i += step) {
  21879. if (!axis.isLabelIgnored(i)) {
  21880. var singleRect = textStyleModel.getTextRect(labels[i]);
  21881. // FIXME consider label rotate
  21882. rect ? rect.union(singleRect) : (rect = singleRect);
  21883. }
  21884. }
  21885. return rect;
  21886. }
  21887. function Grid(gridModel, ecModel, api) {
  21888. /**
  21889. * @type {Object.<string, module:echarts/coord/cartesian/Cartesian2D>}
  21890. * @private
  21891. */
  21892. this._coordsMap = {};
  21893. /**
  21894. * @type {Array.<module:echarts/coord/cartesian/Cartesian>}
  21895. * @private
  21896. */
  21897. this._coordsList = [];
  21898. /**
  21899. * @type {Object.<string, module:echarts/coord/cartesian/Axis2D>}
  21900. * @private
  21901. */
  21902. this._axesMap = {};
  21903. /**
  21904. * @type {Array.<module:echarts/coord/cartesian/Axis2D>}
  21905. * @private
  21906. */
  21907. this._axesList = [];
  21908. this._initCartesian(gridModel, ecModel, api);
  21909. this._model = gridModel;
  21910. }
  21911. var gridProto = Grid.prototype;
  21912. gridProto.type = 'grid';
  21913. gridProto.getRect = function () {
  21914. return this._rect;
  21915. };
  21916. gridProto.update = function (ecModel, api) {
  21917. var axesMap = this._axesMap;
  21918. this._updateScale(ecModel, this._model);
  21919. function ifAxisCanNotOnZero(otherAxisDim) {
  21920. var axes = axesMap[otherAxisDim];
  21921. for (var idx in axes) {
  21922. if (axes.hasOwnProperty(idx)) {
  21923. var axis = axes[idx];
  21924. if (axis && (axis.type === 'category' || !ifAxisCrossZero(axis))) {
  21925. return true;
  21926. }
  21927. }
  21928. }
  21929. return false;
  21930. }
  21931. each(axesMap.x, function (xAxis) {
  21932. niceScaleExtent(xAxis, xAxis.model);
  21933. });
  21934. each(axesMap.y, function (yAxis) {
  21935. niceScaleExtent(yAxis, yAxis.model);
  21936. });
  21937. // Fix configuration
  21938. each(axesMap.x, function (xAxis) {
  21939. // onZero can not be enabled in these two situations
  21940. // 1. When any other axis is a category axis
  21941. // 2. When any other axis not across 0 point
  21942. if (ifAxisCanNotOnZero('y')) {
  21943. xAxis.onZero = false;
  21944. }
  21945. });
  21946. each(axesMap.y, function (yAxis) {
  21947. if (ifAxisCanNotOnZero('x')) {
  21948. yAxis.onZero = false;
  21949. }
  21950. });
  21951. // Resize again if containLabel is enabled
  21952. // FIXME It may cause getting wrong grid size in data processing stage
  21953. this.resize(this._model, api);
  21954. };
  21955. /**
  21956. * Resize the grid
  21957. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  21958. * @param {module:echarts/ExtensionAPI} api
  21959. */
  21960. gridProto.resize = function (gridModel, api) {
  21961. var gridRect = layout.getLayoutRect(
  21962. gridModel.getBoxLayoutParams(), {
  21963. width: api.getWidth(),
  21964. height: api.getHeight()
  21965. });
  21966. this._rect = gridRect;
  21967. var axesList = this._axesList;
  21968. adjustAxes();
  21969. // Minus label size
  21970. if (gridModel.get('containLabel')) {
  21971. each(axesList, function (axis) {
  21972. if (!axis.model.get('axisLabel.inside')) {
  21973. var labelUnionRect = getLabelUnionRect(axis);
  21974. if (labelUnionRect) {
  21975. var dim = axis.isHorizontal() ? 'height' : 'width';
  21976. var margin = axis.model.get('axisLabel.margin');
  21977. gridRect[dim] -= labelUnionRect[dim] + margin;
  21978. if (axis.position === 'top') {
  21979. gridRect.y += labelUnionRect.height + margin;
  21980. }
  21981. else if (axis.position === 'left') {
  21982. gridRect.x += labelUnionRect.width + margin;
  21983. }
  21984. }
  21985. }
  21986. });
  21987. adjustAxes();
  21988. }
  21989. function adjustAxes() {
  21990. each(axesList, function (axis) {
  21991. var isHorizontal = axis.isHorizontal();
  21992. var extent = isHorizontal ? [0, gridRect.width] : [0, gridRect.height];
  21993. var idx = axis.inverse ? 1 : 0;
  21994. axis.setExtent(extent[idx], extent[1 - idx]);
  21995. updateAxisTransfrom(axis, isHorizontal ? gridRect.x : gridRect.y);
  21996. });
  21997. }
  21998. };
  21999. /**
  22000. * @param {string} axisType
  22001. * @param {ndumber} [axisIndex]
  22002. */
  22003. gridProto.getAxis = function (axisType, axisIndex) {
  22004. var axesMapOnDim = this._axesMap[axisType];
  22005. if (axesMapOnDim != null) {
  22006. if (axisIndex == null) {
  22007. // Find first axis
  22008. for (var name in axesMapOnDim) {
  22009. if (axesMapOnDim.hasOwnProperty(name)) {
  22010. return axesMapOnDim[name];
  22011. }
  22012. }
  22013. }
  22014. return axesMapOnDim[axisIndex];
  22015. }
  22016. };
  22017. gridProto.getCartesian = function (xAxisIndex, yAxisIndex) {
  22018. if (xAxisIndex != null && yAxisIndex != null) {
  22019. var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
  22020. return this._coordsMap[key];
  22021. }
  22022. else {
  22023. // When only xAxisIndex or yAxisIndex given, find its first cartesian.
  22024. for (var i = 0, coordList = this._coordsList; i < coordList.length; i++) {
  22025. if (coordList[i].getAxis('x').index === xAxisIndex
  22026. || coordList[i].getAxis('y').index === yAxisIndex
  22027. ) {
  22028. return coordList[i];
  22029. }
  22030. }
  22031. }
  22032. };
  22033. /**
  22034. * @implements
  22035. * see {module:echarts/CoodinateSystem}
  22036. */
  22037. gridProto.convertToPixel = function (ecModel, finder, value) {
  22038. var target = this._findConvertTarget(ecModel, finder);
  22039. return target.cartesian
  22040. ? target.cartesian.dataToPoint(value)
  22041. : target.axis
  22042. ? target.axis.toGlobalCoord(target.axis.dataToCoord(value))
  22043. : null;
  22044. };
  22045. /**
  22046. * @implements
  22047. * see {module:echarts/CoodinateSystem}
  22048. */
  22049. gridProto.convertFromPixel = function (ecModel, finder, value) {
  22050. var target = this._findConvertTarget(ecModel, finder);
  22051. return target.cartesian
  22052. ? target.cartesian.pointToData(value)
  22053. : target.axis
  22054. ? target.axis.coordToData(target.axis.toLocalCoord(value))
  22055. : null;
  22056. };
  22057. /**
  22058. * @inner
  22059. */
  22060. gridProto._findConvertTarget = function (ecModel, finder) {
  22061. var seriesModel = finder.seriesModel;
  22062. var xAxisModel = finder.xAxisModel
  22063. || (seriesModel && seriesModel.getReferringComponents('xAxis')[0]);
  22064. var yAxisModel = finder.yAxisModel
  22065. || (seriesModel && seriesModel.getReferringComponents('yAxis')[0]);
  22066. var gridModel = finder.gridModel;
  22067. var coordsList = this._coordsList;
  22068. var cartesian;
  22069. var axis;
  22070. if (seriesModel) {
  22071. cartesian = seriesModel.coordinateSystem;
  22072. zrUtil.indexOf(coordsList, cartesian) < 0 && (cartesian = null);
  22073. }
  22074. else if (xAxisModel && yAxisModel) {
  22075. cartesian = this.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
  22076. }
  22077. else if (xAxisModel) {
  22078. axis = this.getAxis('x', xAxisModel.componentIndex);
  22079. }
  22080. else if (yAxisModel) {
  22081. axis = this.getAxis('y', yAxisModel.componentIndex);
  22082. }
  22083. // Lowest priority.
  22084. else if (gridModel) {
  22085. var grid = gridModel.coordinateSystem;
  22086. if (grid === this) {
  22087. cartesian = this._coordsList[0];
  22088. }
  22089. }
  22090. return {cartesian: cartesian, axis: axis};
  22091. };
  22092. /**
  22093. * @implements
  22094. * see {module:echarts/CoodinateSystem}
  22095. */
  22096. gridProto.containPoint = function (point) {
  22097. var coord = this._coordsList[0];
  22098. if (coord) {
  22099. return coord.containPoint(point);
  22100. }
  22101. };
  22102. /**
  22103. * Initialize cartesian coordinate systems
  22104. * @private
  22105. */
  22106. gridProto._initCartesian = function (gridModel, ecModel, api) {
  22107. var axisPositionUsed = {
  22108. left: false,
  22109. right: false,
  22110. top: false,
  22111. bottom: false
  22112. };
  22113. var axesMap = {
  22114. x: {},
  22115. y: {}
  22116. };
  22117. var axesCount = {
  22118. x: 0,
  22119. y: 0
  22120. };
  22121. /// Create axis
  22122. ecModel.eachComponent('xAxis', createAxisCreator('x'), this);
  22123. ecModel.eachComponent('yAxis', createAxisCreator('y'), this);
  22124. if (!axesCount.x || !axesCount.y) {
  22125. // Roll back when there no either x or y axis
  22126. this._axesMap = {};
  22127. this._axesList = [];
  22128. return;
  22129. }
  22130. this._axesMap = axesMap;
  22131. /// Create cartesian2d
  22132. each(axesMap.x, function (xAxis, xAxisIndex) {
  22133. each(axesMap.y, function (yAxis, yAxisIndex) {
  22134. var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
  22135. var cartesian = new Cartesian2D(key);
  22136. cartesian.grid = this;
  22137. this._coordsMap[key] = cartesian;
  22138. this._coordsList.push(cartesian);
  22139. cartesian.addAxis(xAxis);
  22140. cartesian.addAxis(yAxis);
  22141. }, this);
  22142. }, this);
  22143. function createAxisCreator(axisType) {
  22144. return function (axisModel, idx) {
  22145. if (!isAxisUsedInTheGrid(axisModel, gridModel, ecModel)) {
  22146. return;
  22147. }
  22148. var axisPosition = axisModel.get('position');
  22149. if (axisType === 'x') {
  22150. // Fix position
  22151. if (axisPosition !== 'top' && axisPosition !== 'bottom') {
  22152. // Default bottom of X
  22153. axisPosition = 'bottom';
  22154. if (axisPositionUsed[axisPosition]) {
  22155. axisPosition = axisPosition === 'top' ? 'bottom' : 'top';
  22156. }
  22157. }
  22158. }
  22159. else {
  22160. // Fix position
  22161. if (axisPosition !== 'left' && axisPosition !== 'right') {
  22162. // Default left of Y
  22163. axisPosition = 'left';
  22164. if (axisPositionUsed[axisPosition]) {
  22165. axisPosition = axisPosition === 'left' ? 'right' : 'left';
  22166. }
  22167. }
  22168. }
  22169. axisPositionUsed[axisPosition] = true;
  22170. var axis = new Axis2D(
  22171. axisType, axisHelper.createScaleByModel(axisModel),
  22172. [0, 0],
  22173. axisModel.get('type'),
  22174. axisPosition
  22175. );
  22176. var isCategory = axis.type === 'category';
  22177. axis.onBand = isCategory && axisModel.get('boundaryGap');
  22178. axis.inverse = axisModel.get('inverse');
  22179. axis.onZero = axisModel.get('axisLine.onZero');
  22180. // Inject axis into axisModel
  22181. axisModel.axis = axis;
  22182. // Inject axisModel into axis
  22183. axis.model = axisModel;
  22184. // Inject grid info axis
  22185. axis.grid = this;
  22186. // Index of axis, can be used as key
  22187. axis.index = idx;
  22188. this._axesList.push(axis);
  22189. axesMap[axisType][idx] = axis;
  22190. axesCount[axisType]++;
  22191. };
  22192. }
  22193. };
  22194. /**
  22195. * Update cartesian properties from series
  22196. * @param {module:echarts/model/Option} option
  22197. * @private
  22198. */
  22199. gridProto._updateScale = function (ecModel, gridModel) {
  22200. // Reset scale
  22201. zrUtil.each(this._axesList, function (axis) {
  22202. axis.scale.setExtent(Infinity, -Infinity);
  22203. });
  22204. ecModel.eachSeries(function (seriesModel) {
  22205. if (isCartesian2D(seriesModel)) {
  22206. var axesModels = findAxesModels(seriesModel, ecModel);
  22207. var xAxisModel = axesModels[0];
  22208. var yAxisModel = axesModels[1];
  22209. if (!isAxisUsedInTheGrid(xAxisModel, gridModel, ecModel)
  22210. || !isAxisUsedInTheGrid(yAxisModel, gridModel, ecModel)
  22211. ) {
  22212. return;
  22213. }
  22214. var cartesian = this.getCartesian(
  22215. xAxisModel.componentIndex, yAxisModel.componentIndex
  22216. );
  22217. var data = seriesModel.getData();
  22218. var xAxis = cartesian.getAxis('x');
  22219. var yAxis = cartesian.getAxis('y');
  22220. if (data.type === 'list') {
  22221. unionExtent(data, xAxis, seriesModel);
  22222. unionExtent(data, yAxis, seriesModel);
  22223. }
  22224. }
  22225. }, this);
  22226. function unionExtent(data, axis, seriesModel) {
  22227. each(seriesModel.coordDimToDataDim(axis.dim), function (dim) {
  22228. axis.scale.unionExtentFromData(data, dim);
  22229. });
  22230. }
  22231. };
  22232. /**
  22233. * @inner
  22234. */
  22235. function updateAxisTransfrom(axis, coordBase) {
  22236. var axisExtent = axis.getExtent();
  22237. var axisExtentSum = axisExtent[0] + axisExtent[1];
  22238. // Fast transform
  22239. axis.toGlobalCoord = axis.dim === 'x'
  22240. ? function (coord) {
  22241. return coord + coordBase;
  22242. }
  22243. : function (coord) {
  22244. return axisExtentSum - coord + coordBase;
  22245. };
  22246. axis.toLocalCoord = axis.dim === 'x'
  22247. ? function (coord) {
  22248. return coord - coordBase;
  22249. }
  22250. : function (coord) {
  22251. return axisExtentSum - coord + coordBase;
  22252. };
  22253. }
  22254. var axesTypes = ['xAxis', 'yAxis'];
  22255. /**
  22256. * @inner
  22257. */
  22258. function findAxesModels(seriesModel, ecModel) {
  22259. return zrUtil.map(axesTypes, function (axisType) {
  22260. var axisModel = seriesModel.getReferringComponents(axisType)[0];
  22261. if (true) {
  22262. if (!axisModel) {
  22263. throw new Error(axisType + ' "' + zrUtil.retrieve(
  22264. seriesModel.get(axisType + 'Index'),
  22265. seriesModel.get(axisType + 'Id'),
  22266. 0
  22267. ) + '" not found');
  22268. }
  22269. }
  22270. return axisModel;
  22271. });
  22272. }
  22273. /**
  22274. * @inner
  22275. */
  22276. function isCartesian2D(seriesModel) {
  22277. return seriesModel.get('coordinateSystem') === 'cartesian2d';
  22278. }
  22279. Grid.create = function (ecModel, api) {
  22280. var grids = [];
  22281. ecModel.eachComponent('grid', function (gridModel, idx) {
  22282. var grid = new Grid(gridModel, ecModel, api);
  22283. grid.name = 'grid_' + idx;
  22284. grid.resize(gridModel, api);
  22285. gridModel.coordinateSystem = grid;
  22286. grids.push(grid);
  22287. });
  22288. // Inject the coordinateSystems into seriesModel
  22289. ecModel.eachSeries(function (seriesModel) {
  22290. if (!isCartesian2D(seriesModel)) {
  22291. return;
  22292. }
  22293. var axesModels = findAxesModels(seriesModel, ecModel);
  22294. var xAxisModel = axesModels[0];
  22295. var yAxisModel = axesModels[1];
  22296. var gridModel = xAxisModel.getCoordSysModel();
  22297. if (true) {
  22298. if (!gridModel) {
  22299. throw new Error(
  22300. 'Grid "' + zrUtil.retrieve(
  22301. xAxisModel.get('gridIndex'),
  22302. xAxisModel.get('gridId'),
  22303. 0
  22304. ) + '" not found'
  22305. );
  22306. }
  22307. if (xAxisModel.getCoordSysModel() !== yAxisModel.getCoordSysModel()) {
  22308. throw new Error('xAxis and yAxis must use the same grid');
  22309. }
  22310. }
  22311. var grid = gridModel.coordinateSystem;
  22312. seriesModel.coordinateSystem = grid.getCartesian(
  22313. xAxisModel.componentIndex, yAxisModel.componentIndex
  22314. );
  22315. });
  22316. return grids;
  22317. };
  22318. // For deciding which dimensions to use when creating list data
  22319. Grid.dimensions = Cartesian2D.prototype.dimensions;
  22320. __webpack_require__(26).register('cartesian2d', Grid);
  22321. module.exports = Grid;
  22322. /***/ },
  22323. /* 115 */
  22324. /***/ function(module, exports, __webpack_require__) {
  22325. var OrdinalScale = __webpack_require__(116);
  22326. var IntervalScale = __webpack_require__(118);
  22327. __webpack_require__(119);
  22328. __webpack_require__(120);
  22329. var Scale = __webpack_require__(117);
  22330. var numberUtil = __webpack_require__(7);
  22331. var zrUtil = __webpack_require__(4);
  22332. var textContain = __webpack_require__(8);
  22333. var axisHelper = {};
  22334. /**
  22335. * Get axis scale extent before niced.
  22336. * Item of returned array can only be number (including Infinity and NaN).
  22337. */
  22338. axisHelper.getScaleExtent = function (axis, model) {
  22339. var scale = axis.scale;
  22340. var scaleType = scale.type;
  22341. var min = model.getMin();
  22342. var max = model.getMax();
  22343. var fixMin = min != null;
  22344. var fixMax = max != null;
  22345. var originalExtent = scale.getExtent();
  22346. var axisDataLen;
  22347. var boundaryGap;
  22348. var span;
  22349. if (scaleType === 'ordinal') {
  22350. axisDataLen = (model.get('data') || []).length;
  22351. }
  22352. else {
  22353. boundaryGap = model.get('boundaryGap');
  22354. if (!zrUtil.isArray(boundaryGap)) {
  22355. boundaryGap = [boundaryGap || 0, boundaryGap || 0];
  22356. }
  22357. boundaryGap[0] = numberUtil.parsePercent(boundaryGap[0], 1);
  22358. boundaryGap[1] = numberUtil.parsePercent(boundaryGap[1], 1);
  22359. span = originalExtent[1] - originalExtent[0];
  22360. }
  22361. if (min == null) {
  22362. min = scaleType === 'ordinal'
  22363. ? (axisDataLen ? 0 : NaN)
  22364. : originalExtent[0] - boundaryGap[0] * span;
  22365. }
  22366. if (max == null) {
  22367. max = scaleType === 'ordinal'
  22368. ? (axisDataLen ? axisDataLen - 1 : NaN)
  22369. : originalExtent[1] + boundaryGap[1] * span;
  22370. }
  22371. if (min === 'dataMin') {
  22372. min = originalExtent[0];
  22373. }
  22374. if (max === 'dataMax') {
  22375. max = originalExtent[1];
  22376. }
  22377. (min == null || !isFinite(min)) && (min = NaN);
  22378. (max == null || !isFinite(max)) && (max = NaN);
  22379. axis.setBlank(zrUtil.eqNaN(min) || zrUtil.eqNaN(max));
  22380. // Evaluate if axis needs cross zero
  22381. if (model.getNeedCrossZero()) {
  22382. // Axis is over zero and min is not set
  22383. if (min > 0 && max > 0 && !fixMin) {
  22384. min = 0;
  22385. }
  22386. // Axis is under zero and max is not set
  22387. if (min < 0 && max < 0 && !fixMax) {
  22388. max = 0;
  22389. }
  22390. }
  22391. return [min, max];
  22392. };
  22393. axisHelper.niceScaleExtent = function (axis, model) {
  22394. var scale = axis.scale;
  22395. var extent = axisHelper.getScaleExtent(axis, model);
  22396. var fixMin = model.getMin() != null;
  22397. var fixMax = model.getMax() != null;
  22398. var splitNumber = model.get('splitNumber');
  22399. if (scale.type === 'log') {
  22400. scale.base = model.get('logBase');
  22401. }
  22402. scale.setExtent(extent[0], extent[1]);
  22403. scale.niceExtent(splitNumber, fixMin, fixMax);
  22404. // Use minInterval to constraint the calculated interval.
  22405. // If calculated interval is less than minInterval. increase the interval quantity until
  22406. // it is larger than minInterval.
  22407. // For example:
  22408. // minInterval is 1, calculated interval is 0.2, so increase it to be 1. In this way we can get
  22409. // an integer axis.
  22410. var minInterval = model.get('minInterval');
  22411. if (isFinite(minInterval) && !fixMin && !fixMax && scale.type === 'interval') {
  22412. var interval = scale.getInterval();
  22413. var intervalScale = Math.max(Math.abs(interval), minInterval) / interval;
  22414. // while (interval < minInterval) {
  22415. // var quantity = numberUtil.quantity(interval);
  22416. // interval = quantity * 10;
  22417. // scaleQuantity *= 10;
  22418. // }
  22419. extent = scale.getExtent();
  22420. var origin = (extent[1] + extent[0]) / 2;
  22421. scale.setExtent(
  22422. intervalScale * (extent[0] - origin) + origin,
  22423. intervalScale * (extent[1] - origin) + origin
  22424. );
  22425. scale.niceExtent(splitNumber);
  22426. }
  22427. // If some one specified the min, max. And the default calculated interval
  22428. // is not good enough. He can specify the interval. It is often appeared
  22429. // in angle axis with angle 0 - 360. Interval calculated in interval scale is hard
  22430. // to be 60.
  22431. // FIXME
  22432. var interval = model.get('interval');
  22433. if (interval != null) {
  22434. scale.setInterval && scale.setInterval(interval);
  22435. }
  22436. };
  22437. /**
  22438. * @param {module:echarts/model/Model} model
  22439. * @param {string} [axisType] Default retrieve from model.type
  22440. * @return {module:echarts/scale/*}
  22441. */
  22442. axisHelper.createScaleByModel = function(model, axisType) {
  22443. axisType = axisType || model.get('type');
  22444. if (axisType) {
  22445. switch (axisType) {
  22446. // Buildin scale
  22447. case 'category':
  22448. return new OrdinalScale(
  22449. model.getCategories(), [Infinity, -Infinity]
  22450. );
  22451. case 'value':
  22452. return new IntervalScale();
  22453. // Extended scale, like time and log
  22454. default:
  22455. return (Scale.getClass(axisType) || IntervalScale).create(model);
  22456. }
  22457. }
  22458. };
  22459. /**
  22460. * Check if the axis corss 0
  22461. */
  22462. axisHelper.ifAxisCrossZero = function (axis) {
  22463. var dataExtent = axis.scale.getExtent();
  22464. var min = dataExtent[0];
  22465. var max = dataExtent[1];
  22466. return !((min > 0 && max > 0) || (min < 0 && max < 0));
  22467. };
  22468. /**
  22469. * @param {Array.<number>} tickCoords In axis self coordinate.
  22470. * @param {Array.<string>} labels
  22471. * @param {string} font
  22472. * @param {boolean} isAxisHorizontal
  22473. * @return {number}
  22474. */
  22475. axisHelper.getAxisLabelInterval = function (tickCoords, labels, font, isAxisHorizontal) {
  22476. // FIXME
  22477. // 不同角的axis和label,不只是horizontal和vertical.
  22478. var textSpaceTakenRect;
  22479. var autoLabelInterval = 0;
  22480. var accumulatedLabelInterval = 0;
  22481. var step = 1;
  22482. if (labels.length > 40) {
  22483. // Simple optimization for large amount of labels
  22484. step = Math.floor(labels.length / 40);
  22485. }
  22486. for (var i = 0; i < tickCoords.length; i += step) {
  22487. var tickCoord = tickCoords[i];
  22488. var rect = textContain.getBoundingRect(
  22489. labels[i], font, 'center', 'top'
  22490. );
  22491. rect[isAxisHorizontal ? 'x' : 'y'] += tickCoord;
  22492. // FIXME Magic number 1.5
  22493. rect[isAxisHorizontal ? 'width' : 'height'] *= 1.3;
  22494. if (!textSpaceTakenRect) {
  22495. textSpaceTakenRect = rect.clone();
  22496. }
  22497. // There is no space for current label;
  22498. else if (textSpaceTakenRect.intersect(rect)) {
  22499. accumulatedLabelInterval++;
  22500. autoLabelInterval = Math.max(autoLabelInterval, accumulatedLabelInterval);
  22501. }
  22502. else {
  22503. textSpaceTakenRect.union(rect);
  22504. // Reset
  22505. accumulatedLabelInterval = 0;
  22506. }
  22507. }
  22508. if (autoLabelInterval === 0 && step > 1) {
  22509. return step;
  22510. }
  22511. return (autoLabelInterval + 1) * step - 1;
  22512. };
  22513. /**
  22514. * @param {Object} axis
  22515. * @param {Function} labelFormatter
  22516. * @return {Array.<string>}
  22517. */
  22518. axisHelper.getFormattedLabels = function (axis, labelFormatter) {
  22519. var scale = axis.scale;
  22520. var labels = scale.getTicksLabels();
  22521. var ticks = scale.getTicks();
  22522. if (typeof labelFormatter === 'string') {
  22523. labelFormatter = (function (tpl) {
  22524. return function (val) {
  22525. return tpl.replace('{value}', val != null ? val : '');
  22526. };
  22527. })(labelFormatter);
  22528. // Consider empty array
  22529. return zrUtil.map(labels, labelFormatter);
  22530. }
  22531. else if (typeof labelFormatter === 'function') {
  22532. return zrUtil.map(ticks, function (tick, idx) {
  22533. return labelFormatter(
  22534. axis.type === 'category' ? scale.getLabel(tick) : tick,
  22535. idx
  22536. );
  22537. }, this);
  22538. }
  22539. else {
  22540. return labels;
  22541. }
  22542. };
  22543. module.exports = axisHelper;
  22544. /***/ },
  22545. /* 116 */
  22546. /***/ function(module, exports, __webpack_require__) {
  22547. /**
  22548. * Linear continuous scale
  22549. * @module echarts/coord/scale/Ordinal
  22550. *
  22551. * http://en.wikipedia.org/wiki/Level_of_measurement
  22552. */
  22553. // FIXME only one data
  22554. var zrUtil = __webpack_require__(4);
  22555. var Scale = __webpack_require__(117);
  22556. var scaleProto = Scale.prototype;
  22557. var OrdinalScale = Scale.extend({
  22558. type: 'ordinal',
  22559. init: function (data, extent) {
  22560. this._data = data;
  22561. this._extent = extent || [0, data.length - 1];
  22562. },
  22563. parse: function (val) {
  22564. return typeof val === 'string'
  22565. ? zrUtil.indexOf(this._data, val)
  22566. // val might be float.
  22567. : Math.round(val);
  22568. },
  22569. contain: function (rank) {
  22570. rank = this.parse(rank);
  22571. return scaleProto.contain.call(this, rank)
  22572. && this._data[rank] != null;
  22573. },
  22574. /**
  22575. * Normalize given rank or name to linear [0, 1]
  22576. * @param {number|string} [val]
  22577. * @return {number}
  22578. */
  22579. normalize: function (val) {
  22580. return scaleProto.normalize.call(this, this.parse(val));
  22581. },
  22582. scale: function (val) {
  22583. return Math.round(scaleProto.scale.call(this, val));
  22584. },
  22585. /**
  22586. * @return {Array}
  22587. */
  22588. getTicks: function () {
  22589. var ticks = [];
  22590. var extent = this._extent;
  22591. var rank = extent[0];
  22592. while (rank <= extent[1]) {
  22593. ticks.push(rank);
  22594. rank++;
  22595. }
  22596. return ticks;
  22597. },
  22598. /**
  22599. * Get item on rank n
  22600. * @param {number} n
  22601. * @return {string}
  22602. */
  22603. getLabel: function (n) {
  22604. return this._data[n];
  22605. },
  22606. /**
  22607. * @return {number}
  22608. */
  22609. count: function () {
  22610. return this._extent[1] - this._extent[0] + 1;
  22611. },
  22612. /**
  22613. * @override
  22614. */
  22615. unionExtentFromData: function (data, dim) {
  22616. this.unionExtent(data.getDataExtent(dim, false));
  22617. },
  22618. niceTicks: zrUtil.noop,
  22619. niceExtent: zrUtil.noop
  22620. });
  22621. /**
  22622. * @return {module:echarts/scale/Time}
  22623. */
  22624. OrdinalScale.create = function () {
  22625. return new OrdinalScale();
  22626. };
  22627. module.exports = OrdinalScale;
  22628. /***/ },
  22629. /* 117 */
  22630. /***/ function(module, exports, __webpack_require__) {
  22631. /**
  22632. * // Scale class management
  22633. * @module echarts/scale/Scale
  22634. */
  22635. var clazzUtil = __webpack_require__(13);
  22636. function Scale() {
  22637. /**
  22638. * Extent
  22639. * @type {Array.<number>}
  22640. * @protected
  22641. */
  22642. this._extent = [Infinity, -Infinity];
  22643. /**
  22644. * Step is calculated in adjustExtent
  22645. * @type {Array.<number>}
  22646. * @protected
  22647. */
  22648. this._interval = 0;
  22649. this.init && this.init.apply(this, arguments);
  22650. }
  22651. var scaleProto = Scale.prototype;
  22652. /**
  22653. * Parse input val to valid inner number.
  22654. * @param {*} val
  22655. * @return {number}
  22656. */
  22657. scaleProto.parse = function (val) {
  22658. // Notice: This would be a trap here, If the implementation
  22659. // of this method depends on extent, and this method is used
  22660. // before extent set (like in dataZoom), it would be wrong.
  22661. // Nevertheless, parse does not depend on extent generally.
  22662. return val;
  22663. };
  22664. scaleProto.contain = function (val) {
  22665. var extent = this._extent;
  22666. return val >= extent[0] && val <= extent[1];
  22667. };
  22668. /**
  22669. * Normalize value to linear [0, 1], return 0.5 if extent span is 0
  22670. * @param {number} val
  22671. * @return {number}
  22672. */
  22673. scaleProto.normalize = function (val) {
  22674. var extent = this._extent;
  22675. if (extent[1] === extent[0]) {
  22676. return 0.5;
  22677. }
  22678. return (val - extent[0]) / (extent[1] - extent[0]);
  22679. };
  22680. /**
  22681. * Scale normalized value
  22682. * @param {number} val
  22683. * @return {number}
  22684. */
  22685. scaleProto.scale = function (val) {
  22686. var extent = this._extent;
  22687. return val * (extent[1] - extent[0]) + extent[0];
  22688. };
  22689. /**
  22690. * Set extent from data
  22691. * @param {Array.<number>} other
  22692. */
  22693. scaleProto.unionExtent = function (other) {
  22694. var extent = this._extent;
  22695. other[0] < extent[0] && (extent[0] = other[0]);
  22696. other[1] > extent[1] && (extent[1] = other[1]);
  22697. // not setExtent because in log axis it may transformed to power
  22698. // this.setExtent(extent[0], extent[1]);
  22699. };
  22700. /**
  22701. * Set extent from data
  22702. * @param {module:echarts/data/List} data
  22703. * @param {string} dim
  22704. */
  22705. scaleProto.unionExtentFromData = function (data, dim) {
  22706. this.unionExtent(data.getDataExtent(dim, true));
  22707. };
  22708. /**
  22709. * Get extent
  22710. * @return {Array.<number>}
  22711. */
  22712. scaleProto.getExtent = function () {
  22713. return this._extent.slice();
  22714. };
  22715. /**
  22716. * Set extent
  22717. * @param {number} start
  22718. * @param {number} end
  22719. */
  22720. scaleProto.setExtent = function (start, end) {
  22721. var thisExtent = this._extent;
  22722. if (!isNaN(start)) {
  22723. thisExtent[0] = start;
  22724. }
  22725. if (!isNaN(end)) {
  22726. thisExtent[1] = end;
  22727. }
  22728. };
  22729. /**
  22730. * @return {Array.<string>}
  22731. */
  22732. scaleProto.getTicksLabels = function () {
  22733. var labels = [];
  22734. var ticks = this.getTicks();
  22735. for (var i = 0; i < ticks.length; i++) {
  22736. labels.push(this.getLabel(ticks[i]));
  22737. }
  22738. return labels;
  22739. };
  22740. clazzUtil.enableClassExtend(Scale);
  22741. clazzUtil.enableClassManagement(Scale, {
  22742. registerWhenExtend: true
  22743. });
  22744. module.exports = Scale;
  22745. /***/ },
  22746. /* 118 */
  22747. /***/ function(module, exports, __webpack_require__) {
  22748. /**
  22749. * Interval scale
  22750. * @module echarts/scale/Interval
  22751. */
  22752. var numberUtil = __webpack_require__(7);
  22753. var formatUtil = __webpack_require__(6);
  22754. var Scale = __webpack_require__(117);
  22755. var mathFloor = Math.floor;
  22756. var mathCeil = Math.ceil;
  22757. var getPrecisionSafe = numberUtil.getPrecisionSafe;
  22758. var roundingErrorFix = numberUtil.round;
  22759. /**
  22760. * @alias module:echarts/coord/scale/Interval
  22761. * @constructor
  22762. */
  22763. var IntervalScale = Scale.extend({
  22764. type: 'interval',
  22765. _interval: 0,
  22766. setExtent: function (start, end) {
  22767. var thisExtent = this._extent;
  22768. //start,end may be a Number like '25',so...
  22769. if (!isNaN(start)) {
  22770. thisExtent[0] = parseFloat(start);
  22771. }
  22772. if (!isNaN(end)) {
  22773. thisExtent[1] = parseFloat(end);
  22774. }
  22775. },
  22776. unionExtent: function (other) {
  22777. var extent = this._extent;
  22778. other[0] < extent[0] && (extent[0] = other[0]);
  22779. other[1] > extent[1] && (extent[1] = other[1]);
  22780. // unionExtent may called by it's sub classes
  22781. IntervalScale.prototype.setExtent.call(this, extent[0], extent[1]);
  22782. },
  22783. /**
  22784. * Get interval
  22785. */
  22786. getInterval: function () {
  22787. if (!this._interval) {
  22788. this.niceTicks();
  22789. }
  22790. return this._interval;
  22791. },
  22792. /**
  22793. * Set interval
  22794. */
  22795. setInterval: function (interval) {
  22796. this._interval = interval;
  22797. // Dropped auto calculated niceExtent and use user setted extent
  22798. // We assume user wan't to set both interval, min, max to get a better result
  22799. this._niceExtent = this._extent.slice();
  22800. },
  22801. /**
  22802. * @return {Array.<number>}
  22803. */
  22804. getTicks: function () {
  22805. if (!this._interval) {
  22806. this.niceTicks();
  22807. }
  22808. var interval = this._interval;
  22809. var extent = this._extent;
  22810. var ticks = [];
  22811. // Consider this case: using dataZoom toolbox, zoom and zoom.
  22812. var safeLimit = 10000;
  22813. if (interval) {
  22814. var niceExtent = this._niceExtent;
  22815. var precision = getPrecisionSafe(interval) + 2;
  22816. if (extent[0] < niceExtent[0]) {
  22817. ticks.push(extent[0]);
  22818. }
  22819. var tick = niceExtent[0];
  22820. while (tick <= niceExtent[1]) {
  22821. ticks.push(tick);
  22822. // Avoid rounding error
  22823. tick = roundingErrorFix(tick + interval, precision);
  22824. if (ticks.length > safeLimit) {
  22825. return [];
  22826. }
  22827. }
  22828. // Consider this case: the last item of ticks is smaller
  22829. // than niceExtent[1] and niceExtent[1] === extent[1].
  22830. if (extent[1] > (ticks.length ? ticks[ticks.length - 1] : niceExtent[1])) {
  22831. ticks.push(extent[1]);
  22832. }
  22833. }
  22834. return ticks;
  22835. },
  22836. /**
  22837. * @return {Array.<string>}
  22838. */
  22839. getTicksLabels: function () {
  22840. var labels = [];
  22841. var ticks = this.getTicks();
  22842. for (var i = 0; i < ticks.length; i++) {
  22843. labels.push(this.getLabel(ticks[i]));
  22844. }
  22845. return labels;
  22846. },
  22847. /**
  22848. * @param {number} n
  22849. * @return {number}
  22850. */
  22851. getLabel: function (data) {
  22852. return formatUtil.addCommas(data);
  22853. },
  22854. /**
  22855. * Update interval and extent of intervals for nice ticks
  22856. *
  22857. * @param {number} [splitNumber = 5] Desired number of ticks
  22858. */
  22859. niceTicks: function (splitNumber) {
  22860. splitNumber = splitNumber || 5;
  22861. var extent = this._extent;
  22862. var span = extent[1] - extent[0];
  22863. if (!isFinite(span)) {
  22864. return;
  22865. }
  22866. // User may set axis min 0 and data are all negative
  22867. // FIXME If it needs to reverse ?
  22868. if (span < 0) {
  22869. span = -span;
  22870. extent.reverse();
  22871. }
  22872. // From "Nice Numbers for Graph Labels" of Graphic Gems
  22873. // var niceSpan = numberUtil.nice(span, false);
  22874. var step = roundingErrorFix(
  22875. numberUtil.nice(span / splitNumber, true),
  22876. Math.max(
  22877. getPrecisionSafe(extent[0]),
  22878. getPrecisionSafe(extent[1])
  22879. // extent may be [0, 1], and step should have 1 more digits.
  22880. // To make it safe we add 2 more digits
  22881. ) + 2
  22882. );
  22883. var precision = getPrecisionSafe(step) + 2;
  22884. // Niced extent inside original extent
  22885. var niceExtent = [
  22886. roundingErrorFix(mathCeil(extent[0] / step) * step, precision),
  22887. roundingErrorFix(mathFloor(extent[1] / step) * step, precision)
  22888. ];
  22889. this._interval = step;
  22890. this._niceExtent = niceExtent;
  22891. },
  22892. /**
  22893. * Nice extent.
  22894. * @param {number} [splitNumber = 5] Given approx tick number
  22895. * @param {boolean} [fixMin=false]
  22896. * @param {boolean} [fixMax=false]
  22897. */
  22898. niceExtent: function (splitNumber, fixMin, fixMax) {
  22899. var extent = this._extent;
  22900. // If extent start and end are same, expand them
  22901. if (extent[0] === extent[1]) {
  22902. if (extent[0] !== 0) {
  22903. // Expand extent
  22904. var expandSize = extent[0];
  22905. // In the fowllowing case
  22906. // Axis has been fixed max 100
  22907. // Plus data are all 100 and axis extent are [100, 100].
  22908. // Extend to the both side will cause expanded max is larger than fixed max.
  22909. // So only expand to the smaller side.
  22910. if (!fixMax) {
  22911. extent[1] += expandSize / 2;
  22912. extent[0] -= expandSize / 2;
  22913. }
  22914. else {
  22915. extent[0] -= expandSize / 2;
  22916. }
  22917. }
  22918. else {
  22919. extent[1] = 1;
  22920. }
  22921. }
  22922. var span = extent[1] - extent[0];
  22923. // If there are no data and extent are [Infinity, -Infinity]
  22924. if (!isFinite(span)) {
  22925. extent[0] = 0;
  22926. extent[1] = 1;
  22927. }
  22928. this.niceTicks(splitNumber);
  22929. // var extent = this._extent;
  22930. var interval = this._interval;
  22931. if (!fixMin) {
  22932. extent[0] = roundingErrorFix(mathFloor(extent[0] / interval) * interval);
  22933. }
  22934. if (!fixMax) {
  22935. extent[1] = roundingErrorFix(mathCeil(extent[1] / interval) * interval);
  22936. }
  22937. }
  22938. });
  22939. /**
  22940. * @return {module:echarts/scale/Time}
  22941. */
  22942. IntervalScale.create = function () {
  22943. return new IntervalScale();
  22944. };
  22945. module.exports = IntervalScale;
  22946. /***/ },
  22947. /* 119 */
  22948. /***/ function(module, exports, __webpack_require__) {
  22949. /**
  22950. * Interval scale
  22951. * @module echarts/coord/scale/Time
  22952. */
  22953. var zrUtil = __webpack_require__(4);
  22954. var numberUtil = __webpack_require__(7);
  22955. var formatUtil = __webpack_require__(6);
  22956. var IntervalScale = __webpack_require__(118);
  22957. var intervalScaleProto = IntervalScale.prototype;
  22958. var mathCeil = Math.ceil;
  22959. var mathFloor = Math.floor;
  22960. var ONE_SECOND = 1000;
  22961. var ONE_MINUTE = ONE_SECOND * 60;
  22962. var ONE_HOUR = ONE_MINUTE * 60;
  22963. var ONE_DAY = ONE_HOUR * 24;
  22964. // FIXME 公用?
  22965. var bisect = function (a, x, lo, hi) {
  22966. while (lo < hi) {
  22967. var mid = lo + hi >>> 1;
  22968. if (a[mid][2] < x) {
  22969. lo = mid + 1;
  22970. }
  22971. else {
  22972. hi = mid;
  22973. }
  22974. }
  22975. return lo;
  22976. };
  22977. /**
  22978. * @alias module:echarts/coord/scale/Time
  22979. * @constructor
  22980. */
  22981. var TimeScale = IntervalScale.extend({
  22982. type: 'time',
  22983. // Overwrite
  22984. getLabel: function (val) {
  22985. var stepLvl = this._stepLvl;
  22986. var date = new Date(val);
  22987. return formatUtil.formatTime(stepLvl[0], date);
  22988. },
  22989. // Overwrite
  22990. niceExtent: function (approxTickNum, fixMin, fixMax) {
  22991. var extent = this._extent;
  22992. // If extent start and end are same, expand them
  22993. if (extent[0] === extent[1]) {
  22994. // Expand extent
  22995. extent[0] -= ONE_DAY;
  22996. extent[1] += ONE_DAY;
  22997. }
  22998. // If there are no data and extent are [Infinity, -Infinity]
  22999. if (extent[1] === -Infinity && extent[0] === Infinity) {
  23000. var d = new Date();
  23001. extent[1] = new Date(d.getFullYear(), d.getMonth(), d.getDate());
  23002. extent[0] = extent[1] - ONE_DAY;
  23003. }
  23004. this.niceTicks(approxTickNum);
  23005. // var extent = this._extent;
  23006. var interval = this._interval;
  23007. if (!fixMin) {
  23008. extent[0] = numberUtil.round(mathFloor(extent[0] / interval) * interval);
  23009. }
  23010. if (!fixMax) {
  23011. extent[1] = numberUtil.round(mathCeil(extent[1] / interval) * interval);
  23012. }
  23013. },
  23014. // Overwrite
  23015. niceTicks: function (approxTickNum) {
  23016. approxTickNum = approxTickNum || 10;
  23017. var extent = this._extent;
  23018. var span = extent[1] - extent[0];
  23019. var approxInterval = span / approxTickNum;
  23020. var scaleLevelsLen = scaleLevels.length;
  23021. var idx = bisect(scaleLevels, approxInterval, 0, scaleLevelsLen);
  23022. var level = scaleLevels[Math.min(idx, scaleLevelsLen - 1)];
  23023. var interval = level[2];
  23024. // Same with interval scale if span is much larger than 1 year
  23025. if (level[0] === 'year') {
  23026. var yearSpan = span / interval;
  23027. // From "Nice Numbers for Graph Labels" of Graphic Gems
  23028. // var niceYearSpan = numberUtil.nice(yearSpan, false);
  23029. var yearStep = numberUtil.nice(yearSpan / approxTickNum, true);
  23030. interval *= yearStep;
  23031. }
  23032. var niceExtent = [
  23033. mathCeil(extent[0] / interval) * interval,
  23034. mathFloor(extent[1] / interval) * interval
  23035. ];
  23036. this._stepLvl = level;
  23037. // Interval will be used in getTicks
  23038. this._interval = interval;
  23039. this._niceExtent = niceExtent;
  23040. },
  23041. parse: function (val) {
  23042. // val might be float.
  23043. return +numberUtil.parseDate(val);
  23044. }
  23045. });
  23046. zrUtil.each(['contain', 'normalize'], function (methodName) {
  23047. TimeScale.prototype[methodName] = function (val) {
  23048. return intervalScaleProto[methodName].call(this, this.parse(val));
  23049. };
  23050. });
  23051. // Steps from d3
  23052. var scaleLevels = [
  23053. // Format step interval
  23054. ['hh:mm:ss', 1, ONE_SECOND], // 1s
  23055. ['hh:mm:ss', 5, ONE_SECOND * 5], // 5s
  23056. ['hh:mm:ss', 10, ONE_SECOND * 10], // 10s
  23057. ['hh:mm:ss', 15, ONE_SECOND * 15], // 15s
  23058. ['hh:mm:ss', 30, ONE_SECOND * 30], // 30s
  23059. ['hh:mm\nMM-dd',1, ONE_MINUTE], // 1m
  23060. ['hh:mm\nMM-dd',5, ONE_MINUTE * 5], // 5m
  23061. ['hh:mm\nMM-dd',10, ONE_MINUTE * 10], // 10m
  23062. ['hh:mm\nMM-dd',15, ONE_MINUTE * 15], // 15m
  23063. ['hh:mm\nMM-dd',30, ONE_MINUTE * 30], // 30m
  23064. ['hh:mm\nMM-dd',1, ONE_HOUR], // 1h
  23065. ['hh:mm\nMM-dd',2, ONE_HOUR * 2], // 2h
  23066. ['hh:mm\nMM-dd',6, ONE_HOUR * 6], // 6h
  23067. ['hh:mm\nMM-dd',12, ONE_HOUR * 12], // 12h
  23068. ['MM-dd\nyyyy', 1, ONE_DAY], // 1d
  23069. ['week', 7, ONE_DAY * 7], // 7d
  23070. ['month', 1, ONE_DAY * 31], // 1M
  23071. ['quarter', 3, ONE_DAY * 380 / 4], // 3M
  23072. ['half-year', 6, ONE_DAY * 380 / 2], // 6M
  23073. ['year', 1, ONE_DAY * 380] // 1Y
  23074. ];
  23075. /**
  23076. * @return {module:echarts/scale/Time}
  23077. */
  23078. TimeScale.create = function () {
  23079. return new TimeScale();
  23080. };
  23081. module.exports = TimeScale;
  23082. /***/ },
  23083. /* 120 */
  23084. /***/ function(module, exports, __webpack_require__) {
  23085. /**
  23086. * Log scale
  23087. * @module echarts/scale/Log
  23088. */
  23089. var zrUtil = __webpack_require__(4);
  23090. var Scale = __webpack_require__(117);
  23091. var numberUtil = __webpack_require__(7);
  23092. // Use some method of IntervalScale
  23093. var IntervalScale = __webpack_require__(118);
  23094. var scaleProto = Scale.prototype;
  23095. var intervalScaleProto = IntervalScale.prototype;
  23096. var getPrecisionSafe = numberUtil.getPrecisionSafe;
  23097. var roundingErrorFix = numberUtil.round;
  23098. var mathFloor = Math.floor;
  23099. var mathCeil = Math.ceil;
  23100. var mathPow = Math.pow;
  23101. var mathLog = Math.log;
  23102. var LogScale = Scale.extend({
  23103. type: 'log',
  23104. base: 10,
  23105. $constructor: function () {
  23106. Scale.apply(this, arguments);
  23107. this._originalScale = new IntervalScale();
  23108. },
  23109. /**
  23110. * @return {Array.<number>}
  23111. */
  23112. getTicks: function () {
  23113. var originalScale = this._originalScale;
  23114. var extent = this._extent;
  23115. var originalExtent = originalScale.getExtent();
  23116. return zrUtil.map(intervalScaleProto.getTicks.call(this), function (val) {
  23117. var powVal = numberUtil.round(mathPow(this.base, val));
  23118. // Fix #4158
  23119. powVal = (val === extent[0] && originalScale.__fixMin)
  23120. ? fixRoundingError(powVal, originalExtent[0])
  23121. : powVal;
  23122. powVal = (val === extent[1] && originalScale.__fixMax)
  23123. ? fixRoundingError(powVal, originalExtent[1])
  23124. : powVal;
  23125. return powVal;
  23126. }, this);
  23127. },
  23128. /**
  23129. * @param {number} val
  23130. * @return {string}
  23131. */
  23132. getLabel: intervalScaleProto.getLabel,
  23133. /**
  23134. * @param {number} val
  23135. * @return {number}
  23136. */
  23137. scale: function (val) {
  23138. val = scaleProto.scale.call(this, val);
  23139. return mathPow(this.base, val);
  23140. },
  23141. /**
  23142. * @param {number} start
  23143. * @param {number} end
  23144. */
  23145. setExtent: function (start, end) {
  23146. var base = this.base;
  23147. start = mathLog(start) / mathLog(base);
  23148. end = mathLog(end) / mathLog(base);
  23149. intervalScaleProto.setExtent.call(this, start, end);
  23150. },
  23151. /**
  23152. * @return {number} end
  23153. */
  23154. getExtent: function () {
  23155. var base = this.base;
  23156. var extent = scaleProto.getExtent.call(this);
  23157. extent[0] = mathPow(base, extent[0]);
  23158. extent[1] = mathPow(base, extent[1]);
  23159. // Fix #4158
  23160. var originalScale = this._originalScale;
  23161. var originalExtent = originalScale.getExtent();
  23162. originalScale.__fixMin && (extent[0] = fixRoundingError(extent[0], originalExtent[0]));
  23163. originalScale.__fixMax && (extent[1] = fixRoundingError(extent[1], originalExtent[1]));
  23164. return extent;
  23165. },
  23166. /**
  23167. * @param {Array.<number>} extent
  23168. */
  23169. unionExtent: function (extent) {
  23170. this._originalScale.unionExtent(extent);
  23171. var base = this.base;
  23172. extent[0] = mathLog(extent[0]) / mathLog(base);
  23173. extent[1] = mathLog(extent[1]) / mathLog(base);
  23174. scaleProto.unionExtent.call(this, extent);
  23175. },
  23176. /**
  23177. * @override
  23178. */
  23179. unionExtentFromData: function (data, dim) {
  23180. this.unionExtent(data.getDataExtent(dim, true, function (val) {
  23181. return val > 0;
  23182. }));
  23183. },
  23184. /**
  23185. * Update interval and extent of intervals for nice ticks
  23186. * @param {number} [approxTickNum = 10] Given approx tick number
  23187. */
  23188. niceTicks: function (approxTickNum) {
  23189. approxTickNum = approxTickNum || 10;
  23190. var extent = this._extent;
  23191. var span = extent[1] - extent[0];
  23192. if (span === Infinity || span <= 0) {
  23193. return;
  23194. }
  23195. var interval = numberUtil.quantity(span);
  23196. var err = approxTickNum / span * interval;
  23197. // Filter ticks to get closer to the desired count.
  23198. if (err <= 0.5) {
  23199. interval *= 10;
  23200. }
  23201. // Interval should be integer
  23202. while (!isNaN(interval) && Math.abs(interval) < 1 && Math.abs(interval) > 0) {
  23203. interval *= 10;
  23204. }
  23205. var niceExtent = [
  23206. numberUtil.round(mathCeil(extent[0] / interval) * interval),
  23207. numberUtil.round(mathFloor(extent[1] / interval) * interval)
  23208. ];
  23209. this._interval = interval;
  23210. this._niceExtent = niceExtent;
  23211. },
  23212. /**
  23213. * Nice extent.
  23214. * @param {number} [approxTickNum = 10] Given approx tick number
  23215. * @param {boolean} [fixMin=false]
  23216. * @param {boolean} [fixMax=false]
  23217. */
  23218. niceExtent: function (splitNumber, fixMin, fixMax) {
  23219. intervalScaleProto.niceExtent.call(this, splitNumber, fixMin, fixMax);
  23220. var originalScale = this._originalScale;
  23221. originalScale.__fixMin = fixMin;
  23222. originalScale.__fixMax = fixMax;
  23223. }
  23224. });
  23225. zrUtil.each(['contain', 'normalize'], function (methodName) {
  23226. LogScale.prototype[methodName] = function (val) {
  23227. val = mathLog(val) / mathLog(this.base);
  23228. return scaleProto[methodName].call(this, val);
  23229. };
  23230. });
  23231. LogScale.create = function () {
  23232. return new LogScale();
  23233. };
  23234. function fixRoundingError(val, originalVal) {
  23235. return roundingErrorFix(val, getPrecisionSafe(originalVal));
  23236. }
  23237. module.exports = LogScale;
  23238. /***/ },
  23239. /* 121 */
  23240. /***/ function(module, exports, __webpack_require__) {
  23241. 'use strict';
  23242. var zrUtil = __webpack_require__(4);
  23243. var Cartesian = __webpack_require__(122);
  23244. function Cartesian2D(name) {
  23245. Cartesian.call(this, name);
  23246. }
  23247. Cartesian2D.prototype = {
  23248. constructor: Cartesian2D,
  23249. type: 'cartesian2d',
  23250. /**
  23251. * @type {Array.<string>}
  23252. * @readOnly
  23253. */
  23254. dimensions: ['x', 'y'],
  23255. /**
  23256. * Base axis will be used on stacking.
  23257. *
  23258. * @return {module:echarts/coord/cartesian/Axis2D}
  23259. */
  23260. getBaseAxis: function () {
  23261. return this.getAxesByScale('ordinal')[0]
  23262. || this.getAxesByScale('time')[0]
  23263. || this.getAxis('x');
  23264. },
  23265. /**
  23266. * If contain point
  23267. * @param {Array.<number>} point
  23268. * @return {boolean}
  23269. */
  23270. containPoint: function (point) {
  23271. var axisX = this.getAxis('x');
  23272. var axisY = this.getAxis('y');
  23273. return axisX.contain(axisX.toLocalCoord(point[0]))
  23274. && axisY.contain(axisY.toLocalCoord(point[1]));
  23275. },
  23276. /**
  23277. * If contain data
  23278. * @param {Array.<number>} data
  23279. * @return {boolean}
  23280. */
  23281. containData: function (data) {
  23282. return this.getAxis('x').containData(data[0])
  23283. && this.getAxis('y').containData(data[1]);
  23284. },
  23285. /**
  23286. * Convert series data to an array of points
  23287. * @param {module:echarts/data/List} data
  23288. * @param {boolean} stack
  23289. * @return {Array}
  23290. * Return array of points. For example:
  23291. * `[[10, 10], [20, 20], [30, 30]]`
  23292. */
  23293. dataToPoints: function (data, stack) {
  23294. return data.mapArray(['x', 'y'], function (x, y) {
  23295. return this.dataToPoint([x, y]);
  23296. }, stack, this);
  23297. },
  23298. /**
  23299. * @param {Array.<number>} data
  23300. * @param {boolean} [clamp=false]
  23301. * @return {Array.<number>}
  23302. */
  23303. dataToPoint: function (data, clamp) {
  23304. var xAxis = this.getAxis('x');
  23305. var yAxis = this.getAxis('y');
  23306. return [
  23307. xAxis.toGlobalCoord(xAxis.dataToCoord(data[0], clamp)),
  23308. yAxis.toGlobalCoord(yAxis.dataToCoord(data[1], clamp))
  23309. ];
  23310. },
  23311. /**
  23312. * @param {Array.<number>} point
  23313. * @param {boolean} [clamp=false]
  23314. * @return {Array.<number>}
  23315. */
  23316. pointToData: function (point, clamp) {
  23317. var xAxis = this.getAxis('x');
  23318. var yAxis = this.getAxis('y');
  23319. return [
  23320. xAxis.coordToData(xAxis.toLocalCoord(point[0]), clamp),
  23321. yAxis.coordToData(yAxis.toLocalCoord(point[1]), clamp)
  23322. ];
  23323. },
  23324. /**
  23325. * Get other axis
  23326. * @param {module:echarts/coord/cartesian/Axis2D} axis
  23327. */
  23328. getOtherAxis: function (axis) {
  23329. return this.getAxis(axis.dim === 'x' ? 'y' : 'x');
  23330. }
  23331. };
  23332. zrUtil.inherits(Cartesian2D, Cartesian);
  23333. module.exports = Cartesian2D;
  23334. /***/ },
  23335. /* 122 */
  23336. /***/ function(module, exports, __webpack_require__) {
  23337. 'use strict';
  23338. /**
  23339. * Cartesian coordinate system
  23340. * @module echarts/coord/Cartesian
  23341. *
  23342. */
  23343. var zrUtil = __webpack_require__(4);
  23344. function dimAxisMapper(dim) {
  23345. return this._axes[dim];
  23346. }
  23347. /**
  23348. * @alias module:echarts/coord/Cartesian
  23349. * @constructor
  23350. */
  23351. var Cartesian = function (name) {
  23352. this._axes = {};
  23353. this._dimList = [];
  23354. /**
  23355. * @type {string}
  23356. */
  23357. this.name = name || '';
  23358. };
  23359. Cartesian.prototype = {
  23360. constructor: Cartesian,
  23361. type: 'cartesian',
  23362. /**
  23363. * Get axis
  23364. * @param {number|string} dim
  23365. * @return {module:echarts/coord/Cartesian~Axis}
  23366. */
  23367. getAxis: function (dim) {
  23368. return this._axes[dim];
  23369. },
  23370. /**
  23371. * Get axes list
  23372. * @return {Array.<module:echarts/coord/Cartesian~Axis>}
  23373. */
  23374. getAxes: function () {
  23375. return zrUtil.map(this._dimList, dimAxisMapper, this);
  23376. },
  23377. /**
  23378. * Get axes list by given scale type
  23379. */
  23380. getAxesByScale: function (scaleType) {
  23381. scaleType = scaleType.toLowerCase();
  23382. return zrUtil.filter(
  23383. this.getAxes(),
  23384. function (axis) {
  23385. return axis.scale.type === scaleType;
  23386. }
  23387. );
  23388. },
  23389. /**
  23390. * Add axis
  23391. * @param {module:echarts/coord/Cartesian.Axis}
  23392. */
  23393. addAxis: function (axis) {
  23394. var dim = axis.dim;
  23395. this._axes[dim] = axis;
  23396. this._dimList.push(dim);
  23397. },
  23398. /**
  23399. * Convert data to coord in nd space
  23400. * @param {Array.<number>|Object.<string, number>} val
  23401. * @return {Array.<number>|Object.<string, number>}
  23402. */
  23403. dataToCoord: function (val) {
  23404. return this._dataCoordConvert(val, 'dataToCoord');
  23405. },
  23406. /**
  23407. * Convert coord in nd space to data
  23408. * @param {Array.<number>|Object.<string, number>} val
  23409. * @return {Array.<number>|Object.<string, number>}
  23410. */
  23411. coordToData: function (val) {
  23412. return this._dataCoordConvert(val, 'coordToData');
  23413. },
  23414. _dataCoordConvert: function (input, method) {
  23415. var dimList = this._dimList;
  23416. var output = input instanceof Array ? [] : {};
  23417. for (var i = 0; i < dimList.length; i++) {
  23418. var dim = dimList[i];
  23419. var axis = this._axes[dim];
  23420. output[dim] = axis[method](input[dim]);
  23421. }
  23422. return output;
  23423. }
  23424. };
  23425. module.exports = Cartesian;
  23426. /***/ },
  23427. /* 123 */
  23428. /***/ function(module, exports, __webpack_require__) {
  23429. var zrUtil = __webpack_require__(4);
  23430. var Axis = __webpack_require__(124);
  23431. var axisLabelInterval = __webpack_require__(125);
  23432. /**
  23433. * Extend axis 2d
  23434. * @constructor module:echarts/coord/cartesian/Axis2D
  23435. * @extends {module:echarts/coord/cartesian/Axis}
  23436. * @param {string} dim
  23437. * @param {*} scale
  23438. * @param {Array.<number>} coordExtent
  23439. * @param {string} axisType
  23440. * @param {string} position
  23441. */
  23442. var Axis2D = function (dim, scale, coordExtent, axisType, position) {
  23443. Axis.call(this, dim, scale, coordExtent);
  23444. /**
  23445. * Axis type
  23446. * - 'category'
  23447. * - 'value'
  23448. * - 'time'
  23449. * - 'log'
  23450. * @type {string}
  23451. */
  23452. this.type = axisType || 'value';
  23453. /**
  23454. * Axis position
  23455. * - 'top'
  23456. * - 'bottom'
  23457. * - 'left'
  23458. * - 'right'
  23459. */
  23460. this.position = position || 'bottom';
  23461. };
  23462. Axis2D.prototype = {
  23463. constructor: Axis2D,
  23464. /**
  23465. * Index of axis, can be used as key
  23466. */
  23467. index: 0,
  23468. /**
  23469. * If axis is on the zero position of the other axis
  23470. * @type {boolean}
  23471. */
  23472. onZero: false,
  23473. /**
  23474. * Axis model
  23475. * @param {module:echarts/coord/cartesian/AxisModel}
  23476. */
  23477. model: null,
  23478. isHorizontal: function () {
  23479. var position = this.position;
  23480. return position === 'top' || position === 'bottom';
  23481. },
  23482. getGlobalExtent: function () {
  23483. var ret = this.getExtent();
  23484. ret[0] = this.toGlobalCoord(ret[0]);
  23485. ret[1] = this.toGlobalCoord(ret[1]);
  23486. return ret;
  23487. },
  23488. /**
  23489. * @return {number}
  23490. */
  23491. getLabelInterval: function () {
  23492. var labelInterval = this._labelInterval;
  23493. if (!labelInterval) {
  23494. labelInterval = this._labelInterval = axisLabelInterval(this);
  23495. }
  23496. return labelInterval;
  23497. },
  23498. /**
  23499. * If label is ignored.
  23500. * Automatically used when axis is category and label can not be all shown
  23501. * @param {number} idx
  23502. * @return {boolean}
  23503. */
  23504. isLabelIgnored: function (idx) {
  23505. if (this.type === 'category') {
  23506. var labelInterval = this.getLabelInterval();
  23507. return ((typeof labelInterval === 'function')
  23508. && !labelInterval(idx, this.scale.getLabel(idx)))
  23509. || idx % (labelInterval + 1);
  23510. }
  23511. },
  23512. /**
  23513. * Transform global coord to local coord,
  23514. * i.e. var localCoord = axis.toLocalCoord(80);
  23515. * designate by module:echarts/coord/cartesian/Grid.
  23516. * @type {Function}
  23517. */
  23518. toLocalCoord: null,
  23519. /**
  23520. * Transform global coord to local coord,
  23521. * i.e. var globalCoord = axis.toLocalCoord(40);
  23522. * designate by module:echarts/coord/cartesian/Grid.
  23523. * @type {Function}
  23524. */
  23525. toGlobalCoord: null
  23526. };
  23527. zrUtil.inherits(Axis2D, Axis);
  23528. module.exports = Axis2D;
  23529. /***/ },
  23530. /* 124 */
  23531. /***/ function(module, exports, __webpack_require__) {
  23532. var numberUtil = __webpack_require__(7);
  23533. var linearMap = numberUtil.linearMap;
  23534. var zrUtil = __webpack_require__(4);
  23535. function fixExtentWithBands(extent, nTick) {
  23536. var size = extent[1] - extent[0];
  23537. var len = nTick;
  23538. var margin = size / len / 2;
  23539. extent[0] += margin;
  23540. extent[1] -= margin;
  23541. }
  23542. var normalizedExtent = [0, 1];
  23543. /**
  23544. * @name module:echarts/coord/CartesianAxis
  23545. * @constructor
  23546. */
  23547. var Axis = function (dim, scale, extent) {
  23548. /**
  23549. * Axis dimension. Such as 'x', 'y', 'z', 'angle', 'radius'
  23550. * @type {string}
  23551. */
  23552. this.dim = dim;
  23553. /**
  23554. * Axis scale
  23555. * @type {module:echarts/coord/scale/*}
  23556. */
  23557. this.scale = scale;
  23558. /**
  23559. * @type {Array.<number>}
  23560. * @private
  23561. */
  23562. this._extent = extent || [0, 0];
  23563. /**
  23564. * @type {boolean}
  23565. */
  23566. this.inverse = false;
  23567. /**
  23568. * Usually true when axis has a ordinal scale
  23569. * @type {boolean}
  23570. */
  23571. this.onBand = false;
  23572. };
  23573. Axis.prototype = {
  23574. constructor: Axis,
  23575. /**
  23576. * If axis extent contain given coord
  23577. * @param {number} coord
  23578. * @return {boolean}
  23579. */
  23580. contain: function (coord) {
  23581. var extent = this._extent;
  23582. var min = Math.min(extent[0], extent[1]);
  23583. var max = Math.max(extent[0], extent[1]);
  23584. return coord >= min && coord <= max;
  23585. },
  23586. /**
  23587. * If axis extent contain given data
  23588. * @param {number} data
  23589. * @return {boolean}
  23590. */
  23591. containData: function (data) {
  23592. return this.contain(this.dataToCoord(data));
  23593. },
  23594. /**
  23595. * Get coord extent.
  23596. * @return {Array.<number>}
  23597. */
  23598. getExtent: function () {
  23599. var ret = this._extent.slice();
  23600. return ret;
  23601. },
  23602. /**
  23603. * Get precision used for formatting
  23604. * @param {Array.<number>} [dataExtent]
  23605. * @return {number}
  23606. */
  23607. getPixelPrecision: function (dataExtent) {
  23608. return numberUtil.getPixelPrecision(
  23609. dataExtent || this.scale.getExtent(),
  23610. this._extent
  23611. );
  23612. },
  23613. /**
  23614. * Set coord extent
  23615. * @param {number} start
  23616. * @param {number} end
  23617. */
  23618. setExtent: function (start, end) {
  23619. var extent = this._extent;
  23620. extent[0] = start;
  23621. extent[1] = end;
  23622. },
  23623. /**
  23624. * Convert data to coord. Data is the rank if it has a ordinal scale
  23625. * @param {number} data
  23626. * @param {boolean} clamp
  23627. * @return {number}
  23628. */
  23629. dataToCoord: function (data, clamp) {
  23630. var extent = this._extent;
  23631. var scale = this.scale;
  23632. data = scale.normalize(data);
  23633. if (this.onBand && scale.type === 'ordinal') {
  23634. extent = extent.slice();
  23635. fixExtentWithBands(extent, scale.count());
  23636. }
  23637. return linearMap(data, normalizedExtent, extent, clamp);
  23638. },
  23639. /**
  23640. * Convert coord to data. Data is the rank if it has a ordinal scale
  23641. * @param {number} coord
  23642. * @param {boolean} clamp
  23643. * @return {number}
  23644. */
  23645. coordToData: function (coord, clamp) {
  23646. var extent = this._extent;
  23647. var scale = this.scale;
  23648. if (this.onBand && scale.type === 'ordinal') {
  23649. extent = extent.slice();
  23650. fixExtentWithBands(extent, scale.count());
  23651. }
  23652. var t = linearMap(coord, extent, normalizedExtent, clamp);
  23653. return this.scale.scale(t);
  23654. },
  23655. /**
  23656. * @return {Array.<number>}
  23657. */
  23658. getTicksCoords: function (alignWithLabel) {
  23659. if (this.onBand && !alignWithLabel) {
  23660. var bands = this.getBands();
  23661. var coords = [];
  23662. for (var i = 0; i < bands.length; i++) {
  23663. coords.push(bands[i][0]);
  23664. }
  23665. if (bands[i - 1]) {
  23666. coords.push(bands[i - 1][1]);
  23667. }
  23668. return coords;
  23669. }
  23670. else {
  23671. return zrUtil.map(this.scale.getTicks(), this.dataToCoord, this);
  23672. }
  23673. },
  23674. /**
  23675. * Coords of labels are on the ticks or on the middle of bands
  23676. * @return {Array.<number>}
  23677. */
  23678. getLabelsCoords: function () {
  23679. return zrUtil.map(this.scale.getTicks(), this.dataToCoord, this);
  23680. },
  23681. /**
  23682. * Get bands.
  23683. *
  23684. * If axis has labels [1, 2, 3, 4]. Bands on the axis are
  23685. * |---1---|---2---|---3---|---4---|.
  23686. *
  23687. * @return {Array}
  23688. */
  23689. // FIXME Situation when labels is on ticks
  23690. getBands: function () {
  23691. var extent = this.getExtent();
  23692. var bands = [];
  23693. var len = this.scale.count();
  23694. var start = extent[0];
  23695. var end = extent[1];
  23696. var span = end - start;
  23697. for (var i = 0; i < len; i++) {
  23698. bands.push([
  23699. span * i / len + start,
  23700. span * (i + 1) / len + start
  23701. ]);
  23702. }
  23703. return bands;
  23704. },
  23705. /**
  23706. * Get width of band
  23707. * @return {number}
  23708. */
  23709. getBandWidth: function () {
  23710. var axisExtent = this._extent;
  23711. var dataExtent = this.scale.getExtent();
  23712. var len = dataExtent[1] - dataExtent[0] + (this.onBand ? 1 : 0);
  23713. // Fix #2728, avoid NaN when only one data.
  23714. len === 0 && (len = 1);
  23715. var size = Math.abs(axisExtent[1] - axisExtent[0]);
  23716. return Math.abs(size) / len;
  23717. },
  23718. /**
  23719. * When axis extent depends on data and no data exists,
  23720. * axis ticks should not be drawn, which is named 'blank'.
  23721. */
  23722. isBlank: function () {
  23723. return this._isBlank;
  23724. },
  23725. /**
  23726. * When axis extent depends on data and no data exists,
  23727. * axis ticks should not be drawn, which is named 'blank'.
  23728. */
  23729. setBlank: function (isBlank) {
  23730. this._isBlank = isBlank;
  23731. }
  23732. };
  23733. module.exports = Axis;
  23734. /***/ },
  23735. /* 125 */
  23736. /***/ function(module, exports, __webpack_require__) {
  23737. 'use strict';
  23738. /**
  23739. * Helper function for axisLabelInterval calculation
  23740. */
  23741. var zrUtil = __webpack_require__(4);
  23742. var axisHelper = __webpack_require__(115);
  23743. module.exports = function (axis) {
  23744. var axisModel = axis.model;
  23745. var labelModel = axisModel.getModel('axisLabel');
  23746. var labelInterval = labelModel.get('interval');
  23747. if (!(axis.type === 'category' && labelInterval === 'auto')) {
  23748. return labelInterval === 'auto' ? 0 : labelInterval;
  23749. }
  23750. return axisHelper.getAxisLabelInterval(
  23751. zrUtil.map(axis.scale.getTicks(), axis.dataToCoord, axis),
  23752. axisModel.getFormattedLabels(),
  23753. labelModel.getModel('textStyle').getFont(),
  23754. axis.isHorizontal()
  23755. );
  23756. };
  23757. /***/ },
  23758. /* 126 */
  23759. /***/ function(module, exports, __webpack_require__) {
  23760. 'use strict';
  23761. // Grid 是在有直角坐标系的时候必须要存在的
  23762. // 所以这里也要被 Cartesian2D 依赖
  23763. __webpack_require__(127);
  23764. var ComponentModel = __webpack_require__(19);
  23765. module.exports = ComponentModel.extend({
  23766. type: 'grid',
  23767. dependencies: ['xAxis', 'yAxis'],
  23768. layoutMode: 'box',
  23769. /**
  23770. * @type {module:echarts/coord/cartesian/Grid}
  23771. */
  23772. coordinateSystem: null,
  23773. defaultOption: {
  23774. show: false,
  23775. zlevel: 0,
  23776. z: 0,
  23777. left: '10%',
  23778. top: 60,
  23779. right: '10%',
  23780. bottom: 60,
  23781. // If grid size contain label
  23782. containLabel: false,
  23783. // width: {totalWidth} - left - right,
  23784. // height: {totalHeight} - top - bottom,
  23785. backgroundColor: 'rgba(0,0,0,0)',
  23786. borderWidth: 1,
  23787. borderColor: '#ccc'
  23788. }
  23789. });
  23790. /***/ },
  23791. /* 127 */
  23792. /***/ function(module, exports, __webpack_require__) {
  23793. 'use strict';
  23794. var ComponentModel = __webpack_require__(19);
  23795. var zrUtil = __webpack_require__(4);
  23796. var axisModelCreator = __webpack_require__(128);
  23797. var AxisModel = ComponentModel.extend({
  23798. type: 'cartesian2dAxis',
  23799. /**
  23800. * @type {module:echarts/coord/cartesian/Axis2D}
  23801. */
  23802. axis: null,
  23803. /**
  23804. * @override
  23805. */
  23806. init: function () {
  23807. AxisModel.superApply(this, 'init', arguments);
  23808. this.resetRange();
  23809. },
  23810. /**
  23811. * @override
  23812. */
  23813. mergeOption: function () {
  23814. AxisModel.superApply(this, 'mergeOption', arguments);
  23815. this.resetRange();
  23816. },
  23817. /**
  23818. * @override
  23819. */
  23820. restoreData: function () {
  23821. AxisModel.superApply(this, 'restoreData', arguments);
  23822. this.resetRange();
  23823. },
  23824. /**
  23825. * @override
  23826. * @return {module:echarts/model/Component}
  23827. */
  23828. getCoordSysModel: function () {
  23829. return this.ecModel.queryComponents({
  23830. mainType: 'grid',
  23831. index: this.option.gridIndex,
  23832. id: this.option.gridId
  23833. })[0];
  23834. }
  23835. });
  23836. function getAxisType(axisDim, option) {
  23837. // Default axis with data is category axis
  23838. return option.type || (option.data ? 'category' : 'value');
  23839. }
  23840. zrUtil.merge(AxisModel.prototype, __webpack_require__(130));
  23841. var extraOption = {
  23842. // gridIndex: 0,
  23843. // gridId: '',
  23844. // Offset is for multiple axis on the same position
  23845. offset: 0
  23846. };
  23847. axisModelCreator('x', AxisModel, getAxisType, extraOption);
  23848. axisModelCreator('y', AxisModel, getAxisType, extraOption);
  23849. module.exports = AxisModel;
  23850. /***/ },
  23851. /* 128 */
  23852. /***/ function(module, exports, __webpack_require__) {
  23853. var axisDefault = __webpack_require__(129);
  23854. var zrUtil = __webpack_require__(4);
  23855. var ComponentModel = __webpack_require__(19);
  23856. var layout = __webpack_require__(21);
  23857. // FIXME axisType is fixed ?
  23858. var AXIS_TYPES = ['value', 'category', 'time', 'log'];
  23859. /**
  23860. * Generate sub axis model class
  23861. * @param {string} axisName 'x' 'y' 'radius' 'angle' 'parallel'
  23862. * @param {module:echarts/model/Component} BaseAxisModelClass
  23863. * @param {Function} axisTypeDefaulter
  23864. * @param {Object} [extraDefaultOption]
  23865. */
  23866. module.exports = function (axisName, BaseAxisModelClass, axisTypeDefaulter, extraDefaultOption) {
  23867. zrUtil.each(AXIS_TYPES, function (axisType) {
  23868. BaseAxisModelClass.extend({
  23869. type: axisName + 'Axis.' + axisType,
  23870. mergeDefaultAndTheme: function (option, ecModel) {
  23871. var layoutMode = this.layoutMode;
  23872. var inputPositionParams = layoutMode
  23873. ? layout.getLayoutParams(option) : {};
  23874. var themeModel = ecModel.getTheme();
  23875. zrUtil.merge(option, themeModel.get(axisType + 'Axis'));
  23876. zrUtil.merge(option, this.getDefaultOption());
  23877. option.type = axisTypeDefaulter(axisName, option);
  23878. if (layoutMode) {
  23879. layout.mergeLayoutParam(option, inputPositionParams, layoutMode);
  23880. }
  23881. },
  23882. defaultOption: zrUtil.mergeAll(
  23883. [
  23884. {},
  23885. axisDefault[axisType + 'Axis'],
  23886. extraDefaultOption
  23887. ],
  23888. true
  23889. )
  23890. });
  23891. });
  23892. ComponentModel.registerSubTypeDefaulter(
  23893. axisName + 'Axis',
  23894. zrUtil.curry(axisTypeDefaulter, axisName)
  23895. );
  23896. };
  23897. /***/ },
  23898. /* 129 */
  23899. /***/ function(module, exports, __webpack_require__) {
  23900. var zrUtil = __webpack_require__(4);
  23901. var defaultOption = {
  23902. show: true,
  23903. zlevel: 0, // 一级层叠
  23904. z: 0, // 二级层叠
  23905. // 反向坐标轴
  23906. inverse: false,
  23907. // 坐标轴名字,默认为空
  23908. name: '',
  23909. // 坐标轴名字位置,支持'start' | 'middle' | 'end'
  23910. nameLocation: 'end',
  23911. // 坐标轴名字旋转,degree。
  23912. nameRotate: null, // Adapt to axis rotate, when nameLocation is 'middle'.
  23913. nameTruncate: {
  23914. maxWidth: null,
  23915. ellipsis: '...',
  23916. placeholder: '.'
  23917. },
  23918. // 坐标轴文字样式,默认取全局样式
  23919. nameTextStyle: {},
  23920. // 文字与轴线距离
  23921. nameGap: 15,
  23922. silent: false, // Default false to support tooltip.
  23923. triggerEvent: false, // Default false to avoid legacy user event listener fail.
  23924. tooltip: {
  23925. show: false
  23926. },
  23927. // 坐标轴线
  23928. axisLine: {
  23929. // 默认显示,属性show控制显示与否
  23930. show: true,
  23931. onZero: true,
  23932. // 属性lineStyle控制线条样式
  23933. lineStyle: {
  23934. color: '#333',
  23935. width: 1,
  23936. type: 'solid'
  23937. }
  23938. },
  23939. // 坐标轴小标记
  23940. axisTick: {
  23941. // 属性show控制显示与否,默认显示
  23942. show: true,
  23943. // 控制小标记是否在grid里
  23944. inside: false,
  23945. // 属性length控制线长
  23946. length: 5,
  23947. // 属性lineStyle控制线条样式
  23948. lineStyle: {
  23949. width: 1
  23950. }
  23951. },
  23952. // 坐标轴文本标签,详见axis.axisLabel
  23953. axisLabel: {
  23954. show: true,
  23955. // 控制文本标签是否在grid里
  23956. inside: false,
  23957. rotate: 0,
  23958. margin: 8,
  23959. // formatter: null,
  23960. // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  23961. textStyle: {
  23962. fontSize: 12
  23963. }
  23964. },
  23965. // 分隔线
  23966. splitLine: {
  23967. // 默认显示,属性show控制显示与否
  23968. show: true,
  23969. // 属性lineStyle(详见lineStyle)控制线条样式
  23970. lineStyle: {
  23971. color: ['#ccc'],
  23972. width: 1,
  23973. type: 'solid'
  23974. }
  23975. },
  23976. // 分隔区域
  23977. splitArea: {
  23978. // 默认不显示,属性show控制显示与否
  23979. show: false,
  23980. // 属性areaStyle(详见areaStyle)控制区域样式
  23981. areaStyle: {
  23982. color: ['rgba(250,250,250,0.3)','rgba(200,200,200,0.3)']
  23983. }
  23984. }
  23985. };
  23986. var categoryAxis = zrUtil.merge({
  23987. // 类目起始和结束两端空白策略
  23988. boundaryGap: true,
  23989. // splitArea: {
  23990. // show: false
  23991. // },
  23992. splitLine: {
  23993. show: false
  23994. },
  23995. // 坐标轴小标记
  23996. axisTick: {
  23997. // If tick is align with label when boundaryGap is true
  23998. // Default with axisTick
  23999. alignWithLabel: false,
  24000. interval: 'auto'
  24001. },
  24002. // 坐标轴文本标签,详见axis.axisLabel
  24003. axisLabel: {
  24004. interval: 'auto'
  24005. }
  24006. }, defaultOption);
  24007. var valueAxis = zrUtil.merge({
  24008. // 数值起始和结束两端空白策略
  24009. boundaryGap: [0, 0],
  24010. // 最小值, 设置成 'dataMin' 则从数据中计算最小值
  24011. // min: null,
  24012. // 最大值,设置成 'dataMax' 则从数据中计算最大值
  24013. // max: null,
  24014. // Readonly prop, specifies start value of the range when using data zoom.
  24015. // rangeStart: null
  24016. // Readonly prop, specifies end value of the range when using data zoom.
  24017. // rangeEnd: null
  24018. // 脱离0值比例,放大聚焦到最终_min,_max区间
  24019. // scale: false,
  24020. // 分割段数,默认为5
  24021. splitNumber: 5
  24022. // Minimum interval
  24023. // minInterval: null
  24024. }, defaultOption);
  24025. // FIXME
  24026. var timeAxis = zrUtil.defaults({
  24027. scale: true,
  24028. min: 'dataMin',
  24029. max: 'dataMax'
  24030. }, valueAxis);
  24031. var logAxis = zrUtil.defaults({
  24032. logBase: 10
  24033. }, valueAxis);
  24034. logAxis.scale = true;
  24035. module.exports = {
  24036. categoryAxis: categoryAxis,
  24037. valueAxis: valueAxis,
  24038. timeAxis: timeAxis,
  24039. logAxis: logAxis
  24040. };
  24041. /***/ },
  24042. /* 130 */
  24043. /***/ function(module, exports, __webpack_require__) {
  24044. var zrUtil = __webpack_require__(4);
  24045. var axisHelper = __webpack_require__(115);
  24046. function getName(obj) {
  24047. if (zrUtil.isObject(obj) && obj.value != null) {
  24048. return obj.value;
  24049. }
  24050. else {
  24051. return obj;
  24052. }
  24053. }
  24054. module.exports = {
  24055. /**
  24056. * Format labels
  24057. * @return {Array.<string>}
  24058. */
  24059. getFormattedLabels: function () {
  24060. return axisHelper.getFormattedLabels(
  24061. this.axis,
  24062. this.get('axisLabel.formatter')
  24063. );
  24064. },
  24065. /**
  24066. * Get categories
  24067. */
  24068. getCategories: function () {
  24069. return this.get('type') === 'category'
  24070. && zrUtil.map(this.get('data'), getName);
  24071. },
  24072. /**
  24073. * @param {boolean} origin
  24074. * @return {number|string} min value or 'dataMin' or null/undefined (means auto) or NaN
  24075. */
  24076. getMin: function (origin) {
  24077. var option = this.option;
  24078. var min = (!origin && option.rangeStart != null)
  24079. ? option.rangeStart : option.min;
  24080. if (min != null && min !== 'dataMin' && !zrUtil.eqNaN(min)) {
  24081. min = this.axis.scale.parse(min);
  24082. }
  24083. return min;
  24084. },
  24085. /**
  24086. * @param {boolean} origin
  24087. * @return {number|string} max value or 'dataMax' or null/undefined (means auto) or NaN
  24088. */
  24089. getMax: function (origin) {
  24090. var option = this.option;
  24091. var max = (!origin && option.rangeEnd != null)
  24092. ? option.rangeEnd : option.max;
  24093. if (max != null && max !== 'dataMax' && !zrUtil.eqNaN(max)) {
  24094. max = this.axis.scale.parse(max);
  24095. }
  24096. return max;
  24097. },
  24098. /**
  24099. * @return {boolean}
  24100. */
  24101. getNeedCrossZero: function () {
  24102. var option = this.option;
  24103. return (option.rangeStart != null || option.rangeEnd != null)
  24104. ? false : !option.scale;
  24105. },
  24106. /**
  24107. * Should be implemented by each axis model if necessary.
  24108. * @return {module:echarts/model/Component} coordinate system model
  24109. */
  24110. getCoordSysModel: zrUtil.noop,
  24111. /**
  24112. * @param {number} rangeStart Can only be finite number or null/undefined or NaN.
  24113. * @param {number} rangeEnd Can only be finite number or null/undefined or NaN.
  24114. */
  24115. setRange: function (rangeStart, rangeEnd) {
  24116. this.option.rangeStart = rangeStart;
  24117. this.option.rangeEnd = rangeEnd;
  24118. },
  24119. /**
  24120. * Reset range
  24121. */
  24122. resetRange: function () {
  24123. // rangeStart and rangeEnd is readonly.
  24124. this.option.rangeStart = this.option.rangeEnd = null;
  24125. }
  24126. };
  24127. /***/ },
  24128. /* 131 */
  24129. /***/ function(module, exports, __webpack_require__) {
  24130. 'use strict';
  24131. // TODO boundaryGap
  24132. __webpack_require__(127);
  24133. __webpack_require__(132);
  24134. /***/ },
  24135. /* 132 */
  24136. /***/ function(module, exports, __webpack_require__) {
  24137. var zrUtil = __webpack_require__(4);
  24138. var graphic = __webpack_require__(43);
  24139. var AxisBuilder = __webpack_require__(133);
  24140. var ifIgnoreOnTick = AxisBuilder.ifIgnoreOnTick;
  24141. var getInterval = AxisBuilder.getInterval;
  24142. var axisBuilderAttrs = [
  24143. 'axisLine', 'axisLabel', 'axisTick', 'axisName'
  24144. ];
  24145. var selfBuilderAttrs = [
  24146. 'splitArea', 'splitLine'
  24147. ];
  24148. // function getAlignWithLabel(model, axisModel) {
  24149. // var alignWithLabel = model.get('alignWithLabel');
  24150. // if (alignWithLabel === 'auto') {
  24151. // alignWithLabel = axisModel.get('axisTick.alignWithLabel');
  24152. // }
  24153. // return alignWithLabel;
  24154. // }
  24155. var AxisView = __webpack_require__(1).extendComponentView({
  24156. type: 'axis',
  24157. render: function (axisModel, ecModel) {
  24158. this.group.removeAll();
  24159. var oldAxisGroup = this._axisGroup;
  24160. this._axisGroup = new graphic.Group();
  24161. this.group.add(this._axisGroup);
  24162. if (!axisModel.get('show')) {
  24163. return;
  24164. }
  24165. var gridModel = axisModel.getCoordSysModel();
  24166. var layout = layoutAxis(gridModel, axisModel);
  24167. var axisBuilder = new AxisBuilder(axisModel, layout);
  24168. zrUtil.each(axisBuilderAttrs, axisBuilder.add, axisBuilder);
  24169. this._axisGroup.add(axisBuilder.getGroup());
  24170. zrUtil.each(selfBuilderAttrs, function (name) {
  24171. if (axisModel.get(name + '.show')) {
  24172. this['_' + name](axisModel, gridModel, layout.labelInterval);
  24173. }
  24174. }, this);
  24175. graphic.groupTransition(oldAxisGroup, this._axisGroup, axisModel);
  24176. },
  24177. /**
  24178. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  24179. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  24180. * @param {number|Function} labelInterval
  24181. * @private
  24182. */
  24183. _splitLine: function (axisModel, gridModel, labelInterval) {
  24184. var axis = axisModel.axis;
  24185. if (axis.isBlank()) {
  24186. return;
  24187. }
  24188. var splitLineModel = axisModel.getModel('splitLine');
  24189. var lineStyleModel = splitLineModel.getModel('lineStyle');
  24190. var lineColors = lineStyleModel.get('color');
  24191. var lineInterval = getInterval(splitLineModel, labelInterval);
  24192. lineColors = zrUtil.isArray(lineColors) ? lineColors : [lineColors];
  24193. var gridRect = gridModel.coordinateSystem.getRect();
  24194. var isHorizontal = axis.isHorizontal();
  24195. var lineCount = 0;
  24196. var ticksCoords = axis.getTicksCoords(
  24197. // splitLineModel.get('alignWithLabel')
  24198. );
  24199. var ticks = axis.scale.getTicks();
  24200. var p1 = [];
  24201. var p2 = [];
  24202. // Simple optimization
  24203. // Batching the lines if color are the same
  24204. var lineStyle = lineStyleModel.getLineStyle();
  24205. for (var i = 0; i < ticksCoords.length; i++) {
  24206. if (ifIgnoreOnTick(axis, i, lineInterval)) {
  24207. continue;
  24208. }
  24209. var tickCoord = axis.toGlobalCoord(ticksCoords[i]);
  24210. if (isHorizontal) {
  24211. p1[0] = tickCoord;
  24212. p1[1] = gridRect.y;
  24213. p2[0] = tickCoord;
  24214. p2[1] = gridRect.y + gridRect.height;
  24215. }
  24216. else {
  24217. p1[0] = gridRect.x;
  24218. p1[1] = tickCoord;
  24219. p2[0] = gridRect.x + gridRect.width;
  24220. p2[1] = tickCoord;
  24221. }
  24222. var colorIndex = (lineCount++) % lineColors.length;
  24223. this._axisGroup.add(new graphic.Line(graphic.subPixelOptimizeLine({
  24224. anid: 'line_' + ticks[i],
  24225. shape: {
  24226. x1: p1[0],
  24227. y1: p1[1],
  24228. x2: p2[0],
  24229. y2: p2[1]
  24230. },
  24231. style: zrUtil.defaults({
  24232. stroke: lineColors[colorIndex]
  24233. }, lineStyle),
  24234. silent: true
  24235. })));
  24236. }
  24237. },
  24238. /**
  24239. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  24240. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  24241. * @param {number|Function} labelInterval
  24242. * @private
  24243. */
  24244. _splitArea: function (axisModel, gridModel, labelInterval) {
  24245. var axis = axisModel.axis;
  24246. if (axis.isBlank()) {
  24247. return;
  24248. }
  24249. var splitAreaModel = axisModel.getModel('splitArea');
  24250. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  24251. var areaColors = areaStyleModel.get('color');
  24252. var gridRect = gridModel.coordinateSystem.getRect();
  24253. var ticksCoords = axis.getTicksCoords(
  24254. // splitAreaModel.get('alignWithLabel')
  24255. );
  24256. var ticks = axis.scale.getTicks();
  24257. var prevX = axis.toGlobalCoord(ticksCoords[0]);
  24258. var prevY = axis.toGlobalCoord(ticksCoords[0]);
  24259. var count = 0;
  24260. var areaInterval = getInterval(splitAreaModel, labelInterval);
  24261. var areaStyle = areaStyleModel.getAreaStyle();
  24262. areaColors = zrUtil.isArray(areaColors) ? areaColors : [areaColors];
  24263. for (var i = 1; i < ticksCoords.length; i++) {
  24264. if (ifIgnoreOnTick(axis, i, areaInterval)) {
  24265. continue;
  24266. }
  24267. var tickCoord = axis.toGlobalCoord(ticksCoords[i]);
  24268. var x;
  24269. var y;
  24270. var width;
  24271. var height;
  24272. if (axis.isHorizontal()) {
  24273. x = prevX;
  24274. y = gridRect.y;
  24275. width = tickCoord - x;
  24276. height = gridRect.height;
  24277. }
  24278. else {
  24279. x = gridRect.x;
  24280. y = prevY;
  24281. width = gridRect.width;
  24282. height = tickCoord - y;
  24283. }
  24284. var colorIndex = (count++) % areaColors.length;
  24285. this._axisGroup.add(new graphic.Rect({
  24286. anid: 'area_' + ticks[i],
  24287. shape: {
  24288. x: x,
  24289. y: y,
  24290. width: width,
  24291. height: height
  24292. },
  24293. style: zrUtil.defaults({
  24294. fill: areaColors[colorIndex]
  24295. }, areaStyle),
  24296. silent: true
  24297. }));
  24298. prevX = x + width;
  24299. prevY = y + height;
  24300. }
  24301. }
  24302. });
  24303. AxisView.extend({
  24304. type: 'xAxis'
  24305. });
  24306. AxisView.extend({
  24307. type: 'yAxis'
  24308. });
  24309. /**
  24310. * @inner
  24311. */
  24312. function layoutAxis(gridModel, axisModel) {
  24313. var grid = gridModel.coordinateSystem;
  24314. var axis = axisModel.axis;
  24315. var layout = {};
  24316. var rawAxisPosition = axis.position;
  24317. var axisPosition = axis.onZero ? 'onZero' : rawAxisPosition;
  24318. var axisDim = axis.dim;
  24319. // [left, right, top, bottom]
  24320. var rect = grid.getRect();
  24321. var rectBound = [rect.x, rect.x + rect.width, rect.y, rect.y + rect.height];
  24322. var axisOffset = axisModel.get('offset') || 0;
  24323. var posMap = {
  24324. x: { top: rectBound[2] - axisOffset, bottom: rectBound[3] + axisOffset },
  24325. y: { left: rectBound[0] - axisOffset, right: rectBound[1] + axisOffset }
  24326. };
  24327. posMap.x.onZero = Math.max(Math.min(getZero('y'), posMap.x.bottom), posMap.x.top);
  24328. posMap.y.onZero = Math.max(Math.min(getZero('x'), posMap.y.right), posMap.y.left);
  24329. function getZero(dim, val) {
  24330. var theAxis = grid.getAxis(dim);
  24331. return theAxis.toGlobalCoord(theAxis.dataToCoord(0));
  24332. }
  24333. // Axis position
  24334. layout.position = [
  24335. axisDim === 'y' ? posMap.y[axisPosition] : rectBound[0],
  24336. axisDim === 'x' ? posMap.x[axisPosition] : rectBound[3]
  24337. ];
  24338. // Axis rotation
  24339. layout.rotation = Math.PI / 2 * (axisDim === 'x' ? 0 : 1);
  24340. // Tick and label direction, x y is axisDim
  24341. var dirMap = {top: -1, bottom: 1, left: -1, right: 1};
  24342. layout.labelDirection = layout.tickDirection = layout.nameDirection = dirMap[rawAxisPosition];
  24343. if (axis.onZero) {
  24344. layout.labelOffset = posMap[axisDim][rawAxisPosition] - posMap[axisDim].onZero;
  24345. }
  24346. if (axisModel.getModel('axisTick').get('inside')) {
  24347. layout.tickDirection = -layout.tickDirection;
  24348. }
  24349. if (axisModel.getModel('axisLabel').get('inside')) {
  24350. layout.labelDirection = -layout.labelDirection;
  24351. }
  24352. // Special label rotation
  24353. var labelRotation = axisModel.getModel('axisLabel').get('rotate');
  24354. layout.labelRotation = axisPosition === 'top' ? -labelRotation : labelRotation;
  24355. // label interval when auto mode.
  24356. layout.labelInterval = axis.getLabelInterval();
  24357. // Over splitLine and splitArea
  24358. layout.z2 = 1;
  24359. return layout;
  24360. }
  24361. /***/ },
  24362. /* 133 */
  24363. /***/ function(module, exports, __webpack_require__) {
  24364. var zrUtil = __webpack_require__(4);
  24365. var formatUtil = __webpack_require__(6);
  24366. var graphic = __webpack_require__(43);
  24367. var Model = __webpack_require__(12);
  24368. var numberUtil = __webpack_require__(7);
  24369. var remRadian = numberUtil.remRadian;
  24370. var isRadianAroundZero = numberUtil.isRadianAroundZero;
  24371. var vec2 = __webpack_require__(10);
  24372. var v2ApplyTransform = vec2.applyTransform;
  24373. var retrieve = zrUtil.retrieve;
  24374. var PI = Math.PI;
  24375. function makeAxisEventDataBase(axisModel) {
  24376. var eventData = {
  24377. componentType: axisModel.mainType
  24378. };
  24379. eventData[axisModel.mainType + 'Index'] = axisModel.componentIndex;
  24380. return eventData;
  24381. }
  24382. /**
  24383. * A final axis is translated and rotated from a "standard axis".
  24384. * So opt.position and opt.rotation is required.
  24385. *
  24386. * A standard axis is and axis from [0, 0] to [0, axisExtent[1]],
  24387. * for example: (0, 0) ------------> (0, 50)
  24388. *
  24389. * nameDirection or tickDirection or labelDirection is 1 means tick
  24390. * or label is below the standard axis, whereas is -1 means above
  24391. * the standard axis. labelOffset means offset between label and axis,
  24392. * which is useful when 'onZero', where axisLabel is in the grid and
  24393. * label in outside grid.
  24394. *
  24395. * Tips: like always,
  24396. * positive rotation represents anticlockwise, and negative rotation
  24397. * represents clockwise.
  24398. * The direction of position coordinate is the same as the direction
  24399. * of screen coordinate.
  24400. *
  24401. * Do not need to consider axis 'inverse', which is auto processed by
  24402. * axis extent.
  24403. *
  24404. * @param {module:zrender/container/Group} group
  24405. * @param {Object} axisModel
  24406. * @param {Object} opt Standard axis parameters.
  24407. * @param {Array.<number>} opt.position [x, y]
  24408. * @param {number} opt.rotation by radian
  24409. * @param {number} [opt.nameDirection=1] 1 or -1 Used when nameLocation is 'middle'.
  24410. * @param {number} [opt.tickDirection=1] 1 or -1
  24411. * @param {number} [opt.labelDirection=1] 1 or -1
  24412. * @param {number} [opt.labelOffset=0] Usefull when onZero.
  24413. * @param {string} [opt.axisLabelShow] default get from axisModel.
  24414. * @param {string} [opt.axisName] default get from axisModel.
  24415. * @param {number} [opt.axisNameAvailableWidth]
  24416. * @param {number} [opt.labelRotation] by degree, default get from axisModel.
  24417. * @param {number} [opt.labelInterval] Default label interval when label
  24418. * interval from model is null or 'auto'.
  24419. * @param {number} [opt.strokeContainThreshold] Default label interval when label
  24420. */
  24421. var AxisBuilder = function (axisModel, opt) {
  24422. /**
  24423. * @readOnly
  24424. */
  24425. this.opt = opt;
  24426. /**
  24427. * @readOnly
  24428. */
  24429. this.axisModel = axisModel;
  24430. // Default value
  24431. zrUtil.defaults(
  24432. opt,
  24433. {
  24434. labelOffset: 0,
  24435. nameDirection: 1,
  24436. tickDirection: 1,
  24437. labelDirection: 1,
  24438. silent: true
  24439. }
  24440. );
  24441. /**
  24442. * @readOnly
  24443. */
  24444. this.group = new graphic.Group();
  24445. // FIXME Not use a seperate text group?
  24446. var dumbGroup = new graphic.Group({
  24447. position: opt.position.slice(),
  24448. rotation: opt.rotation
  24449. });
  24450. // this.group.add(dumbGroup);
  24451. // this._dumbGroup = dumbGroup;
  24452. dumbGroup.updateTransform();
  24453. this._transform = dumbGroup.transform;
  24454. this._dumbGroup = dumbGroup;
  24455. };
  24456. AxisBuilder.prototype = {
  24457. constructor: AxisBuilder,
  24458. hasBuilder: function (name) {
  24459. return !!builders[name];
  24460. },
  24461. add: function (name) {
  24462. builders[name].call(this);
  24463. },
  24464. getGroup: function () {
  24465. return this.group;
  24466. }
  24467. };
  24468. var builders = {
  24469. /**
  24470. * @private
  24471. */
  24472. axisLine: function () {
  24473. var opt = this.opt;
  24474. var axisModel = this.axisModel;
  24475. if (!axisModel.get('axisLine.show')) {
  24476. return;
  24477. }
  24478. var extent = this.axisModel.axis.getExtent();
  24479. var matrix = this._transform;
  24480. var pt1 = [extent[0], 0];
  24481. var pt2 = [extent[1], 0];
  24482. if (matrix) {
  24483. v2ApplyTransform(pt1, pt1, matrix);
  24484. v2ApplyTransform(pt2, pt2, matrix);
  24485. }
  24486. this.group.add(new graphic.Line(graphic.subPixelOptimizeLine({
  24487. // Id for animation
  24488. anid: 'line',
  24489. shape: {
  24490. x1: pt1[0],
  24491. y1: pt1[1],
  24492. x2: pt2[0],
  24493. y2: pt2[1]
  24494. },
  24495. style: zrUtil.extend(
  24496. {lineCap: 'round'},
  24497. axisModel.getModel('axisLine.lineStyle').getLineStyle()
  24498. ),
  24499. strokeContainThreshold: opt.strokeContainThreshold || 5,
  24500. silent: true,
  24501. z2: 1
  24502. })));
  24503. },
  24504. /**
  24505. * @private
  24506. */
  24507. axisTick: function () {
  24508. var axisModel = this.axisModel;
  24509. var axis = axisModel.axis;
  24510. if (!axisModel.get('axisTick.show') || axis.isBlank()) {
  24511. return;
  24512. }
  24513. var tickModel = axisModel.getModel('axisTick');
  24514. var opt = this.opt;
  24515. var lineStyleModel = tickModel.getModel('lineStyle');
  24516. var tickLen = tickModel.get('length');
  24517. var tickInterval = getInterval(tickModel, opt.labelInterval);
  24518. var ticksCoords = axis.getTicksCoords(tickModel.get('alignWithLabel'));
  24519. var ticks = axis.scale.getTicks();
  24520. var pt1 = [];
  24521. var pt2 = [];
  24522. var matrix = this._transform;
  24523. for (var i = 0; i < ticksCoords.length; i++) {
  24524. // Only ordinal scale support tick interval
  24525. if (ifIgnoreOnTick(axis, i, tickInterval)) {
  24526. continue;
  24527. }
  24528. var tickCoord = ticksCoords[i];
  24529. pt1[0] = tickCoord;
  24530. pt1[1] = 0;
  24531. pt2[0] = tickCoord;
  24532. pt2[1] = opt.tickDirection * tickLen;
  24533. if (matrix) {
  24534. v2ApplyTransform(pt1, pt1, matrix);
  24535. v2ApplyTransform(pt2, pt2, matrix);
  24536. }
  24537. // Tick line, Not use group transform to have better line draw
  24538. this.group.add(new graphic.Line(graphic.subPixelOptimizeLine({
  24539. // Id for animation
  24540. anid: 'tick_' + ticks[i],
  24541. shape: {
  24542. x1: pt1[0],
  24543. y1: pt1[1],
  24544. x2: pt2[0],
  24545. y2: pt2[1]
  24546. },
  24547. style: zrUtil.defaults(
  24548. lineStyleModel.getLineStyle(),
  24549. {
  24550. stroke: axisModel.get('axisLine.lineStyle.color')
  24551. }
  24552. ),
  24553. z2: 2,
  24554. silent: true
  24555. })));
  24556. }
  24557. },
  24558. /**
  24559. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  24560. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  24561. * @private
  24562. */
  24563. axisLabel: function () {
  24564. var opt = this.opt;
  24565. var axisModel = this.axisModel;
  24566. var axis = axisModel.axis;
  24567. var show = retrieve(opt.axisLabelShow, axisModel.get('axisLabel.show'));
  24568. if (!show || axis.isBlank()) {
  24569. return;
  24570. }
  24571. var labelModel = axisModel.getModel('axisLabel');
  24572. var textStyleModel = labelModel.getModel('textStyle');
  24573. var labelMargin = labelModel.get('margin');
  24574. var ticks = axis.scale.getTicks();
  24575. var labels = axisModel.getFormattedLabels();
  24576. // Special label rotate.
  24577. var labelRotation = retrieve(opt.labelRotation, labelModel.get('rotate')) || 0;
  24578. // To radian.
  24579. labelRotation = labelRotation * PI / 180;
  24580. var labelLayout = innerTextLayout(opt, labelRotation, opt.labelDirection);
  24581. var categoryData = axisModel.get('data');
  24582. var textEls = [];
  24583. var silent = isSilent(axisModel);
  24584. var triggerEvent = axisModel.get('triggerEvent');
  24585. zrUtil.each(ticks, function (tickVal, index) {
  24586. if (ifIgnoreOnTick(axis, index, opt.labelInterval)) {
  24587. return;
  24588. }
  24589. var itemTextStyleModel = textStyleModel;
  24590. if (categoryData && categoryData[tickVal] && categoryData[tickVal].textStyle) {
  24591. itemTextStyleModel = new Model(
  24592. categoryData[tickVal].textStyle, textStyleModel, axisModel.ecModel
  24593. );
  24594. }
  24595. var textColor = itemTextStyleModel.getTextColor()
  24596. || axisModel.get('axisLine.lineStyle.color');
  24597. var tickCoord = axis.dataToCoord(tickVal);
  24598. var pos = [
  24599. tickCoord,
  24600. opt.labelOffset + opt.labelDirection * labelMargin
  24601. ];
  24602. var labelBeforeFormat = axis.scale.getLabel(tickVal);
  24603. var textEl = new graphic.Text({
  24604. // Id for animation
  24605. anid: 'label_' + tickVal,
  24606. style: {
  24607. text: labels[index],
  24608. textAlign: itemTextStyleModel.get('align', true) || labelLayout.textAlign,
  24609. textVerticalAlign: itemTextStyleModel.get('baseline', true) || labelLayout.verticalAlign,
  24610. textFont: itemTextStyleModel.getFont(),
  24611. fill: typeof textColor === 'function' ? textColor(labelBeforeFormat) : textColor
  24612. },
  24613. position: pos,
  24614. rotation: labelLayout.rotation,
  24615. silent: silent,
  24616. z2: 10
  24617. });
  24618. // Pack data for mouse event
  24619. if (triggerEvent) {
  24620. textEl.eventData = makeAxisEventDataBase(axisModel);
  24621. textEl.eventData.targetType = 'axisLabel';
  24622. textEl.eventData.value = labelBeforeFormat;
  24623. }
  24624. // FIXME
  24625. this._dumbGroup.add(textEl);
  24626. textEl.updateTransform();
  24627. textEls.push(textEl);
  24628. this.group.add(textEl);
  24629. textEl.decomposeTransform();
  24630. }, this);
  24631. function isTwoLabelOverlapped(current, next) {
  24632. var firstRect = current && current.getBoundingRect().clone();
  24633. var nextRect = next && next.getBoundingRect().clone();
  24634. if (firstRect && nextRect) {
  24635. firstRect.applyTransform(current.getLocalTransform());
  24636. nextRect.applyTransform(next.getLocalTransform());
  24637. return firstRect.intersect(nextRect);
  24638. }
  24639. }
  24640. // If min or max are user set, we need to check
  24641. // If the tick on min(max) are overlap on their neighbour tick
  24642. // If they are overlapped, we need to hide the min(max) tick label
  24643. if (axisModel.getMin() != null) {
  24644. var firstLabel = textEls[0];
  24645. var nextLabel = textEls[1];
  24646. if (isTwoLabelOverlapped(firstLabel, nextLabel)) {
  24647. firstLabel.ignore = true;
  24648. }
  24649. }
  24650. if (axisModel.getMax() != null) {
  24651. var lastLabel = textEls[textEls.length - 1];
  24652. var prevLabel = textEls[textEls.length - 2];
  24653. if (isTwoLabelOverlapped(prevLabel, lastLabel)) {
  24654. lastLabel.ignore = true;
  24655. }
  24656. }
  24657. },
  24658. /**
  24659. * @private
  24660. */
  24661. axisName: function () {
  24662. var opt = this.opt;
  24663. var axisModel = this.axisModel;
  24664. var name = retrieve(opt.axisName, axisModel.get('name'));
  24665. if (!name) {
  24666. return;
  24667. }
  24668. var nameLocation = axisModel.get('nameLocation');
  24669. var nameDirection = opt.nameDirection;
  24670. var textStyleModel = axisModel.getModel('nameTextStyle');
  24671. var gap = axisModel.get('nameGap') || 0;
  24672. var extent = this.axisModel.axis.getExtent();
  24673. var gapSignal = extent[0] > extent[1] ? -1 : 1;
  24674. var pos = [
  24675. nameLocation === 'start'
  24676. ? extent[0] - gapSignal * gap
  24677. : nameLocation === 'end'
  24678. ? extent[1] + gapSignal * gap
  24679. : (extent[0] + extent[1]) / 2, // 'middle'
  24680. // Reuse labelOffset.
  24681. nameLocation === 'middle' ? opt.labelOffset + nameDirection * gap : 0
  24682. ];
  24683. var labelLayout;
  24684. var nameRotation = axisModel.get('nameRotate');
  24685. if (nameRotation != null) {
  24686. nameRotation = nameRotation * PI / 180; // To radian.
  24687. }
  24688. var axisNameAvailableWidth;
  24689. if (nameLocation === 'middle') {
  24690. labelLayout = innerTextLayout(
  24691. opt,
  24692. nameRotation != null ? nameRotation : opt.rotation, // Adapt to axis.
  24693. nameDirection
  24694. );
  24695. }
  24696. else {
  24697. labelLayout = endTextLayout(
  24698. opt, nameLocation, nameRotation || 0, extent
  24699. );
  24700. axisNameAvailableWidth = opt.axisNameAvailableWidth;
  24701. if (axisNameAvailableWidth != null) {
  24702. axisNameAvailableWidth = Math.abs(
  24703. axisNameAvailableWidth / Math.sin(labelLayout.rotation)
  24704. );
  24705. !isFinite(axisNameAvailableWidth) && (axisNameAvailableWidth = null);
  24706. }
  24707. }
  24708. var textFont = textStyleModel.getFont();
  24709. var truncateOpt = axisModel.get('nameTruncate', true) || {};
  24710. var ellipsis = truncateOpt.ellipsis;
  24711. var maxWidth = retrieve(truncateOpt.maxWidth, axisNameAvailableWidth);
  24712. var truncatedText = (ellipsis != null && maxWidth != null)
  24713. ? formatUtil.truncateText(
  24714. name, maxWidth, textFont, ellipsis,
  24715. {minChar: 2, placeholder: truncateOpt.placeholder}
  24716. )
  24717. : name;
  24718. var tooltipOpt = axisModel.get('tooltip', true);
  24719. var mainType = axisModel.mainType;
  24720. var formatterParams = {
  24721. componentType: mainType,
  24722. name: name,
  24723. $vars: ['name']
  24724. };
  24725. formatterParams[mainType + 'Index'] = axisModel.componentIndex;
  24726. var textEl = new graphic.Text({
  24727. // Id for animation
  24728. anid: 'name',
  24729. __fullText: name,
  24730. __truncatedText: truncatedText,
  24731. style: {
  24732. text: truncatedText,
  24733. textFont: textFont,
  24734. fill: textStyleModel.getTextColor()
  24735. || axisModel.get('axisLine.lineStyle.color'),
  24736. textAlign: labelLayout.textAlign,
  24737. textVerticalAlign: labelLayout.verticalAlign
  24738. },
  24739. position: pos,
  24740. rotation: labelLayout.rotation,
  24741. silent: isSilent(axisModel),
  24742. z2: 1,
  24743. tooltip: (tooltipOpt && tooltipOpt.show)
  24744. ? zrUtil.extend({
  24745. content: name,
  24746. formatter: function () {
  24747. return name;
  24748. },
  24749. formatterParams: formatterParams
  24750. }, tooltipOpt)
  24751. : null
  24752. });
  24753. if (axisModel.get('triggerEvent')) {
  24754. textEl.eventData = makeAxisEventDataBase(axisModel);
  24755. textEl.eventData.targetType = 'axisName';
  24756. textEl.eventData.name = name;
  24757. }
  24758. // FIXME
  24759. this._dumbGroup.add(textEl);
  24760. textEl.updateTransform();
  24761. this.group.add(textEl);
  24762. textEl.decomposeTransform();
  24763. }
  24764. };
  24765. /**
  24766. * @inner
  24767. */
  24768. function innerTextLayout(opt, textRotation, direction) {
  24769. var rotationDiff = remRadian(textRotation - opt.rotation);
  24770. var textAlign;
  24771. var verticalAlign;
  24772. if (isRadianAroundZero(rotationDiff)) { // Label is parallel with axis line.
  24773. verticalAlign = direction > 0 ? 'top' : 'bottom';
  24774. textAlign = 'center';
  24775. }
  24776. else if (isRadianAroundZero(rotationDiff - PI)) { // Label is inverse parallel with axis line.
  24777. verticalAlign = direction > 0 ? 'bottom' : 'top';
  24778. textAlign = 'center';
  24779. }
  24780. else {
  24781. verticalAlign = 'middle';
  24782. if (rotationDiff > 0 && rotationDiff < PI) {
  24783. textAlign = direction > 0 ? 'right' : 'left';
  24784. }
  24785. else {
  24786. textAlign = direction > 0 ? 'left' : 'right';
  24787. }
  24788. }
  24789. return {
  24790. rotation: rotationDiff,
  24791. textAlign: textAlign,
  24792. verticalAlign: verticalAlign
  24793. };
  24794. }
  24795. /**
  24796. * @inner
  24797. */
  24798. function endTextLayout(opt, textPosition, textRotate, extent) {
  24799. var rotationDiff = remRadian(textRotate - opt.rotation);
  24800. var textAlign;
  24801. var verticalAlign;
  24802. var inverse = extent[0] > extent[1];
  24803. var onLeft = (textPosition === 'start' && !inverse)
  24804. || (textPosition !== 'start' && inverse);
  24805. if (isRadianAroundZero(rotationDiff - PI / 2)) {
  24806. verticalAlign = onLeft ? 'bottom' : 'top';
  24807. textAlign = 'center';
  24808. }
  24809. else if (isRadianAroundZero(rotationDiff - PI * 1.5)) {
  24810. verticalAlign = onLeft ? 'top' : 'bottom';
  24811. textAlign = 'center';
  24812. }
  24813. else {
  24814. verticalAlign = 'middle';
  24815. if (rotationDiff < PI * 1.5 && rotationDiff > PI / 2) {
  24816. textAlign = onLeft ? 'left' : 'right';
  24817. }
  24818. else {
  24819. textAlign = onLeft ? 'right' : 'left';
  24820. }
  24821. }
  24822. return {
  24823. rotation: rotationDiff,
  24824. textAlign: textAlign,
  24825. verticalAlign: verticalAlign
  24826. };
  24827. }
  24828. /**
  24829. * @inner
  24830. */
  24831. function isSilent(axisModel) {
  24832. var tooltipOpt = axisModel.get('tooltip');
  24833. return axisModel.get('silent')
  24834. // Consider mouse cursor, add these restrictions.
  24835. || !(
  24836. axisModel.get('triggerEvent') || (tooltipOpt && tooltipOpt.show)
  24837. );
  24838. }
  24839. /**
  24840. * @static
  24841. */
  24842. var ifIgnoreOnTick = AxisBuilder.ifIgnoreOnTick = function (axis, i, interval) {
  24843. var rawTick;
  24844. var scale = axis.scale;
  24845. return scale.type === 'ordinal'
  24846. && (
  24847. typeof interval === 'function'
  24848. ? (
  24849. rawTick = scale.getTicks()[i],
  24850. !interval(rawTick, scale.getLabel(rawTick))
  24851. )
  24852. : i % (interval + 1)
  24853. );
  24854. };
  24855. /**
  24856. * @static
  24857. */
  24858. var getInterval = AxisBuilder.getInterval = function (model, labelInterval) {
  24859. var interval = model.get('interval');
  24860. if (interval == null || interval == 'auto') {
  24861. interval = labelInterval;
  24862. }
  24863. return interval;
  24864. };
  24865. module.exports = AxisBuilder;
  24866. /***/ },
  24867. /* 134 */
  24868. /***/ function(module, exports, __webpack_require__) {
  24869. var zrUtil = __webpack_require__(4);
  24870. __webpack_require__(114);
  24871. __webpack_require__(135);
  24872. __webpack_require__(137);
  24873. var barLayoutGrid = __webpack_require__(140);
  24874. var echarts = __webpack_require__(1);
  24875. echarts.registerLayout(zrUtil.curry(barLayoutGrid, 'bar'));
  24876. // Visual coding for legend
  24877. echarts.registerVisual(function (ecModel) {
  24878. ecModel.eachSeriesByType('bar', function (seriesModel) {
  24879. var data = seriesModel.getData();
  24880. data.setVisual('legendSymbol', 'roundRect');
  24881. });
  24882. });
  24883. // In case developer forget to include grid component
  24884. __webpack_require__(113);
  24885. /***/ },
  24886. /* 135 */
  24887. /***/ function(module, exports, __webpack_require__) {
  24888. module.exports = __webpack_require__(136).extend({
  24889. type: 'series.bar',
  24890. dependencies: ['grid', 'polar'],
  24891. brushSelector: 'rect'
  24892. });
  24893. /***/ },
  24894. /* 136 */
  24895. /***/ function(module, exports, __webpack_require__) {
  24896. 'use strict';
  24897. var SeriesModel = __webpack_require__(28);
  24898. var createListFromArray = __webpack_require__(102);
  24899. module.exports = SeriesModel.extend({
  24900. type: 'series.__base_bar__',
  24901. getInitialData: function (option, ecModel) {
  24902. if (true) {
  24903. var coordSys = option.coordinateSystem;
  24904. if (coordSys !== 'cartesian2d') {
  24905. throw new Error('Bar only support cartesian2d coordinateSystem');
  24906. }
  24907. }
  24908. return createListFromArray(option.data, this, ecModel);
  24909. },
  24910. getMarkerPosition: function (value) {
  24911. var coordSys = this.coordinateSystem;
  24912. if (coordSys) {
  24913. // PENDING if clamp ?
  24914. var pt = coordSys.dataToPoint(value, true);
  24915. var data = this.getData();
  24916. var offset = data.getLayout('offset');
  24917. var size = data.getLayout('size');
  24918. var offsetIndex = coordSys.getBaseAxis().isHorizontal() ? 0 : 1;
  24919. pt[offsetIndex] += offset + size / 2;
  24920. return pt;
  24921. }
  24922. return [NaN, NaN];
  24923. },
  24924. defaultOption: {
  24925. zlevel: 0, // 一级层叠
  24926. z: 2, // 二级层叠
  24927. coordinateSystem: 'cartesian2d',
  24928. legendHoverLink: true,
  24929. // stack: null
  24930. // Cartesian coordinate system
  24931. // xAxisIndex: 0,
  24932. // yAxisIndex: 0,
  24933. // 最小高度改为0
  24934. barMinHeight: 0,
  24935. // barMaxWidth: null,
  24936. // 默认自适应
  24937. // barWidth: null,
  24938. // 柱间距离,默认为柱形宽度的30%,可设固定值
  24939. // barGap: '30%',
  24940. // 类目间柱形距离,默认为类目间距的20%,可设固定值
  24941. // barCategoryGap: '20%',
  24942. // label: {
  24943. // normal: {
  24944. // show: false
  24945. // }
  24946. // },
  24947. itemStyle: {
  24948. normal: {
  24949. // color: '各异'
  24950. },
  24951. emphasis: {}
  24952. }
  24953. }
  24954. });
  24955. /***/ },
  24956. /* 137 */
  24957. /***/ function(module, exports, __webpack_require__) {
  24958. 'use strict';
  24959. var zrUtil = __webpack_require__(4);
  24960. var graphic = __webpack_require__(43);
  24961. var helper = __webpack_require__(138);
  24962. var BAR_BORDER_WIDTH_QUERY = ['itemStyle', 'normal', 'barBorderWidth'];
  24963. // FIXME
  24964. // Just for compatible with ec2.
  24965. zrUtil.extend(__webpack_require__(12).prototype, __webpack_require__(139));
  24966. var BarView = __webpack_require__(1).extendChartView({
  24967. type: 'bar',
  24968. render: function (seriesModel, ecModel, api) {
  24969. var coordinateSystemType = seriesModel.get('coordinateSystem');
  24970. if (coordinateSystemType === 'cartesian2d') {
  24971. this._renderOnCartesian(seriesModel, ecModel, api);
  24972. }
  24973. return this.group;
  24974. },
  24975. dispose: zrUtil.noop,
  24976. _renderOnCartesian: function (seriesModel, ecModel, api) {
  24977. var group = this.group;
  24978. var data = seriesModel.getData();
  24979. var oldData = this._data;
  24980. var cartesian = seriesModel.coordinateSystem;
  24981. var baseAxis = cartesian.getBaseAxis();
  24982. var isHorizontal = baseAxis.isHorizontal();
  24983. var animationModel = seriesModel.isAnimationEnabled() ? seriesModel : null;
  24984. data.diff(oldData)
  24985. .add(function (dataIndex) {
  24986. if (!data.hasValue(dataIndex)) {
  24987. return;
  24988. }
  24989. var itemModel = data.getItemModel(dataIndex);
  24990. var layout = getRectItemLayout(data, dataIndex, itemModel);
  24991. var el = createRect(data, dataIndex, itemModel, layout, isHorizontal, animationModel);
  24992. data.setItemGraphicEl(dataIndex, el);
  24993. group.add(el);
  24994. updateStyle(el, data, dataIndex, itemModel, layout, seriesModel, isHorizontal);
  24995. })
  24996. .update(function (newIndex, oldIndex) {
  24997. var el = oldData.getItemGraphicEl(oldIndex);
  24998. if (!data.hasValue(newIndex)) {
  24999. group.remove(el);
  25000. return;
  25001. }
  25002. var itemModel = data.getItemModel(newIndex);
  25003. var layout = getRectItemLayout(data, newIndex, itemModel);
  25004. if (el) {
  25005. graphic.updateProps(el, {shape: layout}, animationModel, newIndex);
  25006. }
  25007. else {
  25008. el = createRect(data, newIndex, itemModel, layout, isHorizontal, animationModel, true);
  25009. }
  25010. data.setItemGraphicEl(newIndex, el);
  25011. // Add back
  25012. group.add(el);
  25013. updateStyle(el, data, newIndex, itemModel, layout, seriesModel, isHorizontal);
  25014. })
  25015. .remove(function (dataIndex) {
  25016. var el = oldData.getItemGraphicEl(dataIndex);
  25017. el && removeRect(dataIndex, animationModel, el);
  25018. })
  25019. .execute();
  25020. this._data = data;
  25021. },
  25022. remove: function (ecModel, api) {
  25023. var group = this.group;
  25024. var data = this._data;
  25025. if (ecModel.get('animation')) {
  25026. if (data) {
  25027. data.eachItemGraphicEl(function (el) {
  25028. removeRect(el.dataIndex, ecModel, el);
  25029. });
  25030. }
  25031. }
  25032. else {
  25033. group.removeAll();
  25034. }
  25035. }
  25036. });
  25037. function createRect(data, dataIndex, itemModel, layout, isHorizontal, animationModel, isUpdate) {
  25038. var rect = new graphic.Rect({shape: zrUtil.extend({}, layout)});
  25039. // Animation
  25040. if (animationModel) {
  25041. var rectShape = rect.shape;
  25042. var animateProperty = isHorizontal ? 'height' : 'width';
  25043. var animateTarget = {};
  25044. rectShape[animateProperty] = 0;
  25045. animateTarget[animateProperty] = layout[animateProperty];
  25046. graphic[isUpdate ? 'updateProps' : 'initProps'](rect, {
  25047. shape: animateTarget
  25048. }, animationModel, dataIndex);
  25049. }
  25050. return rect;
  25051. }
  25052. function removeRect(dataIndex, animationModel, el) {
  25053. // Not show text when animating
  25054. el.style.text = '';
  25055. graphic.updateProps(el, {
  25056. shape: {
  25057. width: 0
  25058. }
  25059. }, animationModel, dataIndex, function () {
  25060. el.parent && el.parent.remove(el);
  25061. });
  25062. }
  25063. function getRectItemLayout(data, dataIndex, itemModel) {
  25064. var layout = data.getItemLayout(dataIndex);
  25065. var fixedLineWidth = getLineWidth(itemModel, layout);
  25066. // fix layout with lineWidth
  25067. var signX = layout.width > 0 ? 1 : -1;
  25068. var signY = layout.height > 0 ? 1 : -1;
  25069. return {
  25070. x: layout.x + signX * fixedLineWidth / 2,
  25071. y: layout.y + signY * fixedLineWidth / 2,
  25072. width: layout.width - signX * fixedLineWidth,
  25073. height: layout.height - signY * fixedLineWidth
  25074. };
  25075. }
  25076. function updateStyle(el, data, dataIndex, itemModel, layout, seriesModel, isHorizontal) {
  25077. var color = data.getItemVisual(dataIndex, 'color');
  25078. var opacity = data.getItemVisual(dataIndex, 'opacity');
  25079. var itemStyleModel = itemModel.getModel('itemStyle.normal');
  25080. var hoverStyle = itemModel.getModel('itemStyle.emphasis').getBarItemStyle();
  25081. el.setShape('r', itemStyleModel.get('barBorderRadius') || 0);
  25082. el.useStyle(zrUtil.defaults(
  25083. {
  25084. fill: color,
  25085. opacity: opacity
  25086. },
  25087. itemStyleModel.getBarItemStyle()
  25088. ));
  25089. var labelPositionOutside = isHorizontal
  25090. ? (layout.height > 0 ? 'bottom' : 'top')
  25091. : (layout.width > 0 ? 'left' : 'right');
  25092. helper.setLabel(
  25093. el.style, hoverStyle, itemModel, color,
  25094. seriesModel, dataIndex, labelPositionOutside
  25095. );
  25096. graphic.setHoverStyle(el, hoverStyle);
  25097. }
  25098. // In case width or height are too small.
  25099. function getLineWidth(itemModel, rawLayout) {
  25100. var lineWidth = itemModel.get(BAR_BORDER_WIDTH_QUERY) || 0;
  25101. return Math.min(lineWidth, Math.abs(rawLayout.width), Math.abs(rawLayout.height));
  25102. }
  25103. module.exports = BarView;
  25104. /***/ },
  25105. /* 138 */
  25106. /***/ function(module, exports, __webpack_require__) {
  25107. var zrUtil = __webpack_require__(4);
  25108. var graphic = __webpack_require__(43);
  25109. var helper = {};
  25110. helper.setLabel = function (
  25111. normalStyle, hoverStyle, itemModel, color, seriesModel, dataIndex, labelPositionOutside
  25112. ) {
  25113. var labelModel = itemModel.getModel('label.normal');
  25114. var hoverLabelModel = itemModel.getModel('label.emphasis');
  25115. if (labelModel.get('show')) {
  25116. setLabel(
  25117. normalStyle, labelModel, color,
  25118. zrUtil.retrieve(
  25119. seriesModel.getFormattedLabel(dataIndex, 'normal'),
  25120. seriesModel.getRawValue(dataIndex)
  25121. ),
  25122. labelPositionOutside
  25123. );
  25124. }
  25125. else {
  25126. normalStyle.text = '';
  25127. }
  25128. if (hoverLabelModel.get('show')) {
  25129. setLabel(
  25130. hoverStyle, hoverLabelModel, color,
  25131. zrUtil.retrieve(
  25132. seriesModel.getFormattedLabel(dataIndex, 'emphasis'),
  25133. seriesModel.getRawValue(dataIndex)
  25134. ),
  25135. labelPositionOutside
  25136. );
  25137. }
  25138. else {
  25139. hoverStyle.text = '';
  25140. }
  25141. };
  25142. function setLabel(style, model, color, labelText, labelPositionOutside) {
  25143. graphic.setText(style, model, color);
  25144. style.text = labelText;
  25145. if (style.textPosition === 'outside') {
  25146. style.textPosition = labelPositionOutside;
  25147. }
  25148. }
  25149. module.exports = helper;
  25150. /***/ },
  25151. /* 139 */
  25152. /***/ function(module, exports, __webpack_require__) {
  25153. var getBarItemStyle = __webpack_require__(15)(
  25154. [
  25155. ['fill', 'color'],
  25156. ['stroke', 'borderColor'],
  25157. ['lineWidth', 'borderWidth'],
  25158. // Compatitable with 2
  25159. ['stroke', 'barBorderColor'],
  25160. ['lineWidth', 'barBorderWidth'],
  25161. ['opacity'],
  25162. ['shadowBlur'],
  25163. ['shadowOffsetX'],
  25164. ['shadowOffsetY'],
  25165. ['shadowColor']
  25166. ]
  25167. );
  25168. module.exports = {
  25169. getBarItemStyle: function (excludes) {
  25170. var style = getBarItemStyle.call(this, excludes);
  25171. if (this.getBorderLineDash) {
  25172. var lineDash = this.getBorderLineDash();
  25173. lineDash && (style.lineDash = lineDash);
  25174. }
  25175. return style;
  25176. }
  25177. };
  25178. /***/ },
  25179. /* 140 */
  25180. /***/ function(module, exports, __webpack_require__) {
  25181. 'use strict';
  25182. var zrUtil = __webpack_require__(4);
  25183. var numberUtil = __webpack_require__(7);
  25184. var parsePercent = numberUtil.parsePercent;
  25185. function getSeriesStackId(seriesModel) {
  25186. return seriesModel.get('stack') || '__ec_stack_' + seriesModel.seriesIndex;
  25187. }
  25188. function getAxisKey(axis) {
  25189. return axis.dim + axis.index;
  25190. }
  25191. function calBarWidthAndOffset(barSeries, api) {
  25192. // Columns info on each category axis. Key is cartesian name
  25193. var columnsMap = {};
  25194. zrUtil.each(barSeries, function (seriesModel, idx) {
  25195. var data = seriesModel.getData();
  25196. var cartesian = seriesModel.coordinateSystem;
  25197. var baseAxis = cartesian.getBaseAxis();
  25198. var axisExtent = baseAxis.getExtent();
  25199. var bandWidth = baseAxis.type === 'category'
  25200. ? baseAxis.getBandWidth()
  25201. : (Math.abs(axisExtent[1] - axisExtent[0]) / data.count());
  25202. var columnsOnAxis = columnsMap[getAxisKey(baseAxis)] || {
  25203. bandWidth: bandWidth,
  25204. remainedWidth: bandWidth,
  25205. autoWidthCount: 0,
  25206. categoryGap: '20%',
  25207. gap: '30%',
  25208. stacks: {}
  25209. };
  25210. var stacks = columnsOnAxis.stacks;
  25211. columnsMap[getAxisKey(baseAxis)] = columnsOnAxis;
  25212. var stackId = getSeriesStackId(seriesModel);
  25213. if (!stacks[stackId]) {
  25214. columnsOnAxis.autoWidthCount++;
  25215. }
  25216. stacks[stackId] = stacks[stackId] || {
  25217. width: 0,
  25218. maxWidth: 0
  25219. };
  25220. var barWidth = parsePercent(
  25221. seriesModel.get('barWidth'), bandWidth
  25222. );
  25223. var barMaxWidth = parsePercent(
  25224. seriesModel.get('barMaxWidth'), bandWidth
  25225. );
  25226. var barGap = seriesModel.get('barGap');
  25227. var barCategoryGap = seriesModel.get('barCategoryGap');
  25228. // Caution: In a single coordinate system, these barGrid attributes
  25229. // will be shared by series. Consider that they have default values,
  25230. // only the attributes set on the last series will work.
  25231. // Do not change this fact unless there will be a break change.
  25232. // TODO
  25233. if (barWidth && !stacks[stackId].width) {
  25234. barWidth = Math.min(columnsOnAxis.remainedWidth, barWidth);
  25235. stacks[stackId].width = barWidth;
  25236. columnsOnAxis.remainedWidth -= barWidth;
  25237. }
  25238. barMaxWidth && (stacks[stackId].maxWidth = barMaxWidth);
  25239. (barGap != null) && (columnsOnAxis.gap = barGap);
  25240. (barCategoryGap != null) && (columnsOnAxis.categoryGap = barCategoryGap);
  25241. });
  25242. var result = {};
  25243. zrUtil.each(columnsMap, function (columnsOnAxis, coordSysName) {
  25244. result[coordSysName] = {};
  25245. var stacks = columnsOnAxis.stacks;
  25246. var bandWidth = columnsOnAxis.bandWidth;
  25247. var categoryGap = parsePercent(columnsOnAxis.categoryGap, bandWidth);
  25248. var barGapPercent = parsePercent(columnsOnAxis.gap, 1);
  25249. var remainedWidth = columnsOnAxis.remainedWidth;
  25250. var autoWidthCount = columnsOnAxis.autoWidthCount;
  25251. var autoWidth = (remainedWidth - categoryGap)
  25252. / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  25253. autoWidth = Math.max(autoWidth, 0);
  25254. // Find if any auto calculated bar exceeded maxBarWidth
  25255. zrUtil.each(stacks, function (column, stack) {
  25256. var maxWidth = column.maxWidth;
  25257. if (!column.width && maxWidth && maxWidth < autoWidth) {
  25258. maxWidth = Math.min(maxWidth, remainedWidth);
  25259. remainedWidth -= maxWidth;
  25260. column.width = maxWidth;
  25261. autoWidthCount--;
  25262. }
  25263. });
  25264. // Recalculate width again
  25265. autoWidth = (remainedWidth - categoryGap)
  25266. / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  25267. autoWidth = Math.max(autoWidth, 0);
  25268. var widthSum = 0;
  25269. var lastColumn;
  25270. zrUtil.each(stacks, function (column, idx) {
  25271. if (!column.width) {
  25272. column.width = autoWidth;
  25273. }
  25274. lastColumn = column;
  25275. widthSum += column.width * (1 + barGapPercent);
  25276. });
  25277. if (lastColumn) {
  25278. widthSum -= lastColumn.width * barGapPercent;
  25279. }
  25280. var offset = -widthSum / 2;
  25281. zrUtil.each(stacks, function (column, stackId) {
  25282. result[coordSysName][stackId] = result[coordSysName][stackId] || {
  25283. offset: offset,
  25284. width: column.width
  25285. };
  25286. offset += column.width * (1 + barGapPercent);
  25287. });
  25288. });
  25289. return result;
  25290. }
  25291. /**
  25292. * @param {string} seriesType
  25293. * @param {module:echarts/model/Global} ecModel
  25294. * @param {module:echarts/ExtensionAPI} api
  25295. */
  25296. function barLayoutGrid(seriesType, ecModel, api) {
  25297. var barWidthAndOffset = calBarWidthAndOffset(
  25298. zrUtil.filter(
  25299. ecModel.getSeriesByType(seriesType),
  25300. function (seriesModel) {
  25301. return !ecModel.isSeriesFiltered(seriesModel)
  25302. && seriesModel.coordinateSystem
  25303. && seriesModel.coordinateSystem.type === 'cartesian2d';
  25304. }
  25305. )
  25306. );
  25307. var lastStackCoords = {};
  25308. var lastStackCoordsOrigin = {};
  25309. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  25310. var data = seriesModel.getData();
  25311. var cartesian = seriesModel.coordinateSystem;
  25312. var baseAxis = cartesian.getBaseAxis();
  25313. var stackId = getSeriesStackId(seriesModel);
  25314. var columnLayoutInfo = barWidthAndOffset[getAxisKey(baseAxis)][stackId];
  25315. var columnOffset = columnLayoutInfo.offset;
  25316. var columnWidth = columnLayoutInfo.width;
  25317. var valueAxis = cartesian.getOtherAxis(baseAxis);
  25318. var barMinHeight = seriesModel.get('barMinHeight') || 0;
  25319. var valueAxisStart = baseAxis.onZero
  25320. ? valueAxis.toGlobalCoord(valueAxis.dataToCoord(0))
  25321. : valueAxis.getGlobalExtent()[0];
  25322. var coords = cartesian.dataToPoints(data, true);
  25323. lastStackCoords[stackId] = lastStackCoords[stackId] || [];
  25324. lastStackCoordsOrigin[stackId] = lastStackCoordsOrigin[stackId] || []; // Fix #4243
  25325. data.setLayout({
  25326. offset: columnOffset,
  25327. size: columnWidth
  25328. });
  25329. data.each(valueAxis.dim, function (value, idx) {
  25330. if (isNaN(value)) {
  25331. return;
  25332. }
  25333. if (!lastStackCoords[stackId][idx]) {
  25334. lastStackCoords[stackId][idx] = {
  25335. p: valueAxisStart, // Positive stack
  25336. n: valueAxisStart // Negative stack
  25337. };
  25338. lastStackCoordsOrigin[stackId][idx] = {
  25339. p: valueAxisStart, // Positive stack
  25340. n: valueAxisStart // Negative stack
  25341. };
  25342. }
  25343. var sign = value >= 0 ? 'p' : 'n';
  25344. var coord = coords[idx];
  25345. var lastCoord = lastStackCoords[stackId][idx][sign];
  25346. var lastCoordOrigin = lastStackCoordsOrigin[stackId][idx][sign];
  25347. var x;
  25348. var y;
  25349. var width;
  25350. var height;
  25351. if (valueAxis.isHorizontal()) {
  25352. x = lastCoord;
  25353. y = coord[1] + columnOffset;
  25354. width = coord[0] - lastCoordOrigin;
  25355. height = columnWidth;
  25356. lastStackCoordsOrigin[stackId][idx][sign] += width;
  25357. if (Math.abs(width) < barMinHeight) {
  25358. width = (width < 0 ? -1 : 1) * barMinHeight;
  25359. }
  25360. lastStackCoords[stackId][idx][sign] += width;
  25361. }
  25362. else {
  25363. x = coord[0] + columnOffset;
  25364. y = lastCoord;
  25365. width = columnWidth;
  25366. height = coord[1] - lastCoordOrigin;
  25367. lastStackCoordsOrigin[stackId][idx][sign] += height;
  25368. if (Math.abs(height) < barMinHeight) {
  25369. // Include zero to has a positive bar
  25370. height = (height <= 0 ? -1 : 1) * barMinHeight;
  25371. }
  25372. lastStackCoords[stackId][idx][sign] += height;
  25373. }
  25374. data.setItemLayout(idx, {
  25375. x: x,
  25376. y: y,
  25377. width: width,
  25378. height: height
  25379. });
  25380. }, true);
  25381. }, this);
  25382. }
  25383. module.exports = barLayoutGrid;
  25384. /***/ },
  25385. /* 141 */
  25386. /***/ function(module, exports, __webpack_require__) {
  25387. var zrUtil = __webpack_require__(4);
  25388. var echarts = __webpack_require__(1);
  25389. __webpack_require__(142);
  25390. __webpack_require__(144);
  25391. __webpack_require__(145)('pie', [{
  25392. type: 'pieToggleSelect',
  25393. event: 'pieselectchanged',
  25394. method: 'toggleSelected'
  25395. }, {
  25396. type: 'pieSelect',
  25397. event: 'pieselected',
  25398. method: 'select'
  25399. }, {
  25400. type: 'pieUnSelect',
  25401. event: 'pieunselected',
  25402. method: 'unSelect'
  25403. }]);
  25404. echarts.registerVisual(zrUtil.curry(__webpack_require__(146), 'pie'));
  25405. echarts.registerLayout(zrUtil.curry(
  25406. __webpack_require__(147), 'pie'
  25407. ));
  25408. echarts.registerProcessor(zrUtil.curry(__webpack_require__(149), 'pie'));
  25409. /***/ },
  25410. /* 142 */
  25411. /***/ function(module, exports, __webpack_require__) {
  25412. 'use strict';
  25413. var List = __webpack_require__(98);
  25414. var zrUtil = __webpack_require__(4);
  25415. var modelUtil = __webpack_require__(5);
  25416. var completeDimensions = __webpack_require__(103);
  25417. var dataSelectableMixin = __webpack_require__(143);
  25418. var PieSeries = __webpack_require__(1).extendSeriesModel({
  25419. type: 'series.pie',
  25420. // Overwrite
  25421. init: function (option) {
  25422. PieSeries.superApply(this, 'init', arguments);
  25423. // Enable legend selection for each data item
  25424. // Use a function instead of direct access because data reference may changed
  25425. this.legendDataProvider = function () {
  25426. return this.getRawData();
  25427. };
  25428. this.updateSelectedMap(option.data);
  25429. this._defaultLabelLine(option);
  25430. },
  25431. // Overwrite
  25432. mergeOption: function (newOption) {
  25433. PieSeries.superCall(this, 'mergeOption', newOption);
  25434. this.updateSelectedMap(this.option.data);
  25435. },
  25436. getInitialData: function (option, ecModel) {
  25437. var dimensions = completeDimensions(['value'], option.data);
  25438. var list = new List(dimensions, this);
  25439. list.initData(option.data);
  25440. return list;
  25441. },
  25442. // Overwrite
  25443. getDataParams: function (dataIndex) {
  25444. var data = this.getData();
  25445. var params = PieSeries.superCall(this, 'getDataParams', dataIndex);
  25446. var sum = data.getSum('value');
  25447. // FIXME toFixed?
  25448. //
  25449. // Percent is 0 if sum is 0
  25450. params.percent = !sum ? 0 : +(data.get('value', dataIndex) / sum * 100).toFixed(2);
  25451. params.$vars.push('percent');
  25452. return params;
  25453. },
  25454. _defaultLabelLine: function (option) {
  25455. // Extend labelLine emphasis
  25456. modelUtil.defaultEmphasis(option.labelLine, ['show']);
  25457. var labelLineNormalOpt = option.labelLine.normal;
  25458. var labelLineEmphasisOpt = option.labelLine.emphasis;
  25459. // Not show label line if `label.normal.show = false`
  25460. labelLineNormalOpt.show = labelLineNormalOpt.show
  25461. && option.label.normal.show;
  25462. labelLineEmphasisOpt.show = labelLineEmphasisOpt.show
  25463. && option.label.emphasis.show;
  25464. },
  25465. defaultOption: {
  25466. zlevel: 0,
  25467. z: 2,
  25468. legendHoverLink: true,
  25469. hoverAnimation: true,
  25470. // 默认全局居中
  25471. center: ['50%', '50%'],
  25472. radius: [0, '75%'],
  25473. // 默认顺时针
  25474. clockwise: true,
  25475. startAngle: 90,
  25476. // 最小角度改为0
  25477. minAngle: 0,
  25478. // 选中是扇区偏移量
  25479. selectedOffset: 10,
  25480. // If use strategy to avoid label overlapping
  25481. avoidLabelOverlap: true,
  25482. // 选择模式,默认关闭,可选single,multiple
  25483. // selectedMode: false,
  25484. // 南丁格尔玫瑰图模式,'radius'(半径) | 'area'(面积)
  25485. // roseType: null,
  25486. // If still show when all data zero.
  25487. stillShowZeroSum: true,
  25488. label: {
  25489. normal: {
  25490. // If rotate around circle
  25491. rotate: false,
  25492. show: true,
  25493. // 'outer', 'inside', 'center'
  25494. position: 'outer'
  25495. // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  25496. // textStyle: null // 默认使用全局文本样式,详见TEXTSTYLE
  25497. // distance: 当position为inner时有效,为label位置到圆心的距离与圆半径(环状图为内外半径和)的比例系数
  25498. },
  25499. emphasis: {}
  25500. },
  25501. // Enabled when label.normal.position is 'outer'
  25502. labelLine: {
  25503. normal: {
  25504. show: true,
  25505. // 引导线两段中的第一段长度
  25506. length: 15,
  25507. // 引导线两段中的第二段长度
  25508. length2: 15,
  25509. smooth: false,
  25510. lineStyle: {
  25511. // color: 各异,
  25512. width: 1,
  25513. type: 'solid'
  25514. }
  25515. }
  25516. },
  25517. itemStyle: {
  25518. normal: {
  25519. borderWidth: 1
  25520. },
  25521. emphasis: {}
  25522. },
  25523. // Animation type canbe expansion, scale
  25524. animationType: 'expansion',
  25525. animationEasing: 'cubicOut',
  25526. data: []
  25527. }
  25528. });
  25529. zrUtil.mixin(PieSeries, dataSelectableMixin);
  25530. module.exports = PieSeries;
  25531. /***/ },
  25532. /* 143 */
  25533. /***/ function(module, exports, __webpack_require__) {
  25534. /**
  25535. * Data selectable mixin for chart series.
  25536. * To eanble data select, option of series must have `selectedMode`.
  25537. * And each data item will use `selected` to toggle itself selected status
  25538. *
  25539. * @module echarts/chart/helper/DataSelectable
  25540. */
  25541. var zrUtil = __webpack_require__(4);
  25542. module.exports = {
  25543. updateSelectedMap: function (targetList) {
  25544. this._selectTargetMap = zrUtil.reduce(targetList || [], function (targetMap, target) {
  25545. targetMap[target.name] = target;
  25546. return targetMap;
  25547. }, {});
  25548. },
  25549. /**
  25550. * @param {string} name
  25551. */
  25552. // PENGING If selectedMode is null ?
  25553. select: function (name) {
  25554. var targetMap = this._selectTargetMap;
  25555. var target = targetMap[name];
  25556. var selectedMode = this.get('selectedMode');
  25557. if (selectedMode === 'single') {
  25558. zrUtil.each(targetMap, function (target) {
  25559. target.selected = false;
  25560. });
  25561. }
  25562. target && (target.selected = true);
  25563. },
  25564. /**
  25565. * @param {string} name
  25566. */
  25567. unSelect: function (name) {
  25568. var target = this._selectTargetMap[name];
  25569. // var selectedMode = this.get('selectedMode');
  25570. // selectedMode !== 'single' && target && (target.selected = false);
  25571. target && (target.selected = false);
  25572. },
  25573. /**
  25574. * @param {string} name
  25575. */
  25576. toggleSelected: function (name) {
  25577. var target = this._selectTargetMap[name];
  25578. if (target != null) {
  25579. this[target.selected ? 'unSelect' : 'select'](name);
  25580. return target.selected;
  25581. }
  25582. },
  25583. /**
  25584. * @param {string} name
  25585. */
  25586. isSelected: function (name) {
  25587. var target = this._selectTargetMap[name];
  25588. return target && target.selected;
  25589. }
  25590. };
  25591. /***/ },
  25592. /* 144 */
  25593. /***/ function(module, exports, __webpack_require__) {
  25594. var graphic = __webpack_require__(43);
  25595. var zrUtil = __webpack_require__(4);
  25596. /**
  25597. * @param {module:echarts/model/Series} seriesModel
  25598. * @param {boolean} hasAnimation
  25599. * @inner
  25600. */
  25601. function updateDataSelected(uid, seriesModel, hasAnimation, api) {
  25602. var data = seriesModel.getData();
  25603. var dataIndex = this.dataIndex;
  25604. var name = data.getName(dataIndex);
  25605. var selectedOffset = seriesModel.get('selectedOffset');
  25606. api.dispatchAction({
  25607. type: 'pieToggleSelect',
  25608. from: uid,
  25609. name: name,
  25610. seriesId: seriesModel.id
  25611. });
  25612. data.each(function (idx) {
  25613. toggleItemSelected(
  25614. data.getItemGraphicEl(idx),
  25615. data.getItemLayout(idx),
  25616. seriesModel.isSelected(data.getName(idx)),
  25617. selectedOffset,
  25618. hasAnimation
  25619. );
  25620. });
  25621. }
  25622. /**
  25623. * @param {module:zrender/graphic/Sector} el
  25624. * @param {Object} layout
  25625. * @param {boolean} isSelected
  25626. * @param {number} selectedOffset
  25627. * @param {boolean} hasAnimation
  25628. * @inner
  25629. */
  25630. function toggleItemSelected(el, layout, isSelected, selectedOffset, hasAnimation) {
  25631. var midAngle = (layout.startAngle + layout.endAngle) / 2;
  25632. var dx = Math.cos(midAngle);
  25633. var dy = Math.sin(midAngle);
  25634. var offset = isSelected ? selectedOffset : 0;
  25635. var position = [dx * offset, dy * offset];
  25636. hasAnimation
  25637. // animateTo will stop revious animation like update transition
  25638. ? el.animate()
  25639. .when(200, {
  25640. position: position
  25641. })
  25642. .start('bounceOut')
  25643. : el.attr('position', position);
  25644. }
  25645. /**
  25646. * Piece of pie including Sector, Label, LabelLine
  25647. * @constructor
  25648. * @extends {module:zrender/graphic/Group}
  25649. */
  25650. function PiePiece(data, idx) {
  25651. graphic.Group.call(this);
  25652. var sector = new graphic.Sector({
  25653. z2: 2
  25654. });
  25655. var polyline = new graphic.Polyline();
  25656. var text = new graphic.Text();
  25657. this.add(sector);
  25658. this.add(polyline);
  25659. this.add(text);
  25660. this.updateData(data, idx, true);
  25661. // Hover to change label and labelLine
  25662. function onEmphasis() {
  25663. polyline.ignore = polyline.hoverIgnore;
  25664. text.ignore = text.hoverIgnore;
  25665. }
  25666. function onNormal() {
  25667. polyline.ignore = polyline.normalIgnore;
  25668. text.ignore = text.normalIgnore;
  25669. }
  25670. this.on('emphasis', onEmphasis)
  25671. .on('normal', onNormal)
  25672. .on('mouseover', onEmphasis)
  25673. .on('mouseout', onNormal);
  25674. }
  25675. var piePieceProto = PiePiece.prototype;
  25676. function getLabelStyle(data, idx, state, labelModel, labelPosition) {
  25677. var textStyleModel = labelModel.getModel('textStyle');
  25678. var isLabelInside = labelPosition === 'inside' || labelPosition === 'inner';
  25679. return {
  25680. fill: textStyleModel.getTextColor()
  25681. || (isLabelInside ? '#fff' : data.getItemVisual(idx, 'color')),
  25682. opacity: data.getItemVisual(idx, 'opacity'),
  25683. textFont: textStyleModel.getFont(),
  25684. text: zrUtil.retrieve(
  25685. data.hostModel.getFormattedLabel(idx, state), data.getName(idx)
  25686. )
  25687. };
  25688. }
  25689. piePieceProto.updateData = function (data, idx, firstCreate) {
  25690. var sector = this.childAt(0);
  25691. var seriesModel = data.hostModel;
  25692. var itemModel = data.getItemModel(idx);
  25693. var layout = data.getItemLayout(idx);
  25694. var sectorShape = zrUtil.extend({}, layout);
  25695. sectorShape.label = null;
  25696. if (firstCreate) {
  25697. sector.setShape(sectorShape);
  25698. var animationType = seriesModel.getShallow('animationType');
  25699. if (animationType === 'scale') {
  25700. sector.shape.r = layout.r0;
  25701. graphic.initProps(sector, {
  25702. shape: {
  25703. r: layout.r
  25704. }
  25705. }, seriesModel, idx);
  25706. }
  25707. // Expansion
  25708. else {
  25709. sector.shape.endAngle = layout.startAngle;
  25710. graphic.updateProps(sector, {
  25711. shape: {
  25712. endAngle: layout.endAngle
  25713. }
  25714. }, seriesModel, idx);
  25715. }
  25716. }
  25717. else {
  25718. graphic.updateProps(sector, {
  25719. shape: sectorShape
  25720. }, seriesModel, idx);
  25721. }
  25722. // Update common style
  25723. var itemStyleModel = itemModel.getModel('itemStyle');
  25724. var visualColor = data.getItemVisual(idx, 'color');
  25725. sector.useStyle(
  25726. zrUtil.defaults(
  25727. {
  25728. lineJoin: 'bevel',
  25729. fill: visualColor
  25730. },
  25731. itemStyleModel.getModel('normal').getItemStyle()
  25732. )
  25733. );
  25734. sector.hoverStyle = itemStyleModel.getModel('emphasis').getItemStyle();
  25735. // Toggle selected
  25736. toggleItemSelected(
  25737. this,
  25738. data.getItemLayout(idx),
  25739. itemModel.get('selected'),
  25740. seriesModel.get('selectedOffset'),
  25741. seriesModel.get('animation')
  25742. );
  25743. function onEmphasis() {
  25744. // Sector may has animation of updating data. Force to move to the last frame
  25745. // Or it may stopped on the wrong shape
  25746. sector.stopAnimation(true);
  25747. sector.animateTo({
  25748. shape: {
  25749. r: layout.r + 10
  25750. }
  25751. }, 300, 'elasticOut');
  25752. }
  25753. function onNormal() {
  25754. sector.stopAnimation(true);
  25755. sector.animateTo({
  25756. shape: {
  25757. r: layout.r
  25758. }
  25759. }, 300, 'elasticOut');
  25760. }
  25761. sector.off('mouseover').off('mouseout').off('emphasis').off('normal');
  25762. if (itemModel.get('hoverAnimation') && seriesModel.isAnimationEnabled()) {
  25763. sector
  25764. .on('mouseover', onEmphasis)
  25765. .on('mouseout', onNormal)
  25766. .on('emphasis', onEmphasis)
  25767. .on('normal', onNormal);
  25768. }
  25769. this._updateLabel(data, idx);
  25770. graphic.setHoverStyle(this);
  25771. };
  25772. piePieceProto._updateLabel = function (data, idx) {
  25773. var labelLine = this.childAt(1);
  25774. var labelText = this.childAt(2);
  25775. var seriesModel = data.hostModel;
  25776. var itemModel = data.getItemModel(idx);
  25777. var layout = data.getItemLayout(idx);
  25778. var labelLayout = layout.label;
  25779. var visualColor = data.getItemVisual(idx, 'color');
  25780. graphic.updateProps(labelLine, {
  25781. shape: {
  25782. points: labelLayout.linePoints || [
  25783. [labelLayout.x, labelLayout.y], [labelLayout.x, labelLayout.y], [labelLayout.x, labelLayout.y]
  25784. ]
  25785. }
  25786. }, seriesModel, idx);
  25787. graphic.updateProps(labelText, {
  25788. style: {
  25789. x: labelLayout.x,
  25790. y: labelLayout.y
  25791. }
  25792. }, seriesModel, idx);
  25793. labelText.attr({
  25794. style: {
  25795. textVerticalAlign: labelLayout.verticalAlign,
  25796. textAlign: labelLayout.textAlign,
  25797. textFont: labelLayout.font
  25798. },
  25799. rotation: labelLayout.rotation,
  25800. origin: [labelLayout.x, labelLayout.y],
  25801. z2: 10
  25802. });
  25803. var labelModel = itemModel.getModel('label.normal');
  25804. var labelHoverModel = itemModel.getModel('label.emphasis');
  25805. var labelLineModel = itemModel.getModel('labelLine.normal');
  25806. var labelLineHoverModel = itemModel.getModel('labelLine.emphasis');
  25807. var labelPosition = labelModel.get('position') || labelHoverModel.get('position');
  25808. labelText.setStyle(getLabelStyle(data, idx, 'normal', labelModel, labelPosition));
  25809. labelText.ignore = labelText.normalIgnore = !labelModel.get('show');
  25810. labelText.hoverIgnore = !labelHoverModel.get('show');
  25811. labelLine.ignore = labelLine.normalIgnore = !labelLineModel.get('show');
  25812. labelLine.hoverIgnore = !labelLineHoverModel.get('show');
  25813. // Default use item visual color
  25814. labelLine.setStyle({
  25815. stroke: visualColor,
  25816. opacity: data.getItemVisual(idx, 'opacity')
  25817. });
  25818. labelLine.setStyle(labelLineModel.getModel('lineStyle').getLineStyle());
  25819. labelText.hoverStyle = getLabelStyle(data, idx, 'emphasis', labelHoverModel, labelPosition);
  25820. labelLine.hoverStyle = labelLineHoverModel.getModel('lineStyle').getLineStyle();
  25821. var smooth = labelLineModel.get('smooth');
  25822. if (smooth && smooth === true) {
  25823. smooth = 0.4;
  25824. }
  25825. labelLine.setShape({
  25826. smooth: smooth
  25827. });
  25828. };
  25829. zrUtil.inherits(PiePiece, graphic.Group);
  25830. // Pie view
  25831. var Pie = __webpack_require__(42).extend({
  25832. type: 'pie',
  25833. init: function () {
  25834. var sectorGroup = new graphic.Group();
  25835. this._sectorGroup = sectorGroup;
  25836. },
  25837. render: function (seriesModel, ecModel, api, payload) {
  25838. if (payload && (payload.from === this.uid)) {
  25839. return;
  25840. }
  25841. var data = seriesModel.getData();
  25842. var oldData = this._data;
  25843. var group = this.group;
  25844. var hasAnimation = ecModel.get('animation');
  25845. var isFirstRender = !oldData;
  25846. var animationType = seriesModel.get('animationType');
  25847. var onSectorClick = zrUtil.curry(
  25848. updateDataSelected, this.uid, seriesModel, hasAnimation, api
  25849. );
  25850. var selectedMode = seriesModel.get('selectedMode');
  25851. data.diff(oldData)
  25852. .add(function (idx) {
  25853. var piePiece = new PiePiece(data, idx);
  25854. // Default expansion animation
  25855. if (isFirstRender && animationType !== 'scale') {
  25856. piePiece.eachChild(function (child) {
  25857. child.stopAnimation(true);
  25858. });
  25859. }
  25860. selectedMode && piePiece.on('click', onSectorClick);
  25861. data.setItemGraphicEl(idx, piePiece);
  25862. group.add(piePiece);
  25863. })
  25864. .update(function (newIdx, oldIdx) {
  25865. var piePiece = oldData.getItemGraphicEl(oldIdx);
  25866. piePiece.updateData(data, newIdx);
  25867. piePiece.off('click');
  25868. selectedMode && piePiece.on('click', onSectorClick);
  25869. group.add(piePiece);
  25870. data.setItemGraphicEl(newIdx, piePiece);
  25871. })
  25872. .remove(function (idx) {
  25873. var piePiece = oldData.getItemGraphicEl(idx);
  25874. group.remove(piePiece);
  25875. })
  25876. .execute();
  25877. if (
  25878. hasAnimation && isFirstRender && data.count() > 0
  25879. // Default expansion animation
  25880. && animationType !== 'scale'
  25881. ) {
  25882. var shape = data.getItemLayout(0);
  25883. var r = Math.max(api.getWidth(), api.getHeight()) / 2;
  25884. var removeClipPath = zrUtil.bind(group.removeClipPath, group);
  25885. group.setClipPath(this._createClipPath(
  25886. shape.cx, shape.cy, r, shape.startAngle, shape.clockwise, removeClipPath, seriesModel
  25887. ));
  25888. }
  25889. this._data = data;
  25890. },
  25891. dispose: function () {},
  25892. _createClipPath: function (
  25893. cx, cy, r, startAngle, clockwise, cb, seriesModel
  25894. ) {
  25895. var clipPath = new graphic.Sector({
  25896. shape: {
  25897. cx: cx,
  25898. cy: cy,
  25899. r0: 0,
  25900. r: r,
  25901. startAngle: startAngle,
  25902. endAngle: startAngle,
  25903. clockwise: clockwise
  25904. }
  25905. });
  25906. graphic.initProps(clipPath, {
  25907. shape: {
  25908. endAngle: startAngle + (clockwise ? 1 : -1) * Math.PI * 2
  25909. }
  25910. }, seriesModel, cb);
  25911. return clipPath;
  25912. },
  25913. /**
  25914. * @implement
  25915. */
  25916. containPoint: function (point, seriesModel) {
  25917. var data = seriesModel.getData();
  25918. var itemLayout = data.getItemLayout(0);
  25919. if (itemLayout) {
  25920. var dx = point[0] - itemLayout.cx;
  25921. var dy = point[1] - itemLayout.cy;
  25922. var radius = Math.sqrt(dx * dx + dy * dy);
  25923. return radius <= itemLayout.r && radius >= itemLayout.r0;
  25924. }
  25925. }
  25926. });
  25927. module.exports = Pie;
  25928. /***/ },
  25929. /* 145 */
  25930. /***/ function(module, exports, __webpack_require__) {
  25931. var echarts = __webpack_require__(1);
  25932. var zrUtil = __webpack_require__(4);
  25933. module.exports = function (seriesType, actionInfos) {
  25934. zrUtil.each(actionInfos, function (actionInfo) {
  25935. actionInfo.update = 'updateView';
  25936. /**
  25937. * @payload
  25938. * @property {string} seriesName
  25939. * @property {string} name
  25940. */
  25941. echarts.registerAction(actionInfo, function (payload, ecModel) {
  25942. var selected = {};
  25943. ecModel.eachComponent(
  25944. {mainType: 'series', subType: seriesType, query: payload},
  25945. function (seriesModel) {
  25946. if (seriesModel[actionInfo.method]) {
  25947. seriesModel[actionInfo.method](payload.name);
  25948. }
  25949. var data = seriesModel.getData();
  25950. // Create selected map
  25951. data.each(function (idx) {
  25952. var name = data.getName(idx);
  25953. selected[name] = seriesModel.isSelected(name) || false;
  25954. });
  25955. }
  25956. );
  25957. return {
  25958. name: payload.name,
  25959. selected: selected
  25960. };
  25961. });
  25962. });
  25963. };
  25964. /***/ },
  25965. /* 146 */
  25966. /***/ function(module, exports) {
  25967. // Pick color from palette for each data item.
  25968. // Applicable for charts that require applying color palette
  25969. // in data level (like pie, funnel, chord).
  25970. module.exports = function (seriesType, ecModel) {
  25971. // Pie and funnel may use diferrent scope
  25972. var paletteScope = {};
  25973. ecModel.eachRawSeriesByType(seriesType, function (seriesModel) {
  25974. var dataAll = seriesModel.getRawData();
  25975. var idxMap = {};
  25976. if (!ecModel.isSeriesFiltered(seriesModel)) {
  25977. var data = seriesModel.getData();
  25978. data.each(function (idx) {
  25979. var rawIdx = data.getRawIndex(idx);
  25980. idxMap[rawIdx] = idx;
  25981. });
  25982. dataAll.each(function (rawIdx) {
  25983. var filteredIdx = idxMap[rawIdx];
  25984. // If series.itemStyle.normal.color is a function. itemVisual may be encoded
  25985. var singleDataColor = filteredIdx != null
  25986. && data.getItemVisual(filteredIdx, 'color', true);
  25987. if (!singleDataColor) {
  25988. // FIXME Performance
  25989. var itemModel = dataAll.getItemModel(rawIdx);
  25990. var color = itemModel.get('itemStyle.normal.color')
  25991. || seriesModel.getColorFromPalette(dataAll.getName(rawIdx), paletteScope);
  25992. // Legend may use the visual info in data before processed
  25993. dataAll.setItemVisual(rawIdx, 'color', color);
  25994. // Data is not filtered
  25995. if (filteredIdx != null) {
  25996. data.setItemVisual(filteredIdx, 'color', color);
  25997. }
  25998. }
  25999. else {
  26000. // Set data all color for legend
  26001. dataAll.setItemVisual(rawIdx, 'color', singleDataColor);
  26002. }
  26003. });
  26004. }
  26005. });
  26006. };
  26007. /***/ },
  26008. /* 147 */
  26009. /***/ function(module, exports, __webpack_require__) {
  26010. // TODO minAngle
  26011. var numberUtil = __webpack_require__(7);
  26012. var parsePercent = numberUtil.parsePercent;
  26013. var labelLayout = __webpack_require__(148);
  26014. var zrUtil = __webpack_require__(4);
  26015. var PI2 = Math.PI * 2;
  26016. var RADIAN = Math.PI / 180;
  26017. module.exports = function (seriesType, ecModel, api, payload) {
  26018. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  26019. var center = seriesModel.get('center');
  26020. var radius = seriesModel.get('radius');
  26021. if (!zrUtil.isArray(radius)) {
  26022. radius = [0, radius];
  26023. }
  26024. if (!zrUtil.isArray(center)) {
  26025. center = [center, center];
  26026. }
  26027. var width = api.getWidth();
  26028. var height = api.getHeight();
  26029. var size = Math.min(width, height);
  26030. var cx = parsePercent(center[0], width);
  26031. var cy = parsePercent(center[1], height);
  26032. var r0 = parsePercent(radius[0], size / 2);
  26033. var r = parsePercent(radius[1], size / 2);
  26034. var data = seriesModel.getData();
  26035. var startAngle = -seriesModel.get('startAngle') * RADIAN;
  26036. var minAngle = seriesModel.get('minAngle') * RADIAN;
  26037. var sum = data.getSum('value');
  26038. // Sum may be 0
  26039. var unitRadian = Math.PI / (sum || data.count()) * 2;
  26040. var clockwise = seriesModel.get('clockwise');
  26041. var roseType = seriesModel.get('roseType');
  26042. var stillShowZeroSum = seriesModel.get('stillShowZeroSum');
  26043. // [0...max]
  26044. var extent = data.getDataExtent('value');
  26045. extent[0] = 0;
  26046. // In the case some sector angle is smaller than minAngle
  26047. var restAngle = PI2;
  26048. var valueSumLargerThanMinAngle = 0;
  26049. var currentAngle = startAngle;
  26050. var dir = clockwise ? 1 : -1;
  26051. data.each('value', function (value, idx) {
  26052. var angle;
  26053. if (isNaN(value)) {
  26054. data.setItemLayout(idx, {
  26055. angle: NaN,
  26056. startAngle: NaN,
  26057. endAngle: NaN,
  26058. clockwise: clockwise,
  26059. cx: cx,
  26060. cy: cy,
  26061. r0: r0,
  26062. r: roseType
  26063. ? NaN
  26064. : r
  26065. });
  26066. return;
  26067. }
  26068. // FIXME 兼容 2.0 但是 roseType 是 area 的时候才是这样?
  26069. if (roseType !== 'area') {
  26070. angle = (sum === 0 && stillShowZeroSum)
  26071. ? unitRadian : (value * unitRadian);
  26072. }
  26073. else {
  26074. angle = PI2 / (data.count() || 1);
  26075. }
  26076. if (angle < minAngle) {
  26077. angle = minAngle;
  26078. restAngle -= minAngle;
  26079. }
  26080. else {
  26081. valueSumLargerThanMinAngle += value;
  26082. }
  26083. var endAngle = currentAngle + dir * angle;
  26084. data.setItemLayout(idx, {
  26085. angle: angle,
  26086. startAngle: currentAngle,
  26087. endAngle: endAngle,
  26088. clockwise: clockwise,
  26089. cx: cx,
  26090. cy: cy,
  26091. r0: r0,
  26092. r: roseType
  26093. ? numberUtil.linearMap(value, extent, [r0, r])
  26094. : r
  26095. });
  26096. currentAngle = endAngle;
  26097. }, true);
  26098. // Some sector is constrained by minAngle
  26099. // Rest sectors needs recalculate angle
  26100. if (restAngle < PI2) {
  26101. // Average the angle if rest angle is not enough after all angles is
  26102. // Constrained by minAngle
  26103. if (restAngle <= 1e-3) {
  26104. var angle = PI2 / data.count();
  26105. data.each(function (idx) {
  26106. var layout = data.getItemLayout(idx);
  26107. layout.startAngle = startAngle + dir * idx * angle;
  26108. layout.endAngle = startAngle + dir * (idx + 1) * angle;
  26109. });
  26110. }
  26111. else {
  26112. unitRadian = restAngle / valueSumLargerThanMinAngle;
  26113. currentAngle = startAngle;
  26114. data.each('value', function (value, idx) {
  26115. var layout = data.getItemLayout(idx);
  26116. var angle = layout.angle === minAngle
  26117. ? minAngle : value * unitRadian;
  26118. layout.startAngle = currentAngle;
  26119. layout.endAngle = currentAngle + dir * angle;
  26120. currentAngle += dir * angle;
  26121. });
  26122. }
  26123. }
  26124. labelLayout(seriesModel, r, width, height);
  26125. });
  26126. };
  26127. /***/ },
  26128. /* 148 */
  26129. /***/ function(module, exports, __webpack_require__) {
  26130. 'use strict';
  26131. // FIXME emphasis label position is not same with normal label position
  26132. var textContain = __webpack_require__(8);
  26133. function adjustSingleSide(list, cx, cy, r, dir, viewWidth, viewHeight) {
  26134. list.sort(function (a, b) {
  26135. return a.y - b.y;
  26136. });
  26137. // 压
  26138. function shiftDown(start, end, delta, dir) {
  26139. for (var j = start; j < end; j++) {
  26140. list[j].y += delta;
  26141. if (j > start
  26142. && j + 1 < end
  26143. && list[j + 1].y > list[j].y + list[j].height
  26144. ) {
  26145. shiftUp(j, delta / 2);
  26146. return;
  26147. }
  26148. }
  26149. shiftUp(end - 1, delta / 2);
  26150. }
  26151. // 弹
  26152. function shiftUp(end, delta) {
  26153. for (var j = end; j >= 0; j--) {
  26154. list[j].y -= delta;
  26155. if (j > 0
  26156. && list[j].y > list[j - 1].y + list[j - 1].height
  26157. ) {
  26158. break;
  26159. }
  26160. }
  26161. }
  26162. function changeX(list, isDownList, cx, cy, r, dir) {
  26163. var lastDeltaX = dir > 0
  26164. ? isDownList // 右侧
  26165. ? Number.MAX_VALUE // 下
  26166. : 0 // 上
  26167. : isDownList // 左侧
  26168. ? Number.MAX_VALUE // 下
  26169. : 0; // 上
  26170. for (var i = 0, l = list.length; i < l; i++) {
  26171. // Not change x for center label
  26172. if (list[i].position === 'center') {
  26173. continue;
  26174. }
  26175. var deltaY = Math.abs(list[i].y - cy);
  26176. var length = list[i].len;
  26177. var length2 = list[i].len2;
  26178. var deltaX = (deltaY < r + length)
  26179. ? Math.sqrt(
  26180. (r + length + length2) * (r + length + length2)
  26181. - deltaY * deltaY
  26182. )
  26183. : Math.abs(list[i].x - cx);
  26184. if (isDownList && deltaX >= lastDeltaX) {
  26185. // 右下,左下
  26186. deltaX = lastDeltaX - 10;
  26187. }
  26188. if (!isDownList && deltaX <= lastDeltaX) {
  26189. // 右上,左上
  26190. deltaX = lastDeltaX + 10;
  26191. }
  26192. list[i].x = cx + deltaX * dir;
  26193. lastDeltaX = deltaX;
  26194. }
  26195. }
  26196. var lastY = 0;
  26197. var delta;
  26198. var len = list.length;
  26199. var upList = [];
  26200. var downList = [];
  26201. for (var i = 0; i < len; i++) {
  26202. delta = list[i].y - lastY;
  26203. if (delta < 0) {
  26204. shiftDown(i, len, -delta, dir);
  26205. }
  26206. lastY = list[i].y + list[i].height;
  26207. }
  26208. if (viewHeight - lastY < 0) {
  26209. shiftUp(len - 1, lastY - viewHeight);
  26210. }
  26211. for (var i = 0; i < len; i++) {
  26212. if (list[i].y >= cy) {
  26213. downList.push(list[i]);
  26214. }
  26215. else {
  26216. upList.push(list[i]);
  26217. }
  26218. }
  26219. changeX(upList, false, cx, cy, r, dir);
  26220. changeX(downList, true, cx, cy, r, dir);
  26221. }
  26222. function avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight) {
  26223. var leftList = [];
  26224. var rightList = [];
  26225. for (var i = 0; i < labelLayoutList.length; i++) {
  26226. if (labelLayoutList[i].x < cx) {
  26227. leftList.push(labelLayoutList[i]);
  26228. }
  26229. else {
  26230. rightList.push(labelLayoutList[i]);
  26231. }
  26232. }
  26233. adjustSingleSide(rightList, cx, cy, r, 1, viewWidth, viewHeight);
  26234. adjustSingleSide(leftList, cx, cy, r, -1, viewWidth, viewHeight);
  26235. for (var i = 0; i < labelLayoutList.length; i++) {
  26236. var linePoints = labelLayoutList[i].linePoints;
  26237. if (linePoints) {
  26238. var dist = linePoints[1][0] - linePoints[2][0];
  26239. if (labelLayoutList[i].x < cx) {
  26240. linePoints[2][0] = labelLayoutList[i].x + 3;
  26241. }
  26242. else {
  26243. linePoints[2][0] = labelLayoutList[i].x - 3;
  26244. }
  26245. linePoints[1][1] = linePoints[2][1] = labelLayoutList[i].y;
  26246. linePoints[1][0] = linePoints[2][0] + dist;
  26247. }
  26248. }
  26249. }
  26250. module.exports = function (seriesModel, r, viewWidth, viewHeight) {
  26251. var data = seriesModel.getData();
  26252. var labelLayoutList = [];
  26253. var cx;
  26254. var cy;
  26255. var hasLabelRotate = false;
  26256. data.each(function (idx) {
  26257. var layout = data.getItemLayout(idx);
  26258. var itemModel = data.getItemModel(idx);
  26259. var labelModel = itemModel.getModel('label.normal');
  26260. // Use position in normal or emphasis
  26261. var labelPosition = labelModel.get('position') || itemModel.get('label.emphasis.position');
  26262. var labelLineModel = itemModel.getModel('labelLine.normal');
  26263. var labelLineLen = labelLineModel.get('length');
  26264. var labelLineLen2 = labelLineModel.get('length2');
  26265. var midAngle = (layout.startAngle + layout.endAngle) / 2;
  26266. var dx = Math.cos(midAngle);
  26267. var dy = Math.sin(midAngle);
  26268. var textX;
  26269. var textY;
  26270. var linePoints;
  26271. var textAlign;
  26272. cx = layout.cx;
  26273. cy = layout.cy;
  26274. var isLabelInside = labelPosition === 'inside' || labelPosition === 'inner';
  26275. if (labelPosition === 'center') {
  26276. textX = layout.cx;
  26277. textY = layout.cy;
  26278. textAlign = 'center';
  26279. }
  26280. else {
  26281. var x1 = (isLabelInside ? (layout.r + layout.r0) / 2 * dx : layout.r * dx) + cx;
  26282. var y1 = (isLabelInside ? (layout.r + layout.r0) / 2 * dy : layout.r * dy) + cy;
  26283. textX = x1 + dx * 3;
  26284. textY = y1 + dy * 3;
  26285. if (!isLabelInside) {
  26286. // For roseType
  26287. var x2 = x1 + dx * (labelLineLen + r - layout.r);
  26288. var y2 = y1 + dy * (labelLineLen + r - layout.r);
  26289. var x3 = x2 + ((dx < 0 ? -1 : 1) * labelLineLen2);
  26290. var y3 = y2;
  26291. textX = x3 + (dx < 0 ? -5 : 5);
  26292. textY = y3;
  26293. linePoints = [[x1, y1], [x2, y2], [x3, y3]];
  26294. }
  26295. textAlign = isLabelInside ? 'center' : (dx > 0 ? 'left' : 'right');
  26296. }
  26297. var font = labelModel.getModel('textStyle').getFont();
  26298. var labelRotate = labelModel.get('rotate')
  26299. ? (dx < 0 ? -midAngle + Math.PI : -midAngle) : 0;
  26300. var text = seriesModel.getFormattedLabel(idx, 'normal')
  26301. || data.getName(idx);
  26302. var textRect = textContain.getBoundingRect(
  26303. text, font, textAlign, 'top'
  26304. );
  26305. hasLabelRotate = !!labelRotate;
  26306. layout.label = {
  26307. x: textX,
  26308. y: textY,
  26309. position: labelPosition,
  26310. height: textRect.height,
  26311. len: labelLineLen,
  26312. len2: labelLineLen2,
  26313. linePoints: linePoints,
  26314. textAlign: textAlign,
  26315. verticalAlign: 'middle',
  26316. font: font,
  26317. rotation: labelRotate
  26318. };
  26319. // Not layout the inside label
  26320. if (!isLabelInside) {
  26321. labelLayoutList.push(layout.label);
  26322. }
  26323. });
  26324. if (!hasLabelRotate && seriesModel.get('avoidLabelOverlap')) {
  26325. avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight);
  26326. }
  26327. };
  26328. /***/ },
  26329. /* 149 */
  26330. /***/ function(module, exports) {
  26331. module.exports = function (seriesType, ecModel) {
  26332. var legendModels = ecModel.findComponents({
  26333. mainType: 'legend'
  26334. });
  26335. if (!legendModels || !legendModels.length) {
  26336. return;
  26337. }
  26338. ecModel.eachSeriesByType(seriesType, function (series) {
  26339. var data = series.getData();
  26340. data.filterSelf(function (idx) {
  26341. var name = data.getName(idx);
  26342. // If in any legend component the status is not selected.
  26343. for (var i = 0; i < legendModels.length; i++) {
  26344. if (!legendModels[i].isSelected(name)) {
  26345. return false;
  26346. }
  26347. }
  26348. return true;
  26349. }, this);
  26350. }, this);
  26351. };
  26352. /***/ }
  26353. /******/ ])
  26354. });
  26355. ;